SQOOP-884: Disable interactive client commands in batch mode (Jarcec Cecho via Cheolsoo Park)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/339069f3 Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/339069f3 Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/339069f3 Branch: refs/heads/sqoop2 Commit: 339069f322741b2408d58142106792a29ca517e6 Parents: 4e62986 Author: Cheolsoo Park <[email protected]> Authored: Fri Feb 22 12:04:21 2013 -0800 Committer: Cheolsoo Park <[email protected]> Committed: Fri Feb 22 12:19:06 2013 -0800 ---------------------------------------------------------------------- .../org/apache/sqoop/client/core/ClientError.java | 3 +++ .../org/apache/sqoop/client/core/Environment.java | 10 ++++++++++ .../apache/sqoop/client/shell/CloneCommand.java | 8 ++++++-- .../apache/sqoop/client/shell/CreateCommand.java | 8 ++++++-- .../org/apache/sqoop/client/shell/SqoopShell.java | 7 +++++++ .../apache/sqoop/client/shell/UpdateCommand.java | 8 ++++++-- 6 files changed, 38 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sqoop/blob/339069f3/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 index fd3b97d..179dc55 100644 --- a/client/src/main/java/org/apache/sqoop/client/core/ClientError.java +++ b/client/src/main/java/org/apache/sqoop/client/core/ClientError.java @@ -42,6 +42,9 @@ public enum ClientError implements ErrorCode { /** 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"), + ; private final String message; http://git-wip-us.apache.org/repos/asf/sqoop/blob/339069f3/client/src/main/java/org/apache/sqoop/client/core/Environment.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/sqoop/client/core/Environment.java b/client/src/main/java/org/apache/sqoop/client/core/Environment.java index c9e4e2a..5d1af26 100644 --- a/client/src/main/java/org/apache/sqoop/client/core/Environment.java +++ b/client/src/main/java/org/apache/sqoop/client/core/Environment.java @@ -32,6 +32,8 @@ public final class Environment private static boolean verbose; + private static boolean interactive; + private static final String HOST_DEFAULT = "localhost"; private static final String PORT_DEFAULT = "12000"; private static final String WEBAPP_DEFAULT = "sqoop"; @@ -88,4 +90,12 @@ public final class Environment public static boolean isVerboose() { return verbose; } + + public static void setInteractive(boolean newValue) { + interactive = newValue; + } + + public static boolean isInteractive() { + return interactive; + } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/339069f3/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java index a127d61..abec66b 100644 --- a/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java +++ b/client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java @@ -19,6 +19,7 @@ package org.apache.sqoop.client.shell; import org.apache.sqoop.client.core.ClientError; import org.apache.sqoop.client.core.Constants; +import org.apache.sqoop.client.core.Environment; import org.apache.sqoop.common.SqoopException; import org.codehaus.groovy.tools.shell.Shell; @@ -43,8 +44,11 @@ public class CloneCommand extends SqoopCommand { } public Object executeCommand(List args) { - String usageMsg = MessageFormat.format(getResource().getString(Constants - .RES_CLONE_USAGE), getUsage()); + if(!Environment.isInteractive()) { + throw new SqoopException(ClientError.CLIENT_0007, "clone"); + } + + String usageMsg = MessageFormat.format(getResource().getString(Constants.RES_CLONE_USAGE), getUsage()); if (args.size() == 0) { io.out.println(usageMsg); http://git-wip-us.apache.org/repos/asf/sqoop/blob/339069f3/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java b/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java index 6cd2ff5..f4872d2 100644 --- a/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java +++ b/client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java @@ -19,6 +19,7 @@ package org.apache.sqoop.client.shell; import org.apache.sqoop.client.core.ClientError; import org.apache.sqoop.client.core.Constants; +import org.apache.sqoop.client.core.Environment; import org.apache.sqoop.common.SqoopException; import org.codehaus.groovy.tools.shell.Shell; @@ -42,8 +43,11 @@ public class CreateCommand extends SqoopCommand { } public Object executeCommand(List args) { - String usageMsg = MessageFormat.format(getResource().getString(Constants - .RES_CREATE_USAGE), getUsage()); + if(!Environment.isInteractive()) { + throw new SqoopException(ClientError.CLIENT_0007, "create"); + } + + String usageMsg = MessageFormat.format(getResource().getString(Constants.RES_CREATE_USAGE), getUsage()); if (args.size() == 0) { io.out.println(usageMsg); http://git-wip-us.apache.org/repos/asf/sqoop/blob/339069f3/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 index 9fb5f03..b4d352c 100644 --- a/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java +++ b/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java @@ -27,6 +27,7 @@ import java.util.Iterator; import java.util.ResourceBundle; import org.apache.sqoop.client.core.Constants; +import org.apache.sqoop.client.core.Environment; import org.apache.sqoop.client.utils.ThrowableDisplayer; import org.codehaus.groovy.runtime.MethodClosure; import org.codehaus.groovy.tools.shell.Command; @@ -104,6 +105,9 @@ public final class SqoopShell { shell.register(new CloneCommand(shell)); shell.register(new SubmissionCommand(shell)); + // We're running in batch mode by default + Environment.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); @@ -122,6 +126,9 @@ public final class SqoopShell { shell.getIo().out.println(clientResource.getString(Constants .RES_SQOOP_SHELL_BANNER)); shell.getIo().out.println(); + + // Switch to interactive mode + Environment.setInteractive(true); shell.run(args); } else { http://git-wip-us.apache.org/repos/asf/sqoop/blob/339069f3/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 index fcf8862..0057efb 100644 --- a/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java +++ b/client/src/main/java/org/apache/sqoop/client/shell/UpdateCommand.java @@ -19,6 +19,7 @@ package org.apache.sqoop.client.shell; import org.apache.sqoop.client.core.ClientError; import org.apache.sqoop.client.core.Constants; +import org.apache.sqoop.client.core.Environment; import org.apache.sqoop.common.SqoopException; import org.codehaus.groovy.tools.shell.Shell; @@ -41,8 +42,11 @@ public class UpdateCommand extends SqoopCommand { } public Object executeCommand(List args) { - String usageMsg = MessageFormat.format(getResource().getString(Constants - .RES_UPDATE_USAGE), getUsage()); + if(!Environment.isInteractive()) { + throw new SqoopException(ClientError.CLIENT_0007, "update"); + } + + String usageMsg = MessageFormat.format(getResource().getString(Constants.RES_UPDATE_USAGE), getUsage()); if (args.size() == 0) { io.out.println(usageMsg); io.out.println();
