forked from apache/hadoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YARN-10167. FS-CS Converter: Need to validate c-s.xml after convertin…
…g. Contributed by Peter Bacsko
- Loading branch information
1 parent
2649f8b
commit 004e955
Showing
14 changed files
with
495 additions
and
14 deletions.
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
80 changes: 80 additions & 0 deletions
80
...hadoop/yarn/server/resourcemanager/scheduler/fair/converter/ConvertedConfigValidator.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,80 @@ | ||
/* | ||
* 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.hadoop.yarn.server.resourcemanager.scheduler.fair.converter; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.yarn.FileSystemBasedConfigurationProvider; | ||
import org.apache.hadoop.yarn.conf.ConfigurationProvider; | ||
import org.apache.hadoop.yarn.conf.YarnConfiguration; | ||
import org.apache.hadoop.yarn.server.resourcemanager.RMContextImpl; | ||
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager; | ||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics; | ||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; | ||
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Validates the converted capacity-scheduler.xml by starting | ||
* a Capacity Scheduler instance. | ||
* | ||
*/ | ||
public class ConvertedConfigValidator { | ||
private static final Logger LOG = | ||
LoggerFactory.getLogger(ConvertedConfigValidator.class); | ||
|
||
public void validateConvertedConfig(String outputDir) | ||
throws Exception { | ||
QueueMetrics.clearQueueMetrics(); | ||
Path configPath = new Path(outputDir, "capacity-scheduler.xml"); | ||
|
||
CapacitySchedulerConfiguration csConfig = | ||
new CapacitySchedulerConfiguration( | ||
new Configuration(false), false); | ||
csConfig.addResource(configPath); | ||
|
||
Path convertedSiteConfigPath = new Path(outputDir, "yarn-site.xml"); | ||
Configuration siteConf = new YarnConfiguration( | ||
new Configuration(false)); | ||
siteConf.addResource(convertedSiteConfigPath); | ||
|
||
RMContextImpl rmContext = new RMContextImpl(); | ||
siteConf.set(YarnConfiguration.FS_BASED_RM_CONF_STORE, outputDir); | ||
ConfigurationProvider provider = new FileSystemBasedConfigurationProvider(); | ||
provider.init(siteConf); | ||
rmContext.setConfigurationProvider(provider); | ||
RMNodeLabelsManager mgr = new RMNodeLabelsManager(); | ||
mgr.init(siteConf); | ||
rmContext.setNodeLabelManager(mgr); | ||
|
||
try (CapacityScheduler cs = new CapacityScheduler()) { | ||
cs.setConf(siteConf); | ||
cs.setRMContext(rmContext); | ||
cs.serviceInit(csConfig); | ||
cs.serviceStart(); | ||
LOG.info("Capacity scheduler was successfully started"); | ||
cs.serviceStop(); | ||
} catch (Exception e) { | ||
LOG.error("Could not start Capacity Scheduler", e); | ||
throw new VerificationException( | ||
"Verification of converted configuration failed", e); | ||
} | ||
} | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
...he/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/VerificationException.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,31 @@ | ||
/* | ||
* 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.hadoop.yarn.server.resourcemanager.scheduler.fair.converter; | ||
|
||
/** | ||
* Thrown when Capacity Scheduler fails to start up with | ||
* the converted configuration. | ||
*/ | ||
public class VerificationException extends RuntimeException { | ||
private static final long serialVersionUID = -7697926560416349141L; | ||
|
||
public VerificationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...op/yarn/server/resourcemanager/scheduler/fair/converter/TestConvertedConfigValidator.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,53 @@ | ||
/* | ||
* 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.hadoop.yarn.server.resourcemanager.scheduler.fair.converter; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class TestConvertedConfigValidator { | ||
private static final String CONFIG_DIR_PASSES = | ||
new File("src/test/resources/cs-validation-pass").getAbsolutePath(); | ||
private static final String CONFIG_DIR_FAIL = | ||
new File("src/test/resources/cs-validation-fail").getAbsolutePath(); | ||
|
||
private ConvertedConfigValidator validator; | ||
|
||
@Before | ||
public void setup() { | ||
validator = new ConvertedConfigValidator(); | ||
} | ||
|
||
@Test | ||
public void testValidationPassed() throws Exception { | ||
validator.validateConvertedConfig(CONFIG_DIR_PASSES); | ||
|
||
// expected: no exception | ||
} | ||
|
||
@Test(expected = VerificationException.class) | ||
public void testValidationFails() throws Exception { | ||
validator.validateConvertedConfig(CONFIG_DIR_FAIL); | ||
} | ||
} |
Oops, something went wrong.