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());
}
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);
}
}
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);
}
}
};
}
Aggregations