Search in sources :

Example 51 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerFunctionExecutor method executeOnServer.

private ResultCollector executeOnServer(Function function, ResultCollector rc, byte hasResult) {
    FunctionStats stats = FunctionStats.getFunctionStats(function.getId());
    try {
        validateExecution(function, null);
        long start = stats.startTime();
        stats.startFunctionExecution(true);
        ExecuteFunctionOp.execute(this.pool, function, this, args, memberMappedArg, this.allServers, hasResult, rc, this.isFnSerializationReqd, UserAttributes.userAttributes.get(), groups);
        stats.endFunctionExecution(start, true);
        rc.endResults();
        return rc;
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(true);
        throw functionException;
    } catch (ServerConnectivityException exception) {
        throw exception;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(true);
        throw new FunctionException(exception);
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException)

Example 52 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerToClientFunctionResultSender method lastResult.

public synchronized void lastResult(Object oneResult, DistributedMember memberID) {
    this.lastResultReceived = true;
    if (!isOkayToSendResult()) {
        if (logger.isDebugEnabled()) {
            logger.debug("ServerToClientFunctionResultSender not sending lastResult {} as the server has shutdown", oneResult);
        }
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("ServerToClientFunctionResultSender sending last result2 {} " + oneResult);
    }
    try {
        authorizeResult(oneResult);
        if (!this.fn.hasResult()) {
            throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
        }
        if (!headerSent) {
            sendHeader();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("ServerToClientFunctionResultSender sending lastResult {}", oneResult);
        }
        this.setBuffer();
        this.msg.setNumberOfParts(1);
        this.msg.addObjPart(oneResult);
        this.msg.setLastChunk(true);
        this.msg.sendChunk(this.sc);
        this.sc.setAsTrue(Command.RESPONDED);
        FunctionStats.getFunctionStats(fn.getId()).incResultsReturned();
    } catch (IOException ex) {
        if (isOkayToSendResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_IOEXCEPTION_WHILE_SENDING_LAST_CHUNK.toLocalizedString(), ex);
        }
    }
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 53 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerToClientFunctionResultSender65 method writeFunctionExceptionResponse.

@Override
protected void writeFunctionExceptionResponse(ChunkedMessage message, String errormessage, Throwable e) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug(" ServerToClientFunctionResultSender sending Function Error Response : {}", errormessage);
    }
    int numParts = 0;
    message.clear();
    if (e instanceof FunctionException && e.getCause() instanceof InternalFunctionInvocationTargetException) {
        message.setNumberOfParts(3);
        message.addObjPart(e);
        message.addStringPart(BaseCommand.getExceptionTrace(e));
        InternalFunctionInvocationTargetException fe = (InternalFunctionInvocationTargetException) e.getCause();
        message.addObjPart(fe.getFailedNodeSet());
        numParts = 3;
    } else {
        if (e instanceof FunctionException && e.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).
            e = new FunctionException(e.getLocalizedMessage());
        }
        message.setNumberOfParts(2);
        message.addObjPart(e);
        message.addStringPart(BaseCommand.getExceptionTrace(e));
        numParts = 2;
    }
    message.setServerConnection(this.sc);
    message.setLastChunkAndNumParts(true, numParts);
    // message.setLastChunk(true);
    message.sendChunk(this.sc);
    this.sc.setAsTrue(Command.RESPONDED);
}
Also used : QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 54 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerFunctionExecutor method executeOnServerNoAck.

private void executeOnServerNoAck(String functionId, byte hasResult, boolean isHA, boolean optimizeForWrite) {
    FunctionStats stats = FunctionStats.getFunctionStats(functionId);
    try {
        validateExecution(null, null);
        long start = stats.startTime();
        stats.startFunctionExecution(false);
        ExecuteFunctionNoAckOp.execute(this.pool, functionId, args, memberMappedArg, this.allServers, hasResult, this.isFnSerializationReqd, isHA, optimizeForWrite, groups);
        stats.endFunctionExecution(start, false);
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(false);
        throw functionException;
    } catch (ServerConnectivityException exception) {
        throw exception;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(false);
        throw new FunctionException(exception);
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException)

Example 55 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerRegionFunctionExecutor method executeOnServer.

private ResultCollector executeOnServer(Function function, ResultCollector collector, byte hasResult) throws FunctionException {
    ServerRegionProxy srp = getServerRegionProxy();
    FunctionStats stats = FunctionStats.getFunctionStats(function.getId(), this.region.getSystem());
    try {
        validateExecution(function, null);
        long start = stats.startTime();
        stats.startFunctionExecution(true);
        srp.executeFunction(this.region.getFullPath(), function, this, collector, hasResult, false);
        stats.endFunctionExecution(start, true);
        return collector;
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(true);
        throw functionException;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(true);
        throw new FunctionException(exception);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Aggregations

FunctionException (org.apache.geode.cache.execute.FunctionException)140 Function (org.apache.geode.cache.execute.Function)45 Execution (org.apache.geode.cache.execute.Execution)39 ResultCollector (org.apache.geode.cache.execute.ResultCollector)39 ArrayList (java.util.ArrayList)38 Test (org.junit.Test)38 HashSet (java.util.HashSet)36 CacheClosedException (org.apache.geode.cache.CacheClosedException)31 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 IOException (java.io.IOException)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)30 List (java.util.List)26 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)26 Host (org.apache.geode.test.dunit.Host)25 VM (org.apache.geode.test.dunit.VM)25 Region (org.apache.geode.cache.Region)24 IgnoredException (org.apache.geode.test.dunit.IgnoredException)24 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)24 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)22 Set (java.util.Set)21