Skip to content

Commit

Permalink
HBASE-20358 Fix bin/hbase thrift usage text
Browse files Browse the repository at this point in the history
  • Loading branch information
meszibalu authored and saintstack committed Apr 11, 2018
1 parent 072c503 commit 1ad09d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

package org.apache.hadoop.hbase.thrift;

import java.util.Arrays;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
Expand All @@ -33,9 +30,9 @@
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser;
import org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser;
import org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter;
import org.apache.hbase.thirdparty.org.apache.commons.cli.Options;
import org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser;

/**
* ThriftServer- this class starts up a Thrift server which implements the
Expand Down Expand Up @@ -78,7 +75,8 @@ private static void printUsageAndExit(Options options, int exitCode)
throws ExitCodeException {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("Thrift", null, options,
"To start the Thrift server run 'hbase-daemon.sh start thrift'\n" +
"To start the Thrift server run 'hbase-daemon.sh start thrift' or " +
"'hbase thrift'\n" +
"To shutdown the thrift server run 'hbase-daemon.sh stop " +
"thrift' or send a kill signal to the thrift server pid",
true);
Expand Down Expand Up @@ -144,20 +142,10 @@ private void processOptions(final String[] args) throws Exception {

options.addOptionGroup(ImplType.createOptionGroup());

CommandLineParser parser = new PosixParser();
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);

// This is so complicated to please both bin/hbase and bin/hbase-daemon.
// hbase-daemon provides "start" and "stop" arguments
// hbase should print the help if no argument is provided
List<String> commandLine = Arrays.asList(args);
boolean stop = commandLine.contains("stop");
boolean start = commandLine.contains("start");
boolean invalidStartStop = (start && stop) || (!start && !stop);
if (cmd.hasOption("help") || invalidStartStop) {
if (invalidStartStop) {
LOG.error("Exactly one of 'start' and 'stop' has to be specified");
}
if (cmd.hasOption("help")) {
printUsageAndExit(options, 1);
}

Expand Down Expand Up @@ -195,7 +183,7 @@ private void processOptions(final String[] args) throws Exception {
conf, TBoundedThreadPoolServer.THREAD_KEEP_ALIVE_TIME_SEC_CONF_KEY);
optionToConf(cmd, READ_TIMEOUT_OPTION, conf,
ThriftServerRunner.THRIFT_SERVER_SOCKET_READ_TIMEOUT_KEY);

// Set general thrift server options
boolean compact = cmd.hasOption(COMPACT_OPTION) ||
conf.getBoolean(ThriftServerRunner.COMPACT_CONF_KEY, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.security.PrivilegedAction;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -81,12 +80,12 @@
import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine;
import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser;
import org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser;
import org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter;
import org.apache.hbase.thirdparty.org.apache.commons.cli.Option;
import org.apache.hbase.thirdparty.org.apache.commons.cli.OptionGroup;
import org.apache.hbase.thirdparty.org.apache.commons.cli.Options;
import org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException;
import org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser;

/**
* ThriftServer - this class starts up a Thrift server which implements the HBase API specified in
Expand Down Expand Up @@ -129,9 +128,10 @@ public ThriftServer() {
private static void printUsage() {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("Thrift", null, getOptions(),
"To start the Thrift server run 'hbase-daemon.sh start thrift2'\n" +
"To shutdown the thrift server run 'hbase-daemon.sh stop thrift2' or" +
" send a kill signal to the thrift server pid",
"To start the Thrift server run 'hbase-daemon.sh start thrift2' or " +
"'hbase thrift2'\n" +
"To shutdown the thrift server run 'hbase-daemon.sh stop thrift2' or" +
" send a kill signal to the thrift server pid",
true);
}

Expand Down Expand Up @@ -169,7 +169,7 @@ private static Options getOptions() {

private static CommandLine parseArguments(Configuration conf, Options options, String[] args)
throws ParseException, IOException {
CommandLineParser parser = new PosixParser();
CommandLineParser parser = new DefaultParser();
return parser.parse(options, args);
}

Expand Down Expand Up @@ -388,7 +388,8 @@ public int run(String[] args) throws Exception {
int selectorThreads = 0;
int maxCallQueueSize = -1; // use unbounded queue by default

if (checkArguments(cmd)) {
if (cmd.hasOption("help")) {
printUsage();
return 1;
}

Expand Down Expand Up @@ -545,19 +546,6 @@ private String getImplType(boolean nonblocking, boolean hsha, boolean selector)
return implType;
}

private boolean checkArguments(CommandLine cmd) {
/*
* This is to please both bin/hbase and bin/hbase-daemon. hbase-daemon provides "start" and
* "stop" arguments hbase should print the help if no argument is provided
*/
List<?> argList = cmd.getArgList();
if (cmd.hasOption("help") || !argList.contains("start") || argList.contains("stop")) {
printUsage();
return true;
}
return false;
}

private String getBindAddress(Configuration conf, CommandLine cmd) {
String bindAddress;
if (cmd.hasOption("bind")) {
Expand Down

0 comments on commit 1ad09d2

Please sign in to comment.