use of org.apache.geode.management.internal.cli.functions.RebalanceFunction 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;
}
Aggregations