http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/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 29d68bd..46ee2b0 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,8 +14,28 @@ */ package org.apache.geode.management.internal.cli.commands; +import java.io.Serializable; +import java.util.ArrayList; +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.shiro.subject.Subject; +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.LogWriter; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheClosedException; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.DataPolicy; @@ -30,7 +50,7 @@ import org.apache.geode.cache.execute.FunctionService; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.cache.partition.PartitionRebalanceInfo; import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.security.IntegratedSecurityService; import org.apache.geode.internal.security.SecurityService; import org.apache.geode.management.DistributedRegionMXBean; @@ -59,35 +79,16 @@ 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.CommandMarker; -import org.springframework.shell.core.annotation.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.io.Serializable; -import java.util.ArrayList; -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 */ public class DataCommands implements CommandMarker { final int resultItemCount = 9; + private final ExportDataFunction exportDataFunction = new ExportDataFunction(); + private final ImportDataFunction importDataFunction = new ImportDataFunction(); private SecurityService securityService = IntegratedSecurityService.getSecurityService(); @@ -96,6 +97,10 @@ public class DataCommands implements CommandMarker { return Gfsh.getCurrentInstance(); } + private InternalCache getCache() { + return (InternalCache) CacheFactory.getAnyInstance(); + } + @CliCommand(value = CliStrings.REBALANCE, help = CliStrings.REBALANCE__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION}) @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) @@ -135,15 +140,13 @@ public class DataCommands implements CommandMarker { } LogWrapper.getInstance().info("Rebalance returning result >>>" + result); return result; - - } private class ExecuteRebalanceWithTimeout implements Callable<Result> { String[] includeRegions = null; String[] excludeRegions = null; boolean simulate; - Cache cache = CacheFactory.getAnyInstance();; + InternalCache cache = getCache(); @Override public Result call() throws Exception { @@ -163,8 +166,6 @@ public class DataCommands implements CommandMarker { Result result = null; try { RebalanceOperation op = null; - new HashSet<String>(); - new HashSet<String>(); if (includeRegions != null && includeRegions.length > 0) { CompositeResultData rebalanceResulteData = ResultBuilder.createCompositeResultData(); @@ -253,7 +254,6 @@ public class DataCommands implements CommandMarker { result = ResultBuilder.buildResult(toCompositeResultData(rebalanceResulteData, (ArrayList) rstList, index, simulate, cache)); - } } else { @@ -279,12 +279,11 @@ public class DataCommands implements CommandMarker { // Wait until the rebalance is complete and then get the results result = ResultBuilder.buildResult(buildResultForRebalance(rebalanceResulteData, op.getResults(), index, simulate, cache)); - } } index++; } - LogWrapper.getInstance().info("Rebalance returning result" + result); + LogWrapper.getInstance().info("Rebalance returning result " + result); return result; } else { result = executeRebalanceOnDS(cache, String.valueOf(simulate), excludeRegions); @@ -307,7 +306,6 @@ public class DataCommands implements CommandMarker { } return rstList; - } boolean checkResultList(CompositeResultData rebalanceResulteData, List resultList, @@ -349,10 +347,9 @@ public class DataCommands implements CommandMarker { } return toContinueForOtherMembers; - } - Result executeRebalanceOnDS(Cache cache, String simulate, String[] excludeRegionsList) { + Result executeRebalanceOnDS(InternalCache cache, String simulate, String[] excludeRegionsList) { Result result = null; int index = 1; CompositeResultData rebalanceResulteData = ResultBuilder.createCompositeResultData(); @@ -369,7 +366,6 @@ public class DataCommands implements CommandMarker { .createInfoResult(CliStrings.REBALANCE__MSG__NO_REBALANCING_REGIONS_ON_DS); } - Iterator<MemberPRInfo> iterator = listMemberRegion.iterator(); boolean flagToContinueWithRebalance = false; @@ -471,7 +467,7 @@ public class DataCommands implements CommandMarker { return result; } - public boolean checkMemberPresence(DistributedMember dsMember, Cache cache) { + public boolean checkMemberPresence(DistributedMember dsMember, InternalCache cache) { // check if member's presence just before executing function // this is to avoid running a function on departed members #47248 Set<DistributedMember> dsMemberList = CliUtil.getAllNormalMembers(cache); @@ -488,7 +484,7 @@ public class DataCommands implements CommandMarker { } protected CompositeResultData toCompositeResultData(CompositeResultData rebalanceResulteData, - ArrayList<String> rstlist, int index, boolean simulate, Cache cache) { + ArrayList<String> rstlist, int index, boolean simulate, InternalCache cache) { // add only if there are any valid regions in results if (rstlist.size() > resultItemCount && rstlist.get(resultItemCount) != null @@ -565,7 +561,7 @@ public class DataCommands implements CommandMarker { } CompositeResultData buildResultForRebalance(CompositeResultData rebalanceResulteData, - RebalanceResults results, int index, boolean simulate, Cache cache) { + RebalanceResults results, int index, boolean simulate, InternalCache cache) { Set<PartitionRebalanceInfo> regions = results.getPartitionRebalanceDetails(); Iterator iterator = regions.iterator(); @@ -655,13 +651,11 @@ public class DataCommands implements CommandMarker { cache.getLogger().info(headerText + resultStr); } return rebalanceResulteData; - } - public DistributedMember getAssociatedMembers(String region, final Cache cache) { - - DistributedRegionMXBean bean = ManagementService - .getManagementService(GemFireCacheImpl.getInstance()).getDistributedRegionMXBean(region); + public DistributedMember getAssociatedMembers(String region, final InternalCache cache) { + DistributedRegionMXBean bean = + ManagementService.getManagementService(cache).getDistributedRegionMXBean(region); DistributedMember member = null; @@ -688,10 +682,9 @@ public class DataCommands implements CommandMarker { } } return member; - } - List<MemberPRInfo> getMemberRegionList(Cache cache, List<String> listExcludedRegion) { + List<MemberPRInfo> getMemberRegionList(InternalCache cache, List<String> listExcludedRegion) { List<MemberPRInfo> listMemberPRInfo = new ArrayList<MemberPRInfo>(); String[] listDSRegions = ManagementService.getManagementService(cache).getDistributedSystemMXBean().listRegions(); @@ -729,15 +722,12 @@ public class DataCommands implements CommandMarker { if (!regionName.startsWith("/")) { regionName = Region.SEPARATOR + regionName; - } - // remove this prefix / once Rishi fixes this + // remove this prefix / DistributedRegionMXBean bean = - ManagementService.getManagementService(GemFireCacheImpl.getInstance()) - .getDistributedRegionMXBean(regionName); + ManagementService.getManagementService(cache).getDistributedRegionMXBean(regionName); if (bean != null) { - // TODO: Ajay to call a method once Rishi provides if (bean.getRegionType().equals(DataPolicy.PARTITION.toString()) || bean.getRegionType().equals(DataPolicy.PERSISTENT_PARTITION.toString())) { @@ -755,13 +745,11 @@ public class DataCommands implements CommandMarker { listMember.dsMemberList.add(dsmember); } else { listMemberPRInfo.add(memberAndItsPRRegions); - } break; } } } - } } } @@ -769,8 +757,6 @@ public class DataCommands implements CommandMarker { return listMemberPRInfo; } - - @CliCommand(value = CliStrings.EXPORT_DATA, help = CliStrings.EXPORT_DATA__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION}) public Result exportData( @@ -786,7 +772,6 @@ public class DataCommands implements CommandMarker { help = CliStrings.EXPORT_DATA__MEMBER__HELP) String memberNameOrId) { this.securityService.authorizeRegionRead(regionName); - final Cache cache = CacheFactory.getAnyInstance(); final DistributedMember targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId); Result result = null; @@ -850,7 +835,6 @@ public class DataCommands implements CommandMarker { Result result = null; try { - final Cache cache = CacheFactory.getAnyInstance(); final DistributedMember targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId); if (!filePath.endsWith(CliStrings.GEODE_DATA_FILE_EXTENSION)) { @@ -909,7 +893,7 @@ public class DataCommands implements CommandMarker { unspecifiedDefaultValue = "false") boolean putIfAbsent) { this.securityService.authorizeRegionWrite(regionPath); - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); DataCommandResult dataResult = null; if (regionPath == null || regionPath.isEmpty()) { return makePresentationResult(DataCommandResult.createPutResult(key, null, null, @@ -928,8 +912,7 @@ public class DataCommands implements CommandMarker { Region region = cache.getRegion(regionPath); DataCommandFunction putfn = new DataCommandFunction(); if (region == null) { - Set<DistributedMember> memberList = - getRegionAssociatedMembers(regionPath, CacheFactory.getAnyInstance(), false); + Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), false); if (memberList != null && memberList.size() > 0) { DataCommandRequest request = new DataCommandRequest(); request.setCommand(CliStrings.PUT); @@ -978,7 +961,7 @@ public class DataCommands implements CommandMarker { help = CliStrings.GET__LOAD__HELP) Boolean loadOnCacheMiss) { this.securityService.authorizeRegionRead(regionPath, key); - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); DataCommandResult dataResult = null; if (regionPath == null || regionPath.isEmpty()) { @@ -994,8 +977,7 @@ public class DataCommands implements CommandMarker { Region region = cache.getRegion(regionPath); DataCommandFunction getfn = new DataCommandFunction(); if (region == null) { - Set<DistributedMember> memberList = - getRegionAssociatedMembers(regionPath, CacheFactory.getAnyInstance(), false); + Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), false); if (memberList != null && memberList.size() > 0) { DataCommandRequest request = new DataCommandRequest(); request.setCommand(CliStrings.GET); @@ -1054,8 +1036,7 @@ public class DataCommands implements CommandMarker { null, null, CliStrings.LOCATE_ENTRY__MSG__KEY_EMPTY, false)); DataCommandFunction locateEntry = new DataCommandFunction(); - Set<DistributedMember> memberList = - getRegionAssociatedMembers(regionPath, CacheFactory.getAnyInstance(), true); + Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), true); if (memberList != null && memberList.size() > 0) { DataCommandRequest request = new DataCommandRequest(); request.setCommand(CliStrings.LOCATE_ENTRY); @@ -1088,7 +1069,7 @@ public class DataCommands implements CommandMarker { specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean removeAllKeys, @CliOption(key = {CliStrings.REMOVE__KEYCLASS}, help = CliStrings.REMOVE__KEYCLASS__HELP) String keyClass) { - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); DataCommandResult dataResult = null; if (regionPath == null || regionPath.isEmpty()) { @@ -1111,8 +1092,7 @@ public class DataCommands implements CommandMarker { Region region = cache.getRegion(regionPath); DataCommandFunction removefn = new DataCommandFunction(); if (region == null) { - Set<DistributedMember> memberList = - getRegionAssociatedMembers(regionPath, CacheFactory.getAnyInstance(), false); + Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), false); if (memberList != null && memberList.size() > 0) { DataCommandRequest request = new DataCommandRequest(); request.setCommand(CliStrings.REMOVE); @@ -1188,7 +1168,6 @@ public class DataCommands implements CommandMarker { return true; } return false; - } } @@ -1236,11 +1215,10 @@ public class DataCommands implements CommandMarker { } return result; } - } public static Set<DistributedMember> getQueryRegionsAssociatedMembers(Set<String> regions, - final Cache cache, boolean returnAll) { + final InternalCache cache, boolean returnAll) { LogWriter logger = cache.getLogger(); Set<DistributedMember> members = null; Set<DistributedMember> newMembers = null; @@ -1286,8 +1264,8 @@ public class DataCommands implements CommandMarker { } @SuppressWarnings("rawtypes") - public static Set<DistributedMember> getRegionAssociatedMembers(String region, final Cache cache, - boolean returnAll) { + public static Set<DistributedMember> getRegionAssociatedMembers(String region, + final InternalCache cache, boolean returnAll) { DistributedMember member = null; @@ -1336,7 +1314,7 @@ public class DataCommands implements CommandMarker { return matchedMembers; } - // TODO - Abhishek revisit after adding support in Gfsh.java? + // TODO:k revisit after adding support in Gfsh.java? public static Object[] replaceGfshEnvVar(String query, Map<String, String> gfshEnvVarMap) { boolean done = false; int startIndex = 0;
http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/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 a96d3c2..bea7e77 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,13 +14,35 @@ */ 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.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.springframework.shell.core.annotation.CliAvailabilityIndicator; +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; import org.apache.geode.admin.internal.AdminDistributedSystemImpl; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheExistsException; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; import org.apache.geode.cache.execute.Execution; import org.apache.geode.cache.execute.FunctionInvocationTargetException; @@ -32,7 +54,7 @@ import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; import org.apache.geode.internal.cache.DiskStoreAttributes; import org.apache.geode.internal.cache.DiskStoreImpl; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.execute.AbstractExecution; import org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails; import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; @@ -73,35 +95,10 @@ import org.apache.geode.management.internal.messages.CompactRequest; 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.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; - /** * The DiskStoreCommands class encapsulates all GemFire Disk Store commands in Gfsh. - * </p> - * + * * @see org.apache.geode.management.internal.cli.commands.AbstractCommandsSupport * @since GemFire 7.0 */ @@ -109,12 +106,12 @@ import java.util.concurrent.atomic.AtomicReference; public class DiskStoreCommands extends AbstractCommandsSupport { @Override - protected Set<DistributedMember> getMembers(final Cache cache) { + protected Set<DistributedMember> getMembers(final InternalCache cache) { // TODO determine what this does (as it is untested and unmockable!) return CliUtil.getAllMembers(cache); } - protected Set<DistributedMember> getNormalMembers(final Cache cache) { + protected Set<DistributedMember> getNormalMembers(final InternalCache cache) { // TODO determine what this does (as it is untested and unmockable!) return CliUtil.getAllNormalMembers(cache); } @@ -132,7 +129,7 @@ public class DiskStoreCommands extends AbstractCommandsSupport { Result result = null; try { - GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); DM dm = cache.getDistributionManager(); BackupStatus backupStatus = null; @@ -149,9 +146,7 @@ public class DiskStoreCommands extends AbstractCommandsSupport { Set<DistributedMember> backedupMembers = backedupMemberDiskstoreMap.keySet(); CompositeResultData crd = ResultBuilder.createCompositeResultData(); - if (!backedupMembers.isEmpty()) { - SectionResultData backedupDiskStoresSection = crd.addSection(); backedupDiskStoresSection.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_BACKED_UP_DISK_STORES); TabularResultData backedupDiskStoresTable = backedupDiskStoresSection.addTable(); @@ -218,7 +213,6 @@ public class DiskStoreCommands extends AbstractCommandsSupport { backedupDiskStoreTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_HOST, host); } - @CliCommand(value = CliStrings.LIST_DISK_STORE, help = CliStrings.LIST_DISK_STORE__HELP) @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) @@ -353,7 +347,7 @@ public class DiskStoreCommands extends AbstractCommandsSupport { diskStoreAttributes.diskDirs = directories; diskStoreAttributes.diskDirSizes = sizes; - diskStoreAttributes.setDiskUsageWarningPercentage(diskUsageWarningPercentage);; + diskStoreAttributes.setDiskUsageWarningPercentage(diskUsageWarningPercentage); diskStoreAttributes.setDiskUsageCriticalPercentage(diskUsageCriticalPercentage); TabularResultData tabularData = ResultBuilder.createTabularResultData(); @@ -412,7 +406,6 @@ public class DiskStoreCommands extends AbstractCommandsSupport { } } - @CliCommand(value = CliStrings.COMPACT_DISK_STORE, help = CliStrings.COMPACT_DISK_STORE__HELP) @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) @ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE) @@ -432,8 +425,7 @@ public class DiskStoreCommands extends AbstractCommandsSupport { CliStrings.format(CliStrings.COMPACT_DISK_STORE__DISKSTORE_0_DOESNOT_EXIST, new Object[] {diskStoreName})); } else { - InternalDistributedSystem ds = - (InternalDistributedSystem) getCache().getDistributedSystem(); + InternalDistributedSystem ds = getCache().getInternalDistributedSystem(); Map<DistributedMember, PersistentID> overallCompactInfo = new HashMap<DistributedMember, PersistentID>(); @@ -538,7 +530,7 @@ public class DiskStoreCommands extends AbstractCommandsSupport { } private boolean diskStoreExists(String diskStoreName) { - Cache cache = getCache(); + InternalCache cache = getCache(); ManagementService managementService = ManagementService.getExistingManagementService(cache); DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean(); Map<String, String[]> diskstore = dsMXBean.listMemberDiskstore(); @@ -695,7 +687,6 @@ public class DiskStoreCommands extends AbstractCommandsSupport { return result; } - @CliCommand(value = CliStrings.UPGRADE_OFFLINE_DISK_STORE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__HELP) @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) @@ -713,7 +704,6 @@ public class DiskStoreCommands extends AbstractCommandsSupport { help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__J__HELP) String[] jvmProps) throws InterruptedException { - Result result = null; LogWrapper logWrapper = LogWrapper.getInstance(); @@ -794,8 +784,6 @@ public class DiskStoreCommands extends AbstractCommandsSupport { throw new GemFireIOException(errorMessage); } - // do we have to waitFor?? - // upgraderProcess.waitFor(); upgraderProcess.destroy(); result = ResultBuilder.createInfoResult(output.toString()); } catch (IOException e) { @@ -840,8 +828,6 @@ public class DiskStoreCommands extends AbstractCommandsSupport { return result; } - - private String validatedDirectories(String[] diskDirs) { String invalidDirectories = null; StringBuilder builder = null; @@ -1009,8 +995,8 @@ public class DiskStoreCommands extends AbstractCommandsSupport { mandatory = true, help = CliStrings.REVOKE_MISSING_DISK_STORE__ID__HELP) String id) { try { - DistributedSystemMXBean dsMXBean = ManagementService - .getManagementService(CacheFactory.getAnyInstance()).getDistributedSystemMXBean(); + DistributedSystemMXBean dsMXBean = + ManagementService.getManagementService(getCache()).getDistributedSystemMXBean(); if (dsMXBean.revokeMissingDiskStores(id)) { return ResultBuilder.createInfoResult("Missing disk store successfully revoked"); } @@ -1297,10 +1283,8 @@ public class DiskStoreCommands extends AbstractCommandsSupport { return ResultBuilder.createGemFireErrorResult(CliStrings .format(CliStrings.VALIDATE_DISK_STORE__MSG__ERROR, diskStoreName, ex.getMessage())); } - } - @CliCommand(value = CliStrings.ALTER_DISK_STORE, help = CliStrings.ALTER_DISK_STORE__HELP) @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) public Result alterOfflineDiskStore( @@ -1456,7 +1440,6 @@ public class DiskStoreCommands extends AbstractCommandsSupport { } } - if (!accumulatedData) { return ResultBuilder.createInfoResult("No matching disk stores found."); } http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java index 7afb0db..dfd20a9 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java @@ -14,15 +14,29 @@ */ package org.apache.geode.management.internal.cli.commands; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toSet; +import static java.util.stream.Collectors.*; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.Logger; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +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.distributed.internal.ClusterConfigurationService; import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.lang.StringUtils; import org.apache.geode.internal.logging.LogService; import org.apache.geode.management.cli.CliMetaData; @@ -44,24 +58,9 @@ import org.apache.geode.management.internal.configuration.utils.ZipUtils; 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.logging.log4j.Logger; -import org.springframework.shell.core.annotation.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; -/**** +/** * Commands for the cluster configuration - * */ @SuppressWarnings("unused") public class ExportImportClusterConfigurationCommands extends AbstractCommandsSupport { @@ -117,7 +116,6 @@ public class ExportImportClusterConfigurationCommands extends AbstractCommandsSu return result; } - @CliCommand(value = {CliStrings.IMPORT_SHARED_CONFIG}, help = CliStrings.IMPORT_SHARED_CONFIG__HELP) @CliMetaData( @@ -136,7 +134,7 @@ public class ExportImportClusterConfigurationCommands extends AbstractCommandsSu return ResultBuilder.buildResult(errorData); } - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + InternalCache cache = getCache(); Set<DistributedMember> servers = CliUtil.getAllNormalMembers(cache); @@ -149,7 +147,6 @@ public class ExportImportClusterConfigurationCommands extends AbstractCommandsSu + regionsWithData.stream().collect(joining(","))); } - byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell(); String zipFileName = CliUtil.bytesToNames(shellBytesData)[0]; byte[] zipBytes = CliUtil.bytesToData(shellBytesData)[0]; @@ -261,7 +258,6 @@ public class ExportImportClusterConfigurationCommands extends AbstractCommandsSu } } - public static class ImportInterceptor extends AbstractCliAroundInterceptor { public Result preExecution(GfshParseResult parseResult) { http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java index 647fff2..20ec1f5 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java @@ -12,14 +12,30 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - package org.apache.geode.management.internal.cli.commands; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; +import org.apache.logging.log4j.Logger; +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + +import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.logging.LogService; import org.apache.geode.management.cli.CliMetaData; import org.apache.geode.management.cli.ConverterHint; @@ -34,21 +50,6 @@ import org.apache.geode.management.internal.cli.util.ExportLogsCacheWriter; import org.apache.geode.management.internal.configuration.utils.ZipUtils; import org.apache.geode.management.internal.security.ResourceOperation; import org.apache.geode.security.ResourcePermission; -import org.apache.logging.log4j.Logger; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class ExportLogsCommand implements CommandMarker { @@ -61,6 +62,10 @@ public class ExportLogsCommand implements CommandMarker { private static final Pattern DISK_SPACE_LIMIT_PATTERN = Pattern.compile("(\\d+)([mgtMGT]?)"); + private InternalCache getCache() { + return (InternalCache) CacheFactory.getAnyInstance(); + } + @CliCommand(value = CliStrings.EXPORT_LOGS, help = CliStrings.EXPORT_LOGS__HELP) @CliMetaData(shellOnly = false, isFileDownloadOverHttp = true, interceptor = "org.apache.geode.management.internal.cli.commands.ExportLogsInterceptor", @@ -103,7 +108,7 @@ public class ExportLogsCommand implements CommandMarker { // specifiedDefaultValue = CliStrings.EXPORT_LOGS__FILESIZELIMIT__SPECIFIED_DEFAULT, // help = CliStrings.EXPORT_LOGS__FILESIZELIMIT__HELP) String fileSizeLimit) { Result result = null; - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + InternalCache cache = getCache(); try { Set<DistributedMember> targetMembers = CliUtil.findMembersIncludingLocators(groups, memberIds); @@ -194,13 +199,6 @@ public class ExportLogsCommand implements CommandMarker { ZipUtils.zipDirectory(exportedLogsDir, exportedLogsZipFile); FileUtils.deleteDirectory(tempDir.toFile()); - // try { - // isFileSizeCheckEnabledAndWithinLimit(parseFileSizeLimit(fileSizeLimit), - // exportedLogsZipFile.toFile()); - // } catch (IllegalArgumentException e) { - // return ResultBuilder.createUserErrorResult("TOO BIG: fileSizeLimit = " + fileSizeLimit); - // } - result = ResultBuilder.createInfoResult(exportedLogsZipFile.toString()); } catch (Exception ex) { logger.error(ex.getMessage(), ex); http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java index e21a334..d19f91b 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommands.java @@ -14,8 +14,21 @@ */ package org.apache.geode.management.internal.cli.commands; +import java.util.ArrayList; +import java.util.Arrays; +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 org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.SystemFailure; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; import org.apache.geode.cache.execute.Execution; @@ -25,7 +38,7 @@ import org.apache.geode.cache.execute.FunctionService; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.internal.ClassPathLoader; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.management.DistributedRegionMXBean; import org.apache.geode.management.ManagementService; import org.apache.geode.management.cli.CliMetaData; @@ -51,32 +64,23 @@ 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.CliAvailabilityIndicator; -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.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; /** - * * @since GemFire 7.0 */ @SuppressWarnings("unused") public class FunctionCommands implements CommandMarker { + private final ListFunctionFunction listFunctionFunction = new ListFunctionFunction(); private Gfsh getGfsh() { return Gfsh.getCurrentInstance(); } + private InternalCache getCache() { + return (InternalCache) CacheFactory.getAnyInstance(); + } + @CliCommand(value = CliStrings.EXECUTE_FUNCTION, help = CliStrings.EXECUTE_FUNCTION__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_FUNCTION}) @ResourceOperation(resource = Resource.DATA, operation = Operation.WRITE) @@ -176,8 +180,7 @@ public class FunctionCommands implements CommandMarker { return result; } - Cache cache = CacheFactory.getAnyInstance(); - + InternalCache cache = getCache(); if (resultCollector != null) { resultCollectorInstance = @@ -208,11 +211,10 @@ public class FunctionCommands implements CommandMarker { } else if (onRegion != null && onRegion.length() > 0) { if (cache.getRegion(onRegion) == null) { // find a member where region is present - DistributedRegionMXBean bean = - ManagementService.getManagementService(GemFireCacheImpl.getInstance()) - .getDistributedRegionMXBean(onRegion); + DistributedRegionMXBean bean = ManagementService.getManagementService(getCache()) + .getDistributedRegionMXBean(onRegion); if (bean == null) { - bean = ManagementService.getManagementService(GemFireCacheImpl.getInstance()) + bean = ManagementService.getManagementService(getCache()) .getDistributedRegionMXBean(Region.SEPARATOR + onRegion); if (bean == null) { @@ -350,7 +352,7 @@ public class FunctionCommands implements CommandMarker { return result; } - DistributedMember getMember(Cache cache, String memberNameOrId) { + DistributedMember getMember(InternalCache cache, String memberNameOrId) { DistributedMember member = null; Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache); Iterator<DistributedMember> it = dsMembers.iterator(); @@ -365,8 +367,8 @@ public class FunctionCommands implements CommandMarker { } void executeAndGetResults(String functionId, String filterString, String resultCollector, - String[] arguments, Cache cache, DistributedMember member, TabularResultData resultTable, - String onRegion) { + String[] arguments, InternalCache cache, DistributedMember member, + TabularResultData resultTable, String onRegion) { StringBuilder resultMessege = new StringBuilder(); try { Function function = new UserFunctionExecution(); @@ -448,7 +450,7 @@ public class FunctionCommands implements CommandMarker { help = CliStrings.DESTROY_FUNCTION__ONMEMBER__HELP) String memberId) { Result result = null; try { - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); Set<DistributedMember> dsMembers = new HashSet<DistributedMember>(); if (groups != null && memberId != null) { return ResultBuilder @@ -479,7 +481,6 @@ public class FunctionCommands implements CommandMarker { result = ResultBuilder.buildResult(errorResultData); return result; } - } /** @@ -510,7 +511,7 @@ public class FunctionCommands implements CommandMarker { } } - Result executeFunction(Cache cache, Set<DistributedMember> DsMembers, String functionId) { + Result executeFunction(InternalCache cache, Set<DistributedMember> DsMembers, String functionId) { // unregister on a set of of members Function unregisterFunction = new UnregisterFunction(); FunctionService.registerFunction(unregisterFunction); @@ -565,7 +566,7 @@ public class FunctionCommands implements CommandMarker { TabularResultData tabularData = ResultBuilder.createTabularResultData(); boolean accumulatedData = false; - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); Set<DistributedMember> targetMembers; try { http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java index 080d520..1a7e2df 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java @@ -22,6 +22,7 @@ import org.apache.geode.cache.execute.Execution; import org.apache.geode.cache.execute.FunctionInvocationTargetException; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.execute.AbstractExecution; import org.apache.geode.internal.lang.StringUtils; import org.apache.geode.internal.security.IntegratedSecurityService; @@ -85,7 +86,7 @@ public class IndexCommands extends AbstractCommandsSupport { private SecurityService securityService = IntegratedSecurityService.getSecurityService(); @Override - protected Set<DistributedMember> getMembers(final Cache cache) { + protected Set<DistributedMember> getMembers(final InternalCache cache) { // TODO determine what this does (as it is untested and unmockable!) return CliUtil.getAllMembers(cache); } http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java index c647e98..415dd69 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java @@ -20,12 +20,17 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; -import org.apache.geode.cache.Cache; +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.cache.CacheClosedException; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.execute.FunctionInvocationTargetException; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.management.cli.CliMetaData; import org.apache.geode.management.cli.ConverterHint; import org.apache.geode.management.cli.Result; @@ -44,17 +49,11 @@ 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.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -/*** - * - * +/** * @since GemFire 7.0 */ public class MemberCommands implements CommandMarker { + private Gfsh getGfsh() { return Gfsh.getCurrentInstance(); } @@ -73,7 +72,7 @@ public class MemberCommands implements CommandMarker { // TODO: Add the code for identifying the system services try { Set<DistributedMember> memberSet = new TreeSet<DistributedMember>(); - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); // default get all the members in the DS if (group.isEmpty()) { @@ -105,6 +104,10 @@ public class MemberCommands implements CommandMarker { return result; } + private InternalCache getCache() { + return (InternalCache) CacheFactory.getAnyInstance(); + } + @CliCommand(value = {CliStrings.DESCRIBE_MEMBER}, help = CliStrings.DESCRIBE_MEMBER__HELP) @CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_SERVER) @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) @@ -118,9 +121,10 @@ public class MemberCommands implements CommandMarker { CliUtil.getDistributedMemberByNameOrId(memberNameOrId); if (memberToBeDescribed != null) { - // Abhishek - This information should be available through the MBeans too. We might not need + // This information should be available through the MBeans too. We might not need // the function. - // Sourabh - Yes, but then the command is subject to Mbean availability, which would be + + // Yes, but then the command is subject to Mbean availability, which would be // affected once MBean filters are used. ResultCollector<?, ?> rc = @@ -149,12 +153,12 @@ public class MemberCommands implements CommandMarker { section.addData("Groups", memberInformation.getGroups()); section.addData("Used Heap", memberInformation.getHeapUsage() + "M"); section.addData("Max Heap", memberInformation.getMaxHeapSize() + "M"); - { - String offHeapMemorySize = memberInformation.getOffHeapMemorySize(); - if (offHeapMemorySize != null && !offHeapMemorySize.isEmpty()) { - section.addData("Off Heap Size", offHeapMemorySize); - } + + String offHeapMemorySize = memberInformation.getOffHeapMemorySize(); + if (offHeapMemorySize != null && !offHeapMemorySize.isEmpty()) { + section.addData("Off Heap Size", offHeapMemorySize); } + section.addData("Working Dir", memberInformation.getWorkingDirPath()); section.addData("Log file", memberInformation.getLogFilePath()); http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java index b5fb9fe..6b63f09 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java @@ -14,9 +14,44 @@ */ package org.apache.geode.management.internal.cli.commands; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +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.Callable; +import java.util.concurrent.ExecutionException; +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 java.util.zip.DataFormatException; +import java.util.zip.GZIPInputStream; + +import javax.management.ObjectName; + import org.apache.commons.lang.StringUtils; +import org.apache.logging.log4j.Logger; +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; + import org.apache.geode.LogWriter; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.execute.Execution; import org.apache.geode.cache.execute.Function; @@ -30,7 +65,9 @@ import org.apache.geode.distributed.internal.deadlock.Dependency; import org.apache.geode.distributed.internal.deadlock.DependencyGraph; import org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector; import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.logging.LogService; +import org.apache.geode.internal.logging.log4j.LogLevel; import org.apache.geode.management.CacheServerMXBean; import org.apache.geode.management.DistributedRegionMXBean; import org.apache.geode.management.DistributedSystemMXBean; @@ -70,49 +107,15 @@ import org.apache.geode.management.internal.cli.result.ResultData; import org.apache.geode.management.internal.cli.result.ResultDataException; import org.apache.geode.management.internal.cli.result.TabularResultData; import org.apache.geode.management.internal.cli.shell.Gfsh; -import org.apache.geode.internal.logging.log4j.LogLevel; 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.logging.log4j.Logger; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -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.Callable; -import java.util.concurrent.ExecutionException; -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 java.util.zip.DataFormatException; -import java.util.zip.GZIPInputStream; -import javax.management.ObjectName; /** * @since GemFire 7.0 */ public class MiscellaneousCommands implements CommandMarker { + public static final String NETSTAT_FILE_REQUIRED_EXTENSION = ".txt"; public final static String DEFAULT_TIME_OUT = "10"; private final static Logger logger = LogService.getLogger(); @@ -123,6 +126,9 @@ public class MiscellaneousCommands implements CommandMarker { return Gfsh.getCurrentInstance(); } + private InternalCache getCache() { + return (InternalCache) CacheFactory.getAnyInstance(); + } public void shutdownNode(final long timeout, final Set<DistributedMember> includeMembers) throws TimeoutException, InterruptedException, ExecutionException { @@ -145,7 +151,6 @@ public class MiscellaneousCommands implements CommandMarker { } return "SUCCESS"; } - }; Future<String> result = exec.submit(shutdownNodes); @@ -163,10 +168,8 @@ public class MiscellaneousCommands implements CommandMarker { } finally { exec.shutdownNow(); } - } - @CliCommand(value = CliStrings.SHUTDOWN, help = CliStrings.SHUTDOWN__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_LIFECYCLE}, interceptor = "org.apache.geode.management.internal.cli.commands.MiscellaneousCommands$Interceptor") @@ -185,7 +188,7 @@ public class MiscellaneousCommands implements CommandMarker { // convert to mili-seconds long timeout = userSpecifiedTimeout * 1000; - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); int numDataNodes = CliUtil.getAllNormalMembers(cache).size(); @@ -199,9 +202,7 @@ public class MiscellaneousCommands implements CommandMarker { return ResultBuilder.createInfoResult(CliStrings.SHUTDOWN__MSG__NO_DATA_NODE_FOUND); } - GemFireCacheImpl gemFireCache = (GemFireCacheImpl) cache; - String managerName = - gemFireCache.getJmxManagerAdvisor().getDistributionManager().getId().getId(); + String managerName = cache.getJmxManagerAdvisor().getDistributionManager().getId().getId(); final DistributedMember manager = CliUtil.getDistributedMemberByNameOrId(managerName); @@ -251,7 +252,6 @@ public class MiscellaneousCommands implements CommandMarker { // @TODO. List all the nodes which could be successfully shutdown return ResultBuilder.createInfoResult("Shutdown is triggered"); - } /** @@ -269,10 +269,8 @@ public class MiscellaneousCommands implements CommandMarker { long timeElapsed = shutDownTimeEnd - shutDownTimeStart; - if (timeElapsed > timeout || Boolean.getBoolean("ThrowTimeoutException")) { // The second check - // for - // ThrowTimeoutException - // is a test hook + if (timeElapsed > timeout || Boolean.getBoolean("ThrowTimeoutException")) { + // The second check for ThrowTimeoutException is a test hook throw new TimeoutException(); } return timeElapsed; @@ -310,7 +308,7 @@ public class MiscellaneousCommands implements CommandMarker { @CliOption(key = CliStrings.GC__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.GC__MEMBER__HELP) String memberId) { - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); Result result = null; CompositeResultData gcResultTable = ResultBuilder.createCompositeResultData(); TabularResultData resultTable = gcResultTable.addSection().addTable("Table1"); @@ -324,25 +322,24 @@ public class MiscellaneousCommands implements CommandMarker { .createGemFireErrorResult(memberId + CliStrings.GC__MSG__MEMBER_NOT_FOUND); } dsMembers.add(member); - result = executeAndBuildResult(cache, resultTable, dsMembers); + result = executeAndBuildResult(resultTable, dsMembers); } else if (groups != null && groups.length > 0) { for (String group : groups) { dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(group)); } - result = executeAndBuildResult(cache, resultTable, dsMembers); + result = executeAndBuildResult(resultTable, dsMembers); } else { // gc on entire cluster // exclude locators dsMembers = CliUtil.getAllNormalMembers(cache); - result = executeAndBuildResult(cache, resultTable, dsMembers); + result = executeAndBuildResult(resultTable, dsMembers); } return result; } - Result executeAndBuildResult(Cache cache, TabularResultData resultTable, - Set<DistributedMember> dsMembers) { + Result executeAndBuildResult(TabularResultData resultTable, Set<DistributedMember> dsMembers) { try { List<?> resultList = null; Function garbageCollectionFunction = new GarbageCollectionFunction(); @@ -391,7 +388,6 @@ public class MiscellaneousCommands implements CommandMarker { table.accumulate(CliStrings.GC__MSG__TOTAL_TIME_IN_GC, timeTaken); } - @CliCommand(value = CliStrings.NETSTAT, help = CliStrings.NETSTAT__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DEBUG_UTIL}) @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) @@ -568,7 +564,7 @@ public class MiscellaneousCommands implements CommandMarker { return ResultBuilder .createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, ".txt")); } - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); Set<DistributedMember> allMembers = CliUtil.getAllMembers(cache); GemFireDeadlockDetector gfeDeadLockDetector = new GemFireDeadlockDetector(allMembers); @@ -617,7 +613,7 @@ public class MiscellaneousCommands implements CommandMarker { help = CliStrings.SHOW_LOG_LINE_NUM_HELP, mandatory = false) int numberOfLines) { Result result = null; try { - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache); MemberMXBean bean = null; @@ -651,7 +647,6 @@ public class MiscellaneousCommands implements CommandMarker { ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT) .addLine(memberNameOrId + CliStrings.SHOW_LOG_MSG_MEMBER_NOT_FOUND); return (ResultBuilder.buildResult(errorResultData)); - } result = ResultBuilder.buildResult(resultData); @@ -660,7 +655,6 @@ public class MiscellaneousCommands implements CommandMarker { ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT) .addLine(memberNameOrId + CliStrings.SHOW_LOG_MSG_MEMBER_NOT_FOUND); return (ResultBuilder.buildResult(errorResultData)); - } } catch (Exception e) { @@ -670,11 +664,8 @@ public class MiscellaneousCommands implements CommandMarker { return result; } - /**** + /** * Current implementation supports writing it to a file and returning the location of the file - * - * @param memberNameOrId - * @return Stack Trace */ @CliCommand(value = CliStrings.EXPORT_STACKTRACE, help = CliStrings.EXPORT_STACKTRACE__HELP) @CliMetaData(shellOnly = false, relatedTopic = {CliStrings.TOPIC_GEODE_DEBUG_UTIL}) @@ -706,9 +697,8 @@ public class MiscellaneousCommands implements CommandMarker { CliStrings.EXPORT_STACKTRACE__ERROR__FILE__PRESENT, outFile.getCanonicalPath())); } - Cache cache = CacheFactory.getAnyInstance(); - GemFireCacheImpl gfeCacheImpl = (GemFireCacheImpl) cache; - InternalDistributedSystem ads = gfeCacheImpl.getSystem(); + InternalCache cache = getCache(); + InternalDistributedSystem ads = cache.getInternalDistributedSystem(); InfoResultData resultData = ResultBuilder.createInfoResultData(); @@ -778,7 +768,6 @@ public class MiscellaneousCommands implements CommandMarker { * @throws IOException */ private String writeStacksToFile(Map<String, byte[]> dumps, String fileName) throws IOException { - String filePath = null; OutputStream os = null; PrintWriter ps = null; @@ -897,17 +886,15 @@ public class MiscellaneousCommands implements CommandMarker { return result; } - /**** + /** * Gets the system wide metrics * - * @param export_to_report_to * @return ResultData with required System wide statistics or ErrorResultData if DS MBean is not * found to gather metrics - * @throws Exception */ private ResultData getSystemWideMetrics(String export_to_report_to, String[] categoriesArr) throws Exception { - final Cache cache = CacheFactory.getAnyInstance(); + final InternalCache cache = getCache(); final ManagementService managmentService = ManagementService.getManagementService(cache); DistributedSystemMXBean dsMxBean = managmentService.getDistributedSystemMXBean(); StringBuilder csvBuilder = null; @@ -1001,14 +988,11 @@ public class MiscellaneousCommands implements CommandMarker { CliStrings.format(CliStrings.SHOW_METRICS__ERROR, "Distributed System MBean not found"); return ResultBuilder.createErrorResultData().addLine(errorMessage); } - } - /*** + /** * Gets the Cluster wide metrics for a given member * - * @param distributedMember - * @param export_to_report_to * @return ResultData with required Member statistics or ErrorResultData if MemberMbean is not * found to gather metrics * @throws ResultDataException if building result fails @@ -1016,7 +1000,7 @@ public class MiscellaneousCommands implements CommandMarker { private ResultData getMemberMetrics(DistributedMember distributedMember, String export_to_report_to, String[] categoriesArr, int cacheServerPort) throws ResultDataException { - final Cache cache = CacheFactory.getAnyInstance(); + final InternalCache cache = getCache(); final SystemManagementService managementService = (SystemManagementService) ManagementService.getManagementService(cache); @@ -1086,7 +1070,7 @@ public class MiscellaneousCommands implements CommandMarker { } } - /**** + /* * Member Metrics */ // member, jvm, region, serialization, communication, function, transaction, diskstore, lock, @@ -1100,7 +1084,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "maximumHeapSize", memberMxBean.getMaximumHeapSize(), csvBuilder); } - /**** + /* * JVM Metrics */ if (categoriesMap.get("jvm").booleanValue()) { @@ -1111,7 +1095,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "totalFileDescriptorOpen", memberMxBean.getTotalFileDescriptorOpen(), csvBuilder); } - /*** + /* * Member wide region metrics */ if (categoriesMap.get("region").booleanValue()) { @@ -1170,10 +1154,9 @@ public class MiscellaneousCommands implements CommandMarker { memberMxBean.getCacheListenerCallsAvgLatency(), csvBuilder); writeToTableAndCsv(metricsTable, "", "totalLoadsCompleted", memberMxBean.getTotalLoadsCompleted(), csvBuilder); - } - /****** + /* * SERIALIZATION */ if (categoriesMap.get("serialization").booleanValue()) { @@ -1193,9 +1176,8 @@ public class MiscellaneousCommands implements CommandMarker { memberMxBean.getPDXDeserializationRate(), csvBuilder); } - /*** + /* * Communication Metrics - * */ if (categoriesMap.get("communication").booleanValue()) { writeToTableAndCsv(metricsTable, "communication", "bytesSentRate", @@ -1209,12 +1191,10 @@ public class MiscellaneousCommands implements CommandMarker { String[] connectedGatewaySenders = memberMxBean.listConnectedGatewaySenders(); writeToTableAndCsv(metricsTable, "", "connectedGatewaySenders", connectedGatewaySenders, csvBuilder); - } - /*** + /* * Member wide function metrics - * */ if (categoriesMap.get("function").booleanValue()) { writeToTableAndCsv(metricsTable, "function", "numRunningFunctions", @@ -1228,7 +1208,7 @@ public class MiscellaneousCommands implements CommandMarker { // memberMxBean.getFuncExecutionQueueSize(), csvBuilder); } - /*** + /* * totalTransactionsCount currentTransactionalThreadIds transactionCommitsAvgLatency * transactionCommittedTotalCount transactionRolledBackTotalCount transactionCommitsRate */ @@ -1245,7 +1225,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "transactionCommitsRate", memberMxBean.getTransactionCommitsRate(), csvBuilder); } - /*** + /* * Member wide disk metrics */ if (categoriesMap.get("diskstore").booleanValue()) { @@ -1263,7 +1243,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "totalBackupInProgress", memberMxBean.getTotalBackupInProgress(), csvBuilder); } - /*** + /* * Member wide Lock */ if (categoriesMap.get("lock").booleanValue()) { @@ -1276,7 +1256,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "requestQueues", memberMxBean.getLockRequestQueues(), csvBuilder); } - /**** + /* * Eviction */ if (categoriesMap.get("eviction").booleanValue()) { @@ -1285,7 +1265,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "lruDestroyRate", memberMxBean.getLruDestroyRate(), csvBuilder); } - /*** + /* * Distribution */ if (categoriesMap.get("distribution").booleanValue()) { @@ -1297,7 +1277,7 @@ public class MiscellaneousCommands implements CommandMarker { memberMxBean.getInitialImageKeysReceived(), csvBuilder); } - /*** + /* * OffHeap */ if (categoriesMap.get("offheap").booleanValue()) { @@ -1315,7 +1295,7 @@ public class MiscellaneousCommands implements CommandMarker { memberMxBean.getOffHeapCompactionTime(), csvBuilder); } - /*** + /* * CacheServer stats */ if (csMxBean != null) { @@ -1345,7 +1325,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "putRequestRate", csMxBean.getPutRequestRate(), csvBuilder); - /***** + /* * Notification */ writeToTableAndCsv(metricsTable, "notification", "numClientNotificationRequests", @@ -1355,7 +1335,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "clientNotificationAvgLatency", csMxBean.getClientNotificationAvgLatency(), csvBuilder); - /*** + /* * Query */ writeToTableAndCsv(metricsTable, "query", "activeCQCount", csMxBean.getActiveCQCount(), @@ -1369,7 +1349,6 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "index list", indexList, csvBuilder); writeToTableAndCsv(metricsTable, "", "totalIndexMaintenanceTime", csMxBean.getTotalIndexMaintenanceTime(), csvBuilder); - } if (export_to_report_to != null && !export_to_report_to.isEmpty()) { @@ -1386,17 +1365,16 @@ public class MiscellaneousCommands implements CommandMarker { } } - /**** + /** * Gets the Cluster-wide metrics for a region * - * @param regionName * @return ResultData containing the table * @throws ResultDataException if building result fails */ private ResultData getDistributedRegionMetrics(String regionName, String export_to_report_to, String[] categoriesArr) throws ResultDataException { - final Cache cache = CacheFactory.getAnyInstance(); + final InternalCache cache = getCache(); final ManagementService managementService = ManagementService.getManagementService(cache); DistributedRegionMXBean regionMxBean = managementService.getDistributedRegionMXBean(regionName); @@ -1444,7 +1422,7 @@ public class MiscellaneousCommands implements CommandMarker { return ResultBuilder.createErrorResultData().addLine(sb.toString()); } } - /*** + /* * General System metrics */ // cluster, region, partition , diskstore, callback, eviction @@ -1471,7 +1449,6 @@ public class MiscellaneousCommands implements CommandMarker { csvBuilder); writeToTableAndCsv(metricsTable, "", "putAllRate", regionMxBean.getPutAllRate(), csvBuilder); - } if (categoriesMap.get("partition").booleanValue()) { @@ -1495,7 +1472,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "averageBucketSize", regionMxBean.getAvgBucketSize(), csvBuilder); } - /***** + /* * Disk store */ if (categoriesMap.get("diskstore").booleanValue()) { @@ -1511,7 +1488,7 @@ public class MiscellaneousCommands implements CommandMarker { csvBuilder); } - /***** + /* * LISTENER */ if (categoriesMap.get("callback").booleanValue()) { @@ -1521,7 +1498,7 @@ public class MiscellaneousCommands implements CommandMarker { regionMxBean.getCacheListenerCallsAvgLatency(), csvBuilder); } - /**** + /* * Eviction */ if (categoriesMap.get("eviction").booleanValue()) { @@ -1546,12 +1523,9 @@ public class MiscellaneousCommands implements CommandMarker { } } - /*** + /** * Gets the metrics of region on a given member * - * @param regionName - * @param distributedMember - * @param export_to_report_to * @return ResultData with required Region statistics or ErrorResultData if Region MBean is not * found to gather metrics * @throws ResultDataException if building result fails @@ -1560,7 +1534,7 @@ public class MiscellaneousCommands implements CommandMarker { DistributedMember distributedMember, String export_to_report_to, String[] categoriesArr) throws ResultDataException { - final Cache cache = CacheFactory.getAnyInstance(); + final InternalCache cache = getCache(); final SystemManagementService managementService = (SystemManagementService) ManagementService.getManagementService(cache); @@ -1587,7 +1561,7 @@ public class MiscellaneousCommands implements CommandMarker { csvBuilder.append('\n'); } - /**** + /* * Region Metrics */ Map<String, Boolean> categoriesMap = getRegionMetricsCategories(); @@ -1657,10 +1631,8 @@ public class MiscellaneousCommands implements CommandMarker { regionMxBean.getNumBucketsWithoutRedundancy(), csvBuilder); writeToTableAndCsv(metricsTable, "", "totalBucketSize", regionMxBean.getTotalBucketSize(), csvBuilder); - // writeToTableAndCsv(metricsTable, "", "averageBucketSize", - // regionMxBean.getAvgBucketSize(), csvBuilder); } - /***** + /* * Disk store */ if (categoriesMap.get("diskstore").booleanValue()) { @@ -1675,7 +1647,7 @@ public class MiscellaneousCommands implements CommandMarker { writeToTableAndCsv(metricsTable, "", "diskTaskWaiting", regionMxBean.getDiskTaskWaiting(), csvBuilder); } - /***** + /* * LISTENER */ if (categoriesMap.get("callback").booleanValue()) { @@ -1685,7 +1657,7 @@ public class MiscellaneousCommands implements CommandMarker { regionMxBean.getCacheListenerCallsAvgLatency(), csvBuilder); } - /**** + /* * Eviction */ if (categoriesMap.get("eviction").booleanValue()) { @@ -1708,18 +1680,10 @@ public class MiscellaneousCommands implements CommandMarker { erd.addLine(errorMessage); return erd; } - } - /*** * Writes an entry to a TabularResultData and writes a comma separated entry to a string builder - * - * @param metricsTable - * @param type - * @param metricName - * @param metricValue - * @param csvBuilder */ private void writeToTableAndCsv(TabularResultData metricsTable, String type, String metricName, long metricValue, StringBuilder csvBuilder) { @@ -1737,14 +1701,6 @@ public class MiscellaneousCommands implements CommandMarker { } } - /*** - * - * @param metricsTable - * @param type - * @param metricName - * @param metricValue - * @param csvBuilder - */ private void writeToTableAndCsv(TabularResultData metricsTable, String type, String metricName, double metricValue, StringBuilder csvBuilder) { metricsTable.accumulate(CliStrings.SHOW_METRICS__TYPE__HEADER, type); @@ -1769,7 +1725,7 @@ public class MiscellaneousCommands implements CommandMarker { return categoriesSet; } - /**** + /** * Defines and returns map of categories for System metrics. * * @return map with categories for system metrics and display flag set to true @@ -1783,7 +1739,7 @@ public class MiscellaneousCommands implements CommandMarker { return categories; } - /**** + /** * Defines and returns map of categories for Region Metrics * * @return map with categories for region metrics and display flag set to true @@ -1802,7 +1758,7 @@ public class MiscellaneousCommands implements CommandMarker { return categories; } - /**** + /** * Defines and returns map of categories for system-wide region metrics * * @return map with categories for system wide region metrics and display flag set to true @@ -1813,7 +1769,7 @@ public class MiscellaneousCommands implements CommandMarker { return categories; } - /***** + /** * Defines and returns map of categories for member metrics * * @return map with categories for member metrics and display flag set to true @@ -1835,11 +1791,9 @@ public class MiscellaneousCommands implements CommandMarker { return categories; } - /*** + /** * Converts an array of strings to a String delimited by a new line character for display purposes * - * @param names - * @param startIndex * @return a String delimited by a new line character for display purposes */ private String formatNames(String[] names, int startIndex) { @@ -1867,14 +1821,8 @@ public class MiscellaneousCommands implements CommandMarker { } } - /*** + /** * Writes to a TabularResultData and also appends a CSV string to a String builder - * - * @param metricsTable - * @param type - * @param metricName - * @param metricValue - * @param csvBuilder */ private void writeToTableAndCsv(TabularResultData metricsTable, String type, String metricName, String metricValue, StringBuilder csvBuilder) { @@ -1892,7 +1840,6 @@ public class MiscellaneousCommands implements CommandMarker { } } - @CliCommand(value = CliStrings.CHANGE_LOGLEVEL, help = CliStrings.CHANGE_LOGLEVEL__HELP) @CliMetaData(relatedTopic = {CliStrings.TOPIC_LOGS}, interceptor = "org.apache.geode.management.internal.cli.commands.MiscellaneousCommands$ChangeLogLevelInterceptor") @@ -1911,7 +1858,7 @@ public class MiscellaneousCommands implements CommandMarker { .createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__SPECIFY_GRP_OR_MEMBER); } - Cache cache = GemFireCacheImpl.getInstance(); + InternalCache cache = GemFireCacheImpl.getInstance(); LogWriter logger = cache.getLogger(); Set<DistributedMember> dsMembers = new HashSet<DistributedMember>(); @@ -2008,7 +1955,6 @@ public class MiscellaneousCommands implements CommandMarker { } } - @CliAvailabilityIndicator({CliStrings.SHUTDOWN, CliStrings.GC, CliStrings.SHOW_DEADLOCK, CliStrings.SHOW_METRICS, CliStrings.SHOW_LOG, CliStrings.EXPORT_STACKTRACE, CliStrings.NETSTAT, CliStrings.EXPORT_LOGS, CliStrings.CHANGE_LOGLEVEL}) http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/RegionCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/RegionCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/RegionCommands.java index 0bf80a5..fd03298 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/RegionCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/RegionCommands.java @@ -22,19 +22,17 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -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.CliAvailabilityIndicator; import org.springframework.shell.core.annotation.CliCommand; import org.springframework.shell.core.annotation.CliOption; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; import org.apache.geode.cache.execute.FunctionInvocationTargetException; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.management.cli.CliMetaData; import org.apache.geode.management.cli.ConverterHint; import org.apache.geode.management.cli.Result; @@ -55,8 +53,10 @@ import org.apache.geode.management.internal.cli.result.TabularResultData; import org.apache.geode.management.internal.cli.shell.Gfsh; import org.apache.geode.management.internal.cli.util.RegionAttributesNames; import org.apache.geode.management.internal.security.ResourceOperation; +import org.apache.geode.security.ResourcePermission.Operation; +import org.apache.geode.security.ResourcePermission.Resource; -/*** +/** * Class containing implementation of commands based on region: * <ul> * <li>list region @@ -66,6 +66,7 @@ import org.apache.geode.management.internal.security.ResourceOperation; * @since GemFire 7.0 */ public class RegionCommands implements CommandMarker { + private Gfsh getGfsh() { return Gfsh.getCurrentInstance(); } @@ -168,7 +169,7 @@ public class RegionCommands implements CommandMarker { return ResultBuilder.createUserErrorResult(CliStrings.INVALID_REGION_NAME); } - Cache cache = CacheFactory.getAnyInstance(); + InternalCache cache = getCache(); ResultCollector<?, ?> rc = CliUtil.executeFunction(getRegionDescription, regionName, CliUtil.getAllMembers(cache)); @@ -484,7 +485,6 @@ public class RegionCommands implements CommandMarker { table.accumulate(CliStrings.DESCRIBE_REGION__ATTRIBUTE__VALUE, value); } } - } } @@ -503,10 +503,13 @@ public class RegionCommands implements CommandMarker { @CliAvailabilityIndicator({CliStrings.LIST_REGION, CliStrings.DESCRIBE_REGION}) public boolean isRegionCommandAvailable() { boolean isAvailable = true; // always available on server - if (CliUtil.isGfshVM()) { // in gfsh check if connected //TODO - Abhishek: make this better + if (CliUtil.isGfshVM()) { // in gfsh check if connected //TODO : make this better isAvailable = getGfsh() != null && getGfsh().isConnectedAndReady(); } return isAvailable; } + private InternalCache getCache() { + return (InternalCache) CacheFactory.getAnyInstance(); + } } http://git-wip-us.apache.org/repos/asf/geode/blob/153db276/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java index 5cf5ff1..f8d27de 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java @@ -18,9 +18,14 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +import org.springframework.shell.core.annotation.CliCommand; + import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.management.cli.CliMetaData; import org.apache.geode.management.cli.Result; import org.apache.geode.management.cli.Result.Status; @@ -35,11 +40,6 @@ 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.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; - - public class StatusCommands extends AbstractCommandsSupport implements CommandMarker { static final FetchSharedConfigurationStatusFunction fetchSharedConfigStatusFunction = new FetchSharedConfigurationStatusFunction(); @@ -49,7 +49,7 @@ public class StatusCommands extends AbstractCommandsSupport implements CommandMa @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_LOCATOR) @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ) public Result statusSharedConfiguration() { - final GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); + final InternalCache cache = GemFireCacheImpl.getInstance(); final Set<DistributedMember> locators = new HashSet<DistributedMember>( cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration().keySet()); if (locators.isEmpty()) {