Search in sources :

Example 1 with PhysicalSlotRequest

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);
    });
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest) PhysicalSlot(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile)

Example 2 with PhysicalSlotRequest

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));
}
Also used : PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest)

Example 3 with PhysicalSlotRequest

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();
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest) ArrayList(java.util.ArrayList)

Example 4 with PhysicalSlotRequest

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)));
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest) Test(org.junit.Test)

Example 5 with PhysicalSlotRequest

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));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) PhysicalSlotRequest(org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest)

Aggregations

PhysicalSlotRequest (org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotRequest)5 SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)3 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)2 ArrayList (java.util.ArrayList)1 SlotProfile (org.apache.flink.runtime.clusterframework.types.SlotProfile)1 PhysicalSlot (org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot)1 Test (org.junit.Test)1