knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject git commit: KNOX-45: Clean up usage and help output from server command line
Date Thu, 30 May 2013 13:01:26 GMT
Updated Branches:
  refs/heads/master 71b94f21d -> 0511c11b2


KNOX-45: Clean up usage and help output from server command line


Project: http://git-wip-us.apache.org/repos/asf/incubator-knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-knox/commit/0511c11b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-knox/tree/0511c11b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-knox/diff/0511c11b

Branch: refs/heads/master
Commit: 0511c11b291b1c67a857b90753595b3c6aa66894
Parents: 71b94f2
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Thu May 30 09:00:12 2013 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Thu May 30 09:00:12 2013 -0400

----------------------------------------------------------------------
 gateway-release/home/bin/knox.sh                   |   12 ++++-
 .../apache/hadoop/gateway/GatewayCommandLine.java  |   46 ++++++++++-----
 .../apache/hadoop/gateway/GatewayResources.java    |   11 ++++
 .../org/apache/hadoop/gateway/GatewayServer.java   |   12 ++--
 4 files changed, 60 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/0511c11b/gateway-release/home/bin/knox.sh
----------------------------------------------------------------------
diff --git a/gateway-release/home/bin/knox.sh b/gateway-release/home/bin/knox.sh
index 47c2551..0c97e74 100644
--- a/gateway-release/home/bin/knox.sh
+++ b/gateway-release/home/bin/knox.sh
@@ -64,6 +64,9 @@ function main {
       setup) 
          setupEnv $KNOX_LAUNCH_USER
          ;;
+      help)
+         printHelp
+         ;;
       *)
          printf "Usage: $0 {start|stop|status|clean|setup [USER_NAME]}\n"
          ;;
@@ -248,7 +251,14 @@ function setupEnv {
    setDirPermission $PID_DIR $userName
    setDirPermission $LOG_DIR $userName
 
-   java -jar $KNOX_JAR -persist-master 
+   java -jar $KNOX_JAR -persist-master -nostart
+
+   return 0
+}
+
+function printHelp {
+   java -jar $KNOX_JAR -help
+   return 0
 }
 
 #Starting main

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/0511c11b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java
index bcb12de..54e03f8 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayCommandLine.java
@@ -23,22 +23,13 @@ import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
+import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
 
 import java.io.PrintWriter;
 
-public class GatewayCommandLine {
+import static org.apache.commons.cli.HelpFormatter.*;
 
-  public static Options createCommandLine() {
-    Options options = new Options();
-    //Option option = new Option( "short-flag", "long-flag", true, "desc" );
-    //option.setRequired( true );
-    //options.addOption( options );
-    options.addOption( "h", "help", false, "Help" );
-    options.addOption( "v", "version", false, "Version" );
-    options.addOption( "pm", "persist-master", false, "Persist Master Secret" );
-//    options.addOption( "s", "setup", false, "Setup" );
-    return options;
-  }
+public class GatewayCommandLine {
 
   public static CommandLine parse( String[] args ) throws ParseException {
     CommandLineParser parser = new PosixParser();
@@ -48,14 +39,41 @@ public class GatewayCommandLine {
 
   public static void printUsage() {
     PrintWriter printer = new PrintWriter( System.err );
-    new HelpFormatter().printUsage( printer, 80, "gateway", createCommandLine() );
+    new HelpFormatter().printUsage( printer, LINE_WIDTH, COMMAND_NAME, createCommandLine()
);
     printer.flush();
   }
 
   public static void printHelp() {
     PrintWriter printer = new PrintWriter( System.err );
-    new HelpFormatter().printUsage( printer, 80, "gateway", createCommandLine() );
+    new HelpFormatter().printHelp(printer, LINE_WIDTH, COMMAND_NAME, null, createCommandLine(),
DEFAULT_LEFT_PAD, DEFAULT_DESC_PAD, null);
     printer.flush();
   }
 
+  /** default number of characters per line */
+  public static final int LINE_WIDTH = 80;
+  /** Name of the command to use in the command line */
+  public static final String COMMAND_NAME= "knox";
+
+  public static final String HELP_LONG = "help";
+  public static final String HELP_SHORT = "h";
+
+  public static final String VERSION_LONG = "version";
+  public static final String VERSION_SHORT = "v";
+
+  public static final String PERSIST_LONG = "persist-master";
+  public static final String PERSIST_SHORT = "pm";
+
+  public static final String NOSTART_LONG = "nostart";
+  public static final String NOSTART_SHORT = "n";
+
+  private static Options createCommandLine() {
+    Options options = new Options();
+    options.addOption( HELP_SHORT, HELP_LONG, false, res.helpMessage() );
+    options.addOption( VERSION_SHORT, VERSION_LONG, false, res.versionHelpMessage() );
+    options.addOption( PERSIST_SHORT, PERSIST_LONG, false, res.persistmasterHelpMessage()
);
+    options.addOption( NOSTART_SHORT, NOSTART_LONG, false, res.nostartHelpMessage() );
+    return options;
+  }
+
+  private static GatewayResources res = ResourcesFactory.get( GatewayResources.class );
 }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/0511c11b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
index 3441d58..c05ef28 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayResources.java
@@ -35,4 +35,15 @@ public interface GatewayResources {
   @Resource( text="Service connectivity error." )
   String dispatchConnectionError();
 
+  @Resource( text="Display command line help." )
+  String helpMessage();
+
+  @Resource( text="This parameter causes the server to exit before starting to service requests.
This is typically used with the -persist-master parameter." )
+  String nostartHelpMessage();
+
+  @Resource( text="This parameter causes the provider master secret to be persisted. This
prevents the server from prompting for a master secret on subsequent starts." )
+  String persistmasterHelpMessage();
+
+  @Resource( text="Display server version information." )
+  String versionHelpMessage();
 }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/0511c11b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
index 84e8586..677fb8f 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
@@ -76,11 +76,9 @@ public class GatewayServer {
   public static void main( String[] args ) {
     try {
       CommandLine cmd = GatewayCommandLine.parse( args );
-      if( cmd.hasOption( "help" ) ) {
+      if( cmd.hasOption( GatewayCommandLine.HELP_LONG ) ) {
         GatewayCommandLine.printHelp();
-//      } else if( cmd.hasOption( "setup" ) ) {
-//        setupGateway();
-      } else if( cmd.hasOption( "version" ) ) {
+      } else if( cmd.hasOption( GatewayCommandLine.VERSION_LONG ) ) {
         buildProperties = loadBuildProperties();
         System.out.println( res.gatewayVersionMessage(
             buildProperties.getProperty( "build.version", "unknown" ),
@@ -90,9 +88,11 @@ public class GatewayServer {
         GatewayConfig config = new GatewayConfigImpl();
         configureLogging( config );
         Map<String,String> options = new HashMap<String,String>();
-        options.put("persist-master", Boolean.toString(cmd.hasOption("persist-master")));
+        options.put(GatewayCommandLine.PERSIST_LONG, Boolean.toString(cmd.hasOption(GatewayCommandLine.PERSIST_LONG)));
         services.init(config, options);
-        startGateway( config, services );
+        if (!cmd.hasOption(GatewayCommandLine.NOSTART_LONG)) {
+          startGateway( config, services );
+        }
       }
     } catch( ParseException e ) {
       log.failedToParseCommandLine( e );


Mime
View raw message