Search in sources :

Example 1 with AkkaRpcException

use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.

the class AkkaRpcActor method serializeRemoteResultAndVerifySize.

private Either<AkkaRpcSerializedValue, AkkaRpcException> serializeRemoteResultAndVerifySize(Object result, String methodName) {
    try {
        AkkaRpcSerializedValue serializedResult = AkkaRpcSerializedValue.valueOf(result);
        long resultSize = serializedResult.getSerializedDataLength();
        if (resultSize > maximumFramesize) {
            return Either.Right(new AkkaRpcException("The method " + methodName + "'s result size " + resultSize + " exceeds the maximum size " + maximumFramesize + " ."));
        } else {
            return Either.Left(serializedResult);
        }
    } catch (IOException e) {
        return Either.Right(new AkkaRpcException("Failed to serialize the result for RPC call : " + methodName + '.', e));
    }
}
Also used : IOException(java.io.IOException) AkkaRpcException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException)

Example 2 with AkkaRpcException

use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.

the class AkkaRpcActor method handleMessage.

private void handleMessage(final Object message) {
    if (state.isRunning()) {
        mainThreadValidator.enterMainThread();
        try {
            handleRpcMessage(message);
        } finally {
            mainThreadValidator.exitMainThread();
        }
    } else {
        log.info("The rpc endpoint {} has not been started yet. Discarding message {} until processing is started.", rpcEndpoint.getClass().getName(), message);
        sendErrorIfSender(new AkkaRpcException(String.format("Discard message %s, because the rpc endpoint %s has not been started yet.", message, rpcEndpoint.getAddress())));
    }
}
Also used : AkkaRpcException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException)

Example 3 with AkkaRpcException

use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.

the class AkkaRpcActor method sendAsyncResponse.

private void sendAsyncResponse(CompletableFuture<?> asyncResponse, String methodName) {
    final ActorRef sender = getSender();
    Promise.DefaultPromise<Object> promise = new Promise.DefaultPromise<>();
    FutureUtils.assertNoException(asyncResponse.handle((value, throwable) -> {
        if (throwable != null) {
            promise.failure(throwable);
        } else {
            if (isRemoteSender(sender)) {
                Either<AkkaRpcSerializedValue, AkkaRpcException> serializedResult = serializeRemoteResultAndVerifySize(value, methodName);
                if (serializedResult.isLeft()) {
                    promise.success(serializedResult.left());
                } else {
                    promise.failure(serializedResult.right());
                }
            } else {
                promise.success(new Status.Success(value));
            }
        }
        // consume the provided throwable
        return null;
    }));
    Patterns.pipe(promise.future(), getContext().dispatcher()).to(sender);
}
Also used : RunAsync(org.apache.flink.runtime.rpc.messages.RunAsync) Either(org.apache.flink.types.Either) RpcEndpoint(org.apache.flink.runtime.rpc.RpcEndpoint) LoggerFactory(org.slf4j.LoggerFactory) ClassLoadingUtils.runWithContextClassLoader(org.apache.flink.runtime.concurrent.akka.ClassLoadingUtils.runWithContextClassLoader) MainThreadValidatorUtil(org.apache.flink.runtime.rpc.MainThreadValidatorUtil) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RpcConnectionException(org.apache.flink.runtime.rpc.exceptions.RpcConnectionException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) AkkaHandshakeException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaHandshakeException) LocalRpcInvocation(org.apache.flink.runtime.rpc.messages.LocalRpcInvocation) RemoteHandshakeMessage(org.apache.flink.runtime.rpc.messages.RemoteHandshakeMessage) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) RpcGateway(org.apache.flink.runtime.rpc.RpcGateway) ActorRef(akka.actor.ActorRef) Patterns(akka.pattern.Patterns) Promise(scala.concurrent.impl.Promise) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) Nonnull(javax.annotation.Nonnull) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) CallAsync(org.apache.flink.runtime.rpc.messages.CallAsync) Logger(org.slf4j.Logger) FiniteDuration(scala.concurrent.duration.FiniteDuration) AkkaUnknownMessageException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaUnknownMessageException) HandshakeSuccessMessage(org.apache.flink.runtime.rpc.messages.HandshakeSuccessMessage) IOException(java.io.IOException) Preconditions(org.apache.flink.util.Preconditions) AkkaRpcException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException) AkkaRpcInvalidStateException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcInvalidStateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeUnit(java.util.concurrent.TimeUnit) Status(akka.actor.Status) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) RpcInvocation(org.apache.flink.runtime.rpc.messages.RpcInvocation) AbstractActor(akka.actor.AbstractActor) ReceiveBuilder(akka.japi.pf.ReceiveBuilder) Promise(scala.concurrent.impl.Promise) ActorRef(akka.actor.ActorRef) Either(org.apache.flink.types.Either)

Example 4 with AkkaRpcException

use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.

the class AkkaRpcActorTest method testMessageDiscarding.

/**
 * Tests that the {@link AkkaRpcActor} discards messages until the corresponding {@link
 * RpcEndpoint} has been started.
 */
@Test
public void testMessageDiscarding() throws Exception {
    int expectedValue = 1337;
    DummyRpcEndpoint rpcEndpoint = new DummyRpcEndpoint(akkaRpcService);
    DummyRpcGateway rpcGateway = rpcEndpoint.getSelfGateway(DummyRpcGateway.class);
    // this message should be discarded and completed with an AkkaRpcException
    CompletableFuture<Integer> result = rpcGateway.foobar();
    try {
        result.get(timeout.getSize(), timeout.getUnit());
        fail("Expected an AkkaRpcException.");
    } catch (ExecutionException ee) {
        // expected this exception, because the endpoint has not been started
        assertTrue(ee.getCause() instanceof AkkaRpcException);
    }
    // set a new value which we expect to be returned
    rpcEndpoint.setFoobar(expectedValue);
    // start the endpoint so that it can process messages
    rpcEndpoint.start();
    try {
        // send the rpc again
        result = rpcGateway.foobar();
        // now we should receive a result :-)
        Integer actualValue = result.get(timeout.getSize(), timeout.getUnit());
        assertThat("The new foobar value should have been returned.", actualValue, Is.is(expectedValue));
    } finally {
        RpcUtils.terminateRpcEndpoint(rpcEndpoint, timeout);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutionException(java.util.concurrent.ExecutionException) RpcEndpoint(org.apache.flink.runtime.rpc.RpcEndpoint) AkkaRpcException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException) Test(org.junit.Test)

Example 5 with AkkaRpcException

use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.

the class SupervisorActor method akkaRpcActorFailed.

private void akkaRpcActorFailed(ActorRef actorRef, Throwable cause) {
    LOG.warn("AkkaRpcActor {} has failed. Shutting it down now.", actorRef.path(), cause);
    for (Map.Entry<ActorRef, AkkaRpcActorRegistration> registeredAkkaRpcActor : registeredAkkaRpcActors.entrySet()) {
        final ActorRef otherActorRef = registeredAkkaRpcActor.getKey();
        if (otherActorRef.equals(actorRef)) {
            final AkkaRpcException error = new AkkaRpcException(String.format("Stopping actor %s because it failed.", actorRef.path()), cause);
            registeredAkkaRpcActor.getValue().markFailed(error);
        } else {
            final AkkaRpcException siblingException = new AkkaRpcException(String.format("Stopping actor %s because its sibling %s has failed.", otherActorRef.path(), actorRef.path()));
            registeredAkkaRpcActor.getValue().markFailed(siblingException);
        }
    }
    getContext().getSystem().terminate();
}
Also used : ActorRef(akka.actor.ActorRef) HashMap(java.util.HashMap) Map(java.util.Map) AkkaRpcException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException)

Aggregations

AkkaRpcException (org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException)5 ActorRef (akka.actor.ActorRef)2 IOException (java.io.IOException)2 RpcEndpoint (org.apache.flink.runtime.rpc.RpcEndpoint)2 AbstractActor (akka.actor.AbstractActor)1 Status (akka.actor.Status)1 ReceiveBuilder (akka.japi.pf.ReceiveBuilder)1 Patterns (akka.pattern.Patterns)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1