Search in sources :

Example 1 with FlinkJobNotFoundException

use of org.apache.flink.runtime.messages.FlinkJobNotFoundException in project flink by apache.

the class ApplicationDispatcherBootstrapTest method testDuplicateJobSubmissionWithTerminatedJobIdWithUnknownResult.

/**
 * In this scenario, job result is no longer present in the {@link
 * org.apache.flink.runtime.dispatcher.Dispatcher dispatcher} (job has terminated and job
 * manager failed over), but we know that job has already terminated from {@link
 * org.apache.flink.runtime.highavailability.JobResultStore}.
 */
@Test
public void testDuplicateJobSubmissionWithTerminatedJobIdWithUnknownResult() throws Throwable {
    final JobID testJobID = new JobID(0, 2);
    final Configuration configurationUnderTest = getConfiguration();
    configurationUnderTest.set(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, testJobID.toHexString());
    configurationUnderTest.set(HighAvailabilityOptions.HA_MODE, HighAvailabilityMode.ZOOKEEPER.name());
    final TestingDispatcherGateway.Builder dispatcherBuilder = TestingDispatcherGateway.newBuilder().setSubmitFunction(jobGraph -> FutureUtils.completedExceptionally(DuplicateJobSubmissionException.ofGloballyTerminated(testJobID))).setRequestJobStatusFunction(jobId -> FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId))).setRequestJobResultFunction(jobId -> FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId)));
    final CompletableFuture<Void> applicationFuture = runApplication(dispatcherBuilder, configurationUnderTest, 1);
    applicationFuture.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ExceptionUtils(org.apache.flink.util.ExceptionUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) FailingJob(org.apache.flink.client.testjar.FailingJob) ScheduledExecutor(org.apache.flink.util.concurrent.ScheduledExecutor) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Optional(java.util.Optional) PackagedProgram(org.apache.flink.client.program.PackagedProgram) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlinkException(org.apache.flink.util.FlinkException) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EnumSource(org.junit.jupiter.params.provider.EnumSource) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Supplier(java.util.function.Supplier) EmbeddedExecutor(org.apache.flink.client.deployment.application.executors.EmbeddedExecutor) PipelineOptionsInternal(org.apache.flink.configuration.PipelineOptionsInternal) MultiExecuteJob(org.apache.flink.client.testjar.MultiExecuteJob) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) HighAvailabilityMode(org.apache.flink.runtime.jobmanager.HighAvailabilityMode) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Configuration(org.apache.flink.configuration.Configuration) JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) JobID(org.apache.flink.api.common.JobID) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Configuration(org.apache.flink.configuration.Configuration) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) JobID(org.apache.flink.api.common.JobID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with FlinkJobNotFoundException

use of org.apache.flink.runtime.messages.FlinkJobNotFoundException in project flink by apache.

the class KvStateHandler method requestKvStateLocation.

public KvStateLocation requestKvStateLocation(final JobID jobId, final String registrationName) throws UnknownKvStateLocation, FlinkJobNotFoundException {
    // sanity check for the correct JobID
    if (executionGraph.getJobID().equals(jobId)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Lookup key-value state for job {} with registration " + "name {}.", executionGraph.getJobID(), registrationName);
        }
        final KvStateLocationRegistry registry = executionGraph.getKvStateLocationRegistry();
        final KvStateLocation location = registry.getKvStateLocation(registrationName);
        if (location != null) {
            return location;
        } else {
            throw new UnknownKvStateLocation(registrationName);
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Request of key-value state location for unknown job {} received.", jobId);
        }
        throw new FlinkJobNotFoundException(jobId);
    }
}
Also used : UnknownKvStateLocation(org.apache.flink.runtime.query.UnknownKvStateLocation) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) KvStateLocationRegistry(org.apache.flink.runtime.query.KvStateLocationRegistry) UnknownKvStateLocation(org.apache.flink.runtime.query.UnknownKvStateLocation) KvStateLocation(org.apache.flink.runtime.query.KvStateLocation)

Example 3 with FlinkJobNotFoundException

use of org.apache.flink.runtime.messages.FlinkJobNotFoundException in project flink by apache.

the class KvStateClientProxyHandler method getKvStateLookupInfo.

/**
 * Lookup the {@link KvStateLocation} for the given job and queryable state name.
 *
 * <p>The job manager will be queried for the location only if forced or no cached location can
 * be found. There are no guarantees about
 *
 * @param jobId JobID the state instance belongs to.
 * @param queryableStateName Name under which the state instance has been published.
 * @param forceUpdate Flag to indicate whether to force a update via the lookup service.
 * @return Future holding the KvStateLocation
 */
private CompletableFuture<KvStateLocation> getKvStateLookupInfo(final JobID jobId, final String queryableStateName, final boolean forceUpdate) {
    final Tuple2<JobID, String> cacheKey = new Tuple2<>(jobId, queryableStateName);
    final CompletableFuture<KvStateLocation> cachedFuture = lookupCache.get(cacheKey);
    if (!forceUpdate && cachedFuture != null && !cachedFuture.isCompletedExceptionally()) {
        LOG.debug("Retrieving location for state={} of job={} from the cache.", queryableStateName, jobId);
        return cachedFuture;
    }
    final KvStateLocationOracle kvStateLocationOracle = proxy.getKvStateLocationOracle(jobId);
    if (kvStateLocationOracle != null) {
        LOG.debug("Retrieving location for state={} of job={} from the key-value state location oracle.", queryableStateName, jobId);
        final CompletableFuture<KvStateLocation> location = new CompletableFuture<>();
        lookupCache.put(cacheKey, location);
        kvStateLocationOracle.requestKvStateLocation(jobId, queryableStateName).whenComplete((KvStateLocation kvStateLocation, Throwable throwable) -> {
            if (throwable != null) {
                if (ExceptionUtils.stripCompletionException(throwable) instanceof FlinkJobNotFoundException) {
                    // if the jobId was wrong, remove the entry from the cache.
                    lookupCache.remove(cacheKey);
                }
                location.completeExceptionally(throwable);
            } else {
                location.complete(kvStateLocation);
            }
        });
        return location;
    } else {
        return FutureUtils.completedExceptionally(new UnknownLocationException("Could not retrieve location of state=" + queryableStateName + " of job=" + jobId + ". Potential reasons are: i) the state is not ready, or ii) the job does not exist."));
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Tuple2(org.apache.flink.api.java.tuple.Tuple2) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) UnknownLocationException(org.apache.flink.queryablestate.exceptions.UnknownLocationException) KvStateLocationOracle(org.apache.flink.runtime.jobmaster.KvStateLocationOracle) JobID(org.apache.flink.api.common.JobID) KvStateLocation(org.apache.flink.runtime.query.KvStateLocation)

Example 4 with FlinkJobNotFoundException

use of org.apache.flink.runtime.messages.FlinkJobNotFoundException in project flink by apache.

the class JobExecutionResultHandlerTest method testPropagateFlinkJobNotFoundExceptionAsRestHandlerException.

@Test
public void testPropagateFlinkJobNotFoundExceptionAsRestHandlerException() throws Exception {
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId))).build();
    try {
        jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
        fail("Expected exception not thrown");
    } catch (final ExecutionException e) {
        final Throwable cause = ExceptionUtils.stripCompletionException(e.getCause());
        assertThat(cause, instanceOf(RestHandlerException.class));
        assertThat(((RestHandlerException) cause).getHttpResponseStatus(), equalTo(HttpResponseStatus.NOT_FOUND));
    }
}
Also used : QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) Matchers.not(org.hamcrest.Matchers.not) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Assert.assertThat(org.junit.Assert.assertThat) JobResult(org.apache.flink.runtime.jobmaster.JobResult) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Test(org.junit.Test) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test)

Example 5 with FlinkJobNotFoundException

use of org.apache.flink.runtime.messages.FlinkJobNotFoundException in project flink by apache.

the class DefaultExecutionGraphCacheTest method testImmediateCacheInvalidationAfterFailure.

/**
 * Tests that a failure in requesting an AccessExecutionGraph from the gateway, will not create
 * a cache entry --> another cache request will trigger a new gateway request.
 */
@Test
public void testImmediateCacheInvalidationAfterFailure() throws Exception {
    final Time timeout = Time.milliseconds(100L);
    final Time timeToLive = Time.hours(1L);
    // let's first answer with a JobNotFoundException and then only with the correct result
    final CountingRestfulGateway restfulGateway = createCountingRestfulGateway(expectedJobId, FutureUtils.completedExceptionally(new FlinkJobNotFoundException(expectedJobId)), CompletableFuture.completedFuture(expectedExecutionGraphInfo));
    try (ExecutionGraphCache executionGraphCache = new DefaultExecutionGraphCache(timeout, timeToLive)) {
        CompletableFuture<ExecutionGraphInfo> executionGraphFuture = executionGraphCache.getExecutionGraphInfo(expectedJobId, restfulGateway);
        try {
            executionGraphFuture.get();
            fail("The execution graph future should have been completed exceptionally.");
        } catch (ExecutionException ee) {
            ee.printStackTrace();
            assertTrue(ee.getCause() instanceof FlinkException);
        }
        CompletableFuture<ExecutionGraphInfo> executionGraphFuture2 = executionGraphCache.getExecutionGraphInfo(expectedJobId, restfulGateway);
        assertEquals(expectedExecutionGraphInfo, executionGraphFuture2.get());
    }
}
Also used : ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Time(org.apache.flink.api.common.time.Time) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Aggregations

FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)12 JobID (org.apache.flink.api.common.JobID)9 CompletableFuture (java.util.concurrent.CompletableFuture)6 ExecutionException (java.util.concurrent.ExecutionException)6 JobStatus (org.apache.flink.api.common.JobStatus)5 ExceptionUtils (org.apache.flink.util.ExceptionUtils)5 Collections (java.util.Collections)4 Time (org.apache.flink.api.common.time.Time)4 JobResult (org.apache.flink.runtime.jobmaster.JobResult)4 FlinkException (org.apache.flink.util.FlinkException)4 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)4 Optional (java.util.Optional)3 CompletionException (java.util.concurrent.CompletionException)3 Configuration (org.apache.flink.configuration.Configuration)3 DuplicateJobSubmissionException (org.apache.flink.runtime.client.DuplicateJobSubmissionException)3 ApplicationStatus (org.apache.flink.runtime.clusterframework.ApplicationStatus)3 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)3 FlinkJobTerminatedWithoutCancellationException (org.apache.flink.runtime.messages.FlinkJobTerminatedWithoutCancellationException)3 ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)3 Test (org.junit.Test)3