HDFS-13893. DiskBalancer: no validations for Disk balancer commands. Contributed by Lokesh Jain.
Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org>
This commit is contained in:
parent
98d2065643
commit
272b96d243
@ -21,6 +21,7 @@
|
|||||||
import org.apache.commons.cli.Option;
|
import org.apache.commons.cli.Option;
|
||||||
import org.apache.commons.cli.OptionBuilder;
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
import org.apache.commons.cli.Options;
|
import org.apache.commons.cli.Options;
|
||||||
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.conf.Configured;
|
import org.apache.hadoop.conf.Configured;
|
||||||
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
||||||
@ -37,6 +38,7 @@
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DiskBalancer is a tool that can be used to ensure that data is spread evenly
|
* 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 {
|
|||||||
public int run(String[] args) throws Exception {
|
public int run(String[] args) throws Exception {
|
||||||
Options opts = getOpts();
|
Options opts = getOpts();
|
||||||
CommandLine cmd = parseArgs(args, opts);
|
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);
|
return dispatch(cmd, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
@ -384,6 +385,16 @@ private String runAndVerifyPlan(
|
|||||||
return planFileFullName;
|
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 basic report */
|
||||||
@Test(timeout = 60000)
|
@Test(timeout = 60000)
|
||||||
public void testReportSimple() throws Exception {
|
public void testReportSimple() throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user