From 0bf285413f8fcaadbb2d5817fe8090f5fb0d37d9 Mon Sep 17 00:00:00 2001 From: Harsh J Date: Thu, 27 Aug 2015 16:22:48 +0530 Subject: [PATCH] HDFS-2390. dfsadmin -setBalancerBandwidth does not validate -ve value. Contributed by Gautam Gopalakrishnan. --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java | 5 +++++ .../org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 42eed140de..29ecf7b987 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -359,6 +359,9 @@ Release 2.8.0 - UNRELEASED IMPROVEMENTS + HDFS-2390. dfsadmin -setBalancerBandwidth does not validate -ve value + (Gautam Gopalakrishnan via harsh) + HDFS-8821. Explain message "Operation category X is not supported in state standby" (Gautam Gopalakrishnan via harsh) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java index 014637bbc5..298d55e6b1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java @@ -851,6 +851,11 @@ public int setBalancerBandwidth(String[] argv, int idx) throws IOException { return exitCode; } + if (bandwidth < 0) { + System.err.println("Bandwidth should be a non-negative integer"); + return exitCode; + } + FileSystem fs = getFS(); if (!(fs instanceof DistributedFileSystem)) { System.err.println("FileSystem is " + fs.getUri()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java index 6859e436a4..a6c0924b4f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java @@ -192,6 +192,13 @@ public void testSetBalancerBandwidth() throws Exception { assertOutputMatches(message + newLine + message + newLine); } + @Test (timeout = 30000) + public void testSetNegativeBalancerBandwidth() throws Exception { + setUpHaCluster(false); + int exitCode = admin.run(new String[] {"-setBalancerBandwidth", "-10"}); + assertEquals("Negative bandwidth value must fail the command", -1, exitCode); + } + @Test (timeout = 30000) public void testMetaSave() throws Exception { setUpHaCluster(false);