HDFS-13843. RBF: Add optional parameter -d for detailed listing of mount points. Contributed by Ayush Saxena.

This commit is contained in:
Ayush Saxena 2019-09-02 07:24:04 +05:30
parent 751b5a1ac8
commit c3abfcefdd
3 changed files with 84 additions and 27 deletions

View File

@ -152,7 +152,7 @@ public class RouterAdmin extends Configured implements Tool {
} else if (cmd.equals("-rm")) { } else if (cmd.equals("-rm")) {
return "\t[-rm <source>]"; return "\t[-rm <source>]";
} else if (cmd.equals("-ls")) { } else if (cmd.equals("-ls")) {
return "\t[-ls <path>]"; return "\t[-ls [-d] <path>]";
} else if (cmd.equals("-getDestination")) { } else if (cmd.equals("-getDestination")) {
return "\t[-getDestination <path>]"; return "\t[-getDestination <path>]";
} else if (cmd.equals("-setQuota")) { } else if (cmd.equals("-setQuota")) {
@ -180,9 +180,9 @@ public class RouterAdmin extends Configured implements Tool {
*/ */
private void validateMax(String[] arg) { private void validateMax(String[] arg) {
if (arg[0].equals("-ls")) { if (arg[0].equals("-ls")) {
if (arg.length > 2) { if (arg.length > 3) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Too many arguments, Max=1 argument allowed"); "Too many arguments, Max=2 argument allowed");
} }
} else if (arg[0].equals("-getDestination")) { } else if (arg[0].equals("-getDestination")) {
if (arg.length > 2) { if (arg.length > 2) {
@ -320,11 +320,7 @@ public class RouterAdmin extends Configured implements Tool {
i++; i++;
} }
} else if ("-ls".equals(cmd)) { } else if ("-ls".equals(cmd)) {
if (argv.length > 1) { listMounts(argv, i);
listMounts(argv[i]);
} else {
listMounts("/");
}
} else if ("-getDestination".equals(cmd)) { } else if ("-getDestination".equals(cmd)) {
getDestination(argv[i]); getDestination(argv[i]);
} else if ("-setQuota".equals(cmd)) { } else if ("-setQuota".equals(cmd)) {
@ -732,7 +728,22 @@ public class RouterAdmin extends Configured implements Tool {
* @param path Path to list. * @param path Path to list.
* @throws IOException If it cannot be listed. * @throws IOException If it cannot be listed.
*/ */
public void listMounts(String path) throws IOException { public void listMounts(String[] argv, int i) throws IOException {
String path;
boolean detail = false;
if (argv.length == 1) {
path = "/";
} else if (argv[i].equals("-d")) { // Check if -d parameter is specified.
detail = true;
if (argv.length == 2) {
path = "/"; // If no path is provide with -ls -d.
} else {
path = argv[++i];
}
} else {
path = argv[i];
}
path = normalizeFileSystemPath(path); path = normalizeFileSystemPath(path);
MountTableManager mountTable = client.getMountTableManager(); MountTableManager mountTable = client.getMountTableManager();
GetMountTableEntriesRequest request = GetMountTableEntriesRequest request =
@ -740,14 +751,20 @@ public class RouterAdmin extends Configured implements Tool {
GetMountTableEntriesResponse response = GetMountTableEntriesResponse response =
mountTable.getMountTableEntries(request); mountTable.getMountTableEntries(request);
List<MountTable> entries = response.getEntries(); List<MountTable> entries = response.getEntries();
printMounts(entries); printMounts(entries, detail);
} }
private static void printMounts(List<MountTable> entries) { private static void printMounts(List<MountTable> entries, boolean detail) {
System.out.println("Mount Table Entries:"); System.out.println("Mount Table Entries:");
System.out.println(String.format( if (detail) {
"%-25s %-25s %-25s %-25s %-25s %-25s", System.out.println(
"Source", "Destinations", "Owner", "Group", "Mode", "Quota/Usage")); String.format("%-25s %-25s %-25s %-25s %-10s %-30s %-10s %-10s %-15s",
"Source", "Destinations", "Owner", "Group", "Mode", "Quota/Usage",
"Order", "ReadOnly", "FaultTolerant"));
} else {
System.out.println(String.format("%-25s %-25s %-25s %-25s %-10s %-30s",
"Source", "Destinations", "Owner", "Group", "Mode", "Quota/Usage"));
}
for (MountTable entry : entries) { for (MountTable entry : entries) {
StringBuilder destBuilder = new StringBuilder(); StringBuilder destBuilder = new StringBuilder();
for (RemoteLocation location : entry.getDestinations()) { for (RemoteLocation location : entry.getDestinations()) {
@ -760,10 +777,20 @@ public class RouterAdmin extends Configured implements Tool {
System.out.print(String.format("%-25s %-25s", entry.getSourcePath(), System.out.print(String.format("%-25s %-25s", entry.getSourcePath(),
destBuilder.toString())); destBuilder.toString()));
System.out.print(String.format(" %-25s %-25s %-25s", System.out.print(String.format(" %-25s %-25s %-10s",
entry.getOwnerName(), entry.getGroupName(), entry.getMode())); entry.getOwnerName(), entry.getGroupName(), entry.getMode()));
System.out.println(String.format(" %-25s", entry.getQuota())); System.out.print(String.format(" %-30s", entry.getQuota()));
if (detail) {
System.out.print(String.format(" %-10s", entry.getDestOrder()));
System.out.print(
String.format(" %-10s", entry.isReadOnly() ? "Read-Only" : ""));
System.out.println(String.format(" %-15s",
entry.isFaultTolerant() ? "Fault-Tolerant" : ""));
}
} }
} }

View File

@ -300,19 +300,22 @@ public class TestRouterAdminCLI {
stateStore.loadCache(MountTableStoreImpl.class, true); stateStore.loadCache(MountTableStoreImpl.class, true);
argv = new String[] {"-ls", src}; argv = new String[] {"-ls", src};
assertEquals(0, ToolRunner.run(admin, argv)); assertEquals(0, ToolRunner.run(admin, argv));
assertTrue(out.toString().contains(src)); String response = out.toString();
assertTrue("Wrong response: " + response, response.contains(src));
// Test with not-normalized src input // Test with not-normalized src input
argv = new String[] {"-ls", srcWithSlash}; argv = new String[] {"-ls", srcWithSlash};
assertEquals(0, ToolRunner.run(admin, argv)); assertEquals(0, ToolRunner.run(admin, argv));
assertTrue(out.toString().contains(src)); response = out.toString();
assertTrue("Wrong response: " + response, response.contains(src));
// Test with wrong number of arguments // Test with wrong number of arguments
argv = new String[] {"-ls", srcWithSlash, "check", "check2"}; argv = new String[] {"-ls", srcWithSlash, "check", "check2"};
System.setErr(new PrintStream(err)); System.setErr(new PrintStream(err));
ToolRunner.run(admin, argv); ToolRunner.run(admin, argv);
assertTrue( response = err.toString();
err.toString().contains("Too many arguments, Max=1 argument allowed")); assertTrue("Wrong response: " + response,
response.contains("Too many arguments, Max=2 argument allowed"));
out.reset(); out.reset();
GetMountTableEntriesRequest getRequest = GetMountTableEntriesRequest GetMountTableEntriesRequest getRequest = GetMountTableEntriesRequest
@ -324,14 +327,41 @@ public class TestRouterAdminCLI {
// mount table under root path. // mount table under root path.
argv = new String[] {"-ls"}; argv = new String[] {"-ls"};
assertEquals(0, ToolRunner.run(admin, argv)); assertEquals(0, ToolRunner.run(admin, argv));
assertTrue(out.toString().contains(src)); response = out.toString();
String outStr = out.toString(); assertTrue("Wrong response: " + response, response.contains(src));
// verify if all the mount table are listed // verify if all the mount table are listed
for(MountTable entry: getResponse.getEntries()) { for (MountTable entry : getResponse.getEntries()) {
assertTrue(outStr.contains(entry.getSourcePath())); assertTrue("Wrong response: " + response,
response.contains(entry.getSourcePath()));
} }
} }
@Test
public void testListWithDetails() throws Exception {
// Create mount entry.
String[] argv = new String[] {"-add", "/testLsWithDetails", "ns0,ns1",
"/dest", "-order", "HASH_ALL", "-readonly", "-faulttolerant"};
assertEquals(0, ToolRunner.run(admin, argv));
System.setOut(new PrintStream(out));
stateStore.loadCache(MountTableStoreImpl.class, true);
// Test list with detail for a mount entry.
argv = new String[] {"-ls", "-d", "/testLsWithDetails"};
assertEquals(0, ToolRunner.run(admin, argv));
String response = out.toString();
assertTrue(response.contains("Read-Only"));
assertTrue(response.contains("Fault-Tolerant"));
out.reset();
// Test list with detail without path.
argv = new String[] {"-ls", "-d"};
assertEquals(0, ToolRunner.run(admin, argv));
response = out.toString();
assertTrue("Wrong response: " + response, response.contains("Read-Only"));
assertTrue("Wrong response: " + response,
response.contains("Fault-Tolerant"));
}
@Test @Test
public void testListNestedMountTable() throws Exception { public void testListNestedMountTable() throws Exception {
String dir1 = "/test-ls"; String dir1 = "/test-ls";
@ -627,7 +657,7 @@ public class TestRouterAdminCLI {
+ " [-faulttolerant true|false] " + " [-faulttolerant true|false] "
+ "[-order HASH|LOCAL|RANDOM|HASH_ALL|SPACE] " + "[-order HASH|LOCAL|RANDOM|HASH_ALL|SPACE] "
+ "-owner <owner> -group <group> -mode <mode>]\n" + "\t[-rm <source>]\n" + "-owner <owner> -group <group> -mode <mode>]\n" + "\t[-rm <source>]\n"
+ "\t[-ls <path>]\n" + "\t[-ls [-d] <path>]\n"
+ "\t[-getDestination <path>]\n" + "\t[-getDestination <path>]\n"
+ "\t[-setQuota <path> -nsQuota <nsQuota> -ssQuota " + "\t[-setQuota <path> -nsQuota <nsQuota> -ssQuota "
+ "<quota in bytes or quota size string>]\n" + "\t[-clrQuota <path>]\n" + "<quota in bytes or quota size string>]\n" + "\t[-clrQuota <path>]\n"

View File

@ -435,7 +435,7 @@ Usage:
[-add <source> <nameservice1, nameservice2, ...> <destination> [-readonly] [-faulttolerant] [-order HASH|LOCAL|RANDOM|HASH_ALL] -owner <owner> -group <group> -mode <mode>] [-add <source> <nameservice1, nameservice2, ...> <destination> [-readonly] [-faulttolerant] [-order HASH|LOCAL|RANDOM|HASH_ALL] -owner <owner> -group <group> -mode <mode>]
[-update <source> [<nameservice1, nameservice2, ...> <destination>] [-readonly true|false] [-faulttolerant true|false] [-order HASH|LOCAL|RANDOM|HASH_ALL] -owner <owner> -group <group> -mode <mode>] [-update <source> [<nameservice1, nameservice2, ...> <destination>] [-readonly true|false] [-faulttolerant true|false] [-order HASH|LOCAL|RANDOM|HASH_ALL] -owner <owner> -group <group> -mode <mode>]
[-rm <source>] [-rm <source>]
[-ls <path>] [-ls [-d] <path>]
[-getDestination <path>] [-getDestination <path>]
[-setQuota <path> -nsQuota <nsQuota> -ssQuota <quota in bytes or quota size string>] [-setQuota <path> -nsQuota <nsQuota> -ssQuota <quota in bytes or quota size string>]
[-clrQuota <path>] [-clrQuota <path>]
@ -450,7 +450,7 @@ Usage:
| `-add` *source* *nameservices* *destination* | Add a mount table entry or update if it exists. | | `-add` *source* *nameservices* *destination* | Add a mount table entry or update if it exists. |
| `-update` *source* *nameservices* *destination* | Update a mount table entry attribures. | | `-update` *source* *nameservices* *destination* | Update a mount table entry attribures. |
| `-rm` *source* | Remove mount point of specified path. | | `-rm` *source* | Remove mount point of specified path. |
| `-ls` *path* | List mount points under specified path. | | `-ls` `[-d]` *path* | List mount points under specified path. Specify -d parameter to get detailed listing.|
| `-getDestination` *path* | Get the subcluster where a file is or should be created. | | `-getDestination` *path* | Get the subcluster where a file is or should be created. |
| `-setQuota` *path* `-nsQuota` *nsQuota* `-ssQuota` *ssQuota* | Set quota for specified path. See [HDFS Quotas Guide](./HdfsQuotaAdminGuide.html) for the quota detail. | | `-setQuota` *path* `-nsQuota` *nsQuota* `-ssQuota` *ssQuota* | Set quota for specified path. See [HDFS Quotas Guide](./HdfsQuotaAdminGuide.html) for the quota detail. |
| `-clrQuota` *path* | Clear quota of given mount point. See [HDFS Quotas Guide](./HdfsQuotaAdminGuide.html) for the quota detail. | | `-clrQuota` *path* | Clear quota of given mount point. See [HDFS Quotas Guide](./HdfsQuotaAdminGuide.html) for the quota detail. |