From a6f3bd94aa8a4c54d36bcd8ce2423b3a4f6d96cc Mon Sep 17 00:00:00 2001 From: George Kankava Date: Tue, 21 Jun 2016 10:53:08 +0400 Subject: [PATCH] Multiple code improvements - squid:1213, squid:S2275, squid:SwitchLastCaseIsDefaultCheck, squid:UselessImportCheck, squid:ClassVariableVisibilityCheck --- .../apache/accumulo/core/cli/ClientOpts.java | 170 ++++++++---------- .../core/client/impl/thrift/TDiskUsage.java | 19 +- .../apache/accumulo/core/util/Duration.java | 10 +- 3 files changed, 90 insertions(+), 109 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java b/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java index 71ee6d1f411..a220e02ce19 100644 --- a/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java +++ b/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java @@ -60,70 +60,44 @@ public class ClientOpts extends Help { - public static class TimeConverter implements IStringConverter { - @Override - public Long convert(String value) { - return AccumuloConfiguration.getTimeInMillis(value); - } - } - - public static class MemoryConverter implements IStringConverter { - @Override - public Long convert(String value) { - return AccumuloConfiguration.getMemoryInBytes(value); - } - } - - public static class AuthConverter implements IStringConverter { - @Override - public Authorizations convert(String value) { - return new Authorizations(value.split(",")); - } - } - - public static class Password { - public byte[] value; - - public Password(String dfault) { - value = dfault.getBytes(UTF_8); - } - - @Override - public String toString() { - return new String(value, UTF_8); - } - } - - public static class PasswordConverter implements IStringConverter { - @Override - public Password convert(String value) { - return new Password(value); - } - } - - public static class VisibilityConverter implements IStringConverter { - @Override - public ColumnVisibility convert(String value) { - return new ColumnVisibility(value); - } - } - + @DynamicParameter(names = "-l", + description = "login properties in the format key=value. Reuse -l for each property (prompt for properties if this option is missing") + public Map loginProps = new LinkedHashMap(); + @Parameter(names = {"-z", "--keepers"}, description = "Comma separated list of zookeeper hosts (host:port,host:port)") + public String zookeepers = "localhost:2181"; + @Parameter(names = {"-i", "--instance"}, description = "The name of the accumulo instance") + public String instance = null; + @Parameter(names = {"-auths", "--auths"}, converter = AuthConverter.class, description = "the authorizations to use when reading or writing") + public Authorizations auths = Authorizations.EMPTY; + @Parameter(names = "--debug", description = "turn on TRACE-level log messages") + public boolean debug = false; + @Parameter(names = {"-fake", "--mock"}, description = "Use a mock Instance") + public boolean mock = false; + @Parameter(names = "--site-file", description = "Read the given accumulo site file to find the accumulo instance") + public String siteFile = null; + @Parameter(names = "--ssl", description = "Connect to accumulo over SSL") + public boolean sslEnabled = false; + @Parameter(names = "--sasl", description = "Connecto to Accumulo using SASL (supports Kerberos)") + public boolean saslEnabled = 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") + public String clientConfigFile = null; + @Parameter(names = "--trace", description = "turn on distributed tracing") + public boolean trace = false; + @Parameter(names = "--keytab", description = "Kerberos keytab on the local filesystem") + public String keytabPath = null; + protected Instance cachedInstance = null; + protected ClientConfiguration cachedClientConfig = null; @Parameter(names = {"-u", "--user"}, description = "Connection user") private String principal = null; - @Parameter(names = "-p", converter = PasswordConverter.class, description = "Connection password") private Password password = null; - @Parameter(names = "--password", converter = PasswordConverter.class, description = "Enter the connection password", password = true) private Password securePassword = null; - @Parameter(names = {"-tc", "--tokenClass"}, description = "Token class") private String tokenClassName = null; - @DynamicParameter(names = "-l", - description = "login properties in the format key=value. Reuse -l for each property (prompt for properties if this option is missing") - public Map loginProps = new LinkedHashMap(); - public AuthenticationToken getToken() { if (null != tokenClassName) { final Properties props = new Properties(); @@ -151,46 +125,11 @@ public AuthenticationToken getToken() { return null; } - @Parameter(names = {"-z", "--keepers"}, description = "Comma separated list of zookeeper hosts (host:port,host:port)") - public String zookeepers = "localhost:2181"; - - @Parameter(names = {"-i", "--instance"}, description = "The name of the accumulo instance") - public String instance = null; - - @Parameter(names = {"-auths", "--auths"}, converter = AuthConverter.class, description = "the authorizations to use when reading or writing") - public Authorizations auths = Authorizations.EMPTY; - - @Parameter(names = "--debug", description = "turn on TRACE-level log messages") - public boolean debug = false; - - @Parameter(names = {"-fake", "--mock"}, description = "Use a mock Instance") - public boolean mock = false; - - @Parameter(names = "--site-file", description = "Read the given accumulo site file to find the accumulo instance") - public String siteFile = null; - - @Parameter(names = "--ssl", description = "Connect to accumulo over SSL") - public boolean sslEnabled = false; - - @Parameter(names = "--sasl", description = "Connecto to Accumulo using SASL (supports Kerberos)") - public boolean saslEnabled = 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") - public String clientConfigFile = null; - public void startDebugLogging() { if (debug) Logger.getLogger(Constants.CORE_PACKAGE_NAME).setLevel(Level.TRACE); } - @Parameter(names = "--trace", description = "turn on distributed tracing") - public boolean trace = false; - - @Parameter(names = "--keytab", description = "Kerberos keytab on the local filesystem") - public String keytabPath = null; - public void startTracing(String applicationName) { if (trace) { Trace.on(applicationName); @@ -253,9 +192,6 @@ public void parseArgs(String programName, String[] args, Object... others) { updateKerberosCredentials(); } - protected Instance cachedInstance = null; - protected ClientConfiguration cachedClientConfig = null; - synchronized public Instance getInstance() { if (cachedInstance != null) return cachedInstance; @@ -371,4 +307,52 @@ public String get(Property property) { return cachedClientConfig = clientConfig.withInstance(instance).withZkHosts(zookeepers); } + public static class TimeConverter implements IStringConverter { + @Override + public Long convert(String value) { + return AccumuloConfiguration.getTimeInMillis(value); + } + } + + public static class MemoryConverter implements IStringConverter { + @Override + public Long convert(String value) { + return AccumuloConfiguration.getMemoryInBytes(value); + } + } + + public static class AuthConverter implements IStringConverter { + @Override + public Authorizations convert(String value) { + return new Authorizations(value.split(",")); + } + } + + public static class Password { + public byte[] value; + + public Password(String dfault) { + value = dfault.getBytes(UTF_8); + } + + @Override + public String toString() { + return new String(value, UTF_8); + } + } + + public static class PasswordConverter implements IStringConverter { + @Override + public Password convert(String value) { + return new Password(value); + } + } + + public static class VisibilityConverter implements IStringConverter { + @Override + public ColumnVisibility convert(String value) { + return new ColumnVisibility(value); + } + } + } diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/thrift/TDiskUsage.java b/core/src/main/java/org/apache/accumulo/core/client/impl/thrift/TDiskUsage.java index 30dc624ca2e..4f48922b9af 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/thrift/TDiskUsage.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/thrift/TDiskUsage.java @@ -28,26 +28,17 @@ import org.apache.thrift.scheme.TupleScheme; import org.apache.thrift.protocol.TTupleProtocol; -import org.apache.thrift.protocol.TProtocolException; import org.apache.thrift.EncodingUtils; -import org.apache.thrift.TException; -import org.apache.thrift.async.AsyncMethodCallback; import org.apache.thrift.server.AbstractNonblockingServer.*; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; import java.util.EnumMap; -import java.util.Set; -import java.util.HashSet; import java.util.EnumSet; import java.util.Collections; import java.util.BitSet; -import java.nio.ByteBuffer; -import java.util.Arrays; import javax.annotation.Generated; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) @Generated(value = "Autogenerated by Thrift Compiler (0.9.3)") @@ -63,8 +54,8 @@ public class TDiskUsage implements org.apache.thrift.TBase tables; // required - public long usage; // required + private List tables; // required + private long usage; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { @@ -258,6 +249,8 @@ public void setFieldValue(_Fields field, Object value) { } break; + default: + break; } } @@ -269,6 +262,8 @@ public Object getFieldValue(_Fields field) { case USAGE: return getUsage(); + default: + break; } throw new IllegalStateException(); } @@ -284,6 +279,8 @@ public boolean isSet(_Fields field) { return isSetTables(); case USAGE: return isSetUsage(); + default: + break; } throw new IllegalStateException(); } diff --git a/core/src/main/java/org/apache/accumulo/core/util/Duration.java b/core/src/main/java/org/apache/accumulo/core/util/Duration.java index b1b85728f62..7c500a22d1f 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/Duration.java +++ b/core/src/main/java/org/apache/accumulo/core/util/Duration.java @@ -38,21 +38,21 @@ public static String format(long time, String space, String zero) { sec = time % 60; time /= 60; if (time == 0) - return String.format("%ds" + space + "%dms", sec, ms); + return String.format("%ds%s%dms", sec, space, ms); min = time % 60; time /= 60; if (time == 0) - return String.format("%dm" + space + "%ds", min, sec); + return String.format("%dm%s%ds", min, space, sec); hr = time % 24; time /= 24; if (time == 0) - return String.format("%dh" + space + "%dm", hr, min); + return String.format("%dh%s%dm", hr, space, min); day = time % 365; time /= 365; if (time == 0) - return String.format("%dd" + space + "%dh", day, hr); + return String.format("%dd%s%dh", day, space, hr); yr = time; - return String.format("%dy" + space + "%dd", yr, day); + return String.format("%dy%s%dd", yr, space, day); }