From a82878bc759266b3368e80ea1b43abebdbbefd41 Mon Sep 17 00:00:00 2001 From: Kate Ting Date: Mon, 15 Apr 2013 11:35:45 -0400 Subject: [PATCH] SQOOP-972: Sqoop2: Load server URL from environment in shell (Jarek Jarcec Cecho via Kate Ting) --- .../java/org/apache/sqoop/client/core/Constants.java | 5 +++++ .../apache/sqoop/client/shell/ShellEnvironment.java | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) 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 c6c6d8ec..a48857e4 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 @@ -27,6 +27,11 @@ public class Constants { public static final String BOLD_STR_SEQUENCE = "@|bold"; public static final String END_STR_SEQUENCE = "|@"; + // Environmental variables + public static final String ENV_HOST = "SQOOP2_HOST"; + public static final String ENV_PORT = "SQOOP2_PORT"; + public static final String ENV_WEBAPP = "SQOOP2_WEBAPP"; + // Options public static final String OPT_XID = "xid"; 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 25ae3646..f6d12678 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 @@ -35,9 +35,9 @@ private ShellEnvironment() { // using static API. } - private static String serverHost = "localhost"; - private static String serverPort = "12000"; - private static String serverWebapp = "sqoop"; + 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 boolean verbose = false; private static boolean interactive = false; @@ -46,6 +46,11 @@ private ShellEnvironment() { static SqoopClient client = new SqoopClient(getServerUrl()); static IO io; + public static String getEnv(String variable, String defaultValue) { + String value = System.getenv(variable); + return value != null ? value : defaultValue; + } + public static SqoopClient getClient() { return client; }