HDFS-12948. DiskBalancer report command top option should only take positive numeric values. Contributed by Shashikant Banerjee.
This commit is contained in:
parent
7a55044803
commit
2a48b3594c
|
@ -501,7 +501,8 @@ public abstract class Command extends Configured implements Closeable {
|
|||
* Parse top number of nodes to be processed.
|
||||
* @return top number of nodes to be processed.
|
||||
*/
|
||||
protected int parseTopNodes(final CommandLine cmd, final StrBuilder result) {
|
||||
protected int parseTopNodes(final CommandLine cmd, final StrBuilder result)
|
||||
throws IllegalArgumentException {
|
||||
String outputLine = "";
|
||||
int nodes = 0;
|
||||
final String topVal = cmd.getOptionValue(DiskBalancerCLI.TOP);
|
||||
|
@ -523,6 +524,10 @@ public abstract class Command extends Configured implements Closeable {
|
|||
result.appendln(outputLine);
|
||||
nodes = getDefaultTop();
|
||||
}
|
||||
if (nodes <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Top limit input should be a positive numeric value");
|
||||
}
|
||||
}
|
||||
|
||||
return Math.min(nodes, cluster.getNodes().size());
|
||||
|
|
|
@ -100,7 +100,7 @@ public class ReportCommand extends Command {
|
|||
}
|
||||
|
||||
private void handleTopReport(final CommandLine cmd, final StrBuilder result,
|
||||
final String nodeFormat) {
|
||||
final String nodeFormat) throws IllegalArgumentException {
|
||||
Collections.sort(getCluster().getNodes(), Collections.reverseOrder());
|
||||
|
||||
/* extract value that identifies top X DataNode(s) */
|
||||
|
|
|
@ -244,6 +244,15 @@ public class TestDiskBalancerCommand {
|
|||
|
||||
}
|
||||
|
||||
/* test basic report with negative top limit */
|
||||
@Test(timeout = 60000)
|
||||
public void testReportWithNegativeTopLimit()
|
||||
throws Exception {
|
||||
final String cmdLine = "hdfs diskbalancer -report -top -32";
|
||||
thrown.expect(java.lang.IllegalArgumentException.class);
|
||||
thrown.expectMessage("Top limit input should be a positive numeric value");
|
||||
runCommand(cmdLine);
|
||||
}
|
||||
/* test less than 64 DataNode(s) as total, e.g., -report -top 32 */
|
||||
@Test(timeout = 60000)
|
||||
public void testReportLessThanTotal() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue