use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class DefaultExecutionGraphDeploymentTest method testExecutionGraphIsDeployedInTopologicalOrder.
/**
* Tests that the {@link ExecutionGraph} is deployed in topological order.
*/
@Test
public void testExecutionGraphIsDeployedInTopologicalOrder() throws Exception {
final int sourceParallelism = 2;
final int sinkParallelism = 1;
final JobVertex sourceVertex = new JobVertex("source");
sourceVertex.setInvokableClass(NoOpInvokable.class);
sourceVertex.setParallelism(sourceParallelism);
final JobVertex sinkVertex = new JobVertex("sink");
sinkVertex.setInvokableClass(NoOpInvokable.class);
sinkVertex.setParallelism(sinkParallelism);
sinkVertex.connectNewDataSetAsInput(sourceVertex, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
final int numberTasks = sourceParallelism + sinkParallelism;
final ArrayBlockingQueue<ExecutionAttemptID> submittedTasksQueue = new ArrayBlockingQueue<>(numberTasks);
TestingTaskExecutorGatewayBuilder testingTaskExecutorGatewayBuilder = new TestingTaskExecutorGatewayBuilder();
testingTaskExecutorGatewayBuilder.setSubmitTaskConsumer((taskDeploymentDescriptor, jobMasterId) -> {
submittedTasksQueue.offer(taskDeploymentDescriptor.getExecutionAttemptId());
return CompletableFuture.completedFuture(Acknowledge.get());
});
final TaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
final TestingTaskExecutorGateway taskExecutorGateway = testingTaskExecutorGatewayBuilder.createTestingTaskExecutorGateway();
final RpcTaskManagerGateway taskManagerGateway = new RpcTaskManagerGateway(taskExecutorGateway, JobMasterId.generate());
final JobGraph jobGraph = JobGraphTestUtils.streamingJobGraph(sourceVertex, sinkVertex);
final TestingPhysicalSlotProvider physicalSlotProvider = TestingPhysicalSlotProvider.createWithoutImmediatePhysicalSlotCreation();
final SchedulerBase scheduler = SchedulerTestingUtils.newSchedulerBuilder(jobGraph, ComponentMainThreadExecutorServiceAdapter.forMainThread()).setExecutionSlotAllocatorFactory(SchedulerTestingUtils.newSlotSharingExecutionSlotAllocatorFactory(physicalSlotProvider)).setFutureExecutor(new DirectScheduledExecutorService()).build();
final ExecutionGraph executionGraph = scheduler.getExecutionGraph();
scheduler.startScheduling();
// change the order in which the futures are completed
final List<CompletableFuture<TestingPhysicalSlot>> shuffledFutures = new ArrayList<>(physicalSlotProvider.getResponses().values());
Collections.shuffle(shuffledFutures);
for (CompletableFuture<TestingPhysicalSlot> slotFuture : shuffledFutures) {
slotFuture.complete(TestingPhysicalSlot.builder().withTaskManagerLocation(taskManagerLocation).withTaskManagerGateway(taskManagerGateway).build());
}
final List<ExecutionAttemptID> submittedTasks = new ArrayList<>(numberTasks);
for (int i = 0; i < numberTasks; i++) {
submittedTasks.add(submittedTasksQueue.take());
}
final Collection<ExecutionAttemptID> firstStage = new ArrayList<>(sourceParallelism);
for (ExecutionVertex taskVertex : executionGraph.getJobVertex(sourceVertex.getID()).getTaskVertices()) {
firstStage.add(taskVertex.getCurrentExecutionAttempt().getAttemptId());
}
final Collection<ExecutionAttemptID> secondStage = new ArrayList<>(sinkParallelism);
for (ExecutionVertex taskVertex : executionGraph.getJobVertex(sinkVertex.getID()).getTaskVertices()) {
secondStage.add(taskVertex.getCurrentExecutionAttempt().getAttemptId());
}
assertThat(submittedTasks, new ExecutionStageMatcher(Arrays.asList(firstStage, secondStage)));
}
use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class JobMasterTest method testReleasingTaskExecutorIfNoMoreSlotsRegistered.
/**
* Tests that the TaskExecutor is released if all of its slots have been freed.
*/
@Test
public void testReleasingTaskExecutorIfNoMoreSlotsRegistered() throws Exception {
final JobGraph jobGraph = createSingleVertexJobWithRestartStrategy();
final JobMaster jobMaster = new JobMasterBuilder(jobGraph, rpcService).withConfiguration(configuration).withHighAvailabilityServices(haServices).withHeartbeatServices(heartbeatServices).createJobMaster();
final CompletableFuture<JobID> disconnectTaskExecutorFuture = new CompletableFuture<>();
final CompletableFuture<AllocationID> freedSlotFuture = new CompletableFuture<>();
final TestingTaskExecutorGateway testingTaskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setFreeSlotFunction((allocationID, throwable) -> {
freedSlotFuture.complete(allocationID);
return CompletableFuture.completedFuture(Acknowledge.get());
}).setDisconnectJobManagerConsumer((jobID, throwable) -> disconnectTaskExecutorFuture.complete(jobID)).createTestingTaskExecutorGateway();
final LocalUnresolvedTaskManagerLocation taskManagerLocation = new LocalUnresolvedTaskManagerLocation();
try {
jobMaster.start();
final JobMasterGateway jobMasterGateway = jobMaster.getSelfGateway(JobMasterGateway.class);
final Collection<SlotOffer> slotOffers = registerSlotsAtJobMaster(1, jobMasterGateway, jobGraph.getJobID(), testingTaskExecutorGateway, taskManagerLocation);
// check that we accepted the offered slot
assertThat(slotOffers, hasSize(1));
final AllocationID allocationId = slotOffers.iterator().next().getAllocationId();
// now fail the allocation and check that we close the connection to the TaskExecutor
jobMasterGateway.failSlot(taskManagerLocation.getResourceID(), allocationId, new FlinkException("Fail allocation test exception"));
// we should free the slot and then disconnect from the TaskExecutor because we use no
// longer slots from it
assertThat(freedSlotFuture.get(), equalTo(allocationId));
assertThat(disconnectTaskExecutorFuture.get(), equalTo(jobGraph.getJobID()));
} finally {
RpcUtils.terminateRpcEndpoint(jobMaster, testingTimeout);
}
}
use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class DefaultPreferredLocationsRetrieverTest method testInputLocationsChoosesInputOfFewerLocations.
@Test
public void testInputLocationsChoosesInputOfFewerLocations() {
final TestingInputsLocationsRetriever.Builder locationRetrieverBuilder = new TestingInputsLocationsRetriever.Builder();
final ExecutionVertexID consumerId = new ExecutionVertexID(new JobVertexID(), 0);
int parallelism1 = 3;
final JobVertexID jobVertexId1 = new JobVertexID();
final List<ExecutionVertexID> producers1 = new ArrayList<>(parallelism1);
for (int i = 0; i < parallelism1; i++) {
final ExecutionVertexID producerId = new ExecutionVertexID(jobVertexId1, i);
producers1.add(producerId);
locationRetrieverBuilder.connectConsumerToProducer(consumerId, producerId);
}
final JobVertexID jobVertexId2 = new JobVertexID();
int parallelism2 = 5;
final List<ExecutionVertexID> producers2 = new ArrayList<>(parallelism2);
for (int i = 0; i < parallelism2; i++) {
final ExecutionVertexID producerId = new ExecutionVertexID(jobVertexId2, i);
producers2.add(producerId);
locationRetrieverBuilder.connectConsumerToProducer(consumerId, producerId);
}
final TestingInputsLocationsRetriever inputsLocationsRetriever = locationRetrieverBuilder.build();
final List<TaskManagerLocation> expectedLocations = new ArrayList<>(parallelism1);
for (int i = 0; i < parallelism1; i++) {
inputsLocationsRetriever.assignTaskManagerLocation(producers1.get(i));
expectedLocations.add(inputsLocationsRetriever.getTaskManagerLocation(producers1.get(i)).get().getNow(null));
}
for (int i = 0; i < parallelism2; i++) {
inputsLocationsRetriever.assignTaskManagerLocation(producers2.get(i));
}
final PreferredLocationsRetriever locationsRetriever = new DefaultPreferredLocationsRetriever(id -> Optional.empty(), inputsLocationsRetriever);
final CompletableFuture<Collection<TaskManagerLocation>> preferredLocations = locationsRetriever.getPreferredLocations(consumerId, Collections.emptySet());
assertThat(preferredLocations.getNow(null), containsInAnyOrder(expectedLocations.toArray()));
}
use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class DefaultSchedulerTest method testExceptionHistoryWithRestartableFailure.
@Test
public void testExceptionHistoryWithRestartableFailure() {
final JobGraph jobGraph = singleNonParallelJobVertexJobGraph();
final TaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
final TestingLogicalSlotBuilder logicalSlotBuilder = new TestingLogicalSlotBuilder();
logicalSlotBuilder.setTaskManagerLocation(taskManagerLocation);
executionSlotAllocatorFactory = new TestExecutionSlotAllocatorFactory(logicalSlotBuilder);
final DefaultScheduler scheduler = createSchedulerAndStartScheduling(jobGraph);
// initiate restartable failure
final ArchivedExecutionVertex taskFailureExecutionVertex = Iterables.getOnlyElement(scheduler.requestJob().getArchivedExecutionGraph().getAllExecutionVertices());
final RuntimeException restartableException = new RuntimeException("restartable exception");
final long updateStateTriggeringRestartTimestamp = initiateFailure(scheduler, taskFailureExecutionVertex.getCurrentExecutionAttempt().getAttemptId(), restartableException);
taskRestartExecutor.triggerNonPeriodicScheduledTask();
// initiate job failure
testRestartBackoffTimeStrategy.setCanRestart(false);
final ExecutionAttemptID failingAttemptId = Iterables.getOnlyElement(scheduler.requestJob().getArchivedExecutionGraph().getAllExecutionVertices()).getCurrentExecutionAttempt().getAttemptId();
final RuntimeException failingException = new RuntimeException("failing exception");
final long updateStateTriggeringJobFailureTimestamp = initiateFailure(scheduler, failingAttemptId, failingException);
final Iterable<RootExceptionHistoryEntry> actualExceptionHistory = scheduler.getExceptionHistory();
// assert restarted attempt
assertThat(actualExceptionHistory, IsIterableContainingInOrder.contains(ExceptionHistoryEntryMatcher.matchesFailure(restartableException, updateStateTriggeringRestartTimestamp, taskFailureExecutionVertex.getTaskNameWithSubtaskIndex(), taskFailureExecutionVertex.getCurrentAssignedResourceLocation()), ExceptionHistoryEntryMatcher.matchesGlobalFailure(failingException, updateStateTriggeringJobFailureTimestamp)));
}
use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.
the class JobExceptionsHandlerTest method testArchivedTaskManagerLocationHandling.
@Test
public void testArchivedTaskManagerLocationHandling() {
final TaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
assertThat(JobExceptionsHandler.toString(taskManagerLocation), is(String.format("%s:%s", taskManagerLocation.getFQDNHostname(), taskManagerLocation.dataPort())));
}
Aggregations