use of org.apache.geode.cache.execute.Function in project geode by apache.
the class ExecuteRegionFunction61 method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection servConn, long start) throws IOException {
String regionName = null;
Object function = null;
Object args = null;
MemberMappedArgument memberMappedArg = null;
byte isReExecute = 0;
Set filter = null;
byte hasResult = 0;
int removedNodesSize = 0;
Set removedNodesSet = null;
int filterSize = 0, partNumber = 0;
CachedRegionHelper crHelper = servConn.getCachedRegionHelper();
try {
hasResult = clientMessage.getPart(0).getSerializedForm()[0];
if (hasResult == 1) {
servConn.setAsTrue(REQUIRES_RESPONSE);
servConn.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
}
regionName = clientMessage.getPart(1).getString();
function = clientMessage.getPart(2).getStringOrObject();
args = clientMessage.getPart(3).getObject();
Part part = clientMessage.getPart(4);
if (part != null) {
Object obj = part.getObject();
if (obj instanceof MemberMappedArgument) {
memberMappedArg = (MemberMappedArgument) obj;
}
}
isReExecute = clientMessage.getPart(5).getSerializedForm()[0];
filterSize = clientMessage.getPart(6).getInt();
if (filterSize != 0) {
filter = new HashSet();
partNumber = 7;
for (int i = 0; i < filterSize; i++) {
filter.add(clientMessage.getPart(partNumber + i).getStringOrObject());
}
}
partNumber = 7 + filterSize;
removedNodesSize = clientMessage.getPart(partNumber).getInt();
if (removedNodesSize != 0) {
removedNodesSet = new HashSet();
partNumber = partNumber + 1;
for (int i = 0; i < removedNodesSize; i++) {
removedNodesSet.add(clientMessage.getPart(partNumber + i).getStringOrObject());
}
}
} catch (ClassNotFoundException exception) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), exception);
if (hasResult == 1) {
writeChunkedException(clientMessage, exception, servConn);
servConn.setAsTrue(RESPONDED);
return;
}
}
if (function == null || regionName == null) {
String message = null;
if (function == null) {
message = LocalizedStrings.ExecuteRegionFunction_THE_INPUT_0_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString("function");
}
if (regionName == null) {
message = LocalizedStrings.ExecuteRegionFunction_THE_INPUT_0_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString("region");
}
logger.warn("{}: {}", servConn.getName(), message);
sendError(hasResult, clientMessage, message, servConn);
return;
} else {
Region region = crHelper.getRegion(regionName);
if (region == null) {
String message = LocalizedStrings.ExecuteRegionFunction_THE_REGION_NAMED_0_WAS_NOT_FOUND_DURING_EXECUTE_FUNCTION_REQUEST.toLocalizedString(regionName);
logger.warn("{}: {}", servConn.getName(), message);
sendError(hasResult, clientMessage, message, servConn);
return;
}
HandShake handShake = (HandShake) servConn.getHandshake();
int earlierClientReadTimeout = handShake.getClientReadTimeout();
handShake.setClientReadTimeout(0);
ServerToClientFunctionResultSender resultSender = null;
Function functionObject = null;
try {
if (function instanceof String) {
functionObject = FunctionService.getFunction((String) function);
if (functionObject == null) {
String message = LocalizedStrings.ExecuteRegionFunction_THE_FUNCTION_0_HAS_NOT_BEEN_REGISTERED.toLocalizedString(function);
logger.warn("{}: {}", servConn.getName(), message);
sendError(hasResult, clientMessage, message, servConn);
return;
}
} else {
functionObject = (Function) function;
}
// check if the caller is authorized to do this operation on server
AuthorizeRequest authzRequest = servConn.getAuthzRequest();
final String functionName = functionObject.getId();
final String regionPath = region.getFullPath();
ExecuteFunctionOperationContext executeContext = null;
if (authzRequest != null) {
executeContext = authzRequest.executeFunctionAuthorize(functionName, regionPath, filter, args, functionObject.optimizeForWrite());
}
// Construct execution
AbstractExecution execution = (AbstractExecution) FunctionService.onRegion(region);
ChunkedMessage m = servConn.getFunctionResponseMessage();
m.setTransactionId(clientMessage.getTransactionId());
resultSender = new ServerToClientFunctionResultSender(m, MessageType.EXECUTE_REGION_FUNCTION_RESULT, servConn, functionObject, executeContext);
if (execution instanceof PartitionedRegionFunctionExecutor) {
execution = new PartitionedRegionFunctionExecutor((PartitionedRegion) region, filter, args, memberMappedArg, resultSender, removedNodesSet, false);
} else {
execution = new DistributedRegionFunctionExecutor((DistributedRegion) region, filter, args, memberMappedArg, resultSender);
}
if (isReExecute == 1) {
execution.setIsReExecute();
}
if (logger.isDebugEnabled()) {
logger.debug("Executing Function: {} on Server: {} with Execution: {}", functionObject.getId(), servConn, execution);
}
if (hasResult == 1) {
if (function instanceof String) {
execution.execute((String) function).getResult();
} else {
execution.execute(functionObject).getResult();
}
} else {
if (function instanceof String) {
execution.execute((String) function);
} else {
execution.execute(functionObject);
}
}
} catch (IOException ioe) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), ioe);
final String message = LocalizedStrings.ExecuteRegionFunction_SERVER_COULD_NOT_SEND_THE_REPLY.toLocalizedString();
sendException(hasResult, clientMessage, message, servConn, ioe);
} catch (FunctionException fe) {
String message = fe.getMessage();
if (fe.getCause() instanceof FunctionInvocationTargetException) {
if (fe.getCause() instanceof InternalFunctionInvocationTargetException) {
// 4> in case of HA member departed
if (logger.isDebugEnabled()) {
logger.debug(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, new Object[] { function }), fe);
}
} else if (functionObject.isHA()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function + " :" + message));
} else {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), fe);
}
resultSender.setException(fe);
} else {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), fe);
sendException(hasResult, clientMessage, message, servConn, fe);
}
} catch (Exception e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), e);
String message = e.getMessage();
sendException(hasResult, clientMessage, message, servConn, e);
} finally {
handShake.setClientReadTimeout(earlierClientReadTimeout);
}
}
}
use of org.apache.geode.cache.execute.Function 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.cache.execute.Function in project geode by apache.
the class FunctionCommands method executeFunction.
@CliCommand(value = CliStrings.EXECUTE_FUNCTION, help = CliStrings.EXECUTE_FUNCTION__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_FUNCTION })
@ResourceOperation(resource = Resource.DATA, operation = Operation.WRITE)
public Result executeFunction(// TODO: Add optioncontext for functionID
@CliOption(key = CliStrings.EXECUTE_FUNCTION__ID, mandatory = true, help = CliStrings.EXECUTE_FUNCTION__ID__HELP) String functionId, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONGROUPS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.EXECUTE_FUNCTION__ONGROUPS__HELP) String[] onGroups, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONMEMBER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.EXECUTE_FUNCTION__ONMEMBER__HELP) String onMember, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.REGION_PATH, help = CliStrings.EXECUTE_FUNCTION__ONREGION__HELP) String onRegion, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ARGUMENTS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__ARGUMENTS__HELP) String[] arguments, @CliOption(key = CliStrings.EXECUTE_FUNCTION__RESULTCOLLECTOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__RESULTCOLLECTOR__HELP) String resultCollector, @CliOption(key = CliStrings.EXECUTE_FUNCTION__FILTER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__FILTER__HELP) String filterString) {
Result result = null;
CompositeResultData executeFunctionResultTable = ResultBuilder.createCompositeResultData();
TabularResultData resultTable = executeFunctionResultTable.addSection().addTable("Table1");
String headerText = "Execution summary";
resultTable.setHeader(headerText);
ResultCollector resultCollectorInstance = null;
Function function;
Set<String> filters = new HashSet<String>();
Execution execution = null;
if (functionId != null) {
functionId = functionId.trim();
}
if (onRegion != null) {
onRegion = onRegion.trim();
}
if (onMember != null) {
onMember = onMember.trim();
}
if (filterString != null) {
filterString = filterString.trim();
}
try {
// validate otherwise return right away. no need to process anything
if (functionId == null || functionId.length() == 0) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__MISSING_FUNCTIONID);
result = ResultBuilder.buildResult(errorResultData);
return result;
}
if (onRegion != null && onMember != null && onGroups != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if (onRegion != null && onMember != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if (onMember != null && onGroups != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if (onRegion != null && onGroups != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if (onRegion != null && onMember != null && onGroups != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if ((onRegion == null || onRegion.length() == 0) && (filterString != null)) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__MEMBER_SHOULD_NOT_HAVE_FILTER_FOR_EXECUTION);
result = ResultBuilder.buildResult(errorResultData);
return result;
}
InternalCache cache = getCache();
if (resultCollector != null) {
resultCollectorInstance = (ResultCollector) ClassPathLoader.getLatest().forName(resultCollector).newInstance();
}
if (filterString != null && filterString.length() > 0) {
filters.add(filterString);
}
if (onRegion == null && onMember == null && onGroups == null) {
// run function on all the members excluding locators bug#46113
// if user wish to execute on locator then he can choose --member or --group option
Set<DistributedMember> dsMembers = CliUtil.getAllNormalMembers(cache);
if (dsMembers.size() > 0) {
function = new UserFunctionExecution();
LogWrapper.getInstance().info(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__EXECUTING_0_ON_ENTIRE_DS, functionId));
for (DistributedMember member : dsMembers) {
executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
}
return ResultBuilder.buildResult(resultTable);
} else {
return ResultBuilder.createUserErrorResult(CliStrings.EXECUTE_FUNCTION__MSG__DS_HAS_NO_MEMBERS);
}
} else if (onRegion != null && onRegion.length() > 0) {
if (cache.getRegion(onRegion) == null) {
// find a member where region is present
DistributedRegionMXBean bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean(onRegion);
if (bean == null) {
bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean(Region.SEPARATOR + onRegion);
if (bean == null) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__MXBEAN_0_FOR_NOT_FOUND, onRegion));
}
}
DistributedMember member = null;
String[] membersName = bean.getMembers();
Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
Iterator it = dsMembers.iterator();
boolean matchFound = false;
if (membersName.length > 0) {
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;
}
}
}
}
if (matchFound == true) {
executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
return ResultBuilder.buildResult(resultTable);
} else {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__NO_ASSOCIATED_MEMBER_REGION, " " + onRegion));
}
} else {
execution = FunctionService.onRegion(cache.getRegion(onRegion));
if (execution != null) {
if (resultCollectorInstance != null) {
execution = execution.withCollector(resultCollectorInstance);
}
if (filters != null && filters.size() > 0) {
execution = execution.withFilter(filters);
}
if (arguments != null && arguments.length > 0) {
execution = execution.setArguments(arguments);
}
try {
List<Object> results = (List<Object>) execution.execute(functionId).getResult();
if (results.size() > 0) {
StringBuilder strResult = new StringBuilder();
for (Object obj : results) {
strResult.append(obj);
}
toTabularResultData(resultTable, cache.getDistributedSystem().getDistributedMember().getId(), strResult.toString());
}
return ResultBuilder.buildResult(resultTable);
} catch (FunctionException e) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_EXECUTING_0_ON_REGION_1_DETAILS_2, functionId, onRegion, e.getMessage()));
}
} else {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_EXECUTING_0_ON_REGION_1_DETAILS_2, functionId, onRegion, CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_RETRIEVING_EXECUTOR));
}
}
} else if (onGroups != null) {
// execute on group members
Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
for (String grp : onGroups) {
dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
}
StringBuilder successMessage = new StringBuilder();
if (dsMembers.size() > 0) {
for (DistributedMember member : dsMembers) {
executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
}
return ResultBuilder.buildResult(resultTable);
} else {
StringBuilder grps = new StringBuilder();
for (String grp : onGroups) {
grps.append(grp);
grps.append(", ");
}
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__GROUPS_0_HAS_NO_MEMBERS, grps.toString().substring(0, grps.toString().length() - 1)));
}
} else if (onMember != null && onMember.length() > 0) {
// fix for bug
DistributedMember member = CliUtil.getDistributedMemberByNameOrId(onMember);
// 45658
if (member != null) {
executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
} else {
toTabularResultData(resultTable, onMember, CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__NO_ASSOCIATED_MEMBER + " " + onMember));
}
return ResultBuilder.buildResult(resultTable);
}
} catch (InstantiationException e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (IllegalAccessException e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (IllegalArgumentException e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (SecurityException e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (Exception e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
}
return result;
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class MiscellaneousCommands method shutdownNode.
public void shutdownNode(final long timeout, final Set<DistributedMember> includeMembers) throws TimeoutException, InterruptedException, ExecutionException {
ExecutorService exec = Executors.newSingleThreadExecutor();
try {
final Function shutDownFunction = new ShutDownFunction();
logger.info("Gfsh executing shutdown on members " + includeMembers);
Callable<String> shutdownNodes = new Callable<String>() {
@Override
public String call() {
try {
Execution execution = FunctionService.onMembers(includeMembers);
execution.execute(shutDownFunction);
} catch (FunctionException functionEx) {
// Expected Exception as the function is shutting down the target members and the result
// collector will get member departed exception
}
return "SUCCESS";
}
};
Future<String> result = exec.submit(shutdownNodes);
result.get(timeout, TimeUnit.MILLISECONDS);
} catch (TimeoutException te) {
logger.error("TimeoutException in shutting down members." + includeMembers);
throw te;
} catch (InterruptedException e) {
logger.error("InterruptedException in shutting down members." + includeMembers);
throw e;
} catch (ExecutionException e) {
logger.error("ExecutionException in shutting down members." + includeMembers);
throw e;
} finally {
exec.shutdownNow();
}
}
use of org.apache.geode.cache.execute.Function in project geode by apache.
the class MiscellaneousCommands method executeAndBuildResult.
Result executeAndBuildResult(TabularResultData resultTable, Set<DistributedMember> dsMembers) {
try {
List<?> resultList = null;
Function garbageCollectionFunction = new GarbageCollectionFunction();
resultList = (List<?>) CliUtil.executeFunction(garbageCollectionFunction, null, dsMembers).getResult();
for (int i = 0; i < resultList.size(); i++) {
Object object = resultList.get(i);
if (object instanceof Exception) {
LogWrapper.getInstance().fine("Exception in GC " + ((Throwable) object).getMessage(), ((Throwable) object));
continue;
} else if (object instanceof Throwable) {
LogWrapper.getInstance().fine("Exception in GC " + ((Throwable) object).getMessage(), ((Throwable) object));
continue;
}
if (object != null) {
if (object instanceof String) {
// unexpected exception string - cache may be closed or something
return ResultBuilder.createUserErrorResult((String) object);
} else {
Map<String, String> resultMap = (Map<String, String>) object;
toTabularResultData(resultTable, (String) resultMap.get("MemberId"), (String) resultMap.get("HeapSizeBeforeGC"), (String) resultMap.get("HeapSizeAfterGC"), (String) resultMap.get("TimeSpentInGC"));
}
} else {
LogWrapper.getInstance().fine("ResultMap was null ");
}
}
} catch (Exception e) {
String stack = CliUtil.stackTraceAsString(e);
LogWrapper.getInstance().info("GC exception is " + stack);
return ResultBuilder.createGemFireErrorResult(e.getMessage() + ": " + stack);
}
return ResultBuilder.buildResult(resultTable);
}
Aggregations