HDFS-10402. DiskBalancer: Add QueryStatus command. (Contributed by Anu Engineer)
This commit is contained in:
parent
5df2d2b8fd
commit
9e5fcb5e40
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.hadoop.hdfs.server.diskbalancer.command;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol;
|
||||||
|
import org.apache.hadoop.hdfs.server.datanode.DiskBalancerWorkStatus;
|
||||||
|
import org.apache.hadoop.hdfs.server.diskbalancer.DiskBalancerException;
|
||||||
|
import org.apache.hadoop.hdfs.tools.DiskBalancer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current status of disk balancer command.
|
||||||
|
*/
|
||||||
|
public class QueryCommand extends Command {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs QueryCommand.
|
||||||
|
*
|
||||||
|
* @param conf - Configuration.
|
||||||
|
*/
|
||||||
|
public QueryCommand(Configuration conf) {
|
||||||
|
super(conf);
|
||||||
|
addValidCommandParameters(DiskBalancer.QUERY, "Queries the status of disk" +
|
||||||
|
" plan running on a given datanode.");
|
||||||
|
addValidCommandParameters(DiskBalancer.VERBOSE, "Prints verbose results.");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Executes the Client Calls.
|
||||||
|
*
|
||||||
|
* @param cmd - CommandLine
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void execute(CommandLine cmd) throws Exception {
|
||||||
|
LOG.info("Executing \"query plan\" command.");
|
||||||
|
Preconditions.checkState(cmd.hasOption(DiskBalancer.QUERY));
|
||||||
|
verifyCommandOptions(DiskBalancer.QUERY, cmd);
|
||||||
|
String nodeName = cmd.getOptionValue(DiskBalancer.QUERY);
|
||||||
|
Preconditions.checkNotNull(nodeName);
|
||||||
|
ClientDatanodeProtocol dataNode = getDataNodeProxy(nodeName);
|
||||||
|
try {
|
||||||
|
DiskBalancerWorkStatus workStatus = dataNode.queryDiskBalancerPlan();
|
||||||
|
System.out.printf("Plan ID: %s Result: %s%n", workStatus.getPlanID(),
|
||||||
|
workStatus.getResult().toString());
|
||||||
|
|
||||||
|
if(cmd.hasOption(DiskBalancer.VERBOSE)) {
|
||||||
|
System.out.printf("%s", workStatus.currentStateString());
|
||||||
|
}
|
||||||
|
} catch (DiskBalancerException ex) {
|
||||||
|
LOG.error("Query plan failed. ex: {}", ex);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets extended help for this command.
|
||||||
|
*
|
||||||
|
* @return Help Message
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected String getHelp() {
|
||||||
|
return "Gets the status of disk balancing on a given node";
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ import org.apache.hadoop.hdfs.HdfsConfiguration;
|
||||||
import org.apache.hadoop.hdfs.server.diskbalancer.command.Command;
|
import org.apache.hadoop.hdfs.server.diskbalancer.command.Command;
|
||||||
import org.apache.hadoop.hdfs.server.diskbalancer.command.ExecuteCommand;
|
import org.apache.hadoop.hdfs.server.diskbalancer.command.ExecuteCommand;
|
||||||
import org.apache.hadoop.hdfs.server.diskbalancer.command.PlanCommand;
|
import org.apache.hadoop.hdfs.server.diskbalancer.command.PlanCommand;
|
||||||
|
import org.apache.hadoop.hdfs.server.diskbalancer.command.QueryCommand;
|
||||||
import org.apache.hadoop.util.Tool;
|
import org.apache.hadoop.util.Tool;
|
||||||
import org.apache.hadoop.util.ToolRunner;
|
import org.apache.hadoop.util.ToolRunner;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -100,6 +101,11 @@ public class DiskBalancer extends Configured implements Tool {
|
||||||
*/
|
*/
|
||||||
public static final String VERBOSE = "v";
|
public static final String VERBOSE = "v";
|
||||||
public static final int PLAN_VERSION = 1;
|
public static final int PLAN_VERSION = 1;
|
||||||
|
/**
|
||||||
|
* Reports the status of disk balancer operation.
|
||||||
|
*/
|
||||||
|
public static final String QUERY = "query";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template for the Before File. It is node.before.json.
|
* Template for the Before File. It is node.before.json.
|
||||||
*/
|
*/
|
||||||
|
@ -160,6 +166,8 @@ public class DiskBalancer extends Configured implements Tool {
|
||||||
private Options getOpts() {
|
private Options getOpts() {
|
||||||
Options opts = new Options();
|
Options opts = new Options();
|
||||||
addPlanCommands(opts);
|
addPlanCommands(opts);
|
||||||
|
addExecuteCommands(opts);
|
||||||
|
addQueryCommands(opts);
|
||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +223,16 @@ public class DiskBalancer extends Configured implements Tool {
|
||||||
opt.addOption(execute);
|
opt.addOption(execute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds query command options.
|
||||||
|
* @param opt Options
|
||||||
|
*/
|
||||||
|
private void addQueryCommands(Options opt) {
|
||||||
|
Option query = new Option(QUERY, true, "Queries the disk balancer " +
|
||||||
|
"status of a given datanode. e.g. -query <nodename>");
|
||||||
|
opt.addOption(query);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function parses all command line arguments and returns the appropriate
|
* This function parses all command line arguments and returns the appropriate
|
||||||
* values.
|
* values.
|
||||||
|
@ -249,6 +267,10 @@ public class DiskBalancer extends Configured implements Tool {
|
||||||
currentCommand = new ExecuteCommand(getConf());
|
currentCommand = new ExecuteCommand(getConf());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(cmd.hasOption(DiskBalancer.QUERY)) {
|
||||||
|
currentCommand = new QueryCommand(getConf());
|
||||||
|
}
|
||||||
|
|
||||||
if(currentCommand == null) {
|
if(currentCommand == null) {
|
||||||
HelpFormatter helpFormatter = new HelpFormatter();
|
HelpFormatter helpFormatter = new HelpFormatter();
|
||||||
helpFormatter.printHelp(80, "hdfs diskbalancer -uri [args]",
|
helpFormatter.printHelp(80, "hdfs diskbalancer -uri [args]",
|
||||||
|
|
Loading…
Reference in New Issue