File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
hadoop-hdfs-project/hadoop-hdfs/src
main/java/org/apache/hadoop/hdfs/tools
test/java/org/apache/hadoop/hdfs/server/diskbalancer/command Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 2121import org .apache .commons .cli .Option ;
2222import org .apache .commons .cli .OptionBuilder ;
2323import org .apache .commons .cli .Options ;
24+ import org .apache .hadoop .HadoopIllegalArgumentException ;
2425import org .apache .hadoop .conf .Configuration ;
2526import org .apache .hadoop .conf .Configured ;
2627import org .apache .hadoop .hdfs .HdfsConfiguration ;
3738import org .slf4j .LoggerFactory ;
3839
3940import 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
Original file line number Diff line number Diff line change 4444import java .util .Scanner ;
4545
4646import org .apache .commons .lang3 .StringUtils ;
47+ import org .apache .hadoop .HadoopIllegalArgumentException ;
4748import org .apache .hadoop .conf .Configuration ;
4849import org .apache .hadoop .fs .FileSystem ;
4950import 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 {
You can’t perform that action at this time.
0 commit comments