use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class IndexCommands method destroyIndex.
@CliCommand(value = CliStrings.DESTROY_INDEX, help = CliStrings.DESTROY_INDEX__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public Result destroyIndex(@CliOption(key = CliStrings.DESTROY_INDEX__NAME, mandatory = false, unspecifiedDefaultValue = "", help = CliStrings.DESTROY_INDEX__NAME__HELP) final String indexName, @CliOption(key = CliStrings.DESTROY_INDEX__REGION, mandatory = false, optionContext = ConverterHint.REGION_PATH, help = CliStrings.DESTROY_INDEX__REGION__HELP) final String regionPath, @CliOption(key = CliStrings.DESTROY_INDEX__MEMBER, mandatory = false, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.DESTROY_INDEX__MEMBER__HELP) final String[] memberNameOrID, @CliOption(key = CliStrings.DESTROY_INDEX__GROUP, mandatory = false, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.DESTROY_INDEX__GROUP__HELP) final String[] group) {
Result result = null;
if (StringUtils.isBlank(indexName) && StringUtils.isBlank(regionPath) && ArrayUtils.isEmpty(group) && ArrayUtils.isEmpty(memberNameOrID)) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.PROVIDE_ATLEAST_ONE_OPTION, CliStrings.DESTROY_INDEX));
}
String regionName = null;
final Cache cache = CacheFactory.getAnyInstance();
// requires data manage permission on all regions
if (StringUtils.isNotBlank(regionPath)) {
regionName = regionPath.startsWith("/") ? regionPath.substring(1) : regionPath;
this.securityService.authorizeRegionManage(regionName);
} else {
this.securityService.authorizeDataManage();
}
IndexInfo indexInfo = new IndexInfo(indexName, regionName);
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrID);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ResultCollector rc = CliUtil.executeFunction(destroyIndexFunction, indexInfo, targetMembers);
List<Object> funcResults = (List<Object>) rc.getResult();
Set<String> successfulMembers = new TreeSet<String>();
Map<String, Set<String>> indexOpFailMap = new HashMap<String, Set<String>>();
AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
for (Object funcResult : funcResults) {
if (!(funcResult instanceof CliFunctionResult)) {
continue;
}
CliFunctionResult cliFunctionResult = (CliFunctionResult) funcResult;
if (cliFunctionResult.isSuccessful()) {
successfulMembers.add(cliFunctionResult.getMemberIdOrName());
if (xmlEntity.get() == null) {
xmlEntity.set(cliFunctionResult.getXmlEntity());
}
} else {
String exceptionMessage = cliFunctionResult.getMessage();
Set<String> failedMembers = indexOpFailMap.get(exceptionMessage);
if (failedMembers == null) {
failedMembers = new TreeSet<String>();
}
failedMembers.add(cliFunctionResult.getMemberIdOrName());
indexOpFailMap.put(exceptionMessage, failedMembers);
}
}
if (!successfulMembers.isEmpty()) {
InfoResultData infoResult = ResultBuilder.createInfoResultData();
if (StringUtils.isNotBlank(indexName)) {
if (StringUtils.isNotBlank(regionPath)) {
infoResult.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__ON__REGION__SUCCESS__MSG, indexName, regionPath));
} else {
infoResult.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__SUCCESS__MSG, indexName));
}
} else {
if (StringUtils.isNotBlank(regionPath)) {
infoResult.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__ON__REGION__ONLY__SUCCESS__MSG, regionPath));
} else {
infoResult.addLine(CliStrings.DESTROY_INDEX__ON__MEMBERS__ONLY__SUCCESS__MSG);
}
}
int num = 0;
for (String memberId : successfulMembers) {
infoResult.addLine(CliStrings.format(CliStrings.format(CliStrings.DESTROY_INDEX__NUMBER__AND__MEMBER, ++num, memberId)));
;
}
result = ResultBuilder.buildResult(infoResult);
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
if (StringUtils.isNotBlank(indexName)) {
erd.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__FAILURE__MSG, indexName));
} else {
erd.addLine("Indexes could not be destroyed for following reasons");
}
Set<String> exceptionMessages = indexOpFailMap.keySet();
for (String exceptionMessage : exceptionMessages) {
erd.addLine(CliStrings.format(CliStrings.DESTROY_INDEX__REASON_MESSAGE, exceptionMessage));
erd.addLine(CliStrings.DESTROY_INDEX__EXCEPTION__OCCURRED__ON);
Set<String> memberIds = indexOpFailMap.get(exceptionMessage);
int num = 0;
for (String memberId : memberIds) {
erd.addLine(CliStrings.format(CliStrings.format(CliStrings.DESTROY_INDEX__NUMBER__AND__MEMBER, ++num, memberId)));
}
erd.addLine("");
}
result = ResultBuilder.buildResult(erd);
}
if (xmlEntity.get() != null) {
persistClusterConfiguration(result, () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), group));
}
return result;
}
use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class MiscellaneousCommands method getMemberMetrics.
/**
* Gets the Cluster wide metrics for a given member
*
* @return ResultData with required Member statistics or ErrorResultData if MemberMbean is not
* found to gather metrics
* @throws ResultDataException if building result fails
*/
private ResultData getMemberMetrics(DistributedMember distributedMember, String export_to_report_to, String[] categoriesArr, int cacheServerPort) throws ResultDataException {
final InternalCache cache = getCache();
final SystemManagementService managementService = (SystemManagementService) ManagementService.getManagementService(cache);
ObjectName memberMBeanName = managementService.getMemberMBeanName(distributedMember);
MemberMXBean memberMxBean = managementService.getMBeanInstance(memberMBeanName, MemberMXBean.class);
ObjectName csMxBeanName = null;
CacheServerMXBean csMxBean = null;
if (memberMxBean != null) {
if (cacheServerPort != -1) {
csMxBeanName = managementService.getCacheServerMBeanName(cacheServerPort, distributedMember);
csMxBean = managementService.getMBeanInstance(csMxBeanName, CacheServerMXBean.class);
if (csMxBean == null) {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(CliStrings.format(CliStrings.SHOW_METRICS__CACHE__SERVER__NOT__FOUND, cacheServerPort, MBeanJMXAdapter.getMemberNameOrId(distributedMember)));
return erd;
}
}
JVMMetrics jvmMetrics = memberMxBean.showJVMMetrics();
CompositeResultData crd = ResultBuilder.createCompositeResultData();
SectionResultData section = crd.addSection();
TabularResultData metricsTable = section.addTable();
metricsTable.setHeader("Member 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 = getMemberMetricsCategories();
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());
}
}
// eviction, distribution
if (categoriesMap.get("member").booleanValue()) {
writeToTableAndCsv(metricsTable, "member", "upTime", memberMxBean.getMemberUpTime(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "cpuUsage", memberMxBean.getCpuUsage(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "currentHeapSize", memberMxBean.getCurrentHeapSize(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "maximumHeapSize", memberMxBean.getMaximumHeapSize(), csvBuilder);
}
/*
* JVM Metrics
*/
if (categoriesMap.get("jvm").booleanValue()) {
writeToTableAndCsv(metricsTable, "jvm ", "jvmThreads ", jvmMetrics.getTotalThreads(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "fileDescriptorLimit", memberMxBean.getFileDescriptorLimit(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalFileDescriptorOpen", memberMxBean.getTotalFileDescriptorOpen(), csvBuilder);
}
/*
* Member wide region metrics
*/
if (categoriesMap.get("region").booleanValue()) {
writeToTableAndCsv(metricsTable, "region ", "totalRegionCount ", memberMxBean.getTotalRegionCount(), csvBuilder);
String[] regionNames = memberMxBean.listRegions();
if (regionNames != null) {
for (int i = 0; i < regionNames.length; i++) {
if (i == 0) {
writeToTableAndCsv(metricsTable, "", "listOfRegions", regionNames[i].substring(1), csvBuilder);
} else {
writeToTableAndCsv(metricsTable, "", "", regionNames[i].substring(1), csvBuilder);
}
}
}
String[] rootRegionNames = memberMxBean.getRootRegionNames();
if (rootRegionNames != null) {
for (int i = 0; i < rootRegionNames.length; i++) {
if (i == 0) {
writeToTableAndCsv(metricsTable, "", "rootRegions", rootRegionNames[i], csvBuilder);
} else {
writeToTableAndCsv(metricsTable, "", "", rootRegionNames[i], csvBuilder);
}
}
}
writeToTableAndCsv(metricsTable, "", "totalRegionEntryCount", memberMxBean.getTotalRegionEntryCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalBucketCount", memberMxBean.getTotalBucketCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalPrimaryBucketCount", memberMxBean.getTotalPrimaryBucketCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "getsAvgLatency", memberMxBean.getGetsAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putsAvgLatency", memberMxBean.getPutsAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "createsRate", memberMxBean.getCreatesRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "destroyRate", memberMxBean.getDestroysRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putAllAvgLatency", memberMxBean.getPutAllAvgLatency(), csvBuilder);
// Not available from stats. After Stats re-org it will be avaialble
// writeToTableAndCsv(metricsTable, "", "getAllAvgLatency",
// memberMxBean.getGetAllAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalMissCount", memberMxBean.getTotalMissCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalHitCount", memberMxBean.getTotalHitCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "getsRate", memberMxBean.getGetsRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putsRate", memberMxBean.getPutsRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "cacheWriterCallsAvgLatency", memberMxBean.getCacheWriterCallsAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "cacheListenerCallsAvgLatency", memberMxBean.getCacheListenerCallsAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalLoadsCompleted", memberMxBean.getTotalLoadsCompleted(), csvBuilder);
}
/*
* SERIALIZATION
*/
if (categoriesMap.get("serialization").booleanValue()) {
writeToTableAndCsv(metricsTable, "serialization", "serializationRate", memberMxBean.getSerializationRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "serializationLatency", memberMxBean.getSerializationRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "deserializationRate", memberMxBean.getDeserializationRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "deserializationLatency", memberMxBean.getDeserializationLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "deserializationAvgLatency", memberMxBean.getDeserializationAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "PDXDeserializationAvgLatency", memberMxBean.getPDXDeserializationAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "PDXDeserializationRate", memberMxBean.getPDXDeserializationRate(), csvBuilder);
}
/*
* Communication Metrics
*/
if (categoriesMap.get("communication").booleanValue()) {
writeToTableAndCsv(metricsTable, "communication", "bytesSentRate", memberMxBean.getBytesSentRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "bytesReceivedRate", memberMxBean.getBytesReceivedRate(), csvBuilder);
String[] connectedGatewayReceivers = memberMxBean.listConnectedGatewayReceivers();
writeToTableAndCsv(metricsTable, "", "connectedGatewayReceivers", connectedGatewayReceivers, csvBuilder);
String[] connectedGatewaySenders = memberMxBean.listConnectedGatewaySenders();
writeToTableAndCsv(metricsTable, "", "connectedGatewaySenders", connectedGatewaySenders, csvBuilder);
}
/*
* Member wide function metrics
*/
if (categoriesMap.get("function").booleanValue()) {
writeToTableAndCsv(metricsTable, "function", "numRunningFunctions", memberMxBean.getNumRunningFunctions(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "functionExecutionRate", memberMxBean.getFunctionExecutionRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "numRunningFunctionsHavingResults", memberMxBean.getNumRunningFunctionsHavingResults(), csvBuilder);
// Not Avaialble from Stats
// writeToTableAndCsv(metricsTable, "", "funcExecutionQueueSize",
// memberMxBean.getFuncExecutionQueueSize(), csvBuilder);
}
/*
* totalTransactionsCount currentTransactionalThreadIds transactionCommitsAvgLatency
* transactionCommittedTotalCount transactionRolledBackTotalCount transactionCommitsRate
*/
if (categoriesMap.get("transaction").booleanValue()) {
writeToTableAndCsv(metricsTable, "transaction", "totalTransactionsCount", memberMxBean.getTotalTransactionsCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "transactionCommitsAvgLatency", memberMxBean.getTransactionCommitsAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "transactionCommittedTotalCount", memberMxBean.getTransactionCommittedTotalCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "transactionRolledBackTotalCount", memberMxBean.getTransactionRolledBackTotalCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "transactionCommitsRate", memberMxBean.getTransactionCommitsRate(), csvBuilder);
}
/*
* Member wide disk metrics
*/
if (categoriesMap.get("diskstore").booleanValue()) {
writeToTableAndCsv(metricsTable, "diskstore", "totalDiskUsage", memberMxBean.getTotalDiskUsage(), // deadcoded to workaround bug 46397
csvBuilder);
writeToTableAndCsv(metricsTable, "", /* 46608 */
"diskReadsRate", memberMxBean.getDiskReadsRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "diskWritesRate", memberMxBean.getDiskWritesRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "flushTimeAvgLatency", memberMxBean.getDiskFlushAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalQueueSize", memberMxBean.getTotalDiskTasksWaiting(), // deadcoded to workaround bug
csvBuilder);
// 46397
writeToTableAndCsv(metricsTable, "", "totalBackupInProgress", memberMxBean.getTotalBackupInProgress(), csvBuilder);
}
/*
* Member wide Lock
*/
if (categoriesMap.get("lock").booleanValue()) {
writeToTableAndCsv(metricsTable, "lock", "lockWaitsInProgress", memberMxBean.getLockWaitsInProgress(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalLockWaitTime", memberMxBean.getTotalLockWaitTime(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalNumberOfLockService", memberMxBean.getTotalNumberOfLockService(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "requestQueues", memberMxBean.getLockRequestQueues(), csvBuilder);
}
/*
* Eviction
*/
if (categoriesMap.get("eviction").booleanValue()) {
writeToTableAndCsv(metricsTable, "eviction", "lruEvictionRate", memberMxBean.getLruEvictionRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "lruDestroyRate", memberMxBean.getLruDestroyRate(), csvBuilder);
}
/*
* Distribution
*/
if (categoriesMap.get("distribution").booleanValue()) {
writeToTableAndCsv(metricsTable, "distribution", "getInitialImagesInProgress", memberMxBean.getInitialImagesInProgres(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "getInitialImageTime", memberMxBean.getInitialImageTime(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "getInitialImageKeysReceived", memberMxBean.getInitialImageKeysReceived(), csvBuilder);
}
/*
* OffHeap
*/
if (categoriesMap.get("offheap").booleanValue()) {
writeToTableAndCsv(metricsTable, "offheap", "maxMemory", memberMxBean.getOffHeapMaxMemory(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "freeMemory", memberMxBean.getOffHeapFreeMemory(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "usedMemory", memberMxBean.getOffHeapUsedMemory(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "objects", memberMxBean.getOffHeapObjects(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "fragmentation", memberMxBean.getOffHeapFragmentation(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "compactionTime", memberMxBean.getOffHeapCompactionTime(), csvBuilder);
}
/*
* CacheServer stats
*/
if (csMxBean != null) {
writeToTableAndCsv(metricsTable, "cache-server", "clientConnectionCount", csMxBean.getClientConnectionCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "hostnameForClients", csMxBean.getHostNameForClients(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "getRequestAvgLatency", csMxBean.getGetRequestAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putRequestAvgLatency", csMxBean.getPutRequestAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalConnectionsTimedOut", csMxBean.getTotalConnectionsTimedOut(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "threadQueueSize", csMxBean.getPutRequestAvgLatency(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "connectionThreads", csMxBean.getConnectionThreads(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "connectionLoad", csMxBean.getConnectionLoad(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "loadPerConnection", csMxBean.getLoadPerConnection(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "queueLoad", csMxBean.getQueueLoad(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "loadPerQueue", csMxBean.getLoadPerQueue(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "getRequestRate", csMxBean.getGetRequestRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "putRequestRate", csMxBean.getPutRequestRate(), csvBuilder);
/*
* Notification
*/
writeToTableAndCsv(metricsTable, "notification", "numClientNotificationRequests", csMxBean.getNumClientNotificationRequests(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "clientNotificationRate", csMxBean.getClientNotificationRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "clientNotificationAvgLatency", csMxBean.getClientNotificationAvgLatency(), csvBuilder);
/*
* Query
*/
writeToTableAndCsv(metricsTable, "query", "activeCQCount", csMxBean.getActiveCQCount(), csvBuilder);
writeToTableAndCsv(metricsTable, "query", "queryRequestRate", csMxBean.getQueryRequestRate(), csvBuilder);
writeToTableAndCsv(metricsTable, "", "indexCount", csMxBean.getIndexCount(), csvBuilder);
String[] indexList = csMxBean.getIndexList();
writeToTableAndCsv(metricsTable, "", "index list", indexList, csvBuilder);
writeToTableAndCsv(metricsTable, "", "totalIndexMaintenanceTime", csMxBean.getTotalIndexMaintenanceTime(), csvBuilder);
}
if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
crd.addAsFile(export_to_report_to, csvBuilder.toString(), "Member metrics exported to {0}.", false);
}
return crd;
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
String errorMessage = CliStrings.format(CliStrings.SHOW_METRICS__ERROR, "Member MBean for " + MBeanJMXAdapter.getMemberNameOrId(distributedMember) + " not found");
return ResultBuilder.createErrorResultData().addLine(errorMessage);
}
}
use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class DataCommands method executeRebalanceOnDS.
private Result executeRebalanceOnDS(InternalCache cache, String simulate, String[] excludeRegionsList) {
Result result = null;
int index = 1;
CompositeResultData rebalanceResultData = ResultBuilder.createCompositeResultData();
List<String> listExcludedRegion = new ArrayList<>();
if (excludeRegionsList != null) {
Collections.addAll(listExcludedRegion, excludeRegionsList);
}
List<MemberPRInfo> listMemberRegion = getMemberRegionList(cache, listExcludedRegion);
if (listMemberRegion.size() == 0) {
return ResultBuilder.createInfoResult(CliStrings.REBALANCE__MSG__NO_REBALANCING_REGIONS_ON_DS);
}
Iterator<MemberPRInfo> iterator = listMemberRegion.iterator();
boolean flagToContinueWithRebalance = false;
// check if list has some members that can be rebalanced
while (iterator.hasNext()) {
if (iterator.next().dsMemberList.size() > 1) {
flagToContinueWithRebalance = true;
break;
}
}
if (!flagToContinueWithRebalance) {
return ResultBuilder.createInfoResult(CliStrings.REBALANCE__MSG__NO_REBALANCING_REGIONS_ON_DS);
}
for (MemberPRInfo memberPR : listMemberRegion) {
try {
// check if there are more than one members associated with region for rebalancing
if (memberPR.dsMemberList.size() > 1) {
for (int i = 0; i < memberPR.dsMemberList.size(); i++) {
DistributedMember dsMember = memberPR.dsMemberList.get(i);
Function rebalanceFunction = new RebalanceFunction();
Object[] functionArgs = new Object[3];
functionArgs[0] = simulate;
Set<String> regionSet = new HashSet<>();
regionSet.add(memberPR.region);
functionArgs[1] = regionSet;
Set<String> excludeRegionSet = new HashSet<>();
functionArgs[2] = excludeRegionSet;
List resultList = null;
try {
if (checkMemberPresence(dsMember, cache)) {
resultList = (ArrayList) CliUtil.executeFunction(rebalanceFunction, functionArgs, dsMember).getResult();
if (checkResultList(rebalanceResultData, resultList, dsMember)) {
result = ResultBuilder.buildResult(rebalanceResultData);
continue;
}
List<String> rstList = tokenize((String) resultList.get(0), ",");
result = ResultBuilder.buildResult(toCompositeResultData(rebalanceResultData, (ArrayList) rstList, index, simulate.equals("true"), cache));
index++;
// Rebalancing for region is done so break and continue with other region
break;
} else {
if (i == memberPR.dsMemberList.size() - 1) {
rebalanceResultData.addSection().addData(CliStrings.format(CliStrings.REBALANCE__MSG__NO_EXECUTION_FOR_REGION_0_ON_MEMBERS_1, memberPR.region, listOfAllMembers(memberPR.dsMemberList)), CliStrings.REBALANCE__MSG__MEMBERS_MIGHT_BE_DEPARTED);
result = ResultBuilder.buildResult(rebalanceResultData);
} else {
continue;
}
}
} catch (Exception ex) {
if (i == memberPR.dsMemberList.size() - 1) {
rebalanceResultData.addSection().addData(CliStrings.format(CliStrings.REBALANCE__MSG__NO_EXECUTION_FOR_REGION_0_ON_MEMBERS_1, memberPR.region, listOfAllMembers(memberPR.dsMemberList)), CliStrings.REBALANCE__MSG__REASON + ex.getMessage());
result = ResultBuilder.buildResult(rebalanceResultData);
} else {
continue;
}
}
if (checkResultList(rebalanceResultData, resultList, dsMember)) {
result = ResultBuilder.buildResult(rebalanceResultData);
continue;
}
List<String> rstList = tokenize((String) resultList.get(0), ",");
result = ResultBuilder.buildResult(toCompositeResultData(rebalanceResultData, (ArrayList) rstList, index, simulate.equals("true"), cache));
index++;
}
}
} catch (Exception e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
return (ResultBuilder.buildResult(errorResultData));
}
}
return result;
}
use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class DiskStoreCommands method createErrorResult.
private Result createErrorResult(String message) {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(message);
return ResultBuilder.buildResult(erd);
}
use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class ExportImportClusterConfigurationCommands method importSharedConfig.
@CliCommand(value = { CliStrings.IMPORT_SHARED_CONFIG }, help = CliStrings.IMPORT_SHARED_CONFIG__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.ExportImportClusterConfigurationCommands$ImportInterceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE)
@SuppressWarnings("unchecked")
public Result importSharedConfig(@CliOption(key = { CliStrings.IMPORT_SHARED_CONFIG__ZIP }, mandatory = true, help = CliStrings.IMPORT_SHARED_CONFIG__ZIP__HELP) String zip) {
InternalLocator locator = InternalLocator.getLocator();
if (!locator.isSharedConfigurationRunning()) {
ErrorResultData errorData = ResultBuilder.createErrorResultData();
errorData.addLine(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
return ResultBuilder.buildResult(errorData);
}
InternalCache cache = getCache();
Set<DistributedMember> servers = CliUtil.getAllNormalMembers(cache);
Set<String> regionsWithData = servers.stream().map(this::getRegionNamesOnServer).flatMap(Collection::stream).collect(toSet());
if (!regionsWithData.isEmpty()) {
return ResultBuilder.createGemFireErrorResult("Cannot import cluster configuration with existing regions: " + regionsWithData.stream().collect(joining(",")));
}
byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
String zipFileName = CliUtil.bytesToNames(shellBytesData)[0];
byte[] zipBytes = CliUtil.bytesToData(shellBytesData)[0];
Result result;
InfoResultData infoData = ResultBuilder.createInfoResultData();
File zipFile = new File(zipFileName);
try {
ClusterConfigurationService sc = locator.getSharedConfiguration();
// backup the old config
for (Configuration config : sc.getEntireConfiguration().values()) {
sc.writeConfigToFile(config);
}
sc.renameExistingSharedConfigDirectory();
FileUtils.writeByteArrayToFile(zipFile, zipBytes);
ZipUtils.unzip(zipFileName, sc.getSharedConfigurationDirPath());
// load it from the disk
sc.loadSharedConfigurationFromDisk();
infoData.addLine(CliStrings.IMPORT_SHARED_CONFIG__SUCCESS__MSG);
} catch (Exception e) {
ErrorResultData errorData = ResultBuilder.createErrorResultData();
errorData.addLine("Import failed");
logSevere(e);
result = ResultBuilder.buildResult(errorData);
// if import is unsuccessful, don't need to bounce the server.
return result;
} finally {
FileUtils.deleteQuietly(zipFile);
}
// Bounce the cache of each member
Set<CliFunctionResult> functionResults = servers.stream().map(this::reCreateCache).collect(toSet());
for (CliFunctionResult functionResult : functionResults) {
if (functionResult.isSuccessful()) {
infoData.addLine("Successfully applied the imported cluster configuration on " + functionResult.getMemberIdOrName());
} else {
infoData.addLine("Failed to apply the imported cluster configuration on " + functionResult.getMemberIdOrName() + " due to " + functionResult.getMessage());
}
}
result = ResultBuilder.buildResult(infoData);
return result;
}
Aggregations