sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-973: Sqoop2: Merge host, port and app to single server URL in Sqoop shell
Date Wed, 05 Jun 2013 22:03:47 GMT
Updated Branches:
  refs/heads/sqoop2 8122d4ca9 -> 20082c57d


SQOOP-973: Sqoop2: Merge host, port and app to single server URL in Sqoop shell

(Mengwei Ding via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/20082c57
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/20082c57
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/20082c57

Branch: refs/heads/sqoop2
Commit: 20082c57d2533951c6f315c608c7b3df8616150b
Parents: 8122d4c
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Wed Jun 5 15:02:46 2013 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Wed Jun 5 15:02:46 2013 -0700

----------------------------------------------------------------------
 .../org/apache/sqoop/client/core/Constants.java    |    6 ++
 .../sqoop/client/shell/SetServerFunction.java      |   31 +++++++---
 .../sqoop/client/shell/ShellEnvironment.java       |   47 ++++++++++++++-
 .../src/main/resources/client-resource.properties  |    2 +
 docs/src/site/sphinx/CommandLineClient.rst         |    8 +++
 5 files changed, 83 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/20082c57/client/src/main/java/org/apache/sqoop/client/core/Constants.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/core/Constants.java b/client/src/main/java/org/apache/sqoop/client/core/Constants.java
index 866f3b8..056fcc8 100644
--- a/client/src/main/java/org/apache/sqoop/client/core/Constants.java
+++ b/client/src/main/java/org/apache/sqoop/client/core/Constants.java
@@ -45,6 +45,7 @@ public class Constants {
   public static final String OPT_HOST = "host";
   public static final String OPT_PORT = "port";
   public static final String OPT_WEBAPP = "webapp";
+  public static final String OPT_URL = "url";
   public static final String OPT_SERVER = "server";
   public static final String OPT_CLIENT = "client";
   public static final String OPT_PROTOCOL = "protocol";
@@ -61,6 +62,7 @@ public class Constants {
   public static final char OPT_HOST_CHAR = 'h';
   public static final char OPT_PORT_CHAR = 'p';
   public static final char OPT_WEBAPP_CHAR = 'w';
+  public static final char OPT_URL_CHAR = 'u';
   public static final char OPT_SERVER_CHAR = 's';
   public static final char OPT_CLIENT_CHAR = 'c';
   public static final char OPT_PROTOCOL_CHAR = 'p';
@@ -216,10 +218,14 @@ public class Constants {
       "set.port_description";
   public static final String RES_WEBAPP_DESCRIPTION =
       "set.webapp_description";
+  public static final String RES_URL_DESCRIPTION =
+      "set.url_description";
   public static final String RES_SET_SERVER_USAGE =
       "set.server_usage";
   public static final String RES_SET_SERVER_SUCCESSFUL =
       "set.server_successful";
+  public static final String RES_SET_SERVER_IGNORED =
+      "set.server_ignored";
 
   public static final String RES_SHOW_USAGE =
       "show.usage";

http://git-wip-us.apache.org/repos/asf/sqoop/blob/20082c57/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java
index 1c85592..41fc17a 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java
@@ -39,6 +39,10 @@ public class SetServerFunction extends SqoopFunction {
         .withDescription(resourceString(Constants.RES_WEBAPP_DESCRIPTION))
         .withLongOpt(Constants.OPT_WEBAPP)
         .create(Constants.OPT_WEBAPP_CHAR));
+    this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_URL)
+        .withDescription(resourceString(Constants.RES_URL_DESCRIPTION))
+        .withLongOpt(Constants.OPT_URL)
+        .create(Constants.OPT_URL_CHAR));
   }
 
   public Object executeFunction(CommandLine line) {
@@ -47,14 +51,25 @@ public class SetServerFunction extends SqoopFunction {
       return null;
     }
 
-    if (line.hasOption(Constants.OPT_HOST)) {
-      setServerHost(line.getOptionValue(Constants.OPT_HOST));
-    }
-    if (line.hasOption(Constants.OPT_PORT)) {
-      setServerPort(line.getOptionValue(Constants.OPT_PORT));
-    }
-    if (line.hasOption(Constants.OPT_WEBAPP)) {
-      setServerWebapp(line.getOptionValue(Constants.OPT_WEBAPP));
+    if (line.hasOption(Constants.OPT_URL)) {
+      setServerUrl(line.getOptionValue(Constants.OPT_URL));
+
+      // ignore --host, --port and --webapp option
+      if (line.hasOption(Constants.OPT_HOST)
+       || line.hasOption(Constants.OPT_PORT)
+       || line.hasOption(Constants.OPT_WEBAPP)) {
+        printlnResource(Constants.RES_SET_SERVER_IGNORED);
+      }
+    } else {
+      if (line.hasOption(Constants.OPT_HOST)) {
+          setServerHost(line.getOptionValue(Constants.OPT_HOST));
+      }
+      if (line.hasOption(Constants.OPT_PORT)) {
+        setServerPort(line.getOptionValue(Constants.OPT_PORT));
+      }
+      if (line.hasOption(Constants.OPT_WEBAPP)) {
+        setServerWebapp(line.getOptionValue(Constants.OPT_WEBAPP));
+      }
     }
 
     printlnResource(Constants.RES_SET_SERVER_SUCCESSFUL);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/20082c57/client/src/main/java/org/apache/sqoop/client/shell/ShellEnvironment.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShellEnvironment.java b/client/src/main/java/org/apache/sqoop/client/shell/ShellEnvironment.java
index 79cd8b2..41a8cd3 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShellEnvironment.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShellEnvironment.java
@@ -18,9 +18,13 @@
 package org.apache.sqoop.client.shell;
 
 import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.client.core.ClientError;
 import org.apache.sqoop.client.core.Constants;
+import org.apache.sqoop.common.SqoopException;
 import org.codehaus.groovy.tools.shell.IO;
 
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.text.MessageFormat;
 import java.util.Locale;
 import java.util.ResourceBundle;
@@ -37,9 +41,13 @@ public final class ShellEnvironment {
 
   private static final long DEFAULT_POLL_TIMEOUT = 10000;
 
-  private static String serverHost = getEnv(Constants.ENV_HOST, "localhost");
-  private static String serverPort = getEnv(Constants.ENV_PORT, "12000");
-  private static String serverWebapp = getEnv(Constants.ENV_WEBAPP, "sqoop");
+  private static String DEFAULT_SERVER_HOST = getEnv(Constants.ENV_HOST, "localhost");
+  private static String DEFAULT_SERVER_PORT = getEnv(Constants.ENV_PORT, "12000");
+  private static String DEFAULT_SERVER_WEBAPP = getEnv(Constants.ENV_WEBAPP, "sqoop");
+
+  private static String serverHost = DEFAULT_SERVER_HOST;
+  private static String serverPort = DEFAULT_SERVER_PORT;
+  private static String serverWebapp = DEFAULT_SERVER_WEBAPP;
 
   private static boolean verbose = false;
   private static boolean interactive = false;
@@ -93,6 +101,38 @@ public final class ShellEnvironment {
     return serverWebapp;
   }
 
+  public static void setServerUrl(String ustr){
+    try {
+      URL url = new URL(ustr);
+
+      String host = url.getHost();
+      if (host.length() > 0) {
+        serverHost = host;
+      }
+
+      int port = url.getPort();
+      if (port != -1) {
+        serverPort = Integer.toString(port);
+      } else {
+        // use default port number
+        serverPort = DEFAULT_SERVER_PORT;
+      }
+
+      String webapp = url.getFile();
+      if (webapp.length() > 1) {
+        // get rid of the first slash
+        serverWebapp = webapp.substring(1);
+      } else {
+        // use default webapp name
+        serverWebapp = DEFAULT_SERVER_WEBAPP;
+      }
+
+      client.setServerUrl(getServerUrl());
+    } catch (MalformedURLException ex) {
+      throw new SqoopException(ClientError.CLIENT_0003, ex);
+    }
+  }
+
   public static String getServerUrl() {
     return "http://" + serverHost + ":" + serverPort + "/" + serverWebapp + "/";
   }
@@ -165,3 +205,4 @@ public final class ShellEnvironment {
     io.out.printf(format, args);
   }
 }
+

http://git-wip-us.apache.org/repos/asf/sqoop/blob/20082c57/client/src/main/resources/client-resource.properties
----------------------------------------------------------------------
diff --git a/client/src/main/resources/client-resource.properties b/client/src/main/resources/client-resource.properties
index bbc8313..b159757 100644
--- a/client/src/main/resources/client-resource.properties
+++ b/client/src/main/resources/client-resource.properties
@@ -112,8 +112,10 @@ set.unknown_opt_ignored = Unknown option {0}. Ignoring...
 set.host_description = Host name to invoke server resources
 set.port_description = Port number to invoke server resources
 set.webapp_description = Web app to invoke server resources
+set.url_description = Url to invoke server resources
 set.server_usage = Usage: set server
 set.server_successful = Server is set successfully
+set.server_ignored = --host, --port or --webapp option is ignored, because --url option is
given.
 
 
 show.usage = Usage: show {0}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/20082c57/docs/src/site/sphinx/CommandLineClient.rst
----------------------------------------------------------------------
diff --git a/docs/src/site/sphinx/CommandLineClient.rst b/docs/src/site/sphinx/CommandLineClient.rst
index 721a6c0..073d547 100644
--- a/docs/src/site/sphinx/CommandLineClient.rst
+++ b/docs/src/site/sphinx/CommandLineClient.rst
@@ -94,11 +94,19 @@ Configure connection to Sqoop server - host port and web application name.
Avail
 +-----------------------+---------------+--------------------------------------------------+
 | ``-w``, ``--webapp``  | sqoop         | Tomcat's web application name                 
  |
 +-----------------------+---------------+--------------------------------------------------+
+| ``-u``, ``--url``     |               | Sqoop Server in url format                    
  |
++-----------------------+---------------+--------------------------------------------------+
 
 Example: ::
 
   set server --host sqoop2.company.net --port 80 --webapp sqoop
 
+or ::
+
+  set server --url http://sqoop2.company.net:80/sqoop
+
+Note: When ``--url`` option is given, ``--host``, ``--port`` or ``--webapp`` option will
be ignored.
+
 Set Option Function
 ~~~~~~~~~~~~~~~~~~~
 


Mime
View raw message