Search in sources :

Example 1 with SlotProfile

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

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

Example 3 with SlotProfile

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));
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) HashMap(java.util.HashMap) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile) MemorySize(org.apache.flink.configuration.MemorySize) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Collection(java.util.Collection) Test(org.junit.Test) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Test(org.junit.Test)

Example 4 with SlotProfile

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

Example 5 with SlotProfile

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));
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) HashMap(java.util.HashMap) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile) MemorySize(org.apache.flink.configuration.MemorySize) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Collection(java.util.Collection) Test(org.junit.Test) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) HashMap(java.util.HashMap) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) SlotProfile(org.apache.flink.runtime.clusterframework.types.SlotProfile) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

SlotProfile (org.apache.flink.runtime.clusterframework.types.SlotProfile)8 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)6 Test (org.junit.Test)6 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)5 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 ExecutionException (java.util.concurrent.ExecutionException)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 MemorySize (org.apache.flink.configuration.MemorySize)2 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)2 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)2