use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest in project flink by apache.
the class SlotSharingExecutionSlotAllocator method getOrAllocateSharedSlot.
private SharedSlot getOrAllocateSharedSlot(ExecutionSlotSharingGroup executionSlotSharingGroup, SharedSlotProfileRetriever sharedSlotProfileRetriever) {
return sharedSlots.computeIfAbsent(executionSlotSharingGroup, group -> {
SlotRequestId physicalSlotRequestId = new SlotRequestId();
ResourceProfile physicalSlotResourceProfile = getPhysicalSlotResourceProfile(group);
SlotProfile slotProfile = sharedSlotProfileRetriever.getSlotProfile(group, physicalSlotResourceProfile);
PhysicalSlotRequest physicalSlotRequest = new PhysicalSlotRequest(physicalSlotRequestId, slotProfile, slotWillBeOccupiedIndefinitely);
CompletableFuture<PhysicalSlot> physicalSlotFuture = slotProvider.allocatePhysicalSlot(physicalSlotRequest).thenApply(PhysicalSlotRequest.Result::getPhysicalSlot);
return new SharedSlot(physicalSlotRequestId, physicalSlotResourceProfile, group, physicalSlotFuture, slotWillBeOccupiedIndefinitely, this::releaseSharedSlot);
});
}
use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest in project flink by apache.
the class SlotSharingExecutionSlotAllocatorTest method testSlotWillBeOccupiedIndefinitely.
private static void testSlotWillBeOccupiedIndefinitely(boolean slotWillBeOccupiedIndefinitely) throws ExecutionException, InterruptedException {
AllocationContext context = AllocationContext.newBuilder().addGroup(EV1).setSlotWillBeOccupiedIndefinitely(slotWillBeOccupiedIndefinitely).build();
context.allocateSlotsFor(EV1);
PhysicalSlotRequest slotRequest = context.getSlotProvider().getFirstRequestOrFail();
assertThat(slotRequest.willSlotBeOccupiedIndefinitely(), is(slotWillBeOccupiedIndefinitely));
TestingPhysicalSlot physicalSlot = context.getSlotProvider().getResponses().get(slotRequest.getSlotRequestId()).get();
assertThat(physicalSlot.getPayload(), notNullValue());
assertThat(physicalSlot.getPayload().willOccupySlotIndefinitely(), is(slotWillBeOccupiedIndefinitely));
}
use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest in project flink by apache.
the class SlotSharingExecutionSlotAllocatorTest method fulfilOneOfTwoSlotRequestsAndGetPendingProfile.
private static ResourceProfile fulfilOneOfTwoSlotRequestsAndGetPendingProfile(AllocationContext context, AllocationID allocationId) {
Map<SlotRequestId, PhysicalSlotRequest> requests = context.getSlotProvider().getRequests();
List<SlotRequestId> slotRequestIds = new ArrayList<>(requests.keySet());
assertThat(slotRequestIds, hasSize(2));
SlotRequestId slotRequestId1 = slotRequestIds.get(0);
SlotRequestId slotRequestId2 = slotRequestIds.get(1);
context.getSlotProvider().getResultForRequestId(slotRequestId1).complete(TestingPhysicalSlot.builder().withAllocationID(allocationId).build());
return requests.get(slotRequestId2).getSlotProfile().getPhysicalSlotResourceProfile();
}
use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest in project flink by apache.
the class SlotSharingExecutionSlotAllocatorTest method testSlotRequestProfile.
@Test
public void testSlotRequestProfile() {
AllocationContext context = AllocationContext.newBuilder().addGroup(EV1, EV2, EV3).build();
ResourceProfile physicalsSlotResourceProfile = RESOURCE_PROFILE.multiply(3);
context.allocateSlotsFor(EV1, EV2);
Optional<PhysicalSlotRequest> slotRequest = context.getSlotProvider().getRequests().values().stream().findFirst();
assertThat(slotRequest.isPresent(), is(true));
slotRequest.ifPresent(r -> assertThat(r.getSlotProfile().getPhysicalSlotResourceProfile(), is(physicalsSlotResourceProfile)));
}
use of org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest in project flink by apache.
the class TestingPhysicalSlotProvider method allocatePhysicalSlot.
@Override
public CompletableFuture<PhysicalSlotRequest.Result> allocatePhysicalSlot(PhysicalSlotRequest physicalSlotRequest) {
SlotRequestId slotRequestId = physicalSlotRequest.getSlotRequestId();
requests.put(slotRequestId, physicalSlotRequest);
final CompletableFuture<TestingPhysicalSlot> resultFuture = physicalSlotCreator.apply(physicalSlotRequest.getSlotProfile().getPhysicalSlotResourceProfile());
responses.put(slotRequestId, resultFuture);
return resultFuture.thenApply(physicalSlot -> new PhysicalSlotRequest.Result(slotRequestId, physicalSlot));
}
Aggregations