Search in sources :

Example 1 with SlotAndLocality

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

the class AvailableSlotsTest method testPollFreeSlot.

@Test
public void testPollFreeSlot() {
    SlotPool.AvailableSlots availableSlots = new SlotPool.AvailableSlots();
    final ResourceID resource1 = new ResourceID("resource1");
    final AllocatedSlot slot1 = createAllocatedSlot(resource1);
    availableSlots.add(slot1, 1L);
    assertEquals(1, availableSlots.size());
    assertTrue(availableSlots.contains(slot1.getSlotAllocationId()));
    assertTrue(availableSlots.containsTaskManager(resource1));
    assertNull(availableSlots.poll(DEFAULT_TESTING_BIG_PROFILE, null));
    SlotAndLocality slotAndLocality = availableSlots.poll(DEFAULT_TESTING_PROFILE, null);
    assertEquals(slot1, slotAndLocality.slot());
    assertEquals(0, availableSlots.size());
    assertFalse(availableSlots.contains(slot1.getSlotAllocationId()));
    assertFalse(availableSlots.containsTaskManager(resource1));
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) SlotAndLocality(org.apache.flink.runtime.jobmanager.slots.SlotAndLocality) Test(org.junit.Test)

Example 2 with SlotAndLocality

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

the class SlotPool method internalAllocateSlot.

Future<SimpleSlot> internalAllocateSlot(ScheduledUnit task, ResourceProfile resources, Iterable<TaskManagerLocation> locationPreferences) {
    // (1) do we have a slot available already?
    SlotAndLocality slotFromPool = availableSlots.poll(resources, locationPreferences);
    if (slotFromPool != null) {
        SimpleSlot slot = createSimpleSlot(slotFromPool.slot(), slotFromPool.locality());
        allocatedSlots.add(slot);
        return FlinkCompletableFuture.completed(slot);
    }
    // the request will be completed by a future
    final AllocationID allocationID = new AllocationID();
    final FlinkCompletableFuture<SimpleSlot> future = new FlinkCompletableFuture<>();
    if (resourceManagerGateway == null) {
        // no slot available, and no resource manager connection
        stashRequestWaitingForResourceManager(allocationID, resources, future);
    } else {
        // we have a resource manager connection, so let's ask it for more resources
        requestSlotFromResourceManager(allocationID, future, resources);
    }
    return future;
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotAndLocality(org.apache.flink.runtime.jobmanager.slots.SlotAndLocality) FlinkCompletableFuture(org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture)

Aggregations

SlotAndLocality (org.apache.flink.runtime.jobmanager.slots.SlotAndLocality)2 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)1 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)1 FlinkCompletableFuture (org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture)1 AllocatedSlot (org.apache.flink.runtime.jobmanager.slots.AllocatedSlot)1 Test (org.junit.Test)1