use of org.apache.geode.management.ManagementService in project geode by apache.
the class TestRemoteClusterDUnitTest method stopGatewaySender.
/**
* stops a gateway sender
*
* @param vm reference to VM
*/
@SuppressWarnings("serial")
protected void stopGatewaySender(final VM vm) {
SerializableRunnable stopGatewaySender = new SerializableRunnable("Stop Gateway Sender") {
public void run() {
Cache cache = GemFireCacheImpl.getInstance();
ManagementService service = ManagementService.getManagementService(cache);
GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
assertNotNull(bean);
bean.stop();
assertFalse(bean.isRunning());
}
};
vm.invoke(stopGatewaySender);
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class MiscellaneousCommands method getSystemWideMetrics.
/**
* Gets the system wide metrics
*
* @return ResultData with required System wide statistics or ErrorResultData if DS MBean is not
* found to gather metrics
*/
private ResultData getSystemWideMetrics(String export_to_report_to, String[] categoriesArr) throws Exception {
final InternalCache cache = getCache();
final ManagementService managmentService = ManagementService.getManagementService(cache);
DistributedSystemMXBean dsMxBean = managmentService.getDistributedSystemMXBean();
StringBuilder csvBuilder = null;
if (dsMxBean != null) {
if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
csvBuilder = new StringBuilder();
csvBuilder.append("Category");
csvBuilder.append(',');
csvBuilder.append(CliStrings.SHOW_METRICS__METRIC__HEADER);
csvBuilder.append(',');
csvBuilder.append(CliStrings.SHOW_METRICS__VALUE__HEADER);
csvBuilder.append('\n');
}
CompositeResultData crd = ResultBuilder.createCompositeResultData();
SectionResultData section = crd.addSection();
TabularResultData metricsTable = section.addTable();
Map<String, Boolean> categoriesMap = getSystemMetricsCategories();
if (categoriesArr != null && categoriesArr.length != 0) {
Set<String> categories = createSet(categoriesArr);
Set<String> checkSet = new HashSet<String>(categoriesMap.keySet());
Set<String> userCategories = getSetDifference(categories, checkSet);
if (userCategories.isEmpty()) {
for (String category : checkSet) {
categoriesMap.put(category, false);
}
for (String category : categories) {
categoriesMap.put(category.toLowerCase(), true);
}
} else {
StringBuilder sb = new StringBuilder();
sb.append("Invalid Categories\n");
for (String category : userCategories) {
sb.append(category);
sb.append('\n');
}
return ResultBuilder.createErrorResultData().addLine(sb.toString());
}
}
metricsTable.setHeader("Cluster-wide Metrics");
if (categoriesMap.get("cluster").booleanValue()) {
writeToTableAndCsv(metricsTable, "cluster", "totalHeapSize", dsMxBean.getTotalHeapSize(), csvBuilder);
}
if (categoriesMap.get("cache").booleanValue()) {
writeToTableAndCsv(metricsTable, "cache", "totalRegionEntryCount", dsMxBean.getTotalRegionEntryCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalRegionCount", dsMxBean.getTotalRegionCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalMissCount", dsMxBean.getTotalMissCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalHitCount", dsMxBean.getTotalHitCount(), csvBuilder);
}
if (categoriesMap.get("diskstore").booleanValue()) {
writeToTableAndCsv(metricsTable, "diskstore", "totalDiskUsage", dsMxBean.getTotalDiskUsage(), // deadcoded to workaround bug 46397
csvBuilder);
writeToTableAndCsv(metricsTable, "", /* 46608 */
"diskReadsRate", dsMxBean.getDiskReadsRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "diskWritesRate", dsMxBean.getDiskWritesRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "flushTimeAvgLatency", dsMxBean.getDiskFlushAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalBackupInProgress", dsMxBean.getTotalBackupInProgress(), csvBuilder);
}
if (categoriesMap.get("query").booleanValue()) {
writeToTableAndCsv(metricsTable, "query", "activeCQCount", dsMxBean.getActiveCQCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "queryRequestRate", dsMxBean.getQueryRequestRate(), csvBuilder);
}
if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
crd.addAsFile(export_to_report_to, csvBuilder.toString(), "Cluster wide metrics exported to {0}.", false);
}
return crd;
} else {
String errorMessage = CliStrings.format(CliStrings.SHOW_METRICS__ERROR, "Distributed System MBean not found");
return ResultBuilder.createErrorResultData().addLine(errorMessage);
}
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class MiscellaneousCommands method getDistributedRegionMetrics.
/**
* Gets the Cluster-wide metrics for a region
*
* @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 InternalCache cache = getCache();
final ManagementService managementService = ManagementService.getManagementService(cache);
DistributedRegionMXBean regionMxBean = managementService.getDistributedRegionMXBean(regionName);
if (regionMxBean != null) {
CompositeResultData crd = ResultBuilder.createCompositeResultData();
SectionResultData section = crd.addSection();
TabularResultData metricsTable = section.addTable();
metricsTable.setHeader("Cluster-wide Region Metrics");
StringBuilder csvBuilder = null;
if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
csvBuilder = new StringBuilder();
csvBuilder.append("Category");
csvBuilder.append(',');
csvBuilder.append(CliStrings.SHOW_METRICS__METRIC__HEADER);
csvBuilder.append(',');
csvBuilder.append(CliStrings.SHOW_METRICS__VALUE__HEADER);
csvBuilder.append('\n');
}
Map<String, Boolean> categoriesMap = getSystemRegionMetricsCategories();
if (categoriesArr != null && categoriesArr.length != 0) {
Set<String> categories = createSet(categoriesArr);
Set<String> checkSet = new HashSet<String>(categoriesMap.keySet());
Set<String> userCategories = getSetDifference(categories, checkSet);
// Checking if the categories specified by the user are valid or not
if (userCategories.isEmpty()) {
for (String category : checkSet) {
categoriesMap.put(category, false);
}
for (String category : categories) {
categoriesMap.put(category.toLowerCase(), true);
}
} else {
StringBuilder sb = new StringBuilder();
sb.append("Invalid Categories\n");
for (String category : userCategories) {
sb.append(category);
sb.append('\n');
}
return ResultBuilder.createErrorResultData().addLine(sb.toString());
}
}
// cluster, region, partition , diskstore, callback, eviction
if (categoriesMap.get("cluster").booleanValue()) {
writeToTableAndCsv(metricsTable, "cluster", "member count", regionMxBean.getMemberCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "region entry count", regionMxBean.getSystemRegionEntryCount(), csvBuilder);
}
if (categoriesMap.get("region").booleanValue()) {
writeToTableAndCsv(metricsTable, "region", "lastModifiedTime", regionMxBean.getLastModifiedTime(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "lastAccessedTime", regionMxBean.getLastAccessedTime(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "missCount", regionMxBean.getMissCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "hitCount", regionMxBean.getHitCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "hitRatio", regionMxBean.getHitRatio(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "getsRate", regionMxBean.getGetsRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putsRate", regionMxBean.getPutsRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "createsRate", regionMxBean.getCreatesRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "destroyRate", regionMxBean.getDestroyRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putAllRate", regionMxBean.getPutAllRate(), csvBuilder);
}
if (categoriesMap.get("partition").booleanValue()) {
writeToTableAndCsv(metricsTable, "partition", "putLocalRate", regionMxBean.getPutLocalRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putRemoteRate", regionMxBean.getPutRemoteRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putRemoteLatency", regionMxBean.getPutRemoteLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putRemoteAvgLatency", regionMxBean.getPutRemoteAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "bucketCount", regionMxBean.getBucketCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "primaryBucketCount", regionMxBean.getPrimaryBucketCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "numBucketsWithoutRedundancy", regionMxBean.getNumBucketsWithoutRedundancy(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalBucketSize", regionMxBean.getTotalBucketSize(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "averageBucketSize", regionMxBean.getAvgBucketSize(), csvBuilder);
}
/*
* Disk store
*/
if (categoriesMap.get("diskstore").booleanValue()) {
writeToTableAndCsv(metricsTable, "diskstore", "totalEntriesOnlyOnDisk", regionMxBean.getTotalEntriesOnlyOnDisk(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "diskReadsRate", regionMxBean.getDiskReadsRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "diskWritesRate", regionMxBean.getDiskWritesRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalDiskWriteInProgress", regionMxBean.getTotalDiskWritesProgress(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "diskTaskWaiting", regionMxBean.getDiskTaskWaiting(), csvBuilder);
}
/*
* LISTENER
*/
if (categoriesMap.get("callback").booleanValue()) {
writeToTableAndCsv(metricsTable, "callback", "cacheWriterCallsAvgLatency", regionMxBean.getCacheWriterCallsAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "cacheListenerCallsAvgLatency", regionMxBean.getCacheListenerCallsAvgLatency(), csvBuilder);
}
/*
* Eviction
*/
if (categoriesMap.get("eviction").booleanValue()) {
writeToTableAndCsv(metricsTable, "eviction", "lruEvictionRate", regionMxBean.getLruEvictionRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "lruDestroyRate", regionMxBean.getLruDestroyRate(), csvBuilder);
}
if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
crd.addAsFile(export_to_report_to, csvBuilder.toString(), "Aggregate Region Metrics exported to {0}.", false);
}
return crd;
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
String errorMessage = CliStrings.format(CliStrings.SHOW_METRICS__ERROR, "Distributed Region MBean for " + regionName + " not found");
erd.addLine(errorMessage);
return erd;
}
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class DiskStoreCommands method diskStoreExists.
private boolean diskStoreExists(String diskStoreName) {
InternalCache cache = getCache();
ManagementService managementService = ManagementService.getExistingManagementService(cache);
DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean();
Map<String, String[]> diskstore = dsMXBean.listMemberDiskstore();
Set<Entry<String, String[]>> entrySet = diskstore.entrySet();
for (Entry<String, String[]> entry : entrySet) {
String[] value = entry.getValue();
if (CliUtil.contains(value, diskStoreName)) {
return true;
}
}
return false;
}
use of org.apache.geode.management.ManagementService in project geode by apache.
the class CreateAlterDestroyRegionCommands method validateRegionFunctionArgs.
private void validateRegionFunctionArgs(InternalCache cache, RegionFunctionArgs regionFunctionArgs) {
if (regionFunctionArgs.getRegionPath() == null) {
throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH);
}
ManagementService managementService = ManagementService.getExistingManagementService(cache);
DistributedSystemMXBean dsMBean = managementService.getDistributedSystemMXBean();
String useAttributesFrom = regionFunctionArgs.getUseAttributesFrom();
if (useAttributesFrom != null && !useAttributesFrom.isEmpty() && regionExists(cache, useAttributesFrom)) {
if (!regionExists(cache, useAttributesFrom)) {
// check already done in createRegion !!!
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH_FOR_0_REGIONPATH_1_NOT_FOUND, new Object[] { CliStrings.CREATE_REGION__USEATTRIBUTESFROM, useAttributesFrom }));
}
if (!regionFunctionArgs.isSetUseAttributesFrom() || regionFunctionArgs.getRegionAttributes() == null) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__COULD_NOT_RETRIEVE_REGION_ATTRS_FOR_PATH_0_VERIFY_REGION_EXISTS, useAttributesFrom));
}
}
if (regionFunctionArgs.hasPartitionAttributes()) {
RegionFunctionArgs.PartitionArgs partitionArgs = regionFunctionArgs.getPartitionArgs();
String colocatedWith = partitionArgs.getPrColocatedWith();
if (colocatedWith != null && !colocatedWith.isEmpty()) {
String[] listAllRegionPaths = dsMBean.listAllRegionPaths();
String foundRegionPath = null;
for (String regionPath : listAllRegionPaths) {
if (regionPath.equals(colocatedWith)) {
foundRegionPath = regionPath;
break;
}
}
if (foundRegionPath == null) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH_FOR_0_REGIONPATH_1_NOT_FOUND, new Object[] { CliStrings.CREATE_REGION__COLOCATEDWITH, colocatedWith }));
}
ManagementService mgmtService = ManagementService.getExistingManagementService(cache);
DistributedRegionMXBean distributedRegionMXBean = mgmtService.getDistributedRegionMXBean(foundRegionPath);
String regionType = distributedRegionMXBean.getRegionType();
if (!(DataPolicy.PARTITION.toString().equals(regionType) || DataPolicy.PERSISTENT_PARTITION.toString().equals(regionType))) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__COLOCATEDWITH_REGION_0_IS_NOT_PARTITIONEDREGION, new Object[] { colocatedWith }));
}
}
if (partitionArgs.isSetPRLocalMaxMemory()) {
int prLocalMaxMemory = partitionArgs.getPrLocalMaxMemory();
if (prLocalMaxMemory < 0) {
throw new IllegalArgumentException(LocalizedStrings.AttributesFactory_PARTITIONATTRIBUTES_LOCALMAXMEMORY_MUST_NOT_BE_NEGATIVE.toLocalizedString());
}
}
if (partitionArgs.isSetPRTotalMaxMemory()) {
long prTotalMaxMemory = partitionArgs.getPrTotalMaxMemory();
if (prTotalMaxMemory <= 0) {
throw new IllegalArgumentException(LocalizedStrings.AttributesFactory_TOTAL_SIZE_OF_PARTITION_REGION_MUST_BE_0.toLocalizedString());
}
}
if (partitionArgs.isSetPRRedundantCopies()) {
int prRedundantCopies = partitionArgs.getPrRedundantCopies();
switch(prRedundantCopies) {
case 0:
case 1:
case 2:
case 3:
break;
default:
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__REDUNDANT_COPIES_SHOULD_BE_ONE_OF_0123, new Object[] { prRedundantCopies }));
}
}
}
String keyConstraint = regionFunctionArgs.getKeyConstraint();
if (keyConstraint != null && !isClassNameValid(keyConstraint)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_KEYCONSTRAINT_0_IS_INVALID, new Object[] { keyConstraint }));
}
String valueConstraint = regionFunctionArgs.getValueConstraint();
if (valueConstraint != null && !isClassNameValid(valueConstraint)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_VALUECONSTRAINT_0_IS_INVALID, new Object[] { valueConstraint }));
}
Set<String> cacheListeners = regionFunctionArgs.getCacheListeners();
if (cacheListeners != null && !cacheListeners.isEmpty()) {
for (String cacheListener : cacheListeners) {
if (!isClassNameValid(cacheListener)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELISTENER_0_IS_INVALID, new Object[] { cacheListener }));
}
}
}
String cacheLoader = regionFunctionArgs.getCacheLoader();
if (cacheLoader != null && !isClassNameValid(cacheLoader)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELOADER_0_IS_INVALID, new Object[] { cacheLoader }));
}
String cacheWriter = regionFunctionArgs.getCacheWriter();
if (cacheWriter != null && !isClassNameValid(cacheWriter)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHEWRITER_0_IS_INVALID, new Object[] { cacheWriter }));
}
Set<String> gatewaySenderIds = regionFunctionArgs.getGatewaySenderIds();
if (gatewaySenderIds != null && !gatewaySenderIds.isEmpty()) {
String[] gatewaySenders = dsMBean.listGatewaySenders();
if (gatewaySenders.length == 0) {
throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__NO_GATEWAYSENDERS_IN_THE_SYSTEM);
} else {
List<String> gatewaySendersList = new ArrayList<>(Arrays.asList(gatewaySenders));
gatewaySenderIds = new HashSet<>(gatewaySenderIds);
gatewaySenderIds.removeAll(gatewaySendersList);
if (!gatewaySenderIds.isEmpty()) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_GATEWAYSENDER_ID_UNKNOWN_0, new Object[] { gatewaySenderIds }));
}
}
}
if (regionFunctionArgs.isSetConcurrencyLevel()) {
int concurrencyLevel = regionFunctionArgs.getConcurrencyLevel();
if (concurrencyLevel < 0) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_POSITIVE_INT_FOR_CONCURRENCYLEVEL_0_IS_NOT_VALID, new Object[] { concurrencyLevel }));
}
}
String diskStore = regionFunctionArgs.getDiskStore();
if (diskStore != null) {
RegionShortcut regionShortcut = regionFunctionArgs.getRegionShortcut();
if (regionShortcut != null && !PERSISTENT_OVERFLOW_SHORTCUTS.contains(regionShortcut)) {
String subMessage = LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString();
String message = subMessage + ". " + CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ONE_OF_THESE_SHORTCUTS_0, new Object[] { String.valueOf(PERSISTENT_OVERFLOW_SHORTCUTS) });
throw new IllegalArgumentException(message);
}
RegionAttributes<?, ?> regionAttributes = regionFunctionArgs.getRegionAttributes();
if (regionAttributes != null && !regionAttributes.getDataPolicy().withPersistence()) {
String subMessage = LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString();
String message = subMessage + ". " + CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ATTRIBUTES_FROM_REGION_0_IS_NOT_WITH_PERSISTENCE, new Object[] { String.valueOf(regionFunctionArgs.getUseAttributesFrom()) });
throw new IllegalArgumentException(message);
}
if (!diskStoreExists(cache, diskStore)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_DISKSTORE_UNKNOWN_DISKSTORE_0, new Object[] { diskStore }));
}
}
RegionFunctionArgs.ExpirationAttrs entryExpirationIdleTime = regionFunctionArgs.getEntryExpirationIdleTime();
RegionFunctionArgs.ExpirationAttrs entryExpirationTTL = regionFunctionArgs.getEntryExpirationTTL();
RegionFunctionArgs.ExpirationAttrs regionExpirationIdleTime = regionFunctionArgs.getRegionExpirationIdleTime();
RegionFunctionArgs.ExpirationAttrs regionExpirationTTL = regionFunctionArgs.getRegionExpirationTTL();
if ((!regionFunctionArgs.isSetStatisticsEnabled() || !regionFunctionArgs.isStatisticsEnabled()) && (entryExpirationIdleTime != null || entryExpirationTTL != null || regionExpirationIdleTime != null || regionExpirationTTL != null)) {
String message = LocalizedStrings.AttributesFactory_STATISTICS_MUST_BE_ENABLED_FOR_EXPIRATION.toLocalizedString();
throw new IllegalArgumentException(message + ".");
}
boolean compressorFailure = false;
if (regionFunctionArgs.isSetCompressor()) {
String compressorClassName = regionFunctionArgs.getCompressor();
Object compressor = null;
try {
Class<?> compressorClass = ClassPathLoader.getLatest().forName(compressorClassName);
compressor = compressorClass.newInstance();
} catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) {
compressorFailure = true;
}
if (compressorFailure || !(compressor instanceof Compressor)) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__INVALID_COMPRESSOR, new Object[] { regionFunctionArgs.getCompressor() }));
}
}
if (regionFunctionArgs.hasPartitionAttributes()) {
if (regionFunctionArgs.isPartitionResolverSet()) {
String partitionResolverClassName = regionFunctionArgs.getPartitionResolver();
try {
Class<PartitionResolver> resolverClass = (Class<PartitionResolver>) ClassPathLoader.getLatest().forName(partitionResolverClassName);
PartitionResolver partitionResolver = resolverClass.newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__INVALID_PARTITION_RESOLVER, new Object[] { regionFunctionArgs.getCompressor() }), e);
}
}
}
}
Aggregations