Search in sources :

Example 1 with NotifyResourceStarted

use of org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted in project flink by apache.

the class ResourceManagerTest method testResourceRemoval.

@Test
public void testResourceRemoval() {
    new JavaTestKit(system) {

        {
            new Within(duration("10 seconds")) {

                @Override
                protected void run() {
                    fakeJobManager = TestingUtils.createForwardingActor(system, getTestActor(), Option.<String>empty());
                    resourceManager = TestingUtils.createResourceManager(system, fakeJobManager.actor(), config);
                    // register with JM
                    expectMsgClass(RegisterResourceManager.class);
                    resourceManager.tell(new RegisterResourceManagerSuccessful(fakeJobManager.actor(), Collections.<ResourceID>emptyList()), fakeJobManager);
                    ResourceID resourceID = ResourceID.generate();
                    // remove unknown resource
                    resourceManager.tell(new RemoveResource(resourceID), fakeJobManager);
                    // Send task manager registration
                    resourceManager.tell(new NotifyResourceStarted(resourceID), fakeJobManager);
                    expectMsgClass(Acknowledge.class);
                    // check for number registration of registered resources
                    resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), fakeJobManager);
                    TestingResourceManager.GetRegisteredResourcesReply reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
                    assertEquals(1, reply.resources.size());
                    assertTrue(reply.resources.contains(resourceID));
                    // remove resource
                    resourceManager.tell(new RemoveResource(resourceID), fakeJobManager);
                    // check for number registration of registered resources
                    resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), fakeJobManager);
                    reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
                    assertEquals(0, reply.resources.size());
                }
            };
        }
    };
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingResourceManager(org.apache.flink.runtime.testutils.TestingResourceManager) RegisterResourceManagerSuccessful(org.apache.flink.runtime.clusterframework.messages.RegisterResourceManagerSuccessful) RemoveResource(org.apache.flink.runtime.clusterframework.messages.RemoveResource) NotifyResourceStarted(org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted) JavaTestKit(akka.testkit.JavaTestKit) Test(org.junit.Test)

Example 2 with NotifyResourceStarted

use of org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted in project flink by apache.

the class FlinkResourceManager method handleMessage.

/**
	 *
	 * This method receives the actor messages after they have been filtered for
	 * a match with the leader session.
	 *
	 * @param message The incoming actor message.
	 */
@Override
protected void handleMessage(Object message) {
    try {
        if (message instanceof CheckAndAllocateContainers) {
            checkWorkersPool();
        } else if (message instanceof SetWorkerPoolSize) {
            SetWorkerPoolSize msg = (SetWorkerPoolSize) message;
            adjustDesignatedNumberOfWorkers(msg.numberOfWorkers());
        } else if (message instanceof RemoveResource) {
            RemoveResource msg = (RemoveResource) message;
            removeRegisteredResource(msg.resourceId());
        } else if (message instanceof NotifyResourceStarted) {
            NotifyResourceStarted msg = (NotifyResourceStarted) message;
            handleResourceStarted(sender(), msg.getResourceID());
        } else if (message instanceof NewLeaderAvailable) {
            NewLeaderAvailable msg = (NewLeaderAvailable) message;
            newJobManagerLeaderAvailable(msg.leaderAddress(), msg.leaderSessionId());
        } else if (message instanceof TriggerRegistrationAtJobManager) {
            TriggerRegistrationAtJobManager msg = (TriggerRegistrationAtJobManager) message;
            triggerConnectingToJobManager(msg.jobManagerAddress());
        } else if (message instanceof RegisterResourceManagerSuccessful) {
            RegisterResourceManagerSuccessful msg = (RegisterResourceManagerSuccessful) message;
            jobManagerLeaderConnected(msg.jobManager(), msg.currentlyRegisteredTaskManagers());
        } else if (message instanceof StopCluster) {
            StopCluster msg = (StopCluster) message;
            shutdownCluster(msg.finalStatus(), msg.message());
            sender().tell(decorateMessage(StopClusterSuccessful.getInstance()), ActorRef.noSender());
        } else if (message instanceof RegisterInfoMessageListener) {
            if (jobManager != null) {
                infoMessageListeners.add(sender());
                sender().tell(decorateMessage(RegisterInfoMessageListenerSuccessful.get()), // answer as the JobManager
                jobManager);
            }
        } else if (message instanceof UnRegisterInfoMessageListener) {
            infoMessageListeners.remove(sender());
        } else if (message instanceof FatalErrorOccurred) {
            FatalErrorOccurred fatalErrorOccurred = (FatalErrorOccurred) message;
            fatalError(fatalErrorOccurred.message(), fatalErrorOccurred.error());
        } else // --- unknown messages
        {
            LOG.error("Discarding unknown message: {}", message);
        }
    } catch (Throwable t) {
        // fatal error, needs master recovery
        fatalError("Error processing actor message", t);
    }
}
Also used : CheckAndAllocateContainers(org.apache.flink.runtime.clusterframework.messages.CheckAndAllocateContainers) UnRegisterInfoMessageListener(org.apache.flink.runtime.clusterframework.messages.UnRegisterInfoMessageListener) UnRegisterInfoMessageListener(org.apache.flink.runtime.clusterframework.messages.UnRegisterInfoMessageListener) RegisterInfoMessageListener(org.apache.flink.runtime.clusterframework.messages.RegisterInfoMessageListener) TriggerRegistrationAtJobManager(org.apache.flink.runtime.clusterframework.messages.TriggerRegistrationAtJobManager) NewLeaderAvailable(org.apache.flink.runtime.clusterframework.messages.NewLeaderAvailable) FatalErrorOccurred(org.apache.flink.runtime.clusterframework.messages.FatalErrorOccurred) SetWorkerPoolSize(org.apache.flink.runtime.clusterframework.messages.SetWorkerPoolSize) StopCluster(org.apache.flink.runtime.clusterframework.messages.StopCluster) RegisterResourceManagerSuccessful(org.apache.flink.runtime.clusterframework.messages.RegisterResourceManagerSuccessful) RemoveResource(org.apache.flink.runtime.clusterframework.messages.RemoveResource) NotifyResourceStarted(org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted)

Example 3 with NotifyResourceStarted

use of org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted in project flink by apache.

the class ResourceManagerTest method testResourceFailureNotification.

/**
	 * Tests notification of JobManager about a failed resource.
	 */
@Test
public void testResourceFailureNotification() {
    new JavaTestKit(system) {

        {
            new Within(duration("10 seconds")) {

                @Override
                protected void run() {
                    fakeJobManager = TestingUtils.createForwardingActor(system, getTestActor(), Option.<String>empty());
                    resourceManager = TestingUtils.createResourceManager(system, fakeJobManager.actor(), config);
                    // register with JM
                    expectMsgClass(RegisterResourceManager.class);
                    resourceManager.tell(new RegisterResourceManagerSuccessful(fakeJobManager.actor(), Collections.<ResourceID>emptyList()), fakeJobManager);
                    ResourceID resourceID1 = ResourceID.generate();
                    ResourceID resourceID2 = ResourceID.generate();
                    // Send task manager registration
                    resourceManager.tell(new NotifyResourceStarted(resourceID1), fakeJobManager);
                    expectMsgClass(Acknowledge.class);
                    // Send task manager registration
                    resourceManager.tell(new NotifyResourceStarted(resourceID2), fakeJobManager);
                    expectMsgClass(Acknowledge.class);
                    // check for number registration of registered resources
                    resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), fakeJobManager);
                    TestingResourceManager.GetRegisteredResourcesReply reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
                    assertEquals(2, reply.resources.size());
                    assertTrue(reply.resources.contains(resourceID1));
                    assertTrue(reply.resources.contains(resourceID2));
                    // fail resources
                    resourceManager.tell(new TestingResourceManager.FailResource(resourceID1), fakeJobManager);
                    resourceManager.tell(new TestingResourceManager.FailResource(resourceID2), fakeJobManager);
                    ResourceRemoved answer = expectMsgClass(ResourceRemoved.class);
                    ResourceRemoved answer2 = expectMsgClass(ResourceRemoved.class);
                    assertEquals(resourceID1, answer.resourceId());
                    assertEquals(resourceID2, answer2.resourceId());
                }
            };
        }
    };
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingResourceManager(org.apache.flink.runtime.testutils.TestingResourceManager) RegisterResourceManagerSuccessful(org.apache.flink.runtime.clusterframework.messages.RegisterResourceManagerSuccessful) NotifyResourceStarted(org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted) ResourceRemoved(org.apache.flink.runtime.clusterframework.messages.ResourceRemoved) JavaTestKit(akka.testkit.JavaTestKit) Test(org.junit.Test)

Example 4 with NotifyResourceStarted

use of org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted in project flink by apache.

the class ResourceManagerTest method testTaskManagerRegistration.

/**
	 * Tests the registration and accounting of resources at the ResourceManager.
	 */
@Test
public void testTaskManagerRegistration() {
    new JavaTestKit(system) {

        {
            new Within(duration("10 seconds")) {

                @Override
                protected void run() {
                    fakeJobManager = TestingUtils.createForwardingActor(system, getTestActor(), Option.<String>empty());
                    resourceManager = TestingUtils.createResourceManager(system, fakeJobManager.actor(), config);
                    // register with JM
                    expectMsgClass(RegisterResourceManager.class);
                    resourceManager.tell(new RegisterResourceManagerSuccessful(fakeJobManager.actor(), Collections.<ResourceID>emptyList()), fakeJobManager);
                    ResourceID resourceID = ResourceID.generate();
                    // Send task manager registration
                    resourceManager.tell(new NotifyResourceStarted(resourceID), fakeJobManager);
                    expectMsgClass(Acknowledge.class);
                    // check for number registration of registered resources
                    resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), fakeJobManager);
                    TestingResourceManager.GetRegisteredResourcesReply reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
                    assertEquals(1, reply.resources.size());
                    // Send task manager registration again
                    resourceManager.tell(new NotifyResourceStarted(resourceID), fakeJobManager);
                    expectMsgClass(Acknowledge.class);
                    // check for number registration of registered resources
                    resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), fakeJobManager);
                    reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
                    assertEquals(1, reply.resources.size());
                    // Send invalid null resource id to throw an exception during resource registration
                    resourceManager.tell(new NotifyResourceStarted(null), fakeJobManager);
                    expectMsgClass(Acknowledge.class);
                    // check for number registration of registered resources
                    resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), fakeJobManager);
                    reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
                    assertEquals(1, reply.resources.size());
                }
            };
        }
    };
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingResourceManager(org.apache.flink.runtime.testutils.TestingResourceManager) RegisterResourceManagerSuccessful(org.apache.flink.runtime.clusterframework.messages.RegisterResourceManagerSuccessful) NotifyResourceStarted(org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted) JavaTestKit(akka.testkit.JavaTestKit) Test(org.junit.Test)

Example 5 with NotifyResourceStarted

use of org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted in project flink by apache.

the class TestingYarnFlinkResourceManager method handleMessage.

@Override
protected void handleMessage(Object message) {
    if (message instanceof RequestNumberOfRegisteredResources) {
        getSender().tell(getNumberOfStartedTaskManagers(), getSelf());
    } else if (message instanceof NotifyWhenResourcesRegistered) {
        NotifyWhenResourcesRegistered notifyMessage = (NotifyWhenResourcesRegistered) message;
        if (getNumberOfStartedTaskManagers() >= notifyMessage.getNumberResources()) {
            getSender().tell(true, getSelf());
        } else {
            waitingQueue.offer(Tuple2.of(notifyMessage.getNumberResources(), getSender()));
        }
    } else if (message instanceof NotifyResourceStarted) {
        super.handleMessage(message);
        while (!waitingQueue.isEmpty() && waitingQueue.peek().f0 <= getNumberOfStartedTaskManagers()) {
            ActorRef receiver = waitingQueue.poll().f1;
            receiver.tell(true, getSelf());
        }
    } else {
        super.handleMessage(message);
    }
}
Also used : RequestNumberOfRegisteredResources(org.apache.flink.yarn.messages.RequestNumberOfRegisteredResources) ActorRef(akka.actor.ActorRef) NotifyResourceStarted(org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted) NotifyWhenResourcesRegistered(org.apache.flink.yarn.messages.NotifyWhenResourcesRegistered)

Aggregations

NotifyResourceStarted (org.apache.flink.runtime.clusterframework.messages.NotifyResourceStarted)6 RegisterResourceManagerSuccessful (org.apache.flink.runtime.clusterframework.messages.RegisterResourceManagerSuccessful)5 JavaTestKit (akka.testkit.JavaTestKit)4 Test (org.junit.Test)4 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)3 TestingResourceManager (org.apache.flink.runtime.testutils.TestingResourceManager)3 ActorRef (akka.actor.ActorRef)2 RemoveResource (org.apache.flink.runtime.clusterframework.messages.RemoveResource)2 NotifyWhenResourcesRegistered (org.apache.flink.yarn.messages.NotifyWhenResourcesRegistered)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Configuration (org.apache.flink.configuration.Configuration)1 ContaineredTaskManagerParameters (org.apache.flink.runtime.clusterframework.ContaineredTaskManagerParameters)1 CheckAndAllocateContainers (org.apache.flink.runtime.clusterframework.messages.CheckAndAllocateContainers)1 FatalErrorOccurred (org.apache.flink.runtime.clusterframework.messages.FatalErrorOccurred)1 NewLeaderAvailable (org.apache.flink.runtime.clusterframework.messages.NewLeaderAvailable)1 RegisterInfoMessageListener (org.apache.flink.runtime.clusterframework.messages.RegisterInfoMessageListener)1 ResourceRemoved (org.apache.flink.runtime.clusterframework.messages.ResourceRemoved)1 SetWorkerPoolSize (org.apache.flink.runtime.clusterframework.messages.SetWorkerPoolSize)1 StopCluster (org.apache.flink.runtime.clusterframework.messages.StopCluster)1