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:22:01 UTC
[3/6] SQOOP-921. Sqoop2: Create standalone shell package
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
+ }
+}