Search in sources :

Example 46 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID in project flink by apache.

the class SlotSharingGroupAssignment method removeSlotFromAllEntries.

private static void removeSlotFromAllEntries(Map<AbstractID, Map<ResourceID, List<SharedSlot>>> availableSlots, SharedSlot slot) {
    final ResourceID taskManagerId = slot.getTaskManagerID();
    for (Map.Entry<AbstractID, Map<ResourceID, List<SharedSlot>>> entry : availableSlots.entrySet()) {
        Map<ResourceID, List<SharedSlot>> map = entry.getValue();
        List<SharedSlot> list = map.get(taskManagerId);
        if (list != null) {
            list.remove(slot);
            if (list.isEmpty()) {
                map.remove(taskManagerId);
            }
        }
    }
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AbstractID(org.apache.flink.util.AbstractID)

Example 47 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID in project flink by apache.

the class ResourceManagerITCase method testResourceManagerReconciliation.

/**
	 * Tests whether the resource manager connects and reconciles existing task managers.
	 */
@Test
public void testResourceManagerReconciliation() {
    new JavaTestKit(system) {

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

                @Override
                protected void run() {
                    ActorGateway jobManager = TestingUtils.createJobManager(system, TestingUtils.defaultExecutor(), TestingUtils.defaultExecutor(), config, "ReconciliationTest");
                    ActorGateway me = TestingUtils.createForwardingActor(system, getTestActor(), Option.<String>empty());
                    // !! no resource manager started !!
                    ResourceID resourceID = ResourceID.generate();
                    TaskManagerLocation location = mock(TaskManagerLocation.class);
                    when(location.getResourceID()).thenReturn(resourceID);
                    HardwareDescription resourceProfile = HardwareDescription.extractFromSystem(1_000_000);
                    jobManager.tell(new RegistrationMessages.RegisterTaskManager(resourceID, location, resourceProfile, 1), me);
                    expectMsgClass(RegistrationMessages.AcknowledgeRegistration.class);
                    // now start the resource manager
                    ActorGateway resourceManager = TestingUtils.createResourceManager(system, jobManager.actor(), config);
                    // register at testing job manager to receive a message once a resource manager registers
                    resourceManager.tell(new TestingResourceManager.NotifyWhenResourceManagerConnected(), me);
                    // Wait for resource manager
                    expectMsgEquals(Acknowledge.get());
                    // check if we registered the task manager resource
                    resourceManager.tell(new TestingResourceManager.GetRegisteredResources(), me);
                    TestingResourceManager.GetRegisteredResourcesReply reply = expectMsgClass(TestingResourceManager.GetRegisteredResourcesReply.class);
                    assertEquals(1, reply.resources.size());
                    assertTrue(reply.resources.contains(resourceID));
                }
            };
        }
    };
}
Also used : RegistrationMessages(org.apache.flink.runtime.messages.RegistrationMessages) HardwareDescription(org.apache.flink.runtime.instance.HardwareDescription) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) TestingResourceManager(org.apache.flink.runtime.testutils.TestingResourceManager) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) JavaTestKit(akka.testkit.JavaTestKit) Test(org.junit.Test)

Example 48 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID 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 49 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID 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 50 with ResourceID

use of org.apache.flink.runtime.clusterframework.types.ResourceID in project flink by apache.

the class SlotPoolTest method testReleaseResource.

@Test
public void testReleaseResource() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    Future<SimpleSlot> future1 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    ArgumentCaptor<SlotRequest> slotRequestArgumentCaptor = ArgumentCaptor.forClass(SlotRequest.class);
    verify(resourceManagerGateway).requestSlot(any(UUID.class), any(UUID.class), slotRequestArgumentCaptor.capture(), any(Time.class));
    final SlotRequest slotRequest = slotRequestArgumentCaptor.getValue();
    Future<SimpleSlot> future2 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot1 = future1.get(1, TimeUnit.SECONDS);
    assertTrue(future1.isDone());
    assertFalse(future2.isDone());
    slotPool.releaseTaskManager(resourceID);
    assertTrue(slot1.isReleased());
    // slot released and not usable, second allocation still not fulfilled
    Thread.sleep(10);
    assertFalse(future2.isDone());
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ScheduledUnit(org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit) Time(org.apache.flink.api.common.time.Time) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)74 Test (org.junit.Test)48 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)25 Time (org.apache.flink.api.common.time.Time)18 UUID (java.util.UUID)16 JobID (org.apache.flink.api.common.JobID)16 Configuration (org.apache.flink.configuration.Configuration)14 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)13 JavaTestKit (akka.testkit.JavaTestKit)12 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)12 InetAddress (java.net.InetAddress)11 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)10 HeartbeatServices (org.apache.flink.runtime.heartbeat.HeartbeatServices)10 TestingHighAvailabilityServices (org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices)10 SlotRequest (org.apache.flink.runtime.resourcemanager.SlotRequest)10 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)9 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)9 ActorTaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway)9 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)9 TestingSerialRpcService (org.apache.flink.runtime.rpc.TestingSerialRpcService)9