-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#2278] feat(coordinator): Introduce AccessSupportRssChecker to reject the un-support application earlier #2277
Open
maobaolong
wants to merge
5
commits into
apache:master
Choose a base branch
from
maobaolong:supportRssChecker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3d2c4df
Introduce AccessSupportRssChecker to reject the un-support applicatio…
maobaolong 39e01fa
Add a new config "unsupportedConfigs" and refactor code
maobaolong b611bdf
Refactor CoordinatorConf to avoid class string
maobaolong aa2cbc1
Update document of rss.coordinator.access.checkers
maobaolong 6621014
Fix findbugs issue
maobaolong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
.../src/main/java/org/apache/uniffle/coordinator/access/checker/AccessSupportRssChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.coordinator.access.checker; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.uniffle.common.util.Constants; | ||
import org.apache.uniffle.coordinator.AccessManager; | ||
import org.apache.uniffle.coordinator.CoordinatorConf; | ||
import org.apache.uniffle.coordinator.access.AccessCheckResult; | ||
import org.apache.uniffle.coordinator.access.AccessInfo; | ||
import org.apache.uniffle.coordinator.metric.CoordinatorMetrics; | ||
|
||
/** | ||
* AccessSupportRssChecker checks whether the extra properties support rss, for example, the | ||
* serializer is java, rss is not supported. | ||
*/ | ||
public class AccessSupportRssChecker extends AbstractAccessChecker { | ||
private static final Logger LOG = LoggerFactory.getLogger(AccessSupportRssChecker.class); | ||
private final HashMap<String, String> unsupportedConfigMap; | ||
|
||
public AccessSupportRssChecker(AccessManager accessManager) throws Exception { | ||
super(accessManager); | ||
List<String> unsupportedConfigs = | ||
accessManager.getCoordinatorConf().get(CoordinatorConf.COORDINATOR_UNSUPPORTED_CONFIGS); | ||
unsupportedConfigMap = new HashMap<>(); | ||
if (unsupportedConfigs != null && !unsupportedConfigs.isEmpty()) { | ||
for (String keyValue : unsupportedConfigs) { | ||
String[] pair = keyValue.split(":", 2); | ||
if (pair.length == 2) { | ||
unsupportedConfigMap.put(pair[0], pair[1]); | ||
} else { | ||
LOG.error("Unsupported config {} has wrong format, skip it.", keyValue); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public AccessCheckResult check(AccessInfo accessInfo) { | ||
for (Map.Entry<String, String> entry : unsupportedConfigMap.entrySet()) { | ||
String unsupportedConfKey = entry.getKey(); | ||
String unsupportedConfValue = entry.getValue(); | ||
String actualConfValue = accessInfo.getExtraProperties().get(unsupportedConfKey); | ||
if (Objects.equals(actualConfValue, unsupportedConfValue)) { | ||
String msg = | ||
String.format( | ||
"Denied by AccessSupportRssChecker, %s is %s, AccessSupportRssChecker does not supported.", | ||
unsupportedConfKey, actualConfValue); | ||
LOG.debug(msg); | ||
CoordinatorMetrics.counterTotalSupportRssDeniedRequest.inc(); | ||
return new AccessCheckResult(false, msg); | ||
} | ||
} | ||
|
||
return new AccessCheckResult(true, Constants.COMMON_SUCCESS_MESSAGE); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...tor/src/test/java/org/apache/uniffle/coordinator/checker/AccessSupportRssCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.coordinator.checker; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.io.serializer.JavaSerialization; | ||
import org.apache.hadoop.io.serializer.WritableSerialization; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.apache.uniffle.coordinator.AccessManager; | ||
import org.apache.uniffle.coordinator.ApplicationManager; | ||
import org.apache.uniffle.coordinator.ClusterManager; | ||
import org.apache.uniffle.coordinator.CoordinatorConf; | ||
import org.apache.uniffle.coordinator.SimpleClusterManager; | ||
import org.apache.uniffle.coordinator.access.AccessInfo; | ||
import org.apache.uniffle.coordinator.access.checker.AccessSupportRssChecker; | ||
import org.apache.uniffle.coordinator.metric.CoordinatorMetrics; | ||
|
||
import static org.apache.uniffle.coordinator.CoordinatorConf.COORDINATOR_ACCESS_CHECKERS; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class AccessSupportRssCheckerTest { | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
CoordinatorMetrics.register(); | ||
} | ||
|
||
@AfterEach | ||
public void clear() { | ||
CoordinatorMetrics.clear(); | ||
} | ||
|
||
@Test | ||
public void test() throws Exception { | ||
ClusterManager clusterManager = mock(SimpleClusterManager.class); | ||
|
||
CoordinatorConf conf = new CoordinatorConf(); | ||
conf.set( | ||
COORDINATOR_ACCESS_CHECKERS, | ||
Collections.singletonList(AccessSupportRssChecker.class.getName())); | ||
Map<String, String> properties = new HashMap<>(); | ||
|
||
/** case1: check success when the serializer config is empty. */ | ||
try (ApplicationManager applicationManager = new ApplicationManager(conf)) { | ||
AccessManager accessManager = | ||
new AccessManager( | ||
conf, clusterManager, applicationManager.getQuotaManager(), new Configuration()); | ||
AccessSupportRssChecker checker = | ||
(AccessSupportRssChecker) accessManager.getAccessCheckers().get(0); | ||
AccessInfo accessInfo = new AccessInfo("test", new HashSet<>(), properties, "user"); | ||
assertTrue(checker.check(accessInfo).isSuccess()); | ||
} | ||
|
||
/** case2: check failed when the serializer config is JavaSerialization. */ | ||
properties.put("serializer", JavaSerialization.class.getCanonicalName()); | ||
try (ApplicationManager applicationManager = new ApplicationManager(conf)) { | ||
AccessManager accessManager = | ||
new AccessManager( | ||
conf, clusterManager, applicationManager.getQuotaManager(), new Configuration()); | ||
AccessSupportRssChecker checker = | ||
(AccessSupportRssChecker) accessManager.getAccessCheckers().get(0); | ||
AccessInfo accessInfo = new AccessInfo("test", new HashSet<>(), properties, "user"); | ||
assertFalse(checker.check(accessInfo).isSuccess()); | ||
} | ||
|
||
/** case3: check success when the serializer config is other than JavaSerialization. */ | ||
properties.put("serializer", WritableSerialization.class.getCanonicalName()); | ||
try (ApplicationManager applicationManager = new ApplicationManager(conf)) { | ||
AccessManager accessManager = | ||
new AccessManager( | ||
conf, clusterManager, applicationManager.getQuotaManager(), new Configuration()); | ||
AccessSupportRssChecker checker = | ||
(AccessSupportRssChecker) accessManager.getAccessCheckers().get(0); | ||
AccessInfo accessInfo = new AccessInfo("test", new HashSet<>(), properties, "user"); | ||
assertTrue(checker.check(accessInfo).isSuccess()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you modify the document, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done