Search in sources :

Example 6 with MiniClusterClient

use of org.apache.flink.client.program.MiniClusterClient in project flink by apache.

the class SchedulingITCase method executeSchedulingTest.

private void executeSchedulingTest(Configuration configuration) throws Exception {
    configuration.setString(RestOptions.BIND_PORT, "0");
    final long slotIdleTimeout = 50L;
    configuration.setLong(JobManagerOptions.SLOT_IDLE_TIMEOUT, slotIdleTimeout);
    configuration.set(TaskManagerOptions.TOTAL_FLINK_MEMORY, MemorySize.parse("1g"));
    final int parallelism = 4;
    final MiniClusterConfiguration miniClusterConfiguration = new MiniClusterConfiguration.Builder().setConfiguration(configuration).setNumTaskManagers(parallelism).setNumSlotsPerTaskManager(1).build();
    try (MiniCluster miniCluster = new MiniCluster(miniClusterConfiguration)) {
        miniCluster.start();
        MiniClusterClient miniClusterClient = new MiniClusterClient(configuration, miniCluster);
        JobGraph jobGraph = createJobGraph(slotIdleTimeout << 1, parallelism);
        // wait for the submission to succeed
        JobID jobID = miniClusterClient.submitJob(jobGraph).get();
        CompletableFuture<JobResult> resultFuture = miniClusterClient.requestJobResult(jobID);
        JobResult jobResult = resultFuture.get();
        assertThat(jobResult.getSerializedThrowable().isPresent(), is(false));
    }
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobResult(org.apache.flink.runtime.jobmaster.JobResult) JobGraphBuilder(org.apache.flink.runtime.jobgraph.JobGraphBuilder) MiniClusterConfiguration(org.apache.flink.runtime.minicluster.MiniClusterConfiguration) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) MiniClusterClient(org.apache.flink.client.program.MiniClusterClient) JobID(org.apache.flink.api.common.JobID)

Example 7 with MiniClusterClient

use of org.apache.flink.client.program.MiniClusterClient in project flink by apache.

the class ClassLoaderITCase method testDisposeSavepointWithCustomKvState.

/**
 * Tests disposal of a savepoint, which contains custom user code KvState.
 */
@Test
public void testDisposeSavepointWithCustomKvState() throws Exception {
    ClusterClient<?> clusterClient = new MiniClusterClient(new Configuration(), miniClusterResource.getMiniCluster());
    Deadline deadline = new FiniteDuration(100, TimeUnit.SECONDS).fromNow();
    File checkpointDir = FOLDER.newFolder();
    File outputDir = FOLDER.newFolder();
    final PackagedProgram program = PackagedProgram.newBuilder().setJarFile(new File(CUSTOM_KV_STATE_JAR_PATH)).setArguments(new String[] { String.valueOf(parallelism), checkpointDir.toURI().toString(), "5000", outputDir.toURI().toString(), // Disable unaligned checkpoints as this test is
    "false" // triggering concurrent savepoints/checkpoints
    }).build();
    TestStreamEnvironment.setAsContext(miniClusterResource.getMiniCluster(), parallelism, Collections.singleton(new Path(CUSTOM_KV_STATE_JAR_PATH)), Collections.emptyList());
    // Execute detached
    Thread invokeThread = new Thread(() -> {
        try {
            program.invokeInteractiveModeForExecution();
        } catch (ProgramInvocationException ex) {
            if (ex.getCause() == null || !(ex.getCause() instanceof JobCancellationException)) {
                ex.printStackTrace();
            }
        }
    });
    LOG.info("Starting program invoke thread");
    invokeThread.start();
    // The job ID
    JobID jobId = null;
    LOG.info("Waiting for job status running.");
    // Wait for running job
    while (jobId == null && deadline.hasTimeLeft()) {
        Collection<JobStatusMessage> jobs = clusterClient.listJobs().get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
        for (JobStatusMessage job : jobs) {
            if (job.getJobState() == JobStatus.RUNNING) {
                jobId = job.getJobId();
                LOG.info("Job running. ID: " + jobId);
                break;
            }
        }
        // Retry if job is not available yet
        if (jobId == null) {
            Thread.sleep(100L);
        }
    }
    // Trigger savepoint
    String savepointPath = null;
    for (int i = 0; i < 20; i++) {
        LOG.info("Triggering savepoint (" + (i + 1) + "/20).");
        try {
            savepointPath = clusterClient.triggerSavepoint(jobId, null, SavepointFormatType.CANONICAL).get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
        } catch (Exception cause) {
            LOG.info("Failed to trigger savepoint. Retrying...", cause);
            // This can fail if the operators are not opened yet
            Thread.sleep(500);
        }
    }
    assertNotNull("Failed to trigger savepoint", savepointPath);
    clusterClient.disposeSavepoint(savepointPath).get();
    clusterClient.cancel(jobId).get();
    // make sure, the execution is finished to not influence other test methods
    invokeThread.join(deadline.timeLeft().toMillis());
    assertFalse("Program invoke thread still running", invokeThread.isAlive());
}
Also used : Path(org.apache.flink.core.fs.Path) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) Deadline(scala.concurrent.duration.Deadline) FiniteDuration(scala.concurrent.duration.FiniteDuration) MiniClusterClient(org.apache.flink.client.program.MiniClusterClient) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) SuccessException(org.apache.flink.test.util.SuccessException) JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) IOException(java.io.IOException) JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) PackagedProgram(org.apache.flink.client.program.PackagedProgram) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) File(java.io.File) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

MiniClusterClient (org.apache.flink.client.program.MiniClusterClient)7 JobID (org.apache.flink.api.common.JobID)5 MiniCluster (org.apache.flink.runtime.minicluster.MiniCluster)4 MiniClusterConfiguration (org.apache.flink.runtime.minicluster.MiniClusterConfiguration)4 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)2 JobGraphBuilder (org.apache.flink.runtime.jobgraph.JobGraphBuilder)2 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)2 CheckpointCoordinatorConfiguration (org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration)2 JobCheckpointingSettings (org.apache.flink.runtime.jobgraph.tasks.JobCheckpointingSettings)2 File (java.io.File)1 IOException (java.io.IOException)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 PackagedProgram (org.apache.flink.client.program.PackagedProgram)1 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)1 Configuration (org.apache.flink.configuration.Configuration)1 Path (org.apache.flink.core.fs.Path)1 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)1 JobCancellationException (org.apache.flink.runtime.client.JobCancellationException)1