use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class SingleHopClientExecutor method submitAllHA.
static boolean submitAllHA(List callableTasks, LocalRegion region, boolean isHA, ResultCollector rc, Set<String> failedNodes) {
ClientMetadataService cms = region.getCache().getClientMetadataService();
boolean reexecute = false;
if (callableTasks != null && !callableTasks.isEmpty()) {
List futures = null;
try {
futures = execService.invokeAll(callableTasks);
} catch (RejectedExecutionException rejectedExecutionEx) {
throw rejectedExecutionEx;
} catch (InterruptedException e) {
throw new InternalGemFireException(e.getMessage());
}
if (futures != null) {
GemFireException functionExecutionException = null;
Iterator futureItr = futures.iterator();
Iterator taskItr = callableTasks.iterator();
final boolean isDebugEnabled = logger.isDebugEnabled();
while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
Future fut = (Future) futureItr.next();
SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
ServerLocation server = task.getServer();
try {
fut.get();
if (isDebugEnabled) {
logger.debug("ExecuteRegionFunctionSingleHopOp#got result from {}", server);
}
} catch (InterruptedException e) {
throw new InternalGemFireException(e.getMessage());
} catch (ExecutionException ee) {
if (ee.getCause() instanceof InternalFunctionInvocationTargetException) {
if (isDebugEnabled) {
logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.InternalFunctionInvocationTargetException : Caused by :{}", ee.getCause());
}
try {
cms = region.getCache().getClientMetadataService();
} catch (CacheClosedException e) {
return false;
}
cms.removeBucketServerLocation(server);
cms.scheduleGetPRMetaData(region, false);
reexecute = true;
failedNodes.addAll(((InternalFunctionInvocationTargetException) ee.getCause()).getFailedNodeSet());
// Clear the results only if isHA so that partial results can be returned.
if (isHA) {
rc.clearResults();
} else {
if (ee.getCause().getCause() != null) {
functionExecutionException = new FunctionInvocationTargetException(ee.getCause().getCause());
} else {
functionExecutionException = new FunctionInvocationTargetException(new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString()));
}
}
} else if (ee.getCause() instanceof FunctionException) {
if (isDebugEnabled) {
logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.FunctionException : Caused by :{}", ee.getCause());
}
FunctionException fe = (FunctionException) ee.getCause();
if (isHA) {
throw fe;
} else {
functionExecutionException = fe;
}
} else if (ee.getCause() instanceof ServerOperationException) {
if (isDebugEnabled) {
logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
}
ServerOperationException soe = (ServerOperationException) ee.getCause();
if (isHA) {
throw soe;
} else {
functionExecutionException = soe;
}
} else if (ee.getCause() instanceof ServerConnectivityException) {
if (isDebugEnabled) {
logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
}
try {
cms = region.getCache().getClientMetadataService();
} catch (CacheClosedException e) {
return false;
}
cms.removeBucketServerLocation(server);
cms.scheduleGetPRMetaData(region, false);
// Clear the results only if isHA so that partial results can be returned.
if (isHA) {
reexecute = true;
rc.clearResults();
} else {
functionExecutionException = (ServerConnectivityException) ee.getCause();
}
} else {
throw executionThrowable(ee.getCause());
}
}
}
if (functionExecutionException != null) {
throw functionExecutionException;
}
}
}
return reexecute;
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class PRFunctionStreamingResultCollector method getResult.
@Override
public Object getResult() throws FunctionException {
if (this.resultCollected) {
throw new FunctionException("Result already collected");
}
this.resultCollected = true;
if (this.hasResult) {
try {
this.waitForCacheOrFunctionException(0);
if (!this.execution.getFailedNodes().isEmpty() && !this.execution.isClientServerMode()) {
// end the rc and clear it
endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
throw new FunctionException(this.fites.get(0));
}
} catch (FunctionInvocationTargetException fite) {
// the function.
if (!execution.getWaitOnExceptionFlag()) {
if (!this.fn.isHA()) {
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(iFITE);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
} catch (BucketMovedException e) {
if (!execution.getWaitOnExceptionFlag()) {
if (!this.fn.isHA()) {
// endResults();
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
// endResults();
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
// endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
} catch (CacheClosedException e) {
if (!execution.getWaitOnExceptionFlag()) {
if (!this.fn.isHA()) {
// endResults();
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
// endResults();
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(fite);
} else {
// endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
} catch (CacheException e) {
// endResults();
throw new FunctionException(e);
} catch (ForceReattemptException e) {
// the function.
if (!this.fn.isHA()) {
throw new FunctionException(e);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(iFITE);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
}
return this.userRC.getResult();
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class ConfigCommands method describeConfig.
@CliCommand(value = { CliStrings.DESCRIBE_CONFIG }, help = CliStrings.DESCRIBE_CONFIG__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeConfig(@CliOption(key = CliStrings.DESCRIBE_CONFIG__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_CONFIG__MEMBER__HELP, mandatory = true) String memberNameOrId, @CliOption(key = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS, help = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS__HELP, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true") boolean hideDefaults) {
Result result = null;
try {
DistributedMember targetMember = null;
if (memberNameOrId != null && !memberNameOrId.isEmpty()) {
targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
}
if (targetMember != null) {
ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberConfigFunction, new Boolean(hideDefaults), targetMember);
ArrayList<?> output = (ArrayList<?>) rc.getResult();
Object obj = output.get(0);
if (obj != null && obj instanceof MemberConfigurationInfo) {
MemberConfigurationInfo memberConfigInfo = (MemberConfigurationInfo) obj;
CompositeResultData crd = ResultBuilder.createCompositeResultData();
crd.setHeader(CliStrings.format(CliStrings.DESCRIBE_CONFIG__HEADER__TEXT, memberNameOrId));
List<String> jvmArgsList = memberConfigInfo.getJvmInputArguments();
TabularResultData jvmInputArgs = crd.addSection().addSection().addTable();
for (String jvmArg : jvmArgsList) {
jvmInputArgs.accumulate("JVM command line arguments", jvmArg);
}
addSection(crd, memberConfigInfo.getGfePropsSetUsingApi(), "GemFire properties defined using the API");
addSection(crd, memberConfigInfo.getGfePropsRuntime(), "GemFire properties defined at the runtime");
addSection(crd, memberConfigInfo.getGfePropsSetFromFile(), "GemFire properties defined with the property file");
addSection(crd, memberConfigInfo.getGfePropsSetWithDefaults(), "GemFire properties using default values");
addSection(crd, memberConfigInfo.getCacheAttributes(), "Cache attributes");
List<Map<String, String>> cacheServerAttributesList = memberConfigInfo.getCacheServerAttributes();
if (cacheServerAttributesList != null && !cacheServerAttributesList.isEmpty()) {
SectionResultData cacheServerSection = crd.addSection();
cacheServerSection.setHeader("Cache-server attributes");
for (Map<String, String> cacheServerAttributes : cacheServerAttributesList) {
addSubSection(cacheServerSection, cacheServerAttributes, "");
}
}
result = ResultBuilder.buildResult(crd);
}
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(CliStrings.format(CliStrings.DESCRIBE_CONFIG__MEMBER__NOT__FOUND, new Object[] { memberNameOrId }));
result = ResultBuilder.buildResult(erd);
}
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.DESCRIBE_CONFIG));
} catch (Exception e) {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(e.getMessage());
result = ResultBuilder.buildResult(erd);
}
return result;
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class DataCommands method importData.
@CliCommand(value = CliStrings.IMPORT_DATA, help = CliStrings.IMPORT_DATA__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
public Result importData(@CliOption(key = CliStrings.IMPORT_DATA__REGION, optionContext = ConverterHint.REGION_PATH, mandatory = true, help = CliStrings.IMPORT_DATA__REGION__HELP) String regionName, @CliOption(key = CliStrings.IMPORT_DATA__FILE, mandatory = true, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.IMPORT_DATA__FILE__HELP) String filePath, @CliOption(key = CliStrings.IMPORT_DATA__MEMBER, mandatory = true, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.IMPORT_DATA__MEMBER__HELP) String memberNameOrId, @CliOption(key = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS, unspecifiedDefaultValue = "false", help = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS__HELP) boolean invokeCallbacks) {
this.securityService.authorizeRegionWrite(regionName);
Result result;
try {
final DistributedMember targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
if (!filePath.endsWith(CliStrings.GEODE_DATA_FILE_EXTENSION)) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, CliStrings.GEODE_DATA_FILE_EXTENSION));
}
if (targetMember != null) {
final Object[] args = { regionName, filePath, invokeCallbacks };
ResultCollector<?, ?> rc = CliUtil.executeFunction(importDataFunction, args, targetMember);
List<Object> results = (List<Object>) rc.getResult();
if (results != null) {
Object resultObj = results.get(0);
if (resultObj instanceof String) {
result = ResultBuilder.createInfoResult((String) resultObj);
} else if (resultObj instanceof Exception) {
result = ResultBuilder.createGemFireErrorResult(((Exception) resultObj).getMessage());
} else {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
} else {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
} else {
result = ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.IMPORT_DATA__MEMBER__NOT__FOUND, memberNameOrId));
}
} catch (CacheClosedException e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
return result;
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class FunctionStreamingResultCollector method getResult.
public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
long timeoutInMillis = unit.toMillis(timeout);
if (this.resultCollected) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
}
this.resultCollected = true;
// Should convert it from unit to milliseconds
if (this.userRC != null) {
try {
long timeBefore = System.currentTimeMillis();
boolean isNotTimedOut;
if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
isNotTimedOut = this.waitForCacheOrFunctionException(timeoutInMillis);
} else {
isNotTimedOut = this.waitForRepliesUninterruptibly(timeoutInMillis);
}
if (!isNotTimedOut) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_NOT_COLLECTED_IN_TIME_PROVIDED.toLocalizedString());
}
long timeAfter = System.currentTimeMillis();
timeoutInMillis = timeoutInMillis - (timeAfter - timeBefore);
if (timeoutInMillis < 0)
timeoutInMillis = 0;
if (this.removedNodes != null) {
if (this.removedNodes.size() != 0) {
// end the rc and clear it
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
}
if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
throw new FunctionException(this.fites.get(0));
}
} catch (FunctionInvocationTargetException fite) {
// function.
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage());
throw new FunctionException(iFITE);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
} catch (CacheClosedException e) {
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
}// }
catch (ForceReattemptException e) {
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
} catch (ReplyException e) {
if (!(execution.waitOnException || execution.forwardExceptions)) {
throw new FunctionException(e.getCause());
}
}
return this.userRC.getResult(timeoutInMillis, unit);
}
return null;
}
Aggregations