HDFS-13858. RBF: Add check to have single valid argument to safemode command. Contributed by Ayush Saxena.
This commit is contained in:
parent
3974427f67
commit
75691ad600
@ -218,6 +218,10 @@ public int run(String[] argv) throws Exception {
|
|||||||
"Successfully clear quota for mount point " + argv[i]);
|
"Successfully clear quota for mount point " + argv[i]);
|
||||||
}
|
}
|
||||||
} else if ("-safemode".equals(cmd)) {
|
} else if ("-safemode".equals(cmd)) {
|
||||||
|
if (argv.length > 2) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Too many arguments, Max=1 argument allowed only");
|
||||||
|
}
|
||||||
manageSafeMode(argv[i]);
|
manageSafeMode(argv[i]);
|
||||||
} else if ("-nameservice".equals(cmd)) {
|
} else if ("-nameservice".equals(cmd)) {
|
||||||
String subcmd = argv[i];
|
String subcmd = argv[i];
|
||||||
@ -712,6 +716,8 @@ private void manageSafeMode(String cmd) throws IOException {
|
|||||||
} else if (cmd.equals("get")) {
|
} else if (cmd.equals("get")) {
|
||||||
boolean result = getSafeMode();
|
boolean result = getSafeMode();
|
||||||
System.out.println("Safe Mode: " + result);
|
System.out.println("Safe Mode: " + result);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Invalid argument: " + cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,6 +519,7 @@ public void testManageSafeMode() throws Exception {
|
|||||||
assertTrue(routerContext.getRouter().getSafemodeService().isInSafeMode());
|
assertTrue(routerContext.getRouter().getSafemodeService().isInSafeMode());
|
||||||
|
|
||||||
System.setOut(new PrintStream(out));
|
System.setOut(new PrintStream(out));
|
||||||
|
System.setErr(new PrintStream(err));
|
||||||
assertEquals(0, ToolRunner.run(admin,
|
assertEquals(0, ToolRunner.run(admin,
|
||||||
new String[] {"-safemode", "get"}));
|
new String[] {"-safemode", "get"}));
|
||||||
assertTrue(out.toString().contains("true"));
|
assertTrue(out.toString().contains("true"));
|
||||||
@ -534,6 +535,19 @@ public void testManageSafeMode() throws Exception {
|
|||||||
assertEquals(0, ToolRunner.run(admin,
|
assertEquals(0, ToolRunner.run(admin,
|
||||||
new String[] {"-safemode", "get"}));
|
new String[] {"-safemode", "get"}));
|
||||||
assertTrue(out.toString().contains("false"));
|
assertTrue(out.toString().contains("false"));
|
||||||
|
|
||||||
|
out.reset();
|
||||||
|
assertEquals(-1, ToolRunner.run(admin,
|
||||||
|
new String[] {"-safemode", "get", "-random", "check" }));
|
||||||
|
assertTrue(err.toString(), err.toString()
|
||||||
|
.contains("safemode: Too many arguments, Max=1 argument allowed only"));
|
||||||
|
err.reset();
|
||||||
|
|
||||||
|
assertEquals(-1,
|
||||||
|
ToolRunner.run(admin, new String[] {"-safemode", "check" }));
|
||||||
|
assertTrue(err.toString(),
|
||||||
|
err.toString().contains("safemode: Invalid argument: check"));
|
||||||
|
err.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user