Search in sources :

Example 1 with SlotRequest

use of org.apache.flink.runtime.resourcemanager.SlotRequest in project flink by apache.

the class SlotPoolTest method testAllocationFulfilledByReturnedSlot.

@Test
public void testAllocationFulfilledByReturnedSlot() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    Future<SimpleSlot> future1 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    Future<SimpleSlot> future2 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    assertFalse(future1.isDone());
    assertFalse(future2.isDone());
    ArgumentCaptor<SlotRequest> slotRequestArgumentCaptor = ArgumentCaptor.forClass(SlotRequest.class);
    verify(resourceManagerGateway, times(2)).requestSlot(any(UUID.class), any(UUID.class), slotRequestArgumentCaptor.capture(), any(Time.class));
    final List<SlotRequest> slotRequests = slotRequestArgumentCaptor.getAllValues();
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequests.get(0).getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot1 = future1.get(1, TimeUnit.SECONDS);
    assertTrue(future1.isDone());
    assertFalse(future2.isDone());
    // return this slot to pool
    slot1.releaseSlot();
    // second allocation fulfilled by previous slot returning
    SimpleSlot slot2 = future2.get(1, TimeUnit.SECONDS);
    assertTrue(future2.isDone());
    assertNotEquals(slot1, slot2);
    assertTrue(slot1.isReleased());
    assertTrue(slot2.isAlive());
    assertEquals(slot1.getTaskManagerID(), slot2.getTaskManagerID());
    assertEquals(slot1.getSlotNumber(), slot2.getSlotNumber());
    assertEquals(slotPool.getAllocatedSlots().get(slot1.getAllocatedSlot().getSlotAllocationId()), slot2);
}
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)

Example 2 with SlotRequest

use of org.apache.flink.runtime.resourcemanager.SlotRequest in project flink by apache.

the class SlotPoolTest method testOfferSlot.

@Test
public void testOfferSlot() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    Future<SimpleSlot> future = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    assertFalse(future.isDone());
    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();
    // slot from unregistered resource
    AllocatedSlot invalid = createAllocatedSlot(new ResourceID("unregistered"), slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertFalse(slotPool.offerSlot(invalid));
    AllocatedSlot notRequested = createAllocatedSlot(resourceID, new AllocationID(), jobId, DEFAULT_TESTING_PROFILE);
    // we'll also accept non requested slots
    assertTrue(slotPool.offerSlot(notRequested));
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    // accepted slot
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot = future.get(1, TimeUnit.SECONDS);
    assertTrue(future.isDone());
    assertTrue(slot.isAlive());
    // duplicated offer with using slot
    assertTrue(slotPool.offerSlot(allocatedSlot));
    assertTrue(future.isDone());
    assertTrue(slot.isAlive());
    // duplicated offer with free slot
    slot.releaseSlot();
    assertTrue(slot.isReleased());
    assertTrue(slotPool.offerSlot(allocatedSlot));
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) 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)

Example 3 with SlotRequest

use of org.apache.flink.runtime.resourcemanager.SlotRequest in project flink by apache.

the class SlotPoolTest method testAllocateWithFreeSlot.

@Test
public void testAllocateWithFreeSlot() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    Future<SimpleSlot> future1 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    assertFalse(future1.isDone());
    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();
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot1 = future1.get(1, TimeUnit.SECONDS);
    assertTrue(future1.isDone());
    // return this slot to pool
    slot1.releaseSlot();
    Future<SimpleSlot> future2 = slotPool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
    // second allocation fulfilled by previous slot returning
    SimpleSlot slot2 = future2.get(1, TimeUnit.SECONDS);
    assertTrue(future2.isDone());
    assertNotEquals(slot1, slot2);
    assertTrue(slot1.isReleased());
    assertTrue(slot2.isAlive());
    assertEquals(slot1.getTaskManagerID(), slot2.getTaskManagerID());
    assertEquals(slot1.getSlotNumber(), slot2.getSlotNumber());
}
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)

Example 4 with SlotRequest

use of org.apache.flink.runtime.resourcemanager.SlotRequest in project flink by apache.

the class SlotPoolTest method testAllocateSimpleSlot.

@Test
public void testAllocateSimpleSlot() throws Exception {
    ResourceID resourceID = new ResourceID("resource");
    slotPool.registerTaskManager(resourceID);
    ScheduledUnit task = mock(ScheduledUnit.class);
    Future<SimpleSlot> future = slotPool.allocateSlot(task, DEFAULT_TESTING_PROFILE, null);
    assertFalse(future.isDone());
    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();
    AllocatedSlot allocatedSlot = createAllocatedSlot(resourceID, slotRequest.getAllocationId(), jobId, DEFAULT_TESTING_PROFILE);
    assertTrue(slotPool.offerSlot(allocatedSlot));
    SimpleSlot slot = future.get(1, TimeUnit.SECONDS);
    assertTrue(future.isDone());
    assertTrue(slot.isAlive());
    assertEquals(resourceID, slot.getTaskManagerID());
    assertEquals(jobId, slot.getJobID());
    assertEquals(slotPool.getSlotOwner(), slot.getOwner());
    assertEquals(slotPool.getAllocatedSlots().get(slot.getAllocatedSlot().getSlotAllocationId()), slot);
}
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)

Example 5 with SlotRequest

use of org.apache.flink.runtime.resourcemanager.SlotRequest in project flink by apache.

the class SlotPool method requestSlotFromResourceManager.

private void requestSlotFromResourceManager(final AllocationID allocationID, final FlinkCompletableFuture<SimpleSlot> future, final ResourceProfile resources) {
    LOG.info("Requesting slot with profile {} from resource manager (request = {}).", resources, allocationID);
    pendingRequests.put(allocationID, new PendingRequest(allocationID, future, resources));
    Future<RMSlotRequestReply> rmResponse = resourceManagerGateway.requestSlot(jobManagerLeaderId, resourceManagerLeaderId, new SlotRequest(jobId, allocationID, resources), resourceManagerRequestsTimeout);
    // on success, trigger let the slot pool know
    rmResponse.thenAcceptAsync(new AcceptFunction<RMSlotRequestReply>() {

        @Override
        public void accept(RMSlotRequestReply reply) {
            if (reply.getAllocationID() != null && reply.getAllocationID().equals(allocationID)) {
                if (reply instanceof RMSlotRequestRegistered) {
                    slotRequestToResourceManagerSuccess(allocationID);
                } else if (reply instanceof RMSlotRequestRejected) {
                    slotRequestToResourceManagerFailed(allocationID, new Exception("ResourceManager rejected slot request"));
                } else {
                    slotRequestToResourceManagerFailed(allocationID, new Exception("Unknown ResourceManager response: " + reply));
                }
            } else {
                future.completeExceptionally(new Exception(String.format("Bug: ResourceManager response had wrong AllocationID. Request: %s , Response: %s", allocationID, reply.getAllocationID())));
            }
        }
    }, getMainThreadExecutor());
    // on failure, fail the request future
    rmResponse.exceptionallyAsync(new ApplyFunction<Throwable, Void>() {

        @Override
        public Void apply(Throwable failure) {
            slotRequestToResourceManagerFailed(allocationID, failure);
            return null;
        }
    }, getMainThreadExecutor());
}
Also used : RMSlotRequestRejected(org.apache.flink.runtime.resourcemanager.messages.jobmanager.RMSlotRequestRejected) RMSlotRequestRegistered(org.apache.flink.runtime.resourcemanager.messages.jobmanager.RMSlotRequestRegistered) RMSlotRequestReply(org.apache.flink.runtime.resourcemanager.messages.jobmanager.RMSlotRequestReply) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) NoResourceAvailableException(org.apache.flink.runtime.jobmanager.scheduler.NoResourceAvailableException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

SlotRequest (org.apache.flink.runtime.resourcemanager.SlotRequest)21 Test (org.junit.Test)19 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)16 JobID (org.apache.flink.api.common.JobID)14 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)10 UUID (java.util.UUID)8 Time (org.apache.flink.api.common.time.Time)8 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)7 SlotReport (org.apache.flink.runtime.taskexecutor.SlotReport)6 SlotStatus (org.apache.flink.runtime.taskexecutor.SlotStatus)6 ScheduledUnit (org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit)5 AllocatedSlot (org.apache.flink.runtime.jobmanager.slots.AllocatedSlot)5 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)3 TestingHighAvailabilityServices (org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices)3 JobMasterGateway (org.apache.flink.runtime.jobmaster.JobMasterGateway)3 TestingLeaderElectionService (org.apache.flink.runtime.leaderelection.TestingLeaderElectionService)3 RegistrationResponse (org.apache.flink.runtime.registration.RegistrationResponse)3 JobLeaderIdService (org.apache.flink.runtime.resourcemanager.JobLeaderIdService)3 ResourceManagerConfiguration (org.apache.flink.runtime.resourcemanager.ResourceManagerConfiguration)3 RMSlotRequestReply (org.apache.flink.runtime.resourcemanager.messages.jobmanager.RMSlotRequestReply)3