You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ch...@apache.org on 2013/03/11 05:35:01 UTC
[3/3] git commit: SQOOP-918: Introduce client API and change Sqoop
shell to use it
Updated Branches:
refs/heads/sqoop2 abd2c5258 -> 2f9a2a71a
SQOOP-918: Introduce client API and change Sqoop shell to use it
(Jarcec Cecho via Cheolsoo Park)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/2f9a2a71
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/2f9a2a71
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/2f9a2a71
Branch: refs/heads/sqoop2
Commit: 2f9a2a71a6fc1387f509e47815b7d70cc97d6b0e
Parents: abd2c52
Author: Cheolsoo Park <ch...@apache.org>
Authored: Sun Mar 10 21:34:11 2013 -0700
Committer: Cheolsoo Park <ch...@apache.org>
Committed: Sun Mar 10 21:34:11 2013 -0700
----------------------------------------------------------------------
.../java/org/apache/sqoop/client/SqoopClient.java | 258 +++++++++++++++
.../org/apache/sqoop/client/core/Constants.java | 2 +
.../org/apache/sqoop/client/core/Environment.java | 101 ------
.../org/apache/sqoop/client/core/RequestCache.java | 221 ------------
.../sqoop/client/request/ConnectionRequest.java | 6 +-
.../sqoop/client/request/ConnectorRequest.java | 4 +-
.../apache/sqoop/client/request/JobRequest.java | 6 +-
.../apache/sqoop/client/request/SqoopRequests.java | 208 ++++++++++++
.../sqoop/client/request/SubmissionRequest.java | 6 +-
.../apache/sqoop/client/shell/CloneCommand.java | 21 +-
.../client/shell/CloneConnectionFunction.java | 59 +---
.../sqoop/client/shell/CloneJobFunction.java | 54 +--
.../apache/sqoop/client/shell/CreateCommand.java | 20 +-
.../client/shell/CreateConnectionFunction.java | 59 +---
.../sqoop/client/shell/CreateJobFunction.java | 76 +----
.../apache/sqoop/client/shell/DeleteCommand.java | 19 +-
.../client/shell/DeleteConnectionFunction.java | 22 +-
.../sqoop/client/shell/DeleteJobFunction.java | 21 +-
.../org/apache/sqoop/client/shell/HelpCommand.java | 56 ++--
.../org/apache/sqoop/client/shell/SetCommand.java | 23 +-
.../sqoop/client/shell/SetOptionFunction.java | 37 +--
.../sqoop/client/shell/SetServerFunction.java | 49 +--
.../sqoop/client/shell/ShellEnvironment.java | 147 ++++++++
.../org/apache/sqoop/client/shell/ShowCommand.java | 29 +-
.../sqoop/client/shell/ShowConnectionFunction.java | 99 +++----
.../sqoop/client/shell/ShowConnectorFunction.java | 88 ++---
.../sqoop/client/shell/ShowFrameworkFunction.java | 41 +--
.../apache/sqoop/client/shell/ShowJobFunction.java | 97 +++---
.../sqoop/client/shell/ShowOptionFunction.java | 27 +--
.../sqoop/client/shell/ShowServerFunction.java | 64 +---
.../sqoop/client/shell/ShowVersionFunction.java | 61 +---
.../apache/sqoop/client/shell/SqoopCommand.java | 8 -
.../apache/sqoop/client/shell/SqoopFunction.java | 28 +-
.../org/apache/sqoop/client/shell/SqoopShell.java | 42 +--
.../sqoop/client/shell/SubmissionCommand.java | 21 +-
.../client/shell/SubmissionStartFunction.java | 24 +-
.../client/shell/SubmissionStatusFunction.java | 24 +-
.../sqoop/client/shell/SubmissionStopFunction.java | 24 +-
.../apache/sqoop/client/shell/UpdateCommand.java | 18 +-
.../client/shell/UpdateConnectionFunction.java | 52 +--
.../sqoop/client/shell/UpdateJobFunction.java | 50 +--
.../apache/sqoop/client/utils/FormDisplayer.java | 139 ++++----
.../org/apache/sqoop/client/utils/FormFiller.java | 135 ++++-----
.../sqoop/client/utils/SubmissionDisplayer.java | 70 ++--
.../apache/sqoop/client/utils/TableDisplayer.java | 41 +--
.../sqoop/client/utils/ThrowableDisplayer.java | 56 ++--
.../src/main/resources/client-resource.properties | 3 +-
.../apache/sqoop/integration/TomcatTestCase.java | 17 +
.../connector/jdbc/generic/TableImportTest.java | 53 +---
49 files changed, 1296 insertions(+), 1490 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/SqoopClient.java b/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
new file mode 100644
index 0000000..554a8fe
--- /dev/null
+++ b/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
@@ -0,0 +1,258 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client;
+
+import org.apache.sqoop.client.request.SqoopRequests;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.model.MConnector;
+import org.apache.sqoop.model.MFramework;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.validation.Status;
+
+import java.util.List;
+import java.util.ResourceBundle;
+
+/**
+ * Sqoop client API.
+ *
+ * High level Sqoop client API to communicate with Sqoop server.
+ */
+public class SqoopClient {
+
+ private SqoopRequests requests;
+
+ public SqoopClient(String serverUrl) {
+ requests = new SqoopRequests();
+ requests.setServerUrl(serverUrl);
+ }
+
+ /**
+ * Set new server URL.
+ *
+ * @param serverUrl Server URL
+ */
+ public void setServerUrl(String serverUrl) {
+ requests.setServerUrl(serverUrl);
+ }
+
+ /**
+ * Get connector with given id.
+ *
+ * @param cid Connector id.
+ * @return
+ */
+ public MConnector getConnector(long cid) {
+ return requests.readConnector(cid).getConnectors().get(0);
+ }
+
+ /**
+ * Get list of all connectors.
+ *
+ * @return
+ */
+ public List<MConnector> getConnectors() {
+ return requests.readConnector(null).getConnectors();
+ }
+
+ /**
+ * Get resouce bundle for given connector.
+ *
+ * @param cid Connector id.
+ * @return
+ */
+ public ResourceBundle getResourceBundle(long cid) {
+ return requests.readConnector(cid).getResourceBundles().get(cid);
+ }
+
+ /**
+ * Return framework metadata.
+ *
+ * @return
+ */
+ public MFramework getFramework() {
+ return requests.readFramework().getFramework();
+ }
+
+ /**
+ * Return framework bundle.
+ *
+ * @return
+ */
+ public ResourceBundle getFrameworkResourceBundle() {
+ return requests.readFramework().getResourceBundle();
+ }
+
+ /**
+ * Create new connection object for given connector.
+ *
+ * @param cid Connector id
+ * @return
+ */
+ public MConnection newConnection(long cid) {
+ return new MConnection(
+ cid,
+ getConnector(cid).getConnectionForms(),
+ getFramework().getConnectionForms()
+ );
+ }
+
+ /**
+ * Retrieve connection with given id.
+ *
+ * @param xid Connnection id
+ * @return
+ */
+ public MConnection getConnection(long xid) {
+ return requests.readConnection(xid).getConnections().get(0);
+ }
+
+ /**
+ * Retrieve list of all connections.
+ *
+ * @return
+ */
+ public List<MConnection> getConnections() {
+ return requests.readConnection(null).getConnections();
+ }
+
+ /**
+ * Create the connection on server.
+ *
+ * @param connection Connection that should be created
+ * @return
+ */
+ public Status createConnection(MConnection connection) {
+ return requests.createConnectionApplyValidations(connection);
+ }
+
+ /**
+ * Update connection on the server.
+ *
+ * @param connection Connection that should be updated
+ * @return
+ */
+ public Status updateConnection(MConnection connection) {
+ return requests.updateConnectionApplyValidations(connection);
+ }
+
+ /**
+ * Delete connection with given id.
+ *
+ * @param xid Connection id
+ */
+ public void deleteConnection(long xid) {
+ requests.deleteConnection(xid);
+ }
+
+ /**
+ * Create new job of given type and for given connection.
+ *
+ * @param xid Connection id
+ * @param type Job type
+ * @return
+ */
+ public MJob newJob(long xid, MJob.Type type) {
+ MConnection connection = getConnection(xid);
+
+ return new MJob(
+ connection.getConnectorId(),
+ connection.getPersistenceId(),
+ type,
+ getConnector(connection.getConnectorId()).getJobForms(type),
+ getFramework().getJobForms(type)
+ );
+ }
+
+ /**
+ * Retrieve job for given id.
+ *
+ * @param jid Job id
+ * @return
+ */
+ public MJob getJob(long jid) {
+ return requests.readJob(jid).getJobs().get(0);
+ }
+
+ /**
+ * Retrieve list of all jobs.
+ *
+ * @return
+ */
+ public List<MJob> getJobs() {
+ return requests.readJob(null).getJobs();
+ }
+
+ /**
+ * Create job on server.
+ *
+ * @param job Job that should be created
+ * @return
+ */
+ public Status createJob(MJob job) {
+ return requests.createJobApplyValidations(job);
+ }
+
+ /**
+ * Update job on server.
+ * @param job Job that should be updated
+ * @return
+ */
+ public Status updateJob(MJob job) {
+ return requests.updateJobApplyValidations(job);
+ }
+
+ /**
+ * Delete job with given id.
+ *
+ * @param jid Job id
+ */
+ public void deleteJob(long jid) {
+ requests.deleteJob(jid);
+ }
+
+ /**
+ * Start job with given id.
+ *
+ * @param jid Job id
+ * @return
+ */
+ public MSubmission startSubmission(long jid) {
+ return requests.createSubmission(jid).getSubmission();
+ }
+
+ /**
+ * Stop job with given id.
+ *
+ * @param jid Job id
+ * @return
+ */
+ public MSubmission stopSubmission(long jid) {
+ return requests.deleteSubmission(jid).getSubmission();
+ }
+
+ /**
+ * Get status for given job id.
+ *
+ * @param jid Job id
+ * @return
+ */
+ public MSubmission getSubmissionStatus(long jid) {
+ return requests.readSubmission(jid).getSubmission();
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/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 c364aa8..ae3f994 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
@@ -112,6 +112,8 @@ public class Constants {
// Resource Keys for various messages
+ public static final String RES_FUNCTION_UNKNOWN =
+ "args.function.unknown";
public static final String RES_ARGS_XID_MISSING =
"args.xid_missing";
public static final String RES_ARGS_JID_MISSING =
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/core/Environment.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/core/Environment.java b/client/src/main/java/org/apache/sqoop/client/core/Environment.java
deleted file mode 100644
index 5d1af26..0000000
--- a/client/src/main/java/org/apache/sqoop/client/core/Environment.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.client.core;
-
-import java.util.Locale;
-import java.util.ResourceBundle;
-
-public final class Environment
-{
- private Environment() {
- // Disable explicit object creation
- }
-
- private static String serverHost;
- private static String serverPort;
- private static String serverWebapp;
-
- private static boolean verbose;
-
- private static boolean interactive;
-
- private static final String HOST_DEFAULT = "localhost";
- private static final String PORT_DEFAULT = "12000";
- private static final String WEBAPP_DEFAULT = "sqoop";
- private static final boolean VERBOSE_DEFAULT = false;
-
- private static ResourceBundle resourceBundle;
-
- static {
- serverHost = HOST_DEFAULT;
- serverPort = PORT_DEFAULT;
- serverWebapp = WEBAPP_DEFAULT;
- verbose = VERBOSE_DEFAULT;
-
- resourceBundle =
- ResourceBundle.getBundle(Constants.RESOURCE_NAME, Locale.getDefault());
- }
-
- public static void setServerHost(String host) {
- serverHost = host;
- }
-
- public static String getServerHost() {
- return serverHost;
- }
-
- public static void setServerPort(String port) {
- serverPort = port;
- }
-
- public static String getServerPort() {
- return serverPort;
- }
-
- public static void setServerWebapp(String webapp) {
- serverWebapp = webapp;
- }
-
- public static String getServerWebapp() {
- return serverWebapp;
- }
-
- public static String getServerUrl() {
- return "http://" + serverHost + ":" + serverPort + "/" + serverWebapp + "/";
- }
-
- public static ResourceBundle getResourceBundle() {
- return resourceBundle;
- }
-
- public static void setVerbose(boolean newValue) {
- verbose = newValue;
- }
-
- public static boolean isVerboose() {
- return verbose;
- }
-
- public static void setInteractive(boolean newValue) {
- interactive = newValue;
- }
-
- public static boolean isInteractive() {
- return interactive;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/core/RequestCache.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/core/RequestCache.java b/client/src/main/java/org/apache/sqoop/client/core/RequestCache.java
deleted file mode 100644
index 808b9f1..0000000
--- a/client/src/main/java/org/apache/sqoop/client/core/RequestCache.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.client.core;
-
-import org.apache.sqoop.client.request.ConnectionRequest;
-import org.apache.sqoop.client.request.ConnectorRequest;
-import org.apache.sqoop.client.request.FrameworkRequest;
-import org.apache.sqoop.client.request.JobRequest;
-import org.apache.sqoop.client.request.SubmissionRequest;
-import org.apache.sqoop.json.ConnectionBean;
-import org.apache.sqoop.json.ConnectorBean;
-import org.apache.sqoop.json.FrameworkBean;
-import org.apache.sqoop.json.JobBean;
-import org.apache.sqoop.json.SubmissionBean;
-import org.apache.sqoop.json.ValidationBean;
-import org.apache.sqoop.model.FormUtils;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.model.MSubmission;
-import org.apache.sqoop.validation.Status;
-import org.apache.sqoop.validation.Validation;
-
-/**
- * Client wise caching of various request objects
- */
-public final class RequestCache {
-
- private static FrameworkRequest frameworkRequest;
- private static ConnectorRequest connectorRequest;
- private static ConnectionRequest connectionRequest;
- private static JobRequest jobRequest;
- private static SubmissionRequest submissionRequest;
-
- public static FrameworkRequest getFrameworkRequest() {
- if (frameworkRequest == null) {
- frameworkRequest = new FrameworkRequest();
- }
-
- return frameworkRequest;
- }
-
- public static ConnectorRequest getConnectorRequest() {
- if (connectorRequest == null) {
- connectorRequest = new ConnectorRequest();
- }
-
- return connectorRequest;
- }
-
- public static ConnectionRequest getConnectionRequest() {
- if (connectionRequest == null) {
- connectionRequest = new ConnectionRequest();
- }
-
- return connectionRequest;
- }
-
- public static JobRequest getJobRequest() {
- if (jobRequest == null) {
- jobRequest = new JobRequest();
- }
-
- return jobRequest;
- }
-
- public static SubmissionRequest getSubmissionRequest() {
- if (submissionRequest == null) {
- submissionRequest = new SubmissionRequest();
- }
-
- return submissionRequest;
- }
-
- public static FrameworkBean readFramework() {
- return getFrameworkRequest().read(Environment.getServerUrl());
- }
-
- public static ConnectorBean readConnector(String cid) {
- return getConnectorRequest().read(Environment.getServerUrl(), cid);
- }
-
- public static ValidationBean createConnection(MConnection connection) {
- return getConnectionRequest()
- .create(Environment.getServerUrl(), connection);
- }
-
- public static Status createConnectionApplyValidations(MConnection connection) {
- ValidationBean bean = createConnection(connection);
-
- Validation connector = bean.getConnectorValidation();
- Validation framework = bean.getFrameworkValidation();
-
- FormUtils.applyValidation(connection.getConnectorPart().getForms(), connector);
- FormUtils.applyValidation(connection.getFrameworkPart().getForms(), framework);
-
- Long id = bean.getId();
- if(id != null) {
- connection.setPersistenceId(id);
- }
-
- return Status.getWorstStatus(connector.getStatus(), framework.getStatus());
- }
-
- public static ConnectionBean readConnection(String connectionId) {
- return getConnectionRequest()
- .read(Environment.getServerUrl(), connectionId);
- }
-
- public static ValidationBean updateConnection(MConnection connection) {
- return getConnectionRequest()
- .update(Environment.getServerUrl(), connection);
- }
-
- public static Status updateConnectionApplyValidations(MConnection connection){
- ValidationBean bean = updateConnection(connection);
-
- Validation connector = bean.getConnectorValidation();
- Validation framework = bean.getFrameworkValidation();
-
- FormUtils.applyValidation(connection.getConnectorPart().getForms(), connector);
- FormUtils.applyValidation(connection.getFrameworkPart().getForms(), framework);
-
- Long id = bean.getId();
- if(id != null) {
- connection.setPersistenceId(id);
- }
-
- return Status.getWorstStatus(connector.getStatus(), framework.getStatus());
- }
-
- public static void deleteConnection(String xid) {
- getConnectionRequest().delete(Environment.getServerUrl(), xid);
- }
-
- public static ValidationBean createJob(MJob job) {
- return getJobRequest().create(Environment.getServerUrl(), job);
- }
-
- public static Status createJobApplyValidations(MJob job) {
- ValidationBean bean = createJob(job);
-
- Validation connector = bean.getConnectorValidation();
- Validation framework = bean.getFrameworkValidation();
-
- FormUtils.applyValidation(job.getConnectorPart().getForms(), connector);
- FormUtils.applyValidation(job.getFrameworkPart().getForms(), framework);
-
- Long id = bean.getId();
- if(id != null) {
- job.setPersistenceId(id);
- }
-
- return Status.getWorstStatus(connector.getStatus(), framework.getStatus());
- }
-
- public static JobBean readJob(String jobId) {
- return getJobRequest().read(Environment.getServerUrl(), jobId);
- }
-
- public static ValidationBean updateJob(MJob job) {
- return getJobRequest().update(Environment.getServerUrl(), job);
- }
-
- public static Status updateJobApplyValidations(MJob job) {
- ValidationBean bean = updateJob(job);
-
- Validation connector = bean.getConnectorValidation();
- Validation framework = bean.getFrameworkValidation();
-
- FormUtils.applyValidation(job.getConnectorPart().getForms(), connector);
- FormUtils.applyValidation(job.getFrameworkPart().getForms(), framework);
-
- Long id = bean.getId();
- if(id != null) {
- job.setPersistenceId(id);
- }
-
- return Status.getWorstStatus(connector.getStatus(), framework.getStatus());
- }
-
- public static void deleteJob(String jid) {
- getJobRequest().delete(Environment.getServerUrl(), jid);
- }
-
- public static MSubmission readSubmission(String jid) {
- return getSubmissionRequest()
- .read(Environment.getServerUrl(), jid)
- .getSubmission();
- }
-
- public static MSubmission createSubmission(String jid) {
- return getSubmissionRequest()
- .create(Environment.getServerUrl(), jid)
- .getSubmission();
- }
-
- public static MSubmission deleteSubmission(String jid) {
- return getSubmissionRequest()
- .delete(Environment.getServerUrl(), jid)
- .getSubmission();
- }
-
- private RequestCache() {
- // Instantiation is prohibited
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/request/ConnectionRequest.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/ConnectionRequest.java b/client/src/main/java/org/apache/sqoop/client/request/ConnectionRequest.java
index f1e4d68..57486b1 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/ConnectionRequest.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/ConnectionRequest.java
@@ -31,8 +31,8 @@ public class ConnectionRequest extends Request {
public static final String RESOURCE = "v1/connection/";
- public ConnectionBean read(String serverUrl, String xid) {
- String response = null;
+ public ConnectionBean read(String serverUrl, Long xid) {
+ String response;
if (xid == null) {
response = super.get(serverUrl + RESOURCE + "all");
} else {
@@ -75,7 +75,7 @@ public class ConnectionRequest extends Request {
return validationBean;
}
- public void delete(String serverUrl, String id) {
+ public void delete(String serverUrl, Long id) {
super.delete(serverUrl + RESOURCE + id);
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/request/ConnectorRequest.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/ConnectorRequest.java b/client/src/main/java/org/apache/sqoop/client/request/ConnectorRequest.java
index 9ea9d5d..876099c 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/ConnectorRequest.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/ConnectorRequest.java
@@ -30,8 +30,8 @@ public class ConnectorRequest extends Request
{
public static final String RESOURCE = "v1/connector/";
- public ConnectorBean read(String serverUrl, String cid) {
- String response = null;
+ public ConnectorBean read(String serverUrl, Long cid) {
+ String response;
if (cid == null) {
response = super.get(serverUrl + RESOURCE + "all");
} else {
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/request/JobRequest.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/JobRequest.java b/client/src/main/java/org/apache/sqoop/client/request/JobRequest.java
index c2449f5..499ebeb 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/JobRequest.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/JobRequest.java
@@ -31,8 +31,8 @@ public class JobRequest extends Request {
public static final String RESOURCE = "v1/job/";
- public JobBean read(String serverUrl, String xid) {
- String response = null;
+ public JobBean read(String serverUrl, Long xid) {
+ String response;
if (xid == null) {
response = super.get(serverUrl + RESOURCE + "all");
} else {
@@ -74,7 +74,7 @@ public class JobRequest extends Request {
return validationBean;
}
- public void delete(String serverUrl, String id) {
+ public void delete(String serverUrl, Long id) {
super.delete(serverUrl + RESOURCE + id);
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java b/client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java
new file mode 100644
index 0000000..5ed38b6
--- /dev/null
+++ b/client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.request;
+
+import org.apache.sqoop.json.ConnectionBean;
+import org.apache.sqoop.json.ConnectorBean;
+import org.apache.sqoop.json.FrameworkBean;
+import org.apache.sqoop.json.JobBean;
+import org.apache.sqoop.json.SubmissionBean;
+import org.apache.sqoop.json.ValidationBean;
+import org.apache.sqoop.model.FormUtils;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.validation.Status;
+import org.apache.sqoop.validation.Validation;
+
+/**
+ * Unified class for all request objects.
+ */
+public class SqoopRequests {
+
+ private String serverUrl;
+
+ private FrameworkRequest frameworkRequest;
+ private ConnectorRequest connectorRequest;
+ private ConnectionRequest connectionRequest;
+ private JobRequest jobRequest;
+ private SubmissionRequest submissionRequest;
+
+ public void setServerUrl(String serverUrl) {
+ this.serverUrl = serverUrl;
+ }
+
+ public FrameworkRequest getFrameworkRequest() {
+ if (frameworkRequest == null) {
+ frameworkRequest = new FrameworkRequest();
+ }
+
+ return frameworkRequest;
+ }
+
+ public ConnectorRequest getConnectorRequest() {
+ if (connectorRequest == null) {
+ connectorRequest = new ConnectorRequest();
+ }
+
+ return connectorRequest;
+ }
+
+ public ConnectionRequest getConnectionRequest() {
+ if (connectionRequest == null) {
+ connectionRequest = new ConnectionRequest();
+ }
+
+ return connectionRequest;
+ }
+
+ public JobRequest getJobRequest() {
+ if (jobRequest == null) {
+ jobRequest = new JobRequest();
+ }
+
+ return jobRequest;
+ }
+
+ public SubmissionRequest getSubmissionRequest() {
+ if (submissionRequest == null) {
+ submissionRequest = new SubmissionRequest();
+ }
+
+ return submissionRequest;
+ }
+
+ public FrameworkBean readFramework() {
+ return getFrameworkRequest().read(serverUrl);
+ }
+
+ public ConnectorBean readConnector(Long cid) {
+ return getConnectorRequest().read(serverUrl, cid);
+ }
+
+ public ValidationBean createConnection(MConnection connection) {
+ return getConnectionRequest().create(serverUrl, connection);
+ }
+
+ public Status createConnectionApplyValidations(MConnection connection) {
+ ValidationBean bean = createConnection(connection);
+
+ Validation connector = bean.getConnectorValidation();
+ Validation framework = bean.getFrameworkValidation();
+
+ FormUtils.applyValidation(connection.getConnectorPart().getForms(), connector);
+ FormUtils.applyValidation(connection.getFrameworkPart().getForms(), framework);
+
+ Long id = bean.getId();
+ if(id != null) {
+ connection.setPersistenceId(id);
+ }
+
+ return Status.getWorstStatus(connector.getStatus(), framework.getStatus());
+ }
+
+ public ConnectionBean readConnection(Long connectionId) {
+ return getConnectionRequest().read(serverUrl, connectionId);
+ }
+
+ public ValidationBean updateConnection(MConnection connection) {
+ return getConnectionRequest().update(serverUrl, connection);
+ }
+
+ public Status updateConnectionApplyValidations(MConnection connection){
+ ValidationBean bean = updateConnection(connection);
+
+ Validation connector = bean.getConnectorValidation();
+ Validation framework = bean.getFrameworkValidation();
+
+ FormUtils.applyValidation(connection.getConnectorPart().getForms(), connector);
+ FormUtils.applyValidation(connection.getFrameworkPart().getForms(), framework);
+
+ Long id = bean.getId();
+ if(id != null) {
+ connection.setPersistenceId(id);
+ }
+
+ return Status.getWorstStatus(connector.getStatus(), framework.getStatus());
+ }
+
+ public void deleteConnection(Long xid) {
+ getConnectionRequest().delete(serverUrl, xid);
+ }
+
+ public ValidationBean createJob(MJob job) {
+ return getJobRequest().create(serverUrl, job);
+ }
+
+ public Status createJobApplyValidations(MJob job) {
+ ValidationBean bean = createJob(job);
+
+ Validation connector = bean.getConnectorValidation();
+ Validation framework = bean.getFrameworkValidation();
+
+ FormUtils.applyValidation(job.getConnectorPart().getForms(), connector);
+ FormUtils.applyValidation(job.getFrameworkPart().getForms(), framework);
+
+ Long id = bean.getId();
+ if(id != null) {
+ job.setPersistenceId(id);
+ }
+
+ return Status.getWorstStatus(connector.getStatus(), framework.getStatus());
+ }
+
+ public JobBean readJob(Long jobId) {
+ return getJobRequest().read(serverUrl, jobId);
+ }
+
+ public ValidationBean updateJob(MJob job) {
+ return getJobRequest().update(serverUrl, job);
+ }
+
+ public Status updateJobApplyValidations(MJob job) {
+ ValidationBean bean = updateJob(job);
+
+ Validation connector = bean.getConnectorValidation();
+ Validation framework = bean.getFrameworkValidation();
+
+ FormUtils.applyValidation(job.getConnectorPart().getForms(), connector);
+ FormUtils.applyValidation(job.getFrameworkPart().getForms(), framework);
+
+ Long id = bean.getId();
+ if(id != null) {
+ job.setPersistenceId(id);
+ }
+
+ return Status.getWorstStatus(connector.getStatus(), framework.getStatus());
+ }
+
+ public void deleteJob(Long jid) {
+ getJobRequest().delete(serverUrl, jid);
+ }
+
+ public SubmissionBean readSubmission(Long jid) {
+ return getSubmissionRequest().read(serverUrl, jid);
+ }
+
+ public SubmissionBean createSubmission(Long jid) {
+ return getSubmissionRequest().create(serverUrl, jid);
+ }
+
+ public SubmissionBean deleteSubmission(Long jid) {
+ return getSubmissionRequest().delete(serverUrl, jid);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/request/SubmissionRequest.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/SubmissionRequest.java b/client/src/main/java/org/apache/sqoop/client/request/SubmissionRequest.java
index 60dcbb2..69edabb 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/SubmissionRequest.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/SubmissionRequest.java
@@ -31,7 +31,7 @@ public class SubmissionRequest extends Request {
public static final String ACTION = RESOURCE + "action/";
- public SubmissionBean read(String serverUrl, String jid) {
+ public SubmissionBean read(String serverUrl, Long jid) {
String response = super.get(serverUrl + ACTION + jid);
JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
@@ -42,7 +42,7 @@ public class SubmissionRequest extends Request {
return submissionBean;
}
- public SubmissionBean create(String serverUrl, String jid) {
+ public SubmissionBean create(String serverUrl, Long jid) {
String response = super.post(serverUrl + ACTION + jid, null);
SubmissionBean submissionBean = new SubmissionBean();
@@ -51,7 +51,7 @@ public class SubmissionRequest extends Request {
return submissionBean;
}
- public SubmissionBean delete(String serverUrl, String id) {
+ public SubmissionBean delete(String serverUrl, Long id) {
String response = super.delete(serverUrl + ACTION + id);
SubmissionBean submissionBean = new SubmissionBean();
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java
index abec66b..283b025 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java
@@ -19,13 +19,12 @@ package org.apache.sqoop.client.shell;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
import org.apache.sqoop.common.SqoopException;
import org.codehaus.groovy.tools.shell.Shell;
-import java.text.MessageFormat;
import java.util.List;
-import java.util.ResourceBundle;
+
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
* Client side cloning of connection and job objects.
@@ -35,8 +34,6 @@ public class CloneCommand extends SqoopCommand {
private CloneConnectionFunction connectionFunction;
private CloneJobFunction jobFunction;
-
-
public CloneCommand(Shell shell) {
super(shell, Constants.CMD_CLONE, Constants.CMD_CLONE_SC,
new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
@@ -44,31 +41,29 @@ public class CloneCommand extends SqoopCommand {
}
public Object executeCommand(List args) {
- if(!Environment.isInteractive()) {
+ if(!isInteractive()) {
throw new SqoopException(ClientError.CLIENT_0007, "clone");
}
- String usageMsg = MessageFormat.format(getResource().getString(Constants.RES_CLONE_USAGE), getUsage());
-
if (args.size() == 0) {
- io.out.println(usageMsg);
- io.out.println();
+ printlnResource(Constants.RES_CLONE_USAGE, getUsage());
return null;
}
String func = (String)args.get(0);
if (func.equals(Constants.FN_CONNECTION)) {
if (connectionFunction == null) {
- connectionFunction = new CloneConnectionFunction(io);
+ connectionFunction = new CloneConnectionFunction();
}
return connectionFunction.execute(args);
} else if (func.equals(Constants.FN_JOB)) {
if (jobFunction == null) {
- jobFunction = new CloneJobFunction(io);
+ jobFunction = new CloneJobFunction();
}
return jobFunction.execute(args);
} else {
- throw new SqoopException(ClientError.CLIENT_0002, usageMsg);
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
}
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java
index 9d6c396..0538901 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java
@@ -23,52 +23,38 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.json.ConnectionBean;
import org.apache.sqoop.model.MConnection;
import org.apache.sqoop.model.MPersistableEntity;
import org.apache.sqoop.validation.Status;
-import org.codehaus.groovy.tools.shell.IO;
import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.List;
import java.util.ResourceBundle;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
/**
*
*/
public class CloneConnectionFunction extends SqoopFunction {
-
-
-
- private IO io;
-
-
-
@SuppressWarnings("static-access")
- public CloneConnectionFunction(IO io) {
- this.io = io;
-
+ public CloneConnectionFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_CONN_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
.withLongOpt(Constants.OPT_XID)
.hasArg()
.create(Constants.OPT_XID_CHAR)
);
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_XID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_XID_MISSING));
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
return null;
}
try {
- cloneConnection(line.getOptionValue(Constants.OPT_XID));
+ cloneConnection(getLong(line, Constants.OPT_XID));
} catch (IOException ex) {
throw new SqoopException(ClientError.CLIENT_0005, ex);
}
@@ -76,48 +62,35 @@ public class CloneConnectionFunction extends SqoopFunction {
return null;
}
- private void cloneConnection(String connectionId) throws IOException {
-
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_CLONE_CLONING_CONN), connectionId ));
+ private void cloneConnection(Long connectionId) throws IOException {
+ printlnResource(Constants.RES_CLONE_CLONING_CONN, connectionId);
ConsoleReader reader = new ConsoleReader();
- ConnectionBean connectionBean = readConnection(connectionId);
-
- // TODO(jarcec): Check that we have expected data
- MConnection connection = connectionBean.getConnections().get(0);
- ResourceBundle frameworkBundle
- = connectionBean.getFrameworkBundle();
- ResourceBundle connectorBundle
- = connectionBean.getConnectorBundle(connection.getConnectorId());
-
+ MConnection connection = client.getConnection(connectionId);
// Remove persistent id as we're making a clone
connection.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);
Status status = Status.FINE;
+ printlnResource(Constants.RES_PROMPT_UPDATE_CONN_METADATA);
- io.out.println(getResource().getString(Constants
- .RES_PROMPT_UPDATE_CONN_METADATA));
-
+ ResourceBundle connectorBundle = client.getResourceBundle(connection.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
do {
// Print error introduction if needed
if( !status.canProceed() ) {
- errorIntroduction(io);
+ errorIntroduction();
}
// Fill in data from user
- if(!fillConnection(io, reader, connection,
- connectorBundle, frameworkBundle)) {
+ if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
return;
}
- status = createConnectionApplyValidations(connection);
+ status = client.createConnection(connection);
} while(!status.canProceed());
- io.out.println(MessageFormat.format(getResource()
- .getString(Constants.RES_CLONE_CONN_SUCCESSFUL),
- status.name(), connection.getPersistenceId()));
+ printlnResource(Constants.RES_CLONE_CONN_SUCCESSFUL, status.name(), connection.getPersistenceId());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java
index d06f051..6f62813 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java
@@ -23,49 +23,37 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.json.JobBean;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MPersistableEntity;
import org.apache.sqoop.validation.Status;
-import org.codehaus.groovy.tools.shell.IO;
import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.List;
import java.util.ResourceBundle;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
/**
*
*/
public class CloneJobFunction extends SqoopFunction {
-
-
- private IO io;
-
-
@SuppressWarnings("static-access")
- public CloneJobFunction(IO io) {
- this.io = io;
-
+ public CloneJobFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_JOB_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
.withLongOpt(Constants.OPT_JID)
.hasArg()
.create(Constants.OPT_JID_CHAR));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_JID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_JID_MISSING));
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
return null;
}
try {
- cloneJob(line.getOptionValue(Constants.OPT_JID));
+ cloneJob(getLong(line, Constants.OPT_JID));
} catch (IOException ex) {
throw new SqoopException(ClientError.CLIENT_0005, ex);
}
@@ -73,47 +61,39 @@ public class CloneJobFunction extends SqoopFunction {
return null;
}
- private void cloneJob(String jobId) throws IOException {
- MessageFormat.format(getResource().getString(Constants.RES_CLONE_CLONING_JOB),
- jobId);
+ private void cloneJob(Long jobId) throws IOException {
+ printlnResource(Constants.RES_CLONE_CLONING_JOB, jobId);
ConsoleReader reader = new ConsoleReader();
- JobBean jobBean = readJob(jobId);
+ MJob job = client.getJob(jobId);
+ job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);
- // TODO(jarcec): Check that we have expected data
- MJob job = jobBean.getJobs().get(0);
- ResourceBundle frameworkBundle
- = jobBean.getFrameworkBundle();
- ResourceBundle connectorBundle
- = jobBean.getConnectorBundle(job.getConnectorId());
+ ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
Status status = Status.FINE;
// Remove persistent id as we're making a clone
job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);
- io.out.println(getResource().getString(Constants
- .RES_PROMPT_UPDATE_JOB_METADATA));
-
+ printlnResource(Constants.RES_PROMPT_UPDATE_JOB_METADATA);
do {
// Print error introduction if needed
if( !status.canProceed() ) {
- errorIntroduction(io);
+ errorIntroduction();
}
// Fill in data from user
- if(!fillJob(io, reader, job, connectorBundle, frameworkBundle)) {
+ if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
return;
}
// Try to create
- status = createJobApplyValidations(job);
+ status = client.createJob(job);
} while(!status.canProceed());
- io.out.println(MessageFormat.format(getResource()
- .getString(Constants.RES_CLONE_JOB_SUCCESSFUL), status.name(),
- job.getPersistenceId()));
+ printlnResource(Constants.RES_CLONE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java
index f4872d2..ac555e1 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java
@@ -19,13 +19,12 @@ package org.apache.sqoop.client.shell;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
import org.apache.sqoop.common.SqoopException;
import org.codehaus.groovy.tools.shell.Shell;
-import java.text.MessageFormat;
import java.util.List;
-import java.util.ResourceBundle;
+
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
@@ -35,7 +34,6 @@ public class CreateCommand extends SqoopCommand {
private CreateConnectionFunction connectionFunction;
private CreateJobFunction jobFunction;
-
public CreateCommand(Shell shell) {
super(shell, Constants.CMD_CREATE, Constants.CMD_CREATE_SC,
new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
@@ -43,31 +41,29 @@ public class CreateCommand extends SqoopCommand {
}
public Object executeCommand(List args) {
- if(!Environment.isInteractive()) {
+ if(!isInteractive()) {
throw new SqoopException(ClientError.CLIENT_0007, "create");
}
- String usageMsg = MessageFormat.format(getResource().getString(Constants.RES_CREATE_USAGE), getUsage());
-
if (args.size() == 0) {
- io.out.println(usageMsg);
- io.out.println();
+ printlnResource(Constants.RES_CREATE_USAGE, getUsage());
return null;
}
String func = (String)args.get(0);
if (func.equals(Constants.FN_CONNECTION)) {
if (connectionFunction == null) {
- connectionFunction = new CreateConnectionFunction(io);
+ connectionFunction = new CreateConnectionFunction();
}
return connectionFunction.execute(args);
} else if (func.equals(Constants.FN_JOB)) {
if (jobFunction == null) {
- jobFunction = new CreateJobFunction(io);
+ jobFunction = new CreateJobFunction();
}
return jobFunction.execute(args);
} else {
- throw new SqoopException(ClientError.CLIENT_0002, usageMsg);
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
}
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java
index 2c750d3..5bf9aaa 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java
@@ -23,34 +23,21 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.json.ConnectorBean;
-import org.apache.sqoop.json.FrameworkBean;
import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.model.MConnector;
-import org.apache.sqoop.model.MFramework;
import org.apache.sqoop.validation.Status;
-import org.codehaus.groovy.tools.shell.IO;
import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.List;
import java.util.ResourceBundle;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
/**
*
*/
public class CreateConnectionFunction extends SqoopFunction {
-
-
- private IO io;
-
@SuppressWarnings("static-access")
- public CreateConnectionFunction(IO io) {
- this.io = io;
-
+ public CreateConnectionFunction() {
this.addOption(OptionBuilder
.withDescription(Constants.RES_CONNECTOR_ID)
.withLongOpt(Constants.OPT_CID)
@@ -58,15 +45,14 @@ public class CreateConnectionFunction extends SqoopFunction {
.create(Constants.OPT_CID_CHAR));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_CID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_CID_MISSING));
+ printlnResource(Constants.RES_ARGS_CID_MISSING);
return null;
}
try {
- createConnection(line.getOptionValue(Constants.OPT_CID));
+ createConnection(getLong(line, Constants.OPT_CID));
} catch (IOException ex) {
throw new SqoopException(ClientError.CLIENT_0005, ex);
}
@@ -74,48 +60,33 @@ public class CreateConnectionFunction extends SqoopFunction {
return null;
}
- private void createConnection(String connectorId) throws IOException {
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_CREATE_CREATING_CONN), connectorId));
+ private void createConnection(long connectorId) throws IOException {
+ printlnResource(Constants.RES_CREATE_CREATING_CONN, connectorId);
ConsoleReader reader = new ConsoleReader();
- FrameworkBean frameworkBean = readFramework();
- ConnectorBean connectorBean = readConnector(connectorId);
-
- MFramework framework = frameworkBean.getFramework();
- ResourceBundle frameworkBundle = frameworkBean.getResourceBundle();
+ MConnection connection = client.newConnection(connectorId);
- MConnector connector = connectorBean.getConnectors().get(0);
- ResourceBundle connectorBundle = connectorBean.getResourceBundles().get(connector.getPersistenceId());
-
- MConnection connection = new MConnection(connector.getPersistenceId(),
- connector.getConnectionForms(),
- framework.getConnectionForms());
+ ResourceBundle connectorBundle = client.getResourceBundle(connectorId);
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
Status status = Status.FINE;
-
- io.out.println(getResource().getString(Constants.RES_PROMPT_FILL_CONN_METADATA));
-
+ printlnResource(Constants.RES_PROMPT_FILL_CONN_METADATA);
do {
// Print error introduction if needed
if( !status.canProceed() ) {
- errorIntroduction(io);
+ errorIntroduction();
}
// Fill in data from user
- if(!fillConnection(io, reader, connection,
- connectorBundle, frameworkBundle)) {
+ if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
return;
}
// Try to create
- status = createConnectionApplyValidations(connection);
+ status = client.createConnection(connection);
} while(!status.canProceed());
-
- io.out.println(MessageFormat.format(getResource()
- .getString(Constants.RES_CREATE_CONN_SUCCESSFUL), status.name(),
- connection.getPersistenceId()));
+ printlnResource(Constants.RES_CREATE_CONN_SUCCESSFUL, status.name(), connection.getPersistenceId());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java
index 1f01cc7..4fc2a43 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java
@@ -23,64 +23,48 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.json.ConnectionBean;
-import org.apache.sqoop.json.ConnectorBean;
-import org.apache.sqoop.json.FrameworkBean;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.model.MConnector;
-import org.apache.sqoop.model.MFramework;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.validation.Status;
-import org.codehaus.groovy.tools.shell.IO;
import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.List;
import java.util.ResourceBundle;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.core.RequestCache.*;
/**
* Handles creation of new job objects.
*/
public class CreateJobFunction extends SqoopFunction {
-
-
- private IO io;
-
@SuppressWarnings("static-access")
- public CreateJobFunction(IO io) {
- this.io = io;
-
+ public CreateJobFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_CONN_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
.withLongOpt(Constants.OPT_XID)
.hasArg()
.create(Constants.OPT_XID_CHAR)
);
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_JOB_TYPE))
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_TYPE))
.withLongOpt(Constants.OPT_TYPE)
.hasArg()
.create(Constants.OPT_TYPE_CHAR)
);
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_XID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_XID_MISSING));
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
return null;
}
if (!line.hasOption(Constants.OPT_TYPE)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_TYPE_MISSING));
+ printlnResource(Constants.RES_ARGS_TYPE_MISSING);
return null;
}
try {
- createJob(line.getOptionValue(Constants.OPT_XID),
- line.getOptionValue(Constants.OPT_TYPE));
+ createJob(getLong(line, Constants.OPT_XID),
+ line.getOptionValue(Constants.OPT_TYPE));
} catch (IOException ex) {
throw new SqoopException(ClientError.CLIENT_0005, ex);
}
@@ -88,56 +72,34 @@ public class CreateJobFunction extends SqoopFunction {
return null;
}
- private void createJob(String connectionId, String type) throws IOException {
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_CREATE_CREATING_JOB), connectionId));
+ private void createJob(Long connectionId, String type) throws IOException {
+ printlnResource(Constants.RES_CREATE_CREATING_JOB, connectionId);
ConsoleReader reader = new ConsoleReader();
+ MJob job = client.newJob(connectionId, MJob.Type.valueOf(type));
- FrameworkBean frameworkBean = readFramework();
- ConnectionBean connectionBean = readConnection(connectionId);
- ConnectorBean connectorBean;
-
- MFramework framework = frameworkBean.getFramework();
- ResourceBundle frameworkBundle = frameworkBean.getResourceBundle();
-
- MConnection connection = connectionBean.getConnections().get(0);
-
- connectorBean = readConnector(String.valueOf(connection.getConnectorId()));
- MConnector connector = connectorBean.getConnectors().get(0);
- ResourceBundle connectorBundle = connectorBean.getResourceBundles().get(connector.getPersistenceId());
-
- MJob.Type jobType = MJob.Type.valueOf(type.toUpperCase());
-
- MJob job = new MJob(
- connector.getPersistenceId(),
- connection.getPersistenceId(),
- jobType,
- connector.getJobForms(jobType),
- framework.getJobForms(jobType)
- );
+ ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
Status status = Status.FINE;
- io.out.println(getResource().getString(Constants.RES_PROMPT_FILL_JOB_METADATA));
+ printlnResource(Constants.RES_PROMPT_FILL_JOB_METADATA);
do {
// Print error introduction if needed
if( !status.canProceed() ) {
- errorIntroduction(io);
+ errorIntroduction();
}
// Fill in data from user
- if(!fillJob(io, reader, job, connectorBundle, frameworkBundle)) {
+ if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
return;
}
// Try to create
- status = createJobApplyValidations(job);
+ status = client.createJob(job);
} while(!status.canProceed());
- io.out.println(MessageFormat.format(getResource()
- .getString(Constants.RES_CREATE_JOB_SUCCESSFUL), status.name(),
- job.getPersistenceId()));
+ printlnResource(Constants.RES_CREATE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java
index 38b2fda..6a5b3a1 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java
@@ -17,14 +17,11 @@
*/
package org.apache.sqoop.client.shell;
-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.Shell;
-
-import java.text.MessageFormat;
import java.util.List;
-import java.util.ResourceBundle;
+
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
@@ -43,27 +40,25 @@ public class DeleteCommand extends SqoopCommand {
@Override
@SuppressWarnings("unchecked")
public Object executeCommand(List args) {
- String usageMsg = MessageFormat.format(getResource().getString(Constants
- .RES_DELETE_USAGE), getUsage());
if (args.size() == 0) {
- io.out.println(usageMsg);
- io.out.println();
+ printlnResource(Constants.RES_DELETE_USAGE, getUsage());
return null;
}
String func = (String)args.get(0);
if (func.equals(Constants.FN_CONNECTION)) {
if (connectionFunction == null) {
- connectionFunction = new DeleteConnectionFunction(io);
+ connectionFunction = new DeleteConnectionFunction();
}
return connectionFunction.execute(args);
} else if (func.equals(Constants.FN_JOB)) {
if (jobFunction == null) {
- jobFunction = new DeleteJobFunction(io);
+ jobFunction = new DeleteJobFunction();
}
return jobFunction.execute(args);
} else {
- throw new SqoopException(ClientError.CLIENT_0002, usageMsg);
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
}
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java
index 154acc7..18d3a70 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java
@@ -20,39 +20,29 @@ package org.apache.sqoop.client.shell;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.IO;
-import java.util.List;
-
-import static org.apache.sqoop.client.core.RequestCache.*;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
*/
public class DeleteConnectionFunction extends SqoopFunction {
-
- private IO io;
-
-
@SuppressWarnings("static-access")
- public DeleteConnectionFunction(IO io) {
- this.io = io;
-
+ public DeleteConnectionFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_CONN_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
.withLongOpt(Constants.OPT_XID)
.hasArg()
.create('x'));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_XID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_XID_MISSING));
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
return null;
}
- deleteConnection(line.getOptionValue(Constants.OPT_XID));
+ client.deleteConnection(getLong(line, Constants.OPT_XID));
return null;
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java
index 9d6c53e..736be20 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java
@@ -21,37 +21,28 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
import org.apache.sqoop.client.request.JobRequest;
-import org.codehaus.groovy.tools.shell.IO;
-import java.util.List;
-
-import static org.apache.sqoop.client.core.RequestCache.*;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
* Handles deletion of a job object.
*/
public class DeleteJobFunction extends SqoopFunction {
- private IO io;
-
private JobRequest jobRequest;
-
@SuppressWarnings("static-access")
- public DeleteJobFunction(IO io) {
- this.io = io;
-
+ public DeleteJobFunction() {
this.addOption(OptionBuilder
- .withDescription(getResource().getString(Constants.RES_PROMPT_JOB_ID))
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
.withLongOpt(Constants.OPT_JID)
.hasArg()
.create('j'));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_JID)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_JID_MISSING));
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
return null;
}
@@ -59,7 +50,7 @@ public class DeleteJobFunction extends SqoopFunction {
jobRequest = new JobRequest();
}
- deleteJob(line.getOptionValue(Constants.OPT_JID));
+ client.deleteJob(getLong(line, Constants.OPT_JID));
return null;
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
index e14f738..c6f831d 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
@@ -21,7 +21,6 @@ import java.text.MessageFormat;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.ResourceBundle;
import org.apache.commons.lang.StringUtils;
import org.apache.sqoop.client.core.ClientError;
@@ -32,10 +31,9 @@ import org.codehaus.groovy.tools.shell.CommandSupport;
import org.codehaus.groovy.tools.shell.Shell;
import org.codehaus.groovy.tools.shell.util.SimpleCompletor;
-public class HelpCommand extends CommandSupport
-{
- private static final ResourceBundle clientResource =
- ResourceBundle.getBundle(Constants.RESOURCE_NAME);
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+
+public class HelpCommand extends CommandSupport {
protected HelpCommand(Shell shell) {
super(shell, Constants.CMD_HELP, Constants.CMD_HELP_SC);
@@ -43,17 +41,17 @@ public class HelpCommand extends CommandSupport
@Override
public String getDescription() {
- return clientResource.getString(Constants.RES_HELP_DESCRIPTION);
+ return resourceString(Constants.RES_HELP_DESCRIPTION);
}
@Override
public String getUsage() {
- return clientResource.getString(Constants.RES_HELP_USAGE);
+ return resourceString(Constants.RES_HELP_USAGE);
}
@Override
public String getHelp() {
- return clientResource.getString(Constants.RES_HELP_MESSAGE);
+ return resourceString(Constants.RES_HELP_MESSAGE);
}
@SuppressWarnings("rawtypes")
@@ -90,12 +88,12 @@ public class HelpCommand extends CommandSupport
maxShortcut = command.getShortcut().length();
}
}
-
- io.out.println(clientResource.getString(Constants.RES_HELP_INFO));
- io.out.println();
+
+ printlnResource(Constants.RES_HELP_INFO);
+ println();
// List the commands we know about
- io.out.println(clientResource.getString(Constants.RES_HELP_AVAIL_COMMANDS));
+ printlnResource(Constants.RES_HELP_AVAIL_COMMANDS);
iterator = shell.getRegistry().commands().iterator();
while (iterator.hasNext()) {
@@ -104,39 +102,35 @@ public class HelpCommand extends CommandSupport
continue;
}
- String paddedName =
- StringUtils.rightPad(command.getName(), maxName);
- String paddedShortcut =
- StringUtils.rightPad(command.getShortcut(), maxShortcut);
-
+ String paddedName = StringUtils.rightPad(command.getName(), maxName);
+ String paddedShortcut = StringUtils.rightPad(command.getShortcut(), maxShortcut);
+
String description = command.getDescription();
StringBuilder sb = new StringBuilder();
sb.append(" ")
- .append(MessageFormat.format(clientResource.getString(Constants
+ .append(MessageFormat.format(resource.getString(Constants
.RES_HELP_CMD_DESCRIPTION), paddedName,
paddedShortcut, description));
- io.out.println(sb);
+ println(sb.toString());
}
-
- io.out.println();
- io.out.println(clientResource.getString(Constants.RES_HELP_SPECIFIC_CMD_INFO));
- io.out.println();
+
+ println();
+ printlnResource(Constants.RES_HELP_SPECIFIC_CMD_INFO);
+ println();
}
private void help(String name) {
Command command = shell.getRegistry().find(name);
if (command == null) {
- String msg = MessageFormat.format(clientResource.getString(Constants
+ String msg = MessageFormat.format(resource.getString(Constants
.RES_UNRECOGNIZED_CMD), name);
throw new SqoopException(ClientError.CLIENT_0001, msg);
}
- io.out.println(MessageFormat.format(clientResource.getString
- (Constants.RES_HELP_CMD_USAGE), command.getName(),
- command.getUsage()));
- io.out.println();
- io.out.println(command.getHelp());
- io.out.println();
+ printlnResource(Constants.RES_HELP_CMD_USAGE, command.getName(), command.getUsage());
+ println();
+ println(command.getHelp());
+ println();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -156,4 +150,4 @@ public class HelpCommand extends CommandSupport
completors.add(completor);
return completors;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
index 6c17e25..c831123 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
@@ -17,21 +17,18 @@
*/
package org.apache.sqoop.client.shell;
-import java.text.MessageFormat;
import java.util.List;
-import java.util.ResourceBundle;
-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.Shell;
-public class SetCommand extends SqoopCommand
-{
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+
+public class SetCommand extends SqoopCommand {
+
private SetServerFunction serverFunction;
private SetOptionFunction optionFunction;
-
protected SetCommand(Shell shell) {
super(shell, Constants.CMD_SET, Constants.CMD_SET_SC,
new String[] {Constants.FN_SERVER, Constants.FN_OPTION},
@@ -41,29 +38,27 @@ public class SetCommand extends SqoopCommand
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object executeCommand(List args) {
- String usageMsg = MessageFormat.format(getResource().getString(Constants
- .RES_SET_USAGE), getUsage());
if (args.size() == 0) {
- io.out.println(usageMsg);
- io.out.println();
+ printlnResource(Constants.RES_SET_USAGE, getUsage());
return null;
}
String func = (String)args.get(0);
if (func.equals(Constants.FN_SERVER)) {
if (serverFunction == null) {
- serverFunction = new SetServerFunction(io);
+ serverFunction = new SetServerFunction();
}
return serverFunction.execute(args);
} else if (func.equals(Constants.FN_OPTION)) {
if (optionFunction == null) {
- optionFunction = new SetOptionFunction(io);
+ optionFunction = new SetOptionFunction();
}
return optionFunction.execute(args);
} else {
- throw new SqoopException(ClientError.CLIENT_0002, usageMsg);
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
}
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java
index 5d5e9e7..9414b7d 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java
@@ -20,50 +20,37 @@ package org.apache.sqoop.client.shell;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
-import org.codehaus.groovy.tools.shell.IO;
-import java.text.MessageFormat;
-import java.util.List;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
/**
*
*/
public class SetOptionFunction extends SqoopFunction {
-
-
- private IO io;
-
-
@SuppressWarnings("static-access")
- protected SetOptionFunction(IO io) {
- this.io = io;
-
+ protected SetOptionFunction() {
this.addOption(OptionBuilder.hasArg()
- .withDescription(getResource().getString(Constants.RES_SET_PROMPT_OPT_NAME))
+ .withDescription(resourceString(Constants.RES_SET_PROMPT_OPT_NAME))
.withLongOpt(Constants.OPT_NAME)
.create(Constants.OPT_NAME_CHAR));
this.addOption(OptionBuilder.hasArg()
- .withDescription(getResource().getString(Constants.RES_SET_PROMPT_OPT_VALUE))
+ .withDescription(resourceString(Constants.RES_SET_PROMPT_OPT_VALUE))
.withLongOpt(Constants.OPT_VALUE)
.create(Constants.OPT_VALUE_CHAR));
}
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
+ public Object executeFunction(CommandLine line) {
if (!line.hasOption(Constants.OPT_NAME)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_NAME_MISSING));
+ printlnResource(Constants.RES_ARGS_NAME_MISSING);
return null;
}
if (!line.hasOption(Constants.OPT_VALUE)) {
- io.out.println(getResource().getString(Constants.RES_ARGS_VALUE_MISSING));
+ printlnResource(Constants.RES_ARGS_VALUE_MISSING);
return null;
}
- handleOptionSetting(line.getOptionValue(Constants.OPT_NAME),
- line.getOptionValue(Constants.OPT_VALUE));
+ handleOptionSetting(line.getOptionValue(Constants.OPT_NAME), line.getOptionValue(Constants.OPT_VALUE));
- io.out.println();
return null;
}
@@ -75,13 +62,11 @@ public class SetOptionFunction extends SqoopFunction {
newValue = true;
}
- Environment.setVerbose(newValue);
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_SET_VERBOSE_CHANGED), newValue));
+ setVerbose(newValue);
+ printlnResource(Constants.RES_SET_VERBOSE_CHANGED, newValue);
return;
}
- io.out.println(MessageFormat.format(getResource().getString(Constants
- .RES_SET_UNKNOWN_OPT_IGNORED), name));
+ printlnResource(Constants.RES_SET_UNKNOWN_OPT_IGNORED, name);
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/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 0e1e027..1c85592 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
@@ -17,66 +17,47 @@
*/
package org.apache.sqoop.client.shell;
-import java.io.PrintWriter;
-import java.util.List;
-
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.core.Environment;
-import org.codehaus.groovy.tools.shell.IO;
-
-@SuppressWarnings("serial")
-public class SetServerFunction extends SqoopFunction
-{
-
-
- private IO io;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+@SuppressWarnings("serial")
+public class SetServerFunction extends SqoopFunction {
@SuppressWarnings("static-access")
- protected SetServerFunction(IO io) {
- this.io = io;
-
+ protected SetServerFunction() {
this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_HOST)
- .withDescription(getResource().getString(Constants.RES_SET_HOST_DESCRIPTION))
+ .withDescription(resourceString(Constants.RES_SET_HOST_DESCRIPTION))
.withLongOpt(Constants.OPT_HOST)
.create(Constants.OPT_HOST_CHAR));
this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_PORT)
- .withDescription(getResource().getString(Constants.RES_SET_PORT_DESCRIPTION))
+ .withDescription(resourceString(Constants.RES_SET_PORT_DESCRIPTION))
.withLongOpt(Constants.OPT_PORT)
.create(Constants.OPT_PORT_CHAR));
this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_WEBAPP)
- .withDescription(getResource().getString(Constants.RES_WEBAPP_DESCRIPTION))
+ .withDescription(resourceString(Constants.RES_WEBAPP_DESCRIPTION))
.withLongOpt(Constants.OPT_WEBAPP)
.create(Constants.OPT_WEBAPP_CHAR));
}
- public void printHelp(PrintWriter out) {
- out.println(getResource().getString(Constants.RES_SET_SERVER_USAGE));
- super.printHelp(out);
- }
-
- public Object execute(List<String> args) {
- if (args.size() == 1) {
- printHelp(io.out);
- io.out.println();
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length == 1) {
+ printlnResource(Constants.RES_SET_SERVER_USAGE);
return null;
}
- CommandLine line = parseOptions(this, 1, args);
if (line.hasOption(Constants.OPT_HOST)) {
- Environment.setServerHost(line.getOptionValue(Constants.OPT_HOST));
+ setServerHost(line.getOptionValue(Constants.OPT_HOST));
}
if (line.hasOption(Constants.OPT_PORT)) {
- Environment.setServerPort(line.getOptionValue(Constants.OPT_PORT));
+ setServerPort(line.getOptionValue(Constants.OPT_PORT));
}
if (line.hasOption(Constants.OPT_WEBAPP)) {
- Environment.setServerWebapp(line.getOptionValue(Constants.OPT_WEBAPP));
+ setServerWebapp(line.getOptionValue(Constants.OPT_WEBAPP));
}
- io.out.println(getResource().getString(Constants.RES_SET_SERVER_SUCCESSFUL));
- io.out.println();
+ printlnResource(Constants.RES_SET_SERVER_SUCCESSFUL);
return null;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/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
new file mode 100644
index 0000000..8c133f2
--- /dev/null
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShellEnvironment.java
@@ -0,0 +1,147 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.client.core.Constants;
+import org.codehaus.groovy.tools.shell.IO;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * Static internal environment of the shell shared across all commands and
+ * functions.
+ */
+public final class ShellEnvironment {
+ private ShellEnvironment() {
+ // Direct instantiation is prohibited as entire functionality is exposed
+ // using static API.
+ }
+
+ private static String serverHost = "localhost";
+ private static String serverPort = "12000";
+ private static String serverWebapp = "sqoop";
+
+ private static boolean verbose = false;
+ private static boolean interactive = false;
+
+ static ResourceBundle resource = ResourceBundle.getBundle(Constants.RESOURCE_NAME, Locale.getDefault());
+ static SqoopClient client = new SqoopClient(getServerUrl());
+ static IO io;
+
+ public static SqoopClient getClient() {
+ return client;
+ }
+
+ public static void setIo(IO ioObject) {
+ io = ioObject;
+ }
+
+ public static IO getIo() {
+ return io;
+ }
+
+ public static void setServerHost(String host) {
+ serverHost = host;
+ client.setServerUrl(getServerUrl());
+ }
+
+ public static String getServerHost() {
+ return serverHost;
+ }
+
+ public static void setServerPort(String port) {
+ serverPort = port;
+ client.setServerUrl(getServerUrl());
+ }
+
+ public static String getServerPort() {
+ return serverPort;
+ }
+
+ public static void setServerWebapp(String webapp) {
+ serverWebapp = webapp;
+ client.setServerUrl(getServerUrl());
+ }
+
+ public static String getServerWebapp() {
+ return serverWebapp;
+ }
+
+ public static String getServerUrl() {
+ return "http://" + serverHost + ":" + serverPort + "/" + serverWebapp + "/";
+ }
+
+ public static ResourceBundle getResourceBundle() {
+ return resource;
+ }
+
+ public static void setVerbose(boolean newValue) {
+ verbose = newValue;
+ }
+
+ public static boolean isVerboose() {
+ return verbose;
+ }
+
+ public static void setInteractive(boolean newValue) {
+ interactive = newValue;
+ }
+
+ public static boolean isInteractive() {
+ return interactive;
+ }
+
+ public static String resourceString(String resourceName) {
+ return resource.getString(resourceName);
+ }
+
+ public static void printlnResource(String resourceName) {
+ io.out.println(resource.getString(resourceName));
+ }
+
+ public static void printlnResource(String resourceName, Object... values) {
+ io.out.println(MessageFormat.format(resourceString(resourceName), values));
+ }
+
+ public static void println(String str, Object ... values) {
+ io.out.println(MessageFormat.format(str, values));
+ }
+
+ public static void println(String str) {
+ io.out.println(str);
+ }
+
+ public static void println(Object obj) {
+ io.out.println(obj);
+ }
+
+ public static void println() {
+ io.out.println();
+ }
+
+ public static void print(String str) {
+ io.out.print(str);
+ }
+
+ public static void print(Object obj) {
+ io.out.print(obj);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/2f9a2a71/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java
index a043aa3..e24a7e8 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java
@@ -17,15 +17,12 @@
*/
package org.apache.sqoop.client.shell;
-import java.text.MessageFormat;
import java.util.List;
-import java.util.ResourceBundle;
-
-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.Shell;
+import static org.apache.sqoop.client.shell.ShellEnvironment.*;
+
public class ShowCommand extends SqoopCommand
{
private ShowServerFunction serverFunction;
@@ -48,57 +45,55 @@ public class ShowCommand extends SqoopCommand
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object executeCommand(List args) {
- String usageMsg = MessageFormat.format(getResource().getString(Constants
- .RES_SHOW_USAGE), getUsage());
if (args.size() == 0) {
- shell.getIo().out.println(usageMsg);
- io.out.println();
+ printlnResource(Constants.RES_SHOW_USAGE, getUsage());
return null;
}
String func = (String)args.get(0);
if (func.equals(Constants.FN_SERVER)) {
if (serverFunction == null) {
- serverFunction = new ShowServerFunction(io);
+ serverFunction = new ShowServerFunction();
}
return serverFunction.execute(args);
} else if (func.equals(Constants.FN_VERSION)) {
if (versionFunction == null) {
- versionFunction = new ShowVersionFunction(io);
+ versionFunction = new ShowVersionFunction();
}
return versionFunction.execute(args);
} else if (func.equals(Constants.FN_CONNECTOR)) {
if (connectorFunction == null) {
- connectorFunction = new ShowConnectorFunction(io);
+ connectorFunction = new ShowConnectorFunction();
}
return connectorFunction.execute(args);
} else if (func.equals(Constants.FN_FRAMEWORK)) {
if (frameworkFunction == null) {
- frameworkFunction = new ShowFrameworkFunction(io);
+ frameworkFunction = new ShowFrameworkFunction();
}
return frameworkFunction.execute(args);
} else if (func.equals(Constants.FN_CONNECTION)) {
if (connectionFunction == null) {
- connectionFunction = new ShowConnectionFunction(io);
+ connectionFunction = new ShowConnectionFunction();
}
return connectionFunction.execute(args);
} else if (func.equals(Constants.FN_JOB)) {
if (jobFunction == null) {
- jobFunction = new ShowJobFunction(io);
+ jobFunction = new ShowJobFunction();
}
return jobFunction.execute(args);
} else if (func.equals(Constants.FN_OPTION)) {
if (optionFunction == null) {
- optionFunction = new ShowOptionFunction(io);
+ optionFunction = new ShowOptionFunction();
}
return optionFunction.execute(args);
} else {
- throw new SqoopException(ClientError.CLIENT_0002, usageMsg);
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
}
}
}