org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot Java Examples
The following examples show how to use
org.apache.flink.runtime.jobmaster.slotpool.SingleLogicalSlot.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExecutionGraphSchedulingTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Nonnull static SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner, TaskManagerGateway taskManagerGateway, SlotRequestId slotRequestId) { TaskManagerLocation location = new TaskManagerLocation( ResourceID.generate(), InetAddress.getLoopbackAddress(), 12345); SimpleSlotContext slotContext = new SimpleSlotContext( new AllocationID(), location, 0, taskManagerGateway); return new SingleLogicalSlot( slotRequestId, slotContext, null, Locality.LOCAL, slotOwner); }
Example #2
Source File: ExecutionVertexLocalityTest.java From flink with Apache License 2.0 | 6 votes |
private void initializeLocation(ExecutionVertex vertex, TaskManagerLocation location) throws Exception { // we need a bit of reflection magic to initialize the location without going through // scheduling paths. we choose to do that, rather than the alternatives: // - mocking the scheduler created fragile tests that break whenever the scheduler is adjusted // - exposing test methods in the ExecutionVertex leads to undesirable setters SlotContext slotContext = new SimpleSlotContext( new AllocationID(), location, 0, mock(TaskManagerGateway.class)); LogicalSlot slot = new SingleLogicalSlot( new SlotRequestId(), slotContext, null, Locality.LOCAL, mock(SlotOwner.class)); if (!vertex.getCurrentExecutionAttempt().tryAssignResource(slot)) { throw new FlinkException("Could not assign resource."); } }
Example #3
Source File: ExecutionGraphSchedulingTest.java From flink with Apache License 2.0 | 6 votes |
@Nonnull static SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner, TaskManagerGateway taskManagerGateway, SlotRequestId slotRequestId) { TaskManagerLocation location = new TaskManagerLocation( ResourceID.generate(), InetAddress.getLoopbackAddress(), 12345); SimpleSlotContext slotContext = new SimpleSlotContext( new AllocationID(), location, 0, taskManagerGateway); return new SingleLogicalSlot( slotRequestId, slotContext, null, Locality.LOCAL, slotOwner); }
Example #4
Source File: ExecutionVertexLocalityTest.java From flink with Apache License 2.0 | 6 votes |
private void initializeLocation(ExecutionVertex vertex, TaskManagerLocation location) throws Exception { // we need a bit of reflection magic to initialize the location without going through // scheduling paths. we choose to do that, rather than the alternatives: // - mocking the scheduler created fragile tests that break whenever the scheduler is adjusted // - exposing test methods in the ExecutionVertex leads to undesirable setters SlotContext slotContext = new SimpleSlotContext( new AllocationID(), location, 0, mock(TaskManagerGateway.class)); LogicalSlot slot = new SingleLogicalSlot( new SlotRequestId(), slotContext, null, Locality.LOCAL, mock(SlotOwner.class)); if (!vertex.getCurrentExecutionAttempt().tryAssignResource(slot)) { throw new FlinkException("Could not assign resource."); } }
Example #5
Source File: ExecutionGraphSchedulingTest.java From flink with Apache License 2.0 | 6 votes |
@Nonnull static SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner, TaskManagerGateway taskManagerGateway, SlotRequestId slotRequestId) { TaskManagerLocation location = new TaskManagerLocation( ResourceID.generate(), InetAddress.getLoopbackAddress(), 12345); SimpleSlotContext slotContext = new SimpleSlotContext( new AllocationID(), location, 0, taskManagerGateway); return new SingleLogicalSlot( slotRequestId, slotContext, null, Locality.LOCAL, slotOwner); }
Example #6
Source File: ExecutionTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests that a slot release will atomically release the assigned {@link Execution}. */ @Test public void testSlotReleaseAtomicallyReleasesExecution() throws Exception { final JobVertex jobVertex = createNoOpJobVertex(); final SingleSlotTestingSlotOwner slotOwner = new SingleSlotTestingSlotOwner(); final SingleLogicalSlot slot = ExecutionGraphSchedulingTest.createSingleLogicalSlot( slotOwner, new SimpleAckingTaskManagerGateway(), new SlotRequestId()); final CompletableFuture<LogicalSlot> slotFuture = CompletableFuture.completedFuture(slot); final CountDownLatch slotRequestLatch = new CountDownLatch(1); final TestingSlotProvider slotProvider = new TestingSlotProvider(slotRequestId -> { slotRequestLatch.countDown(); return slotFuture; }); final ExecutionGraph executionGraph = ExecutionGraphTestUtils.createSimpleTestGraph( new JobID(), slotProvider, new NoRestartStrategy(), jobVertex); final Execution execution = executionGraph.getJobVertex(jobVertex.getID()).getTaskVertices()[0].getCurrentExecutionAttempt(); executionGraph.start(testMainThreadUtil.getMainThreadExecutor()); testMainThreadUtil.execute(executionGraph::scheduleForExecution); // wait until the slot has been requested slotRequestLatch.await(); testMainThreadUtil.execute(() -> { assertThat(execution.getAssignedResource(), is(sameInstance(slot))); slot.release(new FlinkException("Test exception")); assertThat(execution.getReleaseFuture().isDone(), is(true)); }); }
Example #7
Source File: ExecutionTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that a slot release will atomically release the assigned {@link Execution}. */ @Test public void testSlotReleaseAtomicallyReleasesExecution() throws Exception { final JobVertex jobVertex = createNoOpJobVertex(); final SingleSlotTestingSlotOwner slotOwner = new SingleSlotTestingSlotOwner(); final SingleLogicalSlot slot = ExecutionGraphSchedulingTest.createSingleLogicalSlot( slotOwner, new SimpleAckingTaskManagerGateway(), new SlotRequestId()); final CompletableFuture<LogicalSlot> slotFuture = CompletableFuture.completedFuture(slot); final CountDownLatch slotRequestLatch = new CountDownLatch(1); final TestingSlotProvider slotProvider = new TestingSlotProvider(slotRequestId -> { slotRequestLatch.countDown(); return slotFuture; }); final ExecutionGraph executionGraph = ExecutionGraphTestUtils.createSimpleTestGraph( new JobID(), slotProvider, new NoRestartStrategy(), jobVertex); final Execution execution = executionGraph.getJobVertex(jobVertex.getID()).getTaskVertices()[0].getCurrentExecutionAttempt(); executionGraph.start(testMainThreadUtil.getMainThreadExecutor()); testMainThreadUtil.execute(executionGraph::scheduleForExecution); // wait until the slot has been requested slotRequestLatch.await(); testMainThreadUtil.execute(() -> { assertThat(execution.getAssignedResource(), is(sameInstance(slot))); slot.release(new FlinkException("Test exception")); assertThat(execution.getReleaseFuture().isDone(), is(true)); }); }
Example #8
Source File: OneSlotPerExecutionSlotAllocator.java From flink with Apache License 2.0 | 5 votes |
private void allocateSlotsForAssignments( final List<CompletableFuture<PhysicalSlotRequest>> physicalSlotRequestFutures, final Map<SlotRequestId, SlotExecutionVertexAssignment> slotExecutionVertexAssignments) { FutureUtils.combineAll(physicalSlotRequestFutures) .thenCompose(physicalSlotRequests -> slotProvider.allocatePhysicalSlots(physicalSlotRequests, allocationTimeout)) .thenAccept(physicalSlotRequestResults -> { for (PhysicalSlotRequest.Result result : physicalSlotRequestResults) { final SlotRequestId slotRequestId = result.getSlotRequestId(); final SlotExecutionVertexAssignment assignment = slotExecutionVertexAssignments.get(slotRequestId); checkState(assignment != null); final LogicalSlot logicalSlot = SingleLogicalSlot.allocateFromPhysicalSlot( slotRequestId, result.getPhysicalSlot(), Locality.UNKNOWN, this, slotWillBeOccupiedIndefinitely); assignment.getLogicalSlotFuture().complete(logicalSlot); } }) .exceptionally(ex -> { slotExecutionVertexAssignments.values().forEach( assignment -> assignment.getLogicalSlotFuture().completeExceptionally(ex)); return null; }); }
Example #9
Source File: ExecutionTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that a slot release will atomically release the assigned {@link Execution}. */ @Test public void testSlotReleaseAtomicallyReleasesExecution() throws Exception { final JobVertex jobVertex = createNoOpJobVertex(); final SingleSlotTestingSlotOwner slotOwner = new SingleSlotTestingSlotOwner(); final SingleLogicalSlot slot = ExecutionGraphSchedulingTest.createSingleLogicalSlot( slotOwner, new SimpleAckingTaskManagerGateway(), new SlotRequestId()); final CompletableFuture<LogicalSlot> slotFuture = CompletableFuture.completedFuture(slot); final CountDownLatch slotRequestLatch = new CountDownLatch(1); final TestingSlotProvider slotProvider = new TestingSlotProvider(slotRequestId -> { slotRequestLatch.countDown(); return slotFuture; }); final ExecutionGraph executionGraph = ExecutionGraphTestUtils.createSimpleTestGraph( slotProvider, new NoRestartStrategy(), jobVertex); final Execution execution = executionGraph.getJobVertex(jobVertex.getID()).getTaskVertices()[0].getCurrentExecutionAttempt(); executionGraph.start(testMainThreadUtil.getMainThreadExecutor()); testMainThreadUtil.execute(executionGraph::scheduleForExecution); // wait until the slot has been requested slotRequestLatch.await(); testMainThreadUtil.execute(() -> { assertThat(execution.getAssignedResource(), is(sameInstance(slot))); slot.release(new FlinkException("Test exception")); assertThat(execution.getReleaseFuture().isDone(), is(true)); }); }