HDFS-13906. RBF: Add multiple paths for dfsrouteradmin 'rm' and 'clrquota' commands. Contributed by Ayush Saxena.
This commit is contained in:
parent
b220ec6f61
commit
41c94a636b
@ -151,17 +151,7 @@ private String getUsage(String cmd) {
|
|||||||
* @param arg List of of command line parameters.
|
* @param arg List of of command line parameters.
|
||||||
*/
|
*/
|
||||||
private void validateMax(String[] arg) {
|
private void validateMax(String[] arg) {
|
||||||
if (arg[0].equals("-rm")) {
|
if (arg[0].equals("-ls")) {
|
||||||
if (arg.length > 2) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Too many arguments, Max=1 argument allowed");
|
|
||||||
}
|
|
||||||
} else if (arg[0].equals("-ls")) {
|
|
||||||
if (arg.length > 2) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Too many arguments, Max=1 argument allowed");
|
|
||||||
}
|
|
||||||
} else if (arg[0].equals("-clrQuota")) {
|
|
||||||
if (arg.length > 2) {
|
if (arg.length > 2) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Too many arguments, Max=1 argument allowed");
|
"Too many arguments, Max=1 argument allowed");
|
||||||
@ -183,6 +173,45 @@ private void validateMax(String[] arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Usage: validates the minimum number of arguments for a command.
|
||||||
|
* @param argv List of of command line parameters.
|
||||||
|
* @return true if number of arguments are valid for the command else false.
|
||||||
|
*/
|
||||||
|
private boolean validateMin(String[] argv) {
|
||||||
|
String cmd = argv[0];
|
||||||
|
if ("-add".equals(cmd)) {
|
||||||
|
if (argv.length < 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if ("-update".equals(cmd)) {
|
||||||
|
if (argv.length < 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if ("-rm".equals(cmd)) {
|
||||||
|
if (argv.length < 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if ("-setQuota".equals(cmd)) {
|
||||||
|
if (argv.length < 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if ("-clrQuota".equals(cmd)) {
|
||||||
|
if (argv.length < 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if ("-safemode".equals(cmd)) {
|
||||||
|
if (argv.length < 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if ("-nameservice".equals(cmd)) {
|
||||||
|
if (argv.length < 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int run(String[] argv) throws Exception {
|
public int run(String[] argv) throws Exception {
|
||||||
if (argv.length < 1) {
|
if (argv.length < 1) {
|
||||||
@ -196,50 +225,11 @@ public int run(String[] argv) throws Exception {
|
|||||||
String cmd = argv[i++];
|
String cmd = argv[i++];
|
||||||
|
|
||||||
// Verify that we have enough command line parameters
|
// Verify that we have enough command line parameters
|
||||||
if ("-add".equals(cmd)) {
|
if (!validateMin(argv)) {
|
||||||
if (argv.length < 4) {
|
System.err.println("Not enough parameters specificed for cmd " + cmd);
|
||||||
System.err.println("Not enough parameters specified for cmd " + cmd);
|
printUsage(cmd);
|
||||||
printUsage(cmd);
|
return exitCode;
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
} else if ("-update".equals(cmd)) {
|
|
||||||
if (argv.length < 4) {
|
|
||||||
System.err.println("Not enough parameters specified for cmd " + cmd);
|
|
||||||
printUsage(cmd);
|
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
} else if ("-rm".equals(cmd)) {
|
|
||||||
if (argv.length < 2) {
|
|
||||||
System.err.println("Not enough parameters specified for cmd " + cmd);
|
|
||||||
printUsage(cmd);
|
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
} else if ("-setQuota".equals(cmd)) {
|
|
||||||
if (argv.length < 4) {
|
|
||||||
System.err.println("Not enough parameters specified for cmd " + cmd);
|
|
||||||
printUsage(cmd);
|
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
} else if ("-clrQuota".equals(cmd)) {
|
|
||||||
if (argv.length < 2) {
|
|
||||||
System.err.println("Not enough parameters specified for cmd " + cmd);
|
|
||||||
printUsage(cmd);
|
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
} else if ("-safemode".equals(cmd)) {
|
|
||||||
if (argv.length < 2) {
|
|
||||||
System.err.println("Not enough parameters specified for cmd " + cmd);
|
|
||||||
printUsage(cmd);
|
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
} else if ("-nameservice".equals(cmd)) {
|
|
||||||
if (argv.length < 3) {
|
|
||||||
System.err.println("Not enough parameters specificed for cmd " + cmd);
|
|
||||||
printUsage(cmd);
|
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize RouterClient
|
// Initialize RouterClient
|
||||||
try {
|
try {
|
||||||
String address = getConf().getTrimmed(
|
String address = getConf().getTrimmed(
|
||||||
@ -273,8 +263,17 @@ public int run(String[] argv) throws Exception {
|
|||||||
exitCode = -1;
|
exitCode = -1;
|
||||||
}
|
}
|
||||||
} else if ("-rm".equals(cmd)) {
|
} else if ("-rm".equals(cmd)) {
|
||||||
if (removeMount(argv[i])) {
|
while (i < argv.length) {
|
||||||
System.out.println("Successfully removed mount point " + argv[i]);
|
try {
|
||||||
|
if (removeMount(argv[i])) {
|
||||||
|
System.out.println("Successfully removed mount point " + argv[i]);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
exitCode = -1;
|
||||||
|
System.err
|
||||||
|
.println(cmd.substring(1) + ": " + e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
} else if ("-ls".equals(cmd)) {
|
} else if ("-ls".equals(cmd)) {
|
||||||
if (argv.length > 1) {
|
if (argv.length > 1) {
|
||||||
@ -288,9 +287,12 @@ public int run(String[] argv) throws Exception {
|
|||||||
"Successfully set quota for mount point " + argv[i]);
|
"Successfully set quota for mount point " + argv[i]);
|
||||||
}
|
}
|
||||||
} else if ("-clrQuota".equals(cmd)) {
|
} else if ("-clrQuota".equals(cmd)) {
|
||||||
if (clrQuota(argv[i])) {
|
while (i < argv.length) {
|
||||||
System.out.println(
|
if (clrQuota(argv[i])) {
|
||||||
"Successfully clear quota for mount point " + argv[i]);
|
System.out
|
||||||
|
.println("Successfully clear quota for mount point " + argv[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if ("-safemode".equals(cmd)) {
|
} else if ("-safemode".equals(cmd)) {
|
||||||
manageSafeMode(argv[i]);
|
manageSafeMode(argv[i]);
|
||||||
|
@ -342,13 +342,43 @@ public void testRemoveMountTable() throws Exception {
|
|||||||
assertEquals(0, ToolRunner.run(admin, argv));
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
assertTrue(out.toString().contains(
|
assertTrue(out.toString().contains(
|
||||||
"Cannot remove mount point " + invalidPath));
|
"Cannot remove mount point " + invalidPath));
|
||||||
|
}
|
||||||
|
|
||||||
// test wrong number of arguments
|
@Test
|
||||||
System.setErr(new PrintStream(err));
|
public void testMultiArgsRemoveMountTable() throws Exception {
|
||||||
argv = new String[] {"-rm", src, "check" };
|
String nsId = "ns0";
|
||||||
ToolRunner.run(admin, argv);
|
String src1 = "/test-rmmounttable1";
|
||||||
assertTrue(err.toString()
|
String src2 = "/test-rmmounttable2";
|
||||||
.contains("Too many arguments, Max=1 argument allowed"));
|
String dest1 = "/rmmounttable1";
|
||||||
|
String dest2 = "/rmmounttable2";
|
||||||
|
// Adding mount table entries
|
||||||
|
String[] argv = new String[] {"-add", src1, nsId, dest1};
|
||||||
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
|
argv = new String[] {"-add", src2, nsId, dest2};
|
||||||
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
|
|
||||||
|
stateStore.loadCache(MountTableStoreImpl.class, true);
|
||||||
|
// Ensure mount table entries added successfully
|
||||||
|
GetMountTableEntriesRequest getRequest =
|
||||||
|
GetMountTableEntriesRequest.newInstance(src1);
|
||||||
|
GetMountTableEntriesResponse getResponse =
|
||||||
|
client.getMountTableManager().getMountTableEntries(getRequest);
|
||||||
|
MountTable mountTable = getResponse.getEntries().get(0);
|
||||||
|
getRequest = GetMountTableEntriesRequest.newInstance(src2);
|
||||||
|
getResponse =
|
||||||
|
client.getMountTableManager().getMountTableEntries(getRequest);
|
||||||
|
assertEquals(src1, mountTable.getSourcePath());
|
||||||
|
mountTable = getResponse.getEntries().get(0);
|
||||||
|
assertEquals(src2, mountTable.getSourcePath());
|
||||||
|
// Remove multiple mount table entries
|
||||||
|
argv = new String[] {"-rm", src1, src2};
|
||||||
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
|
|
||||||
|
stateStore.loadCache(MountTableStoreImpl.class, true);
|
||||||
|
// Verify successful deletion of mount table entries
|
||||||
|
getResponse =
|
||||||
|
client.getMountTableManager().getMountTableEntries(getRequest);
|
||||||
|
assertEquals(0, getResponse.getEntries().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -540,6 +570,7 @@ public void testInvalidArgumentMessage() throws Exception {
|
|||||||
public void testSetAndClearQuota() throws Exception {
|
public void testSetAndClearQuota() throws Exception {
|
||||||
String nsId = "ns0";
|
String nsId = "ns0";
|
||||||
String src = "/test-QuotaMounttable";
|
String src = "/test-QuotaMounttable";
|
||||||
|
String src1 = "/test-QuotaMounttable1";
|
||||||
String dest = "/QuotaMounttable";
|
String dest = "/QuotaMounttable";
|
||||||
String[] argv = new String[] {"-add", src, nsId, dest};
|
String[] argv = new String[] {"-add", src, nsId, dest};
|
||||||
assertEquals(0, ToolRunner.run(admin, argv));
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
@ -605,15 +636,42 @@ public void testSetAndClearQuota() throws Exception {
|
|||||||
assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getQuota());
|
assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getQuota());
|
||||||
assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getSpaceQuota());
|
assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getSpaceQuota());
|
||||||
|
|
||||||
|
// verify multi args ClrQuota
|
||||||
|
String dest1 = "/QuotaMounttable1";
|
||||||
|
// Add mount table entries.
|
||||||
|
argv = new String[] {"-add", src, nsId, dest};
|
||||||
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
|
argv = new String[] {"-add", src1, nsId, dest1};
|
||||||
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
|
|
||||||
|
stateStore.loadCache(MountTableStoreImpl.class, true);
|
||||||
|
// SetQuota for the added entries
|
||||||
|
argv = new String[] {"-setQuota", src, "-nsQuota", String.valueOf(nsQuota),
|
||||||
|
"-ssQuota", String.valueOf(ssQuota)};
|
||||||
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
|
argv = new String[] {"-setQuota", src1, "-nsQuota",
|
||||||
|
String.valueOf(nsQuota), "-ssQuota", String.valueOf(ssQuota)};
|
||||||
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
|
stateStore.loadCache(MountTableStoreImpl.class, true);
|
||||||
|
// Clear quota for the added entries
|
||||||
|
argv = new String[] {"-clrQuota", src, src1};
|
||||||
|
assertEquals(0, ToolRunner.run(admin, argv));
|
||||||
|
|
||||||
|
stateStore.loadCache(MountTableStoreImpl.class, true);
|
||||||
|
getResponse =
|
||||||
|
client.getMountTableManager().getMountTableEntries(getRequest);
|
||||||
|
|
||||||
|
// Verify clear quota for the entries
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
mountTable = getResponse.getEntries().get(i);
|
||||||
|
quotaUsage = mountTable.getQuota();
|
||||||
|
assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getQuota());
|
||||||
|
assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getSpaceQuota());
|
||||||
|
}
|
||||||
|
|
||||||
// verify wrong arguments
|
// verify wrong arguments
|
||||||
System.setErr(new PrintStream(err));
|
System.setErr(new PrintStream(err));
|
||||||
argv = new String[] {"-clrQuota", src, "check"};
|
|
||||||
ToolRunner.run(admin, argv);
|
|
||||||
assertTrue(err.toString(),
|
|
||||||
err.toString().contains("Too many arguments, Max=1 argument allowed"));
|
|
||||||
|
|
||||||
argv = new String[] {"-setQuota", src, "check", "check2"};
|
argv = new String[] {"-setQuota", src, "check", "check2"};
|
||||||
err.reset();
|
|
||||||
ToolRunner.run(admin, argv);
|
ToolRunner.run(admin, argv);
|
||||||
assertTrue(err.toString().contains("Invalid argument : check"));
|
assertTrue(err.toString().contains("Invalid argument : check"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user