You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2014/02/06 01:30:30 UTC
[3/6] git commit: ACCUMULO-2317 Apply ClientOpts fix to shell also
ACCUMULO-2317 Apply ClientOpts fix to shell also
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/ec4bc2fb
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/ec4bc2fb
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/ec4bc2fb
Branch: refs/heads/master
Commit: ec4bc2fb274003e09fab0107f0b6d37a7df0df3a
Parents: 7f789ec
Author: Christopher Tubbs <ct...@apache.org>
Authored: Wed Feb 5 18:57:59 2014 -0500
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Wed Feb 5 18:57:59 2014 -0500
----------------------------------------------------------------------
.../core/util/shell/ShellOptionsJC.java | 100 ++++++++++---------
1 file changed, 52 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/ec4bc2fb/core/src/main/java/org/apache/accumulo/core/util/shell/ShellOptionsJC.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/ShellOptionsJC.java b/core/src/main/java/org/apache/accumulo/core/util/shell/ShellOptionsJC.java
index 7032e0d..38692a0 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/ShellOptionsJC.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/ShellOptionsJC.java
@@ -40,12 +40,13 @@ import com.beust.jcommander.converters.FileConverter;
public class ShellOptionsJC {
// Use the Shell logger because this is really just an extension.
public static final Logger log = Logger.getLogger(Shell.class);
-
+
@Parameter(names = {"-u", "--user"}, description = "username (defaults to your OS user)")
private String username = System.getProperty("user.name", "root");
-
+
public static class PasswordConverter implements IStringConverter<String> {
public static final String STDIN = "stdin";
+
private enum KeyType {
PASS("pass:"), ENV("env:") {
@Override
@@ -74,49 +75,50 @@ public class ShellOptionsJC {
public boolean matches(String value) {
return prefix.equals(value);
}
-
+
@Override
public String convert(String value) {
// Will check for this later
return prefix;
}
};
-
+
String prefix;
-
+
private KeyType(String prefix) {
this.prefix = prefix;
}
-
+
public boolean matches(String value) {
return value.startsWith(prefix);
}
-
+
public String convert(String value) {
return process(value.substring(prefix.length()));
}
-
+
String process(String value) {
return value;
}
};
-
+
+ @Override
public String convert(String value) {
for (KeyType keyType : KeyType.values()) {
if (keyType.matches(value)) {
return keyType.convert(value);
}
}
-
+
return value;
}
}
-
+
// Note: Don't use "password = true" because then it will prompt even if we have a token
@Parameter(names = {"-p", "--password"}, description = "password (can be specified as 'pass:<password>', 'file:<local file containing the password>', "
+ "'env:<variable containing the pass>', or stdin)", converter = PasswordConverter.class)
private String password;
-
+
public static class TokenConverter implements IStringConverter<AuthenticationToken> {
@Override
public AuthenticationToken convert(String value) {
@@ -128,114 +130,116 @@ public class ShellOptionsJC {
}
}
}
-
+
@Parameter(names = {"-tc", "--tokenClass"}, description = "token type to create, use the -l to pass options", converter = TokenConverter.class)
private AuthenticationToken authenticationToken;
-
+
@DynamicParameter(names = {"-l", "--tokenProperty"}, description = "login properties in the format key=value. Reuse -l for each property")
private Map<String,String> tokenProperties = new TreeMap<String,String>();
-
+
@Parameter(names = "--disable-tab-completion", description = "disables tab completion (for less overhead when scripting)")
private boolean tabCompletionDisabled;
-
+
@Parameter(names = "--debug", description = "enables client debugging")
private boolean debugEnabled;
-
+
@Parameter(names = "--fake", description = "fake a connection to accumulo")
private boolean fake;
-
+
@Parameter(names = {"-?", "--help"}, help = true, description = "display this help")
private boolean helpEnabled;
-
+
@Parameter(names = {"-e", "--execute-command"}, description = "executes a command, and then exits")
private String execCommand;
-
+
@Parameter(names = {"-f", "--execute-file"}, description = "executes commands from a file at startup", converter = FileConverter.class)
private File execFile;
-
+
@Parameter(names = {"-fv", "--execute-file-verbose"}, description = "executes commands from a file at startup, with commands shown",
converter = FileConverter.class)
private File execFileVerbose;
-
+
@Parameter(names = {"-h", "--hdfsZooInstance"}, description = "use hdfs zoo instance")
private boolean hdfsZooInstance;
-
+
@Parameter(names = {"-z", "--zooKeeperInstance"}, description = "use a zookeeper instance with the given instance name and list of zoo hosts", arity = 2)
private List<String> zooKeeperInstance = new ArrayList<String>();
-
+
@Parameter(names = {"--ssl"}, description = "use ssl to connect to accumulo")
private boolean useSsl = false;
- @Parameter(names = "--config-file", description = "read the given client config file. If omitted, the path searched can be specified with $ACCUMULO_CLIENT_CONF_PATH, which defaults to ~/.accumulo/config:$ACCUMULO_CONF_DIR/client.conf:/etc/accumulo/client.conf")
+ @Parameter(
+ names = "--config-file",
+ description = "read the given client config file. If omitted, the path searched can be specified with $ACCUMULO_CLIENT_CONF_PATH, which defaults to ~/.accumulo/config:$ACCUMULO_CONF_DIR/client.conf:/etc/accumulo/client.conf")
private String clientConfigFile = null;
- @Parameter(names = {"-zi", "--zooKeeperInstanceName"}, description="use a zookeeper instance with the given instance name")
+ @Parameter(names = {"-zi", "--zooKeeperInstanceName"}, description = "use a zookeeper instance with the given instance name")
private String zooKeeperInstanceName;
- @Parameter(names = {"-zh", "--zooKeeperHosts"}, description="use a zookeeper instance with the given list of zoo hosts")
+ @Parameter(names = {"-zh", "--zooKeeperHosts"}, description = "use a zookeeper instance with the given list of zoo hosts")
private String zooKeeperHosts;
@Parameter(names = "--auth-timeout", description = "minutes the shell can be idle without re-entering a password")
private int authTimeout = 60; // TODO Add validator for positive number
-
+
@Parameter(names = "--disable-auth-timeout", description = "disables requiring the user to re-type a password after being idle")
private boolean authTimeoutDisabled;
-
+
@Parameter(hidden = true)
private List<String> unrecognizedOptions;
-
+
public String getUsername() {
return username;
}
-
+
public String getPassword() {
return password;
}
-
+
public AuthenticationToken getAuthenticationToken() {
return authenticationToken;
}
-
+
public Map<String,String> getTokenProperties() {
return tokenProperties;
}
-
+
public boolean isTabCompletionDisabled() {
return tabCompletionDisabled;
}
-
+
public boolean isDebugEnabled() {
return debugEnabled;
}
-
+
public boolean isFake() {
return fake;
}
-
+
public boolean isHelpEnabled() {
return helpEnabled;
}
-
+
public String getExecCommand() {
return execCommand;
}
-
+
public File getExecFile() {
return execFile;
}
-
+
public File getExecFileVerbose() {
return execFileVerbose;
}
-
+
public boolean isHdfsZooInstance() {
return hdfsZooInstance;
}
-
+
public List<String> getZooKeeperInstance() {
return zooKeeperInstance;
}
-
+
public String getZooKeeperInstanceName() {
return zooKeeperInstanceName;
}
@@ -247,11 +251,11 @@ public class ShellOptionsJC {
public int getAuthTimeout() {
return authTimeout;
}
-
+
public boolean isAuthTimeoutDisabled() {
return authTimeoutDisabled;
}
-
+
public List<String> getUnrecognizedOptions() {
return unrecognizedOptions;
}
@@ -264,9 +268,9 @@ public class ShellOptionsJC {
return clientConfigFile;
}
- public ClientConfiguration getClientConfiguration() throws ConfigurationException,
- FileNotFoundException {
- ClientConfiguration clientConfig = new ClientConfiguration(new PropertiesConfiguration(getClientConfigFile()));
+ public ClientConfiguration getClientConfiguration() throws ConfigurationException, FileNotFoundException {
+ ClientConfiguration clientConfig = clientConfigFile == null ? ClientConfiguration.loadDefault() : new ClientConfiguration(new PropertiesConfiguration(
+ getClientConfigFile()));
if (useSsl()) {
clientConfig.setProperty(ClientProperty.INSTANCE_RPC_SSL_ENABLED, "true");
}