http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/MemberGroupConverter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/MemberGroupConverter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/MemberGroupConverter.java index 96690e8..e961911 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/MemberGroupConverter.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/MemberGroupConverter.java @@ -19,13 +19,13 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.internal.cli.shell.Gfsh; - import org.springframework.shell.core.Completion; import org.springframework.shell.core.Converter; import org.springframework.shell.core.MethodTarget; +import org.apache.geode.management.cli.ConverterHint; +import org.apache.geode.management.internal.cli.shell.Gfsh; + /** * * @since GemFire 7.0 @@ -34,20 +34,17 @@ public class MemberGroupConverter implements Converter<String> { @Override public boolean supports(Class<?> type, String optionContext) { - // System.out.println("MemberGroupConverter.supports("+type+","+optionContext+")"); return String.class.equals(type) && ConverterHint.MEMBERGROUP.equals(optionContext); } @Override public String convertFromText(String value, Class<?> targetType, String optionContext) { - // System.out.println("MemberGroupConverter.convertFromText("+value+","+targetType+","+optionContext+")"); return value; } @Override public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData, String optionContext, MethodTarget target) { - // System.out.println("MemberGroupConverter.getAllPossibleValues("+existingData+","+targetType+","+optionContext+")"); if (String.class.equals(targetType) && ConverterHint.MEMBERGROUP.equals(optionContext)) { String[] memberGroupNames = getMemberGroupNames(); @@ -60,7 +57,7 @@ public class MemberGroupConverter implements Converter<String> { public Set<String> getMemberGroups() { final Gfsh gfsh = Gfsh.getCurrentInstance(); - final Set<String> memberGroups = new TreeSet<String>(); + final Set<String> memberGroups = new TreeSet<>(); if (gfsh != null && gfsh.isConnectedAndReady()) { final String[] memberGroupsArray =
http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/DataCommandResult.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/DataCommandResult.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/DataCommandResult.java index b682767..5ad88c3 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/DataCommandResult.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/domain/DataCommandResult.java @@ -44,9 +44,9 @@ import org.apache.geode.management.internal.cli.util.JsonUtil; /** - * Domain object used for Data Commands Functions TODO : Implement DataSerializable + * Domain object used for Data Commands Functions */ -public class DataCommandResult implements /* Data */ Serializable { +public class DataCommandResult implements Serializable { private static Logger logger = LogManager.getLogger(); private static final long serialVersionUID = 1L; @@ -260,7 +260,6 @@ public class DataCommandResult implements /* Data */ Serializable { DataCommandResult result = new DataCommandResult(); result.command = CliStrings.QUERY; result.inputQuery = inputQuery; - // result.limit = limit; result.queryTraceString = queryTraceString; result.selectResult = value; result.error = error; @@ -390,7 +389,6 @@ public class DataCommandResult implements /* Data */ Serializable { } if (errorString != null) { - // return ResultBuilder.createGemFireErrorResult(errorString); CompositeResultData data = ResultBuilder.createCompositeResultData(); SectionResultData section = data.addSection(); section.addData("Message", errorString); @@ -415,8 +413,6 @@ public class DataCommandResult implements /* Data */ Serializable { toCommandResult_isPut(section, table); } else if (isRemove()) { toCommandResult_isRemove(section, table); - } else if (isSelect()) { - // its moved to its separate method } return ResultBuilder.buildResult(data); } @@ -457,7 +453,6 @@ public class DataCommandResult implements /* Data */ Serializable { if (locations != null) { if (locations.size() == 1) { Object array[] = locations.get(0); - // String regionPath = (String)array[0]; boolean found = (Boolean) array[1]; if (found) { totalLocations++; @@ -537,11 +532,10 @@ public class DataCommandResult implements /* Data */ Serializable { * This method returns result when flag interactive=false i.e. Command returns result in one go * and does not goes through steps waiting for user input. Method returns CompositeResultData * instead of Result as Command Step is required to add NEXT_STEP information to guide - * executionStragey to route it through final step. + * executionStrategy to route it through final step. */ public CompositeResultData toSelectCommandResult() { if (errorString != null) { - // return ResultBuilder.createGemFireErrorResult(errorString); CompositeResultData data = ResultBuilder.createCompositeResultData(); SectionResultData section = data.addSection(); section.addData("Message", errorString); @@ -613,7 +607,6 @@ public class DataCommandResult implements /* Data */ Serializable { try { tableRow.put(key, MISSING_VALUE); } catch (GfJsonException e) { - // TODO: Address this unlikely possibility. logger.warn("Ignored GfJsonException:", e); } } @@ -816,7 +809,6 @@ public class DataCommandResult implements /* Data */ Serializable { if (result == null) {// self-transform result from single to aggregate when numMember==1 if (this.locateEntryResult != null) { locateEntryLocations.add(locateEntryResult); - // TODO : Decide whether to show value or not this.getResult = locateEntryResult.getValue(); } return; } http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java index 96f8815..82a7adf 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java @@ -14,10 +14,8 @@ */ package org.apache.geode.management.internal.cli.functions; -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -26,7 +24,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.lang.StringUtils; import org.apache.logging.log4j.Logger; -import org.apache.shiro.subject.Subject; import org.json.JSONArray; import org.apache.geode.cache.CacheFactory; @@ -211,8 +208,6 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti QueryService qs = cache.getQueryService(); - // TODO : Find out if is this optimised use. Can you have something equivalent of parsed - // queries with names where name can be retrieved to avoid parsing every-time Query query = qs.newQuery(queryString); DefaultQuery tracedQuery = (DefaultQuery) query; WrappedIndexTrackingQueryObserver queryObserver = null; @@ -385,7 +380,6 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti if (logger.isDebugEnabled()) { logger.debug("Removed key {} successfully", key); } - // return DataCommandResult.createRemoveResult(key, value, null, null); Object array[] = getJSONForNonPrimitiveObject(value); DataCommandResult result = DataCommandResult.createRemoveResult(key, array[1], null, null, true); @@ -450,8 +444,6 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti "Error in converting JSON " + e.getMessage(), false); } - // TODO determine whether the following conditional logic (assigned to 'doGet') is safer or - // necessary boolean doGet = Boolean.TRUE.equals(loadOnCacheMiss); if (doGet || region.containsKey(keyObject)) { @@ -465,7 +457,6 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti if (logger.isDebugEnabled()) { logger.debug("Get for key {} value {}", key, value); } - // return DataCommandResult.createGetResult(key, value, null, null); Object array[] = getJSONForNonPrimitiveObject(value); if (value != null) { DataCommandResult result = @@ -723,7 +714,6 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti Object value = object.get(key); if (GfJsonObject.isJSONKind(value)) { GfJsonObject jsonVal = new GfJsonObject(value); - // System.out.println("Re-wrote inner object"); try { if (jsonVal.has("type-class")) { object.put(key, jsonVal.get("type-class")); http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java index 7562005..5e97976 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java @@ -350,10 +350,7 @@ public class CliStrings { "Fully qualified class name of a plug-in to be instantiated for receiving before-event notification of changes to the region and its entries. The plug-in may cancel the event. At most, one cache writer can be defined in each member for the region."; public static final String ALTER_REGION__ASYNCEVENTQUEUEID = "async-event-queue-id"; public static final String ALTER_REGION__ASYNCEVENTQUEUEID__HELP = - "IDs of the Async Event Queues that will be used for write-behind operations."; // TODO - - // Abhishek Is - // this - // correct? + "IDs of the Async Event Queues that will be used for write-behind operations."; public static final String ALTER_REGION__GATEWAYSENDERID = "gateway-sender-id"; public static final String ALTER_REGION__GATEWAYSENDERID__HELP = "IDs of the Gateway Senders to which data will be routed."; @@ -527,8 +524,8 @@ public class CliStrings { "This disk store is in use by other process. \"" + CliStrings.COMPACT_DISK_STORE + "\" can be used to compact disk store that is current in use."; public static final String COMPACT_OFFLINE_DISK_STORE__MSG__CANNOT_ACCESS_DISKSTORE_0_FROM_1_CHECK_GFSH_LOGS = - "Can not access disk store \"{0}\" from \"{1}\". Check " - + org.apache.geode.management.internal.cli.shell.Gfsh.GFSH_APP_NAME + " logs for error."; + "Can not access disk store \"{0}\" from \"{1}\". Check " + Gfsh.GFSH_APP_NAME + + " logs for error."; public static final String COMPACT_OFFLINE_DISK_STORE__MSG__ERROR_WHILE_COMPACTING_DISKSTORE_0_WITH_1_REASON_2 = "While compacting disk store={0} {1}. Reason: {2}"; @@ -885,10 +882,7 @@ public class CliStrings { "Fully qualified class name of a plug-in to be instantiated for receiving before-event notification of changes to the region and its entries. The plug-in may cancel the event. At most, one cache writer can be defined in each member for the region."; public static final String CREATE_REGION__ASYNCEVENTQUEUEID = "async-event-queue-id"; public static final String CREATE_REGION__ASYNCEVENTQUEUEID__HELP = - "IDs of the Async Event Queues that will be used for write-behind operations."; // TODO - - // Abhishek Is - // this - // correct? + "IDs of the Async Event Queues that will be used for write-behind operations."; public static final String CREATE_REGION__GATEWAYSENDERID = "gateway-sender-id"; public static final String CREATE_REGION__GATEWAYSENDERID__HELP = "IDs of the Gateway Senders to which data will be routed."; @@ -985,14 +979,7 @@ public class CliStrings { "Could not access class \"{0}\" specified for \"{1}\"."; public static final String CREATE_REGION__MSG__EXPIRATION_ACTION_0_IS_NOT_VALID = "Expiration action \"{0}\" is not valid."; - public static final String CREATE_REGION__MSG__ERROR_ON_MEMBER_0 = "Error on member: {0}. "; // leave - // space - // in - // the - // end - // for - // further - // message + public static final String CREATE_REGION__MSG__ERROR_ON_MEMBER_0 = "Error on member: {0}. "; public static final String CREATE_REGION__MSG__COULD_NOT_RETRIEVE_REGION_ATTRS_FOR_PATH_0_REASON_1 = "Could not retrieve region attributes for given path \"{0}\". Reason: {1}"; public static final String CREATE_REGION__MSG__COULD_NOT_RETRIEVE_REGION_ATTRS_FOR_PATH_0_VERIFY_REGION_EXISTS = @@ -2333,12 +2320,7 @@ public class CliStrings { public static final String START_LOCATOR__PORT__HELP = "Port the Locator will listen on."; public static final String START_LOCATOR__PROPERTIES = "properties-file"; public static final String START_LOCATOR__PROPERTIES__HELP = - "The gemfire.properties file for configuring the Locator's distributed system. The file's path can be absolute or relative to the gfsh working directory (--dir=)."; // TODO:GEODE-1466: - // update - // golden - // file - // to - // geode.properties + "The gemfire.properties file for configuring the Locator's distributed system. The file's path can be absolute or relative to the gfsh working directory (--dir=)."; public static final String START_LOCATOR__SECURITY_PROPERTIES = "security-properties-file"; public static final String START_LOCATOR__SECURITY_PROPERTIES__HELP = "The gfsecurity.properties file for configuring the Locator's security configuration in the distributed system. The file's path can be absolute or relative to gfsh directory (--dir=)."; @@ -2500,12 +2482,7 @@ public class CliStrings { "The total size of off-heap memory specified as off-heap-memory-size=<n>[g|m]. <n> is the size. [g|m] indicates whether the size should be interpreted as gigabytes or megabytes. A non-zero size causes that much memory to be allocated from the operating system and reserved for off-heap use."; public static final String START_SERVER__PROPERTIES = "properties-file"; public static final String START_SERVER__PROPERTIES__HELP = - "The gemfire.properties file for configuring the Cache Server's distributed system. The file's path can be absolute or relative to the gfsh working directory."; // TODO:GEODE-1466: - // update - // golden - // file - // to - // geode.properties + "The gemfire.properties file for configuring the Cache Server's distributed system. The file's path can be absolute or relative to the gfsh working directory."; public static final String START_SERVER__REDIS_PORT = ConfigurationProperties.REDIS_PORT; public static final String START_SERVER__REDIS_PORT__HELP = "Sets the port that the Geode Redis service listens on for Redis clients."; @@ -2515,8 +2492,7 @@ public class CliStrings { "Sets the IP address the Geode Redis service listens on for Redis clients. The default is to bind to the first non-loopback address for this machine."; public static final String START_SERVER__REDIS_PASSWORD = ConfigurationProperties.REDIS_PASSWORD; public static final String START_SERVER__REDIS_PASSWORD__HELP = - "Sets the authentication password for GeodeRedisServer"; // TODO:GEODE-1566: update golden - // file to GeodeRedisServer + "Sets the authentication password for GeodeRedisServer"; public static final String START_SERVER__SECURITY_PROPERTIES = "security-properties-file"; public static final String START_SERVER__SECURITY_PROPERTIES__HELP = "The gfsecurity.properties file for configuring the Server's security configuration in the distributed system. The file's path can be absolute or relative to gfsh directory."; @@ -2536,10 +2512,6 @@ public class CliStrings { public static final String START_SERVER__STATISTIC_ARCHIVE_FILE = STATISTIC_ARCHIVE_FILE; public static final String START_SERVER__STATISTIC_ARCHIVE_FILE__HELP = "The file that statistic samples are written to. An empty string (default) disables statistic archival."; - // public static final String START_SERVER__START_LOCATOR = "start-locator"; - // public static final String START_SERVER__START_LOCATOR__HELP = - // "To start embedded Locator with given endpoints in the format: host[port]. If no endpoints are - // given defaults (localhost[10334]) are assumed."; public static final String START_SERVER__USE_CLUSTER_CONFIGURATION = USE_CLUSTER_CONFIGURATION; public static final String START_SERVER__USE_CLUSTER_CONFIGURATION__HELP = "When set to true, the server requests the configuration from locator's cluster configuration service."; @@ -2569,15 +2541,6 @@ public class CliStrings { public static final String START_SERVER__EVICTION_OFF_HEAP_PERCENTAGE__HELP = "Set the percentage of off-heap memory at or above which the eviction should begin on Regions configured for off-heap and HeapLRU eviction. Changing this value may cause eviction to begin immediately." + " Only one change to this attribute or critical off-heap percentage will be allowed at any given time and its effect will be fully realized before the next change is allowed."; - // cacheServer.setLoadPollInterval(loadPollInterval) - // cacheServer.setLoadProbe(loadProbe); - // cacheServer.setMaxConnections(maxCons); - // cacheServer.setMaximumMessageCount(maxMessageCount); - // cacheServer.setMaximumTimeBetweenPings(maximumTimeBetweenPings); - // cacheServer.setMaxThreads(maxThreads); - // cacheServer.setMessageTimeToLive(messageTimeToLive); - // cacheServer.setSocketBufferSize(socketBufferSize) - // cacheServer.setTcpNoDelay(noDelay) public static final String START_SERVER__HOSTNAME__FOR__CLIENTS = "hostname-for-clients"; public static final String START_SERVER__HOSTNAME__FOR__CLIENTS__HELP = "Sets the ip address or host name that this cache server is to listen on for client connections." @@ -3017,7 +2980,6 @@ public class CliStrings { /*** * Cluster Configuration commands */ - // TODO: Jared - clean up messages public static final String EXPORT_SHARED_CONFIG = "export cluster-configuration"; public static final String EXPORT_SHARED_CONFIG__HELP = "Exports the cluster configuration artifacts as a zip file."; http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java index 42e3f08..fd4ebb7 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandExecutionContext.java @@ -27,10 +27,9 @@ import org.apache.geode.management.internal.cli.shell.Gfsh; */ public class CommandExecutionContext { // ThreadLocal variables that can be uses by commands - private static final ThreadLocal<Map<String, String>> ENV = - new ThreadLocal<Map<String, String>>(); - private static final ThreadLocal<Boolean> FROM_SHELL = new ThreadLocal<Boolean>(); - private static final ThreadLocal<byte[][]> SHELL_BYTES_DATA = new ThreadLocal<byte[][]>(); + private static final ThreadLocal<Map<String, String>> ENV = new ThreadLocal<>(); + private static final ThreadLocal<Boolean> FROM_SHELL = new ThreadLocal<>(); + private static final ThreadLocal<byte[][]> SHELL_BYTES_DATA = new ThreadLocal<>(); private static final WrapperThreadLocal<CommandResponseWriter> WRITER_WRAPPER = new WrapperThreadLocal<CommandResponseWriter>() { @@ -48,10 +47,6 @@ public class CommandExecutionContext { } return propertyValue != null ? propertyValue : defaultValue; } - // Enable when "use region" command is required. See #46110 - // public static String getShellContextPath() { - // return getShellEnvProperty(CliConstants.ENV_APP_CONTEXT_PATH, null); - // } public static int getShellFetchSize() { int fetchSize = Gfsh.DEFAULT_APP_FETCH_SIZE; @@ -75,8 +70,6 @@ public class CommandExecutionContext { } } - // TODO - Abhishek make this protected & move caller code of this method - // from MemberMBeanBridge to MemberCommandService public static void setShellEnv(Map<String, String> env) { ENV.set(env); } @@ -93,8 +86,6 @@ public class CommandExecutionContext { return FROM_SHELL.get() != null && FROM_SHELL.get(); } - // TODO - Abhishek make this protected & move caller code of this method - // from MemberMBeanBridge to MemberCommandService public static void setShellRequest() { FROM_SHELL.set(true); } http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java index 0d1d91b..0bb96cf 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java @@ -14,24 +14,25 @@ */ package org.apache.geode.management.internal.cli.result; -import org.apache.geode.management.cli.Result.Status; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.CliUtil.DeflaterInflaterData; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.json.GfJsonArray; -import org.apache.geode.management.internal.cli.json.GfJsonException; -import org.apache.geode.management.internal.cli.json.GfJsonObject; -import org.apache.geode.management.internal.cli.shell.Gfsh; - import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.sql.Time; import java.text.MessageFormat; import java.util.Base64; import java.util.zip.DataFormatException; +import org.apache.geode.management.cli.Result.Status; +import org.apache.geode.management.internal.cli.CliUtil; +import org.apache.geode.management.internal.cli.CliUtil.DeflaterInflaterData; +import org.apache.geode.management.internal.cli.i18n.CliStrings; +import org.apache.geode.management.internal.cli.json.GfJsonArray; +import org.apache.geode.management.internal.cli.json.GfJsonException; +import org.apache.geode.management.internal.cli.json.GfJsonObject; +import org.apache.geode.management.internal.cli.shell.Gfsh; + /** * * @@ -123,7 +124,7 @@ public abstract class AbstractResultData implements ResultData { } private static String addTimeStampBeforeLastDot(String src) { - String toAdd = String.valueOf(new java.sql.Time(System.currentTimeMillis())); + String toAdd = String.valueOf(new Time(System.currentTimeMillis())); toAdd = "-" + toAdd.replaceAll(":", "_"); int lastIndexOf = src.lastIndexOf("."); @@ -147,11 +148,10 @@ public abstract class AbstractResultData implements ResultData { public ResultData addAsFile(String fileName, byte[] data, int fileType, String message, boolean addTimeStampToName) { - byte[] bytes = data; if (addTimeStampToName) { fileName = addTimeStampBeforeLastDot(fileName); } - return addAsFile(fileName, bytes, fileType, message); + return addAsFile(fileName, data, fileType, message); } private ResultData addAsFile(String fileName, byte[] data, int fileType, String message) { @@ -191,11 +191,8 @@ public abstract class AbstractResultData implements ResultData { throws GfJsonException, DataFormatException, IOException { boolean overwriteAllExisting = false; int length = byteDataArray.size(); - String options = length > 1 ? "(y/N/a)" : "(y/N)"; // TODO - Abhishek Make this consistent - - // with - // AbstractCliAroundInterceptor.readYesNo() - - BYTEARRAY_LOOP: for (int i = 0; i < length; i++) { + String options = length > 1 ? "(y/N/a)" : "(y/N)"; + for (int i = 0; i < length; i++) { GfJsonObject object = byteDataArray.getJSONObject(i); int fileType = object.getInt(FILE_TYPE_FIELD); @@ -205,8 +202,8 @@ public abstract class AbstractResultData implements ResultData { } // build file name - byte[] fileNameBytes = null; - String fileName = null; + byte[] fileNameBytes; + String fileName; GfJsonArray fileNameJsonBytes = object.getJSONArray(FILE_NAME_FIELD); if (fileNameJsonBytes != null) { // if in gfsh fileNameBytes = GfJsonArray.toByteArray(fileNameJsonBytes); @@ -216,8 +213,8 @@ public abstract class AbstractResultData implements ResultData { } // build file message - byte[] fileMessageBytes = null; - String fileMessage = null; + byte[] fileMessageBytes; + String fileMessage; GfJsonArray fileMessageJsonBytes = object.getJSONArray(FILE_MESSAGE); if (fileMessageJsonBytes != null) { // if in gfsh fileMessageBytes = GfJsonArray.toByteArray(fileMessageJsonBytes); @@ -247,7 +244,7 @@ public abstract class AbstractResultData implements ResultData { if (fileToDumpData.exists()) { String fileExistsMessage = CliStrings.format(CliStrings.ABSTRACTRESULTDATA__MSG__FILE_WITH_NAME_0_EXISTS_IN_1, - new Object[] {fileName, fileToDumpData.getParent(), options}); + fileName, fileToDumpData.getParent(), options); if (gfsh != null && !gfsh.isQuietMode() && !overwriteAllExisting) { fileExistsMessage = fileExistsMessage + " Overwrite? " + options + " : "; String interaction = gfsh.interact(fileExistsMessage); @@ -255,7 +252,7 @@ public abstract class AbstractResultData implements ResultData { overwriteAllExisting = true; } else if (!"y".equalsIgnoreCase(interaction.trim())) { // do not save file & continue - continue BYTEARRAY_LOOP; + continue; } } else { throw new IOException(fileExistsMessage); @@ -289,18 +286,14 @@ public abstract class AbstractResultData implements ResultData { fos.flush(); fos.close(); } - // System.out.println("fileMessage :: "+fileMessage); if (fileMessage != null && !fileMessage.isEmpty()) { if (gfsh != null) { - Gfsh.println( - MessageFormat.format(fileMessage, new Object[] {fileToDumpData.getAbsolutePath()})); + Gfsh.println(MessageFormat.format(fileMessage, fileToDumpData.getAbsolutePath())); } } - // System.out.println(new String(uncompressed)); } } - // TODO - Abhishek : prepare common utility for this & ANSI Styling static void handleCondition(String message) throws IOException { Gfsh gfsh = Gfsh.getCurrentInstance(); // null check required in GfshVM too to avoid test issues http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CommandResult.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CommandResult.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CommandResult.java index 00f1fd9..bbb59d0 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CommandResult.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CommandResult.java @@ -38,7 +38,7 @@ import org.apache.geode.management.internal.cli.result.TableBuilder.Table; * * @since GemFire 7.0 */ -// Should this have info about the command String?? + public class CommandResult implements Result { private GfJsonObject gfJsonObject; @@ -57,7 +57,7 @@ public class CommandResult implements Result { this.resultData = resultData; this.gfJsonObject = this.resultData.getGfJsonObject(); this.status = this.resultData.getStatus(); - this.resultLines = new Vector<String>(); + this.resultLines = new Vector<>(); } @Override @@ -78,7 +78,6 @@ public class CommandResult implements Result { index = 0; } - // TODO -Abhishek - extract this code out in a FormatBuilder or PresentationBuilder?? private void buildData() { try { if (ResultData.TYPE_OBJECT.equals(resultData.getType())) { @@ -95,7 +94,6 @@ public class CommandResult implements Result { RowGroup rowGroup = resultTable.newRowGroup(); if (ResultData.TYPE_TABULAR.equals(resultData.getType())) { - // resultTable.setColumnSeparator(" | "); resultTable.setColumnSeparator(" "); resultTable.setTabularResult(true); buildTable(rowGroup, content); @@ -111,7 +109,6 @@ public class CommandResult implements Result { } catch (GfJsonException e) { resultLines .add("Error occurred while processing Command Result. Internal Error - Invalid Result."); - // TODO - Abhishek. Add stack trace when 'debug' is enabled. Log to LogWrapper always } finally { isDataBuilt = true; } @@ -152,7 +149,7 @@ public class CommandResult implements Result { } } - /* private */ void buildObjectResultOutput() { + void buildObjectResultOutput() { try { Table resultTable = TableBuilder.newTable(); resultTable.setColumnSeparator(" : "); @@ -169,12 +166,7 @@ public class CommandResult implements Result { GfJsonObject object = objectsArray.getJSONObject(i); buildObjectSection(resultTable, null, object, 0); } - } /* - * else { // GfJsonObject jsonObject = - * content.getJSONObject(ObjectResultData.ROOT_OBJECT_ACCESSOR); // - * buildObjectSection(resultTable, null, jsonObject, 0); } - */ - + } addFooterInTable(resultTable, getGfJsonObject()); resultLines.addAll(resultTable.buildTableList()); @@ -182,7 +174,6 @@ public class CommandResult implements Result { } catch (GfJsonException e) { resultLines .add("Error occurred while processing Command Result. Internal Error - Invalid Result."); - // TODO - Abhishek. Add stack trace when 'debug' is enabled. Log to LogWrapper always } finally { isDataBuilt = true; } @@ -191,7 +182,7 @@ public class CommandResult implements Result { private void buildObjectSection(Table table, RowGroup parentRowGroup, GfJsonObject object, int depth) throws GfJsonException { Iterator<String> keys = object.keys(); - RowGroup rowGroup = null; + RowGroup rowGroup; if (parentRowGroup != null) { rowGroup = parentRowGroup; } else { @@ -205,8 +196,8 @@ public class CommandResult implements Result { List<String> fieldsToSkipOnUI = null; if (object.has(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI)) { - GfJsonArray jsonArray = object.getJSONArray(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI);; - fieldsToSkipOnUI = new ArrayList<String>(); + GfJsonArray jsonArray = object.getJSONArray(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI); + fieldsToSkipOnUI = new ArrayList<>(); for (int i = 0; i < jsonArray.size(); i++) { fieldsToSkipOnUI.add(String.valueOf(jsonArray.get(i))); } @@ -222,8 +213,8 @@ public class CommandResult implements Result { try { nestedCollection = object.getJSONArray(key); - } catch (GfJsonException e) { - /* next check if it's a nested object */} + } catch (GfJsonException ignored) { + } Object field = null; if (nestedCollection == null) { @@ -240,10 +231,8 @@ public class CommandResult implements Result { Row newRow = rowGroup.newRow(); String prefix = ""; - /* if (nestedCollection != null) */ { - for (int i = 0; i < depth; i++) { - prefix += " . "; - } + for (int i = 0; i < depth; i++) { + prefix += " . "; } String fieldNameToDisplay = fieldDisplayNames.getString(key); @@ -252,22 +241,21 @@ public class CommandResult implements Result { } if (nestedCollection != null) { - Map<String, Integer> columnsMap = new HashMap<String, Integer>(); + Map<String, Integer> columnsMap = new HashMap<>(); - GfJsonArray rowsArray = nestedCollection; RowGroup newRowGroup = table.newRowGroup(); newRowGroup.setColumnSeparator(" | "); newRowGroup.newBlankRow(); newRowGroup.newRow().newLeftCol(fieldNameToDisplay); Row headerRow = newRowGroup.newRow(); - int numOfRows = rowsArray.size(); + int numOfRows = nestedCollection.size(); List<String> tableFieldsToSkipOnUI = null; for (int j = 0; j < numOfRows; j++) { - GfJsonObject content = rowsArray.getJSONObject(j); + GfJsonObject content = nestedCollection.getJSONObject(j); if (content.has(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI)) { GfJsonArray jsonArray = content.getJSONArray(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI); - tableFieldsToSkipOnUI = new ArrayList<String>(); + tableFieldsToSkipOnUI = new ArrayList<>(); for (int i = 0; i < jsonArray.size(); i++) { tableFieldsToSkipOnUI.add(String.valueOf(jsonArray.get(i))); } @@ -284,7 +272,7 @@ public class CommandResult implements Result { if (CliJsonSerializable.FIELDS_TO_SKIP.contains((String) columnName) || (tableFieldsToSkipOnUI != null && tableFieldsToSkipOnUI.contains(columnName))) { - // skip file data if any //TODO - make response format better + // skip file data if any continue; } @@ -299,7 +287,7 @@ public class CommandResult implements Result { Object columnName = columnNames.get(i); if (CliJsonSerializable.FIELDS_TO_SKIP.contains((String) columnName) || (tableFieldsToSkipOnUI != null && tableFieldsToSkipOnUI.contains(columnName))) { - // skip file data if any //TODO - make response format better + // skip file data if any continue; } newRow.newLeftCol(String.valueOf(content.get((String) columnName))); @@ -308,18 +296,7 @@ public class CommandResult implements Result { } else if (nestedObject != null) { buildObjectSection(table, rowGroup, nestedObject, depth + 1); } else { - // Row newRow = rowGroup.newRow(); - // String prefix = ""; - // for (int i = 0; i < depth; i++) { - // prefix += " . "; - // } - // newRow.newLeftCol(prefix+fieldDisplayNames.getString(key)).newLeftCol(field); - Object value = field; - /* - * if (isPrimitiveOrStringOrWrapperArray(value)) { value = Arrays.toString((String[])value); - * } - */ - newRow.newLeftCol(value); + newRow.newLeftCol(field); } nestedCollection = null; nestedObject = null; @@ -375,14 +352,14 @@ public class CommandResult implements Result { GfJsonArray jsonArr = (GfJsonArray) object; try { isPrimitive = isPrimitiveOrStringOrWrapper(jsonArr.get(0)); - } catch (GfJsonException e) { + } catch (GfJsonException ignored) { } } return isPrimitive; } - /* private */ void buildComposite() { + void buildComposite() { try { GfJsonObject content = getContent(); if (content != null) { @@ -418,7 +395,7 @@ public class CommandResult implements Result { private void buildSection(Table table, RowGroup parentRowGroup, GfJsonObject section, int depth) throws GfJsonException { Iterator<String> keys = section.keys(); - RowGroup rowGroup = null; + RowGroup rowGroup; if (parentRowGroup != null) { rowGroup = parentRowGroup; } else { @@ -428,7 +405,6 @@ public class CommandResult implements Result { while (keys.hasNext()) { String key = keys.next(); Object object = section.get(key); - // System.out.println(key +" : " + object); if (key.startsWith(CompositeResultData.TABLE_DATA_ACCESSOR)) { GfJsonObject tableObject = section.getJSONObject(key); @@ -446,7 +422,6 @@ public class CommandResult implements Result { rowGroup.newRowSeparator(separatorString.charAt(0), true); } else if (key.equals(ResultData.RESULT_HEADER) || key.equals(ResultData.RESULT_FOOTER)) { // skip header & footer - continue; } else { Row newRow = rowGroup.newRow(); String prefix = ""; @@ -468,22 +443,14 @@ public class CommandResult implements Result { newRow.newLeftCol(prefix + key).newLeftCol(""); } } - // System.out.println(key+" : "+object); } } addFooterInRowGroup(rowGroup, section); } - // public static void main(String[] args) { - // String[] valuesSeparatedByLines = getValuesSeparatedByLines(CliConstants.LINE_SEPARATOR); - // System.out.println(valuesSeparatedByLines +" -- "+valuesSeparatedByLines.length); - // } - private static String[] getValuesSeparatedByLines(Object object) { - String[] values = null; String valueString = String.valueOf(object); - values = valueString.split(GfshParser.LINE_SEPARATOR); - return values; + return valueString.split(GfshParser.LINE_SEPARATOR); } /** @@ -502,10 +469,10 @@ public class CommandResult implements Result { for (int i = 0; i < numOfColumns; i++) { Object object = columnNames.get(i); if (AbstractResultData.BYTE_DATA_ACCESSOR.equals(object)) { - // skip file data if any //TODO - make response format better + // skip file data if any continue; } - headerRow.newCenterCol((String) object); + headerRow.newCenterCol(object); } // Build remaining rows by extracting data column-wise from JSON object @@ -513,7 +480,7 @@ public class CommandResult implements Result { for (int i = 0; i < numOfColumns; i++) { Object object = columnNames.get(i); if (AbstractResultData.BYTE_DATA_ACCESSOR.equals(object)) { - // skip file data if any //TODO - make response format better + // skip file data if any continue; } GfJsonArray accumulatedData = content.getJSONArray((String) object); @@ -574,13 +541,10 @@ public class CommandResult implements Result { GfJsonArray bytesArray = content.getJSONArray(CompositeResultData.BYTE_DATA_ACCESSOR); AbstractResultData.readFileDataAndDump(bytesArray, directory); } else { - throw new RuntimeException("No associated files to save .. "); // TODO Abhishek - add i18n - // string + throw new RuntimeException("No associated files to save .. "); } numTimesSaved = numTimesSaved + 1; - } catch (DataFormatException e) { - throw new RuntimeException(e); - } catch (GfJsonException e) { + } catch (DataFormatException | GfJsonException e) { throw new RuntimeException(e); } } @@ -621,14 +585,10 @@ public class CommandResult implements Result { return gfJsonObject.getString(ResultData.RESULT_HEADER); } - public GfJsonObject getContent() throws GfJsonException { + public GfJsonObject getContent() { return gfJsonObject.getJSONObject(ResultData.RESULT_CONTENT); } - // public String getContentStr() { - // return gfJsonObject.getString(ResultData.RESULT_CONTENT); - // } - public String getFooter() { return getFooter(gfJsonObject); } http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CompositeResultData.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CompositeResultData.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CompositeResultData.java index 7d0d23b..9d93d3a 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CompositeResultData.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/CompositeResultData.java @@ -30,11 +30,11 @@ public class CompositeResultData extends AbstractResultData { private int subsectionCount; - /* package */ CompositeResultData() { + CompositeResultData() { super(); } - /* package */ CompositeResultData(GfJsonObject gfJsonObject) { + CompositeResultData(GfJsonObject gfJsonObject) { super(gfJsonObject); } @@ -131,13 +131,13 @@ public class CompositeResultData extends AbstractResultData { * * @since GemFire 7.0 */ - public static class SectionResultData /* extends AbstractResultData */ { + public static class SectionResultData { protected GfJsonObject sectionGfJsonObject; private int subsectionCount = 0; private int tablesCount = 0; - /* package */ SectionResultData() { + SectionResultData() { sectionGfJsonObject = new GfJsonObject(); } @@ -295,7 +295,7 @@ public class CompositeResultData extends AbstractResultData { } public String[] retrieveStringArray(String name) { - String[] stringArray = null; + String[] stringArray; Object retrievedObject = sectionGfJsonObject.get(name); if (retrievedObject instanceof GfJsonArray) { @@ -317,11 +317,6 @@ public class CompositeResultData extends AbstractResultData { public static String generateTableKey(String keyToRetrieve) { return TABLE_DATA_ACCESSOR + "-" + keyToRetrieve; } - - // @Override - // public String getType() { - // return TYPE_SECTION; - // } } public static void main(String[] args) { @@ -362,10 +357,8 @@ public class CompositeResultData extends AbstractResultData { .accumulate("NumOfBuckets", 100); try { - System.out.println(crd.getGfJsonObject().toIndentedString(/* 2 */0)); + System.out.println(crd.getGfJsonObject().toIndentedString(0)); - } catch (GfJsonException e) { - e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java index 94dbca0..2518793 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultBuilder.java @@ -14,19 +14,18 @@ */ package org.apache.geode.management.internal.cli.result; +import java.util.Collection; +import java.util.List; + import org.apache.geode.management.cli.Result; import org.apache.geode.management.internal.cli.json.GfJsonException; import org.apache.geode.management.internal.cli.json.GfJsonObject; -import java.util.Collection; -import java.util.List; - /** * Provides methods for creating {@link Result} objects to return from Gfsh command functions */ public class ResultBuilder { public static final int CODE_SHELLCLIENT_ABORT_OP = 110; - // public static final int OKCODE = 200; // error on gfsh public static final int ERRORCODE_DEFAULT = 400; @@ -169,10 +168,6 @@ public class ResultBuilder { return new ObjectResultData<>(); } - // public static CatalogedResultData createCatalogedResultData() { - // return new CatalogedResultData(); - // } - /** * Creates a {@link InfoResultData} object to start building result that is required to be shown * as an information without any specific format. @@ -233,10 +228,7 @@ public class ResultBuilder { AbstractResultData resultData; if (ResultData.TYPE_TABULAR.equals(contentType)) { resultData = new TabularResultData(data); - } /* - * else if (ResultData.TYPE_CATALOGED.equals(contentType)) { resultData = new - * CatalogedResultData(new GfJsonObject(String.valueOf(content))); } - */ else if (ResultData.TYPE_INFO.equals(contentType)) { + } else if (ResultData.TYPE_INFO.equals(contentType)) { resultData = new InfoResultData(data); } else if (ResultData.TYPE_ERROR.equals(contentType)) { resultData = new ErrorResultData(data); @@ -266,7 +258,6 @@ public class ResultBuilder { while (result.hasNextLine()) { builder.append(result.nextLine()); } - // TODO - what to do with incoming files?? } return builder.toString(); http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultData.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultData.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultData.java index 37a1d60..cacbef8 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultData.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/ResultData.java @@ -28,12 +28,10 @@ public interface ResultData { String RESULT_FOOTER = "footer"; - // String TYPE_CATALOGED = "catalog"; String TYPE_COMPOSITE = "composite"; String TYPE_ERROR = "error"; String TYPE_INFO = "info"; String TYPE_OBJECT = "object"; - // String TYPE_SECTION = "composite-section"; String TYPE_TABULAR = "table"; String getHeader(); @@ -44,7 +42,7 @@ public interface ResultData { String getType(); - public Status getStatus(); + Status getStatus(); - public void setStatus(final Status status); + void setStatus(final Status status); } http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/TableBuilder.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/TableBuilder.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/TableBuilder.java index ff23512..55081ed 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/TableBuilder.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/TableBuilder.java @@ -53,12 +53,14 @@ package org.apache.geode.management.internal.cli.result; * * @since GemFire 7.0 */ -import org.apache.commons.lang.StringUtils; -import org.apache.geode.management.internal.cli.GfshParser; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang.StringUtils; + +import org.apache.geode.management.internal.cli.GfshParser; + public class TableBuilder { public static Table newTable() { @@ -351,7 +353,6 @@ public class TableBuilder { int maxNumCols = this.rowGroup.getNumCols(); for (int i = 0; i < maxNumCols; i++) { - // int maxColLength = this.rowGroup.getMaxColLength(i); int maxColLength = this.rowGroup.getColSize(i); for (int j = 0; j < maxColLength; j++) { stringBuffer.append(this.rowSeparator); @@ -382,7 +383,7 @@ public class TableBuilder { } } - private static enum Align { + private enum Align { LEFT, RIGHT, CENTER } http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java index 503c252..2d55f42 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/Gfsh.java @@ -56,6 +56,7 @@ import org.apache.geode.management.internal.cli.CliUtil; import org.apache.geode.management.internal.cli.CommandManager; import org.apache.geode.management.internal.cli.GfshParser; import org.apache.geode.management.internal.cli.LogWrapper; +import org.apache.geode.management.internal.cli.converters.RegionPathConverter; import org.apache.geode.management.internal.cli.i18n.CliStrings; import org.apache.geode.management.internal.cli.result.CommandResult; import org.apache.geode.management.internal.cli.result.CompositeResultData; @@ -80,7 +81,7 @@ import org.apache.geode.management.internal.cli.util.CommentSkipHelper; * </ul> * <p /> * Additionally, this class is used to maintain GemFire SHell (gfsh) specific information like: - * environment TODO + * environment * * * @since GemFire 7.0 @@ -121,7 +122,6 @@ public class Gfsh extends JLineShell { public static final String ENV_SYS_OS_LINE_SEPARATOR = "SYS_OS_LINE_SEPARATOR"; public static final String ENV_SYS_GEODE_HOME_DIR = "SYS_GEODE_HOME_DIR"; - // TODO merge find a better place for these // SSL Configuration properties. keystore/truststore type is not include public static final String SSL_KEYSTORE = "javax.net.ssl.keyStore"; public static final String SSL_KEYSTORE_PASSWORD = "javax.net.ssl.keyStorePassword"; @@ -133,19 +133,18 @@ public class Gfsh extends JLineShell { private static final int DEFAULT_HEIGHT = 100; private static final Object INSTANCE_LOCK = new Object(); - // private static final String ANIMATION_SLOT = "A"; //see 46072 protected static PrintStream gfshout = System.out; protected static PrintStream gfsherr = System.err; - protected static ThreadLocal<Gfsh> gfshThreadLocal = new ThreadLocal<Gfsh>(); + protected static ThreadLocal<Gfsh> gfshThreadLocal = new ThreadLocal<>(); private static Gfsh instance; // This flag is used to restrict column trimming to table only types - private static ThreadLocal<Boolean> resultTypeTL = new ThreadLocal<Boolean>(); + private static ThreadLocal<Boolean> resultTypeTL = new ThreadLocal<>(); private static String OS = System.getProperty("os.name").toLowerCase(); - private final Map<String, String> env = new TreeMap<String, String>(); - private final List<String> readonlyAppEnv = new ArrayList<String>(); + private final Map<String, String> env = new TreeMap<>(); + private final List<String> readonlyAppEnv = new ArrayList<>(); // Map to keep reference to actual user specified Command String // Should always have one value at the max - private final Map<String, String> expandedPropCommandsMap = new HashMap<String, String>(); + private final Map<String, String> expandedPropCommandsMap = new HashMap<>(); private final ExecutionStrategy executionStrategy; private final GfshParser parser; private final LogWrapper gfshFileLogger; @@ -158,11 +157,11 @@ public class Gfsh extends JLineShell { private Thread runner; private boolean debugON; private Terminal terminal; - private boolean supressScriptCmdOutput; + private boolean suppressScriptCmdOutput; private boolean isScriptRunning; private AbstractSignalNotificationHandler signalHandler; - protected Gfsh() throws ClassNotFoundException, IOException { + protected Gfsh() { this(null); } @@ -173,7 +172,7 @@ public class Gfsh extends JLineShell { * @throws IOException * @throws ClassNotFoundException */ - protected Gfsh(String[] args) throws ClassNotFoundException, IOException { + protected Gfsh(String[] args) { this(true, args, new GfshConfig()); } @@ -186,8 +185,7 @@ public class Gfsh extends JLineShell { * @throws IOException * @throws ClassNotFoundException */ - protected Gfsh(boolean launchShell, String[] args, GfshConfig gfshConfig) - throws ClassNotFoundException, IOException { + protected Gfsh(boolean launchShell, String[] args, GfshConfig gfshConfig) { // 1. Disable suppressing of duplicate messages JLineLogHandler.setSuppressDuplicateMessages(false); @@ -195,11 +193,7 @@ public class Gfsh extends JLineShell { this.gfshConfig = gfshConfig; this.gfshFileLogger = LogWrapper.getInstance(); this.gfshFileLogger.configure(this.gfshConfig); - this.ansiHandler = ANSIHandler.getInstance(this.gfshConfig.isANSISupported()); // TODO - - // Abhishek : - // should take it - // from - // ConsoleReader.terminal?? + this.ansiHandler = ANSIHandler.getInstance(this.gfshConfig.isANSISupported()); /* 3. log system properties & gfsh environment */ this.gfshFileLogger.info(Banner.getString(args)); @@ -255,8 +249,7 @@ public class Gfsh extends JLineShell { } } - public static Gfsh getInstance(boolean launchShell, String[] args, GfshConfig gfshConfig) - throws ClassNotFoundException, IOException { + public static Gfsh getInstance(boolean launchShell, String[] args, GfshConfig gfshConfig) { if (instance == null) { synchronized (INSTANCE_LOCK) { if (instance == null) { @@ -295,7 +288,7 @@ public class Gfsh extends JLineShell { // See 46369 private static String readLine(ConsoleReader reader, String prompt) throws IOException { String earlierLine = reader.getCursorBuffer().toString(); - String readLine = null; + String readLine; try { readLine = reader.readLine(prompt); } catch (IndexOutOfBoundsException e) { @@ -327,7 +320,6 @@ public class Gfsh extends JLineShell { while (loggerNames.hasMoreElements()) { String loggerName = loggerNames.nextElement(); if (loggerName.startsWith("java.") || loggerName.startsWith("javax.")) { - // System.out.println(loggerName); Logger javaLogger = logManager.getLogger(loggerName); /* * From Java Docs: It is also important to note that the Logger associated with the String @@ -423,7 +415,7 @@ public class Gfsh extends JLineShell { } else { final int spaceCharIndex = string.lastIndexOf(" ", index); - // If no spaces were found then there's no logical wayto split the string + // If no spaces were found then there's no logical way to split the string if (spaceCharIndex == -1) { stringBuf.append(string.substring(startOfCurrentLine, index)).append(LINE_SEPARATOR); @@ -453,7 +445,7 @@ public class Gfsh extends JLineShell { env.put(ENV_SYS_OS_LINE_SEPARATOR, System.getProperty("line.separator")); env.put(ENV_SYS_GEODE_HOME_DIR, System.getenv("GEODE_HOME")); - env.put(ENV_APP_NAME, org.apache.geode.management.internal.cli.shell.Gfsh.GFSH_APP_NAME); + env.put(ENV_APP_NAME, Gfsh.GFSH_APP_NAME); readonlyAppEnv.add(ENV_APP_NAME); env.put(ENV_APP_LOGGING_ENABLED, String.valueOf(!Level.OFF.equals(this.gfshConfig.getLogLevel()))); @@ -506,7 +498,6 @@ public class Gfsh extends JLineShell { * Stops this GemFire Shell. */ public void stop() { - // flashMessage("\b"); // see 46072 closeShell(); LogWrapper.close(); if (operationInvoker != null && operationInvoker.isConnected()) { @@ -544,7 +535,6 @@ public class Gfsh extends JLineShell { * See findResources in {@link AbstractShell} */ protected Collection<URL> findResources(String resourceName) { - // return Collections.singleton(ClassPathLoader.getLatest().getResource(resourceName)); return null; } @@ -604,8 +594,6 @@ public class Gfsh extends JLineShell { } success = super.executeScriptLine(withPropsExpanded); } catch (Exception e) { - // TODO: should there be a way to differentiate error in shell & error on - // server. May be by exception type. setLastExecutionStatus(-1); } finally { // Add all commands to in-memory GfshHistory gfshHistory.setAutoFlush(true); @@ -700,7 +688,7 @@ public class Gfsh extends JLineShell { while (commandResult.hasNextLine()) { write(commandResult.nextLine(), isError); } - } else if (!supressScriptCmdOutput) { + } else if (!suppressScriptCmdOutput) { // Command is part of script. Show output only when quite=false while (commandResult.hasNextLine()) { write(commandResult.nextLine(), isError); @@ -742,7 +730,7 @@ public class Gfsh extends JLineShell { } private boolean isUnix() { - return !(OS.indexOf("win") >= 0); + return !(OS.contains("win")); } private void write(String message, boolean isError) { @@ -885,7 +873,7 @@ public class Gfsh extends JLineShell { } public Result executeScript(File scriptFile, boolean quiet, boolean continueOnError) { - Result result = null; + Result result; String initialIsQuiet = getEnvProperty(ENV_APP_QUIET_EXECUTION); try { this.isScriptRunning = true; @@ -900,12 +888,11 @@ public class Gfsh extends JLineShell { ScriptExecutionDetails scriptInfo = new ScriptExecutionDetails(scriptFile.getPath()); if (scriptFile.exists()) { setEnvProperty(ENV_APP_QUIET_EXECUTION, String.valueOf(quiet)); - this.supressScriptCmdOutput = quiet; + this.suppressScriptCmdOutput = quiet; BufferedReader reader = new BufferedReader(new FileReader(scriptFile)); String lineRead = ""; StringBuilder linesBuffer = new StringBuilder(); - String linesBufferString = ""; // used to check whether the string in a buffer contains a - // ";". + String linesBufferString = ""; int commandSrNum = 0; CommentSkipHelper commentSkipper = new CommentSkipHelper(); @@ -925,7 +912,6 @@ public class Gfsh extends JLineShell { linesBufferString = linesBuffer.toString(); // NOTE: Similar code is in promptLoop() if (!linesBufferString.endsWith(GfshParser.CONTINUATION_CHARACTER)) { // see 45893 - // String command = null; List<String> commandList = MultiCommandHelper.getMultipleCommands(linesBufferString); for (String cmdLet : commandList) { @@ -995,18 +981,11 @@ public class Gfsh extends JLineShell { } public Map<String, String> getEnv() { - Map<String, String> map = new TreeMap<String, String>(); + Map<String, String> map = new TreeMap<>(); map.putAll(env); return map; } - @Override - public void setPromptPath(String currentContext) { - super.setPromptPath(currentContext); - // Enable when "use region" command is required. See #46110 - // env.put(CliConstants.ENV_APP_CONTEXT_PATH, currentContext); - } - public boolean isQuietMode() { return Boolean.parseBoolean(env.get(ENV_APP_QUIET_EXECUTION)); } @@ -1100,7 +1079,7 @@ public class Gfsh extends JLineShell { @Override protected String getPromptText() { String defaultPrompt = gfshConfig.getDefaultPrompt(); - String contextPath = /* getEnvProperty(CliConstants.ENV_APP_CONTEXT_PATH) */ ""; + String contextPath = ""; String clusterString = ""; if (getOperationInvoker() != null && isConnectedAndReady()) { @@ -1108,14 +1087,6 @@ public class Gfsh extends JLineShell { if (clusterId != OperationInvoker.CLUSTER_ID_WHEN_NOT_CONNECTED) { clusterString = "Cluster-" + clusterId + " "; } - // //As "use region" is not in scope for 7.0, see 46110. - // if (contextPath == null) { - // contextPath = "." + CliConstants.DEFAULT_APP_CONTEXT_PATH; - // } else { - // contextPath = "." + contextPath; - // } - // } else { - // contextPath = "." + CliConstants.DEFAULT_APP_CONTEXT_PATH; } defaultPrompt = MessageFormat.format(defaultPrompt, clusterString, contextPath); @@ -1130,8 +1101,7 @@ public class Gfsh extends JLineShell { if (gfshFileLogger.severeEnabled()) { gfshFileLogger.severe(message); } - setPromptPath( - org.apache.geode.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH); + setPromptPath(RegionPathConverter.DEFAULT_APP_CONTEXT_PATH); } public boolean getDebug() { @@ -1153,7 +1123,7 @@ public class Gfsh extends JLineShell { private String expandProperties(final String input) { String output = input; Scanner s = new Scanner(output); - String foundInLine = null; + String foundInLine; while ((foundInLine = s.findInLine("(\\$[\\{]\\w+[\\}])")) != null) { String envProperty = getEnvProperty(extractKey(foundInLine)); envProperty = envProperty != null ? envProperty : ""; @@ -1170,7 +1140,7 @@ class ScriptExecutionDetails { ScriptExecutionDetails(String filePath) { this.filePath = filePath; - this.commandAndStatusList = new ArrayList<CommandAndStatus>(); + this.commandAndStatusList = new ArrayList<>(); } void addCommandAndStatus(String command, String status) { @@ -1190,7 +1160,7 @@ class ScriptExecutionDetails { section.addData("Command-" + String.valueOf(commandSrNo), commandAndStatus.command); section.addData("Status", commandAndStatus.status); if (commandAndStatus.status.equals("FAILED")) { - compositeResultData.setStatus(org.apache.geode.management.cli.Result.Status.ERROR); + compositeResultData.setStatus(Result.Status.ERROR); } if (i != this.commandAndStatusList.size()) { section.setFooter(Gfsh.LINE_SEPARATOR); http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java index 6794b3b..735143f 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/GfshExecutionStrategy.java @@ -131,14 +131,6 @@ public class GfshExecutionStrategy implements ExecutionStrategy { return cliMetadata != null ? cliMetadata.interceptor() : CliMetaData.ANNOTATION_NULL_VALUE; } - // Not used currently - // private static String getCommandName(ParseResult result) { - // Method method = result.getMethod(); - // CliCommand cliCommand = method.getAnnotation(CliCommand.class); - // - // return cliCommand != null ? cliCommand.value() [0] : null; - // } - /** * Indicates commands are able to be presented. This generally means all important system startup * activities have completed. Copied from {@link ExecutionStrategy#isReadyForCommands()}. @@ -157,7 +149,6 @@ public class GfshExecutionStrategy implements ExecutionStrategy { */ @Override public void terminate() { - // TODO: Is additional cleanup required? shell = null; } //////////////// ExecutionStrategy interface Methods End ///////////////////// @@ -247,8 +238,6 @@ public class GfshExecutionStrategy implements ExecutionStrategy { String debugInfo = commandResponse.getDebugInfo(); if (StringUtils.isNotBlank(debugInfo)) { - // TODO - Abhishek When debug is ON, log response in gfsh logs - // TODO - Abhishek handle \n better. Is it coming from GemFire formatter debugInfo = debugInfo.replaceAll("\n\n\n", "\n"); debugInfo = debugInfo.replaceAll("\n\n", "\n"); debugInfo = http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java index 5066496..d2407b3 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/JmxOperationInvoker.java @@ -18,7 +18,6 @@ import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_SSL_P import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_SSL_PREFIX; import java.io.IOException; -import java.net.MalformedURLException; import java.text.MessageFormat; import java.util.Arrays; import java.util.HashMap; @@ -88,21 +87,21 @@ public class JmxOperationInvoker implements OperationInvoker { private ObjectName managerMemberObjectName; - /* package */ final AtomicBoolean isConnected = new AtomicBoolean(false); - /* package */ final AtomicBoolean isSelfDisconnect = new AtomicBoolean(false); + final AtomicBoolean isConnected = new AtomicBoolean(false); + final AtomicBoolean isSelfDisconnect = new AtomicBoolean(false); private int clusterId = CLUSTER_ID_WHEN_NOT_CONNECTED; public JmxOperationInvoker(final String host, final int port, Properties gfProperties) throws Exception { - final Set<String> propsToClear = new TreeSet<String>(); + final Set<String> propsToClear = new TreeSet<>(); try { this.managerHost = host; this.managerPort = port; this.endpoints = host + "[" + port + "]"; // Use the same syntax as the "connect" command. // Modify check period from default (60 sec) to 1 sec - final Map<String, Object> env = new HashMap<String, Object>(); + final Map<String, Object> env = new HashMap<>(); env.put(JMXConnectionListener.CHECK_PERIOD_PROP, JMXConnectionListener.CHECK_PERIOD); env.put(JMXConnector.CREDENTIALS, gfProperties); @@ -169,12 +168,6 @@ public class JmxOperationInvoker implements OperationInvoker { this.isConnected.set(true); this.clusterId = distributedSystemMXBeanProxy.getDistributedSystemId(); - } catch (NullPointerException e) { - throw e; - } catch (MalformedURLException e) { - throw e; - } catch (IOException e) { - throw e; } finally { for (String propToClear : propsToClear) { System.clearProperty(propToClear); @@ -215,7 +208,7 @@ public class JmxOperationInvoker implements OperationInvoker { throw new JMXInvocationException(attributeName + " not found for " + resourceName, e); } catch (InstanceNotFoundException e) { throw new JMXInvocationException(resourceName + " is not registered in the MBean server.", e); - } catch (MalformedObjectNameException e) { + } catch (MalformedObjectNameException | IOException e) { throw new JMXInvocationException(resourceName + " is not a valid resource name.", e); } catch (MBeanException e) { throw new JMXInvocationException( @@ -225,8 +218,6 @@ public class JmxOperationInvoker implements OperationInvoker { e); } catch (NullPointerException e) { throw new JMXInvocationException("Given resourceName is null.", e); - } catch (IOException e) { - throw new JMXInvocationException(resourceName + " is not a valid resource name.", e); } } @@ -283,8 +274,6 @@ public class JmxOperationInvoker implements OperationInvoker { @Override public Object processCommand(final CommandRequest commandRequest) throws JMXInvocationException { - // Gfsh.getCurrentInstance().printAsSevere(String.format("Command (%1$s)%n", - // commandRequest.getInput())); if (commandRequest.hasFileData()) { return memberMXBeanProxy.processCommand(commandRequest.getInput(), commandRequest.getEnvironment(), ArrayUtils.toByteArray(commandRequest.getFileData())); @@ -365,7 +354,7 @@ public class JmxOperationInvoker implements OperationInvoker { return this.clusterId; } - /* package */ void resetClusterId() { + void resetClusterId() { clusterId = CLUSTER_ID_WHEN_NOT_CONNECTED; } @@ -378,12 +367,10 @@ public class JmxOperationInvoker implements OperationInvoker { * * @return for an IPv6 address returns compatible host address otherwise returns the same string */ - // TODO - Abhishek: move to utility class - // Taken from GFMon public static String checkAndConvertToCompatibleIPv6Syntax(String hostAddress) { // if host string contains ":", considering it as an IPv6 Address // Conforming to RFC2732 - http://www.ietf.org/rfc/rfc2732.txt - if (hostAddress.indexOf(":") != -1) { + if (hostAddress.contains(":")) { LogWrapper logger = LogWrapper.getInstance(); if (logger.fineEnabled()) { logger.fine("IPv6 host address detected, using IPv6 syntax for host in JMX connection URL"); http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java index 5d9e31b..641c4d9 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java @@ -18,12 +18,12 @@ import java.util.Collections; import java.util.Hashtable; import java.util.Map; +import sun.misc.SignalHandler; + import org.apache.geode.internal.process.signal.AbstractSignalNotificationHandler; import org.apache.geode.internal.process.signal.Signal; import org.apache.geode.internal.process.signal.SignalEvent; -import sun.misc.SignalHandler; - /** * This class externalizes signal handling in order to make the GemFire build process a bit cleaner * - for example we have to have exceptions for sun.misc classes when building javadocs. @@ -42,13 +42,6 @@ public class GfshSignalHandler extends AbstractSignalNotificationHandler impleme public GfshSignalHandler() { for (final Signal signal : Signal.values()) { - // NOTE SignalHandler registration for SIGQUIT led to an IllegalArgumentException without the - // following - // "if" statement... - // Exception in thread "main" java.lang.IllegalArgumentException: Signal already used by VM: - // SIGQUIT - // if (!Signal.SIGQUIT.equals(signal)) { - // TODO uncomment above if statement if all Signals need to be handled by this SignalHandler if (Signal.SIGINT.equals(signal)) { originalSignalHandlers.put(signal, sun.misc.Signal.handle(new sun.misc.Signal(signal.getName()), this)); @@ -58,8 +51,6 @@ public class GfshSignalHandler extends AbstractSignalNotificationHandler impleme @Override public void handle(final sun.misc.Signal sig) { - // System.err.printf("Thread (%1$s) is processing Signal '%2$s' (%3$d)...%n", - // Thread.currentThread().getName(), sig.getName(), sig.getNumber()); notifyListeners(new SignalEvent(sig, Signal.valueOfName(sig.getName()))); handleDefault(sig); } http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ReadWriteFile.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ReadWriteFile.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ReadWriteFile.java index 8adac15..c9d05b0 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ReadWriteFile.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ReadWriteFile.java @@ -14,15 +14,9 @@ */ package org.apache.geode.management.internal.cli.util; -import org.apache.geode.cache.execute.FunctionException; -import org.apache.geode.internal.logging.LogWriterImpl; -import org.apache.geode.internal.logging.log4j.LogLevel; -import org.apache.geode.management.internal.cli.GfshParser; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -32,6 +26,11 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.apache.geode.cache.execute.FunctionException; +import org.apache.geode.internal.logging.LogWriterImpl; +import org.apache.geode.internal.logging.log4j.LogLevel; +import org.apache.geode.management.internal.cli.GfshParser; + /** * * @@ -55,50 +54,38 @@ public class ReadWriteFile { String onlyLogLevel, String startTime, String endTime) { try { long lineCount = 0; - BufferedReader input = null; - BufferedWriter output = null; + BufferedReader input; + BufferedWriter output; File logFileNameFile = new File(logFileName); - if (logFileNameFile.canRead() == false) { + if (!logFileNameFile.canRead()) { return ("Cannot read logFileName=" + logFileName); } input = new BufferedReader(new FileReader(logFileName)); - String line = null; + String line; File logToBeWrittenToFile = new File(logToBeWritten); output = new BufferedWriter(new FileWriter(logToBeWrittenToFile)); if (!logToBeWrittenToFile.exists()) { - if (input != null) { - input.close(); - } - if (output != null) { - output.flush(); - output.close(); - } - return (logToBeWritten + " doesn not exist"); + input.close(); + output.flush(); + output.close(); + return (logToBeWritten + " does not exist"); } if (!logToBeWrittenToFile.isFile()) { - if (input != null) { - input.close(); - } - if (output != null) { - output.flush(); - output.close(); - } + input.close(); + output.flush(); + output.close(); return (logToBeWritten + " is not a file"); } if (!logToBeWrittenToFile.canWrite()) { - if (input != null) { - input.close(); - } - if (output != null) { - output.flush(); - output.close(); - } + input.close(); + output.flush(); + output.close(); return ("can not write file " + logToBeWritten); } // build possible log levels based on user input // get all the levels below the one mentioned by user - List<String> logLevels = new ArrayList<String>(); + List<String> logLevels = new ArrayList<>(); if (onlyLogLevel.toLowerCase().equals("false")) { int[] intLogLevels = LogWriterImpl.allLevels; for (int level : intLogLevels) { @@ -112,18 +99,13 @@ public class ReadWriteFile { boolean timeRangeCheck = false; boolean foundLogLevelTag = false; boolean validateLogLevel = true; - while (input.ready() == true && (line = input.readLine()) != null) { - if (new File(logFileName).canRead() == false) { + while (input.ready() && (line = input.readLine()) != null) { + if (!new File(logFileName).canRead()) { return ("Cannot read logFileName=" + logFileName); } - // boolean validateLogLevel = true; lineCount++; - if (line.startsWith("[")) { - foundLogLevelTag = true; - } else { - foundLogLevelTag = false; - } - if (line.contains("[info ") && timeRangeCheck == false) { + foundLogLevelTag = line.startsWith("["); + if (line.contains("[info ") && !timeRangeCheck) { String stTime = ""; int spaceCounter = 0; for (int i = line.indexOf("[info ") + 6; i < line.length(); i++) { @@ -152,12 +134,12 @@ public class ReadWriteFile { // set this so that no need to check time range for each line timeRangeCheck = true; } else { - // dont take this log file as this does not fit in time range + // don't take this log file as this does not fit in time range break; } } - if (foundLogLevelTag == true) { + if (foundLogLevelTag) { validateLogLevel = checkLogLevel(line, logLevel, logLevels, foundLogLevelTag); } @@ -178,11 +160,9 @@ public class ReadWriteFile { output.flush(); output.close(); } - return ("Sucessfully written file " + logFileName); + return ("Successfully written file " + logFileName); } catch (FunctionException ex) { return ("readWriteFile FunctionException " + ex.getMessage()); - } catch (FileNotFoundException ex) { - return ("readWriteFile FileNotFoundException " + ex.getMessage()); } catch (IOException ex) { return ("readWriteFile FileNotFoundException " + ex.getMessage()); } catch (Exception ex) { @@ -194,7 +174,7 @@ public class ReadWriteFile { boolean foundLogLevelTag) { if (line == null) { return false; - } else if (line != null && foundLogLevelTag == true) { + } else if (foundLogLevelTag) { if (logLevel.toLowerCase().equals("all")) { return true; } else if (line.equals(GfshParser.LINE_SEPARATOR)) { @@ -207,7 +187,7 @@ public class ReadWriteFile { if (indexFrom > -1 && indexTo > -1 && indexTo > indexFrom) { boolean flag = line.substring(indexFrom + 1, indexTo).toLowerCase().contains(permittedLogLevel); - if (flag == true) { + if (flag) { return flag; } } http://git-wip-us.apache.org/repos/asf/geode/blob/fb9a405f/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/CacheElement.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/CacheElement.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/CacheElement.java index 7450757..97f48a5 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/CacheElement.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/CacheElement.java @@ -14,9 +14,9 @@ */ package org.apache.geode.management.internal.configuration.domain; +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; import static org.apache.geode.management.internal.configuration.utils.XmlConstants.W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION; import static org.apache.geode.management.internal.configuration.utils.XmlUtils.getAttribute; -import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; import java.io.IOException; import java.net.URL; @@ -111,8 +111,7 @@ public class CacheElement { XmlUtils.buildSchemaLocationMap(getAttribute(doc.getFirstChild(), W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, W3C_XML_SCHEMA_INSTANCE_NS_URI)); - final LinkedHashMap<String, CacheElement> elementMap = - new LinkedHashMap<String, CacheElement>(); + final LinkedHashMap<String, CacheElement> elementMap = new LinkedHashMap<>(); buildElementMapCacheType(elementMap, resolveSchema(schemaLocationMap, CacheXml.GEODE_NAMESPACE)); @@ -210,10 +209,6 @@ public class CacheElement { final String name = getAttribute(child, "name"); elementMap.put(name, new CacheElement(name, rank++, isMultiple(child))); break; - // TODO group support as XSD matures - // case "xsd:group": - // buildElementMapGroup(elementMap, doc, child, rank, xPathContext); - // break; case "xsd:choice": case "xsd:sequence": rank = buildElementMapXPath(elementMap, schema, child, rank, @@ -223,7 +218,6 @@ public class CacheElement { // ignore extensions break; default: - // TODO jbarrett - localize throw new UnsupportedOperationException( "Unsupported child type '" + child.getNodeName() + "'"); } @@ -236,16 +230,12 @@ public class CacheElement { * Tests if element allows multiple. * * @param element to test for multiple. - * @return true if mulitple allowed, otherwise false. + * @return true if multiple allowed, otherwise false. * @since GemFire 8.1 */ private static boolean isMultiple(final Element element) { - final String maxOccurs = getAttribute(element, "maxOccurs"); - if (null != maxOccurs && !maxOccurs.equals("1")) { - // is "unbounded" or greater than 1 if valid schema. - return true; - } - return false; + String maxOccurs = getAttribute(element, "maxOccurs"); + return null != maxOccurs && !maxOccurs.equals("1"); } }
