HDFS-10540. Diskbalancer: The CLI error message for disk balancer is not enabled is not clear. Contributed by Anu Engineer.

This commit is contained in:
Anu Engineer 2016-06-17 23:25:26 -07:00 committed by Arpit Agarwal
parent 3225c24e0e
commit cb68e5b3bd
3 changed files with 28 additions and 38 deletions

View File

@ -256,6 +256,8 @@ public class DiskBalancer {
} }
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(pathMap); return mapper.writeValueAsString(pathMap);
} catch (DiskBalancerException ex) {
throw ex;
} catch (IOException e) { } catch (IOException e) {
throw new DiskBalancerException("Internal error, Unable to " + throw new DiskBalancerException("Internal error, Unable to " +
"create JSON string.", e, "create JSON string.", e,

View File

@ -171,7 +171,7 @@ public abstract class Command extends Configured {
diskBalancerLogs = new Path(path); diskBalancerLogs = new Path(path);
} }
if (fs.exists(diskBalancerLogs)) { if (fs.exists(diskBalancerLogs)) {
LOG.error("Another Diskbalancer instance is running ? - Target " + LOG.debug("Another Diskbalancer instance is running ? - Target " +
"Directory already exists. {}", diskBalancerLogs); "Directory already exists. {}", diskBalancerLogs);
throw new IOException("Another DiskBalancer files already exist at the " + throw new IOException("Another DiskBalancer files already exist at the " +
"target location. " + diskBalancerLogs.toString()); "target location. " + diskBalancerLogs.toString());

View File

@ -36,9 +36,7 @@ import org.apache.hadoop.util.ToolRunner;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.URISyntaxException;
/** /**
* 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
@ -169,7 +167,7 @@ public class DiskBalancer extends Configured implements Tool {
res = ToolRunner.run(shell, argv); res = ToolRunner.run(shell, argv);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error(ex.toString()); LOG.error(ex.toString());
System.exit(1); res = 1;
} }
System.exit(res); System.exit(res);
} }
@ -449,51 +447,41 @@ public class DiskBalancer extends Configured implements Tool {
* @param cmd - CommandLine * @param cmd - CommandLine
* @param opts options of command line * @param opts options of command line
* @param out the output stream used for printing * @param out the output stream used for printing
* @throws IOException
* @throws URISyntaxException
*/ */
private int dispatch(CommandLine cmd, Options opts, final PrintStream out) private int dispatch(CommandLine cmd, Options opts, final PrintStream out)
throws IOException, URISyntaxException { throws Exception {
Command currentCommand = null; Command currentCommand = null;
if (cmd.hasOption(DiskBalancer.PLAN)) {
currentCommand = new PlanCommand(getConf());
}
try { if (cmd.hasOption(DiskBalancer.EXECUTE)) {
currentCommand = new ExecuteCommand(getConf());
}
if (cmd.hasOption(DiskBalancer.PLAN)) { if (cmd.hasOption(DiskBalancer.QUERY)) {
currentCommand = new PlanCommand(getConf()); currentCommand = new QueryCommand(getConf());
} }
if (cmd.hasOption(DiskBalancer.EXECUTE)) { if (cmd.hasOption(DiskBalancer.CANCEL)) {
currentCommand = new ExecuteCommand(getConf()); currentCommand = new CancelCommand(getConf());
} }
if (cmd.hasOption(DiskBalancer.QUERY)) { if (cmd.hasOption(DiskBalancer.REPORT)) {
currentCommand = new QueryCommand(getConf()); currentCommand = new ReportCommand(getConf(), out);
} }
if (cmd.hasOption(DiskBalancer.CANCEL)) { if (cmd.hasOption(DiskBalancer.HELP)) {
currentCommand = new CancelCommand(getConf()); currentCommand = new HelpCommand(getConf());
} }
if (cmd.hasOption(DiskBalancer.REPORT)) { // Invoke main help here.
currentCommand = new ReportCommand(getConf(), out); if (currentCommand == null) {
} new HelpCommand(getConf()).execute(null);
if (cmd.hasOption(DiskBalancer.HELP)) {
currentCommand = new HelpCommand(getConf());
}
// Invoke Main help here.
if (currentCommand == null) {
new HelpCommand(getConf()).execute(null);
return 1;
}
currentCommand.execute(cmd);
} catch (Exception ex) {
System.err.printf(ex.getMessage());
return 1; return 1;
} }
currentCommand.execute(cmd);
return 0; return 0;
} }
} }