Search in sources :

Example 36 with DefaultScheduler

use of org.apache.flink.runtime.scheduler.DefaultScheduler in project flink by apache.

the class OperatorCoordinatorSchedulerTest method setupTestJobAndScheduler.

private DefaultScheduler setupTestJobAndScheduler(OperatorCoordinator.Provider provider, @Nullable TaskExecutorOperatorEventGateway taskExecutorOperatorEventGateway, @Nullable Consumer<JobGraph> jobGraphPreProcessing, boolean restartAllOnFailover) throws Exception {
    final OperatorIDPair opIds = OperatorIDPair.of(new OperatorID(), provider.getOperatorId());
    final JobVertex vertex = new JobVertex("Vertex with OperatorCoordinator", testVertexId, Collections.singletonList(opIds));
    vertex.setInvokableClass(NoOpInvokable.class);
    vertex.addOperatorCoordinator(new SerializedValue<>(provider));
    vertex.setParallelism(2);
    final JobGraph jobGraph = JobGraphBuilder.newStreamingJobGraphBuilder().addJobVertex(vertex).build();
    SchedulerTestingUtils.enableCheckpointing(jobGraph);
    if (jobGraphPreProcessing != null) {
        jobGraphPreProcessing.accept(jobGraph);
    }
    final ComponentMainThreadExecutor mainThreadExecutor = new ComponentMainThreadExecutorServiceAdapter((ScheduledExecutorService) executor, Thread.currentThread());
    final SchedulerTestingUtils.DefaultSchedulerBuilder schedulerBuilder = taskExecutorOperatorEventGateway == null ? SchedulerTestingUtils.createSchedulerBuilder(jobGraph, mainThreadExecutor) : SchedulerTestingUtils.createSchedulerBuilder(jobGraph, mainThreadExecutor, taskExecutorOperatorEventGateway);
    if (restartAllOnFailover) {
        schedulerBuilder.setFailoverStrategyFactory(new RestartAllFailoverStrategy.Factory());
    }
    final DefaultScheduler scheduler = schedulerBuilder.setFutureExecutor(executor).setDelayExecutor(executor).build();
    this.createdScheduler = scheduler;
    return scheduler;
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) ComponentMainThreadExecutor(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor) RestartAllFailoverStrategy(org.apache.flink.runtime.executiongraph.failover.flip1.RestartAllFailoverStrategy) ComponentMainThreadExecutorServiceAdapter(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) SchedulerTestingUtils(org.apache.flink.runtime.scheduler.SchedulerTestingUtils) DefaultScheduler(org.apache.flink.runtime.scheduler.DefaultScheduler) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair)

Example 37 with DefaultScheduler

use of org.apache.flink.runtime.scheduler.DefaultScheduler in project flink by apache.

the class OperatorCoordinatorSchedulerTest method getCoordinator.

private TestingOperatorCoordinator getCoordinator(DefaultScheduler scheduler) {
    final ExecutionJobVertex vertexWithCoordinator = getJobVertex(scheduler, testVertexId);
    assertNotNull("vertex for coordinator not found", vertexWithCoordinator);
    final Optional<OperatorCoordinatorHolder> coordinatorOptional = vertexWithCoordinator.getOperatorCoordinators().stream().filter((holder) -> holder.operatorId().equals(testOperatorId)).findFirst();
    assertTrue("vertex does not contain coordinator", coordinatorOptional.isPresent());
    final OperatorCoordinator coordinator = coordinatorOptional.get().coordinator();
    assertThat(coordinator, instanceOf(TestingOperatorCoordinator.class));
    return (TestingOperatorCoordinator) coordinator;
}
Also used : ComponentMainThreadExecutorServiceAdapter(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter) CheckpointCoordinator(org.apache.flink.runtime.checkpoint.CheckpointCoordinator) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) Matchers.not(org.hamcrest.Matchers.not) ExceptionUtils(org.apache.flink.util.ExceptionUtils) Random(java.util.Random) DefaultScheduler(org.apache.flink.runtime.scheduler.DefaultScheduler) Assert.assertThat(org.junit.Assert.assertThat) StateBackend(org.apache.flink.runtime.state.StateBackend) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) TestingCheckpointStorageAccessCoordinatorView(org.apache.flink.runtime.state.TestingCheckpointStorageAccessCoordinatorView) After(org.junit.After) Duration(java.time.Duration) TestLogger(org.apache.flink.util.TestLogger) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) Checkpoints(org.apache.flink.runtime.checkpoint.Checkpoints) Assert.fail(org.junit.Assert.fail) CompletedCheckpoint(org.apache.flink.runtime.checkpoint.CompletedCheckpoint) FlinkMatchers.futureFailedWith(org.apache.flink.core.testutils.FlinkMatchers.futureFailedWith) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) Collection(java.util.Collection) ExecutionVertexID(org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID) CommonTestUtils(org.apache.flink.core.testutils.CommonTestUtils) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) MetricGroup(org.apache.flink.metrics.MetricGroup) TtlTimeProvider(org.apache.flink.runtime.state.ttl.TtlTimeProvider) SerializedValue(org.apache.flink.util.SerializedValue) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Optional(java.util.Optional) RestartAllFailoverStrategy(org.apache.flink.runtime.executiongraph.failover.flip1.RestartAllFailoverStrategy) SchedulerTestingUtils(org.apache.flink.runtime.scheduler.SchedulerTestingUtils) Environment(org.apache.flink.runtime.execution.Environment) FlinkException(org.apache.flink.util.FlinkException) ComponentMainThreadExecutor(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ManuallyTriggeredScheduledExecutorService(org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService) CompletableFuture(java.util.concurrent.CompletableFuture) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) Assert.assertSame(org.junit.Assert.assertSame) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FlinkMatchers.futureWillCompleteExceptionally(org.apache.flink.core.testutils.FlinkMatchers.futureWillCompleteExceptionally) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) TaskExecutorOperatorEventGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorOperatorEventGateway) Nonnull(javax.annotation.Nonnull) CheckpointableKeyedStateBackend(org.apache.flink.runtime.state.CheckpointableKeyedStateBackend) Nullable(javax.annotation.Nullable) SchedulerTestingUtils.setExecutionToState(org.apache.flink.runtime.scheduler.SchedulerTestingUtils.setExecutionToState) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) Matchers.empty(org.hamcrest.Matchers.empty) JobGraphBuilder(org.apache.flink.runtime.jobgraph.JobGraphBuilder) Assert.assertNotNull(org.junit.Assert.assertNotNull) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) Consumer(java.util.function.Consumer) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) JobID(org.apache.flink.api.common.JobID) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) Matcher(org.hamcrest.Matcher) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) NoOpInvokable(org.apache.flink.runtime.testtasks.NoOpInvokable) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex)

Example 38 with DefaultScheduler

use of org.apache.flink.runtime.scheduler.DefaultScheduler in project flink by apache.

the class OperatorCoordinatorSchedulerTest method createSchedulerWithAllRestartOnFailureAndDeployTasks.

private DefaultScheduler createSchedulerWithAllRestartOnFailureAndDeployTasks() throws Exception {
    final DefaultScheduler scheduler = setupTestJobAndScheduler(new TestingOperatorCoordinator.Provider(testOperatorId), null, null, true);
    scheduleAllTasksToRunning(scheduler);
    return scheduler;
}
Also used : DefaultScheduler(org.apache.flink.runtime.scheduler.DefaultScheduler)

Example 39 with DefaultScheduler

use of org.apache.flink.runtime.scheduler.DefaultScheduler in project flink by apache.

the class OperatorCoordinatorSchedulerTest method testConfirmCheckpointComplete.

@Test
public void testConfirmCheckpointComplete() throws Exception {
    final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
    final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
    final long checkpointId = takeCompleteCheckpoint(scheduler, coordinator, new byte[] { 37, 11, 83, 4 });
    assertEquals("coordinator should be notified of completed checkpoint", checkpointId, coordinator.getLastCheckpointComplete());
}
Also used : DefaultScheduler(org.apache.flink.runtime.scheduler.DefaultScheduler) Test(org.junit.Test)

Example 40 with DefaultScheduler

use of org.apache.flink.runtime.scheduler.DefaultScheduler in project flink by apache.

the class OperatorCoordinatorSchedulerTest method runningTaskFailureNotifiesCoordinator.

@Test
public void runningTaskFailureNotifiesCoordinator() throws Exception {
    final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
    final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
    failTask(scheduler, 1);
    assertEquals(1, coordinator.getFailedTasks().size());
    assertThat(coordinator.getFailedTasks(), contains(1));
    assertThat(coordinator.getFailedTasks(), not(contains(0)));
}
Also used : DefaultScheduler(org.apache.flink.runtime.scheduler.DefaultScheduler) Test(org.junit.Test)

Aggregations

DefaultScheduler (org.apache.flink.runtime.scheduler.DefaultScheduler)45 Test (org.junit.Test)34 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)9 TtlTimeProvider (org.apache.flink.runtime.state.ttl.TtlTimeProvider)9 JobID (org.apache.flink.api.common.JobID)7 IOException (java.io.IOException)5 Random (java.util.Random)5 ComponentMainThreadExecutor (org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor)5 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)5 Ignore (org.junit.Ignore)5 OperatorIDPair (org.apache.flink.runtime.OperatorIDPair)4 CompletedCheckpoint (org.apache.flink.runtime.checkpoint.CompletedCheckpoint)4 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)4 ComponentMainThreadExecutorServiceAdapter (org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter)4 ExecutionJobVertex (org.apache.flink.runtime.executiongraph.ExecutionJobVertex)4 RestartAllFailoverStrategy (org.apache.flink.runtime.executiongraph.failover.flip1.RestartAllFailoverStrategy)4 SchedulerTestingUtils (org.apache.flink.runtime.scheduler.SchedulerTestingUtils)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Duration (java.time.Duration)3