hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r612913 - in /lucene/hadoop/trunk/src/contrib/hbase: ./ bin/ src/java/org/apache/hadoop/hbase/rest/ src/java/org/apache/hadoop/hbase/thrift/
Date Thu, 17 Jan 2008 18:19:38 GMT
Author: stack
Date: Thu Jan 17 10:19:31 2008
New Revision: 612913

URL: http://svn.apache.org/viewvc?rev=612913&view=rev
Log:
HADOOP-2545 hbase rest server should be started with hbase-daemon.sh

Modified:
    lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt
    lucene/hadoop/trunk/src/contrib/hbase/bin/hbase-daemon.sh
    lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/rest/Dispatcher.java
    lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java
    lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/package.html

Modified: lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt?rev=612913&r1=612912&r2=612913&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt (original)
+++ lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt Thu Jan 17 10:19:31 2008
@@ -192,6 +192,7 @@
    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

Modified: lucene/hadoop/trunk/src/contrib/hbase/bin/hbase-daemon.sh
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/bin/hbase-daemon.sh?rev=612913&r1=612912&r2=612913&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/bin/hbase-daemon.sh (original)
+++ lucene/hadoop/trunk/src/contrib/hbase/bin/hbase-daemon.sh Thu Jan 17 10:19:31 2008
@@ -128,13 +128,13 @@
     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 "."

Modified: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/rest/Dispatcher.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/rest/Dispatcher.java?rev=612913&r1=612912&r2=612913&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/rest/Dispatcher.java
(original)
+++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/rest/Dispatcher.java
Thu Jan 17 10:19:31 2008
@@ -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 @@
     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;
+
+    // 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();
     }
-    
-    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.");
+  /**
+   * @param args
+   * @throws Exception 
+   */
+  public static void main(String [] args) throws Exception {
+    doMain(args);
   }
-}
+}
\ No newline at end of file

Modified: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java?rev=612913&r1=612912&r2=612913&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java
(original)
+++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java
Thu Jan 17 10:19:31 2008
@@ -28,12 +28,6 @@
 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.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.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 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;
+  //
+  // 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 = 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,
+
+    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");
+      }
       
-      LOG.info("Starting the server...");
-      server.serve();
-      
-    } catch (Exception x) {
-      x.printStackTrace();
+      // Print out usage if we get to here.
+      printUsageAndExit();
     }
-    LOG.info("done.");
   }
-}
+  
+  /**
+   * @param args
+   * @throws Exception 
+   */
+  public static void main(String [] args) throws Exception {
+    doMain(args);
+  }
+}
\ No newline at end of file

Modified: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/package.html
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/package.html?rev=612913&r1=612912&r2=612913&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/package.html
(original)
+++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/thrift/package.html
Thu Jan 17 10:19:31 2008
@@ -49,8 +49,7 @@
 
 <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>



Mime
View raw message