Skip to content

Commit 272b96d

Browse files
lokeshj1703jojochuang
authored andcommitted
HDFS-13893. DiskBalancer: no validations for Disk balancer commands. Contributed by Lokesh Jain.
Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org>
1 parent 98d2065 commit 272b96d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.commons.cli.Option;
2222
import org.apache.commons.cli.OptionBuilder;
2323
import org.apache.commons.cli.Options;
24+
import org.apache.hadoop.HadoopIllegalArgumentException;
2425
import org.apache.hadoop.conf.Configuration;
2526
import org.apache.hadoop.conf.Configured;
2627
import org.apache.hadoop.hdfs.HdfsConfiguration;
@@ -37,6 +38,7 @@
3738
import org.slf4j.LoggerFactory;
3839

3940
import java.io.PrintStream;
41+
import java.util.Arrays;
4042

4143
/**
4244
* DiskBalancer is a tool that can be used to ensure that data is spread evenly
@@ -191,6 +193,12 @@ public static void main(String[] argv) throws Exception {
191193
public int run(String[] args) throws Exception {
192194
Options opts = getOpts();
193195
CommandLine cmd = parseArgs(args, opts);
196+
String[] cmdArgs = cmd.getArgs();
197+
if (cmdArgs.length > 2) {
198+
throw new HadoopIllegalArgumentException(
199+
"Invalid or extra Arguments: " + Arrays
200+
.toString(Arrays.copyOfRange(cmdArgs, 2, cmdArgs.length)));
201+
}
194202
return dispatch(cmd, opts);
195203
}
196204

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Scanner;
4545

4646
import org.apache.commons.lang3.StringUtils;
47+
import org.apache.hadoop.HadoopIllegalArgumentException;
4748
import org.apache.hadoop.conf.Configuration;
4849
import org.apache.hadoop.fs.FileSystem;
4950
import org.apache.hadoop.fs.Path;
@@ -384,6 +385,16 @@ private String runAndVerifyPlan(
384385
return planFileFullName;
385386
}
386387

388+
/* test exception on invalid arguments */
389+
@Test(timeout = 60000)
390+
public void testExceptionOnInvalidArguments() throws Exception {
391+
final String cmdLine = "hdfs diskbalancer random1 -report random2 random3";
392+
thrown.expect(HadoopIllegalArgumentException.class);
393+
thrown.expectMessage(
394+
"Invalid or extra Arguments: [random1, random2, random3]");
395+
runCommand(cmdLine);
396+
}
397+
387398
/* test basic report */
388399
@Test(timeout = 60000)
389400
public void testReportSimple() throws Exception {

0 commit comments

Comments
 (0)