use of org.apache.flink.runtime.clusterframework.types.SlotProfile 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.clusterframework.types.SlotProfile in project flink by apache.
the class SlotSharingExecutionSlotAllocatorTest method testSlotRequestProfileFromExecutionSlotSharingGroup.
@Test
public void testSlotRequestProfileFromExecutionSlotSharingGroup() {
final ResourceProfile resourceProfile1 = ResourceProfile.fromResources(1, 10);
final ResourceProfile resourceProfile2 = ResourceProfile.fromResources(2, 20);
final AllocationContext context = AllocationContext.newBuilder().addGroupAndResource(resourceProfile1, EV1, EV3).addGroupAndResource(resourceProfile2, EV2, EV4).build();
context.allocateSlotsFor(EV1, EV2);
assertThat(context.getSlotProvider().getRequests().values().size(), is(2));
assertThat(context.getSlotProvider().getRequests().values().stream().map(PhysicalSlotRequest::getSlotProfile).map(SlotProfile::getPhysicalSlotResourceProfile).collect(Collectors.toList()), containsInAnyOrder(resourceProfile1, resourceProfile2));
}
use of org.apache.flink.runtime.clusterframework.types.SlotProfile in project flink by apache.
the class MergingSharedSlotProfileRetrieverTest method testGetEmptySlotProfile.
@Test
public void testGetEmptySlotProfile() throws ExecutionException, InterruptedException {
SharedSlotProfileRetriever sharedSlotProfileRetriever = new MergingSharedSlotProfileRetrieverFactory(EMPTY_PREFERRED_LOCATIONS_RETRIEVER, executionVertexID -> Optional.of(new AllocationID()), () -> Collections.emptySet()).createFromBulk(Collections.emptySet());
SlotProfile slotProfile = sharedSlotProfileRetriever.getSlotProfile(new ExecutionSlotSharingGroup(), ResourceProfile.ZERO);
assertThat(slotProfile.getTaskResourceProfile(), is(ResourceProfile.ZERO));
assertThat(slotProfile.getPhysicalSlotResourceProfile(), is(ResourceProfile.ZERO));
assertThat(slotProfile.getPreferredLocations(), hasSize(0));
assertThat(slotProfile.getPreferredAllocations(), hasSize(0));
assertThat(slotProfile.getReservedAllocations(), hasSize(0));
}
use of org.apache.flink.runtime.clusterframework.types.SlotProfile in project flink by apache.
the class MergingSharedSlotProfileRetrieverTest method testReservedAllocationsOfSlotProfile.
@Test
public void testReservedAllocationsOfSlotProfile() throws ExecutionException, InterruptedException {
List<AllocationID> reservedAllocationIds = Arrays.asList(new AllocationID(), new AllocationID(), new AllocationID());
SlotProfile slotProfile = getSlotProfile(EMPTY_PREFERRED_LOCATIONS_RETRIEVER, Collections.emptyList(), ResourceProfile.ZERO, Collections.emptyList(), reservedAllocationIds, 0);
assertThat(slotProfile.getReservedAllocations(), containsInAnyOrder(reservedAllocationIds.toArray()));
}
use of org.apache.flink.runtime.clusterframework.types.SlotProfile in project flink by apache.
the class MergingSharedSlotProfileRetrieverTest method testPreferredLocationsOfSlotProfile.
@Test
public void testPreferredLocationsOfSlotProfile() throws ExecutionException, InterruptedException {
// preferred locations
List<ExecutionVertexID> executions = IntStream.range(0, 3).mapToObj(i -> new ExecutionVertexID(new JobVertexID(), 0)).collect(Collectors.toList());
List<TaskManagerLocation> allLocations = executions.stream().map(e -> createTaskManagerLocation()).collect(Collectors.toList());
Map<ExecutionVertexID, Collection<TaskManagerLocation>> locations = new HashMap<>();
locations.put(executions.get(0), Arrays.asList(allLocations.get(0), allLocations.get(1)));
locations.put(executions.get(1), Arrays.asList(allLocations.get(1), allLocations.get(2)));
List<AllocationID> prevAllocationIds = Collections.nCopies(3, new AllocationID());
SlotProfile slotProfile = getSlotProfile((executionVertexId, producersToIgnore) -> {
assertThat(producersToIgnore, containsInAnyOrder(executions.toArray()));
return locations.get(executionVertexId);
}, executions, ResourceProfile.ZERO, prevAllocationIds, prevAllocationIds, 2);
assertThat(slotProfile.getPreferredLocations().stream().filter(allLocations.get(0)::equals).count(), is(1L));
assertThat(slotProfile.getPreferredLocations().stream().filter(allLocations.get(1)::equals).count(), is(2L));
assertThat(slotProfile.getPreferredLocations().stream().filter(allLocations.get(2)::equals).count(), is(1L));
}
Aggregations