hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject [33/37] hadoop git commit: HDFS-13906. RBF: Add multiple paths for dfsrouteradmin 'rm' and 'clrquota' commands. Contributed by Ayush Saxena.
Date Wed, 07 Nov 2018 02:09:31 GMT
HDFS-13906. RBF: Add multiple paths for dfsrouteradmin 'rm' and 'clrquota' commands. Contributed
by Ayush Saxena.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/22c50844
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/22c50844
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/22c50844

Branch: refs/heads/HDFS-13891
Commit: 22c50844d691dc2fec40db6b452218bf39878b9f
Parents: ba1f9d6
Author: Vinayakumar B <vinayakumarb@apache.org>
Authored: Fri Oct 12 17:19:55 2018 +0530
Committer: Brahma Reddy Battula <brahma@apache.org>
Committed: Wed Nov 7 07:37:52 2018 +0530

----------------------------------------------------------------------
 .../hdfs/tools/federation/RouterAdmin.java      | 102 ++++++++++---------
 .../federation/router/TestRouterAdminCLI.java   |  82 ++++++++++++---
 2 files changed, 122 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/22c50844/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java
index 1aefe4f..4a9cc7a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java
@@ -151,17 +151,7 @@ public class RouterAdmin extends Configured implements Tool {
    * @param arg List of of command line parameters.
    */
   private void validateMax(String[] arg) {
-    if (arg[0].equals("-rm")) {
-      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[0].equals("-ls")) {
       if (arg.length > 2) {
         throw new IllegalArgumentException(
             "Too many arguments, Max=1 argument allowed");
@@ -183,63 +173,63 @@ public class RouterAdmin extends Configured implements Tool {
     }
   }
 
-  @Override
-  public int run(String[] argv) throws Exception {
-    if (argv.length < 1) {
-      System.err.println("Not enough parameters specified");
-      printUsage();
-      return -1;
-    }
-
-    int exitCode = -1;
-    int i = 0;
-    String cmd = argv[i++];
-
-    // Verify that we have enough command line parameters
+  /**
+   * 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) {
-        System.err.println("Not enough parameters specified for cmd " + cmd);
-        printUsage(cmd);
-        return exitCode;
+        return false;
       }
     } else if ("-update".equals(cmd)) {
       if (argv.length < 4) {
-        System.err.println("Not enough parameters specified for cmd " + cmd);
-        printUsage(cmd);
-        return exitCode;
+        return false;
       }
     } else if ("-rm".equals(cmd)) {
       if (argv.length < 2) {
-        System.err.println("Not enough parameters specified for cmd " + cmd);
-        printUsage(cmd);
-        return exitCode;
+        return false;
       }
     } else if ("-setQuota".equals(cmd)) {
       if (argv.length < 4) {
-        System.err.println("Not enough parameters specified for cmd " + cmd);
-        printUsage(cmd);
-        return exitCode;
+        return false;
       }
     } else if ("-clrQuota".equals(cmd)) {
       if (argv.length < 2) {
-        System.err.println("Not enough parameters specified for cmd " + cmd);
-        printUsage(cmd);
-        return exitCode;
+        return false;
       }
     } else if ("-safemode".equals(cmd)) {
       if (argv.length < 2) {
-        System.err.println("Not enough parameters specified for cmd " + cmd);
-        printUsage(cmd);
-        return exitCode;
+        return false;
       }
     } else if ("-nameservice".equals(cmd)) {
       if (argv.length < 3) {
-        System.err.println("Not enough parameters specificed for cmd " + cmd);
-        printUsage(cmd);
-        return exitCode;
+        return false;
       }
     }
+    return true;
+  }
+
+  @Override
+  public int run(String[] argv) throws Exception {
+    if (argv.length < 1) {
+      System.err.println("Not enough parameters specified");
+      printUsage();
+      return -1;
+    }
+
+    int exitCode = -1;
+    int i = 0;
+    String cmd = argv[i++];
 
+    // Verify that we have enough command line parameters
+    if (!validateMin(argv)) {
+      System.err.println("Not enough parameters specificed for cmd " + cmd);
+      printUsage(cmd);
+      return exitCode;
+    }
     // Initialize RouterClient
     try {
       String address = getConf().getTrimmed(
@@ -273,8 +263,17 @@ public class RouterAdmin extends Configured implements Tool {
           exitCode = -1;
         }
       } else if ("-rm".equals(cmd)) {
-        if (removeMount(argv[i])) {
-          System.out.println("Successfully removed mount point " + argv[i]);
+        while (i < argv.length) {
+          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)) {
         if (argv.length > 1) {
@@ -288,9 +287,12 @@ public class RouterAdmin extends Configured implements Tool {
               "Successfully set quota for mount point " + argv[i]);
         }
       } else if ("-clrQuota".equals(cmd)) {
-        if (clrQuota(argv[i])) {
-          System.out.println(
-              "Successfully clear quota for mount point " + argv[i]);
+        while (i < argv.length) {
+          if (clrQuota(argv[i])) {
+            System.out
+                .println("Successfully clear quota for mount point " + argv[i]);
+            i++;
+          }
         }
       } else if ("-safemode".equals(cmd)) {
         manageSafeMode(argv[i]);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/22c50844/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
index d968c60..65fe054 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
@@ -342,13 +342,43 @@ public class TestRouterAdminCLI {
     assertEquals(0, ToolRunner.run(admin, argv));
     assertTrue(out.toString().contains(
         "Cannot remove mount point " + invalidPath));
+  }
 
-    // test wrong number of arguments
-    System.setErr(new PrintStream(err));
-    argv = new String[] {"-rm", src, "check" };
-    ToolRunner.run(admin, argv);
-    assertTrue(err.toString()
-        .contains("Too many arguments, Max=1 argument allowed"));
+  @Test
+  public void testMultiArgsRemoveMountTable() throws Exception {
+    String nsId = "ns0";
+    String src1 = "/test-rmmounttable1";
+    String src2 = "/test-rmmounttable2";
+    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
@@ -540,6 +570,7 @@ public class TestRouterAdminCLI {
   public void testSetAndClearQuota() throws Exception {
     String nsId = "ns0";
     String src = "/test-QuotaMounttable";
+    String src1 = "/test-QuotaMounttable1";
     String dest = "/QuotaMounttable";
     String[] argv = new String[] {"-add", src, nsId, dest};
     assertEquals(0, ToolRunner.run(admin, argv));
@@ -605,15 +636,42 @@ public class TestRouterAdminCLI {
     assertEquals(HdfsConstants.QUOTA_RESET, quotaUsage.getQuota());
     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
     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"};
-    err.reset();
     ToolRunner.run(admin, argv);
     assertTrue(err.toString().contains("Invalid argument : check"));
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message