Search in sources :

Example 1 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class SharedSlot method allocateLogicalSlot.

/**
 * Registers an allocation request for a logical slot.
 *
 * @return the logical slot
 */
public LogicalSlot allocateLogicalSlot() {
    LOG.debug("Allocating logical slot from shared slot ({})", physicalSlotRequestId);
    Preconditions.checkState(state == State.ALLOCATED, "The shared slot has already been released.");
    final LogicalSlot slot = new SingleLogicalSlot(new SlotRequestId(), physicalSlot, Locality.UNKNOWN, this, slotWillBeOccupiedIndefinitely);
    allocatedLogicalSlots.put(slot.getSlotRequestId(), slot);
    return slot;
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) SingleLogicalSlot(org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot) SingleLogicalSlot(org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot)

Example 2 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId 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 3 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class SharedSlotTest method testConstructorFailsIfSlotAlreadyHasAssignedPayload.

@Test(expected = IllegalStateException.class)
public void testConstructorFailsIfSlotAlreadyHasAssignedPayload() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    physicalSlot.tryAssignPayload(new TestingPhysicalSlotPayload());
    new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
    });
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) TestingPhysicalSlotPayload(org.apache.flink.runtime.jobmaster.slotpool.TestingPhysicalSlotPayload) Test(org.junit.Test)

Example 4 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class SharedSlotTest method testReleaseAlsoReleasesLogicalSlots.

@Test
public void testReleaseAlsoReleasesLogicalSlots() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
    });
    final LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot();
    sharedSlot.release(new Exception("test"));
    assertThat(logicalSlot.isAlive(), is(false));
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Example 5 with SlotRequestId

use of org.apache.flink.runtime.jobmaster.SlotRequestId in project flink by apache.

the class SharedSlotTest method testReturnLogicalSlotRejectsUnknownSlot.

@Test(expected = IllegalStateException.class)
public void testReturnLogicalSlotRejectsUnknownSlot() {
    final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build();
    final SharedSlot sharedSlot = new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {
    });
    final LogicalSlot logicalSlot = new TestingLogicalSlotBuilder().createTestingLogicalSlot();
    logicalSlot.releaseSlot(new Exception("test"));
    sharedSlot.returnLogicalSlot(logicalSlot);
}
Also used : SlotRequestId(org.apache.flink.runtime.jobmaster.SlotRequestId) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) TestingLogicalSlotBuilder(org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder) LogicalSlot(org.apache.flink.runtime.jobmaster.LogicalSlot) Test(org.junit.Test)

Aggregations

SlotRequestId (org.apache.flink.runtime.jobmaster.SlotRequestId)51 Test (org.junit.Test)40 TestingPhysicalSlot (org.apache.flink.runtime.scheduler.TestingPhysicalSlot)15 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)11 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)8 TestLogger (org.apache.flink.util.TestLogger)6 Collectors (java.util.stream.Collectors)5 CoreMatchers.is (org.hamcrest.CoreMatchers.is)5 Assert.fail (org.junit.Assert.fail)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 List (java.util.List)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Consumer (java.util.function.Consumer)4 Time (org.apache.flink.api.common.time.Time)4 Arrays (java.util.Arrays)3 ExecutionException (java.util.concurrent.ExecutionException)3 SlotProfile (org.apache.flink.runtime.clusterframework.types.SlotProfile)3