HADOOP-2545 hbase rest server should be started with hbase-daemon.sh

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@612913 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2008-01-17 18:19:31 +00:00
parent 5f5472e631
commit 246d4b80ab
5 changed files with 159 additions and 116 deletions

View File

@ -192,6 +192,7 @@ Trunk (unreleased changes)
HADOOP-2557 Shell count function (Edward Yoon via Stack)
HADOOP-2589 Change an classes/package name from Shell to hql
(Edward Yoon via Stack)
HADOOP-2545 hbase rest server should be started with hbase-daemon.sh
Release 0.15.1
Branch 0.15

View File

@ -128,13 +128,13 @@ case $startStop in
if [ -f $pid ]; then
if kill -0 `cat $pid` > /dev/null 2>&1; then
echo -n stopping $command
if [ "$command" = "regionserver" ]; then
kill `cat $pid` > /dev/null 2>&1
else
if [ "$command" = "master" ]; then
nohup nice -n $HADOOP_NICENESS "$HBASE_HOME"/bin/hbase \
--hadoop "${HADOOP_HOME}" \
--config "${HADOOP_CONF_DIR}" --hbaseconfig "${HBASE_CONF_DIR}" \
$command $startStop "$@" > "$log" 2>&1 < /dev/null &
else
kill `cat $pid` > /dev/null 2>&1
fi
while kill -0 `cat $pid` > /dev/null 2>&1; do
echo -n "."

View File

@ -19,23 +19,16 @@
*/
package org.apache.hadoop.hbase.rest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mortbay.http.SocketListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
import org.mortbay.http.HttpContext;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.HBaseAdmin;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.util.InfoServer;
import org.mortbay.http.SocketListener;
/**
* Servlet implementation class for hbase REST interface.
@ -166,53 +159,80 @@ implements javax.servlet.Servlet {
return request.getRequestURI().substring(context_len).split("/");
}
//
// Main program and support routines
//
private static void printUsageAndExit() {
printUsageAndExit(null);
}
private static void printUsageAndExit(final String message) {
if (message != null) {
System.err.println(message);
}
System.out.println("Usage: java org.apache.hadoop.hbase.rest.Dispatcher " +
"--help | [--port=PORT] [--bind=ADDR] start");
System.out.println("Arguments:");
System.out.println(" start Start REST server");
System.out.println(" stop Stop REST server");
System.out.println("Options:");
System.out.println(" port Port to listen on. Default: 60050.");
System.out.println(" bind Address to bind on. Default: 0.0.0.0.");
System.out.println(" help Print this message and exit.");
System.exit(0);
}
/*
* Start up the REST servlet in standalone mode.
* @param args
*/
public static void main(String[] args) throws Exception{
protected static void doMain(final String [] args) throws Exception {
if (args.length < 1) {
printUsageAndExit();
}
int port = 60050;
String bindAddress = "0.0.0.0";
// grab the port and bind addresses from the command line if supplied
for(int i = 0; i < args.length; i++){
if(args[i].equals("--port")){
port = Integer.parseInt(args[++i]);
} else if(args[i].equals("--bind")){
bindAddress = args[++i];
} else if(args[i].equals("--help")){
printUsage();
return;
} else {
System.out.println("Unrecognized switch " + args[i]);
printUsage();
return;
}
}
org.mortbay.jetty.Server webServer = new org.mortbay.jetty.Server();
SocketListener listener = new SocketListener();
listener.setPort(port);
listener.setHost(bindAddress);
webServer.addListener(listener);
webServer.addWebApplication("/api", InfoServer.getWebAppDir("rest"));
webServer.start();
}
/*
* Print out the usage of this class from the command line.
*/
private static void printUsage(){
System.out.println("Start up the HBase REST servlet.");
System.out.println("Options:");
System.out.println("--port [port]");
System.out.println("\tPort to listen on. Defaults to 60050.");
System.out.println("--bind [addr]");
System.out.println("\tAddress to bind on. Defaults to 0.0.0.0.");
System.out.println("--help");
System.out.println("\tPrint this message and exit.");
// Process command-line args. TODO: Better cmd-line processing
// (but hopefully something not as painful as cli options).
final String addressArgKey = "--bind=";
final String portArgKey = "--port=";
for (String cmd: args) {
if (cmd.startsWith(addressArgKey)) {
bindAddress = cmd.substring(addressArgKey.length());
continue;
} else if (cmd.startsWith(portArgKey)) {
port = Integer.parseInt(cmd.substring(portArgKey.length()));
continue;
} else if (cmd.equals("--help") || cmd.equals("-h")) {
printUsageAndExit();
} else if (cmd.equals("start")) {
org.mortbay.jetty.Server webServer = new org.mortbay.jetty.Server();
SocketListener listener = new SocketListener();
listener.setPort(port);
listener.setHost(bindAddress);
webServer.addListener(listener);
webServer.addWebApplication("/api", InfoServer.getWebAppDir("rest"));
webServer.start();
break;
} else if (cmd.equals("stop")) {
printUsageAndExit("To shutdown the REST server run " +
"bin/hbase-daemon.sh stop rest or send a kill signal to " +
"the REST server pid");
}
// Print out usage if we get to here.
printUsageAndExit();
}
}
}
/**
* @param args
* @throws Exception
*/
public static void main(String [] args) throws Exception {
doMain(args);
}
}

View File

@ -28,12 +28,6 @@ import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Map.Entry;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HBaseAdmin;
@ -45,8 +39,6 @@ import org.apache.hadoop.hbase.HStoreKey;
import org.apache.hadoop.hbase.HTable;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.hbase.thrift.generated.AlreadyExists;
import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor;
import org.apache.hadoop.hbase.thrift.generated.Hbase;
@ -56,6 +48,7 @@ import org.apache.hadoop.hbase.thrift.generated.Mutation;
import org.apache.hadoop.hbase.thrift.generated.NotFound;
import org.apache.hadoop.hbase.thrift.generated.RegionDescriptor;
import org.apache.hadoop.hbase.thrift.generated.ScanEntry;
import org.apache.hadoop.io.Text;
import com.facebook.thrift.TException;
import com.facebook.thrift.protocol.TBinaryProtocol;
@ -571,54 +564,84 @@ public class ThriftServer {
}
}
public static void main(String[] args) {
Log LOG = LogFactory.getLog("ThriftServer");
// Parse command-line
//
Options options = new Options();
options.addOption("h", "help", false, "print this message");
options.addOption("p", "port", true,
"server listening port (default: 9090)");
CommandLineParser parser = new GnuParser();
CommandLine line;
try {
line = parser.parse(options, args);
} catch (ParseException e) {
System.out.println("ERROR: " + e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("ThriftServer [options]", options);
return;
}
if (line.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("ThriftServer [options]", options);
return;
}
int port = Integer.parseInt(line.getOptionValue("p", "9090"));
// Launch Thrift Server
//
try {
LOG
.info("starting HBase Thrift server on port "
+ Integer.toString(port));
HBaseHandler handler = new HBaseHandler();
Hbase.Processor processor = new Hbase.Processor(handler);
TServerTransport serverTransport = new TServerSocket(port);
TProtocolFactory protFactory = new TBinaryProtocol.Factory(true, true);
TServer server = new TThreadPoolServer(processor, serverTransport,
protFactory);
LOG.info("Starting the server...");
server.serve();
} catch (Exception x) {
x.printStackTrace();
}
LOG.info("done.");
//
// Main program and support routines
//
private static void printUsageAndExit() {
printUsageAndExit(null);
}
}
private static void printUsageAndExit(final String message) {
if (message != null) {
System.err.println(message);
}
System.out.println("Usage: java org.apache.hadoop.hbase.thrift.ThriftServer " +
"--help | [--port=PORT] start");
System.out.println("Arguments:");
System.out.println(" start Start thrift server");
System.out.println(" stop Stop thrift server");
System.out.println("Options:");
System.out.println(" port Port to listen on. Default: 9090");
// System.out.println(" bind Address to bind on. Default: 0.0.0.0.");
System.out.println(" help Print this message and exit");
System.exit(0);
}
/*
* Start up the REST servlet in standalone mode.
* @param args
*/
protected static void doMain(final String [] args) throws Exception {
if (args.length < 1) {
printUsageAndExit();
}
int port = 9090;
// String bindAddress = "0.0.0.0";
// Process command-line args. TODO: Better cmd-line processing
// (but hopefully something not as painful as cli options).
// final String addressArgKey = "--bind=";
final String portArgKey = "--port=";
for (String cmd: args) {
// if (cmd.startsWith(addressArgKey)) {
// bindAddress = cmd.substring(addressArgKey.length());
// continue;
// } else
if (cmd.startsWith(portArgKey)) {
port = Integer.parseInt(cmd.substring(portArgKey.length()));
continue;
} else if (cmd.equals("--help") || cmd.equals("-h")) {
printUsageAndExit();
} else if (cmd.equals("start")) {
Log LOG = LogFactory.getLog("ThriftServer");
LOG.info("starting HBase Thrift server on port " +
Integer.toString(port));
HBaseHandler handler = new HBaseHandler();
Hbase.Processor processor = new Hbase.Processor(handler);
TServerTransport serverTransport = new TServerSocket(port);
TProtocolFactory protFactory = new TBinaryProtocol.Factory(true, true);
TServer server = new TThreadPoolServer(processor, serverTransport,
protFactory);
server.serve();
break;
} else if (cmd.equals("stop")) {
printUsageAndExit("To shutdown the thrift server run " +
"bin/hbase-daemon.sh stop thrift or send a kill signal to " +
"the thrift server pid");
}
// Print out usage if we get to here.
printUsageAndExit();
}
}
/**
* @param args
* @throws Exception
*/
public static void main(String [] args) throws Exception {
doMain(args);
}
}

View File

@ -49,8 +49,7 @@ the <a href="http://svn.facebook.com/svnroot/thrift/">SVN repository</a>.</p>
<p>The ThriftServer is run like:
<pre>
./bin/hbase thrift [-h|--help] [-p|--port PORT]
./bin/hbase thrift -h|--help | [--port=PORT] start
</pre>
The default port is 9090.
</p>