Search in sources :

Example 11 with SlotRequest

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

the class SlotManagerTest method testSlotAllocationFailedAtTaskManager.

/**
	 * Tests that we did some allocation but failed / rejected by TaskManager, request will retry
	 */
@Test
public void testSlotAllocationFailedAtTaskManager() {
    TestingSlotManager slotManager = new TestingSlotManager();
    ResourceSlot slot = new ResourceSlot(SlotID.generate(), DEFAULT_TESTING_PROFILE, taskExecutorRegistration);
    slotManager.addFreeSlot(slot);
    SlotRequest request = new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_PROFILE);
    slotManager.requestSlot(request);
    assertEquals(1, slotManager.getAllocatedSlotCount());
    assertEquals(0, slotManager.getFreeSlotCount());
    assertEquals(0, slotManager.getPendingRequestCount());
    assertTrue(slotManager.isAllocated(slot.getSlotId()));
    slotManager.handleSlotRequestFailedAtTaskManager(request, slot.getSlotId());
    assertEquals(1, slotManager.getAllocatedSlotCount());
    assertEquals(0, slotManager.getFreeSlotCount());
    assertEquals(0, slotManager.getPendingRequestCount());
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) ResourceSlot(org.apache.flink.runtime.clusterframework.types.ResourceSlot) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 12 with SlotRequest

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

the class SlotManagerTest method testMultipleSlotRequestsWithOneSlot.

/**
	 * Tests multiple slot requests with one slots.
	 */
@Test
public void testMultipleSlotRequestsWithOneSlot() {
    TestingSlotManager slotManager = new TestingSlotManager();
    final AllocationID allocationID = new AllocationID();
    SlotRequest request1 = new SlotRequest(new JobID(), allocationID, DEFAULT_TESTING_PROFILE);
    slotManager.requestSlot(request1);
    final ResourceID resourceID = ResourceID.generate();
    final SlotStatus slotStatus = new SlotStatus(new SlotID(resourceID, 0), DEFAULT_TESTING_PROFILE);
    final SlotReport slotReport = new SlotReport(slotStatus);
    slotManager.registerTaskExecutor(resourceID, taskExecutorRegistration, slotReport);
    // another request pending
    SlotRequest request2 = new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_PROFILE);
    slotManager.requestSlot(request2);
    assertEquals(1, slotManager.getAllocatedSlotCount());
    assertEquals(0, slotManager.getFreeSlotCount());
    assertEquals(1, slotManager.getPendingRequestCount());
    assertTrue(slotManager.isAllocated(allocationID));
    assertTrue(slotManager.isAllocated(request1.getAllocationId()));
    // but slot is reported empty in a report in the meantime which shouldn't affect the state
    slotManager.notifySlotAvailable(resourceID, slotStatus.getSlotID());
    assertEquals(1, slotManager.getAllocatedSlotCount());
    assertEquals(0, slotManager.getFreeSlotCount());
    assertEquals(0, slotManager.getPendingRequestCount());
    assertTrue(slotManager.isAllocated(slotStatus.getSlotID()));
    assertTrue(slotManager.isAllocated(request2.getAllocationId()));
    // but slot is reported empty in a report in the meantime which shouldn't affect the state
    slotManager.notifySlotAvailable(resourceID, slotStatus.getSlotID());
    assertEquals(0, slotManager.getAllocatedSlotCount());
    assertEquals(1, slotManager.getFreeSlotCount());
    assertEquals(0, slotManager.getPendingRequestCount());
}
Also used : SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) SlotStatus(org.apache.flink.runtime.taskexecutor.SlotStatus) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 13 with SlotRequest

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

the class SlotManagerTest method testRequestSlotWithFreeSlot.

/**
	 * Tests that there are some free slots when we request, and the request is fulfilled immediately
	 */
@Test
public void testRequestSlotWithFreeSlot() {
    TestingSlotManager slotManager = new TestingSlotManager();
    directlyProvideFreeSlots(slotManager, DEFAULT_TESTING_PROFILE, 1);
    assertEquals(1, slotManager.getFreeSlotCount());
    slotManager.requestSlot(new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_PROFILE));
    assertEquals(1, slotManager.getAllocatedSlotCount());
    assertEquals(0, slotManager.getFreeSlotCount());
    assertEquals(0, slotManager.getPendingRequestCount());
    assertEquals(0, slotManager.getAllocatedContainers().size());
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 14 with SlotRequest

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

the class SlotManagerTest method testNewlyAppearedFreeSlotNotMatchPendingRequests.

/**
	 * Tests that a new slot appeared in SlotReport, but it't not suitable for all the pending requests
	 */
@Test
public void testNewlyAppearedFreeSlotNotMatchPendingRequests() {
    TestingSlotManager slotManager = new TestingSlotManager();
    slotManager.requestSlot(new SlotRequest(new JobID(), new AllocationID(), DEFAULT_TESTING_BIG_PROFILE));
    assertEquals(1, slotManager.getPendingRequestCount());
    SlotID slotId = SlotID.generate();
    SlotStatus slotStatus = new SlotStatus(slotId, DEFAULT_TESTING_PROFILE);
    SlotReport slotReport = new SlotReport(Collections.singletonList(slotStatus));
    slotManager.registerTaskExecutor(slotId.getResourceID(), taskExecutorRegistration, slotReport);
    assertEquals(0, slotManager.getAllocatedSlotCount());
    assertEquals(1, slotManager.getFreeSlotCount());
    assertEquals(1, slotManager.getPendingRequestCount());
    assertFalse(slotManager.isAllocated(slotId));
}
Also used : SlotID(org.apache.flink.runtime.clusterframework.types.SlotID) SlotStatus(org.apache.flink.runtime.taskexecutor.SlotStatus) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotReport(org.apache.flink.runtime.taskexecutor.SlotReport) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 15 with SlotRequest

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

the class SlotManager method handleFreeSlot.

// ------------------------------------------------------------------------
//  internal behaviors
// ------------------------------------------------------------------------
/**
	 * When we have a free slot, try to fulfill the pending request first. If any request can be fulfilled,
	 * record this allocation in bookkeeping and send slot request to TaskManager, else we just add this slot
	 * to the free pool.
	 *
	 * @param freeSlot The free slot
	 */
private void handleFreeSlot(final ResourceSlot freeSlot) {
    SlotRequest chosenRequest = chooseRequestToFulfill(freeSlot, pendingSlotRequests);
    if (chosenRequest != null) {
        final AllocationID allocationId = chosenRequest.getAllocationId();
        final SlotRequest slotRequest = pendingSlotRequests.remove(allocationId);
        LOG.info("Assigning SlotID({}) to AllocationID({}), JobID:{}", freeSlot.getSlotId(), allocationId, chosenRequest.getJobId());
        allocationMap.addAllocation(freeSlot.getSlotId(), allocationId);
        sendSlotRequest(freeSlot, slotRequest);
    } else {
        freeSlots.put(freeSlot.getSlotId(), freeSlot);
    }
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotRequest(org.apache.flink.runtime.resourcemanager.SlotRequest)

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