com.gemstone.gemfire.management.internal.cli.commands.DataCommands Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
The newest version!
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.management.internal.cli.commands;
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.CancellationException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
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 com.gemstone.gemfire.LogWriter;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.control.RebalanceFactory;
import com.gemstone.gemfire.cache.control.RebalanceOperation;
import com.gemstone.gemfire.cache.control.RebalanceResults;
import com.gemstone.gemfire.cache.control.ResourceManager;
import com.gemstone.gemfire.cache.execute.Function;
import com.gemstone.gemfire.cache.execute.FunctionInvocationTargetException;
import com.gemstone.gemfire.cache.execute.FunctionService;
import com.gemstone.gemfire.cache.execute.ResultCollector;
import com.gemstone.gemfire.cache.partition.PartitionRebalanceInfo;
import com.gemstone.gemfire.distributed.DistributedMember;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.management.DistributedRegionMXBean;
import com.gemstone.gemfire.management.ManagementService;
import com.gemstone.gemfire.management.cli.CliMetaData;
import com.gemstone.gemfire.management.cli.ConverterHint;
import com.gemstone.gemfire.management.cli.Result;
import com.gemstone.gemfire.management.internal.MBeanJMXAdapter;
import com.gemstone.gemfire.management.internal.cli.CliUtil;
import com.gemstone.gemfire.management.internal.cli.LogWrapper;
import com.gemstone.gemfire.management.internal.cli.domain.DataCommandRequest;
import com.gemstone.gemfire.management.internal.cli.domain.DataCommandResult;
import com.gemstone.gemfire.management.internal.cli.functions.DataCommandFunction;
import com.gemstone.gemfire.management.internal.cli.functions.ExportDataFunction;
import com.gemstone.gemfire.management.internal.cli.functions.ImportDataFunction;
import com.gemstone.gemfire.management.internal.cli.functions.RebalanceFunction;
import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings;
import com.gemstone.gemfire.management.internal.cli.multistep.CLIMultiStepHelper;
import com.gemstone.gemfire.management.internal.cli.multistep.CLIStep;
import com.gemstone.gemfire.management.internal.cli.multistep.MultiStepCommand;
import com.gemstone.gemfire.management.internal.cli.result.CompositeResultData;
import com.gemstone.gemfire.management.internal.cli.result.ErrorResultData;
import com.gemstone.gemfire.management.internal.cli.result.ResultBuilder;
import com.gemstone.gemfire.management.internal.cli.result.TabularResultData;
import com.gemstone.gemfire.management.internal.cli.shell.Gfsh;
/**
*
* @author ajayp
* @author tushark
* @since 7.0
*/
public class DataCommands implements CommandMarker {
final int resultItemCount = 9;
private final ExportDataFunction exportDataFunction = new ExportDataFunction();
private final ImportDataFunction importDataFunction = new ImportDataFunction();
private Gfsh getGfsh() {
return Gfsh.getCurrentInstance();
}
@CliCommand(value = CliStrings.REBALANCE, help = CliStrings.REBALANCE__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEMFIRE_DATA,
CliStrings.TOPIC_GEMFIRE_REGION })
public Result rebalance(
@CliOption(key = CliStrings.REBALANCE__INCLUDEREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.REBALANCE__INCLUDEREGION__HELP) String[] includeRegions,
@CliOption(key = CliStrings.REBALANCE__EXCLUDEREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.REBALANCE__EXCLUDEREGION__HELP) String[] excludeRegions,
@CliOption(key = CliStrings.REBALANCE__TIMEOUT, unspecifiedDefaultValue = "-1", help = CliStrings.REBALANCE__TIMEOUT__HELP) long timeout,
@CliOption(key = CliStrings.REBALANCE__SIMULATE, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.REBALANCE__SIMULATE__HELP) boolean simulate) {
Result result = null;
try {
RebalanceOperation op = null;
RebalanceResults results = null;
Set inRegions = new HashSet();
Set exRegions = new HashSet();
Cache cache = CacheFactory.getAnyInstance();
if (includeRegions != null && includeRegions.length > 0) {
CompositeResultData rebalanceResulteData = ResultBuilder
.createCompositeResultData();
int index = 0;
for (String regionName : includeRegions) {
Region region = cache.getRegion(regionName);
if (region == null) {
DistributedMember member = getAssociatedMembers(regionName, cache);
if (member == null) {
LogWrapper
.getInstance()
.info(
CliStrings
.format(
CliStrings.REBALANCE__MSG__NO_ASSOCIATED_DISTRIBUTED_MEMBER,
regionName));
continue;
}
Function rebalanceFunction = new RebalanceFunction();
Object[] functionArgs = new Object[3];
functionArgs[0] = simulate ? "true" : "false";
Set setRegionName = new HashSet();
setRegionName.add(regionName);
functionArgs[1] = setRegionName;
Set excludeRegionSet = new HashSet();
if (excludeRegions != null && excludeRegions.length > 0) {
for (String str : excludeRegions) {
excludeRegionSet.add(str);
}
}
functionArgs[2] = excludeRegionSet;
if (simulate == true) {
List resultList = null;
try {
resultList = (ArrayList) CliUtil.executeFunction(
rebalanceFunction, functionArgs, member).getResult();
} catch (Exception ex) {
LogWrapper
.getInstance()
.info(
CliStrings.format(
CliStrings.REBALANCE__MSG__EXCEPTION_IN_REBALANCE_FOR_MEMBER_0_Exception_1,
member.getId(), ex.getMessage()), ex);
rebalanceResulteData
.addSection()
.addData(
CliStrings.format(
CliStrings.REBALANCE__MSG__EXCEPTION_IN_REBALANCE_FOR_MEMBER_0_Exception,
member.getId()), ex.getMessage());
result = ResultBuilder.buildResult(rebalanceResulteData);
continue;
}
if (checkResultList(rebalanceResulteData, resultList, member) == true) {
result = ResultBuilder.buildResult(rebalanceResulteData);
continue;
}
List rstList = tokenize((String) resultList.get(0), ",");
result = ResultBuilder.buildResult(toCompositeResultData(
rebalanceResulteData, (ArrayList) rstList, index, simulate,
cache));
} else if (timeout > 0) {
List resultList = null;
try {
resultList = (ArrayList) CliUtil.executeFunction(
rebalanceFunction, functionArgs, member).getResult(timeout,
TimeUnit.SECONDS);
} catch (Exception ex) {
LogWrapper
.getInstance()
.info(
CliStrings.format(
CliStrings.REBALANCE__MSG__EXCEPTION_IN_REBALANCE_FOR_MEMBER_0_Exception_1,
member.getId(), ex.getMessage()), ex);
rebalanceResulteData
.addSection()
.addData(
CliStrings.format(
CliStrings.REBALANCE__MSG__EXCEPTION_IN_REBALANCE_FOR_MEMBER_0_Exception,
member.getId()), ex.getMessage());
result = ResultBuilder.buildResult(rebalanceResulteData);
continue;
}
if (checkResultList(rebalanceResulteData, resultList, member) == true) {
result = ResultBuilder.buildResult(rebalanceResulteData);
continue;
}
List rstList = tokenize((String) resultList.get(0), ",");
result = ResultBuilder.buildResult(toCompositeResultData(
rebalanceResulteData, (ArrayList) rstList, index, simulate,
cache));
} else {
List resultList = null;
try {
resultList = (ArrayList) CliUtil.executeFunction(
rebalanceFunction, functionArgs, member).getResult();
} catch (Exception ex) {
LogWrapper
.getInstance()
.info(
CliStrings.format(
CliStrings.REBALANCE__MSG__EXCEPTION_IN_REBALANCE_FOR_MEMBER_0_Exception_1,
member.getId(), ex.getMessage()), ex);
rebalanceResulteData
.addSection()
.addData(
CliStrings.format(
CliStrings.REBALANCE__MSG__EXCEPTION_IN_REBALANCE_FOR_MEMBER_0_Exception,
member.getId()), ex.getMessage());
result = ResultBuilder.buildResult(rebalanceResulteData);
continue;
}
if (checkResultList(rebalanceResulteData, resultList, member) == true) {
result = ResultBuilder.buildResult(rebalanceResulteData);
continue;
}
List rstList = tokenize((String) resultList.get(0), ",");
result = ResultBuilder.buildResult(toCompositeResultData(
rebalanceResulteData, (ArrayList) rstList, index, simulate,
cache));
}
} else {
ResourceManager manager = cache.getResourceManager();
RebalanceFactory rbFactory = manager.createRebalanceFactory();
Set excludeRegionSet = new HashSet();
if (excludeRegions != null) {
for (String excludeRegion : excludeRegions)
excludeRegionSet.add(excludeRegion);
}
rbFactory.excludeRegions(excludeRegionSet);
Set includeRegionSet = new HashSet();
includeRegionSet.add(regionName);
rbFactory.includeRegions(includeRegionSet);
if (simulate == true) {
op = manager.createRebalanceFactory().simulate();
result = ResultBuilder
.buildResult(buildResultForRebalance(rebalanceResulteData,
op.getResults(), index, simulate, cache));
} else {
op = manager.createRebalanceFactory().start();
// Wait until the rebalance is complete and then get the results
if (timeout > 0) {
try {
results = op.getResults(timeout, TimeUnit.SECONDS);
} catch (CancellationException ex) {
ErrorResultData errorResultData = ResultBuilder
.createErrorResultData()
.setErrorCode(ResultBuilder.ERRORCODE_DEFAULT)
.addLine(CliStrings.REBALANCE__MSG__CANCELLED);
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (TimeoutException ex) {
return ResultBuilder
.createInfoResult(CliStrings.REBALANCE__MSG__TIMEOUT);
} catch (InterruptedException ex) {
ErrorResultData errorResultData = ResultBuilder
.createErrorResultData()
.setErrorCode(ResultBuilder.ERRORCODE_DEFAULT)
.addLine(CliStrings.REBALANCE__MSG__WAIT_INTERRUPTED);
result = ResultBuilder.buildResult(errorResultData);
return result;
}
// Rebalanced within specified time limit
result = ResultBuilder.buildResult(buildResultForRebalance(
rebalanceResulteData, results, index, simulate, cache));
} else {
result = ResultBuilder.buildResult(buildResultForRebalance(
rebalanceResulteData, op.getResults(), index, simulate,
cache));
}
}
}
index++;
}
LogWrapper.getInstance().info("Rebalance returning result" + result);
return result;
} else {
if (simulate == true) {
result = executeRebalanceOnDS(cache, 0, "true", excludeRegions);
} else {
// Wait until the rebalance is complete and then get the results
if (timeout > 0) {
result = executeRebalanceOnDS(cache, timeout, "false",
excludeRegions);
} else {
result = executeRebalanceOnDS(cache, 0, "false", excludeRegions);
LogWrapper.getInstance().info(
"Starting Rebalance simulate false result >> " + result);
}
}
}
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
LogWrapper.getInstance().info("Rebalance returning result >>>" + result);
return result;
}
List tokenize(String str, String separator) {
StringTokenizer st = new StringTokenizer(str, separator);
List rstList = new ArrayList();
while (st.hasMoreTokens()) {
rstList.add(st.nextToken());
}
return rstList;
}
boolean checkResultList(CompositeResultData rebalanceResulteData,
List resultList, DistributedMember member) {
boolean toContinueForOtherMembers = false;
if (resultList != null && !resultList.isEmpty()) {
for (int i = 0; i < resultList.size(); i++) {
Object object = resultList.get(i);
if (object instanceof Exception) {
rebalanceResulteData.addSection().addData(
CliStrings.format(CliStrings.REBALANCE__MSG__NO_EXECUTION,
member.getId()), ((Exception) object).getMessage());
LogWrapper.getInstance().info(
CliStrings.REBALANCE__MSG__NO_EXECUTION + member.getId()
+ " exception=" + ((Throwable) object).getMessage(),
((Throwable) object));
toContinueForOtherMembers = true;
break;
} else if (object instanceof Throwable) {
rebalanceResulteData.addSection().addData(
CliStrings.format(CliStrings.REBALANCE__MSG__NO_EXECUTION,
member.getId()), ((Throwable) object).getMessage());
LogWrapper.getInstance().info(
CliStrings.REBALANCE__MSG__NO_EXECUTION + member.getId()
+ " exception=" + ((Throwable) object).getMessage(),
((Throwable) object));
toContinueForOtherMembers = true;
break;
}
}
} else {
LogWrapper.getInstance().info(
"Rebalancing for member=" + member.getId()
+ ", resultList is either null or empty");
rebalanceResulteData.addSection().addData(
"Rebalancing for member=" + member.getId(),
", resultList is either null or empty");
toContinueForOtherMembers = true;
}
return toContinueForOtherMembers;
}
Result executeRebalanceOnDS(Cache cache, long timeOut, String simulate,
String[] excludeRegionsList) {
Result result = null;
int index = 1;
CompositeResultData rebalanceResulteData = ResultBuilder
.createCompositeResultData();
List listMemberRegion = getMemberRegionList(cache);
if (listMemberRegion.size() == 0) {
return ResultBuilder
.createUserErrorResult(CliStrings.REBALANCE__MSG__NO_REBALANCING_REGIONS_ON_DS);
}
List listExcludedRegion = new ArrayList();
if (excludeRegionsList != null) {
for (String str : excludeRegionsList) {
listExcludedRegion.add(str);
}
}
Iterator it1 = listMemberRegion.iterator();
while (it1.hasNext()) {
try {
MemberPRInfo memberPR = (MemberPRInfo) it1.next();
// check if there are more than one members associated with region for
// rebalancing
if (memberPR.dsMemberList.size() > 1) {
//check for excluded region
Iterator it = listExcludedRegion.iterator();
boolean flag = false;
while (it.hasNext()) {
// this is needed since region name may start with / or without it
// also
if (it.next().trim().equals(memberPR.region.trim())) {
flag = true;
break;
}
}
if (flag == true) {
continue;
}
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 regionSet = new HashSet();
regionSet.add(memberPR.region);
functionArgs[1] = regionSet;
Set excludeRegionSet = new HashSet();
functionArgs[2] = excludeRegionSet;
List resultList = null;
try {
if (checkMemberPresence(dsMember, cache)) {
if (timeOut > 0) {
resultList = (ArrayList) CliUtil.executeFunction(
rebalanceFunction, functionArgs, dsMember).getResult(
timeOut, TimeUnit.SECONDS);
} else {
resultList = (ArrayList) CliUtil.executeFunction(
rebalanceFunction, functionArgs, dsMember).getResult();
}
if (checkResultList(rebalanceResulteData, resultList, dsMember) == true) {
result = ResultBuilder.buildResult(rebalanceResulteData);
continue;
}
List rstList = tokenize((String) resultList.get(0), ",");
result = ResultBuilder.buildResult(toCompositeResultData(
rebalanceResulteData, (ArrayList) rstList, index,
simulate.equals("true") ? true : false, cache));
break;
} else {
if (i == memberPR.dsMemberList.size() - 1) {
rebalanceResulteData
.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(rebalanceResulteData);
} else {
continue;
}
}
} catch (Exception ex) {
if (i == memberPR.dsMemberList.size() - 1) {
rebalanceResulteData
.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(rebalanceResulteData);
} else {
continue;
}
}
if (checkResultList(rebalanceResulteData, resultList, dsMember) == true) {
result = ResultBuilder.buildResult(rebalanceResulteData);
continue;
}
List rstList = tokenize((String) resultList.get(0), ",");
result = ResultBuilder.buildResult(toCompositeResultData(
rebalanceResulteData, (ArrayList) rstList, index,
simulate.equals("true") ? true : false, cache));
index++;
}
}
} catch (Exception e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData()
.setErrorCode(ResultBuilder.ERRORCODE_DEFAULT)
.addLine(e.getMessage());
return (ResultBuilder.buildResult(errorResultData));
}
}
return result;
}
public boolean checkMemberPresence(DistributedMember dsMember, Cache cache) {
// check if member's presence just before executing function
// this is to avoid running a function on departed members #47248
Set dsMemberList = CliUtil.getAllNormalMembers(cache);
return dsMemberList.contains(dsMember);
}
public String listOfAllMembers(ArrayList dsMemberList) {
StringBuilder listMembersId = new StringBuilder();
for (int j = 0; j < dsMemberList.size() - 1; j++) {
listMembersId.append(dsMemberList.get(j).getId());
listMembersId.append(" ; ");
}
return listMembersId.toString();
}
protected CompositeResultData toCompositeResultData(
CompositeResultData rebalanceResulteData, ArrayList rstlist,
int index, boolean simulate, Cache cache) {
// add only if there are any valid regions in results
if (rstlist.size() > resultItemCount
&& rstlist.get(resultItemCount) != null
&& rstlist.get(resultItemCount).length() > 0) {
TabularResultData table1 = rebalanceResulteData.addSection().addTable(
"Table" + index);
String newLine = System.getProperty("line.separator");
StringBuilder resultStr = new StringBuilder();
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETCREATEBYTES);
table1.accumulate("Value", rstlist.get(0));
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATEBYTES
+ " = " + rstlist.get(0));
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETCREATETIM);
table1.accumulate("Value", rstlist.get(1));
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATETIM + " = "
+ rstlist.get(1));
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETCREATESCOMPLETED);
table1.accumulate("Value", rstlist.get(2));
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATESCOMPLETED
+ " = " + rstlist.get(2));
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERBYTES);
table1.accumulate("Value", rstlist.get(3));
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERBYTES
+ " = " + rstlist.get(3));
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERTIME);
table1.accumulate("Value", rstlist.get(4));
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERTIME
+ " = " + rstlist.get(4));
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERSCOMPLETED);
table1.accumulate("Value", rstlist.get(5));
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERSCOMPLETED
+ " = " + rstlist.get(5));
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERTIME);
table1.accumulate("Value", rstlist.get(6));
resultStr.append(CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERTIME
+ " = " + rstlist.get(6));
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERSCOMPLETED);
table1.accumulate("Value", rstlist.get(7));
resultStr
.append(CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERSCOMPLETED
+ " = " + rstlist.get(7));
resultStr.append(newLine);
table1.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALTIME);
table1.accumulate("Value", rstlist.get(8));
resultStr.append(CliStrings.REBALANCE__MSG__TOTALTIME + " = "
+ rstlist.get(8));
resultStr.append(newLine);
String headerText = null;
if (simulate) {
headerText = "Simulated partition regions ";
} else {
headerText = "Rebalanced partition regions ";
}
for (int i = resultItemCount; i < rstlist.size(); i++) {
headerText = headerText + " " + rstlist.get(i);
}
table1.setHeader(headerText);
cache.getLogger().info(headerText + resultStr);
}
return rebalanceResulteData;
}
CompositeResultData buildResultForRebalance(
CompositeResultData rebalanceResulteData, RebalanceResults results,
int index, boolean simulate, Cache cache) {
Set regions = results
.getPartitionRebalanceDetails();
Iterator iterator = regions.iterator();
// add only if there are valid number of regions
if (regions.size() > 0
&& ((PartitionRebalanceInfo) iterator.next()).getRegionPath() != null
&& ((PartitionRebalanceInfo) iterator.next()).getRegionPath().length() > 0) {
final TabularResultData resultData = rebalanceResulteData.addSection()
.addTable("Table" + index);
String newLine = System.getProperty("line.separator");
StringBuilder resultStr = new StringBuilder();
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETCREATEBYTES);
resultData.accumulate("Value", results.getTotalBucketCreateBytes());
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATEBYTES
+ " = " + results.getTotalBucketCreateBytes());
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETCREATETIM);
resultData.accumulate("Value", results.getTotalBucketCreateTime());
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATETIM + " = "
+ results.getTotalBucketCreateTime());
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETCREATESCOMPLETED);
resultData.accumulate("Value", results.getTotalBucketCreatesCompleted());
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETCREATESCOMPLETED
+ " = " + results.getTotalBucketCreatesCompleted());
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERBYTES);
resultData.accumulate("Value", results.getTotalBucketTransferBytes());
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERBYTES
+ " = " + results.getTotalBucketTransferBytes());
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERTIME);
resultData.accumulate("Value", results.getTotalBucketTransferTime());
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERTIME
+ " = " + results.getTotalBucketTransferTime());
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERSCOMPLETED);
resultData
.accumulate("Value", results.getTotalBucketTransfersCompleted());
resultStr.append(CliStrings.REBALANCE__MSG__TOTALBUCKETTRANSFERSCOMPLETED
+ " = " + results.getTotalBucketTransfersCompleted());
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERTIME);
resultData.accumulate("Value", results.getTotalPrimaryTransferTime());
resultStr.append(CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERTIME
+ " = " + results.getTotalPrimaryTransferTime());
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERSCOMPLETED);
resultData.accumulate("Value",
results.getTotalPrimaryTransfersCompleted());
resultStr
.append(CliStrings.REBALANCE__MSG__TOTALPRIMARYTRANSFERSCOMPLETED
+ " = " + results.getTotalPrimaryTransfersCompleted());
resultStr.append(newLine);
resultData.accumulate("Rebalanced Stats",
CliStrings.REBALANCE__MSG__TOTALTIME);
resultData.accumulate("Value", results.getTotalTime());
resultStr.append(CliStrings.REBALANCE__MSG__TOTALTIME + " = "
+ results.getTotalTime());
resultStr.append(newLine);
Iterator it = regions.iterator();
String headerText = null;
if (simulate) {
headerText = "Simulated partition regions ";
} else {
headerText = "Rebalanced partition regions ";
}
while (it.hasNext()) {
PartitionRebalanceInfo rgn = it.next();
headerText = headerText + " " + rgn.getRegionPath();
}
resultData.setHeader(resultData.getHeader() + headerText);
cache.getLogger().info(headerText + resultStr);
}
return rebalanceResulteData;
}
public DistributedMember getAssociatedMembers(String region, final Cache cache) {
DistributedRegionMXBean bean = ManagementService.getManagementService(
GemFireCacheImpl.getInstance()).getDistributedRegionMXBean(region);
DistributedMember member = null;
if (bean == null) {
return member;
}
String[] membersName = bean.getMembers();
Set dsMembers = CliUtil.getAllMembers(cache);
Iterator it = dsMembers.iterator();
boolean matchFound = false;
if (membersName.length > 1) {
while (it.hasNext() && matchFound == false) {
DistributedMember dsmember = (DistributedMember) it.next();
for (String memberName : membersName) {
if (MBeanJMXAdapter.getMemberNameOrId(dsmember).equals(memberName)) {
member = dsmember;
matchFound = true;
break;
}
}
}
}
return member;
}
List getMemberRegionList(Cache cache) {
List listMemberPRInfo = new ArrayList();
String[] listDSRegions = ManagementService.getManagementService(cache)
.getDistributedSystemMXBean().listRegions();
final Set dsMembers = CliUtil.getAllMembers(cache);
for (String regionName : listDSRegions) {
// remove this prefix / once Rishi fixes this
DistributedRegionMXBean bean = ManagementService.getManagementService(
GemFireCacheImpl.getInstance()).getDistributedRegionMXBean(
Region.SEPARATOR + 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())) {
String[] memberNames = bean.getMembers();
for (DistributedMember dsmember : dsMembers) {
for (String memberName : memberNames) {
if (MBeanJMXAdapter.getMemberNameOrId(dsmember)
.equals(memberName)) {
MemberPRInfo memberAndItsPRRegions = new MemberPRInfo();
memberAndItsPRRegions.region = regionName;
memberAndItsPRRegions.dsMemberList.add(dsmember);
if (listMemberPRInfo.contains(memberAndItsPRRegions)) {
// add member for appropriate region
int index = listMemberPRInfo.indexOf(memberAndItsPRRegions);
MemberPRInfo listMember = listMemberPRInfo.get(index);
listMember.dsMemberList.add(dsmember);
} else {
listMemberPRInfo.add(memberAndItsPRRegions);
}
break;
}
}
}
}
}
}
return listMemberPRInfo;
}
@CliCommand(value = CliStrings.EXPORT_DATA, help = CliStrings.EXPORT_DATA__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEMFIRE_DATA,
CliStrings.TOPIC_GEMFIRE_REGION })
public Result exportData(
@CliOption(key = CliStrings.EXPORT_DATA__REGION, mandatory = true, optionContext = ConverterHint.REGIONPATH, help = CliStrings.EXPORT_DATA__REGION__HELP) String regionName,
@CliOption(key = CliStrings.EXPORT_DATA__FILE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, mandatory = true, help = CliStrings.EXPORT_DATA__FILE__HELP) String filePath,
@CliOption(key = CliStrings.EXPORT_DATA__MEMBER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, mandatory = true, help = CliStrings.EXPORT_DATA__MEMBER__HELP) String memberNameOrId) {
final Cache cache = CacheFactory.getAnyInstance();
final DistributedMember targetMember = CliUtil
.getDistributedMemberByNameOrId(memberNameOrId);
Result result = null;
if (!filePath.endsWith(CliStrings.GEMFIRE_DATA_FILE_EXTENSION)) {
return ResultBuilder.createUserErrorResult(CliStrings.format(
CliStrings.INVALID_FILE_EXTENTION,
CliStrings.GEMFIRE_DATA_FILE_EXTENSION));
}
try {
if (targetMember != null) {
final String args[] = { regionName, filePath };
ResultCollector rc = CliUtil.executeFunction(exportDataFunction,
args, targetMember);
List