-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce AccessSupportRssChecker to reject the un-support applicatio…
…n earlier
- Loading branch information
1 parent
4ce1aa8
commit 3d2c4df
Showing
4 changed files
with
170 additions
and
1 deletion.
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
60 changes: 60 additions & 0 deletions
60
.../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,60 @@ | ||
/* | ||
* 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 org.apache.hadoop.io.serializer.JavaSerialization; | ||
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.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); | ||
|
||
public AccessSupportRssChecker(AccessManager accessManager) throws Exception { | ||
super(accessManager); | ||
} | ||
|
||
@Override | ||
public AccessCheckResult check(AccessInfo accessInfo) { | ||
String serializer = accessInfo.getExtraProperties().get("serializer"); | ||
if (JavaSerialization.class.getName().equals(serializer)) { | ||
String msg = String.format("Denied by AccessSupportRssChecker, accessInfo[%s].", accessInfo); | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("serializer is {}, {}", serializer, 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()); | ||
} | ||
} | ||
} |