org.apache.flink.runtime.jobmaster.LogicalSlot Java Examples
The following examples show how to use
org.apache.flink.runtime.jobmaster.LogicalSlot.
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: Execution.java From flink with Apache License 2.0 | 6 votes |
/** * Update the partition infos on the assigned resource. * * @param partitionInfos for the remote task */ private void sendUpdatePartitionInfoRpcCall( final Iterable<PartitionInfo> partitionInfos) { final LogicalSlot slot = assignedResource; if (slot != null) { final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway(); final TaskManagerLocation taskManagerLocation = slot.getTaskManagerLocation(); CompletableFuture<Acknowledge> updatePartitionsResultFuture = taskManagerGateway.updatePartitions(attemptId, partitionInfos, rpcTimeout); updatePartitionsResultFuture.whenCompleteAsync( (ack, failure) -> { // fail if there was a failure if (failure != null) { fail(new IllegalStateException("Update to task [" + getVertexWithAttempt() + "] on TaskManager " + taskManagerLocation + " failed", failure)); } }, getVertex().getExecutionGraph().getJobMasterMainThreadExecutor()); } }
Example #2
Source File: DefaultExecutionSlotAllocator.java From flink with Apache License 2.0 | 6 votes |
private CompletableFuture<LogicalSlot> allocateSlot( final ExecutionVertexSchedulingRequirements schedulingRequirements, final SlotRequestId slotRequestId, final Set<AllocationID> allPreviousAllocationIds) { final ExecutionVertexID executionVertexId = schedulingRequirements.getExecutionVertexId(); LOG.debug("Allocate slot with id {} for execution {}", slotRequestId, executionVertexId); final CompletableFuture<SlotProfile> slotProfileFuture = getSlotProfileFuture( schedulingRequirements, schedulingRequirements.getPhysicalSlotResourceProfile(), Collections.emptySet(), allPreviousAllocationIds); return slotProfileFuture.thenCompose( slotProfile -> slotProviderStrategy.allocateSlot( slotRequestId, new ScheduledUnit( executionVertexId, schedulingRequirements.getSlotSharingGroupId(), schedulingRequirements.getCoLocationConstraint()), slotProfile)); }
Example #3
Source File: SlotSharingManagerTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSlotOverAllocatedAndSingleSlotReleased() { SlotSharingResourceTestContext context = createResourceTestContext(new ResourceProfile(7.0, 700)); // The two coLocated requests and the third request is successful. for (int i = 0; i < context.singleTaskSlotsInOrder.size(); ++i) { SlotSharingManager.SingleTaskSlot singleTaskSlot = context.singleTaskSlotsInOrder.get(i); assertThat(singleTaskSlot.getLogicalSlotFuture().isDone(), is(true)); if (i != 3) { assertThat(singleTaskSlot.getLogicalSlotFuture().isCompletedExceptionally(), is(false)); } else { assertThat(singleTaskSlot.getLogicalSlotFuture().isCompletedExceptionally(), is(true)); singleTaskSlot.getLogicalSlotFuture().whenComplete((LogicalSlot ignored, Throwable throwable) -> { assertThat(throwable instanceof SharedSlotOversubscribedException, is(true)); assertThat(((SharedSlotOversubscribedException) throwable).canRetry(), is(true)); }); } } // The multi-task slot for coLocation should be kept. assertThat(context.slotSharingManager.getTaskSlot(context.coLocationTaskSlot.getSlotRequestId()), notNullValue()); }
Example #4
Source File: Execution.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Request a stack trace sample from the task of this execution. * * @param sampleId of the stack trace sample * @param numSamples the sample should contain * @param delayBetweenSamples to wait * @param maxStackTraceDepth of the samples * @param timeout until the request times out * @return Future stack trace sample response */ public CompletableFuture<StackTraceSampleResponse> requestStackTraceSample( int sampleId, int numSamples, Time delayBetweenSamples, int maxStackTraceDepth, Time timeout) { final LogicalSlot slot = assignedResource; if (slot != null) { final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway(); return taskManagerGateway.requestStackTraceSample( attemptId, sampleId, numSamples, delayBetweenSamples, maxStackTraceDepth, timeout); } else { return FutureUtils.completedExceptionally(new Exception("The execution has no slot assigned.")); } }
Example #5
Source File: Execution.java From flink with Apache License 2.0 | 6 votes |
/** * This method sends a CancelTask message to the instance of the assigned slot. * * <p>The sending is tried up to NUM_CANCEL_CALL_TRIES times. */ private void sendCancelRpcCall(int numberRetries) { final LogicalSlot slot = assignedResource; if (slot != null) { final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway(); final ComponentMainThreadExecutor jobMasterMainThreadExecutor = getVertex().getExecutionGraph().getJobMasterMainThreadExecutor(); CompletableFuture<Acknowledge> cancelResultFuture = FutureUtils.retry( () -> taskManagerGateway.cancelTask(attemptId, rpcTimeout), numberRetries, jobMasterMainThreadExecutor); cancelResultFuture.whenComplete( (ack, failure) -> { if (failure != null) { fail(new Exception("Task could not be canceled.", failure)); } }); } }
Example #6
Source File: SlotSharingManagerTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSlotOverAllocatedAndAllTaskSlotReleased() { SlotSharingResourceTestContext context = createResourceTestContext(new ResourceProfile(2.0, 200)); // Only the third request is fulfilled. for (int i = 0; i < context.singleTaskSlotsInOrder.size(); ++i) { SlotSharingManager.SingleTaskSlot singleTaskSlot = context.singleTaskSlotsInOrder.get(i); assertThat(singleTaskSlot.getLogicalSlotFuture().isDone(), is(true)); assertThat(singleTaskSlot.getLogicalSlotFuture().isCompletedExceptionally(), is(true)); singleTaskSlot.getLogicalSlotFuture().whenComplete((LogicalSlot ignored, Throwable throwable) -> { assertThat(throwable instanceof SharedSlotOversubscribedException, is(true)); // Since no request is fulfilled, these requests will be failed and should not retry. assertThat(((SharedSlotOversubscribedException) throwable).canRetry(), is(false)); }); } // All the task slots should be removed. assertThat(context.slotSharingManager.isEmpty(), is(true)); }
Example #7
Source File: SchedulerImpl.java From flink with Apache License 2.0 | 6 votes |
@Nonnull private LogicalSlot completeAllocationByAssigningPayload( @Nonnull SlotRequestId slotRequestId, @Nonnull SlotAndLocality slotAndLocality) throws FlinkException { final PhysicalSlot allocatedSlot = slotAndLocality.getSlot(); try { final SingleLogicalSlot singleTaskSlot = SingleLogicalSlot.allocateFromPhysicalSlot( slotRequestId, allocatedSlot, slotAndLocality.getLocality(), this, true); return singleTaskSlot; } catch (Throwable t) { final FlinkException flinkException = new FlinkException(t); slotPool.releaseSlot(slotRequestId, flinkException); throw flinkException; } }
Example #8
Source File: SchedulerImpl.java From flink with Apache License 2.0 | 6 votes |
@Nonnull private CompletableFuture<LogicalSlot> allocateSlotInternal( SlotRequestId slotRequestId, ScheduledUnit scheduledUnit, SlotProfile slotProfile, @Nullable Time allocationTimeout) { log.debug("Received slot request [{}] for task: {}", slotRequestId, scheduledUnit.getJobVertexId()); componentMainThreadExecutor.assertRunningInMainThread(); final CompletableFuture<LogicalSlot> allocationResultFuture = new CompletableFuture<>(); internalAllocateSlot( allocationResultFuture, slotRequestId, scheduledUnit, slotProfile, allocationTimeout); return allocationResultFuture; }
Example #9
Source File: Execution.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Sends stop RPC call. */ public void stop() { assertRunningInJobMasterMainThread(); final LogicalSlot slot = assignedResource; if (slot != null) { final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway(); CompletableFuture<Acknowledge> stopResultFuture = FutureUtils.retry( () -> taskManagerGateway.stopTask(attemptId, rpcTimeout), NUM_STOP_CALL_TRIES, vertex.getExecutionGraph().getJobMasterMainThreadExecutor()); stopResultFuture.exceptionally( failure -> { LOG.info("Stopping task was not successful.", failure); return null; }); } }
Example #10
Source File: AbstractExecutionSlotAllocator.java From flink with Apache License 2.0 | 6 votes |
SlotExecutionVertexAssignment createAndRegisterSlotExecutionVertexAssignment( final ExecutionVertexID executionVertexId, final CompletableFuture<LogicalSlot> logicalSlotFuture, final Consumer<Throwable> slotRequestFailureHandler) { final SlotExecutionVertexAssignment slotExecutionVertexAssignment = new SlotExecutionVertexAssignment(executionVertexId, logicalSlotFuture); // add to map first in case the slot future is already completed pendingSlotAssignments.put(executionVertexId, slotExecutionVertexAssignment); logicalSlotFuture.whenComplete( (ignored, throwable) -> { pendingSlotAssignments.remove(executionVertexId); if (throwable != null) { slotRequestFailureHandler.accept(throwable); } }); return slotExecutionVertexAssignment; }
Example #11
Source File: SchedulerImpl.java From flink with Apache License 2.0 | 6 votes |
@Nonnull private CompletableFuture<LogicalSlot> allocateSlotInternal( SlotRequestId slotRequestId, ScheduledUnit scheduledUnit, SlotProfile slotProfile, boolean allowQueuedScheduling, @Nullable Time allocationTimeout) { log.debug("Received slot request [{}] for task: {}", slotRequestId, scheduledUnit.getTaskToExecute()); componentMainThreadExecutor.assertRunningInMainThread(); final CompletableFuture<LogicalSlot> allocationResultFuture = new CompletableFuture<>(); internalAllocateSlot( allocationResultFuture, slotRequestId, scheduledUnit, slotProfile, allowQueuedScheduling, allocationTimeout); return allocationResultFuture; }
Example #12
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 #13
Source File: ExecutionVertex.java From flink with Apache License 2.0 | 5 votes |
@VisibleForTesting public void deployToSlot(LogicalSlot slot) throws JobException { if (currentExecution.tryAssignResource(slot)) { currentExecution.deploy(); } else { throw new IllegalStateException("Could not assign resource " + slot + " to current execution " + currentExecution + '.'); } }
Example #14
Source File: SimpleSlotProvider.java From flink with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<LogicalSlot> allocateSlot( SlotRequestId slotRequestId, ScheduledUnit task, SlotProfile slotProfile, boolean allowQueued, Time allocationTimeout) { final SlotContext slot; synchronized (lock) { if (slots.isEmpty()) { slot = null; } else { slot = slots.removeFirst(); } if (slot != null) { TestingLogicalSlot result = new TestingLogicalSlotBuilder() .setTaskManagerLocation(slot.getTaskManagerLocation()) .setTaskManagerGateway(slot.getTaskManagerGateway()) .setSlotNumber(slot.getPhysicalSlotNumber()) .setAllocationId(slot.getAllocationId()) .setSlotRequestId(slotRequestId) .setSlotOwner(this) .createTestingLogicalSlot(); allocatedSlots.put(slotRequestId, slot); return CompletableFuture.completedFuture(result); } else { return FutureUtils.completedExceptionally(new NoResourceAvailableException()); } } }
Example #15
Source File: SlotPoolImplTest.java From flink with Apache License 2.0 | 5 votes |
private CompletableFuture<LogicalSlot> allocateSlot(Scheduler scheduler, SlotRequestId slotRequestId) { return scheduler.allocateSlot( slotRequestId, new DummyScheduledUnit(), SlotProfile.noRequirements(), true, timeout); }
Example #16
Source File: ScheduleWithCoLocationHintTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void nonColocationFollowsCoLocation() throws Exception { JobVertexID jid1 = new JobVertexID(); JobVertexID jid2 = new JobVertexID(); TaskManagerLocation loc1 = testingSlotProvider.addTaskManager(1); TaskManagerLocation loc2 = testingSlotProvider.addTaskManager(1); assertEquals(2, testingSlotProvider.getNumberOfAvailableSlots()); SlotSharingGroup sharingGroup = new SlotSharingGroup(); CoLocationGroup ccg = new CoLocationGroup(); CoLocationConstraint cc1 = new CoLocationConstraint(ccg); CoLocationConstraint cc2 = new CoLocationConstraint(ccg); LogicalSlot s1 = testingSlotProvider.allocateSlot( new ScheduledUnit(getTestVertexWithLocation(jid1, 0, 2, sharingGroup, loc1), sharingGroup.getSlotSharingGroupId(), cc1), false, slotProfileForLocation(loc1), TestingUtils.infiniteTime()).get(); LogicalSlot s2 = testingSlotProvider.allocateSlot( new ScheduledUnit(getTestVertexWithLocation(jid1, 1, 2, sharingGroup, loc2), sharingGroup.getSlotSharingGroupId(), cc2), false, slotProfileForLocation(loc2), TestingUtils.infiniteTime()).get(); LogicalSlot s3 = testingSlotProvider.allocateSlot( new ScheduledUnit(getTestVertexWithLocation(jid2, 0, 2, sharingGroup, loc1), sharingGroup.getSlotSharingGroupId()), false, slotProfileForLocation(loc1), TestingUtils.infiniteTime()).get(); LogicalSlot s4 = testingSlotProvider.allocateSlot( new ScheduledUnit(getTestVertexWithLocation(jid2, 1, 2, sharingGroup, loc1), sharingGroup.getSlotSharingGroupId()), false, slotProfileForLocation(loc1), TestingUtils.infiniteTime()).get(); // check that each slot got two assertEquals(s1.getTaskManagerLocation(), s3.getTaskManagerLocation()); assertEquals(s2.getTaskManagerLocation(), s4.getTaskManagerLocation()); s1.releaseSlot(); s2.releaseSlot(); s3.releaseSlot(); s4.releaseSlot(); assertEquals(2, testingSlotProvider.getNumberOfAvailableSlots()); }
Example #17
Source File: SchedulerImpl.java From flink with Apache License 2.0 | 5 votes |
@Override public void returnLogicalSlot(LogicalSlot logicalSlot) { SlotRequestId slotRequestId = logicalSlot.getSlotRequestId(); SlotSharingGroupId slotSharingGroupId = logicalSlot.getSlotSharingGroupId(); FlinkException cause = new FlinkException("Slot is being returned to the SlotPool."); cancelSlotRequest(slotRequestId, slotSharingGroupId, cause); }
Example #18
Source File: SlotProvider.java From flink with Apache License 2.0 | 5 votes |
/** * Allocating slot with specific requirement. * * @param scheduledUnit The task to allocate the slot for * @param allowQueued Whether allow the task be queued if we do not have enough resource * @param slotProfile profile of the requested slot * @param allocationTimeout after which the allocation fails with a timeout exception * @return The future of the allocation */ default CompletableFuture<LogicalSlot> allocateSlot( ScheduledUnit scheduledUnit, boolean allowQueued, SlotProfile slotProfile, Time allocationTimeout) { return allocateSlot( new SlotRequestId(), scheduledUnit, slotProfile, allowQueued, allocationTimeout); }
Example #19
Source File: SchedulerImpl.java From flink with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<LogicalSlot> allocateBatchSlot( SlotRequestId slotRequestId, ScheduledUnit scheduledUnit, SlotProfile slotProfile, boolean allowQueuedScheduling) { return allocateSlotInternal( slotRequestId, scheduledUnit, slotProfile, allowQueuedScheduling, null); }
Example #20
Source File: DefaultExecutionSlotAllocator.java From flink with Apache License 2.0 | 5 votes |
@Override public List<SlotExecutionVertexAssignment> allocateSlotsFor( List<ExecutionVertexSchedulingRequirements> executionVertexSchedulingRequirements) { validateSchedulingRequirements(executionVertexSchedulingRequirements); List<SlotExecutionVertexAssignment> slotExecutionVertexAssignments = new ArrayList<>(executionVertexSchedulingRequirements.size()); Set<AllocationID> allPreviousAllocationIds = computeAllPriorAllocationIds(executionVertexSchedulingRequirements); for (ExecutionVertexSchedulingRequirements schedulingRequirements : executionVertexSchedulingRequirements) { final ExecutionVertexID executionVertexId = schedulingRequirements.getExecutionVertexId(); final SlotSharingGroupId slotSharingGroupId = schedulingRequirements.getSlotSharingGroupId(); final SlotRequestId slotRequestId = new SlotRequestId(); final CompletableFuture<LogicalSlot> slotFuture = allocateSlot( schedulingRequirements, slotRequestId, allPreviousAllocationIds); final SlotExecutionVertexAssignment slotExecutionVertexAssignment = createAndRegisterSlotExecutionVertexAssignment( executionVertexId, slotFuture, throwable -> slotProviderStrategy.cancelSlotRequest(slotRequestId, slotSharingGroupId, throwable)); slotExecutionVertexAssignments.add(slotExecutionVertexAssignment); } return slotExecutionVertexAssignments; }
Example #21
Source File: SlotPoolInteractionsTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSlotAllocationNoResourceManager() throws Exception { final JobID jid = new JobID(); try (SlotPool pool = new SlotPoolImpl( jid, SystemClock.getInstance(), TestingUtils.infiniteTime(), TestingUtils.infiniteTime() )) { pool.start(JobMasterId.generate(), "foobar", testMainThreadExecutor.getMainThreadExecutor()); Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.INSTANCE, pool); scheduler.start(testMainThreadExecutor.getMainThreadExecutor()); CompletableFuture<LogicalSlot> future = testMainThreadExecutor.execute(() -> scheduler.allocateSlot( new SlotRequestId(), new ScheduledUnit(SchedulerTestUtils.getDummyTask()), SlotProfile.noLocality(DEFAULT_TESTING_PROFILE), true, fastTimeout)); try { future.get(); fail("We expected an ExecutionException."); } catch (ExecutionException e) { assertTrue(ExceptionUtils.stripExecutionException(e) instanceof TimeoutException); } } }
Example #22
Source File: DefaultScheduler.java From flink with Apache License 2.0 | 5 votes |
private BiFunction<Void, Throwable, Void> deployAll(final List<DeploymentHandle> deploymentHandles) { return (ignored, throwable) -> { propagateIfNonNull(throwable); for (final DeploymentHandle deploymentHandle : deploymentHandles) { final SlotExecutionVertexAssignment slotExecutionVertexAssignment = deploymentHandle.getSlotExecutionVertexAssignment(); final CompletableFuture<LogicalSlot> slotAssigned = slotExecutionVertexAssignment.getLogicalSlotFuture(); checkState(slotAssigned.isDone()); FutureUtils.assertNoException( slotAssigned.handle(deployOrHandleError(deploymentHandle))); } return null; }; }
Example #23
Source File: ExecutionGraphTestUtils.java From flink with Apache License 2.0 | 5 votes |
public static void setVertexResource(ExecutionVertex vertex, LogicalSlot slot) { Execution exec = vertex.getCurrentExecutionAttempt(); if (!exec.tryAssignResource(slot)) { throw new RuntimeException("Could not assign resource."); } }
Example #24
Source File: Execution.java From flink with Apache License 2.0 | 5 votes |
/** * Tries to assign the given slot to the execution. The assignment works only if the * Execution is in state SCHEDULED. Returns true, if the resource could be assigned. * * @param logicalSlot to assign to this execution * @return true if the slot could be assigned to the execution, otherwise false */ public boolean tryAssignResource(final LogicalSlot logicalSlot) { assertRunningInJobMasterMainThread(); checkNotNull(logicalSlot); // only allow to set the assigned resource in state SCHEDULED or CREATED // note: we also accept resource assignment when being in state CREATED for testing purposes if (state == SCHEDULED || state == CREATED) { if (assignedResource == null) { assignedResource = logicalSlot; if (logicalSlot.tryAssignPayload(this)) { // check for concurrent modification (e.g. cancelling call) if ((state == SCHEDULED || state == CREATED) && !taskManagerLocationFuture.isDone()) { taskManagerLocationFuture.complete(logicalSlot.getTaskManagerLocation()); assignedAllocationID = logicalSlot.getAllocationId(); return true; } else { // free assigned resource and return false assignedResource = null; return false; } } else { assignedResource = null; return false; } } else { // the slot already has another slot assigned return false; } } else { // do not allow resource assignment if we are not in state SCHEDULED return false; } }
Example #25
Source File: SlotPoolImplTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that create report of allocated slots on a {@link TaskExecutor}. */ @Test public void testCreateAllocatedSlotReport() throws Exception { try (SlotPoolImpl slotPool = createSlotPoolImpl()) { final ArrayBlockingQueue<AllocationID> allocationIds = new ArrayBlockingQueue<>(1); resourceManagerGateway.setRequestSlotConsumer( slotRequest -> allocationIds.offer(slotRequest.getAllocationId())); setupSlotPool(slotPool, resourceManagerGateway, mainThreadExecutor); Scheduler scheduler = setupScheduler(slotPool, mainThreadExecutor); final SlotRequestId slotRequestId = new SlotRequestId(); final CompletableFuture<LogicalSlot> slotRequestFuture = allocateSlot(scheduler, slotRequestId); final List<AllocatedSlotInfo> allocatedSlotInfos = new ArrayList<>(2); final List<SlotOffer> slotOffers = new ArrayList<>(2); final AllocationID allocatedId = allocationIds.take(); slotOffers.add(new SlotOffer(allocatedId, 0, ResourceProfile.UNKNOWN)); allocatedSlotInfos.add(new AllocatedSlotInfo(0, allocatedId)); final AllocationID availableId = new AllocationID(); slotOffers.add(new SlotOffer(availableId, 1, ResourceProfile.UNKNOWN)); allocatedSlotInfos.add(new AllocatedSlotInfo(1, availableId)); slotPool.registerTaskManager(taskManagerLocation.getResourceID()); slotPool.offerSlots(taskManagerLocation, taskManagerGateway, slotOffers); // wait for the completion of slot future slotRequestFuture.get(); final AllocatedSlotReport slotReport = slotPool.createAllocatedSlotReport(taskManagerLocation.getResourceID()); assertThat(jobId, is(slotReport.getJobId())); assertThat(slotReport.getAllocatedSlotInfos(), containsInAnyOrder(isEachEqual(allocatedSlotInfos))); } }
Example #26
Source File: ExecutionVertexSchedulingTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSlotReleasedWhenScheduledImmediately() { try { final ExecutionJobVertex ejv = getExecutionVertex(new JobVertexID()); final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout()); // a slot than cannot be deployed to final LogicalSlot slot = new TestingLogicalSlotBuilder().createTestingLogicalSlot(); slot.releaseSlot(new Exception("Test Exception")); assertFalse(slot.isAlive()); CompletableFuture<LogicalSlot> future = new CompletableFuture<>(); future.complete(slot); assertEquals(ExecutionState.CREATED, vertex.getExecutionState()); // try to deploy to the slot vertex.scheduleForExecution( TestingSlotProviderStrategy.from(new TestingSlotProvider((i) -> future), false), LocationPreferenceConstraint.ALL, Collections.emptySet()); // will have failed assertEquals(ExecutionState.FAILED, vertex.getExecutionState()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #27
Source File: SingleLogicalSlotTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests that the slot release is only signaled after the owner has * taken it back. */ @Test public void testSlotRelease() { final CompletableFuture<LogicalSlot> returnedSlotFuture = new CompletableFuture<>(); final CompletableFuture<Boolean> returnSlotResponseFuture = new CompletableFuture<>(); final WaitingSlotOwner waitingSlotOwner = new WaitingSlotOwner(returnedSlotFuture, returnSlotResponseFuture); final CompletableFuture<?> terminalStateFuture = new CompletableFuture<>(); final CompletableFuture<?> failFuture = new CompletableFuture<>(); final ManualTestingPayload dummyPayload = new ManualTestingPayload(failFuture, terminalStateFuture); final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot(waitingSlotOwner); assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(true)); final CompletableFuture<?> releaseFuture = singleLogicalSlot.releaseSlot(new FlinkException("Test exception")); assertThat(releaseFuture.isDone(), is(false)); assertThat(returnedSlotFuture.isDone(), is(false)); assertThat(failFuture.isDone(), is(true)); terminalStateFuture.complete(null); assertThat(returnedSlotFuture.isDone(), is(true)); returnSlotResponseFuture.complete(true); assertThat(releaseFuture.isDone(), is(true)); }
Example #28
Source File: ExecutionVertexDeploymentTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDeployFailedSynchronous() { try { final JobVertexID jid = new JobVertexID(); final ExecutionJobVertex ejv = getExecutionVertex(jid, new DirectScheduledExecutorService()); final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout()); final LogicalSlot slot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new SubmitFailingSimpleAckingTaskManagerGateway()).createTestingLogicalSlot(); assertEquals(ExecutionState.CREATED, vertex.getExecutionState()); vertex.deployToSlot(slot); assertEquals(ExecutionState.FAILED, vertex.getExecutionState()); assertNotNull(vertex.getFailureCause()); assertTrue(vertex.getFailureCause().getMessage().contains(ERROR_MESSAGE)); assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0); assertTrue(vertex.getStateTimestamp(ExecutionState.DEPLOYING) > 0); assertTrue(vertex.getStateTimestamp(ExecutionState.FAILED) > 0); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #29
Source File: ExecutionVertexSchedulingTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSlotReleasedWhenScheduledQueued() { try { final ExecutionJobVertex ejv = getExecutionVertex(new JobVertexID()); final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0], AkkaUtils.getDefaultTimeout()); // a slot than cannot be deployed to final LogicalSlot slot = new TestingLogicalSlot(); slot.releaseSlot(new Exception("Test Exception")); assertFalse(slot.isAlive()); final CompletableFuture<LogicalSlot> future = new CompletableFuture<>(); assertEquals(ExecutionState.CREATED, vertex.getExecutionState()); // try to deploy to the slot vertex.scheduleForExecution( new TestingSlotProvider(ignore -> future), true, LocationPreferenceConstraint.ALL, Collections.emptySet()); // future has not yet a slot assertEquals(ExecutionState.SCHEDULED, vertex.getExecutionState()); future.complete(slot); // will have failed assertEquals(ExecutionState.FAILED, vertex.getExecutionState()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #30
Source File: CheckpointCoordinatorTestingUtils.java From flink with Apache License 2.0 | 5 votes |
static ExecutionVertex mockExecutionVertex( ExecutionAttemptID attemptID, TaskManagerGateway taskManagerGateway) { TestingLogicalSlotBuilder slotBuilder = new TestingLogicalSlotBuilder(); slotBuilder.setTaskManagerGateway(taskManagerGateway); LogicalSlot slot = slotBuilder.createTestingLogicalSlot(); return mockExecutionVertex(attemptID, slot); }