HBASE-2846 Make rest server be same as thrift and avro servers

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@965160 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2010-07-18 05:24:17 +00:00
parent 4c16c452e6
commit 3ada3242b4
3 changed files with 46 additions and 6 deletions

View File

@ -439,6 +439,7 @@ Release 0.21.0 - Unreleased
HBASE-2727 Splits writing one file only is untenable; need dir of recovered
edits ordered by sequenceid
HBASE-2843 Readd bloomfilter test over zealously removed by HBASE-2625
HBASE-2846 Make rest server be same as thrift and avro servers
IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable

View File

@ -70,6 +70,7 @@ if [ $# = 0 ]; then
echo " master run an HBase HMaster node"
echo " regionserver run an HBase HRegionServer node"
echo " thrift run an HBase Thrift server"
echo " rest run an HBase REST server"
echo " avro run an HBase Avro server"
echo " zookeeper run a Zookeeper server"
echo " migrate upgrade an hbase.rootdir"
@ -239,6 +240,11 @@ elif [ "$COMMAND" = "thrift" ] ; then
if [ "$1" != "stop" ] ; then
HBASE_OPTS="$HBASE_OPTS $HBASE_THRIFT_OPTS"
fi
elif [ "$COMMAND" = "rest" ] ; then
CLASS='org.apache.hadoop.hbase.rest.Main'
if [ "$1" != "stop" ] ; then
HBASE_OPTS="$HBASE_OPTS $HBASE_REST_OPTS"
fi
elif [ "$COMMAND" = "avro" ] ; then
CLASS='org.apache.hadoop.hbase.avro.AvroServer'
if [ "$1" != "stop" ] ; then

View File

@ -22,9 +22,16 @@ package org.apache.hadoop.hbase.rest;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Arrays;
import java.util.List;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
@ -40,17 +47,43 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
* </ul>
*/
public class Main implements Constants {
private static final String DEFAULT_LISTEN_PORT = "8080";
private static void printUsageAndExit(Options options, int exitCode) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("REST", null, options,
"To start the REST server run 'bin/hbase-daemon.sh start rest'\n" +
"To shutdown the REST server run 'bin/hbase-daemon.sh stop rest' or" +
" send a kill signal to the rest server pid",
true);
System.exit(exitCode);
}
public static void main(String[] args) throws Exception {
// process command line
Log LOG = LogFactory.getLog("RESTServer");
Options options = new Options();
options.addOption("p", "port", true, "service port");
options.addOption("p", "port", true, "Port to bind to [default:" +
DEFAULT_LISTEN_PORT + "]");
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
int port = 8080;
if (cmd.hasOption("p")) {
port = Integer.valueOf(cmd.getOptionValue("p"));
/**
* 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");
if (cmd.hasOption("help") || !start || stop) {
printUsageAndExit(options, 1);
}
// Get port to bind to
int port = 0;
try {
port = Integer.parseInt(cmd.getOptionValue("port", DEFAULT_LISTEN_PORT));
} catch (NumberFormatException e) {
LOG.error("Could not parse the value provided for the port option", e);
printUsageAndExit(options, -1);
}
// set up the Jersey servlet container for Jetty