This is an automated email from the ASF dual-hosted git repository.
weichiu pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 272b96d HDFS-13893. DiskBalancer: no validations for Disk balancer
commands. Contributed by Lokesh Jain.
272b96d is described below
commit 272b96d243383d9f50241d48cb070f638243bc9c
Author: Lokesh Jain <[email protected]>
AuthorDate: Thu Jun 20 20:22:14 2019 -0700
HDFS-13893. DiskBalancer: no validations for Disk balancer commands.
Contributed by Lokesh Jain.
Signed-off-by: Wei-Chiu Chuang <[email protected]>
---
.../java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java | 8 ++++++++
.../server/diskbalancer/command/TestDiskBalancerCommand.java | 11 +++++++++++
2 files changed, 19 insertions(+)
diff --git
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java
index 34bd68b..980da67a 100644
---
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java
+++
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java
@@ -21,6 +21,7 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
+import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hdfs.HdfsConfiguration;
@@ -37,6 +38,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.PrintStream;
+import java.util.Arrays;
/**
* DiskBalancer is a tool that can be used to ensure that data is spread evenly
@@ -191,6 +193,12 @@ public class DiskBalancerCLI extends Configured implements
Tool {
public int run(String[] args) throws Exception {
Options opts = getOpts();
CommandLine cmd = parseArgs(args, opts);
+ String[] cmdArgs = cmd.getArgs();
+ if (cmdArgs.length > 2) {
+ throw new HadoopIllegalArgumentException(
+ "Invalid or extra Arguments: " + Arrays
+ .toString(Arrays.copyOfRange(cmdArgs, 2, cmdArgs.length)));
+ }
return dispatch(cmd, opts);
}
diff --git
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
index f2e998e..e662fa1 100644
---
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
+++
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
@@ -44,6 +44,7 @@ import java.util.List;
import java.util.Scanner;
import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
@@ -384,6 +385,16 @@ public class TestDiskBalancerCommand {
return planFileFullName;
}
+ /* test exception on invalid arguments */
+ @Test(timeout = 60000)
+ public void testExceptionOnInvalidArguments() throws Exception {
+ final String cmdLine = "hdfs diskbalancer random1 -report random2 random3";
+ thrown.expect(HadoopIllegalArgumentException.class);
+ thrown.expectMessage(
+ "Invalid or extra Arguments: [random1, random2, random3]");
+ runCommand(cmdLine);
+ }
+
/* test basic report */
@Test(timeout = 60000)
public void testReportSimple() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]