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