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-2557 Shell count function (Edward Yoon via Stack)
HADOOP-2589 Change an classes/package name from Shell to hql HADOOP-2589 Change an classes/package name from Shell to hql
(Edward Yoon via Stack) (Edward Yoon via Stack)
HADOOP-2545 hbase rest server should be started with hbase-daemon.sh
Release 0.15.1 Release 0.15.1
Branch 0.15 Branch 0.15

View File

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

View File

@ -19,23 +19,16 @@
*/ */
package org.apache.hadoop.hbase.rest; package org.apache.hadoop.hbase.rest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.mortbay.http.SocketListener;
import java.io.File; import org.apache.hadoop.hbase.HBaseAdmin;
import java.io.FileNotFoundException; import org.apache.hadoop.hbase.HBaseConfiguration;
import java.net.URL;
import org.mortbay.http.HttpContext;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.util.InfoServer; import org.apache.hadoop.hbase.util.InfoServer;
import org.mortbay.http.SocketListener;
/** /**
* Servlet implementation class for hbase REST interface. * Servlet implementation class for hbase REST interface.
@ -166,53 +159,80 @@ implements javax.servlet.Servlet {
return request.getRequestURI().substring(context_len).split("/"); 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. * 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; int port = 60050;
String bindAddress = "0.0.0.0"; String bindAddress = "0.0.0.0";
// grab the port and bind addresses from the command line if supplied // Process command-line args. TODO: Better cmd-line processing
for(int i = 0; i < args.length; i++){ // (but hopefully something not as painful as cli options).
if(args[i].equals("--port")){ final String addressArgKey = "--bind=";
port = Integer.parseInt(args[++i]); final String portArgKey = "--port=";
} else if(args[i].equals("--bind")){ for (String cmd: args) {
bindAddress = args[++i]; if (cmd.startsWith(addressArgKey)) {
} else if(args[i].equals("--help")){ bindAddress = cmd.substring(addressArgKey.length());
printUsage(); continue;
return; } else if (cmd.startsWith(portArgKey)) {
} else { port = Integer.parseInt(cmd.substring(portArgKey.length()));
System.out.println("Unrecognized switch " + args[i]); continue;
printUsage(); } else if (cmd.equals("--help") || cmd.equals("-h")) {
return; printUsageAndExit();
} } else if (cmd.equals("start")) {
}
org.mortbay.jetty.Server webServer = new org.mortbay.jetty.Server(); org.mortbay.jetty.Server webServer = new org.mortbay.jetty.Server();
SocketListener listener = new SocketListener(); SocketListener listener = new SocketListener();
listener.setPort(port); listener.setPort(port);
listener.setHost(bindAddress); listener.setHost(bindAddress);
webServer.addListener(listener); webServer.addListener(listener);
webServer.addWebApplication("/api", InfoServer.getWebAppDir("rest")); webServer.addWebApplication("/api", InfoServer.getWebAppDir("rest"));
webServer.start(); 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.
* Print out the usage of this class from the command line. printUsageAndExit();
}
}
/**
* @param args
* @throws Exception
*/ */
private static void printUsage(){ public static void main(String [] args) throws Exception {
System.out.println("Start up the HBase REST servlet."); doMain(args);
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.");
} }
} }

View File

@ -28,12 +28,6 @@ import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Map.Entry; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HBaseAdmin; 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.HTable;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException; 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.AlreadyExists;
import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor; import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor;
import org.apache.hadoop.hbase.thrift.generated.Hbase; 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.NotFound;
import org.apache.hadoop.hbase.thrift.generated.RegionDescriptor; import org.apache.hadoop.hbase.thrift.generated.RegionDescriptor;
import org.apache.hadoop.hbase.thrift.generated.ScanEntry; import org.apache.hadoop.hbase.thrift.generated.ScanEntry;
import org.apache.hadoop.io.Text;
import com.facebook.thrift.TException; import com.facebook.thrift.TException;
import com.facebook.thrift.protocol.TBinaryProtocol; import com.facebook.thrift.protocol.TBinaryProtocol;
@ -571,54 +564,84 @@ public class ThriftServer {
} }
} }
public static void main(String[] args) { //
// 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 LOG = LogFactory.getLog("ThriftServer");
LOG.info("starting HBase Thrift server on port " +
// Parse command-line Integer.toString(port));
//
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(); HBaseHandler handler = new HBaseHandler();
Hbase.Processor processor = new Hbase.Processor(handler); Hbase.Processor processor = new Hbase.Processor(handler);
TServerTransport serverTransport = new TServerSocket(port); TServerTransport serverTransport = new TServerSocket(port);
TProtocolFactory protFactory = new TBinaryProtocol.Factory(true, true); TProtocolFactory protFactory = new TBinaryProtocol.Factory(true, true);
TServer server = new TThreadPoolServer(processor, serverTransport, TServer server = new TThreadPoolServer(processor, serverTransport,
protFactory); protFactory);
LOG.info("Starting the server...");
server.serve(); 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");
}
} catch (Exception x) { // Print out usage if we get to here.
x.printStackTrace(); printUsageAndExit();
} }
LOG.info("done."); }
/**
* @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: <p>The ThriftServer is run like:
<pre> <pre>
./bin/hbase thrift -h|--help | [--port=PORT] start
./bin/hbase thrift [-h|--help] [-p|--port PORT]
</pre> </pre>
The default port is 9090. The default port is 9090.
</p> </p>