Search in sources :

Example 1 with ResponseWebMonitorPort

use of org.apache.flink.runtime.messages.JobManagerMessages.ResponseWebMonitorPort in project flink by apache.

the class JobManagerRetriever method notifyLeaderAddress.

@Override
public void notifyLeaderAddress(final String leaderAddress, final UUID leaderSessionID) {
    if (leaderAddress != null && !leaderAddress.equals("")) {
        try {
            final Promise<Tuple2<ActorGateway, Integer>> leaderGatewayPortPromise = new scala.concurrent.impl.Promise.DefaultPromise<>();
            synchronized (waitLock) {
                leaderGatewayPortFuture = leaderGatewayPortPromise.future();
                waitLock.notifyAll();
            }
            LOG.info("New leader reachable under {}:{}.", leaderAddress, leaderSessionID);
            AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, lookupTimeout).flatMap(new Mapper<ActorRef, Future<Tuple2<ActorGateway, Object>>>() {

                @Override
                public Future<Tuple2<ActorGateway, Object>> apply(ActorRef jobManagerRef) {
                    ActorGateway leaderGateway = new AkkaActorGateway(jobManagerRef, leaderSessionID);
                    Future<Object> webMonitorPort = leaderGateway.ask(JobManagerMessages.getRequestWebMonitorPort(), timeout);
                    return Futures.successful(leaderGateway).zip(webMonitorPort);
                }
            }, actorSystem.dispatcher()).onComplete(new OnComplete<Tuple2<ActorGateway, Object>>() {

                @Override
                public void onComplete(Throwable failure, Tuple2<ActorGateway, Object> success) throws Throwable {
                    if (failure == null) {
                        if (success._2() instanceof ResponseWebMonitorPort) {
                            int webMonitorPort = ((ResponseWebMonitorPort) success._2()).port();
                            leaderGatewayPortPromise.success(new Tuple2<>(success._1(), webMonitorPort));
                        } else {
                            leaderGatewayPortPromise.failure(new Exception("Received the message " + success._2() + " as response to " + JobManagerMessages.getRequestWebMonitorPort() + ". But a message of type " + ResponseWebMonitorPort.class + " was expected."));
                        }
                    } else {
                        LOG.warn("Failed to retrieve leader gateway and port.", failure);
                        leaderGatewayPortPromise.failure(failure);
                    }
                }
            }, actorSystem.dispatcher());
        } catch (Exception e) {
            handleError(e);
        }
    }
}
Also used : AkkaActorGateway(org.apache.flink.runtime.instance.AkkaActorGateway) ActorRef(akka.actor.ActorRef) ResponseWebMonitorPort(org.apache.flink.runtime.messages.JobManagerMessages.ResponseWebMonitorPort) TimeoutException(java.util.concurrent.TimeoutException) Mapper(akka.dispatch.Mapper) Tuple2(scala.Tuple2) AkkaActorGateway(org.apache.flink.runtime.instance.AkkaActorGateway) ActorGateway(org.apache.flink.runtime.instance.ActorGateway)

Aggregations

ActorRef (akka.actor.ActorRef)1 Mapper (akka.dispatch.Mapper)1 TimeoutException (java.util.concurrent.TimeoutException)1 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)1 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)1 ResponseWebMonitorPort (org.apache.flink.runtime.messages.JobManagerMessages.ResponseWebMonitorPort)1 Tuple2 (scala.Tuple2)1