Search in sources :

Example 21 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class ManualCheckpointITCase method testTriggeringWhenPeriodicEnabled.

@Test
public void testTriggeringWhenPeriodicEnabled() throws Exception {
    int parallelism = MINI_CLUSTER_RESOURCE.getNumberSlots();
    final int checkpointingInterval = 500;
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(parallelism);
    env.enableCheckpointing(checkpointingInterval);
    env.getCheckpointConfig().setCheckpointStorage(storageSupplier.apply(temporaryFolder.newFolder().toURI().toString()));
    env.fromSource(MockSource.continuous(parallelism).build(), WatermarkStrategy.noWatermarks(), "generator").keyBy(key -> key % parallelism).flatMap(new StatefulMapper()).addSink(new DiscardingSink<>());
    final JobClient jobClient = env.executeAsync();
    final JobID jobID = jobClient.getJobID();
    final MiniCluster miniCluster = MINI_CLUSTER_RESOURCE.getMiniCluster();
    CommonTestUtils.waitForJobStatus(jobClient, Collections.singletonList(JobStatus.RUNNING), Deadline.fromNow(Duration.ofSeconds(30)));
    CommonTestUtils.waitForAllTaskRunning(miniCluster, jobID, false);
    CommonTestUtils.waitUntilCondition(() -> queryCompletedCheckpoints(miniCluster, jobID) > 0L, Deadline.fromNow(Duration.ofSeconds(30)), checkpointingInterval / 2);
    final long numberOfPeriodicCheckpoints = queryCompletedCheckpoints(miniCluster, jobID);
    // wait for the checkpoint to be taken
    miniCluster.triggerCheckpoint(jobID).get();
    miniCluster.cancelJob(jobID).get();
    queryCompletedCheckpointsUntil(miniCluster, jobID, count -> count >= numberOfPeriodicCheckpoints + 1);
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 22 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class ManualCheckpointITCase method testTriggeringWhenPeriodicDisabled.

@Test
public void testTriggeringWhenPeriodicDisabled() throws Exception {
    int parallelism = MINI_CLUSTER_RESOURCE.getNumberSlots();
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(parallelism);
    env.getCheckpointConfig().setCheckpointStorage(storageSupplier.apply(temporaryFolder.newFolder().toURI().toString()));
    env.fromSource(MockSource.continuous(parallelism).build(), WatermarkStrategy.noWatermarks(), "generator").keyBy(key -> key % parallelism).flatMap(new StatefulMapper()).addSink(new DiscardingSink<>());
    final JobClient jobClient = env.executeAsync();
    final JobID jobID = jobClient.getJobID();
    final MiniCluster miniCluster = MINI_CLUSTER_RESOURCE.getMiniCluster();
    CommonTestUtils.waitForJobStatus(jobClient, Collections.singletonList(JobStatus.RUNNING), Deadline.fromNow(Duration.ofSeconds(30)));
    CommonTestUtils.waitForAllTaskRunning(miniCluster, jobID, false);
    // wait for the checkpoint to be taken
    miniCluster.triggerCheckpoint(jobID).get();
    miniCluster.cancelJob(jobID).get();
    queryCompletedCheckpointsUntil(miniCluster, jobID, count -> count == 1);
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 23 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class Flip6LocalStreamEnvironment method execute.

/**
	 * Executes the JobGraph of the on a mini cluster of CLusterUtil with a user
	 * specified name.
	 * 
	 * @param jobName
	 *            name of the job
	 * @return The result of the job execution, containing elapsed time and accumulators.
	 */
@Override
public JobExecutionResult execute(String jobName) throws Exception {
    // transform the streaming program into a JobGraph
    StreamGraph streamGraph = getStreamGraph();
    streamGraph.setJobName(jobName);
    // TODO - temp fix to enforce restarts due to a bug in the allocation protocol
    streamGraph.getExecutionConfig().setRestartStrategy(RestartStrategies.fixedDelayRestart(Integer.MAX_VALUE, 5));
    JobGraph jobGraph = streamGraph.getJobGraph();
    jobGraph.setAllowQueuedScheduling(true);
    Configuration configuration = new Configuration();
    configuration.addAll(jobGraph.getJobConfiguration());
    configuration.setLong(ConfigConstants.TASK_MANAGER_MEMORY_SIZE_KEY, -1L);
    // add (and override) the settings with what the user defined
    configuration.addAll(this.conf);
    MiniClusterConfiguration cfg = new MiniClusterConfiguration(configuration);
    // Currently we do not reuse slot anymore,
    // so we need to sum up the parallelism of all vertices
    int slotsCount = 0;
    for (JobVertex jobVertex : jobGraph.getVertices()) {
        slotsCount += jobVertex.getParallelism();
    }
    cfg.setNumTaskManagerSlots(slotsCount);
    if (LOG.isInfoEnabled()) {
        LOG.info("Running job on local embedded Flink mini cluster");
    }
    MiniCluster miniCluster = new MiniCluster(cfg);
    try {
        miniCluster.start();
        miniCluster.waitUntilTaskManagerRegistrationsComplete();
        return miniCluster.runJobBlocking(jobGraph);
    } finally {
        transformations.clear();
        miniCluster.shutdown();
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) MiniClusterConfiguration(org.apache.flink.runtime.minicluster.MiniClusterConfiguration) Configuration(org.apache.flink.configuration.Configuration) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) MiniClusterConfiguration(org.apache.flink.runtime.minicluster.MiniClusterConfiguration) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster)

Example 24 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class FileSinkCompactionSwitchITCase method testSwitchingCompaction.

@Test
public void testSwitchingCompaction() throws Exception {
    String path = TEMPORARY_FOLDER.newFolder().getAbsolutePath();
    String cpPath = "file://" + TEMPORARY_FOLDER.newFolder().getAbsolutePath();
    SharedReference<ConcurrentHashMap<Integer, Integer>> sendCountMap = sharedObjects.add(new ConcurrentHashMap<>());
    JobGraph jobGraph = createJobGraph(path, cpPath, isOnToOff, false, sendCountMap);
    JobGraph restoringJobGraph = createJobGraph(path, cpPath, !isOnToOff, true, sendCountMap);
    final Configuration config = new Configuration();
    config.setString(RestOptions.BIND_PORT, "18081-19000");
    final MiniClusterConfiguration cfg = new MiniClusterConfiguration.Builder().setNumTaskManagers(1).setNumSlotsPerTaskManager(4).setConfiguration(config).build();
    try (MiniCluster miniCluster = new MiniCluster(cfg)) {
        miniCluster.start();
        miniCluster.submitJob(jobGraph);
        LATCH_MAP.get(latchId).await();
        String savepointPath = miniCluster.triggerSavepoint(jobGraph.getJobID(), TEMPORARY_FOLDER.newFolder().getAbsolutePath(), true, SavepointFormatType.CANONICAL).get();
        // We wait for two successful checkpoints in sources before shutting down. This ensures
        // that the sink can commit its data.
        LATCH_MAP.put(latchId, new CountDownLatch(NUM_SOURCES * 2));
        restoringJobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(savepointPath, false));
        miniCluster.executeJobBlocking(restoringJobGraph);
    }
    checkIntegerSequenceSinkOutput(path, sendCountMap.get(), NUM_BUCKETS, NUM_SOURCES);
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) MiniClusterConfiguration(org.apache.flink.runtime.minicluster.MiniClusterConfiguration) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) DefaultRowFormatBuilder(org.apache.flink.connector.file.sink.FileSink.DefaultRowFormatBuilder) MiniClusterConfiguration(org.apache.flink.runtime.minicluster.MiniClusterConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 25 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class FileSinkMigrationITCase method executeAndTakeSavepoint.

private String executeAndTakeSavepoint(MiniClusterConfiguration cfg, JobGraph jobGraph, String savepointBasePath) throws Exception {
    try (MiniCluster miniCluster = new MiniCluster(cfg)) {
        miniCluster.start();
        CompletableFuture<JobSubmissionResult> jobSubmissionResultFuture = miniCluster.submitJob(jobGraph);
        JobID jobId = jobSubmissionResultFuture.get().getJobID();
        waitForAllTaskRunning(miniCluster, jobId, false);
        CompletableFuture<String> savepointResultFuture = miniCluster.triggerSavepoint(jobId, savepointBasePath, true, SavepointFormatType.CANONICAL);
        return savepointResultFuture.get();
    }
}
Also used : JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) JobID(org.apache.flink.api.common.JobID)

Aggregations

MiniCluster (org.apache.flink.runtime.minicluster.MiniCluster)44 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)21 Configuration (org.apache.flink.configuration.Configuration)20 Test (org.junit.Test)18 MiniClusterConfiguration (org.apache.flink.runtime.minicluster.MiniClusterConfiguration)17 JobID (org.apache.flink.api.common.JobID)14 JobResult (org.apache.flink.runtime.jobmaster.JobResult)13 Deadline (org.apache.flink.api.common.time.Deadline)9 Duration (java.time.Duration)6 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)6 Test (org.junit.jupiter.api.Test)6 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)5 JobStatus (org.apache.flink.api.common.JobStatus)4 JobClient (org.apache.flink.core.execution.JobClient)4 EmbeddedHaServicesWithLeadershipControl (org.apache.flink.runtime.highavailability.nonha.embedded.EmbeddedHaServicesWithLeadershipControl)4 TestingMiniCluster (org.apache.flink.runtime.minicluster.TestingMiniCluster)4 TestingMiniClusterConfiguration (org.apache.flink.runtime.minicluster.TestingMiniClusterConfiguration)4 File (java.io.File)3 TimeUnit (java.util.concurrent.TimeUnit)3 MiniClusterClient (org.apache.flink.client.program.MiniClusterClient)3