Search in sources :

Example 6 with AllocatedSlot

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

the class AvailableSlotsTest method createAllocatedSlot.

static AllocatedSlot createAllocatedSlot(final ResourceID resourceId) {
    TaskManagerLocation mockTaskManagerLocation = mock(TaskManagerLocation.class);
    when(mockTaskManagerLocation.getResourceID()).thenReturn(resourceId);
    TaskManagerGateway mockTaskManagerGateway = mock(TaskManagerGateway.class);
    return new AllocatedSlot(new AllocationID(), new JobID(), mockTaskManagerLocation, 0, DEFAULT_TESTING_PROFILE, mockTaskManagerGateway);
}
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) TaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway) JobID(org.apache.flink.api.common.JobID)

Example 7 with AllocatedSlot

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

the class ExecutionVertexDeploymentTest method testTddProducedPartitionsLazyScheduling.

/**
	 * Tests that the lazy scheduling flag is correctly forwarded to the produced partition descriptors.
	 */
@Test
public void testTddProducedPartitionsLazyScheduling() throws Exception {
    TestingUtils.QueuedActionExecutionContext context = TestingUtils.queuedActionExecutionContext();
    ExecutionJobVertex jobVertex = getExecutionVertex(new JobVertexID(), context);
    IntermediateResult result = new IntermediateResult(new IntermediateDataSetID(), jobVertex, 1, ResultPartitionType.PIPELINED);
    ExecutionVertex vertex = new ExecutionVertex(jobVertex, 0, new IntermediateResult[] { result }, Time.minutes(1));
    ExecutionEdge mockEdge = createMockExecutionEdge(1);
    result.getPartitions()[0].addConsumerGroup();
    result.getPartitions()[0].addConsumer(mockEdge, 0);
    AllocatedSlot allocatedSlot = mock(AllocatedSlot.class);
    when(allocatedSlot.getSlotAllocationId()).thenReturn(new AllocationID());
    Slot root = mock(Slot.class);
    when(root.getSlotNumber()).thenReturn(1);
    SimpleSlot slot = mock(SimpleSlot.class);
    when(slot.getRoot()).thenReturn(root);
    when(slot.getAllocatedSlot()).thenReturn(allocatedSlot);
    when(root.getAllocatedSlot()).thenReturn(allocatedSlot);
    for (ScheduleMode mode : ScheduleMode.values()) {
        vertex.getExecutionGraph().setScheduleMode(mode);
        TaskDeploymentDescriptor tdd = vertex.createDeploymentDescriptor(new ExecutionAttemptID(), slot, null, 1);
        Collection<ResultPartitionDeploymentDescriptor> producedPartitions = tdd.getProducedPartitions();
        assertEquals(1, producedPartitions.size());
        ResultPartitionDeploymentDescriptor desc = producedPartitions.iterator().next();
        assertEquals(mode.allowLazyDeployment(), desc.sendScheduleOrUpdateConsumersMessage());
    }
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) ExecutionGraphTestUtils.getExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex) TestingUtils(org.apache.flink.runtime.testingUtils.TestingUtils) ScheduleMode(org.apache.flink.runtime.jobgraph.ScheduleMode) Slot(org.apache.flink.runtime.instance.Slot) SimpleSlot(org.apache.flink.runtime.instance.SimpleSlot) AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) IntermediateDataSetID(org.apache.flink.runtime.jobgraph.IntermediateDataSetID) TaskDeploymentDescriptor(org.apache.flink.runtime.deployment.TaskDeploymentDescriptor) Test(org.junit.Test)

Example 8 with AllocatedSlot

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

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

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

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