Skip to content

Commit

Permalink
YARN-10167. FS-CS Converter: Need to validate c-s.xml after convertin…
Browse files Browse the repository at this point in the history
…g. Contributed by Peter Bacsko
  • Loading branch information
szilard-nemeth committed Mar 5, 2020
1 parent 2649f8b commit 004e955
Show file tree
Hide file tree
Showing 14 changed files with 495 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public void handlePreconditionError(String msg) {
}
}

public void handleVerificationFailure(Throwable e, String msg) {
FSConfigToCSConfigArgumentHandler.logAndStdErr(e, msg);
if (dryRun) {
dryRunResultHolder.setVerificationFailed();
}
}

public void handleParsingFinished() {
if (dryRun) {
dryRunResultHolder.printDryRunResults();
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DryRunResultHolder {

private Set<String> warnings;
private Set<String> errors;
private boolean verificationFailed;

public DryRunResultHolder() {
this.warnings = new HashSet<>();
Expand All @@ -46,6 +47,10 @@ public void addDryRunError(String message) {
errors.add(message);
}

public void setVerificationFailed() {
verificationFailed = true;
}

public Set<String> getWarnings() {
return ImmutableSet.copyOf(warnings);
}
Expand All @@ -64,6 +69,8 @@ public void printDryRunResults() {

LOG.info("Number of errors: {}", noOfErrors);
LOG.info("Number of warnings: {}", noOfWarnings);
LOG.info("Verification result: {}",
verificationFailed ? "FAILED" : "PASSED");

if (noOfErrors > 0) {
LOG.info("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,22 @@ public class FSConfigToCSConfigArgumentHandler {
private FSConfigToCSConfigRuleHandler ruleHandler;
private FSConfigToCSConfigConverterParams converterParams;
private ConversionOptions conversionOptions;
private ConvertedConfigValidator validator;

private Supplier<FSConfigToCSConfigConverter>
converterFunc = this::getConverter;

public FSConfigToCSConfigArgumentHandler() {
this.conversionOptions = new ConversionOptions(new DryRunResultHolder(),
false);
this.validator = new ConvertedConfigValidator();
}

@VisibleForTesting
FSConfigToCSConfigArgumentHandler(ConversionOptions conversionOptions) {
FSConfigToCSConfigArgumentHandler(ConversionOptions conversionOptions,
ConvertedConfigValidator validator) {
this.conversionOptions = conversionOptions;
this.validator = validator;
}

/**
Expand Down Expand Up @@ -102,6 +106,9 @@ public enum CliOption {
"m", "convert-placement-rules",
"Convert Fair Scheduler placement rules to Capacity" +
" Scheduler mapping rules", false),
SKIP_VERIFICATION("skip verification", "s",
"skip-verification",
"Skips the verification of the converted configuration", false),
HELP("help", "h", "help", "Displays the list of options", false);

private final String name;
Expand Down Expand Up @@ -147,6 +154,14 @@ int parseAndConvert(String[] args) throws Exception {
prepareAndGetConverter(cliParser);

converter.convert(converterParams);

String outputDir = converterParams.getOutputDirectory();
boolean skipVerification =
cliParser.hasOption(CliOption.SKIP_VERIFICATION.shortSwitch);
if (outputDir != null && !skipVerification) {
validator.validateConvertedConfig(
converterParams.getOutputDirectory());
}
} catch (ParseException e) {
String msg = "Options parsing failed: " + e.getMessage();
logAndStdErr(e, msg);
Expand All @@ -166,6 +181,11 @@ int parseAndConvert(String[] args) throws Exception {
String msg = "Fatal error during FS config conversion: " + e.getMessage();
handleException(e, msg);
retVal = -1;
} catch (VerificationException e) {
Throwable cause = e.getCause();
String msg = "Verification failed: " + e.getCause().getMessage();
conversionOptions.handleVerificationFailure(cause, msg);
retVal = -1;
}

conversionOptions.handleParsingFinished();
Expand All @@ -177,8 +197,8 @@ private void handleException(Exception e, String msg) {
conversionOptions.handleGenericException(e, msg);
}

static void logAndStdErr(Exception e, String msg) {
LOG.debug("Stack trace", e);
static void logAndStdErr(Throwable t, String msg) {
LOG.debug("Stack trace", t);
LOG.error(msg);
System.err.println(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void convertQueueHierarchy(FSQueue queue) {

emitChildCapacity(queue);
emitMaximumCapacity(queueName, queue);
emitAutoCreateChildQueue(queueName);
emitAutoCreateChildQueue(queueName, queue);
emitSizeBasedWeight(queueName);
emitOrderingPolicy(queueName, queue);
checkMaxChildCapacitySetting(queue);
Expand Down Expand Up @@ -267,8 +267,8 @@ private void emitPreemptionDisabled(String queueName, FSQueue queue) {
* .auto-create-child-queue.enabled.
* @param queueName
*/
private void emitAutoCreateChildQueue(String queueName) {
if (autoCreateChildQueues) {
private void emitAutoCreateChildQueue(String queueName, FSQueue queue) {
if (autoCreateChildQueues && !queue.getChildQueues().isEmpty()) {
capacitySchedulerConfig.setBoolean(PREFIX + queueName +
".auto-create-child-queue.enabled", true);
}
Expand Down
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);
}
}
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);
}
}
Loading

0 comments on commit 004e955

Please sign in to comment.