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);
}
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);
}
}
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."));
}
}
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));
}
}
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());
}
}
Aggregations