Search in sources :

Example 1 with LeaderSessionMessage

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

the class FlinkResourceManager method triggerConnectingToJobManager.

/**
	 * Causes the resource manager to announce itself at the new leader JobManager and
	 * obtains its connection information and currently known TaskManagers.
	 *
	 * @param leaderAddress The akka actor URL of the new leader JobManager.
	 */
protected void triggerConnectingToJobManager(String leaderAddress) {
    LOG.info("Trying to associate with JobManager leader " + leaderAddress);
    final Object registerMessage = decorateMessage(new RegisterResourceManager(self()));
    final Object retryMessage = decorateMessage(new TriggerRegistrationAtJobManager(leaderAddress));
    // send the registration message to the JobManager
    ActorSelection jobManagerSel = context().actorSelection(leaderAddress);
    Future<Object> future = Patterns.ask(jobManagerSel, registerMessage, new Timeout(messageTimeout));
    future.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(Throwable failure, Object msg) {
            // only process if we haven't been connected in the meantime
            if (jobManager == null) {
                if (msg != null) {
                    if (msg instanceof LeaderSessionMessage && ((LeaderSessionMessage) msg).message() instanceof RegisterResourceManagerSuccessful) {
                        self().tell(msg, ActorRef.noSender());
                    } else {
                        LOG.error("Invalid response type to registration at JobManager: {}", msg);
                        self().tell(retryMessage, ActorRef.noSender());
                    }
                } else {
                    // no success
                    LOG.error("Resource manager could not register at JobManager", failure);
                    self().tell(retryMessage, ActorRef.noSender());
                }
            }
        }
    }, context().dispatcher());
}
Also used : LeaderSessionMessage(org.apache.flink.runtime.messages.JobManagerMessages.LeaderSessionMessage) TriggerRegistrationAtJobManager(org.apache.flink.runtime.clusterframework.messages.TriggerRegistrationAtJobManager) ActorSelection(akka.actor.ActorSelection) Timeout(akka.util.Timeout) RegisterResourceManagerSuccessful(org.apache.flink.runtime.clusterframework.messages.RegisterResourceManagerSuccessful) RegisterResourceManager(org.apache.flink.runtime.clusterframework.messages.RegisterResourceManager)

Example 2 with LeaderSessionMessage

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

the class FlinkUntypedActor method handleLeaderSessionID.

/**
	 * This method filters out {@link LeaderSessionMessage} whose leader session ID is not equal
	 * to the actors leader session ID. If a message of type {@link RequiresLeaderSessionID}
	 * arrives, then an Exception is thrown, because these messages have to be wrapped in a
	 * {@link LeaderSessionMessage}.
	 *
	 * @param message Incoming message
	 * @throws Exception
	 */
private void handleLeaderSessionID(Object message) throws Exception {
    if (message instanceof LeaderSessionMessage) {
        LeaderSessionMessage msg = (LeaderSessionMessage) message;
        UUID expectedID = getLeaderSessionID();
        UUID actualID = msg.leaderSessionID();
        if (expectedID == actualID || (expectedID != null && expectedID.equals(actualID))) {
            handleMessage(msg.message());
        } else {
            handleDiscardedMessage(expectedID, msg);
        }
    } else if (message instanceof RequiresLeaderSessionID) {
        throw new Exception("Received a message " + message + " without a leader session " + "ID, even though the message requires a leader session ID.");
    } else {
        // call method to handle message
        handleMessage(message);
    }
}
Also used : LeaderSessionMessage(org.apache.flink.runtime.messages.JobManagerMessages.LeaderSessionMessage) RequiresLeaderSessionID(org.apache.flink.runtime.messages.RequiresLeaderSessionID) UUID(java.util.UUID)

Example 3 with LeaderSessionMessage

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

the class TaskManagerRegistrationTest method testCheckForValidRegistrationSessionIDs.

@Test
public void testCheckForValidRegistrationSessionIDs() {
    new JavaTestKit(actorSystem) {

        {
            ActorGateway taskManagerGateway = null;
            try {
                // we make the test actor (the test kit) the JobManager to intercept
                // the messages
                taskManagerGateway = createTaskManager(actorSystem, getTestActor(), config, true, false);
                final ActorRef taskManager = taskManagerGateway.actor();
                final UUID falseLeaderSessionID = UUID.randomUUID();
                final UUID trueLeaderSessionID = null;
                new Within(timeout) {

                    @Override
                    protected void run() {
                        taskManager.tell(TaskManagerMessages.getNotifyWhenRegisteredAtJobManagerMessage(), getTestActor());
                        // the TaskManager should try to register
                        LeaderSessionMessage lsm = expectMsgClass(LeaderSessionMessage.class);
                        assertTrue(lsm.leaderSessionID() == trueLeaderSessionID);
                        assertTrue(lsm.message() instanceof RegisterTaskManager);
                        final ActorRef tm = getLastSender();
                        // This AcknowledgeRegistration message should be discarded because the
                        // registration session ID is wrong
                        tm.tell(new LeaderSessionMessage(falseLeaderSessionID, new AcknowledgeRegistration(new InstanceID(), 1)), getTestActor());
                        // Valid AcknowledgeRegistration message
                        tm.tell(new LeaderSessionMessage(trueLeaderSessionID, new AcknowledgeRegistration(new InstanceID(), 1)), getTestActor());
                        Object message = null;
                        Object confirmMessageClass = TaskManagerMessages.getRegisteredAtJobManagerMessage().getClass();
                        while (message == null || !(message.getClass().equals(confirmMessageClass))) {
                            message = receiveOne(TestingUtils.TESTING_DURATION());
                        }
                        tm.tell(JobManagerMessages.getRequestLeaderSessionID(), getTestActor());
                        expectMsgEquals(new JobManagerMessages.ResponseLeaderSessionID(trueLeaderSessionID));
                    }
                };
            } catch (Throwable e) {
                e.printStackTrace();
                fail(e.getMessage());
            } finally {
                stopActor(taskManagerGateway);
            }
        }
    };
}
Also used : LeaderSessionMessage(org.apache.flink.runtime.messages.JobManagerMessages.LeaderSessionMessage) RegisterTaskManager(org.apache.flink.runtime.messages.RegistrationMessages.RegisterTaskManager) InstanceID(org.apache.flink.runtime.instance.InstanceID) ActorRef(akka.actor.ActorRef) JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) AcknowledgeRegistration(org.apache.flink.runtime.messages.RegistrationMessages.AcknowledgeRegistration) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) UUID(java.util.UUID) JavaTestKit(akka.testkit.JavaTestKit) Test(org.junit.Test)

Aggregations

LeaderSessionMessage (org.apache.flink.runtime.messages.JobManagerMessages.LeaderSessionMessage)3 UUID (java.util.UUID)2 ActorRef (akka.actor.ActorRef)1 ActorSelection (akka.actor.ActorSelection)1 JavaTestKit (akka.testkit.JavaTestKit)1 Timeout (akka.util.Timeout)1 RegisterResourceManager (org.apache.flink.runtime.clusterframework.messages.RegisterResourceManager)1 RegisterResourceManagerSuccessful (org.apache.flink.runtime.clusterframework.messages.RegisterResourceManagerSuccessful)1 TriggerRegistrationAtJobManager (org.apache.flink.runtime.clusterframework.messages.TriggerRegistrationAtJobManager)1 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)1 InstanceID (org.apache.flink.runtime.instance.InstanceID)1 JobManagerMessages (org.apache.flink.runtime.messages.JobManagerMessages)1 AcknowledgeRegistration (org.apache.flink.runtime.messages.RegistrationMessages.AcknowledgeRegistration)1 RegisterTaskManager (org.apache.flink.runtime.messages.RegistrationMessages.RegisterTaskManager)1 RequiresLeaderSessionID (org.apache.flink.runtime.messages.RequiresLeaderSessionID)1 Test (org.junit.Test)1