use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class FunctionExecutionNodePruner method groupByBucket.
public static HashMap<Integer, HashSet> groupByBucket(PartitionedRegion pr, Set routingKeys, final boolean primaryMembersNeeded, final boolean hasRoutingObjects, final boolean isBucketSetAsFilter) {
HashMap bucketToKeysMap = new HashMap();
Iterator i = routingKeys.iterator();
while (i.hasNext()) {
final Integer bucketId;
Object key = i.next();
if (isBucketSetAsFilter) {
bucketId = ((Integer) key);
} else {
if (hasRoutingObjects) {
bucketId = Integer.valueOf(PartitionedRegionHelper.getHashKey(pr, key));
} else {
bucketId = Integer.valueOf(PartitionedRegionHelper.getHashKey(pr, Operation.FUNCTION_EXECUTION, key, null, null));
}
}
InternalDistributedMember mem = null;
if (primaryMembersNeeded) {
mem = pr.getOrCreateNodeForBucketWrite(bucketId.intValue(), null);
} else {
mem = pr.getOrCreateNodeForBucketRead(bucketId.intValue());
}
if (mem == null) {
throw new FunctionException(LocalizedStrings.PartitionedRegion_NO_TARGET_NODE_FOUND_FOR_KEY_0.toLocalizedString(key));
}
HashSet bucketKeys = (HashSet) bucketToKeysMap.get(bucketId);
if (bucketKeys == null) {
// faster if this was an ArrayList
bucketKeys = new HashSet();
bucketToKeysMap.put(bucketId, bucketKeys);
}
bucketKeys.add(key);
}
return bucketToKeysMap;
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class AbstractExecution method handleException.
private void handleException(Throwable functionException, final Function fn, final FunctionContext cx, final ResultSender sender, DM dm) {
FunctionStats stats = FunctionStats.getFunctionStats(fn.getId(), dm.getSystem());
if (logger.isDebugEnabled()) {
logger.debug("Exception occurred on local node while executing Function: {}", fn.getId(), functionException);
}
stats.endFunctionExecutionWithException(fn.hasResult());
if (fn.hasResult()) {
if (waitOnException || forwardExceptions) {
if (functionException instanceof FunctionException && functionException.getCause() instanceof QueryInvalidException) {
// Handle this exception differently since it can contain
// non-serializable objects.
// java.io.NotSerializableException: antlr.CommonToken
// create a new FunctionException on the original one's message (not cause).
functionException = new FunctionException(functionException.getLocalizedMessage());
}
sender.lastResult(functionException);
} else {
((InternalResultSender) sender).setException(functionException);
}
} else {
logger.warn(LocalizedMessage.create(LocalizedStrings.FunctionService_EXCEPTION_ON_LOCAL_NODE), functionException);
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class AbstractExecution method executeFunctionOnLocalPRNode.
public void executeFunctionOnLocalPRNode(final Function fn, final FunctionContext cx, final PartitionedRegionFunctionResultSender sender, DM dm, boolean isTx) {
if (dm instanceof DistributionManager && !isTx) {
if (ServerConnection.isExecuteFunctionOnLocalNodeOnly().byteValue() == 1) {
// executed locally
ServerConnection.executeFunctionOnLocalNodeOnly((byte) 3);
executeFunctionLocally(fn, cx, sender, dm);
if (!sender.isLastResultReceived() && fn.hasResult()) {
((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
}
} else {
final DistributionManager newDM = (DistributionManager) dm;
newDM.getFunctionExcecutor().execute(new Runnable() {
public void run() {
executeFunctionLocally(fn, cx, sender, newDM);
if (!sender.isLastResultReceived() && fn.hasResult()) {
((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
}
}
});
}
} else {
executeFunctionLocally(fn, cx, sender, dm);
if (!sender.isLastResultReceived() && fn.hasResult()) {
((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
}
}
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class AbstractExecution method execute.
public ResultCollector execute(final String functionName) {
if (functionName == null) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_INPUT_FUNCTION_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString());
}
this.isFnSerializationReqd = false;
Function functionObject = FunctionService.getFunction(functionName);
if (functionObject == null) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_FUNCTION_NAMED_0_IS_NOT_REGISTERED.toLocalizedString(functionName));
}
return executeFunction(functionObject);
}
use of org.apache.geode.cache.execute.FunctionException in project geode by apache.
the class MemberRegionFunction method execute.
@Override
public void execute(FunctionContext context) {
Object[] args = (Object[]) context.getArguments();
String region = (String) args[0];
String functionId = (String) args[1];
Cache cache = CacheFactory.getAnyInstance();
try {
Function function = FunctionService.getFunction(functionId);
if (function == null) {
context.getResultSender().lastResult("For region on a member did not get function " + functionId);
}
Execution execution = FunctionService.onRegion(cache.getRegion(region));
if (execution == null) {
context.getResultSender().lastResult("For region on a member could not execute");
} else {
execution.execute(function);
context.getResultSender().lastResult("succeeded in executing on region " + region);
}
} catch (FunctionException e) {
context.getResultSender().lastResult("FunctionException in MemberRegionFunction =" + e.getMessage());
} catch (Exception e) {
context.getResultSender().lastResult("Exception in MemberRegionFunction =" + e.getMessage());
}
}
Aggregations