Search in sources :

Example 1 with ScheduledUnit

use of org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit in project flink by apache.

the class Execution method allocateSlotForExecution.

public Future<SimpleSlot> allocateSlotForExecution(SlotProvider slotProvider, boolean queued) throws IllegalExecutionStateException {
    checkNotNull(slotProvider);
    final SlotSharingGroup sharingGroup = vertex.getJobVertex().getSlotSharingGroup();
    final CoLocationConstraint locationConstraint = vertex.getLocationConstraint();
    // sanity check
    if (locationConstraint != null && sharingGroup == null) {
        throw new IllegalStateException("Trying to schedule with co-location constraint but without slot sharing allowed.");
    }
    // this method only works if the execution is in the state 'CREATED'
    if (transitionState(CREATED, SCHEDULED)) {
        ScheduledUnit toSchedule = locationConstraint == null ? new ScheduledUnit(this, sharingGroup) : new ScheduledUnit(this, sharingGroup, locationConstraint);
        return slotProvider.allocateSlot(toSchedule, queued);
    } else {
        // call race, already deployed, or already done
        throw new IllegalExecutionStateException(this, CREATED, state);
    }
}
Also used : CoLocationConstraint(org.apache.flink.runtime.jobmanager.scheduler.CoLocationConstraint) ScheduledUnit(org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup)

Example 2 with ScheduledUnit

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

Aggregations

ScheduledUnit (org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit)2 UUID (java.util.UUID)1 Time (org.apache.flink.api.common.time.Time)1 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)1 CoLocationConstraint (org.apache.flink.runtime.jobmanager.scheduler.CoLocationConstraint)1 SlotSharingGroup (org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup)1 AllocatedSlot (org.apache.flink.runtime.jobmanager.slots.AllocatedSlot)1 SlotRequest (org.apache.flink.runtime.resourcemanager.SlotRequest)1 Test (org.junit.Test)1