http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java index c45da73..28edbf6 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/DistributedSystemMBean.java @@ -14,6 +14,12 @@ */ package org.apache.geode.management.internal.beans; +import java.util.Map; + +import javax.management.NotificationBroadcasterSupport; +import javax.management.ObjectName; + +import org.apache.geode.internal.security.SecurityServiceFactory; import org.apache.geode.management.DiskBackupStatus; import org.apache.geode.management.DiskMetrics; import org.apache.geode.management.DistributedSystemMXBean; @@ -22,10 +28,9 @@ import org.apache.geode.management.JVMMetrics; import org.apache.geode.management.NetworkMetrics; import org.apache.geode.management.OSMetrics; import org.apache.geode.management.PersistentMemberDetails; - -import java.util.Map; -import javax.management.NotificationBroadcasterSupport; -import javax.management.ObjectName; +import org.apache.geode.security.ResourcePermission.Operation; +import org.apache.geode.security.ResourcePermission.Resource; +import org.apache.geode.security.ResourcePermission.Target; /** * Distributed System MBean @@ -48,8 +53,9 @@ public class DistributedSystemMBean extends NotificationBroadcasterSupport @Override public DiskBackupStatus backupAllMembers(String targetDirPath, String baselineDirPath) throws Exception { + SecurityServiceFactory.findSecurityService().authorize(Resource.CLUSTER, Operation.WRITE, + Target.DISK); return bridge.backupAllMembers(targetDirPath, baselineDirPath); - } @Override @@ -60,7 +66,6 @@ public class DistributedSystemMBean extends NotificationBroadcasterSupport @Override public String[] listCacheServers() { return bridge.listCacheServers(); - } @@ -243,7 +248,7 @@ public class DistributedSystemMBean extends NotificationBroadcasterSupport } @Override - public boolean revokeMissingDiskStores(final String diskStoreId) throws Exception { + public boolean revokeMissingDiskStores(final String diskStoreId) { return bridge.revokeMissingDiskStores(diskStoreId); } @@ -433,6 +438,6 @@ public class DistributedSystemMBean extends NotificationBroadcasterSupport @Override public void setQueryCollectionsDepth(int queryCollectionsDepth) { - bridge.setQueryCollectionsDepth(queryCollectionsDepth);; + bridge.setQueryCollectionsDepth(queryCollectionsDepth); } }
http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java index 9d717d0..271dce1 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBean.java @@ -148,7 +148,12 @@ public class MemberMBean extends NotificationBroadcasterSupport implements Membe @Override public int getInitialImagesInProgres() { - return bridge.getInitialImagesInProgres(); + return getInitialImagesInProgress(); + } + + @Override + public int getInitialImagesInProgress() { + return bridge.getInitialImagesInProgress(); } http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java index 516b97d..dd905eb 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/MemberMBeanBridge.java @@ -14,7 +14,7 @@ */ package org.apache.geode.management.internal.beans; -import static org.apache.geode.internal.lang.SystemUtils.*; +import static org.apache.geode.internal.lang.SystemUtils.getLineSeparator; import java.io.File; import java.io.IOException; @@ -1341,7 +1341,7 @@ public class MemberMBeanBridge { return getMemberLevelStatistic(StatsKey.GET_INITIAL_IMAGE_TIME).longValue(); } - public int getInitialImagesInProgres() { + public int getInitialImagesInProgress() { return getMemberLevelStatistic(StatsKey.GET_INITIAL_IMAGES_INPROGRESS).intValue(); } http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java index fe27b60..dac12fa 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClientCommands.java @@ -14,7 +14,19 @@ */ package org.apache.geode.management.internal.cli.commands; -import org.apache.geode.cache.CacheFactory; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.management.ObjectName; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.cache.execute.FunctionService; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.internal.cache.InternalCache; @@ -25,30 +37,16 @@ import org.apache.geode.management.cli.CliMetaData; import org.apache.geode.management.cli.Result; import org.apache.geode.management.internal.cli.CliUtil; import org.apache.geode.management.internal.cli.LogWrapper; -import org.apache.geode.management.internal.cli.functions.ContunuousQueryFunction; -import org.apache.geode.management.internal.cli.functions.ContunuousQueryFunction.ClientInfo; +import org.apache.geode.management.internal.cli.functions.ContinuousQueryFunction; +import org.apache.geode.management.internal.cli.functions.ContinuousQueryFunction.ClientInfo; import org.apache.geode.management.internal.cli.i18n.CliStrings; import org.apache.geode.management.internal.cli.result.CompositeResultData; import org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData; import org.apache.geode.management.internal.cli.result.ResultBuilder; import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.cli.shell.Gfsh; import org.apache.geode.management.internal.security.ResourceOperation; import org.apache.geode.security.ResourcePermission.Operation; import org.apache.geode.security.ResourcePermission.Resource; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import javax.management.ObjectName; /** * @since GemFire 8.0 @@ -59,7 +57,7 @@ public class ClientCommands implements GfshCommand { @CliMetaData(relatedTopic = {CliStrings.TOPIC_CLIENT}) @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) public Result listClient() { - Result result = null; + Result result; try { CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData(); @@ -78,7 +76,7 @@ public class ClientCommands implements GfshCommand { CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST)); } - Map<String, List<String>> clientServerMap = new HashMap<String, List<String>>(); + Map<String, List<String>> clientServerMap = new HashMap<>(); for (ObjectName objName : cacheServers) { CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class); @@ -89,16 +87,16 @@ public class ClientCommands implements GfshCommand { } - for (String clietName : listOfClient) { + for (String clientName : listOfClient) { String serverDetails = "member=" + objName.getKeyProperty("member") + ",port=" + objName.getKeyProperty("port"); - if (clientServerMap.containsKey(clietName)) { - List<String> listServers = clientServerMap.get(clietName); + if (clientServerMap.containsKey(clientName)) { + List<String> listServers = clientServerMap.get(clientName); listServers.add(serverDetails); } else { - List<String> listServer = new ArrayList<String>(); + List<String> listServer = new ArrayList<>(); listServer.add(serverDetails); - clientServerMap.put(clietName, listServer); + clientServerMap.put(clientName, listServer); } } } @@ -109,12 +107,10 @@ public class ClientCommands implements GfshCommand { } String memberSeparator = "; "; - Iterator<Entry<String, List<String>>> it = clientServerMap.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry<String, List<String>> pairs = (Map.Entry<String, List<String>>) it.next(); - String client = (String) pairs.getKey(); - List<String> servers = (List<String>) pairs.getValue(); + for (Entry<String, List<String>> pairs : clientServerMap.entrySet()) { + String client = pairs.getKey(); + List<String> servers = pairs.getValue(); StringBuilder serverListForClient = new StringBuilder(); int serversSize = servers.size(); int i = 0; @@ -148,7 +144,7 @@ public class ClientCommands implements GfshCommand { @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) public Result describeClient(@CliOption(key = CliStrings.DESCRIBE_CLIENT__ID, mandatory = true, help = CliStrings.DESCRIBE_CLIENT__ID__HELP) String clientId) { - Result result = null; + Result result; if (clientId.startsWith("\"")) { clientId = clientId.substring(1); @@ -179,7 +175,7 @@ public class ClientCommands implements GfshCommand { for (ObjectName objName : cacheServers) { CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class); List<String> listOfClient = - new ArrayList<String>(Arrays.asList((String[]) serverMbean.getClientIds())); + new ArrayList<>(Arrays.asList((String[]) serverMbean.getClientIds())); if (listOfClient.contains(clientId)) { if (clientHealthStatus == null) { try { @@ -204,17 +200,17 @@ public class ClientCommands implements GfshCommand { Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache); String isDurable = null; - List<String> primaryServers = new ArrayList<String>(); - List<String> secondaryServers = new ArrayList<String>(); + List<String> primaryServers = new ArrayList<>(); + List<String> secondaryServers = new ArrayList<>(); if (dsMembers.size() > 0) { - ContunuousQueryFunction contunuousQueryFunction = new ContunuousQueryFunction(); - FunctionService.registerFunction(contunuousQueryFunction); + ContinuousQueryFunction continuousQueryFunction = new ContinuousQueryFunction(); + FunctionService.registerFunction(continuousQueryFunction); List<?> resultList = (List<?>) CliUtil - .executeFunction(contunuousQueryFunction, clientId, dsMembers).getResult(); - for (int i = 0; i < resultList.size(); i++) { + .executeFunction(continuousQueryFunction, clientId, dsMembers).getResult(); + for (Object aResultList : resultList) { try { - Object object = resultList.get(i); + Object object = aResultList; if (object instanceof Throwable) { LogWrapper.getInstance().warning( "Exception in Describe Client " + ((Throwable) object).getMessage(), @@ -261,11 +257,11 @@ public class ClientCommands implements GfshCommand { } } catch (Exception e) { LogWrapper.getInstance() - .info("Error in decribe clients. stack trace" + CliUtil.stackTraceAsString(e)); + .info("Error in describe clients. stack trace" + CliUtil.stackTraceAsString(e)); result = ResultBuilder.createGemFireErrorResult(CliStrings .format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_CLIENT_0, e.getMessage())); } - LogWrapper.getInstance().info("decribe client result " + result); + LogWrapper.getInstance().info("describe client result " + result); return result; } @@ -309,29 +305,27 @@ public class ClientCommands implements GfshCommand { Map<String, String> poolStats = clientHealthStatus.getPoolStats(); if (poolStats.size() > 0) { - Iterator<Entry<String, String>> it = poolStats.entrySet().iterator(); - while (it.hasNext()) { - Entry<String, String> entry = it.next(); + for (Entry<String, String> entry : poolStats.entrySet()) { TabularResultData poolStatsResultTable = sectionResult.addTable("Pool Stats For Pool Name = " + entry.getKey()); poolStatsResultTable.setHeader("Pool Stats For Pool Name = " + entry.getKey()); String poolStatsStr = entry.getValue(); String str[] = poolStatsStr.split(";"); - LogWrapper.getInstance().info("decribe client clientHealthStatus min conn=" + LogWrapper.getInstance().info("describe client clientHealthStatus min conn=" + str[0].substring(str[0].indexOf("=") + 1)); - LogWrapper.getInstance().info("decribe client clientHealthStatus max conn =" + LogWrapper.getInstance().info("describe client clientHealthStatus max conn =" + str[1].substring(str[1].indexOf("=") + 1)); - LogWrapper.getInstance().info("decribe client clientHealthStatus redundancy =" + LogWrapper.getInstance().info("describe client clientHealthStatus redundancy =" + str[2].substring(str[2].indexOf("=") + 1)); - LogWrapper.getInstance().info("decribe client clientHealthStatus CQs =" + LogWrapper.getInstance().info("describe client clientHealthStatus CQs =" + str[3].substring(str[3].indexOf("=") + 1)); poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_MIN_CONN, str[0].substring(str[0].indexOf("=") + 1)); poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_MAX_CONN, str[1].substring(str[1].indexOf("=") + 1)); - poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_REDUDANCY, + poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_REDUNDANCY, str[2].substring(str[2].indexOf("=") + 1)); poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_CQs, str[3].substring(str[3].indexOf("=") + 1)); http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java index b762396..883bfee 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -79,6 +78,7 @@ import org.apache.geode.management.internal.configuration.domain.XmlEntity; import org.apache.geode.management.internal.security.ResourceOperation; import org.apache.geode.security.ResourcePermission.Operation; import org.apache.geode.security.ResourcePermission.Resource; +import org.apache.geode.security.ResourcePermission.Target; /** * @since GemFire 7.0 @@ -103,7 +103,8 @@ public class CreateAlterDestroyRegionCommands implements GfshCommand { } /** - * TODO: method createRegion is too complex to analyze + * Internally, we also verify the resource operation permissions CLUSTER:WRITE:DISK if the region + * is persistent */ @CliCommand(value = CliStrings.CREATE_REGION, help = CliStrings.CREATE_REGION__HELP) @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION) @@ -295,19 +296,20 @@ public class CreateAlterDestroyRegionCommands implements GfshCommand { } } + // Do we prefer to validate or authorize first? validateRegionFunctionArgs(cache, regionFunctionArgs); + if (isPersistentShortcut(regionFunctionArgs.getRegionShortcut()) + || isAttributePersistent(regionFunctionArgs.getRegionAttributes())) { + getSecurityService().authorize(Resource.CLUSTER, Operation.WRITE, Target.DISK); + } Set<DistributedMember> membersToCreateRegionOn; if (groups != null && groups.length != 0) { membersToCreateRegionOn = CliUtil.getDistributedMembersByGroup(cache, groups); // have only normal members from the group - for (Iterator<DistributedMember> it = membersToCreateRegionOn.iterator(); it.hasNext();) { - DistributedMember distributedMember = it.next(); - if (((InternalDistributedMember) distributedMember) - .getVmKind() == DistributionManager.LOCATOR_DM_TYPE) { - it.remove(); - } - } + membersToCreateRegionOn + .removeIf(distributedMember -> ((InternalDistributedMember) distributedMember) + .getVmKind() == DistributionManager.LOCATOR_DM_TYPE); } else { membersToCreateRegionOn = CliUtil.getAllNormalMembers(cache); } @@ -340,9 +342,6 @@ public class CreateAlterDestroyRegionCommands implements GfshCommand { } catch (IllegalArgumentException | IllegalStateException e) { LogWrapper.getInstance().info(e.getMessage()); result = ResultBuilder.createUserErrorResult(e.getMessage()); - } catch (RuntimeException e) { - LogWrapper.getInstance().info(e.getMessage(), e); - result = ResultBuilder.createGemFireErrorResult(e.getMessage()); } if (xmlEntity.get() != null) { persistClusterConfiguration(result, @@ -424,7 +423,7 @@ public class CreateAlterDestroyRegionCommands implements GfshCommand { Result result; AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>(); - getCache().getSecurityService().authorizeRegionManage(regionPath); + getSecurityService().authorizeRegionManage(regionPath); try { InternalCache cache = getCache(); @@ -914,7 +913,7 @@ public class CreateAlterDestroyRegionCommands implements GfshCommand { } // attributes null check } // not IllegalArgumentException or other throwable } // iterate over list - there should be only one result in the list - } // result list is not null or mpty + } // result list is not null or empty } // regionAssociatedMembers is not-empty } // attributes are null because do not exist on local member @@ -1128,4 +1127,20 @@ public class CreateAlterDestroyRegionCommands implements GfshCommand { } return foundMembers; } + + private boolean isPersistentShortcut(RegionShortcut shortcut) { + return shortcut == RegionShortcut.LOCAL_PERSISTENT + || shortcut == RegionShortcut.LOCAL_PERSISTENT_OVERFLOW + || shortcut == RegionShortcut.PARTITION_PERSISTENT + || shortcut == RegionShortcut.PARTITION_PERSISTENT_OVERFLOW + || shortcut == RegionShortcut.PARTITION_REDUNDANT_PERSISTENT + || shortcut == RegionShortcut.PARTITION_REDUNDANT_PERSISTENT_OVERFLOW + || shortcut == RegionShortcut.REPLICATE_PERSISTENT + || shortcut == RegionShortcut.REPLICATE_PERSISTENT_OVERFLOW; + } + + private boolean isAttributePersistent(RegionAttributes attributes) { + return attributes != null && attributes.getDataPolicy() != null + && attributes.getDataPolicy().toString().contains("PERSISTENT"); + } } http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java index b2789e3..3f4397b 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java @@ -14,9 +14,28 @@ */ package org.apache.geode.management.internal.cli.commands; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; +import org.apache.shiro.subject.Subject; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.LogWriter; import org.apache.geode.cache.CacheClosedException; import org.apache.geode.cache.CacheFactory; @@ -60,24 +79,6 @@ import org.apache.geode.management.internal.cli.shell.Gfsh; import org.apache.geode.management.internal.security.ResourceOperation; import org.apache.geode.security.ResourcePermission.Operation; import org.apache.geode.security.ResourcePermission.Resource; -import org.apache.shiro.subject.Subject; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; /** * @since GemFire 7.0 @@ -105,10 +106,8 @@ public class DataCommands implements GfshCommand { @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) public Result rebalance( @CliOption(key = CliStrings.REBALANCE__INCLUDEREGION, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.REBALANCE__INCLUDEREGION__HELP) String[] includeRegions, @CliOption(key = CliStrings.REBALANCE__EXCLUDEREGION, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.REBALANCE__EXCLUDEREGION__HELP) String[] excludeRegions, @CliOption(key = CliStrings.REBALANCE__TIMEOUT, unspecifiedDefaultValue = "-1", help = CliStrings.REBALANCE__TIMEOUT__HELP) long timeout, @@ -135,7 +134,7 @@ public class DataCommands implements GfshCommand { } catch (Exception ex) { result = ResultBuilder.createGemFireErrorResult(CliStrings.format( - CliStrings.REBALANCE__MSG__EXCEPTION_OCCRED_WHILE_REBALANCING_0, ex.getMessage())); + CliStrings.REBALANCE__MSG__EXCEPTION_OCCURRED_WHILE_REBALANCING_0, ex.getMessage())); } LogWrapper.getInstance().info("Rebalance returning result >>>" + result); return result; @@ -473,12 +472,12 @@ public class DataCommands implements GfshCommand { return listMembersId.toString(); } - private CompositeResultData toCompositeResultData(CompositeResultData rebalanceResulteData, + private CompositeResultData toCompositeResultData(CompositeResultData rebalanceResultData, ArrayList<String> rstlist, int index, boolean simulate, InternalCache cache) { // add only if there are any valid regions in results if (rstlist.size() > resultItemCount && StringUtils.isNotEmpty(rstlist.get(resultItemCount))) { - TabularResultData table1 = rebalanceResulteData.addSection().addTable("Table" + index); + TabularResultData table1 = rebalanceResultData.addSection().addTable("Table" + index); String newLine = System.getProperty("line.separator"); StringBuilder resultStr = new StringBuilder(); resultStr.append(newLine); @@ -541,7 +540,7 @@ public class DataCommands implements GfshCommand { table1.setHeader(headerText); cache.getLogger().info(headerText + resultStr); } - return rebalanceResulteData; + return rebalanceResultData; } private CompositeResultData buildResultForRebalance(CompositeResultData rebalanceResultData, @@ -739,15 +738,12 @@ public class DataCommands implements GfshCommand { @CliOption(key = CliStrings.EXPORT_DATA__REGION, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = CliStrings.EXPORT_DATA__REGION__HELP) String regionName, - @CliOption(key = CliStrings.EXPORT_DATA__FILE, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, mandatory = true, + @CliOption(key = CliStrings.EXPORT_DATA__FILE, mandatory = true, help = CliStrings.EXPORT_DATA__FILE__HELP) String filePath, - @CliOption(key = CliStrings.MEMBER, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, - optionContext = ConverterHint.MEMBERIDNAME, mandatory = true, - help = CliStrings.EXPORT_DATA__MEMBER__HELP) String memberNameOrId) { + @CliOption(key = CliStrings.MEMBER, optionContext = ConverterHint.MEMBERIDNAME, + mandatory = true, help = CliStrings.EXPORT_DATA__MEMBER__HELP) String memberNameOrId) { - getCache().getSecurityService().authorizeRegionRead(regionName); + getSecurityService().authorizeRegionRead(regionName); final DistributedMember targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId); Result result; @@ -796,16 +792,14 @@ public class DataCommands implements GfshCommand { @CliOption(key = CliStrings.IMPORT_DATA__REGION, optionContext = ConverterHint.REGION_PATH, mandatory = true, help = CliStrings.IMPORT_DATA__REGION__HELP) String regionName, @CliOption(key = CliStrings.IMPORT_DATA__FILE, mandatory = true, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.IMPORT_DATA__FILE__HELP) String filePath, @CliOption(key = CliStrings.MEMBER, mandatory = true, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.IMPORT_DATA__MEMBER__HELP) String memberNameOrId, @CliOption(key = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS, unspecifiedDefaultValue = "false", help = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS__HELP) boolean invokeCallbacks) { - getCache().getSecurityService().authorizeRegionWrite(regionName); + getSecurityService().authorizeRegionWrite(regionName); Result result; @@ -1003,7 +997,7 @@ public class DataCommands implements GfshCommand { help = CliStrings.LOCATE_ENTRY__RECURSIVE__HELP, unspecifiedDefaultValue = "false") boolean recursive) { - getCache().getSecurityService().authorizeRegionRead(regionPath, key); + getSecurityService().authorizeRegionRead(regionPath, key); DataCommandResult dataResult; http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java index 9b79e1d..e502154 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java @@ -15,8 +15,17 @@ package org.apache.geode.management.internal.cli.commands; import static org.apache.commons.io.FileUtils.ONE_MB; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.text.DecimalFormat; +import java.util.List; +import java.util.Set; + import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; import org.apache.geode.SystemFailure; import org.apache.geode.cache.execute.ResultCollector; @@ -42,15 +51,9 @@ import org.apache.geode.management.internal.security.ResourceOperation; import org.apache.geode.security.NotAuthorizedException; import org.apache.geode.security.ResourcePermission.Operation; import org.apache.geode.security.ResourcePermission.Resource; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; +import org.apache.geode.security.ResourcePermission.Target; + -import java.io.FileNotFoundException; -import java.io.IOException; -import java.text.DecimalFormat; -import java.util.List; -import java.util.Map; -import java.util.Set; /** * Commands for deploying, un-deploying and listing files deployed using the command line shell. @@ -76,6 +79,7 @@ public class DeployCommands implements GfshCommand { @CliMetaData( interceptor = "org.apache.geode.management.internal.cli.commands.DeployCommands$Interceptor", relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG}) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, target = Target.JAR) public Result deploy( @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.DEPLOY__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) String[] groups, @@ -86,11 +90,7 @@ public class DeployCommands implements GfshCommand { // since deploy function can potentially do a lot of damage to security, this action should // require these following privileges - SecurityService securityService = getCache().getSecurityService(); - securityService.authorizeClusterManage(); - securityService.authorizeClusterWrite(); - securityService.authorizeDataManage(); - securityService.authorizeDataWrite(); + SecurityService securityService = getSecurityService(); TabularResultData tabularData = ResultBuilder.createTabularResultData(); @@ -155,13 +155,13 @@ public class DeployCommands implements GfshCommand { */ @CliCommand(value = {CliStrings.UNDEPLOY}, help = CliStrings.UNDEPLOY__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG}) - @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, target = Target.JAR) public Result undeploy( @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.UNDEPLOY__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) String[] groups, - @CliOption(key = {CliStrings.JAR, CliStrings.JARS}, help = CliStrings.UNDEPLOY__JAR__HELP, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE) String[] jars) { + @CliOption(key = {CliStrings.JAR, CliStrings.JARS}, + help = CliStrings.UNDEPLOY__JAR__HELP) String[] jars) { try { TabularResultData tabularData = ResultBuilder.createTabularResultData(); @@ -289,7 +289,7 @@ public class DeployCommands implements GfshCommand { public Result preExecution(GfshParseResult parseResult) { // 2nd argument is the jar String[] jars = (String[]) parseResult.getArguments()[1]; - // 3rd arguemnt is the dir + // 3rd argument is the dir String dir = (String) parseResult.getArguments()[2]; if (ArrayUtils.isEmpty(jars) && StringUtils.isBlank(dir)) { http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java index e14c3a6..80f3804 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommands.java @@ -14,6 +14,28 @@ */ package org.apache.geode.management.internal.cli.commands; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.GemFireIOException; import org.apache.geode.SystemFailure; import org.apache.geode.admin.BackupStatus; @@ -68,32 +90,9 @@ import org.apache.geode.management.internal.cli.util.MemberNotFoundException; import org.apache.geode.management.internal.configuration.domain.XmlEntity; import org.apache.geode.management.internal.messages.CompactRequest; import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission.Target; import org.apache.geode.security.ResourcePermission.Operation; import org.apache.geode.security.ResourcePermission.Resource; -import org.springframework.shell.core.annotation.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; +import org.apache.geode.security.ResourcePermission.Target; /** * The DiskStoreCommands class encapsulates all GemFire Disk Store commands in Gfsh. @@ -103,27 +102,31 @@ import java.util.concurrent.atomic.AtomicReference; */ @SuppressWarnings("unused") public class DiskStoreCommands implements GfshCommand { + protected Set<DistributedMember> getNormalMembers(final InternalCache cache) { // TODO determine what this does (as it is untested and unmockable!) return CliUtil.getAllNormalMembers(cache); } + /** + * Internally, we also verify the resource operation permissions CLUSTER:WRITE:DISK if the region + * is persistent + */ @CliCommand(value = CliStrings.BACKUP_DISK_STORE, help = CliStrings.BACKUP_DISK_STORE__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) @ResourceOperation(resource = Resource.DATA, operation = Operation.READ) public Result backupDiskStore( - @CliOption(key = CliStrings.BACKUP_DISK_STORE__DISKDIRS, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.BACKUP_DISK_STORE__DISKDIRS__HELP, mandatory = true) String targetDir, @CliOption(key = CliStrings.BACKUP_DISK_STORE__BASELINEDIR, help = CliStrings.BACKUP_DISK_STORE__BASELINEDIR__HELP) String baselineDir) { - Result result = null; + getSecurityService().authorize(Resource.CLUSTER, Operation.WRITE, Target.DISK); + Result result; try { InternalCache cache = getCache(); DM dm = cache.getDistributionManager(); - BackupStatus backupStatus = null; + BackupStatus backupStatus; if (baselineDir != null && !baselineDir.isEmpty()) { backupStatus = AdminDistributedSystemImpl.backupAllMembers(dm, new File(targetDir), @@ -159,11 +162,11 @@ public class DiskStoreCommands implements GfshCommand { String directory = persistentId.getDirectory(); if (printMember) { - writeToBackupDisktoreTable(backedupDiskStoresTable, memberName, UUID, hostName, + writeToBackupDiskStoreTable(backedupDiskStoresTable, memberName, UUID, hostName, directory); printMember = false; } else { - writeToBackupDisktoreTable(backedupDiskStoresTable, "", UUID, hostName, directory); + writeToBackupDiskStoreTable(backedupDiskStoresTable, "", UUID, hostName, directory); } } } @@ -197,8 +200,8 @@ public class DiskStoreCommands implements GfshCommand { return result; } - private void writeToBackupDisktoreTable(TabularResultData backedupDiskStoreTable, String memberId, - String UUID, String host, String directory) { + private void writeToBackupDiskStoreTable(TabularResultData backedupDiskStoreTable, + String memberId, String UUID, String host, String directory) { backedupDiskStoreTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_MEMBER, memberId); backedupDiskStoreTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_UUID, UUID); backedupDiskStoreTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_DIRECTORY, directory); @@ -206,7 +209,7 @@ public class DiskStoreCommands implements GfshCommand { } @CliCommand(value = CliStrings.LIST_DISK_STORE, help = CliStrings.LIST_DISK_STORE__HELP) - @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) public Result listDiskStore() { try { @@ -242,7 +245,7 @@ public class DiskStoreCommands implements GfshCommand { final List<?> results = (List<?>) resultCollector.getResult(); final List<DiskStoreDetails> distributedSystemMemberDiskStores = - new ArrayList<DiskStoreDetails>(results.size()); + new ArrayList<>(results.size()); for (final Object result : results) { if (result instanceof Set) { // ignore FunctionInvocationTargetExceptions and other @@ -276,8 +279,9 @@ public class DiskStoreCommands implements GfshCommand { } @CliCommand(value = CliStrings.CREATE_DISK_STORE, help = CliStrings.CREATE_DISK_STORE__HELP) - @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) - @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.DISK) public Result createDiskStore( @CliOption(key = CliStrings.CREATE_DISK_STORE__NAME, mandatory = true, optionContext = ConverterHint.DISKSTORE, @@ -398,7 +402,7 @@ public class DiskStoreCommands implements GfshCommand { } @CliCommand(value = CliStrings.COMPACT_DISK_STORE, help = CliStrings.COMPACT_DISK_STORE__HELP) - @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, target = Target.DISK) public Result compactDiskStore( @@ -406,9 +410,8 @@ public class DiskStoreCommands implements GfshCommand { optionContext = ConverterHint.DISKSTORE, help = CliStrings.COMPACT_DISK_STORE__NAME__HELP) String diskStoreName, @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.COMPACT_DISK_STORE__GROUP__HELP) String[] groups) { - Result result = null; + Result result; try { // disk store exists validation @@ -419,29 +422,24 @@ public class DiskStoreCommands implements GfshCommand { } else { InternalDistributedSystem ds = getCache().getInternalDistributedSystem(); - Map<DistributedMember, PersistentID> overallCompactInfo = - new HashMap<DistributedMember, PersistentID>(); + Map<DistributedMember, PersistentID> overallCompactInfo = new HashMap<>(); Set<?> otherMembers = ds.getDistributionManager().getOtherNormalDistributionManagerIds(); - Set<InternalDistributedMember> allMembers = new HashSet<InternalDistributedMember>(); + Set<InternalDistributedMember> allMembers = new HashSet<>(); for (Object member : otherMembers) { allMembers.add((InternalDistributedMember) member); } allMembers.add(ds.getDistributedMember()); - otherMembers = null; String groupInfo = ""; // if groups are specified, find members in the specified group if (groups != null && groups.length > 0) { groupInfo = CliStrings.format(CliStrings.COMPACT_DISK_STORE__MSG__FOR_GROUP, new Object[] {Arrays.toString(groups) + "."}); - final Set<InternalDistributedMember> selectedMembers = - new HashSet<InternalDistributedMember>(); + final Set<InternalDistributedMember> selectedMembers = new HashSet<>(); List<String> targetedGroups = Arrays.asList(groups); - for (Iterator<InternalDistributedMember> iterator = allMembers.iterator(); iterator - .hasNext();) { - InternalDistributedMember member = iterator.next(); + for (InternalDistributedMember member : allMembers) { List<String> memberGroups = member.getGroups(); if (!Collections.disjoint(targetedGroups, memberGroups)) { selectedMembers.add(member); @@ -486,7 +484,7 @@ public class DiskStoreCommands implements GfshCommand { // If compaction happened at all, then prepare the summary if (overallCompactInfo != null && !overallCompactInfo.isEmpty()) { CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData(); - SectionResultData section = null; + SectionResultData section; Set<Entry<DistributedMember, PersistentID>> entries = overallCompactInfo.entrySet(); @@ -546,20 +544,18 @@ public class DiskStoreCommands implements GfshCommand { @CliOption(key = CliStrings.COMPACT_OFFLINE_DISK_STORE__NAME, mandatory = true, help = CliStrings.COMPACT_OFFLINE_DISK_STORE__NAME__HELP) String diskStoreName, @CliOption(key = CliStrings.COMPACT_OFFLINE_DISK_STORE__DISKDIRS, mandatory = true, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.COMPACT_OFFLINE_DISK_STORE__DISKDIRS__HELP) String[] diskDirs, @CliOption(key = CliStrings.COMPACT_OFFLINE_DISK_STORE__MAXOPLOGSIZE, unspecifiedDefaultValue = "-1", help = CliStrings.COMPACT_OFFLINE_DISK_STORE__MAXOPLOGSIZE__HELP) long maxOplogSize, @CliOption(key = CliStrings.COMPACT_OFFLINE_DISK_STORE__J, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.COMPACT_OFFLINE_DISK_STORE__J__HELP) String[] jvmProps) { - Result result = null; + Result result; LogWrapper logWrapper = LogWrapper.getInstance(); StringBuilder output = new StringBuilder(); StringBuilder error = new StringBuilder(); - String errorMessage = ""; + StringBuilder errorMessage = new StringBuilder(); Process compacterProcess = null; try { @@ -570,16 +566,14 @@ public class DiskStoreCommands implements GfshCommand { + validatedDirectories + "\""); } - List<String> commandList = new ArrayList<String>(); + List<String> commandList = new ArrayList<>(); commandList.add(System.getProperty("java.home") + File.separatorChar + "bin" + File.separatorChar + "java"); configureLogging(commandList); if (jvmProps != null && jvmProps.length != 0) { - for (int i = 0; i < jvmProps.length; i++) { - commandList.add(jvmProps[i]); - } + commandList.addAll(Arrays.asList(jvmProps)); } commandList.add("-classpath"); commandList.add(System.getProperty("java.class.path", ".")); @@ -612,12 +606,11 @@ public class DiskStoreCommands implements GfshCommand { BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream)); BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream)); - String line = null; + String line; while ((line = inputReader.readLine()) != null) { output.append(line).append(GfshParser.LINE_SEPARATOR); } - line = null; boolean switchToStackTrace = false; while ((line = errorReader.readLine()) != null) { if (!switchToStackTrace && DiskStoreCompacter.STACKTRACE_START.equals(line)) { @@ -625,12 +618,12 @@ public class DiskStoreCommands implements GfshCommand { } else if (switchToStackTrace) { error.append(line).append(GfshParser.LINE_SEPARATOR); } else { - errorMessage = errorMessage + line; + errorMessage.append(line); } } - if (!errorMessage.isEmpty()) { - throw new GemFireIOException(errorMessage); + if (errorMessage.length() > 0) { + throw new GemFireIOException(errorMessage.toString()); } // do we have to waitFor?? @@ -654,7 +647,7 @@ public class DiskStoreCommands implements GfshCommand { if (output.length() != 0) { Gfsh.println(output.toString()); } - result = ResultBuilder.createUserErrorResult(errorMessage); + result = ResultBuilder.createUserErrorResult(errorMessage.toString()); if (logWrapper.fineEnabled()) { logWrapper.fine(error.toString()); } @@ -686,22 +679,20 @@ public class DiskStoreCommands implements GfshCommand { @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME, mandatory = true, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME__HELP) String diskStoreName, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS, mandatory = true, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS__HELP) String[] diskDirs, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE, unspecifiedDefaultValue = "-1", help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE__HELP) long maxOplogSize, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__J, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__J__HELP) String[] jvmProps) throws InterruptedException { - Result result = null; + Result result; LogWrapper logWrapper = LogWrapper.getInstance(); StringBuilder output = new StringBuilder(); StringBuilder error = new StringBuilder(); - String errorMessage = ""; + StringBuilder errorMessage = new StringBuilder(); Process upgraderProcess = null; try { @@ -712,16 +703,14 @@ public class DiskStoreCommands implements GfshCommand { + validatedDirectories + "\""); } - List<String> commandList = new ArrayList<String>(); + List<String> commandList = new ArrayList<>(); commandList.add(System.getProperty("java.home") + File.separatorChar + "bin" + File.separatorChar + "java"); configureLogging(commandList); if (jvmProps != null && jvmProps.length != 0) { - for (int i = 0; i < jvmProps.length; i++) { - commandList.add(jvmProps[i]); - } + commandList.addAll(Arrays.asList(jvmProps)); } commandList.add("-classpath"); commandList.add(System.getProperty("java.class.path", ".")); @@ -755,12 +744,11 @@ public class DiskStoreCommands implements GfshCommand { BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream)); BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream)); - String line = null; + String line; while ((line = inputReader.readLine()) != null) { output.append(line).append(GfshParser.LINE_SEPARATOR); } - line = null; boolean switchToStackTrace = false; while ((line = errorReader.readLine()) != null) { if (!switchToStackTrace && DiskStoreUpgrader.STACKTRACE_START.equals(line)) { @@ -768,12 +756,12 @@ public class DiskStoreCommands implements GfshCommand { } else if (switchToStackTrace) { error.append(line).append(GfshParser.LINE_SEPARATOR); } else { - errorMessage = errorMessage + line; + errorMessage.append(line); } } - if (!errorMessage.isEmpty()) { - throw new GemFireIOException(errorMessage); + if (errorMessage.length() > 0) { + throw new GemFireIOException(errorMessage.toString()); } upgraderProcess.destroy(); @@ -796,7 +784,7 @@ public class DiskStoreCommands implements GfshCommand { if (output.length() != 0) { Gfsh.println(output.toString()); } - result = ResultBuilder.createUserErrorResult(errorMessage); + result = ResultBuilder.createUserErrorResult(errorMessage.toString()); if (logWrapper.fineEnabled()) { logWrapper.fine(error.toString()); } @@ -823,7 +811,7 @@ public class DiskStoreCommands implements GfshCommand { private String validatedDirectories(String[] diskDirs) { String invalidDirectories = null; StringBuilder builder = null; - File diskDir = null; + File diskDir; for (String diskDirPath : diskDirs) { diskDir = new File(diskDirPath); if (!diskDir.exists()) { @@ -843,7 +831,7 @@ public class DiskStoreCommands implements GfshCommand { } @CliCommand(value = CliStrings.DESCRIBE_DISK_STORE, help = CliStrings.DESCRIBE_DISK_STORE__HELP) - @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) public Result describeDiskStore( @CliOption(key = CliStrings.MEMBER, mandatory = true, @@ -854,9 +842,7 @@ public class DiskStoreCommands implements GfshCommand { help = CliStrings.DESCRIBE_DISK_STORE__NAME__HELP) final String diskStoreName) { try { return toCompositeResult(getDiskStoreDescription(memberName, diskStoreName)); - } catch (DiskStoreNotFoundException e) { - return ResultBuilder.createShellClientErrorResult(e.getMessage()); - } catch (MemberNotFoundException e) { + } catch (DiskStoreNotFoundException | MemberNotFoundException e) { return ResultBuilder.createShellClientErrorResult(e.getMessage()); } catch (FunctionInvocationTargetException ignore) { return ResultBuilder.createGemFireErrorResult(CliStrings @@ -982,7 +968,8 @@ public class DiskStoreCommands implements GfshCommand { @CliCommand(value = CliStrings.REVOKE_MISSING_DISK_STORE, help = CliStrings.REVOKE_MISSING_DISK_STORE__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) - @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.DISK) public Result revokeMissingDiskStore(@CliOption(key = CliStrings.REVOKE_MISSING_DISK_STORE__ID, mandatory = true, help = CliStrings.REVOKE_MISSING_DISK_STORE__ID__HELP) String id) { @@ -1049,7 +1036,7 @@ public class DiskStoreCommands implements GfshCommand { membersFunctionExecutor.execute(new ShowMissingDiskStoresFunction()); final List<?> results = (List<?>) resultCollector.getResult(); - final List<Object> distributedPersistentRecoveryDetails = new ArrayList<Object>(results.size()); + final List<Object> distributedPersistentRecoveryDetails = new ArrayList<>(results.size()); for (final Object result : results) { if (result instanceof Set) { // ignore FunctionInvocationTargetExceptions and other // Exceptions... @@ -1062,8 +1049,8 @@ public class DiskStoreCommands implements GfshCommand { protected Result toMissingDiskStoresTabularResult(final List<Object> resultDetails) throws ResultDataException { CompositeResultData crd = ResultBuilder.createCompositeResultData(); - List<PersistentMemberPattern> missingDiskStores = new ArrayList<PersistentMemberPattern>(); - List<ColocatedRegionDetails> missingColocatedRegions = new ArrayList<ColocatedRegionDetails>(); + List<PersistentMemberPattern> missingDiskStores = new ArrayList<>(); + List<ColocatedRegionDetails> missingColocatedRegions = new ArrayList<>(); for (Object detail : resultDetails) { if (detail instanceof PersistentMemberPattern) { @@ -1082,10 +1069,10 @@ public class DiskStoreCommands implements GfshCommand { missingDiskStoresSection.setHeader("Missing Disk Stores"); TabularResultData missingDiskStoreData = missingDiskStoresSection.addTable(); - for (PersistentMemberPattern peristentMemberDetails : missingDiskStores) { - missingDiskStoreData.accumulate("Disk Store ID", peristentMemberDetails.getUUID()); - missingDiskStoreData.accumulate("Host", peristentMemberDetails.getHost()); - missingDiskStoreData.accumulate("Directory", peristentMemberDetails.getDirectory()); + for (PersistentMemberPattern persistentMemberDetails : missingDiskStores) { + missingDiskStoreData.accumulate("Disk Store ID", persistentMemberDetails.getUUID()); + missingDiskStoreData.accumulate("Host", persistentMemberDetails.getHost()); + missingDiskStoreData.accumulate("Directory", persistentMemberDetails.getDirectory()); } } else { SectionResultData noMissingDiskStores = crd.addSection(); @@ -1124,11 +1111,9 @@ public class DiskStoreCommands implements GfshCommand { @CliOption(key = CliStrings.DESCRIBE_OFFLINE_DISK_STORE__DISKDIRS, mandatory = true, help = CliStrings.DESCRIBE_OFFLINE_DISK_STORE__DISKDIRS__HELP) String[] diskDirs, @CliOption(key = CliStrings.DESCRIBE_OFFLINE_DISK_STORE__PDX_TYPES, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.DESCRIBE_OFFLINE_DISK_STORE__PDX_TYPES__HELP) Boolean listPdxTypes, @CliOption(key = CliStrings.DESCRIBE_OFFLINE_DISK_STORE__REGIONNAME, - help = CliStrings.DESCRIBE_OFFLINE_DISK_STORE__REGIONNAME__HELP, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE) String regionName) { + help = CliStrings.DESCRIBE_OFFLINE_DISK_STORE__REGIONNAME__HELP) String regionName) { try { final File[] dirs = new File[diskDirs.length]; @@ -1184,7 +1169,7 @@ public class DiskStoreCommands implements GfshCommand { DiskStoreImpl.exportOfflineSnapshot(diskStoreName, dirs, output); String resultString = CliStrings.format(CliStrings.EXPORT_OFFLINE_DISK_STORE__SUCCESS, diskStoreName, dir); - return ResultBuilder.createInfoResult(resultString.toString()); + return ResultBuilder.createInfoResult(resultString); } catch (VirtualMachineError e) { SystemFailure.initiateFailure(e); throw e; @@ -1209,31 +1194,25 @@ public class DiskStoreCommands implements GfshCommand { @CliOption(key = CliStrings.VALIDATE_DISK_STORE__NAME, mandatory = true, help = CliStrings.VALIDATE_DISK_STORE__NAME__HELP) String diskStoreName, @CliOption(key = CliStrings.VALIDATE_DISK_STORE__DISKDIRS, mandatory = true, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.VALIDATE_DISK_STORE__DISKDIRS__HELP) String[] diskDirs, @CliOption(key = CliStrings.VALIDATE_DISK_STORE__J, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.VALIDATE_DISK_STORE__J__HELP) String[] jvmProps) { try { - String resultString = new String(); - // create a new process ...bug 46075 StringBuilder dirList = new StringBuilder(); - for (int i = 0; i < diskDirs.length; i++) { - dirList.append(diskDirs[i]); + for (String diskDir : diskDirs) { + dirList.append(diskDir); dirList.append(";"); } - List<String> commandList = new ArrayList<String>(); + List<String> commandList = new ArrayList<>(); commandList.add(System.getProperty("java.home") + File.separatorChar + "bin" + File.separatorChar + "java"); configureLogging(commandList); if (jvmProps != null && jvmProps.length != 0) { - for (int i = 0; i < jvmProps.length; i++) { - commandList.add(jvmProps[i]); - } + commandList.addAll(Arrays.asList(jvmProps)); } // Pass any java options on to the command @@ -1249,23 +1228,22 @@ public class DiskStoreCommands implements GfshCommand { ProcessBuilder procBuilder = new ProcessBuilder(commandList); StringBuilder output = new StringBuilder(); - String errorString = new String(); + String errorString = ""; Process validateDiskStoreProcess = procBuilder.redirectErrorStream(true).start(); InputStream inputStream = validateDiskStoreProcess.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); - String line = null; + String line; while ((line = br.readLine()) != null) { output.append(line).append(GfshParser.LINE_SEPARATOR); } validateDiskStoreProcess.destroy(); - if (errorString != null) { - output.append(errorString).append(GfshParser.LINE_SEPARATOR); - } - resultString = "Validating " + diskStoreName + GfshParser.LINE_SEPARATOR + output.toString(); - return ResultBuilder.createInfoResult(resultString.toString()); + output.append(errorString).append(GfshParser.LINE_SEPARATOR); + String resultString = + "Validating " + diskStoreName + GfshParser.LINE_SEPARATOR + output.toString(); + return ResultBuilder.createInfoResult(resultString); } catch (IOException ex) { return ResultBuilder.createGemFireErrorResult(CliStrings .format(CliStrings.VALIDATE_DISK_STORE__MSG__IO_ERROR, diskStoreName, ex.getMessage())); @@ -1285,39 +1263,30 @@ public class DiskStoreCommands implements GfshCommand { @CliOption(key = CliStrings.ALTER_DISK_STORE__REGIONNAME, mandatory = true, help = CliStrings.ALTER_DISK_STORE__REGIONNAME__HELP) String regionName, @CliOption(key = CliStrings.ALTER_DISK_STORE__DISKDIRS, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__DISKDIRS__HELP, mandatory = true) String[] diskDirs, - @CliOption(key = CliStrings.ALTER_DISK_STORE__COMPRESSOR, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, - specifiedDefaultValue = "none", + @CliOption(key = CliStrings.ALTER_DISK_STORE__COMPRESSOR, specifiedDefaultValue = "none", help = CliStrings.ALTER_DISK_STORE__COMPRESSOR__HELP) String compressorClassName, @CliOption(key = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL__HELP) Integer concurrencyLevel, @CliOption(key = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED__HELP) Boolean statisticsEnabled, @CliOption(key = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY__HELP) Integer initialCapacity, @CliOption(key = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR__HELP) Float loadFactor, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION__HELP) String lruEvictionAction, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM__HELP) String lruEvictionAlgo, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT__HELP) Integer lruEvictionLimit, @CliOption(key = CliStrings.ALTER_DISK_STORE__OFF_HEAP, - unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__OFF_HEAP__HELP) Boolean offHeap, @CliOption(key = CliStrings.ALTER_DISK_STORE__REMOVE, - help = CliStrings.ALTER_DISK_STORE__REMOVE__HELP, mandatory = false, - specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean remove) { + help = CliStrings.ALTER_DISK_STORE__REMOVE__HELP, specifiedDefaultValue = "true", + unspecifiedDefaultValue = "false") boolean remove) { - Result result = null; + Result result; try { File[] dirs = null; @@ -1390,8 +1359,9 @@ public class DiskStoreCommands implements GfshCommand { } @CliCommand(value = CliStrings.DESTROY_DISK_STORE, help = CliStrings.DESTROY_DISK_STORE__HELP) - @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) - @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) + @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.DISK) public Result destroyDiskStore( @CliOption(key = CliStrings.DESTROY_DISK_STORE__NAME, mandatory = true, help = CliStrings.DESTROY_DISK_STORE__NAME__HELP) String name, http://git-wip-us.apache.org/repos/asf/geode/blob/451d12e8/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java index 87ad1be..c5d859e 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DurableClientCommands.java @@ -14,6 +14,16 @@ */ package org.apache.geode.management.internal.cli.commands; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.management.cli.CliMetaData; @@ -28,7 +38,6 @@ import org.apache.geode.management.internal.cli.functions.CloseDurableCqFunction import org.apache.geode.management.internal.cli.functions.GetSubscriptionQueueSizeFunction; import org.apache.geode.management.internal.cli.functions.ListDurableCqNamesFunction; import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.CommandResultException; import org.apache.geode.management.internal.cli.result.ErrorResultData; import org.apache.geode.management.internal.cli.result.InfoResultData; import org.apache.geode.management.internal.cli.result.ResultBuilder; @@ -36,15 +45,7 @@ import org.apache.geode.management.internal.cli.result.TabularResultData; import org.apache.geode.management.internal.security.ResourceOperation; import org.apache.geode.security.ResourcePermission.Operation; import org.apache.geode.security.ResourcePermission.Resource; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; +import org.apache.geode.security.ResourcePermission.Target; /** * The DurableClientCommands class encapsulates all GemFire shell (Gfsh) commands related to durable @@ -63,7 +64,7 @@ public class DurableClientCommands implements GfshCommand { new GetSubscriptionQueueSizeFunction(); @CliCommand(value = CliStrings.LIST_DURABLE_CQS, help = CliStrings.LIST_DURABLE_CQS__HELP) - @CliMetaData(shellOnly = false) + @CliMetaData() @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) public Result listDurableClientCqs( @CliOption(key = CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, mandatory = true, @@ -76,7 +77,7 @@ public class DurableClientCommands implements GfshCommand { @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.LIST_DURABLE_CQS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) { - Result result = null; + Result result; try { boolean noResults = true; @@ -89,9 +90,9 @@ public class DurableClientCommands implements GfshCommand { final ResultCollector<?, ?> rc = CliUtil.executeFunction(new ListDurableCqNamesFunction(), durableClientId, targetMembers); final List<DurableCqNamesResult> results = (List<DurableCqNamesResult>) rc.getResult(); - Map<String, List<String>> memberCqNamesMap = new TreeMap<String, List<String>>(); - Map<String, List<String>> errorMessageNodes = new HashMap<String, List<String>>(); - Map<String, List<String>> exceptionMessageNodes = new HashMap<String, List<String>>(); + Map<String, List<String>> memberCqNamesMap = new TreeMap<>(); + Map<String, List<String>> errorMessageNodes = new HashMap<>(); + Map<String, List<String>> exceptionMessageNodes = new HashMap<>(); for (DurableCqNamesResult memberResult : results) { if (memberResult != null) { @@ -142,21 +143,21 @@ public class DurableClientCommands implements GfshCommand { @CliCommand(value = CliStrings.COUNT_DURABLE_CQ_EVENTS, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__HELP) - @CliMetaData(shellOnly = false) + @CliMetaData() @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) public Result countDurableCqEvents( @CliOption(key = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, mandatory = true, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID__HELP) final String durableClientId, - @CliOption(key = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME, mandatory = false, + @CliOption(key = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME__HELP) final String cqName, - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, mandatory = false, + @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, mandatory = false, + @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) { - Result result = null; + Result result; try { Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId); @@ -191,19 +192,20 @@ public class DurableClientCommands implements GfshCommand { @CliCommand(value = CliStrings.CLOSE_DURABLE_CLIENTS, help = CliStrings.CLOSE_DURABLE_CLIENTS__HELP) - @CliMetaData(shellOnly = false) - @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) + @CliMetaData() + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.QUERY) public Result closeDurableClient( @CliOption(key = CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID, mandatory = true, help = CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID__HELP) final String durableClientId, - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, mandatory = false, + @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, help = CliStrings.CLOSE_DURABLE_CLIENTS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, mandatory = false, + @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) { - Result result = null; + Result result; try { Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId); @@ -228,8 +230,9 @@ public class DurableClientCommands implements GfshCommand { @CliCommand(value = CliStrings.CLOSE_DURABLE_CQS, help = CliStrings.CLOSE_DURABLE_CQS__HELP) - @CliMetaData(shellOnly = false) - @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) + @CliMetaData() + @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE, + target = Target.QUERY) public Result closeDurableCqs(@CliOption(key = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID__HELP) final String durableClientId, @@ -237,14 +240,14 @@ public class DurableClientCommands implements GfshCommand { @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__NAME, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__NAME__HELP) final String cqName, - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, mandatory = false, + @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, help = CliStrings.CLOSE_DURABLE_CQS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, mandatory = false, + @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.CLOSE_DURABLE_CQS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) { - Result result = null; + Result result; try { Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId); @@ -273,14 +276,14 @@ public class DurableClientCommands implements GfshCommand { private Result buildResult(List<MemberResult> results, String successHeader, String failureHeader) { - Result result = null; + Result result; boolean failure = true; boolean partialFailure = false; - Map<String, List<String>> errorMap = new HashMap<String, List<String>>(); - Map<String, List<String>> successMap = new HashMap<String, List<String>>(); - Map<String, List<String>> exceptionMap = new HashMap<String, List<String>>(); + Map<String, List<String>> errorMap = new HashMap<>(); + Map<String, List<String>> successMap = new HashMap<>(); + Map<String, List<String>> exceptionMap = new HashMap<>(); - /*** + /* * Aggregate the results from the members */ for (MemberResult memberResult : results) { @@ -314,20 +317,19 @@ public class DurableClientCommands implements GfshCommand { private Result buildTableResultForQueueSize(List<SubscriptionQueueSizeResult> results, String queueSizeColumnName) { - Result result = null; + Result result; boolean failure = true; - Map<String, List<String>> failureMap = new HashMap<String, List<String>>(); - Map<String, Long> memberQueueSizeTable = new TreeMap<String, Long>(); + Map<String, List<String>> failureMap = new HashMap<>(); + Map<String, Long> memberQueueSizeTable = new TreeMap<>(); - /*** + /* * Aggregate the results from the members */ for (SubscriptionQueueSizeResult memberResult : results) { if (memberResult.isSuccessful()) { failure = false; - memberResult.getSubscriptionQueueSize(); memberQueueSizeTable.put(memberResult.getMemberNameOrId(), memberResult.getSubscriptionQueueSize()); } else { @@ -361,7 +363,7 @@ public class DurableClientCommands implements GfshCommand { List<String> members = map.get(message); if (members == null) { - members = new LinkedList<String>(); + members = new LinkedList<>(); } members.add(memberNameOrId); map.put(message, members); @@ -373,11 +375,11 @@ public class DurableClientCommands implements GfshCommand { Set<String> successMessages = successMap.keySet(); for (String successMessage : successMessages) { - ird.addLine(CliStrings.format(CliStrings.ACTION_SUCCCEEDED_ON_MEMBER, successMessage)); + ird.addLine(CliStrings.format(CliStrings.ACTION_SUCCEEDED_ON_MEMBER, successMessage)); - List<String> successfullMembers = successMap.get(successMessage); + List<String> successfulMembers = successMap.get(successMessage); int num = 0; - for (String member : successfullMembers) { + for (String member : successfulMembers) { ird.addLine("" + ++num + "." + member); } ird.addLine("\n");