Search in sources :

Example 6 with JobManagerRunner

use of org.apache.flink.runtime.jobmaster.JobManagerRunner in project flink by apache.

the class MiniClusterJobDispatcher method startJobRunners.

private JobManagerRunner[] startJobRunners(JobGraph job, OnCompletionActions onCompletion, FatalErrorHandler errorHandler) throws JobExecutionException {
    LOG.info("Starting {} JobMaster(s) for job {} ({})", numJobManagers, job.getName(), job.getJobID());
    // start all JobManagers
    JobManagerRunner[] runners = new JobManagerRunner[numJobManagers];
    for (int i = 0; i < numJobManagers; i++) {
        try {
            runners[i] = new JobManagerRunner(ResourceID.generate(), job, configuration, rpcServices[i], haServices, heartbeatServices, jobManagerServices, metricRegistry, onCompletion, errorHandler);
            runners[i].start();
        } catch (Throwable t) {
            // shut down all the ones so far
            for (int k = 0; k <= i; k++) {
                try {
                    if (runners[i] != null) {
                        runners[i].shutdown();
                    }
                } catch (Throwable ignored) {
                // silent shutdown
                }
            }
            // un-register the job from the high.availability services
            try {
                haServices.getRunningJobsRegistry().setJobFinished(job.getJobID());
            } catch (Throwable tt) {
                LOG.warn("Could not properly unregister job from high-availability services", tt);
            }
            throw new JobExecutionException(job.getJobID(), "Could not start the JobManager(s) for the job", t);
        }
    }
    return runners;
}
Also used : JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner)

Example 7 with JobManagerRunner

use of org.apache.flink.runtime.jobmaster.JobManagerRunner in project flink by apache.

the class DefaultJobManagerRunnerRegistryTest method testGet.

@Test
public void testGet() {
    final JobID jobId = new JobID();
    final JobManagerRunner jobManagerRunner = TestingJobManagerRunner.newBuilder().setJobId(jobId).build();
    testInstance.register(jobManagerRunner);
    assertThat(testInstance.get(jobId)).isEqualTo(jobManagerRunner);
}
Also used : JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) JobID(org.apache.flink.api.common.JobID) Test(org.junit.jupiter.api.Test)

Example 8 with JobManagerRunner

use of org.apache.flink.runtime.jobmaster.JobManagerRunner in project flink by apache.

the class DefaultJobManagerRunnerRegistryTest method testGetJobManagerRunners.

@Test
public void testGetJobManagerRunners() {
    assertThat(testInstance.getJobManagerRunners()).isEmpty();
    final JobManagerRunner jobManagerRunner0 = TestingJobManagerRunner.newBuilder().build();
    final JobManagerRunner jobManagerRunner1 = TestingJobManagerRunner.newBuilder().build();
    testInstance.register(jobManagerRunner0);
    testInstance.register(jobManagerRunner1);
    assertThat(testInstance.getJobManagerRunners()).containsExactlyInAnyOrder(jobManagerRunner0, jobManagerRunner1);
}
Also used : JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) Test(org.junit.jupiter.api.Test)

Example 9 with JobManagerRunner

use of org.apache.flink.runtime.jobmaster.JobManagerRunner in project flink by apache.

the class Dispatcher method cancelJob.

@Override
public CompletableFuture<Acknowledge> cancelJob(JobID jobId, Time timeout) {
    Optional<JobManagerRunner> maybeJob = getJobManagerRunner(jobId);
    if (maybeJob.isPresent()) {
        return maybeJob.get().cancel(timeout);
    }
    final ExecutionGraphInfo executionGraphInfo = executionGraphInfoStore.get(jobId);
    if (executionGraphInfo != null) {
        final JobStatus jobStatus = executionGraphInfo.getArchivedExecutionGraph().getState();
        if (jobStatus == JobStatus.CANCELED) {
            return CompletableFuture.completedFuture(Acknowledge.get());
        } else {
            return FutureUtils.completedExceptionally(new FlinkJobTerminatedWithoutCancellationException(jobId, jobStatus));
        }
    }
    log.debug("Dispatcher is unable to cancel job {}: not found", jobId);
    return FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId));
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) FlinkJobTerminatedWithoutCancellationException(org.apache.flink.runtime.messages.FlinkJobTerminatedWithoutCancellationException) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner)

Example 10 with JobManagerRunner

use of org.apache.flink.runtime.jobmaster.JobManagerRunner in project flink by apache.

the class Dispatcher method queryJobMastersForInformation.

@Nonnull
private <T> List<CompletableFuture<Optional<T>>> queryJobMastersForInformation(Function<JobManagerRunner, CompletableFuture<T>> queryFunction) {
    List<CompletableFuture<Optional<T>>> optionalJobInformation = new ArrayList<>(jobManagerRunnerRegistry.size());
    for (JobManagerRunner job : jobManagerRunnerRegistry.getJobManagerRunners()) {
        final CompletableFuture<Optional<T>> queryResult = queryFunction.apply(job).handle((T value, Throwable t) -> Optional.ofNullable(value));
        optionalJobInformation.add(queryResult);
    }
    return optionalJobInformation;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) ArrayList(java.util.ArrayList) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner) Nonnull(javax.annotation.Nonnull)

Aggregations

JobManagerRunner (org.apache.flink.runtime.jobmaster.JobManagerRunner)11 Optional (java.util.Optional)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 JobID (org.apache.flink.api.common.JobID)4 JobStatus (org.apache.flink.api.common.JobStatus)4 Collections (java.util.Collections)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 ForkJoinPool (java.util.concurrent.ForkJoinPool)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Nonnull (javax.annotation.Nonnull)2