Search in sources :

Example 11 with AllocatedSlot

use of org.apache.flink.runtime.jobmanager.slots.AllocatedSlot 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 12 with AllocatedSlot

use of org.apache.flink.runtime.jobmanager.slots.AllocatedSlot in project flink by apache.

the class SlotPool method internalReturnAllocatedSlot.

// ------------------------------------------------------------------------
//  Slot releasing & offering
// ------------------------------------------------------------------------
/**
	 * Return the slot back to this pool without releasing it. It's mainly called by failed / cancelled tasks, and the
	 * slot can be reused by other pending requests if the resource profile matches.n
	 *
	 * @param slot The slot needs to be returned
	 */
private void internalReturnAllocatedSlot(Slot slot) {
    checkNotNull(slot);
    checkArgument(!slot.isAlive(), "slot is still alive");
    checkArgument(slot.getOwner() == providerAndOwner, "slot belongs to the wrong pool.");
    // to be returned only once
    if (slot.markReleased()) {
        if (allocatedSlots.remove(slot)) {
            // this slot allocation is still valid, use the slot to fulfill another request
            // or make it available again
            final AllocatedSlot taskManagerSlot = slot.getAllocatedSlot();
            final PendingRequest pendingRequest = pollMatchingPendingRequest(taskManagerSlot);
            if (pendingRequest != null) {
                LOG.debug("Fulfilling pending request [{}] early with returned slot [{}]", pendingRequest.allocationID(), taskManagerSlot.getSlotAllocationId());
                SimpleSlot newSlot = createSimpleSlot(taskManagerSlot, Locality.UNKNOWN);
                allocatedSlots.add(newSlot);
                pendingRequest.future().complete(newSlot);
            } else {
                LOG.debug("Adding returned slot [{}] to available slots", taskManagerSlot.getSlotAllocationId());
                availableSlots.add(taskManagerSlot, clock.relativeTimeMillis());
            }
        } else {
            LOG.debug("Returned slot's allocation has been failed. Dropping slot.");
        }
    }
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot)

Example 13 with AllocatedSlot

use of org.apache.flink.runtime.jobmanager.slots.AllocatedSlot 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)

Example 14 with AllocatedSlot

use of org.apache.flink.runtime.jobmanager.slots.AllocatedSlot in project flink by apache.

the class SlotPoolTest method createAllocatedSlot.

static AllocatedSlot createAllocatedSlot(final ResourceID resourceId, final AllocationID allocationId, final JobID jobId, final ResourceProfile resourceProfile) {
    TaskManagerLocation mockTaskManagerLocation = mock(TaskManagerLocation.class);
    when(mockTaskManagerLocation.getResourceID()).thenReturn(resourceId);
    TaskManagerGateway mockTaskManagerGateway = mock(TaskManagerGateway.class);
    return new AllocatedSlot(allocationId, jobId, mockTaskManagerLocation, 0, resourceProfile, mockTaskManagerGateway);
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) TaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway)

Example 15 with AllocatedSlot

use of org.apache.flink.runtime.jobmanager.slots.AllocatedSlot in project flink by apache.

the class ExecutionGraphSchedulingTest method createSlot.

private SimpleSlot createSlot(TaskManagerGateway taskManager, JobID jobId, SlotOwner slotOwner) {
    TaskManagerLocation location = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 12345);
    AllocatedSlot slot = new AllocatedSlot(new AllocationID(), jobId, location, 0, ResourceProfile.UNKNOWN, taskManager);
    return new SimpleSlot(slot, slotOwner, 0);
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot)

Aggregations

AllocatedSlot (org.apache.flink.runtime.jobmanager.slots.AllocatedSlot)16 Test (org.junit.Test)9 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)8 Time (org.apache.flink.api.common.time.Time)6 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)6 ScheduledUnit (org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit)6 UUID (java.util.UUID)5 SlotRequest (org.apache.flink.runtime.resourcemanager.SlotRequest)5 TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)5 SimpleSlot (org.apache.flink.runtime.instance.SimpleSlot)4 TaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JobID (org.apache.flink.api.common.JobID)2 TaskDeploymentDescriptor (org.apache.flink.runtime.deployment.TaskDeploymentDescriptor)2 Slot (org.apache.flink.runtime.instance.Slot)2 Field (java.lang.reflect.Field)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1