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));
}
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;
}
Aggregations