You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by hs...@apache.org on 2013/08/07 01:21:59 UTC
[1/6] SQOOP-921. Sqoop2: Create standalone shell package
Updated Branches:
refs/heads/sqoop2 0d4efda17 -> 21c1207b7 (forced update)
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java b/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java
new file mode 100644
index 0000000..6026a95
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java
@@ -0,0 +1,90 @@
+/**
+ * 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.shell.utils;
+
+import groovy.lang.MissingPropertyException;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Pretty printing of Throwable objects
+ */
+public class ThrowableDisplayer {
+
+ /**
+ * Error hook installed to Groovy shell.
+ *
+ * Will display exception that appeared during executing command. In most
+ * cases we will simply delegate the call to printing throwable method,
+ * however in case that we've received ClientError.CLIENT_0006 (server
+ * exception), we will unwrap server issue and view only that as local
+ * context shouldn't make any difference.
+ *
+ * @param t Throwable to be displayed
+ */
+ public static void errorHook(Throwable t) {
+ println("@|red Exception has occurred during processing command |@");
+
+ // If this is server exception from server
+ if(t instanceof SqoopException
+ && ((SqoopException)t).getErrorCode() == ShellError.SHELL_0006) {
+ print("@|red Server has returned exception: |@");
+ printThrowable(t.getCause(), isVerbose());
+ } else if(t.getClass() == MissingPropertyException.class) {
+ print("@|red Unknown command: |@");
+ println(t.getMessage());
+ } else {
+ printThrowable(t, isVerbose());
+ }
+ }
+
+ /**
+ * Pretty print Throwable instance including stack trace and causes.
+ *
+ * @param t Throwable to display
+ */
+ protected static void printThrowable(Throwable t, boolean verbose) {
+ print("@|red Exception: |@");
+ print(t.getClass().getName());
+ print(" @|red Message: |@");
+ print(t.getMessage());
+ println();
+
+ if(verbose) {
+ println("Stack trace:");
+ for(StackTraceElement e : t.getStackTrace()) {
+ print("\t @|bold at |@ ");
+ print(e.getClassName());
+ print(" (@|bold " + e.getFileName() + ":" + e.getLineNumber() + ") |@ ");
+ println();
+ }
+
+ Throwable cause = t.getCause();
+ if(cause != null) {
+ print("Caused by: ");
+ printThrowable(cause, verbose);
+ }
+ }
+ }
+
+ private ThrowableDisplayer() {
+ // Instantiation is prohibited
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/shell/src/main/resources/log4j.properties b/shell/src/main/resources/log4j.properties
new file mode 100644
index 0000000..af7e9f3
--- /dev/null
+++ b/shell/src/main/resources/log4j.properties
@@ -0,0 +1,24 @@
+# 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.
+
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=WARN, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/resources/shell-resource.properties
----------------------------------------------------------------------
diff --git a/shell/src/main/resources/shell-resource.properties b/shell/src/main/resources/shell-resource.properties
new file mode 100644
index 0000000..1a8f963
--- /dev/null
+++ b/shell/src/main/resources/shell-resource.properties
@@ -0,0 +1,232 @@
+# 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.
+
+# Client Resources in default language (english)
+
+############################
+# Security Form
+#
+object-name.label = Name
+object-name.help = Non unique name of the entity to help you remember \
+ it's purpose
+
+
+#############################
+# Messages
+#
+# Argument related
+#
+args.function.unknown = The specified function "{0}" is not recognized.
+args.xid_missing = Required argument --xid is missing.
+args.jid_missing = Required argument --jid is missing.
+args.cid_missing = Required argument --cid is missing.
+args.type_missing = Required argument --type is missing.
+args.name_missing = Required argument --name is missing.
+args.value_missing = Required argument --value is missing.
+
+
+## Generic description of various ids, types etc
+prompt.conn_id = Connection ID
+prompt.connector_id = Connector ID
+prompt.job_id = Job ID
+prompt.job_type = Job type
+
+## Prompt messages for updating, filling metadata info
+
+prompt.update_conn_metadata = Please update connection metadata:
+prompt.update_job_metadata = Please update job metadata:
+prompt.fill_conn_metadata = Please fill following values to create new \
+connection object
+prompt.fill_job_metadata = Please fill following values to create new \
+job object
+
+#
+# Update command
+update.conn = Updating connection with id {0}
+update.job = Updating job with id {0}
+update.usage = Usage: update {0}
+update.conn_successful = Connection was successfully updated with status {0}
+update.job_successful = Job was successfully updated with status {0}
+
+#
+# Clone command
+clone.usage = Usage: clone {0}
+clone.conn.successful = Connection was successfully created with validation \
+ status {0} and persistent id {1}
+clone.job.successful = Job was successfully created with validation \
+ status {0} and persistent id {1}
+clone.cloning_conn = Cloning connection with id {0}
+clone.cloning_job = Cloning job with id {0}
+
+#
+# Create command
+create.usage = Usage: create {0}
+create.conn_successful = New connection was successfully created with \
+ validation status {0} and persistent id {1}
+create.job_successful = New job was successfully created with validation \
+ status {0} and persistent id {1}
+## Creating messages
+create.creating_conn = Creating connection for connector with id {0}
+create.creating_job = Creating job for connection with id {0}
+
+#
+# Delete command
+delete.usage = Usage: delete {0}
+
+#
+# Enable command
+enable.usage = Usage: enable {0}
+enable.conn_successful = Connection {0} was successfully enabled
+enable.job_successful = Job {0} was successfully enabled
+
+#
+# Disable command
+disable.usage = Usage: disable {0}
+disable.conn_successful = Connection {0} was successfully disabled
+disable.job_successful = Job {0} was successfully disabled
+
+#
+# Help command
+help.usage = [<command>]
+help.description = Display this help message
+help.cmd_usage = Usage: @|bold {0} |@ {1}
+help.message = Display the list of commands or the help text for \
+ @|bold command|@.
+help.info = For information about @|green Sqoop|@, visit: \
+ @|cyan http://sqoop.apache.org/|@
+help.avail_commands = Available commands:
+help.cmd_description = @|bold {0} ({1}|@) {2}
+help.specific_cmd_info = For help on a specific command type: \
+ help @|bold command|@
+
+unrecognized.cmd = Unrecognized command {0}
+
+#
+# Set command
+set.usage = Usage: set {0}
+set.prompt_opt_name = Client option name
+set.prompt_opt_value = New option value
+set.verbose_changed = Verbose option was changed to {0}
+set.poll_timeout_changed = Poll timeout option has been changed to {0}
+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}
+
+show.prompt_display_all_conns = Display all connections
+show.prompt_display_conn_xid = Display the connection with xid
+show.conn_usage = Usage: show connection
+show.prompt_conns_to_show = @|bold {0} connection(s) to show: |@
+show.prompt_conn_info = Connection with id {0} and name {1} (Enabled: {2}, Created {3}, Updated {4})
+show.prompt_conn_cid_info = Using Connector id {0}
+
+show.prompt_display_all_connectors = Display all connectors
+show.prompt_display_connector_cid = Display the connector with cid
+show.connector_usage = Usage: show connector
+show.prompt_connectors_to_show = @|bold {0} connector(s) to show: |@
+show.prompt_connector_info = Connector with id {0}:\n Name: {1} \n \
+Class: {2}\n Version: {3}
+
+show.framework_usage = Usage: show framework
+show.prompt_framework_opts = @|bold Framework specific options: |@\nPersistent id: {0}
+
+show.prompt_display_all_jobs = Display all jobs
+show.prompt_display_job_jid = Display jobwith given jid
+show.job_usage = Usage: show job
+show.prompt_jobs_to_show = @|bold {0} job(s) to show: |@
+show.prompt_job_info = Job with id {0} and name {1} (Enabled: {2}, Created {3}, Updated {4})
+show.prompt_job_xid_cid_info = Using Connection id {0} and Connector id {1}
+
+show.prompt_display_all_submissions = Display all submissions
+show.prompt_display_all_submissions_jid = Display all submissions given jid
+
+show.prompt_display_all_servers = Display all server information
+show.prompt_display_server_host = Display server host name
+show.prompt_display_server_port = Display server port number
+show.prompt_display_server_webapp = Display server web app name
+show.server_usage = Usage: show server
+show.prompt_server_host = @|bold Server host:|@ {0}
+show.prompt_server_port = @|bold Server port:|@ {0}
+show.prompt_server_webapp = @|bold Server webapp:|@ {0}
+
+show.prompt_display_all_versions = Display all versions
+show.prompt_display_version_server = Display server version
+show.prompt_display_version_client = Display client version
+show.prompt_display_version_protocol = Display protocol version
+show.version_usage = Usage: show version
+show.prompt_version_client_server = @|bold {0} version:|@\n Sqoop {1} \
+revision {2} \n Compiled by {3} on {4}
+show.prompt_version_protocol = @|bold Protocol version:|@\n {0}
+
+sqoop.shell_banner = @|green Sqoop Shell:|@ Type '@|bold help|@' or '@|bold \\h|@' for help.
+sqoop.prompt_shell_loadrc = Loading resource file {0}
+sqoop.prompt_shell_loadedrc = Resource file loaded.
+
+start.usage = Usage: start {0}
+start.prompt_synchronous = Wait for submission to finish
+
+stop.usage = Usage: stop {0}
+
+status.usage = Usage: status {0}
+
+# Various Table headers
+table.header.id = Id
+table.header.name = Name
+table.header.version = Version
+table.header.class = Class
+table.header.type = Type
+table.header.connector = Connector
+table.header.jid = Job Id
+table.header.eid = External Id
+table.header.status = Status
+table.header.date = Last Update Date
+table.header.enabled = Enabled
+
+#Form displayer resources
+formdisplayer.supported_job_types = Supported job types
+formdisplayer.connection = Connection
+formdisplayer.job = Job
+formdisplayer.forms_jobtype = Forms for job type
+formdisplayer.form = form
+formdisplayer.name = Name
+formdisplayer.label = Label
+formdisplayer.help = Help
+formdisplayer.input = Input
+formdisplayer.type = Type
+formdisplayer.sensitive = Sensitive
+formdisplayer.size = Size
+formdisplayer.possible_values = Possible values
+formdisplayer.unsupported_datatype = Unsupported data type
+formdisplayer.input_sensitive = This input is sensitive
+
+formdisplayer.warning_message = There were warnings while create or update, but saved successfully.
+
+submission.submission_detail = Submission details
+submission.job_id = Job ID
+submission.creation_date = Creation date
+submission.external_id = External ID
+submission.progress_not_available = Progress is not available
+submission.counters = Counters
+submission.executed_success = Job executed successfully
+submission.server_url = Server URL
+submission.connector_schema = Connector schema
+submission.hio_schema = Input/Output schema
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/shell/src/test/resources/log4j.properties b/shell/src/test/resources/log4j.properties
new file mode 100644
index 0000000..44ffced
--- /dev/null
+++ b/shell/src/test/resources/log4j.properties
@@ -0,0 +1,24 @@
+# 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.
+
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=DEBUG, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
[2/6] SQOOP-921. Sqoop2: Create standalone shell package
Posted by hs...@apache.org.
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java b/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java
new file mode 100644
index 0000000..f03e08f
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java
@@ -0,0 +1,58 @@
+/**
+ * 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.shell;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
+
+public class StartCommand extends SqoopCommand {
+ public static final Logger LOG = Logger.getLogger(StartCommand.class);
+
+ private StartJobFunction startJobFunction;
+
+ @SuppressWarnings("static-access")
+ protected StartCommand(Shell shell) {
+ super(shell, Constants.CMD_START, Constants.CMD_START_SC,
+ new String[] {Constants.FN_JOB}, Constants.PRE_START, null);
+ }
+
+ @Override
+ public Object executeCommand(List args) {
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_START_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String) args.get(0);
+ if (func.equals(Constants.FN_JOB)) {
+ if (startJobFunction == null) {
+ startJobFunction = new StartJobFunction();
+ }
+ return startJobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/StartJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StartJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/StartJobFunction.java
new file mode 100644
index 0000000..02148de
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/StartJobFunction.java
@@ -0,0 +1,89 @@
+/**
+ * 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.shell;
+
+import static org.apache.sqoop.shell.ShellEnvironment.client;
+import static org.apache.sqoop.shell.ShellEnvironment.getPollTimeout;
+import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.log4j.Logger;
+import org.apache.sqoop.client.SubmissionCallback;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.SubmissionDisplayer;
+
+public class StartJobFunction extends SqoopFunction {
+ public static final Logger LOG = Logger.getLogger(StartJobFunction.class);
+
+ @SuppressWarnings("static-access")
+ public StartJobFunction() {
+ this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .create(Constants.OPT_JID_CHAR));
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_SYNCHRONOUS))
+ .withLongOpt(Constants.OPT_SYNCHRONOUS)
+ .create(Constants.OPT_SYNCHRONOUS_CHAR));
+ }
+
+ @Override
+ public Object executeFunction(CommandLine line) {
+ // Poll until finished
+ if (line.hasOption(Constants.OPT_SYNCHRONOUS) && line.hasOption(Constants.OPT_JID)) {
+ long pollTimeout = getPollTimeout();
+ SubmissionCallback callback = new SubmissionCallback() {
+ @Override
+ public void submitted(MSubmission submission) {
+ SubmissionDisplayer.displayHeader(submission);
+ SubmissionDisplayer.displayProgress(submission);
+ }
+
+ @Override
+ public void updated(MSubmission submission) {
+ SubmissionDisplayer.displayProgress(submission);
+ }
+
+ @Override
+ public void finished(MSubmission submission) {
+ SubmissionDisplayer.displayFooter(submission);
+ }
+ };
+
+ try {
+ client.startSubmission(getLong(line, Constants.OPT_JID), callback, pollTimeout);
+ } catch (InterruptedException e) {
+ throw new SqoopException(ShellError.SHELL_0008, e);
+ }
+ } else if (line.hasOption(Constants.OPT_JID)) {
+ MSubmission submission = client.startSubmission(getLong(line, Constants.OPT_JID));
+ if(submission.getStatus().isFailure()) {
+ SubmissionDisplayer.displayFooter(submission);
+ } else {
+ SubmissionDisplayer.displayHeader(submission);
+ SubmissionDisplayer.displayProgress(submission);
+ }
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java b/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java
new file mode 100644
index 0000000..184892a
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java
@@ -0,0 +1,56 @@
+/**
+ * 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.shell;
+
+import java.util.List;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
+
+public class StatusCommand extends SqoopCommand {
+
+ private StatusJobFunction statusJobFunction;
+
+ @SuppressWarnings("static-access")
+ protected StatusCommand(Shell shell) {
+ super(shell, Constants.CMD_STATUS, Constants.CMD_STATUS_SC,
+ new String[] { Constants.FN_JOB }, Constants.PRE_STATUS, null);
+ }
+
+ @Override
+ public Object executeCommand(List args) {
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_STATUS_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String) args.get(0);
+ if (func.equals(Constants.FN_JOB)) {
+ if (statusJobFunction == null) {
+ statusJobFunction = new StatusJobFunction();
+ }
+ return statusJobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/StatusJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StatusJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/StatusJobFunction.java
new file mode 100644
index 0000000..be0de8c
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/StatusJobFunction.java
@@ -0,0 +1,55 @@
+/**
+ * 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.shell;
+
+import static org.apache.sqoop.shell.ShellEnvironment.client;
+import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.SubmissionDisplayer;
+import org.apache.sqoop.submission.SubmissionStatus;
+
+public class StatusJobFunction extends SqoopFunction{
+
+ @SuppressWarnings("static-access")
+ public StatusJobFunction() {
+ this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .create(Constants.OPT_JID_CHAR));
+ }
+
+ @Override
+ public Object executeFunction(CommandLine line) {
+ if (line.hasOption(Constants.OPT_JID)) {
+ MSubmission submission = client.getSubmissionStatus(getLong(line, Constants.OPT_JID));
+ if(submission.getStatus().isFailure() || submission.getStatus().equals(SubmissionStatus.SUCCEEDED)) {
+ SubmissionDisplayer.displayHeader(submission);
+ SubmissionDisplayer.displayFooter(submission);
+ } else {
+ SubmissionDisplayer.displayHeader(submission);
+ SubmissionDisplayer.displayProgress(submission);
+ }
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java b/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java
new file mode 100644
index 0000000..698bca7
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java
@@ -0,0 +1,54 @@
+/**
+ * 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.shell;
+
+import java.util.List;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
+
+public class StopCommand extends SqoopCommand {
+
+ private StopJobFunction stopJobFunction;
+
+ @SuppressWarnings("static-access")
+ protected StopCommand(Shell shell) {
+ super(shell, Constants.CMD_STOP, Constants.CMD_STOP_SC,
+ new String[] { Constants.FN_JOB }, Constants.PRE_STOP, null);
+ }
+ @Override
+ public Object executeCommand(List args) {
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_STOP_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String) args.get(0);
+ if (func.equals(Constants.FN_JOB)) {
+ if (stopJobFunction == null) {
+ stopJobFunction = new StopJobFunction();
+ }
+ return stopJobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/StopJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StopJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/StopJobFunction.java
new file mode 100644
index 0000000..6c0e3c2
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/StopJobFunction.java
@@ -0,0 +1,53 @@
+/**
+ * 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.shell;
+
+import static org.apache.sqoop.shell.ShellEnvironment.client;
+import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.SubmissionDisplayer;
+
+public class StopJobFunction extends SqoopFunction {
+
+ @SuppressWarnings("static-access")
+ public StopJobFunction() {
+ this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .create(Constants.OPT_JID_CHAR));
+ }
+
+ @Override
+ public Object executeFunction(CommandLine line) {
+ if (line.hasOption(Constants.OPT_JID)) {
+ MSubmission submission = client.stopSubmission(getLong(line, Constants.OPT_JID));
+ if(submission.getStatus().isFailure()) {
+ SubmissionDisplayer.displayFooter(submission);
+ } else {
+ SubmissionDisplayer.displayHeader(submission);
+ SubmissionDisplayer.displayProgress(submission);
+ }
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/UpdateCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/UpdateCommand.java b/shell/src/main/java/org/apache/sqoop/shell/UpdateCommand.java
new file mode 100644
index 0000000..9262ccd
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/UpdateCommand.java
@@ -0,0 +1,69 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class UpdateCommand extends SqoopCommand {
+
+ private UpdateConnectionFunction connectionFunction;
+ private UpdateJobFunction jobFunction;
+
+ public UpdateCommand(Shell shell) {
+ super(shell, Constants.CMD_UPDATE, Constants.CMD_UPDATE_SC,
+ new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
+ Constants.PRE_UPDATE, Constants.SUF_INFO);
+ }
+
+ public Object executeCommand(List args) {
+ if(!isInteractive()) {
+ throw new SqoopException(ShellError.SHELL_0007, "update");
+ }
+
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_UPDATE_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String)args.get(0);
+ if (func.equals(Constants.FN_CONNECTION)) {
+ if (connectionFunction == null) {
+ connectionFunction = new UpdateConnectionFunction();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new UpdateJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/UpdateConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/UpdateConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/UpdateConnectionFunction.java
new file mode 100644
index 0000000..c062fe6
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/UpdateConnectionFunction.java
@@ -0,0 +1,97 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.FormDisplayer;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ *
+ */
+public class UpdateConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public UpdateConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create(Constants.OPT_XID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+
+ try {
+ updateConnection(getLong(line, Constants.OPT_XID));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void updateConnection(Long connectionId) throws IOException {
+ printlnResource(Constants.RES_UPDATE_UPDATING_CONN, connectionId);
+
+ ConsoleReader reader = new ConsoleReader();
+
+ MConnection connection = client.getConnection(connectionId);
+
+ ResourceBundle connectorBundle = client.getResourceBundle(connection.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+
+ Status status = Status.FINE;
+
+ printlnResource(Constants.RES_PROMPT_UPDATE_CONN_METADATA);
+
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ // Try to create
+ status = client.updateConnection(connection);
+ } while(!status.canProceed());
+ FormDisplayer.displayFormWarning(connection);
+ printlnResource(Constants.RES_UPDATE_CONN_SUCCESSFUL, status.name());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/UpdateJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/UpdateJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/UpdateJobFunction.java
new file mode 100644
index 0000000..da1e0c5
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/UpdateJobFunction.java
@@ -0,0 +1,95 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.FormDisplayer;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ *
+ */
+public class UpdateJobFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public UpdateJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .hasArg()
+ .create(Constants.OPT_JID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_JID)) {
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
+ return null;
+ }
+
+ try {
+ updateJob(getLong(line, Constants.OPT_JID));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void updateJob(Long jobId) throws IOException {
+ printlnResource(Constants.RES_UPDATE_UPDATING_JOB, jobId);
+
+ ConsoleReader reader = new ConsoleReader();
+
+ MJob job = client.getJob(jobId);
+
+ ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+
+ Status status = Status.FINE;
+
+ printlnResource(Constants.RES_PROMPT_UPDATE_JOB_METADATA);
+
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ // Try to create
+ status = client.updateJob(job);
+ } while(!status.canProceed());
+ FormDisplayer.displayFormWarning(job);
+ printlnResource(Constants.RES_UPDATE_JOB_SUCCESSFUL, status.name());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
new file mode 100644
index 0000000..0e33d42
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
@@ -0,0 +1,451 @@
+/**
+ * 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.shell.core;
+
+/**
+ *
+ */
+public class Constants {
+
+ // General string constants
+ public static final String RESOURCE_NAME = "shell-resource";
+ 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";
+ public static final String OPT_ALL = "all";
+ public static final String OPT_JID = "jid";
+ public static final String OPT_CID = "cid";
+ public static final String OPT_TYPE = "type";
+ public static final String OPT_NAME = "name";
+ public static final String OPT_VALUE = "value";
+ public static final String OPT_VERBOSE = "verbose";
+ 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";
+ public static final String OPT_SYNCHRONOUS = "synchronous";
+ public static final String OPT_POLL_TIMEOUT = "poll-timeout";
+ public static final String OPT_DETAIL = "detail";
+
+ public static final char OPT_XID_CHAR = 'x';
+ public static final char OPT_ALL_CHAR = 'a';
+ public static final char OPT_JID_CHAR = 'j';
+ public static final char OPT_CID_CHAR = 'c';
+ public static final char OPT_TYPE_CHAR = 't';
+ public static final char OPT_NAME_CHAR = 'n';
+ public static final char OPT_VALUE_CHAR = 'v';
+ 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';
+ public static final char OPT_SYNCHRONOUS_CHAR = 's';
+ public static final char OPT_POLL_TIMEOUT_CHAR = 'p';
+ public static final char OPT_DETAIL_CHAR = 'd';
+
+ // Resource keys for various commands, command options,
+ // functions and descriptions
+ public static final String CMD_CLONE = "clone";
+ public static final String CMD_CLONE_SC = "\\cl";
+
+ public static final String CMD_CREATE = "create";
+ public static final String CMD_CREATE_SC = "\\cr";
+
+ public static final String CMD_DELETE = "delete";
+ public static final String CMD_DELETE_SC = "\\d";
+
+ public static final String CMD_HELP = "help";
+ public static final String CMD_HELP_SC = "\\h";
+
+ public static final String CMD_SET = "set";
+ public static final String CMD_SET_SC = "\\st";
+
+ public static final String CMD_SHOW = "show";
+ public static final String CMD_SHOW_SC = "\\sh";
+
+ public static final String CMD_UPDATE = "update";
+ public static final String CMD_UPDATE_SC = "\\up";
+
+ public static final String CMD_START = "start";
+ public static final String CMD_START_SC = "\\sta";
+
+ public static final String CMD_STOP = "stop";
+ public static final String CMD_STOP_SC = "\\stp";
+
+ public static final String CMD_STATUS = "status";
+ public static final String CMD_STATUS_SC = "\\stu";
+
+ public static final String CMD_ENABLE = "enable";
+ public static final String CMD_ENABLE_SC = "\\en";
+
+ public static final String CMD_DISABLE = "disable";
+ public static final String CMD_DISABLE_SC = "\\di";
+
+ public static final String FN_CONNECTION = "connection";
+ public static final String FN_JOB = "job";
+ public static final String FN_SUBMISSION = "submission";
+ public static final String FN_SERVER = "server";
+ public static final String FN_OPTION = "option";
+ public static final String FN_CONNECTOR = "connector";
+ public static final String FN_VERSION = "version";
+ public static final String FN_FRAMEWORK = "framework";
+
+ public static final String PRE_CLONE = "Clone";
+ public static final String PRE_CREATE = "Create";
+ public static final String PRE_DELETE = "Delete";
+ public static final String PRE_SET = "Set";
+ public static final String PRE_SHOW = "Show";
+ public static final String PRE_UPDATE = "Update";
+ public static final String PRE_START = "Start";
+ public static final String PRE_STATUS = "Status";
+ public static final String PRE_STOP = "Stop";
+ public static final String PRE_ENABLE = "Enable";
+ public static final String PRE_DISABLE = "Disable";
+ public static final String SUF_INFO = "Info";
+
+
+ public static final String PROP_HOMEDIR = "user.home";
+ public static final String PROP_CURDIR = "user.dir";
+ public static final String SQOOP_PROMPT = "sqoop";
+
+
+ // 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 =
+ "args.jid_missing";
+ public static final String RES_ARGS_CID_MISSING =
+ "args.cid_missing";
+ public static final String RES_ARGS_TYPE_MISSING =
+ "args.type_missing";
+ public static final String RES_ARGS_NAME_MISSING =
+ "args.name_missing";
+ public static final String RES_ARGS_VALUE_MISSING =
+ "args.value_missing";
+
+ public static final String RES_PROMPT_CONN_ID =
+ "prompt.conn_id";
+ public static final String RES_PROMPT_JOB_ID =
+ "prompt.job_id";
+ public static final String RES_CONNECTOR_ID =
+ "prompt.connector_id";
+ public static final String RES_PROMPT_JOB_TYPE =
+ "prompt.job_type";
+ public static final String RES_PROMPT_UPDATE_CONN_METADATA =
+ "prompt.update_conn_metadata";
+ public static final String RES_PROMPT_UPDATE_JOB_METADATA =
+ "prompt.update_job_metadata";
+ public static final String RES_PROMPT_FILL_CONN_METADATA =
+ "prompt.fill_conn_metadata";
+ public static final String RES_PROMPT_FILL_JOB_METADATA =
+ "prompt.fill_job_metadata";
+
+ public static final String RES_CLONE_USAGE =
+ "clone.usage";
+ public static final String RES_CLONE_CONN_SUCCESSFUL =
+ "clone.conn.successful";
+ public static final String RES_CLONE_JOB_SUCCESSFUL =
+ "clone.job.successful";
+ public static final String RES_CLONE_CLONING_CONN =
+ "clone.cloning_conn";
+ public static final String RES_CLONE_CLONING_JOB =
+ "clone.cloning_job";
+
+ public static final String RES_CREATE_USAGE =
+ "create.usage";
+ public static final String RES_CREATE_CONN_SUCCESSFUL =
+ "create.conn_successful";
+ public static final String RES_CREATE_JOB_SUCCESSFUL =
+ "create.job_successful";
+ public static final String RES_CREATE_CREATING_CONN =
+ "create.creating_conn";
+ public static final String RES_CREATE_CREATING_JOB =
+ "create.creating_job";
+
+ public static final String RES_DELETE_USAGE =
+ "delete.usage";
+
+ public static final String RES_DISABLE_USAGE =
+ "disable.usage";
+ public static final String RES_DISABLE_CONNECTION_SUCCESSFUL =
+ "disable.conn_successful";
+ public static final String RES_DISABLE_JOB_SUCCESSFUL =
+ "disable.job_successful";
+
+ public static final String RES_ENABLE_USAGE =
+ "enable.usage";
+ public static final String RES_ENABLE_CONNECTION_SUCCESSFUL =
+ "enable.conn_successful";
+ public static final String RES_ENABLE_JOB_SUCCESSFUL =
+ "enable.job_successful";
+
+ public static final String RES_HELP_USAGE =
+ "help.usage";
+ public static final String RES_HELP_DESCRIPTION =
+ "help.description";
+ public static final String RES_HELP_CMD_USAGE =
+ "help.cmd_usage";
+ public static final String RES_HELP_MESSAGE =
+ "help.message";
+ public static final String RES_HELP_INFO =
+ "help.info";
+ public static final String RES_HELP_AVAIL_COMMANDS =
+ "help.avail_commands";
+ public static final String RES_HELP_CMD_DESCRIPTION =
+ "help.cmd_description";
+ public static final String RES_HELP_SPECIFIC_CMD_INFO =
+ "help.specific_cmd_info";
+
+ public static final String RES_UNRECOGNIZED_CMD =
+ "unrecognized.cmd";
+
+ public static final String RES_SET_USAGE =
+ "set.usage";
+ public static final String RES_SET_PROMPT_OPT_NAME =
+ "set.prompt_opt_name";
+ public static final String RES_SET_PROMPT_OPT_VALUE =
+ "set.prompt_opt_value";
+ public static final String RES_SET_VERBOSE_CHANGED =
+ "set.verbose_changed";
+ public static final String RES_SET_POLL_TIMEOUT_CHANGED =
+ "set.poll_timeout_changed";
+ public static final String RES_SET_UNKNOWN_OPT_IGNORED =
+ "set.unknown_opt_ignored";
+ public static final String RES_SET_HOST_DESCRIPTION =
+ "set.host_description";
+ public static final String RES_SET_PORT_DESCRIPTION =
+ "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";
+ public static final String RES_SHOW_PROMPT_DISPLAY_ALL_CONNS =
+ "show.prompt_display_all_conns";
+ public static final String RES_SHOW_PROMPT_DISPLAY_CONN_XID =
+ "show.prompt_display_conn_xid";
+ public static final String RES_SHOW_CONN_USAGE =
+ "show.conn_usage";
+ public static final String RES_SHOW_PROMPT_CONNS_TO_SHOW =
+ "show.prompt_conns_to_show";
+ public static final String RES_SHOW_PROMPT_CONN_INFO =
+ "show.prompt_conn_info";
+ public static final String RES_SHOW_PROMPT_CONN_CID_INFO =
+ "show.prompt_conn_cid_info";
+
+ public static final String RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS =
+ "show.prompt_display_all_connectors";
+ public static final String RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID =
+ "show.prompt_display_connector_cid";
+ public static final String RES_SHOW_CONNECTOR_USAGE =
+ "show.connector_usage";
+ public static final String RES_SHOW_PROMPT_CONNECTORS_TO_SHOW =
+ "show.prompt_connectors_to_show";
+ public static final String RES_SHOW_PROMPT_CONNECTOR_INFO =
+ "show.prompt_connector_info";
+
+ public static final String RES_SHOW_FRAMEWORK_USAGE =
+ "show.framework_usage";
+ public static final String RES_SHOW_PROMPT_FRAMEWORK_OPTS =
+ "show.prompt_framework_opts";
+
+ public static final String RES_SHOW_PROMPT_DISPLAY_ALL_JOBS =
+ "show.prompt_display_all_jobs";
+ public static final String RES_SHOW_PROMPT_DISPLAY_JOB_JID =
+ "show.prompt_display_job_jid";
+ public static final String RES_SHOW_JOB_USAGE =
+ "show.job_usage";
+ public static final String RES_SHOW_PROMPT_JOBS_TO_SHOW =
+ "show.prompt_jobs_to_show";
+ public static final String RES_SHOW_PROMPT_JOB_INFO =
+ "show.prompt_job_info";
+ public static final String RES_SHOW_PROMPT_JOB_XID_CID_INFO =
+ "show.prompt_job_xid_cid_info";
+
+ public static final String RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS =
+ "show.prompt_display_all_submissions";
+ public static final String RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS_JOB_ID =
+ "show.prompt_display_all_submissions_jid";
+
+ public static final String RES_SHOW_PROMPT_DISPLAY_ALL_SERVERS =
+ "show.prompt_display_all_servers";
+ public static final String RES_SHOW_PROMPT_DISPLAY_SERVER_HOST =
+ "show.prompt_display_server_host";
+ public static final String RES_SHOW_PROMPT_DISPLAY_SERVER_PORT =
+ "show.prompt_display_server_port";
+ public static final String RES_SHOW_PROMPT_DISPLAY_SERVER_WEBAPP =
+ "show.prompt_display_server_webapp";
+ public static final String RES_SHOW_SERVER_USAGE =
+ "show.server_usage";
+ public static final String RES_SHOW_PROMPT_SERVER_HOST =
+ "show.prompt_server_host";
+ public static final String RES_SHOW_PROMPT_SERVER_PORT =
+ "show.prompt_server_port";
+ public static final String RES_SHOW_PROMPT_SERVER_WEBAPP =
+ "show.prompt_server_webapp";
+
+ public static final String RES_SHOW_PROMPT_DISPLAY_ALL_VERSIONS =
+ "show.prompt_display_all_versions";
+ public static final String RES_SHOW_PROMPT_DISPLAY_VERSION_SERVER =
+ "show.prompt_display_version_server";
+ public static final String RES_SHOW_PROMPT_DISPLAY_VERSION_CLIENT =
+ "show.prompt_display_version_client";
+ public static final String RES_SHOW_PROMPT_DISPLAY_VERSION_PROTOCOL =
+ "show.prompt_display_version_protocol";
+ public static final String RES_SHOW_VERSION_USAGE =
+ "show.version_usage";
+ public static final String RES_SHOW_PROMPT_VERSION_CLIENT_SERVER =
+ "show.prompt_version_client_server";
+ public static final String RES_SHOW_PROMPT_VERSION_PROTOCOL =
+ "show.prompt_version_protocol";
+
+ public static final String RES_START_USAGE =
+ "start.usage";
+
+ public static final String RES_STATUS_USAGE =
+ "status.usage";
+ public static final String RES_PROMPT_SYNCHRONOUS =
+ "start.prompt_synchronous";
+
+ public static final String RES_STOP_USAGE =
+ "stop.usage";
+
+ public static final String RES_SQOOP_SHELL_BANNER =
+ "sqoop.shell_banner";
+ public static final String RES_SQOOP_PROMPT_SHELL_LOADRC =
+ "sqoop.prompt_shell_loadrc";
+ public static final String RES_SQOOP_PROMPT_SHELL_LOADEDRC =
+ "sqoop.prompt_shell_loadedrc";
+
+ public static final String RES_UPDATE_USAGE =
+ "update.usage";
+ public static final String RES_UPDATE_UPDATING_CONN =
+ "update.conn";
+ public static final String RES_UPDATE_CONN_SUCCESSFUL =
+ "update.conn_successful";
+ public static final String RES_UPDATE_UPDATING_JOB =
+ "update.job";
+ public static final String RES_UPDATE_JOB_SUCCESSFUL =
+ "update.job_successful";
+
+ public static final String RES_TABLE_HEADER_ID =
+ "table.header.id";
+ public static final String RES_TABLE_HEADER_NAME =
+ "table.header.name";
+ public static final String RES_TABLE_HEADER_VERSION =
+ "table.header.version";
+ public static final String RES_TABLE_HEADER_CLASS =
+ "table.header.class";
+ public static final String RES_TABLE_HEADER_TYPE =
+ "table.header.type";
+ public static final String RES_TABLE_HEADER_CONNECTOR =
+ "table.header.connector";
+ public static final String RES_TABLE_HEADER_JOB_ID =
+ "table.header.jid";
+ public static final String RES_TABLE_HEADER_EXTERNAL_ID =
+ "table.header.eid";
+ public static final String RES_TABLE_HEADER_STATUS =
+ "table.header.status";
+ public static final String RES_TABLE_HEADER_DATE =
+ "table.header.date";
+ public static final String RES_TABLE_HEADER_ENABLED =
+ "table.header.enabled";
+
+ public static final String RES_FORMDISPLAYER_SUPPORTED_JOBTYPE =
+ "formdisplayer.supported_job_types";
+ public static final String RES_FORMDISPLAYER_CONNECTION =
+ "formdisplayer.connection";
+ public static final String RES_FORMDISPLAYER_JOB =
+ "formdisplayer.job";
+ public static final String RES_FORMDISPLAYER_FORM_JOBTYPE =
+ "formdisplayer.forms_jobtype";
+ public static final String RES_FORMDISPLAYER_FORM =
+ "formdisplayer.form";
+ public static final String RES_FORMDISPLAYER_NAME =
+ "formdisplayer.name";
+ public static final String RES_FORMDISPLAYER_LABEL =
+ "formdisplayer.label";
+ public static final String RES_FORMDISPLAYER_HELP =
+ "formdisplayer.help";
+ public static final String RES_FORMDISPLAYER_INPUT =
+ "formdisplayer.input";
+ public static final String RES_FORMDISPLAYER_TYPE =
+ "formdisplayer.type";
+ public static final String RES_FORMDISPLAYER_SENSITIVE =
+ "formdisplayer.sensitive";
+ public static final String RES_FORMDISPLAYER_SIZE =
+ "formdisplayer.size";
+ public static final String RES_FORMDISPLAYER_POSSIBLE_VALUES =
+ "formdisplayer.possible_values";
+ public static final String RES_FORMDISPLAYER_UNSUPPORTED_DATATYPE =
+ "formdisplayer.unsupported_datatype";
+ public static final String RES_FORMDISPLAYER_INPUT_SENSITIVE =
+ "formdisplayer.input_sensitive";
+
+ public static final String RES_FORMDISPLAYER_FORM_WARNING =
+ "formdisplayer.warning_message";
+
+ public static final String RES_SUBMISSION_SUBMISSION_DETAIL =
+ "submission.submission_detail";
+ public static final String RES_SUBMISSION_JOB_ID =
+ "submission.job_id";
+ public static final String RES_SUBMISSION_CREATION_DATE =
+ "submission.creation_date";
+ public static final String RES_SUBMISSION_EXTERNAL_ID =
+ "submission.external_id";
+ public static final String RES_SUBMISSION_PROGRESS_NOT_AVAIL =
+ "submission.progress_not_available";
+ public static final String RES_SUBMISSION_COUNTERS =
+ "submission.counters";
+ public static final String RES_SUBMISSION_EXECUTED_SUCCESS =
+ "submission.executed_success";
+ public static final String RES_SUBMISSION_SERVER_URL =
+ "submission.server_url";
+ public static final String RES_CONNECTOR_SCHEMA =
+ "submission.connector_schema";
+ public static final String RES_HIO_SCHEMA =
+ "submission.hio_schema";
+
+ private Constants() {
+ // Instantiation is prohibited
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/core/ShellError.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/core/ShellError.java b/shell/src/main/java/org/apache/sqoop/shell/core/ShellError.java
new file mode 100644
index 0000000..e5a99f1
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/core/ShellError.java
@@ -0,0 +1,66 @@
+/**
+ * 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.shell.core;
+
+import org.apache.sqoop.common.ErrorCode;
+
+public enum ShellError implements ErrorCode {
+
+ /** An unknown error has occurred. */
+ SHELL_0000("An unknown error has occurred"),
+
+ /** The specified command is not recognized. */
+ SHELL_0001("The specified command is not recognized"),
+
+ /** The specified function is not recognized. */
+ SHELL_0002("The specified function is not recognized"),
+
+ /** An error has occurred when parsing options. */
+ SHELL_0003("An error has occurred when parsing options"),
+
+ /** Unable to resolve the variables. */
+ SHELL_0004("Unable to resolve the variables"),
+
+ /** We're not able to get user input */
+ SHELL_0005("Can't get user input"),
+
+ /** There occurred exception on server side **/
+ SHELL_0006("Server has returned exception"),
+
+ /** Command not compatible with batch mode */
+ SHELL_0007("Command not compatible with batch mode"),
+
+ /** Job Submission : Cannot sleep */
+ SHELL_0008("Cannot sleep"),
+
+ ;
+
+ private final String message;
+
+ private ShellError(String message) {
+ this.message = message;
+ }
+
+ public String getCode() {
+ return name();
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/utils/FormDisplayer.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/utils/FormDisplayer.java b/shell/src/main/java/org/apache/sqoop/shell/utils/FormDisplayer.java
new file mode 100644
index 0000000..56e0b4e
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/utils/FormDisplayer.java
@@ -0,0 +1,249 @@
+/**
+ * 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.shell.utils;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sqoop.model.MAccountableEntity;
+import org.apache.sqoop.model.MBooleanInput;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.model.MEnumInput;
+import org.apache.sqoop.model.MForm;
+import org.apache.sqoop.model.MFramework;
+import org.apache.sqoop.model.MInput;
+import org.apache.sqoop.model.MInputType;
+import org.apache.sqoop.model.MIntegerInput;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MJobForms;
+import org.apache.sqoop.model.MMapInput;
+import org.apache.sqoop.model.MStringInput;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Convenience static methods for displaying form related information
+ */
+public final class FormDisplayer {
+
+ public static void displayFormMetadataDetails(MFramework framework,
+ ResourceBundle bundle) {
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SUPPORTED_JOBTYPE));
+ println(framework.getAllJobsForms().keySet().toString());
+
+ displayFormsMetadata(
+ framework.getConnectionForms().getForms(),
+ resourceString(Constants.RES_FORMDISPLAYER_CONNECTION),
+ bundle);
+
+ for (MJobForms jobForms : framework.getAllJobsForms().values()) {
+ print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_FORM_JOBTYPE));
+ print(jobForms.getType().name());
+ println(":");
+
+ displayFormsMetadata(jobForms.getForms(), resourceString(Constants.RES_FORMDISPLAYER_JOB), bundle);
+ }
+ }
+
+ public static void displayFormsMetadata(List<MForm> forms,
+ String type,
+ ResourceBundle bundle) {
+ Iterator<MForm> fiter = forms.iterator();
+ int findx = 1;
+ while (fiter.hasNext()) {
+ print(" ");
+ print(type);
+ print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_FORM));
+ print(findx++);
+ println(":");
+
+ MForm form = fiter.next();
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_NAME));
+ println(form.getName());
+
+ // Label
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_LABEL));
+ println(bundle.getString(form.getLabelKey()));
+
+ // Help text
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_HELP));
+ println(bundle.getString(form.getHelpKey()));
+
+ List<MInput<?>> inputs = form.getInputs();
+ Iterator<MInput<?>> iiter = inputs.iterator();
+ int iindx = 1;
+ while (iiter.hasNext()) {
+ print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_INPUT));
+ print(iindx++);
+ println(":");
+
+ MInput<?> input = iiter.next();
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_NAME));
+ println(input.getName());
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_LABEL));
+ println(bundle.getString(input.getLabelKey()));
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_HELP));
+ println(bundle.getString(input.getHelpKey()));
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_TYPE));
+ println(input.getType());
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SENSITIVE));
+ println(input.isSensitive());
+ if (input.getType() == MInputType.STRING) {
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SIZE));
+ println(((MStringInput)input).getMaxLength());
+ } else if(input.getType() == MInputType.ENUM) {
+ print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_POSSIBLE_VALUES));
+ println(StringUtils.join(((MEnumInput)input).getValues(), ","));
+ }
+ }
+ }
+ }
+
+ public static void displayForms(List<MForm> forms, ResourceBundle bundle) {
+ for(MForm form : forms) {
+ displayForm(form, bundle);
+ }
+ }
+
+ /**
+ * Method prints the warning message of ACCEPTABLE status
+ * @param entity - connection or job instance
+ */
+ public static void displayFormWarning(MAccountableEntity entity) {
+ List<MForm> formList = new ArrayList<MForm>();
+ boolean showMessage = true;
+ if (entity instanceof MConnection) {
+ MConnection connection = (MConnection) entity;
+ formList.addAll(connection.getConnectorPart().getForms());
+ formList.addAll(connection.getFrameworkPart().getForms());
+ } else if(entity instanceof MJob) {
+ MJob job = (MJob) entity;
+ formList.addAll(job.getConnectorPart().getForms());
+ formList.addAll(job.getFrameworkPart().getForms());
+ }
+ for(MForm form : formList) {
+ if(form.getValidationStatus() == Status.ACCEPTABLE) {
+ if(showMessage) {
+ print("\n@|yellow %s|@\n", resourceString(Constants.RES_FORMDISPLAYER_FORM_WARNING));
+ showMessage = false;
+ }
+ FormFiller.warningMessage(form.getValidationMessage());
+ }
+ }
+ }
+
+ private static void displayForm(MForm form, ResourceBundle bundle) {
+ print(" ");
+ println(bundle.getString(form.getLabelKey()));
+
+ for (MInput<?> input : form.getInputs()) {
+ print(" ");
+ print(bundle.getString(input.getLabelKey()));
+ print(": ");
+ if(!input.isEmpty()) {
+ if (input.isSensitive()) {
+ print("(%s)", resourceString(Constants.RES_FORMDISPLAYER_INPUT_SENSITIVE));
+ } else {
+ // Based on the input type, let's perform specific load
+ switch (input.getType()) {
+ case STRING:
+ displayInputString((MStringInput) input);
+ break;
+ case INTEGER:
+ displayInputInteger((MIntegerInput) input);
+ break;
+ case BOOLEAN:
+ displayInputBoolean((MBooleanInput) input);
+ break;
+ case MAP:
+ displayInputMap((MMapInput) input);
+ break;
+ case ENUM:
+ displayInputEnum((MEnumInput) input);
+ break;
+ default:
+ print("\n%s " + input.getType(), resourceString(Constants.RES_FORMDISPLAYER_UNSUPPORTED_DATATYPE));
+ return;
+ }
+ }
+ }
+ println("");
+ }
+ }
+
+ /**
+ * Display content of String input.
+ *
+ * @param input String input
+ */
+ private static void displayInputString(MStringInput input) {
+ print(input.getValue());
+ }
+
+ /**
+ * Display content of Integer input.
+ *
+ * @param input Integer input
+ */
+ private static void displayInputInteger(MIntegerInput input) {
+ print(input.getValue());
+ }
+
+ /**
+ * Display content of Boolean input.
+ *
+ * @param input Boolean input
+ */
+ private static void displayInputBoolean(MBooleanInput input) {
+ print(input.getValue());
+ }
+
+ /**
+ * Display content of Map input
+ *
+ * @param input Map input
+ */
+ private static void displayInputMap(MMapInput input) {
+ for(Map.Entry<String, String> entry : input.getValue().entrySet()) {
+ println();
+ print(" ");
+ print(entry.getKey());
+ print(" = ");
+ print(entry.getValue());
+ }
+ }
+
+ /**
+ * Display content of Enum input
+ *
+ * @param input Enum input
+ */
+ private static void displayInputEnum(MEnumInput input) {
+ print(input.getValue());
+ }
+
+ private FormDisplayer() {
+ // Do not instantiate
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/utils/FormFiller.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/utils/FormFiller.java b/shell/src/main/java/org/apache/sqoop/shell/utils/FormFiller.java
new file mode 100644
index 0000000..9bc0b93
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/utils/FormFiller.java
@@ -0,0 +1,566 @@
+/**
+ * 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.shell.utils;
+
+import jline.ConsoleReader;
+import org.apache.sqoop.model.MBooleanInput;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.model.MEnumInput;
+import org.apache.sqoop.model.MForm;
+import org.apache.sqoop.model.MInput;
+import org.apache.sqoop.model.MIntegerInput;
+import org.apache.sqoop.model.MMapInput;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MStringInput;
+import org.apache.sqoop.model.MValidatedElement;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Convenient methods for retrieving user input.
+ */
+public final class FormFiller {
+
+ /**
+ * Internal input that will be reused for loading names for connection and
+ * job objects.
+ */
+ private static MStringInput nameInput = new MStringInput("object-name", false, (short)25);
+
+ /**
+ * Fill job object based on user input.
+ *
+ * @param reader Associated console reader object
+ * @param job Job that user is suppose to fill in
+ * @param connectorBundle Connector resource bundle
+ * @param frameworkBundle Framework resource bundle
+ * @return True if we filled all inputs, false if user has stopped processing
+ * @throws IOException
+ */
+ public static boolean fillJob(ConsoleReader reader,
+ MJob job,
+ ResourceBundle connectorBundle,
+ ResourceBundle frameworkBundle)
+ throws IOException {
+
+ job.setName(getName(reader, job.getName()));
+
+ // Fill in data from user
+ return fillForms(reader,
+ job.getConnectorPart().getForms(),
+ connectorBundle,
+ job.getFrameworkPart().getForms(),
+ frameworkBundle);
+ }
+
+ /**
+ * Fill connection object based on user input.
+ *
+ * @param reader Associated console reader object
+ * @param connection Connection that user is suppose to fill in
+ * @param connectorBundle Connector resource bundle
+ * @param frameworkBundle Framework resouce bundle
+ * @return True if we filled all inputs, false if user has stopped processing
+ * @throws IOException
+ */
+ public static boolean fillConnection(ConsoleReader reader,
+ MConnection connection,
+ ResourceBundle connectorBundle,
+ ResourceBundle frameworkBundle)
+ throws IOException {
+
+ connection.setName(getName(reader, connection.getName()));
+
+ // Fill in data from user
+ return fillForms(reader,
+ connection.getConnectorPart().getForms(),
+ connectorBundle,
+ connection.getFrameworkPart().getForms(),
+ frameworkBundle);
+ }
+
+ public static boolean fillForms(ConsoleReader reader,
+ List<MForm> connectorForms,
+ ResourceBundle connectorBundle,
+ List<MForm> frameworkForms,
+ ResourceBundle frameworkBundle
+ ) throws IOException {
+
+
+ // Query connector forms
+ if(!fillForms(connectorForms, reader, connectorBundle)) {
+ return false;
+ }
+
+ // Query framework forms
+ if(!fillForms(frameworkForms, reader, frameworkBundle)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public static boolean fillForms(List<MForm> forms,
+ ConsoleReader reader,
+ ResourceBundle bundle)
+ throws IOException {
+ for (MForm form : forms) {
+ if(!fillForm(form, reader, bundle)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean fillForm(MForm form,
+ ConsoleReader reader,
+ ResourceBundle bundle) throws IOException {
+ println("");
+ println(bundle.getString(form.getLabelKey()));
+
+ // Print out form validation
+ printValidationMessage(form);
+ println("");
+
+ for (MInput input : form.getInputs()) {
+ if(!fillInput(input, reader, bundle)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean fillInput(MInput input,
+ ConsoleReader reader,
+ ResourceBundle bundle) throws IOException {
+ // Print out validation
+ printValidationMessage(input);
+
+ // Based on the input type, let's perform specific load
+ switch (input.getType()) {
+ case STRING:
+ return fillInputString((MStringInput) input, reader, bundle);
+ case INTEGER:
+ return fillInputInteger((MIntegerInput) input, reader, bundle);
+ case BOOLEAN:
+ return fillInputBoolean((MBooleanInput) input, reader, bundle);
+ case MAP:
+ return fillInputMap((MMapInput) input, reader, bundle);
+ case ENUM:
+ return fillInputEnum((MEnumInput) input, reader, bundle);
+ default:
+ println("Unsupported data type " + input.getType());
+ return true;
+ }
+ }
+
+ /**
+ * Load user input for enum type.
+ *
+ * Print out numbered list of all available options and let user choose one
+ * item from that.
+ *
+ * @param input Input that we should read or edit
+ * @param reader Associated console reader
+ * @param bundle Resource bundle
+ * @return True if user with to continue with loading addtional inputs
+ * @throws IOException
+ */
+ private static boolean fillInputEnum(MEnumInput input,
+ ConsoleReader reader,
+ ResourceBundle bundle)
+ throws IOException {
+ // Prompt in enum case
+ println(bundle.getString(input.getLabelKey()) + ": ");
+
+ // Indexes
+ int i = -1;
+ int lastChoice = -1;
+
+ // Print out all values as a numbered list
+ for(String value : input.getValues()) {
+ i++;
+
+ println(" " + i + " : " + value);
+
+ // Only show last choice if not sensitive
+ if(!input.isEmpty() && value.equals(input.getValue()) && !input.isSensitive()) {
+ lastChoice = i;
+ }
+ }
+
+ // Prompt
+ reader.printString("Choose: ");
+
+ // Fill previously filled index when available
+ if(lastChoice != -1) {
+ reader.putString(Integer.toString(lastChoice));
+ }
+
+ reader.flushConsole();
+ String userTyped;
+ if(input.isSensitive()) {
+ userTyped = reader.readLine('*');
+ } else {
+ userTyped = reader.readLine();
+ }
+
+ if (userTyped == null) {
+ return false;
+ } else if (userTyped.isEmpty()) {
+ input.setEmpty();
+ } else {
+ Integer index;
+ try {
+ index = Integer.valueOf(userTyped);
+
+ if(index < 0 || index >= input.getValues().length) {
+ errorMessage("Invalid index");
+ return fillInputEnum(input, reader, bundle);
+ }
+
+ input.setValue(input.getValues()[index]);
+ } catch (NumberFormatException ex) {
+ errorMessage("Input is not valid integer number");
+ return fillInputEnum(input, reader, bundle);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Load user input for map type.
+ *
+ * This implementation will load one map entry at the time. Current flows is
+ * as follows: if user did not enter anything (empty input) finish loading
+ * and return from function. If user specified input with equal sign (=),
+ * lets add new key value pair. Otherwise consider entire input as a key name
+ * and try to remove it from the map.
+ *
+ * Please note that following code do not supports equal sign in property
+ * name. It's however perfectly fine to have equal sign in value.
+ *
+ * @param input Input that we should read or edit
+ * @param reader Associated console reader
+ * @param bundle Resource bundle
+ * @return True if user wish to continue with loading additional inputs
+ * @throws IOException
+ */
+ private static boolean fillInputMap(MMapInput input,
+ ConsoleReader reader,
+ ResourceBundle bundle)
+ throws IOException {
+ // Special prompt in Map case
+ println(bundle.getString(input.getLabelKey()) + ": ");
+
+ // Internal loading map
+ Map<String, String> values = input.getValue();
+ if(values == null) {
+ values = new HashMap<String, String>();
+ }
+
+ String userTyped;
+
+ while(true) {
+ // Print all current items in each iteration
+ // However do not printout if this input contains sensitive information.
+ println("There are currently " + values.size() + " values in the map:");
+ if (!input.isSensitive()) {
+ for(Map.Entry<String, String> entry : values.entrySet()) {
+ println(entry.getKey() + " = " + entry.getValue());
+ }
+ }
+
+ // Special prompt for Map entry
+ reader.printString("entry# ");
+ reader.flushConsole();
+
+ if(input.isSensitive()) {
+ userTyped = reader.readLine('*');
+ } else {
+ userTyped = reader.readLine();
+ }
+
+ if(userTyped == null) {
+ // Finish loading and return back to Sqoop shell
+ return false;
+ } else if(userTyped.isEmpty()) {
+ // User has finished loading data to Map input, either set input empty
+ // if there are no entries or propagate entries to the input
+ if(values.size() == 0) {
+ input.setEmpty();
+ } else {
+ input.setValue(values);
+ }
+ return true;
+ } else {
+ // User has specified regular input, let's check if it contains equals
+ // sign. Save new entry (or update existing one) if it does. Otherwise
+ // try to remove entry that user specified.
+ if(userTyped.contains("=")) {
+ String []keyValue = userTyped.split("=", 2);
+ values.put(handleUserInput(keyValue[0]), handleUserInput(keyValue[1]));
+ } else {
+ String key = handleUserInput(userTyped);
+ if(values.containsKey(key)) {
+ values.remove(key);
+ } else {
+ errorMessage("Don't know what to do with " + userTyped);
+ }
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Handle special cases in user input.
+ *
+ * Preserve null and empty values, remove whitespace characters before and
+ * after loaded string and de-quote the string if it's quoted (to preserve
+ * spaces for example).
+ *
+ * @param input String loaded from user
+ * @return Unquoted transformed string
+ */
+ private static String handleUserInput(String input) {
+ // Preserve null and empty values
+ if(input == null) {
+ return null;
+ }
+ if(input.isEmpty()) {
+ return input;
+ }
+
+ // Removes empty characters at the begging and end of loaded string
+ input = input.trim();
+
+ int lastIndex = input.length() - 1;
+ char first = input.charAt(0);
+ char last = input.charAt(lastIndex);
+
+ // Remove quoting if present
+ if(first == '\'' && last == '\'') {
+ input = input.substring(1, lastIndex);
+ } else if(first == '"' && last == '"') {
+ input = input.substring(1, lastIndex);
+ }
+
+ // Return final string
+ return input;
+ }
+
+ private static boolean fillInputInteger(MIntegerInput input,
+ ConsoleReader reader,
+ ResourceBundle bundle)
+ throws IOException {
+ generatePrompt(reader, bundle, input);
+
+ // Fill already filled data when available
+ // However do not printout if this input contains sensitive information.
+ if(!input.isEmpty() && !input.isSensitive()) {
+ reader.putString(input.getValue().toString());
+ }
+
+ // Get the data
+ String userTyped;
+ if(input.isSensitive()) {
+ userTyped = reader.readLine('*');
+ } else {
+ userTyped = reader.readLine();
+ }
+
+ if (userTyped == null) {
+ return false;
+ } else if (userTyped.isEmpty()) {
+ input.setEmpty();
+ } else {
+ Integer value;
+ try {
+ value = Integer.valueOf(userTyped);
+ input.setValue(value);
+ } catch (NumberFormatException ex) {
+ errorMessage("Input is not valid integer number");
+ return fillInputInteger(input, reader, bundle);
+ }
+
+ input.setValue(Integer.valueOf(userTyped));
+ }
+
+ return true;
+ }
+
+ /**
+ * Load string input from the user.
+ *
+ * @param input Input that we should load in
+ * @param reader Associated console reader
+ * @param bundle Resource bundle for this input
+ * @return
+ * @throws IOException
+ */
+ public static boolean fillInputString(MStringInput input,
+ ConsoleReader reader,
+ ResourceBundle bundle)
+ throws IOException {
+ generatePrompt(reader, bundle, input);
+
+ // Fill already filled data when available
+ // However do not printout if this input contains sensitive information.
+ if(!input.isEmpty() && !input.isSensitive()) {
+ reader.putString(input.getValue());
+ }
+
+ // Get the data
+ String userTyped;
+ if(input.isSensitive()) {
+ userTyped = reader.readLine('*');
+ } else {
+ userTyped = reader.readLine();
+ }
+
+ if (userTyped == null) {
+ // Propagate end of loading process
+ return false;
+ } else if (userTyped.isEmpty()) {
+ // Empty input in case that nothing was given
+ input.setEmpty();
+ } else {
+ // Set value that user has entered
+ input.setValue(userTyped);
+
+ // Check that it did not exceeds maximal allowance for given input
+ if(userTyped.length() > input.getMaxLength()) {
+ errorMessage("Size of input exceeds allowance for this input"
+ + " field. Maximal allowed size is " + input.getMaxLength());
+ return fillInputString(input, reader, bundle);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Load boolean input from the user.
+ *
+ * @param input Input that we should load in
+ * @param reader Associated console reader
+ * @param bundle Resource bundle for this input
+ * @return
+ * @throws IOException
+ */
+ public static boolean fillInputBoolean(MBooleanInput input,
+ ConsoleReader reader,
+ ResourceBundle bundle)
+ throws IOException {
+ generatePrompt(reader, bundle, input);
+
+ // Fill already filled data when available
+ // However do not printout if this input contains sensitive information.
+ if(!input.isEmpty() && !input.isSensitive()) {
+ reader.putString(input.getValue().toString());
+ }
+
+ // Get the data
+ String userTyped;
+ if(input.isSensitive()) {
+ userTyped = reader.readLine('*');
+ } else {
+ userTyped = reader.readLine();
+ }
+
+ if (userTyped == null) {
+ // Propagate end of loading process
+ return false;
+ } else if (userTyped.isEmpty()) {
+ // Empty input in case that nothing was given
+ input.setEmpty();
+ } else {
+ // Set value that user has entered
+ input.setValue(Boolean.valueOf(userTyped));
+ }
+
+ return true;
+ }
+
+ public static void generatePrompt(ConsoleReader reader,
+ ResourceBundle bundle,
+ MInput input)
+ throws IOException {
+ reader.printString(bundle.getString(input.getLabelKey()) + ": ");
+ reader.flushConsole();
+ }
+
+ public static String getName(ConsoleReader reader,
+ String name) throws IOException {
+ if(name == null) {
+ nameInput.setEmpty();
+ } else {
+ nameInput.setValue(name);
+ }
+
+ fillInputString(nameInput, reader, getResourceBundle());
+
+ return nameInput.getValue();
+ }
+
+ /**
+ * Print validation message in cases that it's not in state "FINE"
+ *
+ * @param element Validated element
+ */
+ public static void printValidationMessage(MValidatedElement element) {
+ switch (element.getValidationStatus()) {
+ case UNACCEPTABLE:
+ errorMessage(element.getValidationMessage());
+ break;
+ case ACCEPTABLE:
+ warningMessage(element.getValidationMessage());
+ break;
+ default:
+ // Simply ignore all other states for the moment
+ break;
+ }
+ }
+
+ public static void errorMessage(String message) {
+ println("Error message: @|red " + message + " |@");
+ }
+
+ public static void warningMessage(String message) {
+ println("Warning message: @|yellow " + message + " |@");
+ }
+
+ public static void errorIntroduction() {
+ println();
+ println("@|red There are issues with entered data, please revise your input:|@");
+ }
+
+ private FormFiller() {
+ // Do not instantiate
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/utils/SubmissionDisplayer.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/utils/SubmissionDisplayer.java b/shell/src/main/java/org/apache/sqoop/shell/utils/SubmissionDisplayer.java
new file mode 100644
index 0000000..1f61fb2
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/utils/SubmissionDisplayer.java
@@ -0,0 +1,148 @@
+/**
+ * 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.shell.utils;
+
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.submission.SubmissionStatus;
+import org.apache.sqoop.submission.counter.Counter;
+import org.apache.sqoop.submission.counter.CounterGroup;
+import org.apache.sqoop.submission.counter.Counters;
+
+import java.text.SimpleDateFormat;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Class used for displaying or printing the submission details
+ */
+public final class SubmissionDisplayer {
+
+ private final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
+
+ /**
+ * On job submission, displays the initial job info
+ * @param submission
+ */
+ public static void displayHeader(MSubmission submission) {
+ println("@|bold "+ resourceString(Constants.RES_SUBMISSION_SUBMISSION_DETAIL) +"|@");
+
+ print(resourceString(Constants.RES_SUBMISSION_JOB_ID)+": ");
+ println(submission.getJobId());
+
+ print(resourceString(Constants.RES_SUBMISSION_SERVER_URL)+": ");
+ println(getServerUrl());
+
+ print(resourceString(Constants.RES_SUBMISSION_CREATION_DATE)+": ");
+ println(dateFormat.format(submission.getCreationDate()));
+
+ String externalId = submission.getExternalId();
+ if(externalId != null) {
+ print(resourceString(Constants.RES_SUBMISSION_EXTERNAL_ID)+": ");
+ println(externalId);
+
+ String externalLink = submission.getExternalLink();
+ if(externalLink != null) {
+ println("\t" + externalLink);
+ }
+ }
+
+ if(isVerbose() && submission.getConnectorSchema() != null) {
+ print(resourceString(Constants.RES_CONNECTOR_SCHEMA)+": ");
+ println(submission.getConnectorSchema());
+ }
+
+ if(isVerbose() && submission.getHioSchema() != null) {
+ print(resourceString(Constants.RES_HIO_SCHEMA)+": ");
+ println(submission.getHioSchema());
+ }
+ }
+
+ /**
+ * Displays the progress of the executing job
+ * @param submission
+ */
+ public static void displayProgress(MSubmission submission) {
+ StringBuilder sb = new StringBuilder();
+ if(submission.getStatus().isRunning()) {
+ sb.append(dateFormat.format(submission.getLastUpdateDate())+": @|green "+submission.getStatus()+ " |@");
+ double progress = submission.getProgress();
+ sb.append(" - ");
+ if(progress == -1) {
+ sb.append(resourceString(Constants.RES_SUBMISSION_PROGRESS_NOT_AVAIL));
+ } else {
+ sb.append(String.format("%.2f %%", progress * 100));
+ }
+ } else {
+ sb.append(dateFormat.format(submission.getLastUpdateDate())+": "+submission.getStatus());
+ }
+
+ println(sb.toString());
+ }
+
+ /**
+ * On successfull or error, method is invoked
+ * @param submission
+ */
+ public static void displayFooter(MSubmission submission) {
+ if (submission.getStatus().toString().equals(SubmissionStatus.SUCCEEDED.toString())) {
+ println(dateFormat.format(submission.getLastUpdateDate())+": @|green "+submission.getStatus()+ " |@");
+ Counters counters = submission.getCounters();
+ if (counters != null) {
+ println(resourceString(Constants.RES_SUBMISSION_COUNTERS) + ":");
+ for (CounterGroup group : counters) {
+ print("\t");
+ println(group.getName());
+ for (Counter counter : group) {
+ print("\t\t");
+ print(counter.getName());
+ print(": ");
+ println(counter.getValue());
+ }
+ }
+ println(resourceString(Constants.RES_SUBMISSION_EXECUTED_SUCCESS));
+ }
+ } else {
+ if (submission.getStatus().isFailure()) {
+ println(dateFormat.format(submission.getLastUpdateDate())+": @|red "+submission.getStatus()+ " |@");
+ } else {
+ println(dateFormat.format(submission.getLastUpdateDate())+": "+submission.getStatus());
+ }
+ // Exception handling
+ if (submission.getExceptionInfo() != null) {
+ print("@|red Exception: |@");
+ println(submission.getExceptionInfo());
+
+ if (isVerbose() && submission.getExceptionStackTrace() != null) {
+ print("@|bold Stack trace: |@");
+ println(submission.getExceptionStackTrace());
+ }
+ }
+ }
+ }
+
+ public static void displaySubmission(MSubmission submission) {
+ if(submission.getStatus().isFailure() || submission.getStatus().equals(SubmissionStatus.SUCCEEDED)) {
+ SubmissionDisplayer.displayHeader(submission);
+ SubmissionDisplayer.displayFooter(submission);
+ } else {
+ SubmissionDisplayer.displayHeader(submission);
+ SubmissionDisplayer.displayProgress(submission);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/utils/TableDisplayer.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/utils/TableDisplayer.java b/shell/src/main/java/org/apache/sqoop/shell/utils/TableDisplayer.java
new file mode 100644
index 0000000..51030d0
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/utils/TableDisplayer.java
@@ -0,0 +1,141 @@
+/**
+ * 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.shell.utils;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Display table based data
+ */
+public class TableDisplayer {
+
+ /**
+ * Display given columns in nice table structure to given IO object.
+ *
+ * @param headers List of headers
+ * @param columns Array of columns
+ */
+ public static void display(List<String> headers, List<String> ...columns) {
+ assert headers != null;
+ assert columns != null;
+ assert headers.size() == columns.length;
+
+ // Count of columns
+ int columnCount = headers.size();
+
+ // List of all maximal widths of each column
+ List<Integer> widths = new LinkedList<Integer>();
+ for(int i = 0; i < columnCount; i++) {
+ widths.add(getMaximalWidth(headers.get(i), columns[i]));
+ }
+
+ // First line is border
+ drawLine(widths);
+
+ // Print out header (text is centralised)
+ print("| ");
+ for(int i = 0 ; i < columnCount; i++) {
+ print(StringUtils.center(headers.get(i), widths.get(i), ' '));
+ print((i == columnCount -1) ? " |" : " | ");
+ }
+ println();
+
+ // End up header by border
+ drawLine(widths);
+
+ // Number of rows in the table
+ int rows = getMaximalRows(columns);
+
+ // Print out each row
+ for(int row = 0 ; row < rows; row++) {
+ print("| ");
+ for(int i = 0 ; i < columnCount; i++) {
+ print(StringUtils.rightPad(columns[i].get(row), widths.get(i), ' '));
+ print((i == columnCount -1) ? " |" : " | ");
+ }
+ println();
+ }
+
+ // End table by final border
+ drawLine(widths);
+ }
+
+ /**
+ * Draw border line
+ *
+ * @param widths List of widths of each column
+ */
+ private static void drawLine(List<Integer> widths) {
+ int last = widths.size() - 1;
+ print("+-");
+ for(int i = 0; i < widths.size(); i++) {
+ print(StringUtils.repeat("-", widths.get(i)));
+ print((i == last) ? "-+" : "-+-");
+ }
+ println();
+ }
+
+ /**
+ * Get maximal width for given column with it's associated header.
+ *
+ * @param header Associated header
+ * @param column All column values
+ * @return Maximal
+ */
+ private static int getMaximalWidth(String header, List<String> column) {
+ assert header != null;
+ assert column != null;
+
+ int max = header.length();
+
+ for(String value : column) {
+ if(value != null && value.length() > max) {
+ max = value.length();
+ }
+ }
+
+ return max;
+ }
+
+ /**
+ * Get maximal number of rows available in the column list
+ *
+ * @param columns Array with all column values
+ * @return
+ */
+ private static int getMaximalRows(List<String>... columns) {
+ int max = 0;
+
+ for(List<String> column : columns) {
+ if(column.size() > max) {
+ max = column.size();
+ }
+ }
+
+ return max;
+ }
+
+ private TableDisplayer() {
+ // Instantiation is prohibited
+ }
+}
[6/6] git commit: SQOOP-921. Sqoop2: Create standalone shell package
Posted by hs...@apache.org.
SQOOP-921. Sqoop2: Create standalone shell package
(Mengwei Ding via Hari Shreedharan)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/21c1207b
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/21c1207b
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/21c1207b
Branch: refs/heads/sqoop2
Commit: 21c1207b7952c0f2515c892324cbbf0c951fccca
Parents: ff8e050
Author: Hari Shreedharan <hs...@apache.org>
Authored: Tue Aug 6 16:18:58 2013 -0700
Committer: Hari Shreedharan <hs...@apache.org>
Committed: Tue Aug 6 16:21:39 2013 -0700
----------------------------------------------------------------------
client/pom.xml | 60 +-
.../org/apache/sqoop/client/ClientError.java | 48 ++
.../org/apache/sqoop/client/SqoopClient.java | 3 +-
.../apache/sqoop/client/core/ClientError.java | 69 ---
.../org/apache/sqoop/client/core/Constants.java | 451 ---------------
.../apache/sqoop/client/request/Request.java | 5 +-
.../apache/sqoop/client/shell/CloneCommand.java | 69 ---
.../client/shell/CloneConnectionFunction.java | 96 ----
.../sqoop/client/shell/CloneJobFunction.java | 99 ----
.../sqoop/client/shell/CreateCommand.java | 69 ---
.../client/shell/CreateConnectionFunction.java | 93 ---
.../sqoop/client/shell/CreateJobFunction.java | 106 ----
.../sqoop/client/shell/DeleteCommand.java | 64 ---
.../client/shell/DeleteConnectionFunction.java | 50 --
.../sqoop/client/shell/DeleteJobFunction.java | 58 --
.../sqoop/client/shell/DisableCommand.java | 64 ---
.../client/shell/DisableConnectionFunction.java | 51 --
.../sqoop/client/shell/DisableJobFunction.java | 59 --
.../sqoop/client/shell/EnableCommand.java | 64 ---
.../client/shell/EnableConnectionFunction.java | 51 --
.../sqoop/client/shell/EnableJobFunction.java | 59 --
.../apache/sqoop/client/shell/HelpCommand.java | 153 -----
.../apache/sqoop/client/shell/SetCommand.java | 64 ---
.../sqoop/client/shell/SetOptionFunction.java | 87 ---
.../sqoop/client/shell/SetServerFunction.java | 78 ---
.../sqoop/client/shell/ShellEnvironment.java | 208 -------
.../apache/sqoop/client/shell/ShowCommand.java | 105 ----
.../client/shell/ShowConnectionFunction.java | 123 ----
.../client/shell/ShowConnectorFunction.java | 110 ----
.../client/shell/ShowFrameworkFunction.java | 55 --
.../sqoop/client/shell/ShowJobFunction.java | 125 ----
.../sqoop/client/shell/ShowOptionFunction.java | 89 ---
.../sqoop/client/shell/ShowServerFunction.java | 88 ---
.../client/shell/ShowSubmissionFunction.java | 106 ----
.../sqoop/client/shell/ShowVersionFunction.java | 127 -----
.../apache/sqoop/client/shell/SqoopCommand.java | 152 -----
.../sqoop/client/shell/SqoopFunction.java | 74 ---
.../apache/sqoop/client/shell/SqoopShell.java | 176 ------
.../apache/sqoop/client/shell/StartCommand.java | 58 --
.../sqoop/client/shell/StartJobFunction.java | 89 ---
.../sqoop/client/shell/StatusCommand.java | 56 --
.../sqoop/client/shell/StatusJobFunction.java | 55 --
.../apache/sqoop/client/shell/StopCommand.java | 54 --
.../sqoop/client/shell/StopJobFunction.java | 53 --
.../sqoop/client/shell/UpdateCommand.java | 69 ---
.../client/shell/UpdateConnectionFunction.java | 97 ----
.../sqoop/client/shell/UpdateJobFunction.java | 95 ----
.../sqoop/client/utils/FormDisplayer.java | 249 --------
.../apache/sqoop/client/utils/FormFiller.java | 566 -------------------
.../sqoop/client/utils/SubmissionDisplayer.java | 148 -----
.../sqoop/client/utils/TableDisplayer.java | 141 -----
.../sqoop/client/utils/ThrowableDisplayer.java | 90 ---
.../main/resources/client-resource.properties | 232 --------
dist/pom.xml | 12 +-
dist/src/main/bin/sqoop.sh | 4 +-
pom.xml | 6 +
shell/pom.xml | 108 ++++
.../org/apache/sqoop/shell/CloneCommand.java | 69 +++
.../sqoop/shell/CloneConnectionFunction.java | 96 ++++
.../apache/sqoop/shell/CloneJobFunction.java | 99 ++++
.../org/apache/sqoop/shell/CreateCommand.java | 69 +++
.../sqoop/shell/CreateConnectionFunction.java | 93 +++
.../apache/sqoop/shell/CreateJobFunction.java | 106 ++++
.../org/apache/sqoop/shell/DeleteCommand.java | 64 +++
.../sqoop/shell/DeleteConnectionFunction.java | 50 ++
.../apache/sqoop/shell/DeleteJobFunction.java | 58 ++
.../org/apache/sqoop/shell/DisableCommand.java | 64 +++
.../sqoop/shell/DisableConnectionFunction.java | 49 ++
.../apache/sqoop/shell/DisableJobFunction.java | 57 ++
.../org/apache/sqoop/shell/EnableCommand.java | 64 +++
.../sqoop/shell/EnableConnectionFunction.java | 49 ++
.../apache/sqoop/shell/EnableJobFunction.java | 57 ++
.../org/apache/sqoop/shell/HelpCommand.java | 153 +++++
.../java/org/apache/sqoop/shell/SetCommand.java | 64 +++
.../apache/sqoop/shell/SetOptionFunction.java | 87 +++
.../apache/sqoop/shell/SetServerFunction.java | 78 +++
.../apache/sqoop/shell/ShellEnvironment.java | 208 +++++++
.../org/apache/sqoop/shell/ShowCommand.java | 106 ++++
.../sqoop/shell/ShowConnectionFunction.java | 123 ++++
.../sqoop/shell/ShowConnectorFunction.java | 110 ++++
.../sqoop/shell/ShowFrameworkFunction.java | 55 ++
.../org/apache/sqoop/shell/ShowJobFunction.java | 125 ++++
.../apache/sqoop/shell/ShowOptionFunction.java | 89 +++
.../apache/sqoop/shell/ShowServerFunction.java | 88 +++
.../sqoop/shell/ShowSubmissionFunction.java | 105 ++++
.../apache/sqoop/shell/ShowVersionFunction.java | 127 +++++
.../org/apache/sqoop/shell/SqoopCommand.java | 152 +++++
.../org/apache/sqoop/shell/SqoopFunction.java | 74 +++
.../java/org/apache/sqoop/shell/SqoopShell.java | 176 ++++++
.../org/apache/sqoop/shell/StartCommand.java | 58 ++
.../apache/sqoop/shell/StartJobFunction.java | 89 +++
.../org/apache/sqoop/shell/StatusCommand.java | 56 ++
.../apache/sqoop/shell/StatusJobFunction.java | 55 ++
.../org/apache/sqoop/shell/StopCommand.java | 54 ++
.../org/apache/sqoop/shell/StopJobFunction.java | 53 ++
.../org/apache/sqoop/shell/UpdateCommand.java | 69 +++
.../sqoop/shell/UpdateConnectionFunction.java | 97 ++++
.../apache/sqoop/shell/UpdateJobFunction.java | 95 ++++
.../org/apache/sqoop/shell/core/Constants.java | 451 +++++++++++++++
.../org/apache/sqoop/shell/core/ShellError.java | 66 +++
.../apache/sqoop/shell/utils/FormDisplayer.java | 249 ++++++++
.../apache/sqoop/shell/utils/FormFiller.java | 566 +++++++++++++++++++
.../sqoop/shell/utils/SubmissionDisplayer.java | 148 +++++
.../sqoop/shell/utils/TableDisplayer.java | 141 +++++
.../sqoop/shell/utils/ThrowableDisplayer.java | 90 +++
shell/src/main/resources/log4j.properties | 24 +
.../main/resources/shell-resource.properties | 232 ++++++++
shell/src/test/resources/log4j.properties | 24 +
108 files changed, 5761 insertions(+), 5610 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index c6351ed..975773d 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -32,7 +32,12 @@ limitations under the License.
<name>Sqoop Client</name>
<dependencies>
- <dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
@@ -42,63 +47,10 @@ limitations under the License.
<artifactId>sqoop-common</artifactId>
</dependency>
<dependency>
- <groupId>commons-cli</groupId>
- <artifactId>commons-cli</artifactId>
- <version>1.2</version>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- </dependency>
- <dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.11</version>
</dependency>
- <dependency>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
- <version>0.9.94</version>
- </dependency>
- <dependency>
- <groupId>org.fusesource.jansi</groupId>
- <artifactId>jansi</artifactId>
- <version>1.7</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy-all</artifactId>
- <version>1.8.5</version>
- </dependency>
</dependencies>
- <profiles>
- <profile>
- <id>dist</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/lib</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
</project>
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/ClientError.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/ClientError.java b/client/src/main/java/org/apache/sqoop/client/ClientError.java
new file mode 100644
index 0000000..aafb5b0
--- /dev/null
+++ b/client/src/main/java/org/apache/sqoop/client/ClientError.java
@@ -0,0 +1,48 @@
+/**
+ * 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.common.ErrorCode;
+
+public enum ClientError implements ErrorCode {
+
+ /** An unknown error has occurred. */
+ CLIENT_0000("An unknown error has occurred"),
+
+ /** There occurred exception on server side **/
+ CLIENT_0001("Server has returned exception"),
+
+ /** Polling time of submission status cannot be negative */
+ CLIENT_0002("Polling time of submission status cannot be negative"),
+
+ ;
+
+ private final String message;
+
+ private ClientError(String message) {
+ this.message = message;
+ }
+
+ public String getCode() {
+ return name();
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
index 158e46c..f9e7ddd 100644
--- a/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
+++ b/client/src/main/java/org/apache/sqoop/client/SqoopClient.java
@@ -17,7 +17,6 @@
*/
package org.apache.sqoop.client;
-import org.apache.sqoop.client.core.ClientError;
import org.apache.sqoop.client.request.SqoopRequests;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.json.ConnectorBean;
@@ -396,7 +395,7 @@ public class SqoopClient {
*/
public MSubmission startSubmission(long jid, SubmissionCallback callback, long pollTime) throws InterruptedException {
if(pollTime <= 0) {
- throw new SqoopException(ClientError.CLIENT_0008);
+ throw new SqoopException(ClientError.CLIENT_0002);
}
boolean first = true;
MSubmission submission = requests.createSubmission(jid).getSubmissions().get(0);
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/core/ClientError.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/core/ClientError.java b/client/src/main/java/org/apache/sqoop/client/core/ClientError.java
deleted file mode 100644
index d96f44e..0000000
--- a/client/src/main/java/org/apache/sqoop/client/core/ClientError.java
+++ /dev/null
@@ -1,69 +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.common.ErrorCode;
-
-public enum ClientError implements ErrorCode {
-
- /** An unknown error has occurred. */
- CLIENT_0000("An unknown error has occurred"),
-
- /** The specified command is not recognized. */
- CLIENT_0001("The specified command is not recognized"),
-
- /** The specified function is not recognized. */
- CLIENT_0002("The specified function is not recognized"),
-
- /** An error has occurred when parsing options. */
- CLIENT_0003("An error has occurred when parsing options"),
-
- /** Unable to resolve the variables. */
- CLIENT_0004("Unable to resolve the variables"),
-
- /** We're not able to get user input */
- CLIENT_0005("Can't get user input"),
-
- /** There occurred exception on server side **/
- CLIENT_0006("Server has returned exception"),
-
- /** Command not compatible with batch mode */
- CLIENT_0007("Command not compatible with batch mode"),
-
- /** Polling time of submission status cannot be negative */
- CLIENT_0008("Polling time of submission status cannot be negative"),
-
- /** Job Submission : Cannot sleep */
- CLIENT_0009("Cannot sleep"),
-
- ;
-
- private final String message;
-
- private ClientError(String message) {
- this.message = message;
- }
-
- public String getCode() {
- return name();
- }
-
- public String getMessage() {
- return message;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 999790d..0000000
--- a/client/src/main/java/org/apache/sqoop/client/core/Constants.java
+++ /dev/null
@@ -1,451 +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;
-
-/**
- *
- */
-public class Constants {
-
- // General string constants
- public static final String RESOURCE_NAME = "client-resource";
- 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";
- public static final String OPT_ALL = "all";
- public static final String OPT_JID = "jid";
- public static final String OPT_CID = "cid";
- public static final String OPT_TYPE = "type";
- public static final String OPT_NAME = "name";
- public static final String OPT_VALUE = "value";
- public static final String OPT_VERBOSE = "verbose";
- 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";
- public static final String OPT_SYNCHRONOUS = "synchronous";
- public static final String OPT_POLL_TIMEOUT = "poll-timeout";
- public static final String OPT_DETAIL = "detail";
-
- public static final char OPT_XID_CHAR = 'x';
- public static final char OPT_ALL_CHAR = 'a';
- public static final char OPT_JID_CHAR = 'j';
- public static final char OPT_CID_CHAR = 'c';
- public static final char OPT_TYPE_CHAR = 't';
- public static final char OPT_NAME_CHAR = 'n';
- public static final char OPT_VALUE_CHAR = 'v';
- 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';
- public static final char OPT_SYNCHRONOUS_CHAR = 's';
- public static final char OPT_POLL_TIMEOUT_CHAR = 'p';
- public static final char OPT_DETAIL_CHAR = 'd';
-
- // Resource keys for various commands, command options,
- // functions and descriptions
- public static final String CMD_CLONE = "clone";
- public static final String CMD_CLONE_SC = "\\cl";
-
- public static final String CMD_CREATE = "create";
- public static final String CMD_CREATE_SC = "\\cr";
-
- public static final String CMD_DELETE = "delete";
- public static final String CMD_DELETE_SC = "\\d";
-
- public static final String CMD_HELP = "help";
- public static final String CMD_HELP_SC = "\\h";
-
- public static final String CMD_SET = "set";
- public static final String CMD_SET_SC = "\\st";
-
- public static final String CMD_SHOW = "show";
- public static final String CMD_SHOW_SC = "\\sh";
-
- public static final String CMD_UPDATE = "update";
- public static final String CMD_UPDATE_SC = "\\up";
-
- public static final String CMD_START = "start";
- public static final String CMD_START_SC = "\\sta";
-
- public static final String CMD_STOP = "stop";
- public static final String CMD_STOP_SC = "\\stp";
-
- public static final String CMD_STATUS = "status";
- public static final String CMD_STATUS_SC = "\\stu";
-
- public static final String CMD_ENABLE = "enable";
- public static final String CMD_ENABLE_SC = "\\en";
-
- public static final String CMD_DISABLE = "disable";
- public static final String CMD_DISABLE_SC = "\\di";
-
- public static final String FN_CONNECTION = "connection";
- public static final String FN_JOB = "job";
- public static final String FN_SUBMISSION = "submission";
- public static final String FN_SERVER = "server";
- public static final String FN_OPTION = "option";
- public static final String FN_CONNECTOR = "connector";
- public static final String FN_VERSION = "version";
- public static final String FN_FRAMEWORK = "framework";
-
- public static final String PRE_CLONE = "Clone";
- public static final String PRE_CREATE = "Create";
- public static final String PRE_DELETE = "Delete";
- public static final String PRE_SET = "Set";
- public static final String PRE_SHOW = "Show";
- public static final String PRE_UPDATE = "Update";
- public static final String PRE_START = "Start";
- public static final String PRE_STATUS = "Status";
- public static final String PRE_STOP = "Stop";
- public static final String PRE_ENABLE = "Enable";
- public static final String PRE_DISABLE = "Disable";
- public static final String SUF_INFO = "Info";
-
-
- public static final String PROP_HOMEDIR = "user.home";
- public static final String PROP_CURDIR = "user.dir";
- public static final String SQOOP_PROMPT = "sqoop";
-
-
- // 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 =
- "args.jid_missing";
- public static final String RES_ARGS_CID_MISSING =
- "args.cid_missing";
- public static final String RES_ARGS_TYPE_MISSING =
- "args.type_missing";
- public static final String RES_ARGS_NAME_MISSING =
- "args.name_missing";
- public static final String RES_ARGS_VALUE_MISSING =
- "args.value_missing";
-
- public static final String RES_PROMPT_CONN_ID =
- "prompt.conn_id";
- public static final String RES_PROMPT_JOB_ID =
- "prompt.job_id";
- public static final String RES_CONNECTOR_ID =
- "prompt.connector_id";
- public static final String RES_PROMPT_JOB_TYPE =
- "prompt.job_type";
- public static final String RES_PROMPT_UPDATE_CONN_METADATA =
- "prompt.update_conn_metadata";
- public static final String RES_PROMPT_UPDATE_JOB_METADATA =
- "prompt.update_job_metadata";
- public static final String RES_PROMPT_FILL_CONN_METADATA =
- "prompt.fill_conn_metadata";
- public static final String RES_PROMPT_FILL_JOB_METADATA =
- "prompt.fill_job_metadata";
-
- public static final String RES_CLONE_USAGE =
- "clone.usage";
- public static final String RES_CLONE_CONN_SUCCESSFUL =
- "clone.conn.successful";
- public static final String RES_CLONE_JOB_SUCCESSFUL =
- "clone.job.successful";
- public static final String RES_CLONE_CLONING_CONN =
- "clone.cloning_conn";
- public static final String RES_CLONE_CLONING_JOB =
- "clone.cloning_job";
-
- public static final String RES_CREATE_USAGE =
- "create.usage";
- public static final String RES_CREATE_CONN_SUCCESSFUL =
- "create.conn_successful";
- public static final String RES_CREATE_JOB_SUCCESSFUL =
- "create.job_successful";
- public static final String RES_CREATE_CREATING_CONN =
- "create.creating_conn";
- public static final String RES_CREATE_CREATING_JOB =
- "create.creating_job";
-
- public static final String RES_DELETE_USAGE =
- "delete.usage";
-
- public static final String RES_DISABLE_USAGE =
- "disable.usage";
- public static final String RES_DISABLE_CONNECTION_SUCCESSFUL =
- "disable.conn_successful";
- public static final String RES_DISABLE_JOB_SUCCESSFUL =
- "disable.job_successful";
-
- public static final String RES_ENABLE_USAGE =
- "enable.usage";
- public static final String RES_ENABLE_CONNECTION_SUCCESSFUL =
- "enable.conn_successful";
- public static final String RES_ENABLE_JOB_SUCCESSFUL =
- "enable.job_successful";
-
- public static final String RES_HELP_USAGE =
- "help.usage";
- public static final String RES_HELP_DESCRIPTION =
- "help.description";
- public static final String RES_HELP_CMD_USAGE =
- "help.cmd_usage";
- public static final String RES_HELP_MESSAGE =
- "help.message";
- public static final String RES_HELP_INFO =
- "help.info";
- public static final String RES_HELP_AVAIL_COMMANDS =
- "help.avail_commands";
- public static final String RES_HELP_CMD_DESCRIPTION =
- "help.cmd_description";
- public static final String RES_HELP_SPECIFIC_CMD_INFO =
- "help.specific_cmd_info";
-
- public static final String RES_UNRECOGNIZED_CMD =
- "unrecognized.cmd";
-
- public static final String RES_SET_USAGE =
- "set.usage";
- public static final String RES_SET_PROMPT_OPT_NAME =
- "set.prompt_opt_name";
- public static final String RES_SET_PROMPT_OPT_VALUE =
- "set.prompt_opt_value";
- public static final String RES_SET_VERBOSE_CHANGED =
- "set.verbose_changed";
- public static final String RES_SET_POLL_TIMEOUT_CHANGED =
- "set.poll_timeout_changed";
- public static final String RES_SET_UNKNOWN_OPT_IGNORED =
- "set.unknown_opt_ignored";
- public static final String RES_SET_HOST_DESCRIPTION =
- "set.host_description";
- public static final String RES_SET_PORT_DESCRIPTION =
- "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";
- public static final String RES_SHOW_PROMPT_DISPLAY_ALL_CONNS =
- "show.prompt_display_all_conns";
- public static final String RES_SHOW_PROMPT_DISPLAY_CONN_XID =
- "show.prompt_display_conn_xid";
- public static final String RES_SHOW_CONN_USAGE =
- "show.conn_usage";
- public static final String RES_SHOW_PROMPT_CONNS_TO_SHOW =
- "show.prompt_conns_to_show";
- public static final String RES_SHOW_PROMPT_CONN_INFO =
- "show.prompt_conn_info";
- public static final String RES_SHOW_PROMPT_CONN_CID_INFO =
- "show.prompt_conn_cid_info";
-
- public static final String RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS =
- "show.prompt_display_all_connectors";
- public static final String RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID =
- "show.prompt_display_connector_cid";
- public static final String RES_SHOW_CONNECTOR_USAGE =
- "show.connector_usage";
- public static final String RES_SHOW_PROMPT_CONNECTORS_TO_SHOW =
- "show.prompt_connectors_to_show";
- public static final String RES_SHOW_PROMPT_CONNECTOR_INFO =
- "show.prompt_connector_info";
-
- public static final String RES_SHOW_FRAMEWORK_USAGE =
- "show.framework_usage";
- public static final String RES_SHOW_PROMPT_FRAMEWORK_OPTS =
- "show.prompt_framework_opts";
-
- public static final String RES_SHOW_PROMPT_DISPLAY_ALL_JOBS =
- "show.prompt_display_all_jobs";
- public static final String RES_SHOW_PROMPT_DISPLAY_JOB_JID =
- "show.prompt_display_job_jid";
- public static final String RES_SHOW_JOB_USAGE =
- "show.job_usage";
- public static final String RES_SHOW_PROMPT_JOBS_TO_SHOW =
- "show.prompt_jobs_to_show";
- public static final String RES_SHOW_PROMPT_JOB_INFO =
- "show.prompt_job_info";
- public static final String RES_SHOW_PROMPT_JOB_XID_CID_INFO =
- "show.prompt_job_xid_cid_info";
-
- public static final String RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS =
- "show.prompt_display_all_submissions";
- public static final String RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS_JOB_ID =
- "show.prompt_display_all_submissions_jid";
-
- public static final String RES_SHOW_PROMPT_DISPLAY_ALL_SERVERS =
- "show.prompt_display_all_servers";
- public static final String RES_SHOW_PROMPT_DISPLAY_SERVER_HOST =
- "show.prompt_display_server_host";
- public static final String RES_SHOW_PROMPT_DISPLAY_SERVER_PORT =
- "show.prompt_display_server_port";
- public static final String RES_SHOW_PROMPT_DISPLAY_SERVER_WEBAPP =
- "show.prompt_display_server_webapp";
- public static final String RES_SHOW_SERVER_USAGE =
- "show.server_usage";
- public static final String RES_SHOW_PROMPT_SERVER_HOST =
- "show.prompt_server_host";
- public static final String RES_SHOW_PROMPT_SERVER_PORT =
- "show.prompt_server_port";
- public static final String RES_SHOW_PROMPT_SERVER_WEBAPP =
- "show.prompt_server_webapp";
-
- public static final String RES_SHOW_PROMPT_DISPLAY_ALL_VERSIONS =
- "show.prompt_display_all_versions";
- public static final String RES_SHOW_PROMPT_DISPLAY_VERSION_SERVER =
- "show.prompt_display_version_server";
- public static final String RES_SHOW_PROMPT_DISPLAY_VERSION_CLIENT =
- "show.prompt_display_version_client";
- public static final String RES_SHOW_PROMPT_DISPLAY_VERSION_PROTOCOL =
- "show.prompt_display_version_protocol";
- public static final String RES_SHOW_VERSION_USAGE =
- "show.version_usage";
- public static final String RES_SHOW_PROMPT_VERSION_CLIENT_SERVER =
- "show.prompt_version_client_server";
- public static final String RES_SHOW_PROMPT_VERSION_PROTOCOL =
- "show.prompt_version_protocol";
-
- public static final String RES_START_USAGE =
- "start.usage";
-
- public static final String RES_STATUS_USAGE =
- "status.usage";
- public static final String RES_PROMPT_SYNCHRONOUS =
- "start.prompt_synchronous";
-
- public static final String RES_STOP_USAGE =
- "stop.usage";
-
- public static final String RES_SQOOP_SHELL_BANNER =
- "sqoop.shell_banner";
- public static final String RES_SQOOP_PROMPT_SHELL_LOADRC =
- "sqoop.prompt_shell_loadrc";
- public static final String RES_SQOOP_PROMPT_SHELL_LOADEDRC =
- "sqoop.prompt_shell_loadedrc";
-
- public static final String RES_UPDATE_USAGE =
- "update.usage";
- public static final String RES_UPDATE_UPDATING_CONN =
- "update.conn";
- public static final String RES_UPDATE_CONN_SUCCESSFUL =
- "update.conn_successful";
- public static final String RES_UPDATE_UPDATING_JOB =
- "update.job";
- public static final String RES_UPDATE_JOB_SUCCESSFUL =
- "update.job_successful";
-
- public static final String RES_TABLE_HEADER_ID =
- "table.header.id";
- public static final String RES_TABLE_HEADER_NAME =
- "table.header.name";
- public static final String RES_TABLE_HEADER_VERSION =
- "table.header.version";
- public static final String RES_TABLE_HEADER_CLASS =
- "table.header.class";
- public static final String RES_TABLE_HEADER_TYPE =
- "table.header.type";
- public static final String RES_TABLE_HEADER_CONNECTOR =
- "table.header.connector";
- public static final String RES_TABLE_HEADER_JOB_ID =
- "table.header.jid";
- public static final String RES_TABLE_HEADER_EXTERNAL_ID =
- "table.header.eid";
- public static final String RES_TABLE_HEADER_STATUS =
- "table.header.status";
- public static final String RES_TABLE_HEADER_DATE =
- "table.header.date";
- public static final String RES_TABLE_HEADER_ENABLED =
- "table.header.enabled";
-
- public static final String RES_FORMDISPLAYER_SUPPORTED_JOBTYPE =
- "formdisplayer.supported_job_types";
- public static final String RES_FORMDISPLAYER_CONNECTION =
- "formdisplayer.connection";
- public static final String RES_FORMDISPLAYER_JOB =
- "formdisplayer.job";
- public static final String RES_FORMDISPLAYER_FORM_JOBTYPE =
- "formdisplayer.forms_jobtype";
- public static final String RES_FORMDISPLAYER_FORM =
- "formdisplayer.form";
- public static final String RES_FORMDISPLAYER_NAME =
- "formdisplayer.name";
- public static final String RES_FORMDISPLAYER_LABEL =
- "formdisplayer.label";
- public static final String RES_FORMDISPLAYER_HELP =
- "formdisplayer.help";
- public static final String RES_FORMDISPLAYER_INPUT =
- "formdisplayer.input";
- public static final String RES_FORMDISPLAYER_TYPE =
- "formdisplayer.type";
- public static final String RES_FORMDISPLAYER_SENSITIVE =
- "formdisplayer.sensitive";
- public static final String RES_FORMDISPLAYER_SIZE =
- "formdisplayer.size";
- public static final String RES_FORMDISPLAYER_POSSIBLE_VALUES =
- "formdisplayer.possible_values";
- public static final String RES_FORMDISPLAYER_UNSUPPORTED_DATATYPE =
- "formdisplayer.unsupported_datatype";
- public static final String RES_FORMDISPLAYER_INPUT_SENSITIVE =
- "formdisplayer.input_sensitive";
-
- public static final String RES_FORMDISPLAYER_FORM_WARNING =
- "formdisplayer.warning_message";
-
- public static final String RES_SUBMISSION_SUBMISSION_DETAIL =
- "submission.submission_detail";
- public static final String RES_SUBMISSION_JOB_ID =
- "submission.job_id";
- public static final String RES_SUBMISSION_CREATION_DATE =
- "submission.creation_date";
- public static final String RES_SUBMISSION_EXTERNAL_ID =
- "submission.external_id";
- public static final String RES_SUBMISSION_PROGRESS_NOT_AVAIL =
- "submission.progress_not_available";
- public static final String RES_SUBMISSION_COUNTERS =
- "submission.counters";
- public static final String RES_SUBMISSION_EXECUTED_SUCCESS =
- "submission.executed_success";
- public static final String RES_SUBMISSION_SERVER_URL =
- "submission.server_url";
- public static final String RES_CONNECTOR_SCHEMA =
- "submission.connector_schema";
- public static final String RES_HIO_SCHEMA =
- "submission.hio_schema";
-
- private Constants() {
- // Instantiation is prohibited
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/request/Request.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/Request.java b/client/src/main/java/org/apache/sqoop/client/request/Request.java
index befb793..d9229f5 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/Request.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/Request.java
@@ -25,7 +25,8 @@ import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.api.client.filter.ClientFilter;
-import org.apache.sqoop.client.core.ClientError;
+
+import org.apache.sqoop.client.ClientError;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.common.SqoopProtocolConstants;
import org.apache.sqoop.json.ThrowableBean;
@@ -99,7 +100,7 @@ public class Request
JSONObject json = (JSONObject) JSONValue.parse(responseText);
ex.restore(json);
- throw new SqoopException(ClientError.CLIENT_0006, ex.getThrowable());
+ throw new SqoopException(ClientError.CLIENT_0001, ex.getThrowable());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 283b025..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java
+++ /dev/null
@@ -1,69 +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.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.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Client side cloning of connection and job objects.
- */
-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},
- Constants.PRE_CLONE, Constants.SUF_INFO);
- }
-
- public Object executeCommand(List args) {
- if(!isInteractive()) {
- throw new SqoopException(ClientError.CLIENT_0007, "clone");
- }
-
- if (args.size() == 0) {
- 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();
- }
- return connectionFunction.execute(args);
- } else if (func.equals(Constants.FN_JOB)) {
- if (jobFunction == null) {
- jobFunction = new CloneJobFunction();
- }
- return jobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 0538901..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java
+++ /dev/null
@@ -1,96 +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.shell;
-
-import jline.ConsoleReader;
-import org.apache.commons.cli.CommandLine;
-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.model.MConnection;
-import org.apache.sqoop.model.MPersistableEntity;
-import org.apache.sqoop.validation.Status;
-
-import java.io.IOException;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-import static org.apache.sqoop.client.utils.FormFiller.*;
-
-/**
- *
- */
-public class CloneConnectionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public CloneConnectionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
- .withLongOpt(Constants.OPT_XID)
- .hasArg()
- .create(Constants.OPT_XID_CHAR)
- );
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_XID)) {
- printlnResource(Constants.RES_ARGS_XID_MISSING);
- return null;
- }
-
- try {
- cloneConnection(getLong(line, Constants.OPT_XID));
- } catch (IOException ex) {
- throw new SqoopException(ClientError.CLIENT_0005, ex);
- }
-
- return null;
- }
-
- private void cloneConnection(Long connectionId) throws IOException {
- printlnResource(Constants.RES_CLONE_CLONING_CONN, connectionId);
-
- ConsoleReader reader = new ConsoleReader();
-
- 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);
-
- ResourceBundle connectorBundle = client.getResourceBundle(connection.getConnectorId());
- ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
- do {
- // Print error introduction if needed
- if( !status.canProceed() ) {
- errorIntroduction();
- }
-
- // Fill in data from user
- if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
- return;
- }
-
- status = client.createConnection(connection);
-
- } while(!status.canProceed());
-
- printlnResource(Constants.RES_CLONE_CONN_SUCCESSFUL, status.name(), connection.getPersistenceId());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 6f62813..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java
+++ /dev/null
@@ -1,99 +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.shell;
-
-import jline.ConsoleReader;
-import org.apache.commons.cli.CommandLine;
-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.model.MJob;
-import org.apache.sqoop.model.MPersistableEntity;
-import org.apache.sqoop.validation.Status;
-
-import java.io.IOException;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-import static org.apache.sqoop.client.utils.FormFiller.*;
-
-/**
- *
- */
-public class CloneJobFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public CloneJobFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .hasArg()
- .create(Constants.OPT_JID_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_JID)) {
- printlnResource(Constants.RES_ARGS_JID_MISSING);
- return null;
- }
-
- try {
- cloneJob(getLong(line, Constants.OPT_JID));
- } catch (IOException ex) {
- throw new SqoopException(ClientError.CLIENT_0005, ex);
- }
-
- return null;
- }
-
- private void cloneJob(Long jobId) throws IOException {
- printlnResource(Constants.RES_CLONE_CLONING_JOB, jobId);
-
- ConsoleReader reader = new ConsoleReader();
-
- MJob job = client.getJob(jobId);
- job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);
-
- 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);
-
- printlnResource(Constants.RES_PROMPT_UPDATE_JOB_METADATA);
- do {
- // Print error introduction if needed
- if( !status.canProceed() ) {
- errorIntroduction();
- }
-
- // Fill in data from user
- if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
- return;
- }
-
- // Try to create
- status = client.createJob(job);
- } while(!status.canProceed());
-
- printlnResource(Constants.RES_CLONE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index ac555e1..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java
+++ /dev/null
@@ -1,69 +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.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.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-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},
- Constants.PRE_CREATE, Constants.SUF_INFO);
- }
-
- public Object executeCommand(List args) {
- if(!isInteractive()) {
- throw new SqoopException(ClientError.CLIENT_0007, "create");
- }
-
- if (args.size() == 0) {
- 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();
- }
- return connectionFunction.execute(args);
- } else if (func.equals(Constants.FN_JOB)) {
- if (jobFunction == null) {
- jobFunction = new CreateJobFunction();
- }
- return jobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 04b240c..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java
+++ /dev/null
@@ -1,93 +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.shell;
-
-import jline.ConsoleReader;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.FormDisplayer;
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.validation.Status;
-
-import java.io.IOException;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-import static org.apache.sqoop.client.utils.FormFiller.*;
-
-/**
- *
- */
-public class CreateConnectionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public CreateConnectionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_CONNECTOR_ID))
- .withLongOpt(Constants.OPT_CID)
- .hasArg()
- .create(Constants.OPT_CID_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_CID)) {
- printlnResource(Constants.RES_ARGS_CID_MISSING);
- return null;
- }
-
- try {
- createConnection(getLong(line, Constants.OPT_CID));
- } catch (IOException ex) {
- throw new SqoopException(ClientError.CLIENT_0005, ex);
- }
-
- return null;
- }
-
- private void createConnection(long connectorId) throws IOException {
- printlnResource(Constants.RES_CREATE_CREATING_CONN, connectorId);
-
- ConsoleReader reader = new ConsoleReader();
-
- MConnection connection = client.newConnection(connectorId);
-
- ResourceBundle connectorBundle = client.getResourceBundle(connectorId);
- ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
-
- Status status = Status.FINE;
- printlnResource(Constants.RES_PROMPT_FILL_CONN_METADATA);
- do {
- // Print error introduction if needed
- if( !status.canProceed() ) {
- errorIntroduction();
- }
-
- // Fill in data from user
- if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
- return;
- }
-
- // Try to create
- status = client.createConnection(connection);
- } while(!status.canProceed());
- FormDisplayer.displayFormWarning(connection);
- printlnResource(Constants.RES_CREATE_CONN_SUCCESSFUL, status.name(), connection.getPersistenceId());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index cc4d546..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java
+++ /dev/null
@@ -1,106 +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.shell;
-
-import jline.ConsoleReader;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.FormDisplayer;
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.validation.Status;
-
-import java.io.IOException;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-import static org.apache.sqoop.client.utils.FormFiller.*;
-
-/**
- * Handles creation of new job objects.
- */
-public class CreateJobFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public CreateJobFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
- .withLongOpt(Constants.OPT_XID)
- .hasArg()
- .create(Constants.OPT_XID_CHAR)
- );
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_TYPE))
- .withLongOpt(Constants.OPT_TYPE)
- .hasArg()
- .create(Constants.OPT_TYPE_CHAR)
- );
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_XID)) {
- printlnResource(Constants.RES_ARGS_XID_MISSING);
- return null;
- }
- if (!line.hasOption(Constants.OPT_TYPE)) {
- printlnResource(Constants.RES_ARGS_TYPE_MISSING);
- return null;
- }
-
- try {
- createJob(getLong(line, Constants.OPT_XID),
- line.getOptionValue(Constants.OPT_TYPE));
- } catch (IOException ex) {
- throw new SqoopException(ClientError.CLIENT_0005, ex);
- }
-
- return null;
- }
-
- 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.toUpperCase()));
-
- ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
- ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
-
- Status status = Status.FINE;
-
- printlnResource(Constants.RES_PROMPT_FILL_JOB_METADATA);
-
- do {
- // Print error introduction if needed
- if( !status.canProceed() ) {
- errorIntroduction();
- }
-
- // Fill in data from user
- if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
- return;
- }
-
- // Try to create
- status = client.createJob(job);
- } while(!status.canProceed());
- FormDisplayer.displayFormWarning(job);
- printlnResource(Constants.RES_CREATE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 6a5b3a1..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java
+++ /dev/null
@@ -1,64 +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.shell;
-
-import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.Shell;
-import java.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class DeleteCommand extends SqoopCommand {
-
- private DeleteConnectionFunction connectionFunction;
- private DeleteJobFunction jobFunction;
-
- public DeleteCommand(Shell shell) {
- super(shell, Constants.CMD_DELETE, Constants.CMD_DELETE_SC,
- new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
- Constants.PRE_DELETE, Constants.SUF_INFO);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Object executeCommand(List args) {
- if (args.size() == 0) {
- 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();
- }
- return connectionFunction.execute(args);
- } else if (func.equals(Constants.FN_JOB)) {
- if (jobFunction == null) {
- jobFunction = new DeleteJobFunction();
- }
- return jobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 18d3a70..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java
+++ /dev/null
@@ -1,50 +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.shell;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class DeleteConnectionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public DeleteConnectionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
- .withLongOpt(Constants.OPT_XID)
- .hasArg()
- .create('x'));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_XID)) {
- printlnResource(Constants.RES_ARGS_XID_MISSING);
- return null;
- }
-
- client.deleteConnection(getLong(line, Constants.OPT_XID));
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 736be20..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java
+++ /dev/null
@@ -1,58 +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.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.request.JobRequest;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Handles deletion of a job object.
- */
-public class DeleteJobFunction extends SqoopFunction {
-
- private JobRequest jobRequest;
-
- @SuppressWarnings("static-access")
- public DeleteJobFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .hasArg()
- .create('j'));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_JID)) {
- printlnResource(Constants.RES_ARGS_JID_MISSING);
- return null;
- }
-
- if (jobRequest == null) {
- jobRequest = new JobRequest();
- }
-
- client.deleteJob(getLong(line, Constants.OPT_JID));
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/DisableCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/DisableCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/DisableCommand.java
deleted file mode 100644
index 5cbd6db..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/DisableCommand.java
+++ /dev/null
@@ -1,64 +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.shell;
-
-import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.Shell;
-import java.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class DisableCommand extends SqoopCommand {
-
- private DisableConnectionFunction connectionFunction;
- private DisableJobFunction jobFunction;
-
- public DisableCommand(Shell shell) {
- super(shell, Constants.CMD_DISABLE, Constants.CMD_DISABLE_SC,
- new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
- Constants.PRE_DISABLE, Constants.SUF_INFO);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Object executeCommand(List args) {
- if (args.size() == 0) {
- printlnResource(Constants.RES_DISABLE_USAGE, getUsage());
- return null;
- }
-
- String func = (String)args.get(0);
- if (func.equals(Constants.FN_CONNECTION)) {
- if (connectionFunction == null) {
- connectionFunction = new DisableConnectionFunction();
- }
- return connectionFunction.execute(args);
- } else if (func.equals(Constants.FN_JOB)) {
- if (jobFunction == null) {
- jobFunction = new DisableJobFunction();
- }
- return jobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/DisableConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/DisableConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/DisableConnectionFunction.java
deleted file mode 100644
index e04292a..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/DisableConnectionFunction.java
+++ /dev/null
@@ -1,51 +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.shell;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.validation.Status;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Handles enabling of a connection object
- */
-public class DisableConnectionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public DisableConnectionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
- .withLongOpt(Constants.OPT_XID)
- .hasArg()
- .create('x'));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_XID)) {
- printlnResource(Constants.RES_ARGS_XID_MISSING);
- return null;
- }
-
- client.enableConnection(getLong(line, Constants.OPT_XID), false);
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/DisableJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/DisableJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/DisableJobFunction.java
deleted file mode 100644
index 5962cd2..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/DisableJobFunction.java
+++ /dev/null
@@ -1,59 +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.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.request.JobRequest;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.validation.Status;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Handles disabling of a job object.
- */
-public class DisableJobFunction extends SqoopFunction {
-
- private JobRequest jobRequest;
-
- @SuppressWarnings("static-access")
- public DisableJobFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .hasArg()
- .create('j'));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_JID)) {
- printlnResource(Constants.RES_ARGS_JID_MISSING);
- return null;
- }
-
- if (jobRequest == null) {
- jobRequest = new JobRequest();
- }
-
- client.enableJob(getLong(line, Constants.OPT_JID), false);
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/EnableCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/EnableCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/EnableCommand.java
deleted file mode 100644
index 8a2c1c7..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/EnableCommand.java
+++ /dev/null
@@ -1,64 +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.shell;
-
-import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.Shell;
-import java.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class EnableCommand extends SqoopCommand {
-
- private EnableConnectionFunction connectionFunction;
- private EnableJobFunction jobFunction;
-
- public EnableCommand(Shell shell) {
- super(shell, Constants.CMD_ENABLE, Constants.CMD_ENABLE_SC,
- new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
- Constants.PRE_ENABLE, Constants.SUF_INFO);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Object executeCommand(List args) {
- if (args.size() == 0) {
- printlnResource(Constants.RES_ENABLE_USAGE, getUsage());
- return null;
- }
-
- String func = (String)args.get(0);
- if (func.equals(Constants.FN_CONNECTION)) {
- if (connectionFunction == null) {
- connectionFunction = new EnableConnectionFunction();
- }
- return connectionFunction.execute(args);
- } else if (func.equals(Constants.FN_JOB)) {
- if (jobFunction == null) {
- jobFunction = new EnableJobFunction();
- }
- return jobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/EnableConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/EnableConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/EnableConnectionFunction.java
deleted file mode 100644
index ed6dc3c..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/EnableConnectionFunction.java
+++ /dev/null
@@ -1,51 +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.shell;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.validation.Status;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Handles enabling of a connection object
- */
-public class EnableConnectionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public EnableConnectionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
- .withLongOpt(Constants.OPT_XID)
- .hasArg()
- .create('x'));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_XID)) {
- printlnResource(Constants.RES_ARGS_XID_MISSING);
- return null;
- }
-
- client.enableConnection(getLong(line, Constants.OPT_XID), true);
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/EnableJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/EnableJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/EnableJobFunction.java
deleted file mode 100644
index 9e4e320..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/EnableJobFunction.java
+++ /dev/null
@@ -1,59 +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.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.request.JobRequest;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.validation.Status;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Handles disabling of a job object.
- */
-public class EnableJobFunction extends SqoopFunction {
-
- private JobRequest jobRequest;
-
- @SuppressWarnings("static-access")
- public EnableJobFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .hasArg()
- .create('j'));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_JID)) {
- printlnResource(Constants.RES_ARGS_JID_MISSING);
- return null;
- }
-
- if (jobRequest == null) {
- jobRequest = new JobRequest();
- }
-
- client.enableJob(getLong(line, Constants.OPT_JID), true);
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index c6f831d..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
+++ /dev/null
@@ -1,153 +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.shell;
-
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.commons.lang.StringUtils;
-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.Command;
-import org.codehaus.groovy.tools.shell.CommandSupport;
-import org.codehaus.groovy.tools.shell.Shell;
-import org.codehaus.groovy.tools.shell.util.SimpleCompletor;
-
-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);
- }
-
- @Override
- public String getDescription() {
- return resourceString(Constants.RES_HELP_DESCRIPTION);
- }
-
- @Override
- public String getUsage() {
- return resourceString(Constants.RES_HELP_USAGE);
- }
-
- @Override
- public String getHelp() {
- return resourceString(Constants.RES_HELP_MESSAGE);
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public Object execute(List args) {
- if (args.size() == 0) {
- list();
- }
- else {
- help((String)args.get(0));
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- private void list() {
- Iterator<Command> iterator;
-
- // Figure out the max command name and shortcut length dynamically
- int maxName = 0;
- int maxShortcut = 0;
- iterator = shell.getRegistry().commands().iterator();
- while (iterator.hasNext()) {
- Command command = iterator.next();
- if (command.getHidden()) {
- continue;
- }
-
- if (command.getName().length() > maxName) {
- maxName = command.getName().length();
- }
-
- if (command.getShortcut().length() > maxShortcut) {
- maxShortcut = command.getShortcut().length();
- }
- }
-
- printlnResource(Constants.RES_HELP_INFO);
- println();
-
- // List the commands we know about
- printlnResource(Constants.RES_HELP_AVAIL_COMMANDS);
-
- iterator = shell.getRegistry().commands().iterator();
- while (iterator.hasNext()) {
- Command command = iterator.next();
- if (command.getHidden()) {
- continue;
- }
-
- 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(resource.getString(Constants
- .RES_HELP_CMD_DESCRIPTION), paddedName,
- paddedShortcut, description));
- println(sb.toString());
- }
-
- 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(resource.getString(Constants
- .RES_UNRECOGNIZED_CMD), name);
- throw new SqoopException(ClientError.CLIENT_0001, msg);
- }
- printlnResource(Constants.RES_HELP_CMD_USAGE, command.getName(), command.getUsage());
- println();
- println(command.getHelp());
- println();
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected List createCompletors() {
- SimpleCompletor completor = new SimpleCompletor();
- Iterator<Command> iterator = registry.iterator();
- while (iterator.hasNext()) {
- Command command = iterator.next();
- if (command.getHidden()) {
- continue;
- }
-
- completor.add(command.getName());
- }
-
- List completors = new LinkedList();
- completors.add(completor);
- return completors;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index c831123..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
+++ /dev/null
@@ -1,64 +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.shell;
-
-import java.util.List;
-
-import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.Shell;
-
-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},
- Constants.PRE_SET, Constants.SUF_INFO);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public Object executeCommand(List args) {
-
- if (args.size() == 0) {
- 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();
- }
- return serverFunction.execute(args);
-
- } else if (func.equals(Constants.FN_OPTION)) {
- if (optionFunction == null) {
- optionFunction = new SetOptionFunction();
- }
- return optionFunction.execute(args);
-
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- return null;
- }
- }
-}
[3/6] SQOOP-921. Sqoop2: Create standalone shell package
Posted by hs...@apache.org.
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/DeleteJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DeleteJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/DeleteJobFunction.java
new file mode 100644
index 0000000..d4095b7
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DeleteJobFunction.java
@@ -0,0 +1,58 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.client.request.JobRequest;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Handles deletion of a job object.
+ */
+public class DeleteJobFunction extends SqoopFunction {
+
+ private JobRequest jobRequest;
+
+ @SuppressWarnings("static-access")
+ public DeleteJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .hasArg()
+ .create('j'));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_JID)) {
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
+ return null;
+ }
+
+ if (jobRequest == null) {
+ jobRequest = new JobRequest();
+ }
+
+ client.deleteJob(getLong(line, Constants.OPT_JID));
+
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/DisableCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DisableCommand.java b/shell/src/main/java/org/apache/sqoop/shell/DisableCommand.java
new file mode 100644
index 0000000..5a6d942
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DisableCommand.java
@@ -0,0 +1,64 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class DisableCommand extends SqoopCommand {
+
+ private DisableConnectionFunction connectionFunction;
+ private DisableJobFunction jobFunction;
+
+ public DisableCommand(Shell shell) {
+ super(shell, Constants.CMD_DISABLE, Constants.CMD_DISABLE_SC,
+ new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
+ Constants.PRE_DISABLE, Constants.SUF_INFO);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeCommand(List args) {
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_DISABLE_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String)args.get(0);
+ if (func.equals(Constants.FN_CONNECTION)) {
+ if (connectionFunction == null) {
+ connectionFunction = new DisableConnectionFunction();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new DisableJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/DisableConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DisableConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/DisableConnectionFunction.java
new file mode 100644
index 0000000..f119660
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DisableConnectionFunction.java
@@ -0,0 +1,49 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Handles enabling of a connection object
+ */
+public class DisableConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public DisableConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create('x'));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+
+ client.enableConnection(getLong(line, Constants.OPT_XID), false);
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/DisableJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DisableJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/DisableJobFunction.java
new file mode 100644
index 0000000..a87e51f
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DisableJobFunction.java
@@ -0,0 +1,57 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.client.request.JobRequest;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Handles disabling of a job object.
+ */
+public class DisableJobFunction extends SqoopFunction {
+
+ private JobRequest jobRequest;
+
+ @SuppressWarnings("static-access")
+ public DisableJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .hasArg()
+ .create('j'));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_JID)) {
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
+ return null;
+ }
+
+ if (jobRequest == null) {
+ jobRequest = new JobRequest();
+ }
+
+ client.enableJob(getLong(line, Constants.OPT_JID), false);
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/EnableCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/EnableCommand.java b/shell/src/main/java/org/apache/sqoop/shell/EnableCommand.java
new file mode 100644
index 0000000..3b8c0b1
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/EnableCommand.java
@@ -0,0 +1,64 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class EnableCommand extends SqoopCommand {
+
+ private EnableConnectionFunction connectionFunction;
+ private EnableJobFunction jobFunction;
+
+ public EnableCommand(Shell shell) {
+ super(shell, Constants.CMD_ENABLE, Constants.CMD_ENABLE_SC,
+ new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
+ Constants.PRE_ENABLE, Constants.SUF_INFO);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeCommand(List args) {
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_ENABLE_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String)args.get(0);
+ if (func.equals(Constants.FN_CONNECTION)) {
+ if (connectionFunction == null) {
+ connectionFunction = new EnableConnectionFunction();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new EnableJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/EnableConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/EnableConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/EnableConnectionFunction.java
new file mode 100644
index 0000000..f782b16
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/EnableConnectionFunction.java
@@ -0,0 +1,49 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Handles enabling of a connection object
+ */
+public class EnableConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public EnableConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create('x'));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+
+ client.enableConnection(getLong(line, Constants.OPT_XID), true);
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/EnableJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/EnableJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/EnableJobFunction.java
new file mode 100644
index 0000000..20c80dc
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/EnableJobFunction.java
@@ -0,0 +1,57 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.client.request.JobRequest;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Handles disabling of a job object.
+ */
+public class EnableJobFunction extends SqoopFunction {
+
+ private JobRequest jobRequest;
+
+ @SuppressWarnings("static-access")
+ public EnableJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .hasArg()
+ .create('j'));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_JID)) {
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
+ return null;
+ }
+
+ if (jobRequest == null) {
+ jobRequest = new JobRequest();
+ }
+
+ client.enableJob(getLong(line, Constants.OPT_JID), true);
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/HelpCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/HelpCommand.java b/shell/src/main/java/org/apache/sqoop/shell/HelpCommand.java
new file mode 100644
index 0000000..e8d531f
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/HelpCommand.java
@@ -0,0 +1,153 @@
+/**
+ * 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.shell;
+
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Command;
+import org.codehaus.groovy.tools.shell.CommandSupport;
+import org.codehaus.groovy.tools.shell.Shell;
+import org.codehaus.groovy.tools.shell.util.SimpleCompletor;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+public class HelpCommand extends CommandSupport {
+
+ protected HelpCommand(Shell shell) {
+ super(shell, Constants.CMD_HELP, Constants.CMD_HELP_SC);
+ }
+
+ @Override
+ public String getDescription() {
+ return resourceString(Constants.RES_HELP_DESCRIPTION);
+ }
+
+ @Override
+ public String getUsage() {
+ return resourceString(Constants.RES_HELP_USAGE);
+ }
+
+ @Override
+ public String getHelp() {
+ return resourceString(Constants.RES_HELP_MESSAGE);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Object execute(List args) {
+ if (args.size() == 0) {
+ list();
+ }
+ else {
+ help((String)args.get(0));
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void list() {
+ Iterator<Command> iterator;
+
+ // Figure out the max command name and shortcut length dynamically
+ int maxName = 0;
+ int maxShortcut = 0;
+ iterator = shell.getRegistry().commands().iterator();
+ while (iterator.hasNext()) {
+ Command command = iterator.next();
+ if (command.getHidden()) {
+ continue;
+ }
+
+ if (command.getName().length() > maxName) {
+ maxName = command.getName().length();
+ }
+
+ if (command.getShortcut().length() > maxShortcut) {
+ maxShortcut = command.getShortcut().length();
+ }
+ }
+
+ printlnResource(Constants.RES_HELP_INFO);
+ println();
+
+ // List the commands we know about
+ printlnResource(Constants.RES_HELP_AVAIL_COMMANDS);
+
+ iterator = shell.getRegistry().commands().iterator();
+ while (iterator.hasNext()) {
+ Command command = iterator.next();
+ if (command.getHidden()) {
+ continue;
+ }
+
+ 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(resource.getString(Constants
+ .RES_HELP_CMD_DESCRIPTION), paddedName,
+ paddedShortcut, description));
+ println(sb.toString());
+ }
+
+ 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(resource.getString(Constants
+ .RES_UNRECOGNIZED_CMD), name);
+ throw new SqoopException(ShellError.SHELL_0001, msg);
+ }
+ printlnResource(Constants.RES_HELP_CMD_USAGE, command.getName(), command.getUsage());
+ println();
+ println(command.getHelp());
+ println();
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected List createCompletors() {
+ SimpleCompletor completor = new SimpleCompletor();
+ Iterator<Command> iterator = registry.iterator();
+ while (iterator.hasNext()) {
+ Command command = iterator.next();
+ if (command.getHidden()) {
+ continue;
+ }
+
+ completor.add(command.getName());
+ }
+
+ List completors = new LinkedList();
+ completors.add(completor);
+ return completors;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java b/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java
new file mode 100644
index 0000000..548def0
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java
@@ -0,0 +1,64 @@
+/**
+ * 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.shell;
+
+import java.util.List;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import static org.apache.sqoop.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},
+ Constants.PRE_SET, Constants.SUF_INFO);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public Object executeCommand(List args) {
+
+ if (args.size() == 0) {
+ 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();
+ }
+ return serverFunction.execute(args);
+
+ } else if (func.equals(Constants.FN_OPTION)) {
+ if (optionFunction == null) {
+ optionFunction = new SetOptionFunction();
+ }
+ return optionFunction.execute(args);
+
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/SetOptionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SetOptionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/SetOptionFunction.java
new file mode 100644
index 0000000..1c43dce
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/SetOptionFunction.java
@@ -0,0 +1,87 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class SetOptionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ protected SetOptionFunction() {
+ this.addOption(OptionBuilder.hasArg()
+ .withDescription(resourceString(Constants.RES_SET_PROMPT_OPT_NAME))
+ .withLongOpt(Constants.OPT_NAME)
+ .create(Constants.OPT_NAME_CHAR));
+ this.addOption(OptionBuilder.hasArg()
+ .withDescription(resourceString(Constants.RES_SET_PROMPT_OPT_VALUE))
+ .withLongOpt(Constants.OPT_VALUE)
+ .create(Constants.OPT_VALUE_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_NAME)) {
+ printlnResource(Constants.RES_ARGS_NAME_MISSING);
+ return null;
+ }
+ if (!line.hasOption(Constants.OPT_VALUE)) {
+ printlnResource(Constants.RES_ARGS_VALUE_MISSING);
+ return null;
+ }
+
+ handleOptionSetting(line.getOptionValue(Constants.OPT_NAME), line.getOptionValue(Constants.OPT_VALUE));
+
+ return null;
+ }
+
+ private void handleOptionSetting(String name, String value) {
+ if(name.equals(Constants.OPT_VERBOSE)) {
+ boolean newValue = false;
+
+ if(value.equals("1") || value.equals("true")) {
+ newValue = true;
+ }
+
+ setVerbose(newValue);
+ printlnResource(Constants.RES_SET_VERBOSE_CHANGED, newValue);
+ return;
+ }
+
+ if (name.equals(Constants.OPT_POLL_TIMEOUT)) {
+ long newValue = 0;
+
+ try {
+ newValue = Long.parseLong(value);
+ } catch (NumberFormatException ex) {
+ // make the value stay the same
+ newValue = getPollTimeout();
+ }
+
+ setPollTimeout(newValue);
+ printlnResource(Constants.RES_SET_POLL_TIMEOUT_CHANGED, newValue);
+ return;
+ }
+
+ printlnResource(Constants.RES_SET_UNKNOWN_OPT_IGNORED, name);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/SetServerFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SetServerFunction.java b/shell/src/main/java/org/apache/sqoop/shell/SetServerFunction.java
new file mode 100644
index 0000000..abd9cea
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/SetServerFunction.java
@@ -0,0 +1,78 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+@SuppressWarnings("serial")
+public class SetServerFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ protected SetServerFunction() {
+ this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_HOST)
+ .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(resourceString(Constants.RES_SET_PORT_DESCRIPTION))
+ .withLongOpt(Constants.OPT_PORT)
+ .create(Constants.OPT_PORT_CHAR));
+ this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_WEBAPP)
+ .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) {
+ if (line.getArgs().length == 1) {
+ printlnResource(Constants.RES_SET_SERVER_USAGE);
+ return null;
+ }
+
+ 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);
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.java b/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.java
new file mode 100644
index 0000000..8be2e54
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShellEnvironment.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.shell;
+
+import org.apache.sqoop.client.SqoopClient;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+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;
+
+/**
+ * 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 final long DEFAULT_POLL_TIMEOUT = 10000;
+
+ 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;
+ private static long pollTimeout = DEFAULT_POLL_TIMEOUT;
+
+ static ResourceBundle resource = ResourceBundle.getBundle(Constants.RESOURCE_NAME, Locale.getDefault());
+ 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;
+ }
+
+ 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 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(ShellError.SHELL_0003, ex);
+ }
+ }
+
+ 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 isVerbose() {
+ return verbose;
+ }
+
+ public static void setInteractive(boolean newValue) {
+ interactive = newValue;
+ }
+
+ public static boolean isInteractive() {
+ return interactive;
+ }
+
+ public static void setPollTimeout(long timeout) {
+ pollTimeout = timeout;
+ }
+
+ public static long getPollTimeout() {
+ return pollTimeout;
+ }
+
+ 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);
+ }
+
+ public static void print(String format, Object... args) {
+ io.out.printf(format, args);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java b/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
new file mode 100644
index 0000000..672fa85
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
@@ -0,0 +1,106 @@
+/**
+ * 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.shell;
+
+import java.util.List;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+public class ShowCommand extends SqoopCommand
+{
+ private ShowServerFunction serverFunction;
+ private ShowVersionFunction versionFunction;
+ private ShowConnectorFunction connectorFunction;
+ private ShowJobFunction jobFunction;
+ private ShowSubmissionFunction submissionFunction;
+ private ShowFrameworkFunction frameworkFunction;
+ private ShowConnectionFunction connectionFunction;
+ private ShowOptionFunction optionFunction;
+
+
+ protected ShowCommand(Shell shell) {
+ super(shell, Constants.CMD_SHOW, Constants.CMD_SHOW_SC,
+ new String[] {Constants.FN_SERVER, Constants.FN_VERSION,
+ Constants.FN_CONNECTOR, Constants.FN_FRAMEWORK,
+ Constants.FN_CONNECTION, Constants.FN_JOB, Constants.FN_SUBMISSION, Constants.FN_OPTION },
+ Constants.PRE_SHOW, Constants.SUF_INFO);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public Object executeCommand(List args) {
+ if (args.size() == 0) {
+ 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();
+ }
+ return serverFunction.execute(args);
+
+ } else if (func.equals(Constants.FN_VERSION)) {
+ if (versionFunction == null) {
+ versionFunction = new ShowVersionFunction();
+ }
+ return versionFunction.execute(args);
+
+ } else if (func.equals(Constants.FN_CONNECTOR)) {
+ if (connectorFunction == null) {
+ connectorFunction = new ShowConnectorFunction();
+ }
+ return connectorFunction.execute(args);
+
+ } else if (func.equals(Constants.FN_FRAMEWORK)) {
+ if (frameworkFunction == null) {
+ frameworkFunction = new ShowFrameworkFunction();
+ }
+ return frameworkFunction.execute(args);
+
+ } else if (func.equals(Constants.FN_CONNECTION)) {
+ if (connectionFunction == null) {
+ connectionFunction = new ShowConnectionFunction();
+ }
+ return connectionFunction.execute(args);
+
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new ShowJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else if (func.equals(Constants.FN_SUBMISSION)) {
+ if (submissionFunction == null) {
+ submissionFunction = new ShowSubmissionFunction();
+ }
+ return submissionFunction.execute(args);
+ } else if (func.equals(Constants.FN_OPTION)) {
+ if (optionFunction == null) {
+ optionFunction = new ShowOptionFunction();
+ }
+ return optionFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowConnectionFunction.java
new file mode 100644
index 0000000..b7204ff
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowConnectionFunction.java
@@ -0,0 +1,123 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.TableDisplayer;
+
+import java.text.DateFormat;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormDisplayer.*;
+
+/**
+ *
+ */
+public class ShowConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ protected ShowConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNS))
+ .withLongOpt(Constants.OPT_ALL)
+ .create(Constants.OPT_ALL_CHAR));
+ this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_XID)
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONN_XID))
+ .withLongOpt(Constants.OPT_XID)
+ .create(Constants.OPT_XID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (line.hasOption(Constants.OPT_ALL)) {
+ showConnections();
+ } else if (line.hasOption(Constants.OPT_XID)) {
+ showConnection(getLong(line, Constants.OPT_XID));
+ } else {
+ showSummary();
+ }
+
+ return null;
+ }
+
+ private void showSummary() {
+ List<MConnection> connections = client.getConnections();
+
+ List<String> header = new LinkedList<String>();
+ header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_ENABLED));
+
+ List<String> ids = new LinkedList<String>();
+ List<String> names = new LinkedList<String>();
+ List<String> connectors = new LinkedList<String>();
+ List<String> availabilities = new LinkedList<String>();
+
+ for(MConnection connection : connections) {
+ ids.add(String.valueOf(connection.getPersistenceId()));
+ names.add(connection.getName());
+ connectors.add(String.valueOf(connection.getConnectorId()));
+ availabilities.add(String.valueOf(connection.getEnabled()));
+ }
+
+ TableDisplayer.display(header, ids, names, connectors, availabilities);
+ }
+
+ private void showConnections() {
+ List<MConnection> connections = client.getConnections();
+
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNS_TO_SHOW, connections.size());
+
+ for (MConnection connection : connections) {
+ displayConnection(connection);
+ }
+ }
+
+ private void showConnection(Long xid) {
+ MConnection connection = client.getConnection(xid);
+
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNS_TO_SHOW, 1);
+
+ displayConnection(connection);
+ }
+
+ private void displayConnection(MConnection connection) {
+ DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
+
+ printlnResource(Constants.RES_SHOW_PROMPT_CONN_INFO,
+ connection.getPersistenceId(),
+ connection.getName(),
+ connection.getEnabled(),
+ formatter.format(connection.getCreationDate()),
+ formatter.format(connection.getLastUpdateDate())
+ );
+
+ long connectorId = connection.getConnectorId();
+ printlnResource(Constants.RES_SHOW_PROMPT_CONN_CID_INFO, connectorId);
+
+ // Display connector part
+ displayForms(connection.getConnectorPart().getForms(),
+ client.getResourceBundle(connectorId));
+ displayForms(connection.getFrameworkPart().getForms(),
+ client.getFrameworkResourceBundle());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowConnectorFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowConnectorFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowConnectorFunction.java
new file mode 100644
index 0000000..97a4ab2
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowConnectorFunction.java
@@ -0,0 +1,110 @@
+/**
+ * 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.shell;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MConnector;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.TableDisplayer;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormDisplayer.*;
+
+@SuppressWarnings("serial")
+public class ShowConnectorFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ protected ShowConnectorFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS))
+ .withLongOpt(Constants.OPT_ALL)
+ .create(Constants.OPT_ALL_CHAR));
+ this.addOption(OptionBuilder.hasArg().withArgName("cid")
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID))
+ .withLongOpt(Constants.OPT_CID)
+ .create(Constants.OPT_CID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (line.hasOption(Constants.OPT_ALL)) {
+ showConnectors();
+ } else if (line.hasOption(Constants.OPT_CID)) {
+ showConnector(getLong(line, Constants.OPT_CID));
+ } else {
+ showSummary();
+ }
+
+ return null;
+ }
+
+ private void showSummary() {
+ Collection<MConnector> connectors = client.getConnectors();
+
+ List<String> header = new LinkedList<String>();
+ header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_VERSION));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_CLASS));
+
+ List<String> ids = new LinkedList<String>();
+ List<String> uniqueNames = new LinkedList<String>();
+ List<String> versions = new LinkedList<String>();
+ List<String> classes = new LinkedList<String>();
+
+ for(MConnector connector : connectors) {
+ ids.add(String.valueOf(connector.getPersistenceId()));
+ uniqueNames.add(connector.getUniqueName());
+ versions.add(connector.getVersion());
+ classes.add(connector.getClassName());
+ }
+
+ TableDisplayer.display(header, ids, uniqueNames, versions, classes);
+ }
+
+ private void showConnectors() {
+ Collection<MConnector> connectors = client.getConnectors();
+
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, connectors.size());
+
+ for (MConnector connector : connectors) {
+ displayConnector(connector);
+ }
+ }
+
+ private void showConnector(Long cid) {
+ MConnector connector = client.getConnector(cid);
+
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, 1);
+
+ displayConnector(connector);
+ }
+
+ private void displayConnector(MConnector connector) {
+ printlnResource(Constants.RES_SHOW_PROMPT_CONNECTOR_INFO,
+ connector.getPersistenceId(),
+ connector.getUniqueName(),
+ connector.getClassName(),
+ connector.getVersion()
+ );
+ displayFormMetadataDetails(connector, client.getResourceBundle(connector.getPersistenceId()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowFrameworkFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowFrameworkFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowFrameworkFunction.java
new file mode 100644
index 0000000..28497db
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowFrameworkFunction.java
@@ -0,0 +1,55 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.sqoop.model.MFramework;
+import org.apache.sqoop.shell.core.Constants;
+
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormDisplayer.*;
+
+/**
+ *
+ */
+public class ShowFrameworkFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ protected ShowFrameworkFunction() {
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length != 0) {
+ printlnResource(Constants.RES_SHOW_FRAMEWORK_USAGE);
+ return null;
+ }
+
+ showFramework();
+
+ return null;
+ }
+
+ private void showFramework() {
+ MFramework framework = client.getFramework();
+ ResourceBundle bundle = client.getFrameworkResourceBundle();
+
+ printlnResource(Constants.RES_SHOW_PROMPT_FRAMEWORK_OPTS, framework.getPersistenceId());
+ displayFormMetadataDetails(framework, bundle);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowJobFunction.java
new file mode 100644
index 0000000..fc6f416
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowJobFunction.java
@@ -0,0 +1,125 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.TableDisplayer;
+
+import java.text.DateFormat;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormDisplayer.*;
+
+/**
+ *
+ */
+public class ShowJobFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ protected ShowJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_JOBS))
+ .withLongOpt(Constants.OPT_ALL)
+ .create(Constants.OPT_ALL_CHAR));
+ this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOB_JID))
+ .withLongOpt(Constants.OPT_JID)
+ .create(Constants.OPT_JID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (line.hasOption(Constants.OPT_ALL)) {
+ showJobs();
+ } else if (line.hasOption(Constants.OPT_JID)) {
+ showJob(getLong(line, Constants.OPT_JID));
+ } else {
+ showSummary();
+ }
+
+ return null;
+ }
+
+ private void showSummary() {
+ List<MJob> jobs = client.getJobs();
+
+ List<String> header = new LinkedList<String>();
+ header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_TYPE));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_ENABLED));
+
+ List<String> ids = new LinkedList<String>();
+ List<String> names = new LinkedList<String>();
+ List<String> types = new LinkedList<String>();
+ List<String> connectors = new LinkedList<String>();
+ List<String> availabilities = new LinkedList<String>();
+
+ for(MJob job : jobs) {
+ ids.add(String.valueOf(job.getPersistenceId()));
+ names.add(job.getName());
+ types.add(job.getType().toString());
+ connectors.add(String.valueOf(job.getConnectorId()));
+ availabilities.add(String.valueOf(job.getEnabled()));
+ }
+
+ TableDisplayer.display(header, ids, names, types, connectors, availabilities);
+ }
+
+ private void showJobs() {
+ List<MJob> jobs = client.getJobs();
+ printlnResource(Constants.RES_SHOW_PROMPT_JOBS_TO_SHOW, jobs.size());
+
+ for (MJob job : jobs) {
+ displayJob(job);
+ }
+ }
+
+ private void showJob(Long jid) {
+ MJob job = client.getJob(jid);
+ printlnResource(Constants.RES_SHOW_PROMPT_JOBS_TO_SHOW, 1);
+
+ displayJob(job);
+ }
+
+ private void displayJob(MJob job) {
+ DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
+
+ printlnResource(
+ Constants.RES_SHOW_PROMPT_JOB_INFO,
+ job.getPersistenceId(),
+ job.getName(),
+ job.getEnabled(),
+ formatter.format(job.getCreationDate()),
+ formatter.format(job.getLastUpdateDate())
+ );
+ printlnResource(Constants.RES_SHOW_PROMPT_JOB_XID_CID_INFO,
+ job.getConnectionId(),
+ job.getConnectorId());
+
+ // Display connector part
+ displayForms(job.getConnectorPart().getForms(),
+ client.getResourceBundle(job.getConnectorId()));
+ displayForms(job.getFrameworkPart().getForms(),
+ client.getFrameworkResourceBundle());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
new file mode 100644
index 0000000..5e3c3ff
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowOptionFunction.java
@@ -0,0 +1,89 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Show client internal options
+ */
+public class ShowOptionFunction extends SqoopFunction {
+ /**
+ * Construct new object.
+ */
+ @SuppressWarnings("static-access")
+ protected ShowOptionFunction() {
+ this.addOption(OptionBuilder
+ .hasArg().withArgName(Constants.OPT_NAME)
+ .withDescription(resource.getString(Constants.RES_SET_PROMPT_OPT_NAME))
+ .withLongOpt(Constants.OPT_NAME)
+ .create(Constants.OPT_NAME_CHAR));
+ }
+
+ /**
+ * Execute this function from parsed command line.
+ */
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length == 1) {
+ printAllOptions();
+ return null;
+ }
+
+ if (line.hasOption(Constants.OPT_NAME)) {
+ String optionName = line.getOptionValue(Constants.OPT_NAME);
+
+ if(optionName.equals(Constants.OPT_VERBOSE)) {
+ printVerbose();
+ }
+
+ if(optionName.equals(Constants.OPT_POLL_TIMEOUT)) {
+ printPollTimeout();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Print all known client options.
+ */
+ private void printAllOptions() {
+ printVerbose();
+ printPollTimeout();
+ }
+
+ /**
+ * Print verbose option.
+ */
+ private void printVerbose() {
+ print("Verbose = ");
+ println(String.valueOf(isVerbose()));
+ }
+
+ /**
+ * Print poll-timeout option.
+ */
+ private void printPollTimeout() {
+ print("Poll-timeout = ");
+ println(String.valueOf(getPollTimeout()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowServerFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowServerFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowServerFunction.java
new file mode 100644
index 0000000..ec97e63
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowServerFunction.java
@@ -0,0 +1,88 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+@SuppressWarnings("serial")
+public class ShowServerFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ protected ShowServerFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_SERVERS))
+ .withLongOpt(Constants.OPT_ALL)
+ .create(Constants.OPT_ALL_CHAR));
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_HOST))
+ .withLongOpt(Constants.OPT_HOST)
+ .create(Constants.OPT_HOST_CHAR));
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_PORT))
+ .withLongOpt(Constants.OPT_PORT)
+ .create(Constants.OPT_PORT_CHAR));
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_WEBAPP))
+ .withLongOpt(Constants.OPT_WEBAPP)
+ .create(Constants.OPT_WEBAPP_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length == 1) {
+ printlnResource(Constants.RES_SHOW_SERVER_USAGE);
+ return null;
+ }
+
+ if (line.hasOption(Constants.OPT_ALL)) {
+ showServer(true, true, true, true);
+
+ } else {
+ boolean host = false, port = false, webapp = false, version = false;
+ if (line.hasOption(Constants.OPT_HOST)) {
+ host = true;
+ }
+ if (line.hasOption(Constants.OPT_PORT)) {
+ port = true;
+ }
+ if (line.hasOption(Constants.OPT_WEBAPP)) {
+ webapp = true;
+ }
+
+ showServer(host, port, webapp, version);
+ }
+
+ return null;
+ }
+
+ private void showServer(boolean host, boolean port, boolean webapp, boolean version) {
+ if (host) {
+ printlnResource(Constants.RES_SHOW_PROMPT_SERVER_HOST, getServerHost());
+ }
+
+ if (port) {
+ printlnResource(Constants.RES_SHOW_PROMPT_SERVER_PORT, getServerPort());
+ }
+
+ if (webapp) {
+ printlnResource(Constants.RES_SHOW_PROMPT_SERVER_WEBAPP, getServerWebapp());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowSubmissionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowSubmissionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowSubmissionFunction.java
new file mode 100644
index 0000000..a592a98
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowSubmissionFunction.java
@@ -0,0 +1,105 @@
+/**
+ * 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.shell;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.SubmissionDisplayer;
+import org.apache.sqoop.shell.utils.TableDisplayer;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+public class ShowSubmissionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ protected ShowSubmissionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS))
+ .withLongOpt(Constants.OPT_DETAIL)
+ .create(Constants.OPT_DETAIL_CHAR));
+ this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .create(Constants.OPT_JID_CHAR));
+ }
+
+ @Override
+ public Object executeFunction(CommandLine line) {
+ if (line.hasOption(Constants.OPT_DETAIL)) {
+ if (line.hasOption(Constants.OPT_JID)) {
+ showSubmissions(getLong(line, Constants.OPT_JID));
+ } else {
+ showSubmissions(null);
+ }
+ } else {
+ if (line.hasOption(Constants.OPT_JID)) {
+ showSummary(getLong(line, Constants.OPT_JID));
+ } else {
+ showSummary(null);
+ }
+ }
+
+ return null;
+ }
+
+ private void showSummary(Long jid) {
+ List<MSubmission> submissions;
+ if (jid == null) {
+ submissions = client.getSubmissions();
+ } else {
+ submissions = client.getSubmissionsForJob(jid);
+ }
+
+ List<String> header = new LinkedList<String>();
+ header.add(resourceString(Constants.RES_TABLE_HEADER_JOB_ID));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_EXTERNAL_ID));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_STATUS));
+ header.add(resourceString(Constants.RES_TABLE_HEADER_DATE));
+
+ List<String> jids = new LinkedList<String>();
+ List<String> eids = new LinkedList<String>();
+ List<String> status = new LinkedList<String>();
+ List<String> dates = new LinkedList<String>();
+
+ for (MSubmission submission : submissions) {
+ jids.add(String.valueOf(submission.getJobId()));
+ eids.add(String.valueOf(submission.getExternalId()));
+ status.add(submission.getStatus().toString());
+ dates.add(submission.getLastUpdateDate().toString());
+ }
+
+ TableDisplayer.display(header, jids, eids, status, dates);
+ }
+
+ private void showSubmissions(Long jid) {
+ List<MSubmission> submissions;
+ if (jid == null) {
+ submissions = client.getSubmissions();
+ } else {
+ submissions = client.getSubmissionsForJob(jid);
+ }
+
+ for (MSubmission submission : submissions) {
+ SubmissionDisplayer.displaySubmission(submission);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java
new file mode 100644
index 0000000..764b754
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowVersionFunction.java
@@ -0,0 +1,127 @@
+/**
+ * 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.shell;
+
+import java.util.Arrays;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.client.request.VersionRequest;
+import org.apache.sqoop.common.VersionInfo;
+import org.apache.sqoop.json.VersionBean;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+@SuppressWarnings("serial")
+public class ShowVersionFunction extends SqoopFunction {
+ private VersionRequest versionRequest;
+
+
+ @SuppressWarnings("static-access")
+ protected ShowVersionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_VERSIONS))
+ .withLongOpt(Constants.OPT_ALL)
+ .create(Constants.OPT_ALL_CHAR));
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_SERVER))
+ .withLongOpt(Constants.OPT_SERVER)
+ .create(Constants.OPT_SERVER_CHAR));
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_CLIENT))
+ .withLongOpt(Constants.OPT_CLIENT)
+ .create(Constants.OPT_CLIENT_CHAR));
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_PROTOCOL))
+ .withLongOpt(Constants.OPT_PROTOCOL)
+ .create(Constants.OPT_PROTOCOL_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (line.getArgs().length == 1) {
+ printlnResource(Constants.RES_SHOW_VERSION_USAGE);
+ return null;
+ }
+
+ if (line.hasOption(Constants.OPT_ALL)) {
+ showVersion(true, true, true);
+
+ } else {
+ boolean server = false, client = false, protocol = false;
+ if (line.hasOption(Constants.OPT_SERVER)) {
+ server = true;
+ }
+ if (line.hasOption(Constants.OPT_CLIENT)) {
+ client = true;
+ }
+ if (line.hasOption(Constants.OPT_PROTOCOL)) {
+ protocol = true;
+ }
+
+ showVersion(server, client, protocol);
+ }
+
+ return null;
+ }
+
+ private void showVersion(boolean server, boolean client, boolean protocol) {
+
+ // If no option has been given, print out client version as default
+ if (!client && !server && !protocol) {
+ client = true;
+ }
+
+ // Print out client string if needed
+ if (client) {
+ printlnResource(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER,
+ Constants.OPT_CLIENT,
+ VersionInfo.getVersion(),
+ VersionInfo.getRevision(),
+ VersionInfo.getUser(),
+ VersionInfo.getDate()
+ );
+ }
+
+ // If only client version was required we do not need to continue
+ if(!server && !protocol) {
+ return;
+ }
+
+ if (versionRequest == null) {
+ versionRequest = new VersionRequest();
+ }
+ VersionBean versionBean = versionRequest.doGet(getServerUrl());
+
+ if (server) {
+ printlnResource(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER,
+ Constants.OPT_SERVER,
+ versionBean.getVersion(),
+ versionBean.getRevision(),
+ versionBean.getUser(),
+ versionBean.getDate()
+ );
+ }
+
+ if (protocol) {
+ printlnResource(Constants.RES_SHOW_PROMPT_VERSION_PROTOCOL,
+ Arrays.toString(versionBean.getProtocols())
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java b/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java
new file mode 100644
index 0000000..241d120
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java
@@ -0,0 +1,152 @@
+/**
+ * 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.shell;
+
+import groovy.lang.GroovyShell;
+import groovy.lang.MissingPropertyException;
+import groovy.lang.Script;
+
+import java.util.*;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+import org.codehaus.groovy.tools.shell.ComplexCommandSupport;
+import org.codehaus.groovy.tools.shell.Shell;
+
+public abstract class SqoopCommand extends ComplexCommandSupport
+{
+ private String descriptionPrefix;
+ private String descriptionPostfix;
+
+ private String description;
+ private String usage;
+ private String help;
+
+ @SuppressWarnings("unchecked")
+ protected SqoopCommand(Shell shell, String name, String shortcut,
+ String[] funcs, String descriptionPrefix, String descriptionPostfix) {
+ super(shell, name, shortcut);
+
+ this.functions = new LinkedList<String>();
+ for (String func : funcs) {
+ this.functions.add(func);
+ }
+
+ this.descriptionPrefix = descriptionPrefix;
+ this.descriptionPostfix = descriptionPostfix;
+ }
+
+ @Override
+ public String getDescription() {
+ if (description == null) {
+ StringBuilder sb = new StringBuilder();
+
+ if (descriptionPrefix != null) {
+ sb.append(descriptionPrefix);
+ sb.append(" ");
+ }
+
+ @SuppressWarnings("unchecked")
+ Iterator<String> iterator = functions.iterator();
+ int size = functions.size();
+ sb.append(iterator.next());
+ if (size > 1) {
+ for (int i = 1; i < (size - 1); i++) {
+ sb.append(", ");
+ sb.append(iterator.next());
+ }
+ sb.append(" or ");
+ sb.append(iterator.next());
+ }
+
+ if (descriptionPostfix != null) {
+ sb.append(" ");
+ sb.append(descriptionPostfix);
+ }
+
+ description = sb.toString();
+ }
+
+ return description;
+ }
+
+ @Override
+ public String getUsage() {
+ if (usage == null) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("[");
+
+ @SuppressWarnings("unchecked")
+ Iterator<String> iterator = functions.iterator();
+ int size = functions.size();
+ sb.append(iterator.next());
+ for (int i = 1; i < size; i++) {
+ sb.append("|");
+ sb.append(iterator.next());
+ }
+
+ sb.append("]");
+
+ usage = sb.toString();
+ }
+
+ return usage;
+ }
+
+ @Override
+ public String getHelp() {
+ if (help == null) {
+ help = getDescription() + ".";
+ }
+
+ return help;
+ }
+
+ /**
+ * Override execute method
+ */
+ @Override
+ public Object execute(List args) {
+ resolveVariables(args);
+ return executeCommand(args);
+ }
+
+ /**
+ * Abstract executeCommand
+ * @param args list
+ * @return Object
+ */
+ public abstract Object executeCommand(List args);
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected void resolveVariables(List arg) {
+ List temp = new ArrayList();
+ GroovyShell gs = new GroovyShell(getBinding());
+ for(Object obj:arg) {
+ Script scr = gs.parse("\""+(String)obj+"\"");
+ try {
+ temp.add(scr.run().toString());
+ }
+ catch(MissingPropertyException e) {
+ throw new SqoopException(ShellError.SHELL_0004, e.getMessage(), e);
+ }
+ }
+ Collections.copy(arg, temp);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/SqoopFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SqoopFunction.java b/shell/src/main/java/org/apache/sqoop/shell/SqoopFunction.java
new file mode 100644
index 0000000..675a796
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/SqoopFunction.java
@@ -0,0 +1,74 @@
+/**
+ * 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.shell;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+@SuppressWarnings("serial")
+abstract public class SqoopFunction extends Options {
+
+ public void printHelp() {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printOptions(getIo().out, formatter.getWidth(), this, 0, 4);
+ }
+
+ public abstract Object executeFunction(CommandLine line);
+
+ public Object execute(List<String> args) {
+ CommandLine line = parseOptions(this, 1, args);
+ return executeFunction(line);
+ }
+
+ protected CommandLine parseOptions(Options options, int start, List<String> arglist) {
+ Iterator<String> iterator = arglist.iterator();
+ int i = 0;
+ for (; i < start; i ++) {
+ iterator.next();
+ }
+
+ String[] args = new String[arglist.size() - start];
+ for (; i < arglist.size(); i ++) {
+ args[i - start] = iterator.next();
+ }
+
+ CommandLineParser parser = new GnuParser();
+ CommandLine line;
+ try {
+ line = parser.parse(options, args);
+ } catch (ParseException e) {
+ throw new SqoopException(ShellError.SHELL_0003, e.getMessage(), e);
+ }
+ return line;
+ }
+
+ protected long getLong(CommandLine line, String parameterName) {
+ return Long.parseLong(line.getOptionValue(parameterName));
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java b/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java
new file mode 100644
index 0000000..900c0e5
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java
@@ -0,0 +1,176 @@
+/**
+ * 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.shell;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.ThrowableDisplayer;
+import org.codehaus.groovy.runtime.MethodClosure;
+import org.codehaus.groovy.tools.shell.Command;
+import org.codehaus.groovy.tools.shell.CommandRegistry;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.codehaus.groovy.tools.shell.IO.Verbosity;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Main entry point to Sqoop client.
+ *
+ * Sqoop shell is implemented on top of Groovy shell.
+ */
+public final class SqoopShell {
+
+ /**
+ * Location of resource file that can contain few initial commands that will
+ * be loaded during each client execution.
+ */
+ private static final String RC_FILE = ".sqoop2rc";
+
+ /**
+ * Banner message that is displayed in interactive mode after client start.
+ */
+
+ /**
+ * Hash of commands that we want to have in history in all cases.
+ */
+ public final static HashSet<String> commandsToKeep;
+
+ static {
+ commandsToKeep = new HashSet<String>();
+ commandsToKeep.add("exit");
+ commandsToKeep.add("history");
+ }
+
+ /**
+ * Main entry point to the client execution.
+ *
+ * @param args Command line arguments
+ * @throws Exception
+ */
+ public static void main (String[] args) throws Exception {
+ System.setProperty("groovysh.prompt", Constants.SQOOP_PROMPT);
+ Groovysh shell = new Groovysh();
+
+ // Install our error hook (exception handling)
+ shell.setErrorHook(new MethodClosure(ThrowableDisplayer.class, "errorHook"));
+
+ CommandRegistry registry = shell.getRegistry();
+ @SuppressWarnings("unchecked")
+ Iterator<Command> iterator = registry.iterator();
+ while (iterator.hasNext()) {
+ Command command = iterator.next();
+ if (!commandsToKeep.contains(command.getName())) {
+ iterator.remove();
+ // remove from "names" set to avoid duplicate error.
+ registry.remove(command);
+ }
+ }
+
+ shell.register(new HelpCommand(shell));
+ shell.register(new SetCommand(shell));
+ shell.register(new ShowCommand(shell));
+ shell.register(new CreateCommand(shell));
+ shell.register(new DeleteCommand(shell));
+ shell.register(new UpdateCommand(shell));
+ shell.register(new CloneCommand(shell));
+ shell.register(new StartCommand(shell));
+ shell.register(new StopCommand(shell));
+ shell.register(new StatusCommand(shell));
+ shell.register(new EnableCommand(shell));
+ shell.register(new DisableCommand(shell));
+
+ // Configure shared shell io object
+ setIo(shell.getIo());
+
+ // We're running in batch mode by default
+ setInteractive(false);
+
+ // Let's see if user do have resource file with initial commands that he
+ // would like to apply.
+ String homeDir = System.getProperty(Constants.PROP_HOMEDIR);
+ File rcFile = new File(homeDir, RC_FILE);
+
+ if(rcFile.exists()) {
+ printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADRC, RC_FILE);
+ interpretFileContent(rcFile, shell);
+ printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADEDRC);
+ }
+
+ if (args.length == 0) {
+ // Interactive mode:
+ getIo().setVerbosity(Verbosity.QUIET);
+ printlnResource(Constants.RES_SQOOP_SHELL_BANNER);
+ println();
+
+ // Switch to interactive mode
+ setInteractive(true);
+ shell.run(args);
+
+ } else {
+ // Batch mode (with a script file):
+ File script = new File(args[0]);
+ if (!script.isAbsolute()) {
+ String userDir = System.getProperty(Constants.PROP_CURDIR);
+ script = new File(userDir, args[0]);
+ }
+
+ interpretFileContent(script, shell);
+ }
+ }
+
+ /**
+ * Interpret file content in given shell.
+ *
+ * @param script Script file that should be interpreted
+ * @param shell Shell where the script should be interpreted
+ * @throws IOException
+ */
+ private static void interpretFileContent(File script, Groovysh shell) throws IOException {
+ BufferedReader in = new BufferedReader(new FileReader(script));
+ String line;
+
+ // Iterate over all lines and executed them one by one
+ while ((line = in.readLine()) != null) {
+
+ // Skip comments and empty lines as we don't need to interpret those
+ if(line.isEmpty() || line.startsWith("#")) {
+ continue;
+ }
+
+ // Render shell and command to get user perception that it was run as usual
+ print(shell.renderPrompt());
+ println(line);
+
+ // Manually trigger command line parsing
+ Object result = shell.execute(line);
+ if (result != null) {
+ println(result);
+ }
+ }
+ }
+
+ private SqoopShell() {
+ // Instantiation of this class is prohibited
+ }
+}
[4/6] SQOOP-921. Sqoop2: Create standalone shell package
Posted by hs...@apache.org.
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
deleted file mode 100644
index 425a53f..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
+++ /dev/null
@@ -1,95 +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.shell;
-
-import jline.ConsoleReader;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.FormDisplayer;
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.validation.Status;
-
-import java.io.IOException;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class UpdateJobFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public UpdateJobFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .hasArg()
- .create(Constants.OPT_JID_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_JID)) {
- printlnResource(Constants.RES_ARGS_JID_MISSING);
- return null;
- }
-
- try {
- updateJob(getLong(line, Constants.OPT_JID));
- } catch (IOException ex) {
- throw new SqoopException(ClientError.CLIENT_0005, ex);
- }
-
- return null;
- }
-
- private void updateJob(Long jobId) throws IOException {
- printlnResource(Constants.RES_UPDATE_UPDATING_JOB, jobId);
-
- ConsoleReader reader = new ConsoleReader();
-
- MJob job = client.getJob(jobId);
-
- ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
- ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
-
- Status status = Status.FINE;
-
- printlnResource(Constants.RES_PROMPT_UPDATE_JOB_METADATA);
-
- do {
- // Print error introduction if needed
- if( !status.canProceed() ) {
- errorIntroduction();
- }
-
- // Fill in data from user
- if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
- return;
- }
-
- // Try to create
- status = client.updateJob(job);
- } while(!status.canProceed());
- FormDisplayer.displayFormWarning(job);
- printlnResource(Constants.RES_UPDATE_JOB_SUCCESSFUL, status.name());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
deleted file mode 100644
index b044e22..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
+++ /dev/null
@@ -1,249 +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.utils;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.model.MAccountableEntity;
-import org.apache.sqoop.model.MBooleanInput;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.model.MEnumInput;
-import org.apache.sqoop.model.MForm;
-import org.apache.sqoop.model.MFramework;
-import org.apache.sqoop.model.MInput;
-import org.apache.sqoop.model.MInputType;
-import org.apache.sqoop.model.MIntegerInput;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.model.MJobForms;
-import org.apache.sqoop.model.MMapInput;
-import org.apache.sqoop.model.MStringInput;
-import org.apache.sqoop.validation.Status;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Convenience static methods for displaying form related information
- */
-public final class FormDisplayer {
-
- public static void displayFormMetadataDetails(MFramework framework,
- ResourceBundle bundle) {
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SUPPORTED_JOBTYPE));
- println(framework.getAllJobsForms().keySet().toString());
-
- displayFormsMetadata(
- framework.getConnectionForms().getForms(),
- resourceString(Constants.RES_FORMDISPLAYER_CONNECTION),
- bundle);
-
- for (MJobForms jobForms : framework.getAllJobsForms().values()) {
- print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_FORM_JOBTYPE));
- print(jobForms.getType().name());
- println(":");
-
- displayFormsMetadata(jobForms.getForms(), resourceString(Constants.RES_FORMDISPLAYER_JOB), bundle);
- }
- }
-
- public static void displayFormsMetadata(List<MForm> forms,
- String type,
- ResourceBundle bundle) {
- Iterator<MForm> fiter = forms.iterator();
- int findx = 1;
- while (fiter.hasNext()) {
- print(" ");
- print(type);
- print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_FORM));
- print(findx++);
- println(":");
-
- MForm form = fiter.next();
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_NAME));
- println(form.getName());
-
- // Label
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_LABEL));
- println(bundle.getString(form.getLabelKey()));
-
- // Help text
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_HELP));
- println(bundle.getString(form.getHelpKey()));
-
- List<MInput<?>> inputs = form.getInputs();
- Iterator<MInput<?>> iiter = inputs.iterator();
- int iindx = 1;
- while (iiter.hasNext()) {
- print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_INPUT));
- print(iindx++);
- println(":");
-
- MInput<?> input = iiter.next();
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_NAME));
- println(input.getName());
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_LABEL));
- println(bundle.getString(input.getLabelKey()));
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_HELP));
- println(bundle.getString(input.getHelpKey()));
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_TYPE));
- println(input.getType());
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SENSITIVE));
- println(input.isSensitive());
- if (input.getType() == MInputType.STRING) {
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SIZE));
- println(((MStringInput)input).getMaxLength());
- } else if(input.getType() == MInputType.ENUM) {
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_POSSIBLE_VALUES));
- println(StringUtils.join(((MEnumInput)input).getValues(), ","));
- }
- }
- }
- }
-
- public static void displayForms(List<MForm> forms, ResourceBundle bundle) {
- for(MForm form : forms) {
- displayForm(form, bundle);
- }
- }
-
- /**
- * Method prints the warning message of ACCEPTABLE status
- * @param entity - connection or job instance
- */
- public static void displayFormWarning(MAccountableEntity entity) {
- List<MForm> formList = new ArrayList<MForm>();
- boolean showMessage = true;
- if (entity instanceof MConnection) {
- MConnection connection = (MConnection) entity;
- formList.addAll(connection.getConnectorPart().getForms());
- formList.addAll(connection.getFrameworkPart().getForms());
- } else if(entity instanceof MJob) {
- MJob job = (MJob) entity;
- formList.addAll(job.getConnectorPart().getForms());
- formList.addAll(job.getFrameworkPart().getForms());
- }
- for(MForm form : formList) {
- if(form.getValidationStatus() == Status.ACCEPTABLE) {
- if(showMessage) {
- print("\n@|yellow %s|@\n", resourceString(Constants.RES_FORMDISPLAYER_FORM_WARNING));
- showMessage = false;
- }
- FormFiller.warningMessage(form.getValidationMessage());
- }
- }
- }
-
- private static void displayForm(MForm form, ResourceBundle bundle) {
- print(" ");
- println(bundle.getString(form.getLabelKey()));
-
- for (MInput<?> input : form.getInputs()) {
- print(" ");
- print(bundle.getString(input.getLabelKey()));
- print(": ");
- if(!input.isEmpty()) {
- if (input.isSensitive()) {
- print("(%s)", resourceString(Constants.RES_FORMDISPLAYER_INPUT_SENSITIVE));
- } else {
- // Based on the input type, let's perform specific load
- switch (input.getType()) {
- case STRING:
- displayInputString((MStringInput) input);
- break;
- case INTEGER:
- displayInputInteger((MIntegerInput) input);
- break;
- case BOOLEAN:
- displayInputBoolean((MBooleanInput) input);
- break;
- case MAP:
- displayInputMap((MMapInput) input);
- break;
- case ENUM:
- displayInputEnum((MEnumInput) input);
- break;
- default:
- print("\n%s " + input.getType(), resourceString(Constants.RES_FORMDISPLAYER_UNSUPPORTED_DATATYPE));
- return;
- }
- }
- }
- println("");
- }
- }
-
- /**
- * Display content of String input.
- *
- * @param input String input
- */
- private static void displayInputString(MStringInput input) {
- print(input.getValue());
- }
-
- /**
- * Display content of Integer input.
- *
- * @param input Integer input
- */
- private static void displayInputInteger(MIntegerInput input) {
- print(input.getValue());
- }
-
- /**
- * Display content of Boolean input.
- *
- * @param input Boolean input
- */
- private static void displayInputBoolean(MBooleanInput input) {
- print(input.getValue());
- }
-
- /**
- * Display content of Map input
- *
- * @param input Map input
- */
- private static void displayInputMap(MMapInput input) {
- for(Map.Entry<String, String> entry : input.getValue().entrySet()) {
- println();
- print(" ");
- print(entry.getKey());
- print(" = ");
- print(entry.getValue());
- }
- }
-
- /**
- * Display content of Enum input
- *
- * @param input Enum input
- */
- private static void displayInputEnum(MEnumInput input) {
- print(input.getValue());
- }
-
- private FormDisplayer() {
- // Do not instantiate
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java b/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
deleted file mode 100644
index 2fbf129..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
+++ /dev/null
@@ -1,566 +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.utils;
-
-import jline.ConsoleReader;
-import org.apache.sqoop.model.MBooleanInput;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.model.MEnumInput;
-import org.apache.sqoop.model.MForm;
-import org.apache.sqoop.model.MInput;
-import org.apache.sqoop.model.MIntegerInput;
-import org.apache.sqoop.model.MMapInput;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.model.MStringInput;
-import org.apache.sqoop.model.MValidatedElement;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Convenient methods for retrieving user input.
- */
-public final class FormFiller {
-
- /**
- * Internal input that will be reused for loading names for connection and
- * job objects.
- */
- private static MStringInput nameInput = new MStringInput("object-name", false, (short)25);
-
- /**
- * Fill job object based on user input.
- *
- * @param reader Associated console reader object
- * @param job Job that user is suppose to fill in
- * @param connectorBundle Connector resource bundle
- * @param frameworkBundle Framework resource bundle
- * @return True if we filled all inputs, false if user has stopped processing
- * @throws IOException
- */
- public static boolean fillJob(ConsoleReader reader,
- MJob job,
- ResourceBundle connectorBundle,
- ResourceBundle frameworkBundle)
- throws IOException {
-
- job.setName(getName(reader, job.getName()));
-
- // Fill in data from user
- return fillForms(reader,
- job.getConnectorPart().getForms(),
- connectorBundle,
- job.getFrameworkPart().getForms(),
- frameworkBundle);
- }
-
- /**
- * Fill connection object based on user input.
- *
- * @param reader Associated console reader object
- * @param connection Connection that user is suppose to fill in
- * @param connectorBundle Connector resource bundle
- * @param frameworkBundle Framework resouce bundle
- * @return True if we filled all inputs, false if user has stopped processing
- * @throws IOException
- */
- public static boolean fillConnection(ConsoleReader reader,
- MConnection connection,
- ResourceBundle connectorBundle,
- ResourceBundle frameworkBundle)
- throws IOException {
-
- connection.setName(getName(reader, connection.getName()));
-
- // Fill in data from user
- return fillForms(reader,
- connection.getConnectorPart().getForms(),
- connectorBundle,
- connection.getFrameworkPart().getForms(),
- frameworkBundle);
- }
-
- public static boolean fillForms(ConsoleReader reader,
- List<MForm> connectorForms,
- ResourceBundle connectorBundle,
- List<MForm> frameworkForms,
- ResourceBundle frameworkBundle
- ) throws IOException {
-
-
- // Query connector forms
- if(!fillForms(connectorForms, reader, connectorBundle)) {
- return false;
- }
-
- // Query framework forms
- if(!fillForms(frameworkForms, reader, frameworkBundle)) {
- return false;
- }
-
- return true;
- }
-
- public static boolean fillForms(List<MForm> forms,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- for (MForm form : forms) {
- if(!fillForm(form, reader, bundle)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean fillForm(MForm form,
- ConsoleReader reader,
- ResourceBundle bundle) throws IOException {
- println("");
- println(bundle.getString(form.getLabelKey()));
-
- // Print out form validation
- printValidationMessage(form);
- println("");
-
- for (MInput input : form.getInputs()) {
- if(!fillInput(input, reader, bundle)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean fillInput(MInput input,
- ConsoleReader reader,
- ResourceBundle bundle) throws IOException {
- // Print out validation
- printValidationMessage(input);
-
- // Based on the input type, let's perform specific load
- switch (input.getType()) {
- case STRING:
- return fillInputString((MStringInput) input, reader, bundle);
- case INTEGER:
- return fillInputInteger((MIntegerInput) input, reader, bundle);
- case BOOLEAN:
- return fillInputBoolean((MBooleanInput) input, reader, bundle);
- case MAP:
- return fillInputMap((MMapInput) input, reader, bundle);
- case ENUM:
- return fillInputEnum((MEnumInput) input, reader, bundle);
- default:
- println("Unsupported data type " + input.getType());
- return true;
- }
- }
-
- /**
- * Load user input for enum type.
- *
- * Print out numbered list of all available options and let user choose one
- * item from that.
- *
- * @param input Input that we should read or edit
- * @param reader Associated console reader
- * @param bundle Resource bundle
- * @return True if user with to continue with loading addtional inputs
- * @throws IOException
- */
- private static boolean fillInputEnum(MEnumInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- // Prompt in enum case
- println(bundle.getString(input.getLabelKey()) + ": ");
-
- // Indexes
- int i = -1;
- int lastChoice = -1;
-
- // Print out all values as a numbered list
- for(String value : input.getValues()) {
- i++;
-
- println(" " + i + " : " + value);
-
- // Only show last choice if not sensitive
- if(!input.isEmpty() && value.equals(input.getValue()) && !input.isSensitive()) {
- lastChoice = i;
- }
- }
-
- // Prompt
- reader.printString("Choose: ");
-
- // Fill previously filled index when available
- if(lastChoice != -1) {
- reader.putString(Integer.toString(lastChoice));
- }
-
- reader.flushConsole();
- String userTyped;
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if (userTyped == null) {
- return false;
- } else if (userTyped.isEmpty()) {
- input.setEmpty();
- } else {
- Integer index;
- try {
- index = Integer.valueOf(userTyped);
-
- if(index < 0 || index >= input.getValues().length) {
- errorMessage("Invalid index");
- return fillInputEnum(input, reader, bundle);
- }
-
- input.setValue(input.getValues()[index]);
- } catch (NumberFormatException ex) {
- errorMessage("Input is not valid integer number");
- return fillInputEnum(input, reader, bundle);
- }
- }
-
- return true;
- }
-
- /**
- * Load user input for map type.
- *
- * This implementation will load one map entry at the time. Current flows is
- * as follows: if user did not enter anything (empty input) finish loading
- * and return from function. If user specified input with equal sign (=),
- * lets add new key value pair. Otherwise consider entire input as a key name
- * and try to remove it from the map.
- *
- * Please note that following code do not supports equal sign in property
- * name. It's however perfectly fine to have equal sign in value.
- *
- * @param input Input that we should read or edit
- * @param reader Associated console reader
- * @param bundle Resource bundle
- * @return True if user wish to continue with loading additional inputs
- * @throws IOException
- */
- private static boolean fillInputMap(MMapInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- // Special prompt in Map case
- println(bundle.getString(input.getLabelKey()) + ": ");
-
- // Internal loading map
- Map<String, String> values = input.getValue();
- if(values == null) {
- values = new HashMap<String, String>();
- }
-
- String userTyped;
-
- while(true) {
- // Print all current items in each iteration
- // However do not printout if this input contains sensitive information.
- println("There are currently " + values.size() + " values in the map:");
- if (!input.isSensitive()) {
- for(Map.Entry<String, String> entry : values.entrySet()) {
- println(entry.getKey() + " = " + entry.getValue());
- }
- }
-
- // Special prompt for Map entry
- reader.printString("entry# ");
- reader.flushConsole();
-
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if(userTyped == null) {
- // Finish loading and return back to Sqoop shell
- return false;
- } else if(userTyped.isEmpty()) {
- // User has finished loading data to Map input, either set input empty
- // if there are no entries or propagate entries to the input
- if(values.size() == 0) {
- input.setEmpty();
- } else {
- input.setValue(values);
- }
- return true;
- } else {
- // User has specified regular input, let's check if it contains equals
- // sign. Save new entry (or update existing one) if it does. Otherwise
- // try to remove entry that user specified.
- if(userTyped.contains("=")) {
- String []keyValue = userTyped.split("=", 2);
- values.put(handleUserInput(keyValue[0]), handleUserInput(keyValue[1]));
- } else {
- String key = handleUserInput(userTyped);
- if(values.containsKey(key)) {
- values.remove(key);
- } else {
- errorMessage("Don't know what to do with " + userTyped);
- }
- }
- }
-
- }
- }
-
- /**
- * Handle special cases in user input.
- *
- * Preserve null and empty values, remove whitespace characters before and
- * after loaded string and de-quote the string if it's quoted (to preserve
- * spaces for example).
- *
- * @param input String loaded from user
- * @return Unquoted transformed string
- */
- private static String handleUserInput(String input) {
- // Preserve null and empty values
- if(input == null) {
- return null;
- }
- if(input.isEmpty()) {
- return input;
- }
-
- // Removes empty characters at the begging and end of loaded string
- input = input.trim();
-
- int lastIndex = input.length() - 1;
- char first = input.charAt(0);
- char last = input.charAt(lastIndex);
-
- // Remove quoting if present
- if(first == '\'' && last == '\'') {
- input = input.substring(1, lastIndex);
- } else if(first == '"' && last == '"') {
- input = input.substring(1, lastIndex);
- }
-
- // Return final string
- return input;
- }
-
- private static boolean fillInputInteger(MIntegerInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- generatePrompt(reader, bundle, input);
-
- // Fill already filled data when available
- // However do not printout if this input contains sensitive information.
- if(!input.isEmpty() && !input.isSensitive()) {
- reader.putString(input.getValue().toString());
- }
-
- // Get the data
- String userTyped;
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if (userTyped == null) {
- return false;
- } else if (userTyped.isEmpty()) {
- input.setEmpty();
- } else {
- Integer value;
- try {
- value = Integer.valueOf(userTyped);
- input.setValue(value);
- } catch (NumberFormatException ex) {
- errorMessage("Input is not valid integer number");
- return fillInputInteger(input, reader, bundle);
- }
-
- input.setValue(Integer.valueOf(userTyped));
- }
-
- return true;
- }
-
- /**
- * Load string input from the user.
- *
- * @param input Input that we should load in
- * @param reader Associated console reader
- * @param bundle Resource bundle for this input
- * @return
- * @throws IOException
- */
- public static boolean fillInputString(MStringInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- generatePrompt(reader, bundle, input);
-
- // Fill already filled data when available
- // However do not printout if this input contains sensitive information.
- if(!input.isEmpty() && !input.isSensitive()) {
- reader.putString(input.getValue());
- }
-
- // Get the data
- String userTyped;
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if (userTyped == null) {
- // Propagate end of loading process
- return false;
- } else if (userTyped.isEmpty()) {
- // Empty input in case that nothing was given
- input.setEmpty();
- } else {
- // Set value that user has entered
- input.setValue(userTyped);
-
- // Check that it did not exceeds maximal allowance for given input
- if(userTyped.length() > input.getMaxLength()) {
- errorMessage("Size of input exceeds allowance for this input"
- + " field. Maximal allowed size is " + input.getMaxLength());
- return fillInputString(input, reader, bundle);
- }
- }
-
- return true;
- }
-
- /**
- * Load boolean input from the user.
- *
- * @param input Input that we should load in
- * @param reader Associated console reader
- * @param bundle Resource bundle for this input
- * @return
- * @throws IOException
- */
- public static boolean fillInputBoolean(MBooleanInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- generatePrompt(reader, bundle, input);
-
- // Fill already filled data when available
- // However do not printout if this input contains sensitive information.
- if(!input.isEmpty() && !input.isSensitive()) {
- reader.putString(input.getValue().toString());
- }
-
- // Get the data
- String userTyped;
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if (userTyped == null) {
- // Propagate end of loading process
- return false;
- } else if (userTyped.isEmpty()) {
- // Empty input in case that nothing was given
- input.setEmpty();
- } else {
- // Set value that user has entered
- input.setValue(Boolean.valueOf(userTyped));
- }
-
- return true;
- }
-
- public static void generatePrompt(ConsoleReader reader,
- ResourceBundle bundle,
- MInput input)
- throws IOException {
- reader.printString(bundle.getString(input.getLabelKey()) + ": ");
- reader.flushConsole();
- }
-
- public static String getName(ConsoleReader reader,
- String name) throws IOException {
- if(name == null) {
- nameInput.setEmpty();
- } else {
- nameInput.setValue(name);
- }
-
- fillInputString(nameInput, reader, getResourceBundle());
-
- return nameInput.getValue();
- }
-
- /**
- * Print validation message in cases that it's not in state "FINE"
- *
- * @param element Validated element
- */
- public static void printValidationMessage(MValidatedElement element) {
- switch (element.getValidationStatus()) {
- case UNACCEPTABLE:
- errorMessage(element.getValidationMessage());
- break;
- case ACCEPTABLE:
- warningMessage(element.getValidationMessage());
- break;
- default:
- // Simply ignore all other states for the moment
- break;
- }
- }
-
- public static void errorMessage(String message) {
- println("Error message: @|red " + message + " |@");
- }
-
- public static void warningMessage(String message) {
- println("Warning message: @|yellow " + message + " |@");
- }
-
- public static void errorIntroduction() {
- println();
- println("@|red There are issues with entered data, please revise your input:|@");
- }
-
- private FormFiller() {
- // Do not instantiate
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
deleted file mode 100644
index cbc956d..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
+++ /dev/null
@@ -1,148 +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.utils;
-
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.model.MSubmission;
-import org.apache.sqoop.submission.SubmissionStatus;
-import org.apache.sqoop.submission.counter.Counter;
-import org.apache.sqoop.submission.counter.CounterGroup;
-import org.apache.sqoop.submission.counter.Counters;
-
-import java.text.SimpleDateFormat;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Class used for displaying or printing the submission details
- */
-public final class SubmissionDisplayer {
-
- private final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
-
- /**
- * On job submission, displays the initial job info
- * @param submission
- */
- public static void displayHeader(MSubmission submission) {
- println("@|bold "+ resourceString(Constants.RES_SUBMISSION_SUBMISSION_DETAIL) +"|@");
-
- print(resourceString(Constants.RES_SUBMISSION_JOB_ID)+": ");
- println(submission.getJobId());
-
- print(resourceString(Constants.RES_SUBMISSION_SERVER_URL)+": ");
- println(getServerUrl());
-
- print(resourceString(Constants.RES_SUBMISSION_CREATION_DATE)+": ");
- println(dateFormat.format(submission.getCreationDate()));
-
- String externalId = submission.getExternalId();
- if(externalId != null) {
- print(resourceString(Constants.RES_SUBMISSION_EXTERNAL_ID)+": ");
- println(externalId);
-
- String externalLink = submission.getExternalLink();
- if(externalLink != null) {
- println("\t" + externalLink);
- }
- }
-
- if(isVerbose() && submission.getConnectorSchema() != null) {
- print(resourceString(Constants.RES_CONNECTOR_SCHEMA)+": ");
- println(submission.getConnectorSchema());
- }
-
- if(isVerbose() && submission.getHioSchema() != null) {
- print(resourceString(Constants.RES_HIO_SCHEMA)+": ");
- println(submission.getHioSchema());
- }
- }
-
- /**
- * Displays the progress of the executing job
- * @param submission
- */
- public static void displayProgress(MSubmission submission) {
- StringBuilder sb = new StringBuilder();
- if(submission.getStatus().isRunning()) {
- sb.append(dateFormat.format(submission.getLastUpdateDate())+": @|green "+submission.getStatus()+ " |@");
- double progress = submission.getProgress();
- sb.append(" - ");
- if(progress == -1) {
- sb.append(resourceString(Constants.RES_SUBMISSION_PROGRESS_NOT_AVAIL));
- } else {
- sb.append(String.format("%.2f %%", progress * 100));
- }
- } else {
- sb.append(dateFormat.format(submission.getLastUpdateDate())+": "+submission.getStatus());
- }
-
- println(sb.toString());
- }
-
- /**
- * On successfull or error, method is invoked
- * @param submission
- */
- public static void displayFooter(MSubmission submission) {
- if (submission.getStatus().toString().equals(SubmissionStatus.SUCCEEDED.toString())) {
- println(dateFormat.format(submission.getLastUpdateDate())+": @|green "+submission.getStatus()+ " |@");
- Counters counters = submission.getCounters();
- if (counters != null) {
- println(resourceString(Constants.RES_SUBMISSION_COUNTERS) + ":");
- for (CounterGroup group : counters) {
- print("\t");
- println(group.getName());
- for (Counter counter : group) {
- print("\t\t");
- print(counter.getName());
- print(": ");
- println(counter.getValue());
- }
- }
- println(resourceString(Constants.RES_SUBMISSION_EXECUTED_SUCCESS));
- }
- } else {
- if (submission.getStatus().isFailure()) {
- println(dateFormat.format(submission.getLastUpdateDate())+": @|red "+submission.getStatus()+ " |@");
- } else {
- println(dateFormat.format(submission.getLastUpdateDate())+": "+submission.getStatus());
- }
- // Exception handling
- if (submission.getExceptionInfo() != null) {
- print("@|red Exception: |@");
- println(submission.getExceptionInfo());
-
- if (isVerbose() && submission.getExceptionStackTrace() != null) {
- print("@|bold Stack trace: |@");
- println(submission.getExceptionStackTrace());
- }
- }
- }
- }
-
- public static void displaySubmission(MSubmission submission) {
- if(submission.getStatus().isFailure() || submission.getStatus().equals(SubmissionStatus.SUCCEEDED)) {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayFooter(submission);
- } else {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayProgress(submission);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/TableDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/TableDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/TableDisplayer.java
deleted file mode 100644
index 487fa50..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/TableDisplayer.java
+++ /dev/null
@@ -1,141 +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.utils;
-
-import org.apache.commons.lang.StringUtils;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Display table based data
- */
-public class TableDisplayer {
-
- /**
- * Display given columns in nice table structure to given IO object.
- *
- * @param headers List of headers
- * @param columns Array of columns
- */
- public static void display(List<String> headers, List<String> ...columns) {
- assert headers != null;
- assert columns != null;
- assert headers.size() == columns.length;
-
- // Count of columns
- int columnCount = headers.size();
-
- // List of all maximal widths of each column
- List<Integer> widths = new LinkedList<Integer>();
- for(int i = 0; i < columnCount; i++) {
- widths.add(getMaximalWidth(headers.get(i), columns[i]));
- }
-
- // First line is border
- drawLine(widths);
-
- // Print out header (text is centralised)
- print("| ");
- for(int i = 0 ; i < columnCount; i++) {
- print(StringUtils.center(headers.get(i), widths.get(i), ' '));
- print((i == columnCount -1) ? " |" : " | ");
- }
- println();
-
- // End up header by border
- drawLine(widths);
-
- // Number of rows in the table
- int rows = getMaximalRows(columns);
-
- // Print out each row
- for(int row = 0 ; row < rows; row++) {
- print("| ");
- for(int i = 0 ; i < columnCount; i++) {
- print(StringUtils.rightPad(columns[i].get(row), widths.get(i), ' '));
- print((i == columnCount -1) ? " |" : " | ");
- }
- println();
- }
-
- // End table by final border
- drawLine(widths);
- }
-
- /**
- * Draw border line
- *
- * @param widths List of widths of each column
- */
- private static void drawLine(List<Integer> widths) {
- int last = widths.size() - 1;
- print("+-");
- for(int i = 0; i < widths.size(); i++) {
- print(StringUtils.repeat("-", widths.get(i)));
- print((i == last) ? "-+" : "-+-");
- }
- println();
- }
-
- /**
- * Get maximal width for given column with it's associated header.
- *
- * @param header Associated header
- * @param column All column values
- * @return Maximal
- */
- private static int getMaximalWidth(String header, List<String> column) {
- assert header != null;
- assert column != null;
-
- int max = header.length();
-
- for(String value : column) {
- if(value != null && value.length() > max) {
- max = value.length();
- }
- }
-
- return max;
- }
-
- /**
- * Get maximal number of rows available in the column list
- *
- * @param columns Array with all column values
- * @return
- */
- private static int getMaximalRows(List<String>... columns) {
- int max = 0;
-
- for(List<String> column : columns) {
- if(column.size() > max) {
- max = column.size();
- }
- }
-
- return max;
- }
-
- private TableDisplayer() {
- // Instantiation is prohibited
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/ThrowableDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/ThrowableDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/ThrowableDisplayer.java
deleted file mode 100644
index 8a34f34..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/ThrowableDisplayer.java
+++ /dev/null
@@ -1,90 +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.utils;
-
-import groovy.lang.MissingPropertyException;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.common.SqoopException;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Pretty printing of Throwable objects
- */
-public class ThrowableDisplayer {
-
- /**
- * Error hook installed to Groovy shell.
- *
- * Will display exception that appeared during executing command. In most
- * cases we will simply delegate the call to printing throwable method,
- * however in case that we've received ClientError.CLIENT_0006 (server
- * exception), we will unwrap server issue and view only that as local
- * context shouldn't make any difference.
- *
- * @param t Throwable to be displayed
- */
- public static void errorHook(Throwable t) {
- println("@|red Exception has occurred during processing command |@");
-
- // If this is server exception from server
- if(t instanceof SqoopException
- && ((SqoopException)t).getErrorCode() == ClientError.CLIENT_0006) {
- print("@|red Server has returned exception: |@");
- printThrowable(t.getCause(), isVerbose());
- } else if(t.getClass() == MissingPropertyException.class) {
- print("@|red Unknown command: |@");
- println(t.getMessage());
- } else {
- printThrowable(t, isVerbose());
- }
- }
-
- /**
- * Pretty print Throwable instance including stack trace and causes.
- *
- * @param t Throwable to display
- */
- protected static void printThrowable(Throwable t, boolean verbose) {
- print("@|red Exception: |@");
- print(t.getClass().getName());
- print(" @|red Message: |@");
- print(t.getMessage());
- println();
-
- if(verbose) {
- println("Stack trace:");
- for(StackTraceElement e : t.getStackTrace()) {
- print("\t @|bold at |@ ");
- print(e.getClassName());
- print(" (@|bold " + e.getFileName() + ":" + e.getLineNumber() + ") |@ ");
- println();
- }
-
- Throwable cause = t.getCause();
- if(cause != null) {
- print("Caused by: ");
- printThrowable(cause, verbose);
- }
- }
- }
-
- private ThrowableDisplayer() {
- // Instantiation is prohibited
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 1a8f963..0000000
--- a/client/src/main/resources/client-resource.properties
+++ /dev/null
@@ -1,232 +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.
-
-# Client Resources in default language (english)
-
-############################
-# Security Form
-#
-object-name.label = Name
-object-name.help = Non unique name of the entity to help you remember \
- it's purpose
-
-
-#############################
-# Messages
-#
-# Argument related
-#
-args.function.unknown = The specified function "{0}" is not recognized.
-args.xid_missing = Required argument --xid is missing.
-args.jid_missing = Required argument --jid is missing.
-args.cid_missing = Required argument --cid is missing.
-args.type_missing = Required argument --type is missing.
-args.name_missing = Required argument --name is missing.
-args.value_missing = Required argument --value is missing.
-
-
-## Generic description of various ids, types etc
-prompt.conn_id = Connection ID
-prompt.connector_id = Connector ID
-prompt.job_id = Job ID
-prompt.job_type = Job type
-
-## Prompt messages for updating, filling metadata info
-
-prompt.update_conn_metadata = Please update connection metadata:
-prompt.update_job_metadata = Please update job metadata:
-prompt.fill_conn_metadata = Please fill following values to create new \
-connection object
-prompt.fill_job_metadata = Please fill following values to create new \
-job object
-
-#
-# Update command
-update.conn = Updating connection with id {0}
-update.job = Updating job with id {0}
-update.usage = Usage: update {0}
-update.conn_successful = Connection was successfully updated with status {0}
-update.job_successful = Job was successfully updated with status {0}
-
-#
-# Clone command
-clone.usage = Usage: clone {0}
-clone.conn.successful = Connection was successfully created with validation \
- status {0} and persistent id {1}
-clone.job.successful = Job was successfully created with validation \
- status {0} and persistent id {1}
-clone.cloning_conn = Cloning connection with id {0}
-clone.cloning_job = Cloning job with id {0}
-
-#
-# Create command
-create.usage = Usage: create {0}
-create.conn_successful = New connection was successfully created with \
- validation status {0} and persistent id {1}
-create.job_successful = New job was successfully created with validation \
- status {0} and persistent id {1}
-## Creating messages
-create.creating_conn = Creating connection for connector with id {0}
-create.creating_job = Creating job for connection with id {0}
-
-#
-# Delete command
-delete.usage = Usage: delete {0}
-
-#
-# Enable command
-enable.usage = Usage: enable {0}
-enable.conn_successful = Connection {0} was successfully enabled
-enable.job_successful = Job {0} was successfully enabled
-
-#
-# Disable command
-disable.usage = Usage: disable {0}
-disable.conn_successful = Connection {0} was successfully disabled
-disable.job_successful = Job {0} was successfully disabled
-
-#
-# Help command
-help.usage = [<command>]
-help.description = Display this help message
-help.cmd_usage = Usage: @|bold {0} |@ {1}
-help.message = Display the list of commands or the help text for \
- @|bold command|@.
-help.info = For information about @|green Sqoop|@, visit: \
- @|cyan http://sqoop.apache.org/|@
-help.avail_commands = Available commands:
-help.cmd_description = @|bold {0} ({1}|@) {2}
-help.specific_cmd_info = For help on a specific command type: \
- help @|bold command|@
-
-unrecognized.cmd = Unrecognized command {0}
-
-#
-# Set command
-set.usage = Usage: set {0}
-set.prompt_opt_name = Client option name
-set.prompt_opt_value = New option value
-set.verbose_changed = Verbose option was changed to {0}
-set.poll_timeout_changed = Poll timeout option has been changed to {0}
-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}
-
-show.prompt_display_all_conns = Display all connections
-show.prompt_display_conn_xid = Display the connection with xid
-show.conn_usage = Usage: show connection
-show.prompt_conns_to_show = @|bold {0} connection(s) to show: |@
-show.prompt_conn_info = Connection with id {0} and name {1} (Enabled: {2}, Created {3}, Updated {4})
-show.prompt_conn_cid_info = Using Connector id {0}
-
-show.prompt_display_all_connectors = Display all connectors
-show.prompt_display_connector_cid = Display the connector with cid
-show.connector_usage = Usage: show connector
-show.prompt_connectors_to_show = @|bold {0} connector(s) to show: |@
-show.prompt_connector_info = Connector with id {0}:\n Name: {1} \n \
-Class: {2}\n Version: {3}
-
-show.framework_usage = Usage: show framework
-show.prompt_framework_opts = @|bold Framework specific options: |@\nPersistent id: {0}
-
-show.prompt_display_all_jobs = Display all jobs
-show.prompt_display_job_jid = Display jobwith given jid
-show.job_usage = Usage: show job
-show.prompt_jobs_to_show = @|bold {0} job(s) to show: |@
-show.prompt_job_info = Job with id {0} and name {1} (Enabled: {2}, Created {3}, Updated {4})
-show.prompt_job_xid_cid_info = Using Connection id {0} and Connector id {1}
-
-show.prompt_display_all_submissions = Display all submissions
-show.prompt_display_all_submissions_jid = Display all submissions given jid
-
-show.prompt_display_all_servers = Display all server information
-show.prompt_display_server_host = Display server host name
-show.prompt_display_server_port = Display server port number
-show.prompt_display_server_webapp = Display server web app name
-show.server_usage = Usage: show server
-show.prompt_server_host = @|bold Server host:|@ {0}
-show.prompt_server_port = @|bold Server port:|@ {0}
-show.prompt_server_webapp = @|bold Server webapp:|@ {0}
-
-show.prompt_display_all_versions = Display all versions
-show.prompt_display_version_server = Display server version
-show.prompt_display_version_client = Display client version
-show.prompt_display_version_protocol = Display protocol version
-show.version_usage = Usage: show version
-show.prompt_version_client_server = @|bold {0} version:|@\n Sqoop {1} \
-revision {2} \n Compiled by {3} on {4}
-show.prompt_version_protocol = @|bold Protocol version:|@\n {0}
-
-sqoop.shell_banner = @|green Sqoop Shell:|@ Type '@|bold help|@' or '@|bold \\h|@' for help.
-sqoop.prompt_shell_loadrc = Loading resource file {0}
-sqoop.prompt_shell_loadedrc = Resource file loaded.
-
-start.usage = Usage: start {0}
-start.prompt_synchronous = Wait for submission to finish
-
-stop.usage = Usage: stop {0}
-
-status.usage = Usage: status {0}
-
-# Various Table headers
-table.header.id = Id
-table.header.name = Name
-table.header.version = Version
-table.header.class = Class
-table.header.type = Type
-table.header.connector = Connector
-table.header.jid = Job Id
-table.header.eid = External Id
-table.header.status = Status
-table.header.date = Last Update Date
-table.header.enabled = Enabled
-
-#Form displayer resources
-formdisplayer.supported_job_types = Supported job types
-formdisplayer.connection = Connection
-formdisplayer.job = Job
-formdisplayer.forms_jobtype = Forms for job type
-formdisplayer.form = form
-formdisplayer.name = Name
-formdisplayer.label = Label
-formdisplayer.help = Help
-formdisplayer.input = Input
-formdisplayer.type = Type
-formdisplayer.sensitive = Sensitive
-formdisplayer.size = Size
-formdisplayer.possible_values = Possible values
-formdisplayer.unsupported_datatype = Unsupported data type
-formdisplayer.input_sensitive = This input is sensitive
-
-formdisplayer.warning_message = There were warnings while create or update, but saved successfully.
-
-submission.submission_detail = Submission details
-submission.job_id = Job ID
-submission.creation_date = Creation date
-submission.external_id = External ID
-submission.progress_not_available = Progress is not available
-submission.counters = Counters
-submission.executed_success = Job executed successfully
-submission.server_url = Server URL
-submission.connector_schema = Connector schema
-submission.hio_schema = Input/Output schema
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/dist/pom.xml
----------------------------------------------------------------------
diff --git a/dist/pom.xml b/dist/pom.xml
index dd67f85..9186a38 100644
--- a/dist/pom.xml
+++ b/dist/pom.xml
@@ -40,7 +40,7 @@ limitations under the License.
</dependency>
<dependency>
<groupId>org.apache.sqoop</groupId>
- <artifactId>sqoop-client</artifactId>
+ <artifactId>sqoop-shell</artifactId>
</dependency>
</dependencies>
@@ -167,16 +167,16 @@ limitations under the License.
<copy file="../server/target/sqoop.war"
toDir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/server/webapps"/>
- <!-- Build client directory -->
- <copy todir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/client/lib">
- <fileset dir="../client/target/lib">
+ <!-- Build shell client directory -->
+ <copy todir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/shell/lib">
+ <fileset dir="../shell/target/lib">
<include name="*.jar" />
<exclude name="junit-*.jar" />
<exclude name="mockito-*.jar" />
</fileset>
</copy>
- <copy file="../client/target/sqoop-client-${project.version}.jar"
- toDir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/client/lib"/>
+ <copy file="../shell/target/sqoop-shell-${project.version}.jar"
+ toDir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/shell/lib"/>
<!-- Build "bin" directory -->
<copy todir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/bin">
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/dist/src/main/bin/sqoop.sh
----------------------------------------------------------------------
diff --git a/dist/src/main/bin/sqoop.sh b/dist/src/main/bin/sqoop.sh
index 88adb04..e3ed5ef 100755
--- a/dist/src/main/bin/sqoop.sh
+++ b/dist/src/main/bin/sqoop.sh
@@ -51,7 +51,7 @@ cd ${BASEDIR}
echo "Sqoop home directory: ${BASEDIR}"
CATALINA_BIN=${CATALINA_BIN:-server/bin}
-CLIENT_LIB=${CLIENT_LIB:-client/lib}
+CLIENT_LIB=${CLIENT_LIB:-shell/lib}
setup_catalina_opts() {
# The Java System properties 'sqoop.http.port' and 'sqoop.admin.port' are
@@ -107,7 +107,7 @@ case $COMMAND in
if [ -n "${JAVA_HOME}" ] ; then
EXEC_JAVA="${JAVA_HOME}/bin/java"
fi
- ${EXEC_JAVA} -classpath ${CLASSPATH} org.apache.sqoop.client.shell.SqoopShell $2
+ ${EXEC_JAVA} -classpath ${CLASSPATH} org.apache.sqoop.shell.SqoopShell $2
;;
*)
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5ea0633..513b6d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -247,6 +247,11 @@ limitations under the License.
<artifactId>sqoop-client</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-shell</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.sqoop</groupId>
<artifactId>sqoop-common</artifactId>
@@ -413,6 +418,7 @@ limitations under the License.
<module>repository</module>
<module>server</module>
<module>client</module>
+ <module>shell</module>
<module>docs</module>
<module>connector</module>
<module>execution</module>
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/pom.xml
----------------------------------------------------------------------
diff --git a/shell/pom.xml b/shell/pom.xml
new file mode 100644
index 0000000..947eab0
--- /dev/null
+++ b/shell/pom.xml
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>sqoop</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-shell</artifactId>
+ <name>Sqoop Shell</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>1.11</version>
+ </dependency>
+ <dependency>
+ <groupId>jline</groupId>
+ <artifactId>jline</artifactId>
+ <version>0.9.94</version>
+ </dependency>
+ <dependency>
+ <groupId>org.fusesource.jansi</groupId>
+ <artifactId>jansi</artifactId>
+ <version>1.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.8.5</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>dist</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CloneCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CloneCommand.java b/shell/src/main/java/org/apache/sqoop/shell/CloneCommand.java
new file mode 100644
index 0000000..980a908
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CloneCommand.java
@@ -0,0 +1,69 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Client side cloning of connection and job objects.
+ */
+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},
+ Constants.PRE_CLONE, Constants.SUF_INFO);
+ }
+
+ public Object executeCommand(List args) {
+ if(!isInteractive()) {
+ throw new SqoopException(ShellError.SHELL_0007, "clone");
+ }
+
+ if (args.size() == 0) {
+ 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();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new CloneJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CloneConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CloneConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CloneConnectionFunction.java
new file mode 100644
index 0000000..856abaa
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CloneConnectionFunction.java
@@ -0,0 +1,96 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.model.MPersistableEntity;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ *
+ */
+public class CloneConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CloneConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create(Constants.OPT_XID_CHAR)
+ );
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+
+ try {
+ cloneConnection(getLong(line, Constants.OPT_XID));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void cloneConnection(Long connectionId) throws IOException {
+ printlnResource(Constants.RES_CLONE_CLONING_CONN, connectionId);
+
+ ConsoleReader reader = new ConsoleReader();
+
+ 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);
+
+ ResourceBundle connectorBundle = client.getResourceBundle(connection.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ status = client.createConnection(connection);
+
+ } while(!status.canProceed());
+
+ printlnResource(Constants.RES_CLONE_CONN_SUCCESSFUL, status.name(), connection.getPersistenceId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CloneJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CloneJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CloneJobFunction.java
new file mode 100644
index 0000000..3e23025
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CloneJobFunction.java
@@ -0,0 +1,99 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MPersistableEntity;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ *
+ */
+public class CloneJobFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CloneJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .hasArg()
+ .create(Constants.OPT_JID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_JID)) {
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
+ return null;
+ }
+
+ try {
+ cloneJob(getLong(line, Constants.OPT_JID));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void cloneJob(Long jobId) throws IOException {
+ printlnResource(Constants.RES_CLONE_CLONING_JOB, jobId);
+
+ ConsoleReader reader = new ConsoleReader();
+
+ MJob job = client.getJob(jobId);
+ job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);
+
+ 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);
+
+ printlnResource(Constants.RES_PROMPT_UPDATE_JOB_METADATA);
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ // Try to create
+ status = client.createJob(job);
+ } while(!status.canProceed());
+
+ printlnResource(Constants.RES_CLONE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java b/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
new file mode 100644
index 0000000..e62ce08
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
@@ -0,0 +1,69 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+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},
+ Constants.PRE_CREATE, Constants.SUF_INFO);
+ }
+
+ public Object executeCommand(List args) {
+ if(!isInteractive()) {
+ throw new SqoopException(ShellError.SHELL_0007, "create");
+ }
+
+ if (args.size() == 0) {
+ 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();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new CreateJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CreateConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CreateConnectionFunction.java
new file mode 100644
index 0000000..5fbf0a3
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CreateConnectionFunction.java
@@ -0,0 +1,93 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.FormDisplayer;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ *
+ */
+public class CreateConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CreateConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_CONNECTOR_ID))
+ .withLongOpt(Constants.OPT_CID)
+ .hasArg()
+ .create(Constants.OPT_CID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_CID)) {
+ printlnResource(Constants.RES_ARGS_CID_MISSING);
+ return null;
+ }
+
+ try {
+ createConnection(getLong(line, Constants.OPT_CID));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void createConnection(long connectorId) throws IOException {
+ printlnResource(Constants.RES_CREATE_CREATING_CONN, connectorId);
+
+ ConsoleReader reader = new ConsoleReader();
+
+ MConnection connection = client.newConnection(connectorId);
+
+ ResourceBundle connectorBundle = client.getResourceBundle(connectorId);
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+
+ Status status = Status.FINE;
+ printlnResource(Constants.RES_PROMPT_FILL_CONN_METADATA);
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ // Try to create
+ status = client.createConnection(connection);
+ } while(!status.canProceed());
+ FormDisplayer.displayFormWarning(connection);
+ printlnResource(Constants.RES_CREATE_CONN_SUCCESSFUL, status.name(), connection.getPersistenceId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CreateJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CreateJobFunction.java
new file mode 100644
index 0000000..6e4f04b
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CreateJobFunction.java
@@ -0,0 +1,106 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.FormDisplayer;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ * Handles creation of new job objects.
+ */
+public class CreateJobFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CreateJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create(Constants.OPT_XID_CHAR)
+ );
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_TYPE))
+ .withLongOpt(Constants.OPT_TYPE)
+ .hasArg()
+ .create(Constants.OPT_TYPE_CHAR)
+ );
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+ if (!line.hasOption(Constants.OPT_TYPE)) {
+ printlnResource(Constants.RES_ARGS_TYPE_MISSING);
+ return null;
+ }
+
+ try {
+ createJob(getLong(line, Constants.OPT_XID),
+ line.getOptionValue(Constants.OPT_TYPE));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ 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.toUpperCase()));
+
+ ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+
+ Status status = Status.FINE;
+
+ printlnResource(Constants.RES_PROMPT_FILL_JOB_METADATA);
+
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ // Try to create
+ status = client.createJob(job);
+ } while(!status.canProceed());
+ FormDisplayer.displayFormWarning(job);
+ printlnResource(Constants.RES_CREATE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java b/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
new file mode 100644
index 0000000..abfcf2e
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
@@ -0,0 +1,64 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class DeleteCommand extends SqoopCommand {
+
+ private DeleteConnectionFunction connectionFunction;
+ private DeleteJobFunction jobFunction;
+
+ public DeleteCommand(Shell shell) {
+ super(shell, Constants.CMD_DELETE, Constants.CMD_DELETE_SC,
+ new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
+ Constants.PRE_DELETE, Constants.SUF_INFO);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeCommand(List args) {
+ if (args.size() == 0) {
+ 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();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new DeleteJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/DeleteConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DeleteConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/DeleteConnectionFunction.java
new file mode 100644
index 0000000..c123732
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DeleteConnectionFunction.java
@@ -0,0 +1,50 @@
+/**
+ * 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.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class DeleteConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public DeleteConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create('x'));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+
+ client.deleteConnection(getLong(line, Constants.OPT_XID));
+
+ return null;
+ }
+
+}
[5/6] SQOOP-921. Sqoop2: Create standalone shell package
Posted by hs...@apache.org.
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index e843ede..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java
+++ /dev/null
@@ -1,87 +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.shell;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class SetOptionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- protected SetOptionFunction() {
- this.addOption(OptionBuilder.hasArg()
- .withDescription(resourceString(Constants.RES_SET_PROMPT_OPT_NAME))
- .withLongOpt(Constants.OPT_NAME)
- .create(Constants.OPT_NAME_CHAR));
- this.addOption(OptionBuilder.hasArg()
- .withDescription(resourceString(Constants.RES_SET_PROMPT_OPT_VALUE))
- .withLongOpt(Constants.OPT_VALUE)
- .create(Constants.OPT_VALUE_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_NAME)) {
- printlnResource(Constants.RES_ARGS_NAME_MISSING);
- return null;
- }
- if (!line.hasOption(Constants.OPT_VALUE)) {
- printlnResource(Constants.RES_ARGS_VALUE_MISSING);
- return null;
- }
-
- handleOptionSetting(line.getOptionValue(Constants.OPT_NAME), line.getOptionValue(Constants.OPT_VALUE));
-
- return null;
- }
-
- private void handleOptionSetting(String name, String value) {
- if(name.equals(Constants.OPT_VERBOSE)) {
- boolean newValue = false;
-
- if(value.equals("1") || value.equals("true")) {
- newValue = true;
- }
-
- setVerbose(newValue);
- printlnResource(Constants.RES_SET_VERBOSE_CHANGED, newValue);
- return;
- }
-
- if (name.equals(Constants.OPT_POLL_TIMEOUT)) {
- long newValue = 0;
-
- try {
- newValue = Long.parseLong(value);
- } catch (NumberFormatException ex) {
- // make the value stay the same
- newValue = getPollTimeout();
- }
-
- setPollTimeout(newValue);
- printlnResource(Constants.RES_SET_POLL_TIMEOUT_CHANGED, newValue);
- return;
- }
-
- printlnResource(Constants.RES_SET_UNKNOWN_OPT_IGNORED, name);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 41fc17a..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/SetServerFunction.java
+++ /dev/null
@@ -1,78 +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.shell;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-@SuppressWarnings("serial")
-public class SetServerFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- protected SetServerFunction() {
- this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_HOST)
- .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(resourceString(Constants.RES_SET_PORT_DESCRIPTION))
- .withLongOpt(Constants.OPT_PORT)
- .create(Constants.OPT_PORT_CHAR));
- this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_WEBAPP)
- .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) {
- if (line.getArgs().length == 1) {
- printlnResource(Constants.RES_SET_SERVER_USAGE);
- return null;
- }
-
- 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);
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 41a8cd3..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShellEnvironment.java
+++ /dev/null
@@ -1,208 +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.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;
-
-/**
- * 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 final long DEFAULT_POLL_TIMEOUT = 10000;
-
- 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;
- private static long pollTimeout = DEFAULT_POLL_TIMEOUT;
-
- static ResourceBundle resource = ResourceBundle.getBundle(Constants.RESOURCE_NAME, Locale.getDefault());
- 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;
- }
-
- 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 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 + "/";
- }
-
- public static ResourceBundle getResourceBundle() {
- return resource;
- }
-
- public static void setVerbose(boolean newValue) {
- verbose = newValue;
- }
-
- public static boolean isVerbose() {
- return verbose;
- }
-
- public static void setInteractive(boolean newValue) {
- interactive = newValue;
- }
-
- public static boolean isInteractive() {
- return interactive;
- }
-
- public static void setPollTimeout(long timeout) {
- pollTimeout = timeout;
- }
-
- public static long getPollTimeout() {
- return pollTimeout;
- }
-
- 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);
- }
-
- public static void print(String format, Object... args) {
- io.out.printf(format, args);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/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
deleted file mode 100644
index 4245717..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java
+++ /dev/null
@@ -1,105 +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.shell;
-
-import java.util.List;
-import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.Shell;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-public class ShowCommand extends SqoopCommand
-{
- private ShowServerFunction serverFunction;
- private ShowVersionFunction versionFunction;
- private ShowConnectorFunction connectorFunction;
- private ShowJobFunction jobFunction;
- private ShowSubmissionFunction submissionFunction;
- private ShowFrameworkFunction frameworkFunction;
- private ShowConnectionFunction connectionFunction;
- private ShowOptionFunction optionFunction;
-
-
- protected ShowCommand(Shell shell) {
- super(shell, Constants.CMD_SHOW, Constants.CMD_SHOW_SC,
- new String[] {Constants.FN_SERVER, Constants.FN_VERSION,
- Constants.FN_CONNECTOR, Constants.FN_FRAMEWORK,
- Constants.FN_CONNECTION, Constants.FN_JOB, Constants.FN_SUBMISSION, Constants.FN_OPTION },
- Constants.PRE_SHOW, Constants.SUF_INFO);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public Object executeCommand(List args) {
- if (args.size() == 0) {
- 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();
- }
- return serverFunction.execute(args);
-
- } else if (func.equals(Constants.FN_VERSION)) {
- if (versionFunction == null) {
- versionFunction = new ShowVersionFunction();
- }
- return versionFunction.execute(args);
-
- } else if (func.equals(Constants.FN_CONNECTOR)) {
- if (connectorFunction == null) {
- connectorFunction = new ShowConnectorFunction();
- }
- return connectorFunction.execute(args);
-
- } else if (func.equals(Constants.FN_FRAMEWORK)) {
- if (frameworkFunction == null) {
- frameworkFunction = new ShowFrameworkFunction();
- }
- return frameworkFunction.execute(args);
-
- } else if (func.equals(Constants.FN_CONNECTION)) {
- if (connectionFunction == null) {
- connectionFunction = new ShowConnectionFunction();
- }
- return connectionFunction.execute(args);
-
- } else if (func.equals(Constants.FN_JOB)) {
- if (jobFunction == null) {
- jobFunction = new ShowJobFunction();
- }
- return jobFunction.execute(args);
- } else if (func.equals(Constants.FN_SUBMISSION)) {
- if (submissionFunction == null) {
- submissionFunction = new ShowSubmissionFunction();
- }
- return submissionFunction.execute(args);
- } else if (func.equals(Constants.FN_OPTION)) {
- if (optionFunction == null) {
- optionFunction = new ShowOptionFunction();
- }
- return optionFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java
deleted file mode 100644
index 94f92b3..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectionFunction.java
+++ /dev/null
@@ -1,123 +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.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.utils.TableDisplayer;
-import org.apache.sqoop.model.MConnection;
-
-import java.text.DateFormat;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-import static org.apache.sqoop.client.utils.FormDisplayer.*;
-
-/**
- *
- */
-public class ShowConnectionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- protected ShowConnectionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNS))
- .withLongOpt(Constants.OPT_ALL)
- .create(Constants.OPT_ALL_CHAR));
- this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_XID)
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONN_XID))
- .withLongOpt(Constants.OPT_XID)
- .create(Constants.OPT_XID_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (line.hasOption(Constants.OPT_ALL)) {
- showConnections();
- } else if (line.hasOption(Constants.OPT_XID)) {
- showConnection(getLong(line, Constants.OPT_XID));
- } else {
- showSummary();
- }
-
- return null;
- }
-
- private void showSummary() {
- List<MConnection> connections = client.getConnections();
-
- List<String> header = new LinkedList<String>();
- header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
- header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
- header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR));
- header.add(resourceString(Constants.RES_TABLE_HEADER_ENABLED));
-
- List<String> ids = new LinkedList<String>();
- List<String> names = new LinkedList<String>();
- List<String> connectors = new LinkedList<String>();
- List<String> availabilities = new LinkedList<String>();
-
- for(MConnection connection : connections) {
- ids.add(String.valueOf(connection.getPersistenceId()));
- names.add(connection.getName());
- connectors.add(String.valueOf(connection.getConnectorId()));
- availabilities.add(String.valueOf(connection.getEnabled()));
- }
-
- TableDisplayer.display(header, ids, names, connectors, availabilities);
- }
-
- private void showConnections() {
- List<MConnection> connections = client.getConnections();
-
- printlnResource(Constants.RES_SHOW_PROMPT_CONNS_TO_SHOW, connections.size());
-
- for (MConnection connection : connections) {
- displayConnection(connection);
- }
- }
-
- private void showConnection(Long xid) {
- MConnection connection = client.getConnection(xid);
-
- printlnResource(Constants.RES_SHOW_PROMPT_CONNS_TO_SHOW, 1);
-
- displayConnection(connection);
- }
-
- private void displayConnection(MConnection connection) {
- DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
-
- printlnResource(Constants.RES_SHOW_PROMPT_CONN_INFO,
- connection.getPersistenceId(),
- connection.getName(),
- connection.getEnabled(),
- formatter.format(connection.getCreationDate()),
- formatter.format(connection.getLastUpdateDate())
- );
-
- long connectorId = connection.getConnectorId();
- printlnResource(Constants.RES_SHOW_PROMPT_CONN_CID_INFO, connectorId);
-
- // Display connector part
- displayForms(connection.getConnectorPart().getForms(),
- client.getResourceBundle(connectorId));
- displayForms(connection.getFrameworkPart().getForms(),
- client.getFrameworkResourceBundle());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
deleted file mode 100644
index b053339..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
+++ /dev/null
@@ -1,110 +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.shell;
-
-import java.util.Collection;
-import java.util.LinkedList;
-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.utils.TableDisplayer;
-import org.apache.sqoop.model.MConnector;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-import static org.apache.sqoop.client.utils.FormDisplayer.*;
-
-@SuppressWarnings("serial")
-public class ShowConnectorFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- protected ShowConnectorFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS))
- .withLongOpt(Constants.OPT_ALL)
- .create(Constants.OPT_ALL_CHAR));
- this.addOption(OptionBuilder.hasArg().withArgName("cid")
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID))
- .withLongOpt(Constants.OPT_CID)
- .create(Constants.OPT_CID_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (line.hasOption(Constants.OPT_ALL)) {
- showConnectors();
- } else if (line.hasOption(Constants.OPT_CID)) {
- showConnector(getLong(line, Constants.OPT_CID));
- } else {
- showSummary();
- }
-
- return null;
- }
-
- private void showSummary() {
- Collection<MConnector> connectors = client.getConnectors();
-
- List<String> header = new LinkedList<String>();
- header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
- header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
- header.add(resourceString(Constants.RES_TABLE_HEADER_VERSION));
- header.add(resourceString(Constants.RES_TABLE_HEADER_CLASS));
-
- List<String> ids = new LinkedList<String>();
- List<String> uniqueNames = new LinkedList<String>();
- List<String> versions = new LinkedList<String>();
- List<String> classes = new LinkedList<String>();
-
- for(MConnector connector : connectors) {
- ids.add(String.valueOf(connector.getPersistenceId()));
- uniqueNames.add(connector.getUniqueName());
- versions.add(connector.getVersion());
- classes.add(connector.getClassName());
- }
-
- TableDisplayer.display(header, ids, uniqueNames, versions, classes);
- }
-
- private void showConnectors() {
- Collection<MConnector> connectors = client.getConnectors();
-
- printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, connectors.size());
-
- for (MConnector connector : connectors) {
- displayConnector(connector);
- }
- }
-
- private void showConnector(Long cid) {
- MConnector connector = client.getConnector(cid);
-
- printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, 1);
-
- displayConnector(connector);
- }
-
- private void displayConnector(MConnector connector) {
- printlnResource(Constants.RES_SHOW_PROMPT_CONNECTOR_INFO,
- connector.getPersistenceId(),
- connector.getUniqueName(),
- connector.getClassName(),
- connector.getVersion()
- );
- displayFormMetadataDetails(connector, client.getResourceBundle(connector.getPersistenceId()));
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java
deleted file mode 100644
index 58b2c6e..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowFrameworkFunction.java
+++ /dev/null
@@ -1,55 +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.shell;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.model.MFramework;
-
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-import static org.apache.sqoop.client.utils.FormDisplayer.*;
-
-/**
- *
- */
-public class ShowFrameworkFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- protected ShowFrameworkFunction() {
- }
-
- public Object executeFunction(CommandLine line) {
- if (line.getArgs().length != 0) {
- printlnResource(Constants.RES_SHOW_FRAMEWORK_USAGE);
- return null;
- }
-
- showFramework();
-
- return null;
- }
-
- private void showFramework() {
- MFramework framework = client.getFramework();
- ResourceBundle bundle = client.getFrameworkResourceBundle();
-
- printlnResource(Constants.RES_SHOW_PROMPT_FRAMEWORK_OPTS, framework.getPersistenceId());
- displayFormMetadataDetails(framework, bundle);
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java
deleted file mode 100644
index 97a240b..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowJobFunction.java
+++ /dev/null
@@ -1,125 +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.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.utils.TableDisplayer;
-import org.apache.sqoop.model.MJob;
-
-import java.text.DateFormat;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-import static org.apache.sqoop.client.utils.FormDisplayer.*;
-
-/**
- *
- */
-public class ShowJobFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- protected ShowJobFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_JOBS))
- .withLongOpt(Constants.OPT_ALL)
- .create(Constants.OPT_ALL_CHAR));
- this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOB_JID))
- .withLongOpt(Constants.OPT_JID)
- .create(Constants.OPT_JID_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (line.hasOption(Constants.OPT_ALL)) {
- showJobs();
- } else if (line.hasOption(Constants.OPT_JID)) {
- showJob(getLong(line, Constants.OPT_JID));
- } else {
- showSummary();
- }
-
- return null;
- }
-
- private void showSummary() {
- List<MJob> jobs = client.getJobs();
-
- List<String> header = new LinkedList<String>();
- header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
- header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
- header.add(resourceString(Constants.RES_TABLE_HEADER_TYPE));
- header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR));
- header.add(resourceString(Constants.RES_TABLE_HEADER_ENABLED));
-
- List<String> ids = new LinkedList<String>();
- List<String> names = new LinkedList<String>();
- List<String> types = new LinkedList<String>();
- List<String> connectors = new LinkedList<String>();
- List<String> availabilities = new LinkedList<String>();
-
- for(MJob job : jobs) {
- ids.add(String.valueOf(job.getPersistenceId()));
- names.add(job.getName());
- types.add(job.getType().toString());
- connectors.add(String.valueOf(job.getConnectorId()));
- availabilities.add(String.valueOf(job.getEnabled()));
- }
-
- TableDisplayer.display(header, ids, names, types, connectors, availabilities);
- }
-
- private void showJobs() {
- List<MJob> jobs = client.getJobs();
- printlnResource(Constants.RES_SHOW_PROMPT_JOBS_TO_SHOW, jobs.size());
-
- for (MJob job : jobs) {
- displayJob(job);
- }
- }
-
- private void showJob(Long jid) {
- MJob job = client.getJob(jid);
- printlnResource(Constants.RES_SHOW_PROMPT_JOBS_TO_SHOW, 1);
-
- displayJob(job);
- }
-
- private void displayJob(MJob job) {
- DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
-
- printlnResource(
- Constants.RES_SHOW_PROMPT_JOB_INFO,
- job.getPersistenceId(),
- job.getName(),
- job.getEnabled(),
- formatter.format(job.getCreationDate()),
- formatter.format(job.getLastUpdateDate())
- );
- printlnResource(Constants.RES_SHOW_PROMPT_JOB_XID_CID_INFO,
- job.getConnectionId(),
- job.getConnectorId());
-
- // Display connector part
- displayForms(job.getConnectorPart().getForms(),
- client.getResourceBundle(job.getConnectorId()));
- displayForms(job.getFrameworkPart().getForms(),
- client.getFrameworkResourceBundle());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java
deleted file mode 100644
index 81c5612..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowOptionFunction.java
+++ /dev/null
@@ -1,89 +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.shell;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Show client internal options
- */
-public class ShowOptionFunction extends SqoopFunction {
- /**
- * Construct new object.
- */
- @SuppressWarnings("static-access")
- protected ShowOptionFunction() {
- this.addOption(OptionBuilder
- .hasArg().withArgName(Constants.OPT_NAME)
- .withDescription(resource.getString(Constants.RES_SET_PROMPT_OPT_NAME))
- .withLongOpt(Constants.OPT_NAME)
- .create(Constants.OPT_NAME_CHAR));
- }
-
- /**
- * Execute this function from parsed command line.
- */
- public Object executeFunction(CommandLine line) {
- if (line.getArgs().length == 1) {
- printAllOptions();
- return null;
- }
-
- if (line.hasOption(Constants.OPT_NAME)) {
- String optionName = line.getOptionValue(Constants.OPT_NAME);
-
- if(optionName.equals(Constants.OPT_VERBOSE)) {
- printVerbose();
- }
-
- if(optionName.equals(Constants.OPT_POLL_TIMEOUT)) {
- printPollTimeout();
- }
- }
-
- return null;
- }
-
- /**
- * Print all known client options.
- */
- private void printAllOptions() {
- printVerbose();
- printPollTimeout();
- }
-
- /**
- * Print verbose option.
- */
- private void printVerbose() {
- print("Verbose = ");
- println(String.valueOf(isVerbose()));
- }
-
- /**
- * Print poll-timeout option.
- */
- private void printPollTimeout() {
- print("Poll-timeout = ");
- println(String.valueOf(getPollTimeout()));
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
deleted file mode 100644
index 110f67e..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
+++ /dev/null
@@ -1,88 +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.shell;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-@SuppressWarnings("serial")
-public class ShowServerFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- protected ShowServerFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_SERVERS))
- .withLongOpt(Constants.OPT_ALL)
- .create(Constants.OPT_ALL_CHAR));
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_HOST))
- .withLongOpt(Constants.OPT_HOST)
- .create(Constants.OPT_HOST_CHAR));
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_PORT))
- .withLongOpt(Constants.OPT_PORT)
- .create(Constants.OPT_PORT_CHAR));
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_SERVER_WEBAPP))
- .withLongOpt(Constants.OPT_WEBAPP)
- .create(Constants.OPT_WEBAPP_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (line.getArgs().length == 1) {
- printlnResource(Constants.RES_SHOW_SERVER_USAGE);
- return null;
- }
-
- if (line.hasOption(Constants.OPT_ALL)) {
- showServer(true, true, true, true);
-
- } else {
- boolean host = false, port = false, webapp = false, version = false;
- if (line.hasOption(Constants.OPT_HOST)) {
- host = true;
- }
- if (line.hasOption(Constants.OPT_PORT)) {
- port = true;
- }
- if (line.hasOption(Constants.OPT_WEBAPP)) {
- webapp = true;
- }
-
- showServer(host, port, webapp, version);
- }
-
- return null;
- }
-
- private void showServer(boolean host, boolean port, boolean webapp, boolean version) {
- if (host) {
- printlnResource(Constants.RES_SHOW_PROMPT_SERVER_HOST, getServerHost());
- }
-
- if (port) {
- printlnResource(Constants.RES_SHOW_PROMPT_SERVER_PORT, getServerPort());
- }
-
- if (webapp) {
- printlnResource(Constants.RES_SHOW_PROMPT_SERVER_WEBAPP, getServerWebapp());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/ShowSubmissionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowSubmissionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowSubmissionFunction.java
deleted file mode 100644
index 666eb7a..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowSubmissionFunction.java
+++ /dev/null
@@ -1,106 +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.shell;
-
-import java.util.LinkedList;
-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.utils.SubmissionDisplayer;
-import org.apache.sqoop.client.utils.TableDisplayer;
-import org.apache.sqoop.model.MSubmission;
-import org.apache.sqoop.submission.SubmissionStatus;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-public class ShowSubmissionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- protected ShowSubmissionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS))
- .withLongOpt(Constants.OPT_DETAIL)
- .create(Constants.OPT_DETAIL_CHAR));
- this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .create(Constants.OPT_JID_CHAR));
- }
-
- @Override
- public Object executeFunction(CommandLine line) {
- if (line.hasOption(Constants.OPT_DETAIL)) {
- if (line.hasOption(Constants.OPT_JID)) {
- showSubmissions(getLong(line, Constants.OPT_JID));
- } else {
- showSubmissions(null);
- }
- } else {
- if (line.hasOption(Constants.OPT_JID)) {
- showSummary(getLong(line, Constants.OPT_JID));
- } else {
- showSummary(null);
- }
- }
-
- return null;
- }
-
- private void showSummary(Long jid) {
- List<MSubmission> submissions;
- if (jid == null) {
- submissions = client.getSubmissions();
- } else {
- submissions = client.getSubmissionsForJob(jid);
- }
-
- List<String> header = new LinkedList<String>();
- header.add(resourceString(Constants.RES_TABLE_HEADER_JOB_ID));
- header.add(resourceString(Constants.RES_TABLE_HEADER_EXTERNAL_ID));
- header.add(resourceString(Constants.RES_TABLE_HEADER_STATUS));
- header.add(resourceString(Constants.RES_TABLE_HEADER_DATE));
-
- List<String> jids = new LinkedList<String>();
- List<String> eids = new LinkedList<String>();
- List<String> status = new LinkedList<String>();
- List<String> dates = new LinkedList<String>();
-
- for (MSubmission submission : submissions) {
- jids.add(String.valueOf(submission.getJobId()));
- eids.add(String.valueOf(submission.getExternalId()));
- status.add(submission.getStatus().toString());
- dates.add(submission.getLastUpdateDate().toString());
- }
-
- TableDisplayer.display(header, jids, eids, status, dates);
- }
-
- private void showSubmissions(Long jid) {
- List<MSubmission> submissions;
- if (jid == null) {
- submissions = client.getSubmissions();
- } else {
- submissions = client.getSubmissionsForJob(jid);
- }
-
- for (MSubmission submission : submissions) {
- SubmissionDisplayer.displaySubmission(submission);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
deleted file mode 100644
index 8e17f67..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
+++ /dev/null
@@ -1,127 +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.shell;
-
-import java.util.Arrays;
-
-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.VersionRequest;
-import org.apache.sqoop.common.VersionInfo;
-import org.apache.sqoop.json.VersionBean;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-@SuppressWarnings("serial")
-public class ShowVersionFunction extends SqoopFunction {
- private VersionRequest versionRequest;
-
-
- @SuppressWarnings("static-access")
- protected ShowVersionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_VERSIONS))
- .withLongOpt(Constants.OPT_ALL)
- .create(Constants.OPT_ALL_CHAR));
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_SERVER))
- .withLongOpt(Constants.OPT_SERVER)
- .create(Constants.OPT_SERVER_CHAR));
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_CLIENT))
- .withLongOpt(Constants.OPT_CLIENT)
- .create(Constants.OPT_CLIENT_CHAR));
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_VERSION_PROTOCOL))
- .withLongOpt(Constants.OPT_PROTOCOL)
- .create(Constants.OPT_PROTOCOL_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (line.getArgs().length == 1) {
- printlnResource(Constants.RES_SHOW_VERSION_USAGE);
- return null;
- }
-
- if (line.hasOption(Constants.OPT_ALL)) {
- showVersion(true, true, true);
-
- } else {
- boolean server = false, client = false, protocol = false;
- if (line.hasOption(Constants.OPT_SERVER)) {
- server = true;
- }
- if (line.hasOption(Constants.OPT_CLIENT)) {
- client = true;
- }
- if (line.hasOption(Constants.OPT_PROTOCOL)) {
- protocol = true;
- }
-
- showVersion(server, client, protocol);
- }
-
- return null;
- }
-
- private void showVersion(boolean server, boolean client, boolean protocol) {
-
- // If no option has been given, print out client version as default
- if (!client && !server && !protocol) {
- client = true;
- }
-
- // Print out client string if needed
- if (client) {
- printlnResource(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER,
- Constants.OPT_CLIENT,
- VersionInfo.getVersion(),
- VersionInfo.getRevision(),
- VersionInfo.getUser(),
- VersionInfo.getDate()
- );
- }
-
- // If only client version was required we do not need to continue
- if(!server && !protocol) {
- return;
- }
-
- if (versionRequest == null) {
- versionRequest = new VersionRequest();
- }
- VersionBean versionBean = versionRequest.doGet(getServerUrl());
-
- if (server) {
- printlnResource(Constants.RES_SHOW_PROMPT_VERSION_CLIENT_SERVER,
- Constants.OPT_SERVER,
- versionBean.getVersion(),
- versionBean.getRevision(),
- versionBean.getUser(),
- versionBean.getDate()
- );
- }
-
- if (protocol) {
- printlnResource(Constants.RES_SHOW_PROMPT_VERSION_PROTOCOL,
- Arrays.toString(versionBean.getProtocols())
- );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
deleted file mode 100644
index 2188482..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/SqoopCommand.java
+++ /dev/null
@@ -1,152 +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.shell;
-
-import groovy.lang.GroovyShell;
-import groovy.lang.MissingPropertyException;
-import groovy.lang.Script;
-
-import java.util.*;
-
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.common.SqoopException;
-import org.codehaus.groovy.tools.shell.ComplexCommandSupport;
-import org.codehaus.groovy.tools.shell.Shell;
-
-public abstract class SqoopCommand extends ComplexCommandSupport
-{
- private String descriptionPrefix;
- private String descriptionPostfix;
-
- private String description;
- private String usage;
- private String help;
-
- @SuppressWarnings("unchecked")
- protected SqoopCommand(Shell shell, String name, String shortcut,
- String[] funcs, String descriptionPrefix, String descriptionPostfix) {
- super(shell, name, shortcut);
-
- this.functions = new LinkedList<String>();
- for (String func : funcs) {
- this.functions.add(func);
- }
-
- this.descriptionPrefix = descriptionPrefix;
- this.descriptionPostfix = descriptionPostfix;
- }
-
- @Override
- public String getDescription() {
- if (description == null) {
- StringBuilder sb = new StringBuilder();
-
- if (descriptionPrefix != null) {
- sb.append(descriptionPrefix);
- sb.append(" ");
- }
-
- @SuppressWarnings("unchecked")
- Iterator<String> iterator = functions.iterator();
- int size = functions.size();
- sb.append(iterator.next());
- if (size > 1) {
- for (int i = 1; i < (size - 1); i++) {
- sb.append(", ");
- sb.append(iterator.next());
- }
- sb.append(" or ");
- sb.append(iterator.next());
- }
-
- if (descriptionPostfix != null) {
- sb.append(" ");
- sb.append(descriptionPostfix);
- }
-
- description = sb.toString();
- }
-
- return description;
- }
-
- @Override
- public String getUsage() {
- if (usage == null) {
- StringBuilder sb = new StringBuilder();
-
- sb.append("[");
-
- @SuppressWarnings("unchecked")
- Iterator<String> iterator = functions.iterator();
- int size = functions.size();
- sb.append(iterator.next());
- for (int i = 1; i < size; i++) {
- sb.append("|");
- sb.append(iterator.next());
- }
-
- sb.append("]");
-
- usage = sb.toString();
- }
-
- return usage;
- }
-
- @Override
- public String getHelp() {
- if (help == null) {
- help = getDescription() + ".";
- }
-
- return help;
- }
-
- /**
- * Override execute method
- */
- @Override
- public Object execute(List args) {
- resolveVariables(args);
- return executeCommand(args);
- }
-
- /**
- * Abstract executeCommand
- * @param args list
- * @return Object
- */
- public abstract Object executeCommand(List args);
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected void resolveVariables(List arg) {
- List temp = new ArrayList();
- GroovyShell gs = new GroovyShell(getBinding());
- for(Object obj:arg) {
- Script scr = gs.parse("\""+(String)obj+"\"");
- try {
- temp.add(scr.run().toString());
- }
- catch(MissingPropertyException e) {
- throw new SqoopException(ClientError.CLIENT_0004, e.getMessage(), e);
- }
- }
- Collections.copy(arg, temp);
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
deleted file mode 100644
index bf26761..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/SqoopFunction.java
+++ /dev/null
@@ -1,74 +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.shell;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.common.SqoopException;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-@SuppressWarnings("serial")
-abstract public class SqoopFunction extends Options {
-
- public void printHelp() {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printOptions(getIo().out, formatter.getWidth(), this, 0, 4);
- }
-
- public abstract Object executeFunction(CommandLine line);
-
- public Object execute(List<String> args) {
- CommandLine line = parseOptions(this, 1, args);
- return executeFunction(line);
- }
-
- protected CommandLine parseOptions(Options options, int start, List<String> arglist) {
- Iterator<String> iterator = arglist.iterator();
- int i = 0;
- for (; i < start; i ++) {
- iterator.next();
- }
-
- String[] args = new String[arglist.size() - start];
- for (; i < arglist.size(); i ++) {
- args[i - start] = iterator.next();
- }
-
- CommandLineParser parser = new GnuParser();
- CommandLine line;
- try {
- line = parser.parse(options, args);
- } catch (ParseException e) {
- throw new SqoopException(ClientError.CLIENT_0003, e.getMessage(), e);
- }
- return line;
- }
-
- protected long getLong(CommandLine line, String parameterName) {
- return Long.parseLong(line.getOptionValue(parameterName));
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java b/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
deleted file mode 100644
index f4ea3be..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
+++ /dev/null
@@ -1,176 +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.shell;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.ThrowableDisplayer;
-import org.codehaus.groovy.runtime.MethodClosure;
-import org.codehaus.groovy.tools.shell.Command;
-import org.codehaus.groovy.tools.shell.CommandRegistry;
-import org.codehaus.groovy.tools.shell.Groovysh;
-import org.codehaus.groovy.tools.shell.IO.Verbosity;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Main entry point to Sqoop client.
- *
- * Sqoop shell is implemented on top of Groovy shell.
- */
-public final class SqoopShell {
-
- /**
- * Location of resource file that can contain few initial commands that will
- * be loaded during each client execution.
- */
- private static final String RC_FILE = ".sqoop2rc";
-
- /**
- * Banner message that is displayed in interactive mode after client start.
- */
-
- /**
- * Hash of commands that we want to have in history in all cases.
- */
- public final static HashSet<String> commandsToKeep;
-
- static {
- commandsToKeep = new HashSet<String>();
- commandsToKeep.add("exit");
- commandsToKeep.add("history");
- }
-
- /**
- * Main entry point to the client execution.
- *
- * @param args Command line arguments
- * @throws Exception
- */
- public static void main (String[] args) throws Exception {
- System.setProperty("groovysh.prompt", Constants.SQOOP_PROMPT);
- Groovysh shell = new Groovysh();
-
- // Install our error hook (exception handling)
- shell.setErrorHook(new MethodClosure(ThrowableDisplayer.class, "errorHook"));
-
- CommandRegistry registry = shell.getRegistry();
- @SuppressWarnings("unchecked")
- Iterator<Command> iterator = registry.iterator();
- while (iterator.hasNext()) {
- Command command = iterator.next();
- if (!commandsToKeep.contains(command.getName())) {
- iterator.remove();
- // remove from "names" set to avoid duplicate error.
- registry.remove(command);
- }
- }
-
- shell.register(new HelpCommand(shell));
- shell.register(new SetCommand(shell));
- shell.register(new ShowCommand(shell));
- shell.register(new CreateCommand(shell));
- shell.register(new DeleteCommand(shell));
- shell.register(new UpdateCommand(shell));
- shell.register(new CloneCommand(shell));
- shell.register(new StartCommand(shell));
- shell.register(new StopCommand(shell));
- shell.register(new StatusCommand(shell));
- shell.register(new EnableCommand(shell));
- shell.register(new DisableCommand(shell));
-
- // Configure shared shell io object
- setIo(shell.getIo());
-
- // We're running in batch mode by default
- setInteractive(false);
-
- // Let's see if user do have resource file with initial commands that he
- // would like to apply.
- String homeDir = System.getProperty(Constants.PROP_HOMEDIR);
- File rcFile = new File(homeDir, RC_FILE);
-
- if(rcFile.exists()) {
- printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADRC, RC_FILE);
- interpretFileContent(rcFile, shell);
- printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADEDRC);
- }
-
- if (args.length == 0) {
- // Interactive mode:
- getIo().setVerbosity(Verbosity.QUIET);
- printlnResource(Constants.RES_SQOOP_SHELL_BANNER);
- println();
-
- // Switch to interactive mode
- setInteractive(true);
- shell.run(args);
-
- } else {
- // Batch mode (with a script file):
- File script = new File(args[0]);
- if (!script.isAbsolute()) {
- String userDir = System.getProperty(Constants.PROP_CURDIR);
- script = new File(userDir, args[0]);
- }
-
- interpretFileContent(script, shell);
- }
- }
-
- /**
- * Interpret file content in given shell.
- *
- * @param script Script file that should be interpreted
- * @param shell Shell where the script should be interpreted
- * @throws IOException
- */
- private static void interpretFileContent(File script, Groovysh shell) throws IOException {
- BufferedReader in = new BufferedReader(new FileReader(script));
- String line;
-
- // Iterate over all lines and executed them one by one
- while ((line = in.readLine()) != null) {
-
- // Skip comments and empty lines as we don't need to interpret those
- if(line.isEmpty() || line.startsWith("#")) {
- continue;
- }
-
- // Render shell and command to get user perception that it was run as usual
- print(shell.renderPrompt());
- println(line);
-
- // Manually trigger command line parsing
- Object result = shell.execute(line);
- if (result != null) {
- println(result);
- }
- }
- }
-
- private SqoopShell() {
- // Instantiation of this class is prohibited
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/StartCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/StartCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/StartCommand.java
deleted file mode 100644
index 7293f56..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/StartCommand.java
+++ /dev/null
@@ -1,58 +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.shell;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.Shell;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.printlnResource;
-
-public class StartCommand extends SqoopCommand {
- public static final Logger LOG = Logger.getLogger(StartCommand.class);
-
- private StartJobFunction startJobFunction;
-
- @SuppressWarnings("static-access")
- protected StartCommand(Shell shell) {
- super(shell, Constants.CMD_START, Constants.CMD_START_SC,
- new String[] {Constants.FN_JOB}, Constants.PRE_START, null);
- }
-
- @Override
- public Object executeCommand(List args) {
- if (args.size() == 0) {
- printlnResource(Constants.RES_START_USAGE, getUsage());
- return null;
- }
-
- String func = (String) args.get(0);
- if (func.equals(Constants.FN_JOB)) {
- if (startJobFunction == null) {
- startJobFunction = new StartJobFunction();
- }
- return startJobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/StartJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/StartJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/StartJobFunction.java
deleted file mode 100644
index 2e1c8d3..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/StartJobFunction.java
+++ /dev/null
@@ -1,89 +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.shell;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.client;
-import static org.apache.sqoop.client.shell.ShellEnvironment.getPollTimeout;
-import static org.apache.sqoop.client.shell.ShellEnvironment.resourceString;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.log4j.Logger;
-import org.apache.sqoop.client.SubmissionCallback;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.SubmissionDisplayer;
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.model.MSubmission;
-
-public class StartJobFunction extends SqoopFunction {
- public static final Logger LOG = Logger.getLogger(StartJobFunction.class);
-
- @SuppressWarnings("static-access")
- public StartJobFunction() {
- this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .create(Constants.OPT_JID_CHAR));
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_SYNCHRONOUS))
- .withLongOpt(Constants.OPT_SYNCHRONOUS)
- .create(Constants.OPT_SYNCHRONOUS_CHAR));
- }
-
- @Override
- public Object executeFunction(CommandLine line) {
- // Poll until finished
- if (line.hasOption(Constants.OPT_SYNCHRONOUS) && line.hasOption(Constants.OPT_JID)) {
- long pollTimeout = getPollTimeout();
- SubmissionCallback callback = new SubmissionCallback() {
- @Override
- public void submitted(MSubmission submission) {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayProgress(submission);
- }
-
- @Override
- public void updated(MSubmission submission) {
- SubmissionDisplayer.displayProgress(submission);
- }
-
- @Override
- public void finished(MSubmission submission) {
- SubmissionDisplayer.displayFooter(submission);
- }
- };
-
- try {
- client.startSubmission(getLong(line, Constants.OPT_JID), callback, pollTimeout);
- } catch (InterruptedException e) {
- throw new SqoopException(ClientError.CLIENT_0009, e);
- }
- } else if (line.hasOption(Constants.OPT_JID)) {
- MSubmission submission = client.startSubmission(getLong(line, Constants.OPT_JID));
- if(submission.getStatus().isFailure()) {
- SubmissionDisplayer.displayFooter(submission);
- } else {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayProgress(submission);
- }
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/StatusCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/StatusCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/StatusCommand.java
deleted file mode 100644
index 5aab035..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/StatusCommand.java
+++ /dev/null
@@ -1,56 +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.shell;
-
-import java.util.List;
-
-import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.Shell;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.printlnResource;
-
-public class StatusCommand extends SqoopCommand {
-
- private StatusJobFunction statusJobFunction;
-
- @SuppressWarnings("static-access")
- protected StatusCommand(Shell shell) {
- super(shell, Constants.CMD_STATUS, Constants.CMD_STATUS_SC,
- new String[] { Constants.FN_JOB }, Constants.PRE_STATUS, null);
- }
-
- @Override
- public Object executeCommand(List args) {
- if (args.size() == 0) {
- printlnResource(Constants.RES_STATUS_USAGE, getUsage());
- return null;
- }
-
- String func = (String) args.get(0);
- if (func.equals(Constants.FN_JOB)) {
- if (statusJobFunction == null) {
- statusJobFunction = new StatusJobFunction();
- }
- return statusJobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/StatusJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/StatusJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/StatusJobFunction.java
deleted file mode 100644
index b854a90..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/StatusJobFunction.java
+++ /dev/null
@@ -1,55 +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.shell;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.client;
-import static org.apache.sqoop.client.shell.ShellEnvironment.resourceString;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.SubmissionDisplayer;
-import org.apache.sqoop.model.MSubmission;
-import org.apache.sqoop.submission.SubmissionStatus;
-
-public class StatusJobFunction extends SqoopFunction{
-
- @SuppressWarnings("static-access")
- public StatusJobFunction() {
- this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .create(Constants.OPT_JID_CHAR));
- }
-
- @Override
- public Object executeFunction(CommandLine line) {
- if (line.hasOption(Constants.OPT_JID)) {
- MSubmission submission = client.getSubmissionStatus(getLong(line, Constants.OPT_JID));
- if(submission.getStatus().isFailure() || submission.getStatus().equals(SubmissionStatus.SUCCEEDED)) {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayFooter(submission);
- } else {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayProgress(submission);
- }
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/StopCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/StopCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/StopCommand.java
deleted file mode 100644
index 154c58e..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/StopCommand.java
+++ /dev/null
@@ -1,54 +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.shell;
-
-import java.util.List;
-
-import org.apache.sqoop.client.core.Constants;
-import org.codehaus.groovy.tools.shell.Shell;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.printlnResource;
-
-public class StopCommand extends SqoopCommand {
-
- private StopJobFunction stopJobFunction;
-
- @SuppressWarnings("static-access")
- protected StopCommand(Shell shell) {
- super(shell, Constants.CMD_STOP, Constants.CMD_STOP_SC,
- new String[] { Constants.FN_JOB }, Constants.PRE_STOP, null);
- }
- @Override
- public Object executeCommand(List args) {
- if (args.size() == 0) {
- printlnResource(Constants.RES_STOP_USAGE, getUsage());
- return null;
- }
-
- String func = (String) args.get(0);
- if (func.equals(Constants.FN_JOB)) {
- if (stopJobFunction == null) {
- stopJobFunction = new StopJobFunction();
- }
- return stopJobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/StopJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/StopJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/StopJobFunction.java
deleted file mode 100644
index 49ab461..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/StopJobFunction.java
+++ /dev/null
@@ -1,53 +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.shell;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.client;
-import static org.apache.sqoop.client.shell.ShellEnvironment.resourceString;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.SubmissionDisplayer;
-import org.apache.sqoop.model.MSubmission;
-
-public class StopJobFunction extends SqoopFunction {
-
- @SuppressWarnings("static-access")
- public StopJobFunction() {
- this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .create(Constants.OPT_JID_CHAR));
- }
-
- @Override
- public Object executeFunction(CommandLine line) {
- if (line.hasOption(Constants.OPT_JID)) {
- MSubmission submission = client.stopSubmission(getLong(line, Constants.OPT_JID));
- if(submission.getStatus().isFailure()) {
- SubmissionDisplayer.displayFooter(submission);
- } else {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayProgress(submission);
- }
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java
deleted file mode 100644
index f16745c..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java
+++ /dev/null
@@ -1,69 +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.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.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class UpdateCommand extends SqoopCommand {
-
- private UpdateConnectionFunction connectionFunction;
- private UpdateJobFunction jobFunction;
-
- public UpdateCommand(Shell shell) {
- super(shell, Constants.CMD_UPDATE, Constants.CMD_UPDATE_SC,
- new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
- Constants.PRE_UPDATE, Constants.SUF_INFO);
- }
-
- public Object executeCommand(List args) {
- if(!isInteractive()) {
- throw new SqoopException(ClientError.CLIENT_0007, "update");
- }
-
- if (args.size() == 0) {
- printlnResource(Constants.RES_UPDATE_USAGE, getUsage());
- return null;
- }
-
- String func = (String)args.get(0);
- if (func.equals(Constants.FN_CONNECTION)) {
- if (connectionFunction == null) {
- connectionFunction = new UpdateConnectionFunction();
- }
- return connectionFunction.execute(args);
- } else if (func.equals(Constants.FN_JOB)) {
- if (jobFunction == null) {
- jobFunction = new UpdateJobFunction();
- }
- return jobFunction.execute(args);
- } else {
- printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java
deleted file mode 100644
index 8556e2b..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/UpdateConnectionFunction.java
+++ /dev/null
@@ -1,97 +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.shell;
-
-import jline.ConsoleReader;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.FormDisplayer;
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.validation.Status;
-
-import java.io.IOException;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class UpdateConnectionFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public UpdateConnectionFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
- .withLongOpt(Constants.OPT_XID)
- .hasArg()
- .create(Constants.OPT_XID_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_XID)) {
- printlnResource(Constants.RES_ARGS_XID_MISSING);
- return null;
- }
-
- try {
- updateConnection(getLong(line, Constants.OPT_XID));
- } catch (IOException ex) {
- throw new SqoopException(ClientError.CLIENT_0005, ex);
- }
-
- return null;
- }
-
- private void updateConnection(Long connectionId) throws IOException {
- printlnResource(Constants.RES_UPDATE_UPDATING_CONN, connectionId);
-
- ConsoleReader reader = new ConsoleReader();
-
- MConnection connection = client.getConnection(connectionId);
-
- ResourceBundle connectorBundle = client.getResourceBundle(connection.getConnectorId());
- ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
-
- Status status = Status.FINE;
-
- printlnResource(Constants.RES_PROMPT_UPDATE_CONN_METADATA);
-
- do {
- // Print error introduction if needed
- if( !status.canProceed() ) {
- errorIntroduction();
- }
-
- // Fill in data from user
- if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
- return;
- }
-
- // Try to create
- status = client.updateConnection(connection);
- } while(!status.canProceed());
- FormDisplayer.displayFormWarning(connection);
- printlnResource(Constants.RES_UPDATE_CONN_SUCCESSFUL, status.name());
- }
-
-
-}