hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [40/50] hadoop git commit: HDFS-12009. Accept human-friendly units in dfsadmin -setBalancerBandwidth and -setQuota. Contributed by Andrew Wang.
Date Mon, 26 Jun 2017 12:50:14 GMT
HDFS-12009. Accept human-friendly units in dfsadmin -setBalancerBandwidth and -setQuota. Contributed
by Andrew Wang.


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

Branch: refs/heads/HADOOP-13345
Commit: 68dc7c24050951f4709f7fe5363e11a003cf53eb
Parents: 740204b
Author: Xiao Chen <xiao@apache.org>
Authored: Thu Jun 22 19:56:43 2017 -0700
Committer: Xiao Chen <xiao@apache.org>
Committed: Thu Jun 22 19:57:54 2017 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hdfs/tools/DFSAdmin.java  |  5 +--
 .../java/org/apache/hadoop/hdfs/TestQuota.java  | 13 +++++--
 .../apache/hadoop/hdfs/tools/TestDFSAdmin.java  | 36 ++++++++++++++++++++
 3 files changed, 50 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/68dc7c24/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
index 70509d4..b771ff0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
@@ -195,7 +195,8 @@ public class DFSAdmin extends FsShell {
       super(conf);
       CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE);
       List<String> parameters = c.parse(args, pos);
-      this.quota = Long.parseLong(parameters.remove(0));
+      this.quota =
+          StringUtils.TraditionalBinaryPrefix.string2long(parameters.remove(0));
       this.args = parameters.toArray(new String[parameters.size()]);
     }
     
@@ -938,7 +939,7 @@ public class DFSAdmin extends FsShell {
     int exitCode = -1;
 
     try {
-      bandwidth = Long.parseLong(argv[idx]);
+      bandwidth = StringUtils.TraditionalBinaryPrefix.string2long(argv[idx]);
     } catch (NumberFormatException nfe) {
       System.err.println("NumberFormatException: " + nfe.getMessage());
       System.err.println("Usage: hdfs dfsadmin"

http://git-wip-us.apache.org/repos/asf/hadoop/blob/68dc7c24/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
index 4bfb62c..dd1d538 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
@@ -184,11 +184,20 @@ public class TestQuota {
     final short replication = 5;
     final long spaceQuota = fileLen * replication * 15 / 8;
 
-    // 1: create a directory test and set its quota to be 3
+    // 1: create a test directory
     final Path parent = new Path(dir, "test");
     assertTrue(dfs.mkdirs(parent));
-    String[] args = new String[]{"-setQuota", "3", parent.toString()};
+
+    // Try setting name quota with suffixes
+    String[] args;
+    args = new String[]{"-setQuota", "3K", parent.toString()};
+    runCommand(admin, args, false);
+    args = new String[]{"-setQuota", "3m", parent.toString()};
     runCommand(admin, args, false);
+    // Set the final name quota to 3
+    args = new String[]{"-setQuota", "3", parent.toString()};
+    runCommand(admin, args, false);
+
 
     //try setting space quota with a 'binary prefix'
     runCommand(admin, false, "-setSpaceQuota", "2t", parent.toString());

http://git-wip-us.apache.org/repos/asf/hadoop/blob/68dc7c24/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
index 2ef45e7..ed43dc0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java
@@ -696,4 +696,40 @@ public class TestDFSAdmin {
         client.getDatanodeStorageReport(DatanodeReportType.DEAD).length);
     assertEquals(numCorruptBlocks, client.getCorruptBlocksCount());
   }
+
+  @Test
+  public void testSetBalancerBandwidth() throws Exception {
+    redirectStream();
+
+    final DFSAdmin dfsAdmin = new DFSAdmin(conf);
+    String outStr;
+
+    // Test basic case: 10000
+    assertEquals(0, ToolRunner.run(dfsAdmin,
+        new String[]{"-setBalancerBandwidth", "10000"}));
+    outStr = scanIntoString(out);
+    assertTrue("Did not set bandwidth!", outStr.contains("Balancer " +
+        "bandwidth is set to 10000"));
+
+    // Test parsing with units
+    resetStream();
+    assertEquals(0, ToolRunner.run(dfsAdmin,
+        new String[]{"-setBalancerBandwidth", "10m"}));
+    outStr = scanIntoString(out);
+    assertTrue("Did not set bandwidth!", outStr.contains("Balancer " +
+        "bandwidth is set to 10485760"));
+
+    resetStream();
+    assertEquals(0, ToolRunner.run(dfsAdmin,
+        new String[]{"-setBalancerBandwidth", "10k"}));
+    outStr = scanIntoString(out);
+    assertTrue("Did not set bandwidth!", outStr.contains("Balancer " +
+        "bandwidth is set to 10240"));
+
+    // Test negative numbers
+    assertEquals(-1, ToolRunner.run(dfsAdmin,
+        new String[]{"-setBalancerBandwidth", "-10000"}));
+    assertEquals(-1, ToolRunner.run(dfsAdmin,
+        new String[]{"-setBalancerBandwidth", "-10m"}));
+  }
 }
\ No newline at end of file


---------------------------------------------------------------------
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