YARN-10104. FS-CS converter: dry run should work without output defined. Contributed by Peter Bacsko

This commit is contained in:
Szilard Nemeth 2020-01-28 15:36:04 +01:00
parent ca29768035
commit 94f060242e
2 changed files with 20 additions and 7 deletions

View File

@ -183,13 +183,14 @@ public class FSConfigToCSConfigArgumentHandler {
private FSConfigToCSConfigConverter prepareAndGetConverter(
CommandLine cliParser) {
conversionOptions.setDryRun(
cliParser.hasOption(CliOption.DRY_RUN.shortSwitch));
boolean dryRun =
cliParser.hasOption(CliOption.DRY_RUN.shortSwitch);
conversionOptions.setDryRun(dryRun);
conversionOptions.setNoTerminalRuleCheck(
cliParser.hasOption(CliOption.NO_TERMINAL_RULE_CHECK.shortSwitch));
checkOptionPresent(cliParser, CliOption.YARN_SITE);
checkOutputDefined(cliParser);
checkOutputDefined(cliParser, dryRun);
converterParams = validateInputFiles(cliParser);
ruleHandler = new FSConfigToCSConfigRuleHandler(conversionOptions);
@ -238,14 +239,15 @@ public class FSConfigToCSConfigArgumentHandler {
}
}
private static void checkOutputDefined(CommandLine cliParser) {
private static void checkOutputDefined(CommandLine cliParser,
boolean dryRun) {
boolean hasOutputDir =
cliParser.hasOption(CliOption.OUTPUT_DIR.shortSwitch);
boolean console =
cliParser.hasOption(CliOption.CONSOLE_MODE.shortSwitch);
if (!console && !hasOutputDir) {
if (!console && !hasOutputDir && !dryRun) {
throw new PreconditionException(
"Output directory or console mode was not defined. Please" +
" use -h or --help to see command line switches");

View File

@ -108,12 +108,23 @@ public class TestFSConfigToCSConfigArgumentHandler {
"-o", FSConfigConverterTestCommons.OUTPUT_DIR);
}
private static List<String> getDefaultArgumentsWithNoOutput() {
return Lists.newArrayList("-y", FSConfigConverterTestCommons.YARN_SITE_XML);
}
private String[] getArgumentsAsArrayWithDefaults(String... args) {
List<String> result = getDefaultArguments();
result.addAll(Arrays.asList(args));
return result.toArray(new String[0]);
}
private String[] getArgumentsAsArrayWithDefaultsNoOutput(
String... args) {
List<String> result = getDefaultArgumentsWithNoOutput();
result.addAll(Arrays.asList(args));
return result.toArray(new String[0]);
}
private String[] getArgumentsAsArray(String... args) {
List<String> result = Lists.newArrayList();
result.addAll(Arrays.asList(args));
@ -426,9 +437,9 @@ public class TestFSConfigToCSConfigArgumentHandler {
String expectedErrorMessage) throws Exception {
setupFSConfigConversionFiles(true);
String[] args = getArgumentsAsArrayWithDefaults("-f",
String[] args = getArgumentsAsArrayWithDefaultsNoOutput("-f",
FSConfigConverterTestCommons.FS_ALLOC_FILE,
"-r", FSConfigConverterTestCommons.CONVERSION_RULES_FILE, "-p",
"-r", FSConfigConverterTestCommons.CONVERSION_RULES_FILE,
"-d");
FSConfigToCSConfigArgumentHandler argumentHandler =
new FSConfigToCSConfigArgumentHandler(conversionOptions);