You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by zh...@apache.org on 2026/03/06 02:21:58 UTC

(flink) 03/03: [FLINK-38974][runtime] Handle jobs in running applications during HA recovery

This is an automated email from the ASF dual-hosted git repository.

zhuzh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit dfd785c2b3a58af60e34a4c56890e0c1b925ec1a
Author: Yi Zhang <zh...@163.com>
AuthorDate: Wed Feb 25 14:48:20 2026 +0800

    [FLINK-38974][runtime] Handle jobs in running applications during HA recovery
---
 docs/static/generated/rest_v1_dispatcher.yml       |   8 +
 .../application/PackagedProgramApplication.java    |  22 +-
 .../application/executors/EmbeddedExecutor.java    |  73 ++-
 .../executors/EmbeddedExecutorFactory.java         |  29 +-
 .../executors/EmbeddedExecutorServiceLoader.java   |  32 +-
 .../PackagedProgramApplicationITCase.java          |  33 +-
 .../PackagedProgramApplicationTest.java            | 107 +++++
 .../webmonitor/history/HistoryServerTest.java      |   4 +-
 .../runtime/dispatcher/ApplicationBootstrap.java   |   2 +-
 .../flink/runtime/dispatcher/Dispatcher.java       | 324 +++++++++----
 .../runtime/dispatcher/DispatcherGateway.java      |   9 +
 .../cleanup/CheckpointResourcesCleanupRunner.java  |   8 +-
 .../executiongraph/ArchivedExecutionGraph.java     |  42 +-
 .../apache/flink/runtime/jobmaster/JobResult.java  |  63 ++-
 .../flink/runtime/minicluster/MiniCluster.java     |   6 +-
 .../runtime/rest/messages/job/JobDetailsInfo.java  |   5 +-
 .../rest/messages/json/JobResultDeserializer.java  |  22 +
 .../rest/messages/json/JobResultSerializer.java    |  16 +
 .../dispatcher/DispatcherCleanupITCase.java        |  11 +-
 .../dispatcher/DispatcherResourceCleanupTest.java  |  82 ++--
 .../flink/runtime/dispatcher/DispatcherTest.java   | 499 +++++++++++++++------
 .../runtime/dispatcher/TestingApplication.java     | 146 ++++++
 .../runner/DefaultDispatcherRunnerITCase.java      |   6 +-
 .../ZooKeeperDefaultDispatcherRunnerTest.java      |   5 +-
 .../runtime/testutils/TestingJobResultStore.java   |   2 +
 .../webmonitor/TestingDispatcherGateway.java       |  19 +
 26 files changed, 1237 insertions(+), 338 deletions(-)

diff --git a/docs/static/generated/rest_v1_dispatcher.yml b/docs/static/generated/rest_v1_dispatcher.yml
index 3c0c3aae4ea..e76c44fc536 100644
--- a/docs/static/generated/rest_v1_dispatcher.yml
+++ b/docs/static/generated/rest_v1_dispatcher.yml
@@ -2737,6 +2737,11 @@ components:
           type: object
           additionalProperties:
             $ref: "#/components/schemas/SerializedValueOptionalFailureObject"
+        applicationId:
+          $ref: "#/components/schemas/ApplicationID"
+        endTime:
+          type: integer
+          format: int64
         jobId:
           $ref: "#/components/schemas/JobID"
         jobName:
@@ -2748,6 +2753,9 @@ components:
           format: int64
         serializedThrowable:
           $ref: "#/components/schemas/SerializedThrowable"
+        startTime:
+          type: integer
+          format: int64
         success:
           type: boolean
     JobStatus:
diff --git a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/PackagedProgramApplication.java b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/PackagedProgramApplication.java
index 7352ec85a1e..9eb68447989 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/PackagedProgramApplication.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/PackagedProgramApplication.java
@@ -49,6 +49,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.time.Duration;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -570,8 +571,21 @@ public class PackagedProgramApplication extends AbstractApplication {
                                             .key())));
             return;
         }
-        final List<JobID> applicationJobIds =
+
+        // applicationJobIds should contain all jobs involved in the current application execution
+        // after ClientUtils.executeProgram completes, including:
+        // 1. newly submitted jobs,
+        // 2. jobs recovered from a previous execution,
+        // 3. jobs skipped because they were already in a terminal state in a previous execution.
+        // Note: This list may not include all jobs from suspendedJobIds or terminalJobIds,
+        // as the user program's execution path may differ from the previous run.
+        final List<JobID> applicationJobIds = new ArrayList<>();
+        final List<JobID> suspendedJobIds =
                 recoveredJobInfos.stream().map(JobInfo::getJobId).collect(Collectors.toList());
+        final List<JobID> terminalJobIds =
+                recoveredTerminalJobInfos.stream()
+                        .map(JobInfo::getJobId)
+                        .collect(Collectors.toList());
         try {
             if (program == null) {
                 LOG.info("Reconstructing program from descriptor {}", programDescriptor);
@@ -580,7 +594,11 @@ public class PackagedProgramApplication extends AbstractApplication {
 
             final PipelineExecutorServiceLoader executorServiceLoader =
                     new EmbeddedExecutorServiceLoader(
-                            applicationJobIds, dispatcherGateway, scheduledExecutor);
+                            applicationJobIds,
+                            suspendedJobIds,
+                            terminalJobIds,
+                            dispatcherGateway,
+                            scheduledExecutor);
 
             ClientUtils.executeProgram(
                     executorServiceLoader,
diff --git a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutor.java b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutor.java
index b2a1db2ad3c..9adebbb4d72 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutor.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutor.java
@@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory;
 import java.net.InetSocketAddress;
 import java.time.Duration;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
@@ -69,7 +70,11 @@ public class EmbeddedExecutor implements PipelineExecutor {
 
     public static final String NAME = "embedded";
 
-    private final Collection<JobID> submittedJobIds;
+    private final Collection<JobID> applicationJobIds;
+
+    private final Collection<JobID> suspendedJobIds;
+
+    private final Collection<JobID> terminalJobIds;
 
     private final DispatcherGateway dispatcherGateway;
 
@@ -93,7 +98,41 @@ public class EmbeddedExecutor implements PipelineExecutor {
             final DispatcherGateway dispatcherGateway,
             final Configuration configuration,
             final EmbeddedJobClientCreator jobClientCreator) {
-        this.submittedJobIds = checkNotNull(submittedJobIds);
+        this(
+                submittedJobIds,
+                Collections.emptyList(),
+                Collections.emptyList(),
+                dispatcherGateway,
+                configuration,
+                jobClientCreator);
+    }
+
+    /**
+     * Creates a {@link EmbeddedExecutor}.
+     *
+     * @param applicationJobIds a list that is going to be filled by the {@link EmbeddedExecutor}
+     *     with job ids of all jobs that are part of the current application execution. This is
+     *     essentially used to return the job ids to the caller.
+     * @param suspendedJobIds ids of jobs that are suspended from a previous application execution,
+     *     which are not supposed to be modified by the {@link EmbeddedExecutor}.
+     * @param terminalJobIds ids of jobs that are already in a terminal state in a previous
+     *     application execution, which are not supposed to be modified by the {@link
+     *     EmbeddedExecutor}.
+     * @param dispatcherGateway the dispatcher of the cluster which is going to be used to submit
+     *     jobs.
+     * @param configuration the flink application configuration
+     * @param jobClientCreator the job client creator
+     */
+    public EmbeddedExecutor(
+            final Collection<JobID> applicationJobIds,
+            final Collection<JobID> suspendedJobIds,
+            final Collection<JobID> terminalJobIds,
+            final DispatcherGateway dispatcherGateway,
+            final Configuration configuration,
+            final EmbeddedJobClientCreator jobClientCreator) {
+        this.applicationJobIds = checkNotNull(applicationJobIds);
+        this.suspendedJobIds = checkNotNull(suspendedJobIds);
+        this.terminalJobIds = checkNotNull(terminalJobIds);
         this.dispatcherGateway = checkNotNull(dispatcherGateway);
         this.jobClientCreator = checkNotNull(jobClientCreator);
         this.jobStatusChangedListeners =
@@ -122,18 +161,34 @@ public class EmbeddedExecutor implements PipelineExecutor {
 
         // Skip resubmission if the job is recovered via HA.
         // When optJobId is present, the streamGraph's ID is deterministically derived from it. In
-        // this case, if the streamGraph's ID is in submittedJobIds, it means the job was submitted
-        // in a previous run and should not be resubmitted.
-        if (optJobId.isPresent() && submittedJobIds.contains(streamGraph.getJobID())) {
-            return getJobClientFuture(streamGraph.getJobID(), userCodeClassloader);
+        // this case, if the streamGraph's ID is in terminalJobIds or submittedJobIds, it means the
+        // job was submitted in a previous run and should not be resubmitted.
+        if (optJobId.isPresent()) {
+            final JobID actualJobId = streamGraph.getJobID();
+            if (terminalJobIds.contains(actualJobId)) {
+                LOG.info("Job {} reached a terminal state in a previous execution.", actualJobId);
+                return addJobAndGetJobClientFuture(actualJobId, userCodeClassloader);
+            }
+
+            if (suspendedJobIds.contains(actualJobId)) {
+                final Duration timeout = configuration.get(ClientOptions.CLIENT_TIMEOUT);
+                return dispatcherGateway
+                        .recoverJob(actualJobId, timeout)
+                        .thenCompose(
+                                ack -> {
+                                    LOG.info("Job {} is recovered successfully.", actualJobId);
+                                    return addJobAndGetJobClientFuture(
+                                            actualJobId, userCodeClassloader);
+                                });
+            }
         }
 
         return submitAndGetJobClientFuture(pipeline, configuration, userCodeClassloader);
     }
 
-    private CompletableFuture<JobClient> getJobClientFuture(
+    private CompletableFuture<JobClient> addJobAndGetJobClientFuture(
             final JobID jobId, final ClassLoader userCodeClassloader) {
-        LOG.info("Job {} was recovered successfully.", jobId);
+        applicationJobIds.add(jobId);
         return CompletableFuture.completedFuture(
                 jobClientCreator.getJobClient(jobId, userCodeClassloader));
     }
@@ -149,7 +204,7 @@ public class EmbeddedExecutor implements PipelineExecutor {
                 PipelineExecutorUtils.getStreamGraph(pipeline, configuration);
         final JobID actualJobId = streamGraph.getJobID();
 
-        this.submittedJobIds.add(actualJobId);
+        this.applicationJobIds.add(actualJobId);
         LOG.info("Job {} is submitted.", actualJobId);
 
         if (LOG.isDebugEnabled()) {
diff --git a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutorFactory.java b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutorFactory.java
index 15c11cae270..0841bb16885 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutorFactory.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutorFactory.java
@@ -37,7 +37,11 @@ import static org.apache.flink.util.Preconditions.checkNotNull;
 @Internal
 public class EmbeddedExecutorFactory implements PipelineExecutorFactory {
 
-    private final Collection<JobID> submittedJobIds;
+    private final Collection<JobID> applicationJobIds;
+
+    private final Collection<JobID> suspendedJobIds;
+
+    private final Collection<JobID> terminalJobIds;
 
     private final DispatcherGateway dispatcherGateway;
 
@@ -46,17 +50,26 @@ public class EmbeddedExecutorFactory implements PipelineExecutorFactory {
     /**
      * Creates an {@link EmbeddedExecutorFactory}.
      *
-     * @param submittedJobIds a list that is going to be filled with the job ids of the new jobs
-     *     that will be submitted. This is essentially used to return the submitted job ids to the
-     *     caller.
+     * @param applicationJobIds a list that is going to be filled by the {@link EmbeddedExecutor}
+     *     with job ids of all jobs that are part of the current application execution. This is
+     *     essentially used to return the job ids to the caller.
+     * @param suspendedJobIds ids of jobs that are suspended from a previous application execution,
+     *     which are not supposed to be modified by the {@link EmbeddedExecutor}.
+     * @param terminalJobIds ids of jobs that are already in a terminal state in a previous
+     *     application execution, which are not supposed to be modified by the {@link
+     *     EmbeddedExecutor}.
      * @param dispatcherGateway the dispatcher of the cluster which is going to be used to submit
      *     jobs.
      */
     public EmbeddedExecutorFactory(
-            final Collection<JobID> submittedJobIds,
+            final Collection<JobID> applicationJobIds,
+            final Collection<JobID> suspendedJobIds,
+            final Collection<JobID> terminalJobIds,
             final DispatcherGateway dispatcherGateway,
             final ScheduledExecutor retryExecutor) {
-        this.submittedJobIds = checkNotNull(submittedJobIds);
+        this.applicationJobIds = checkNotNull(applicationJobIds);
+        this.suspendedJobIds = checkNotNull(suspendedJobIds);
+        this.terminalJobIds = checkNotNull(terminalJobIds);
         this.dispatcherGateway = checkNotNull(dispatcherGateway);
         this.retryExecutor = checkNotNull(retryExecutor);
     }
@@ -77,7 +90,9 @@ public class EmbeddedExecutorFactory implements PipelineExecutorFactory {
     public PipelineExecutor getExecutor(final Configuration configuration) {
         checkNotNull(configuration);
         return new EmbeddedExecutor(
-                submittedJobIds,
+                applicationJobIds,
+                suspendedJobIds,
+                terminalJobIds,
                 dispatcherGateway,
                 configuration,
                 (jobId, userCodeClassloader) -> {
diff --git a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutorServiceLoader.java b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutorServiceLoader.java
index d4f17957038..94fbd39d71e 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutorServiceLoader.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/executors/EmbeddedExecutorServiceLoader.java
@@ -38,7 +38,11 @@ import static org.apache.flink.util.Preconditions.checkNotNull;
 @Internal
 public class EmbeddedExecutorServiceLoader implements PipelineExecutorServiceLoader {
 
-    private final Collection<JobID> submittedJobIds;
+    private final Collection<JobID> applicationJobIds;
+
+    private final Collection<JobID> suspendedJobIds;
+
+    private final Collection<JobID> terminalJobIds;
 
     private final DispatcherGateway dispatcherGateway;
 
@@ -47,24 +51,38 @@ public class EmbeddedExecutorServiceLoader implements PipelineExecutorServiceLoa
     /**
      * Creates an {@link EmbeddedExecutorServiceLoader}.
      *
-     * @param submittedJobIds a list that is going to be filled by the {@link EmbeddedExecutor} with
-     *     the job ids of the new jobs that will be submitted. This is essentially used to return
-     *     the submitted job ids to the caller.
+     * @param applicationJobIds a list that is going to be filled by the {@link EmbeddedExecutor}
+     *     with job ids of all jobs that are part of the current application execution. This is
+     *     essentially used to return the job ids to the caller.
+     * @param suspendedJobIds ids of jobs that are suspended from a previous application execution,
+     *     which are not supposed to be modified by the {@link EmbeddedExecutor}.
+     * @param terminalJobIds ids of jobs that are already in a terminal state in a previous
+     *     application execution, which are not supposed to be modified by the {@link
+     *     EmbeddedExecutor}.
      * @param dispatcherGateway the dispatcher of the cluster which is going to be used to submit
      *     jobs.
      */
     public EmbeddedExecutorServiceLoader(
-            final Collection<JobID> submittedJobIds,
+            final Collection<JobID> applicationJobIds,
+            final Collection<JobID> suspendedJobIds,
+            final Collection<JobID> terminalJobIds,
             final DispatcherGateway dispatcherGateway,
             final ScheduledExecutor retryExecutor) {
-        this.submittedJobIds = checkNotNull(submittedJobIds);
+        this.applicationJobIds = checkNotNull(applicationJobIds);
+        this.suspendedJobIds = checkNotNull(suspendedJobIds);
+        this.terminalJobIds = checkNotNull(terminalJobIds);
         this.dispatcherGateway = checkNotNull(dispatcherGateway);
         this.retryExecutor = checkNotNull(retryExecutor);
     }
 
     @Override
     public PipelineExecutorFactory getExecutorFactory(final Configuration configuration) {
-        return new EmbeddedExecutorFactory(submittedJobIds, dispatcherGateway, retryExecutor);
+        return new EmbeddedExecutorFactory(
+                applicationJobIds,
+                suspendedJobIds,
+                terminalJobIds,
+                dispatcherGateway,
+                retryExecutor);
     }
 
     @Override
diff --git a/flink-clients/src/test/java/org/apache/flink/client/deployment/application/PackagedProgramApplicationITCase.java b/flink-clients/src/test/java/org/apache/flink/client/deployment/application/PackagedProgramApplicationITCase.java
index 03570d12095..7b119f0bf1e 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/deployment/application/PackagedProgramApplicationITCase.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/deployment/application/PackagedProgramApplicationITCase.java
@@ -18,6 +18,7 @@
 
 package org.apache.flink.client.deployment.application;
 
+import org.apache.flink.api.common.ApplicationID;
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.client.cli.ClientOptions;
@@ -27,12 +28,11 @@ import org.apache.flink.client.program.ProgramInvocationException;
 import org.apache.flink.client.testjar.BlockingJob;
 import org.apache.flink.client.testjar.ErrorHandlingSubmissionJob;
 import org.apache.flink.client.testjar.FailingJob;
+import org.apache.flink.configuration.ApplicationOptionsInternal;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.configuration.DeploymentOptions;
 import org.apache.flink.configuration.HighAvailabilityOptions;
 import org.apache.flink.configuration.PipelineOptionsInternal;
-import org.apache.flink.core.testutils.FlinkAssertions;
-import org.apache.flink.runtime.client.DuplicateJobSubmissionException;
 import org.apache.flink.runtime.dispatcher.SessionDispatcherFactory;
 import org.apache.flink.runtime.dispatcher.runner.DefaultDispatcherRunnerFactory;
 import org.apache.flink.runtime.entrypoint.component.DefaultDispatcherResourceManagerComponentFactory;
@@ -52,7 +52,6 @@ import org.apache.flink.runtime.minicluster.TestingMiniClusterConfiguration;
 import org.apache.flink.runtime.resourcemanager.StandaloneResourceManagerFactory;
 import org.apache.flink.runtime.rest.ApplicationRestEndpointFactory;
 import org.apache.flink.runtime.testutils.CommonTestUtils;
-import org.apache.flink.runtime.testutils.TestingJobResultStore;
 import org.apache.flink.testutils.TestingUtils;
 import org.apache.flink.testutils.executor.TestExecutorExtension;
 import org.apache.flink.util.ExceptionUtils;
@@ -67,7 +66,9 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.function.Supplier;
 
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_STREAMING_JOB_NAME;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
 /** Integration tests related to {@link PackagedProgramApplication}. */
 class PackagedProgramApplicationITCase {
@@ -155,22 +156,28 @@ class PackagedProgramApplicationITCase {
     void testDirtyJobResultRecoveryInApplicationMode() throws Exception {
         final Configuration configuration = new Configuration();
         final JobID jobId = new JobID();
+        final ApplicationID applicationId = new ApplicationID();
         configuration.set(HighAvailabilityOptions.HA_MODE, HighAvailabilityMode.ZOOKEEPER.name());
         configuration.set(DeploymentOptions.TARGET, EmbeddedExecutor.NAME);
         configuration.set(ClientOptions.CLIENT_RETRY_PERIOD, Duration.ofMillis(100));
         configuration.set(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, jobId.toHexString());
+        configuration.set(
+                ApplicationOptionsInternal.FIXED_APPLICATION_ID, applicationId.toHexString());
         final TestingMiniClusterConfiguration clusterConfiguration =
                 TestingMiniClusterConfiguration.newBuilder()
                         .setConfiguration(configuration)
                         .build();
 
-        // having a dirty entry in the JobResultStore should make the ApplicationDispatcherBootstrap
-        // implementation fail to submit the job
         final JobResultStore jobResultStore = new EmbeddedJobResultStore();
-        jobResultStore
-                .createDirtyResultAsync(
-                        new JobResultEntry(TestingJobResultStore.createSuccessfulJobResult(jobId)))
-                .get();
+        final JobResult jobResult =
+                new JobResult.Builder()
+                        .jobId(jobId)
+                        .applicationId(applicationId)
+                        .jobName(DEFAULT_STREAMING_JOB_NAME)
+                        .jobStatus(JobStatus.FINISHED)
+                        .netRuntime(1)
+                        .build();
+        jobResultStore.createDirtyResultAsync(new JobResultEntry(jobResult)).get();
         final EmbeddedHaServicesWithLeadershipControl haServices =
                 new EmbeddedHaServicesWithLeadershipControl(EXECUTOR_EXTENSION.getExecutor()) {
 
@@ -195,10 +202,10 @@ class PackagedProgramApplicationITCase {
             awaitClusterStopped(cluster);
         }
 
-        FlinkAssertions.assertThatChainOfCauses(ErrorHandlingSubmissionJob.getSubmissionException())
-                .as(
-                        "The job's main method shouldn't have been succeeded due to a DuplicateJobSubmissionException.")
-                .hasAtLeastOneElementOfType(DuplicateJobSubmissionException.class);
+        // submission should succeed because the EmbeddedExecutor skips resubmitting jobs that were
+        // already in a terminal state in a previous application execution and instead retrieves
+        // their JobClient directly
+        assertNull(ErrorHandlingSubmissionJob.getSubmissionException());
 
         assertThat(jobResultStore.hasDirtyJobResultEntryAsync(jobId).get()).isFalse();
         assertThat(jobResultStore.hasCleanJobResultEntryAsync(jobId).get()).isTrue();
diff --git a/flink-clients/src/test/java/org/apache/flink/client/deployment/application/PackagedProgramApplicationTest.java b/flink-clients/src/test/java/org/apache/flink/client/deployment/application/PackagedProgramApplicationTest.java
index e6e26eacdb6..4f04931b4a4 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/deployment/application/PackagedProgramApplicationTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/deployment/application/PackagedProgramApplicationTest.java
@@ -21,6 +21,8 @@ package org.apache.flink.client.deployment.application;
 import org.apache.flink.api.common.ApplicationID;
 import org.apache.flink.api.common.ApplicationState;
 import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.JobInfo;
+import org.apache.flink.api.common.JobInfoImpl;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.client.deployment.application.executors.EmbeddedExecutor;
 import org.apache.flink.client.program.PackagedProgram;
@@ -55,6 +57,9 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.EnumSource;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentLinkedDeque;
@@ -69,6 +74,7 @@ import java.util.function.BiConsumer;
 import java.util.function.Supplier;
 
 import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_STREAMING_JOB_NAME;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -1152,6 +1158,107 @@ public class PackagedProgramApplicationTest {
         assertThat(application.getExceptionHistory()).isEmpty();
     }
 
+    @Test
+    void testRecoveredTerminalJobsAreNotResubmitted() throws Exception {
+        final JobID recoveredTerminalJobId = new JobID();
+
+        final Configuration configuration = getConfiguration();
+        configuration.set(
+                PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID,
+                recoveredTerminalJobId.toHexString());
+
+        final List<JobID> submittedJobs = new ArrayList<>();
+        final List<JobID> recoveredJobs = new ArrayList<>();
+
+        final TestingDispatcherGateway.Builder dispatcherBuilder =
+                finishedJobGatewayBuilder()
+                        .setSubmitFunction(
+                                jobGraph -> {
+                                    submittedJobs.add(jobGraph.getJobID());
+                                    return CompletableFuture.completedFuture(Acknowledge.get());
+                                })
+                        .setRecoverJobFunction(
+                                jobId -> {
+                                    recoveredJobs.add(jobId);
+                                    return CompletableFuture.completedFuture(Acknowledge.get());
+                                });
+
+        // create application with a recovered terminal job
+        final JobInfo recoveredTerminalJobInfo =
+                new JobInfoImpl(recoveredTerminalJobId, DEFAULT_STREAMING_JOB_NAME);
+        final PackagedProgramApplication application =
+                new PackagedProgramApplication(
+                        new ApplicationID(),
+                        getProgram(1),
+                        Collections.emptyList(),
+                        Collections.singletonList(recoveredTerminalJobInfo),
+                        configuration,
+                        true,
+                        false,
+                        false,
+                        true);
+
+        executeApplication(
+                application, dispatcherBuilder.build(), scheduledExecutor, exception -> {});
+
+        application.getFinishApplicationFuture().get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+        assertApplicationFinished(application);
+
+        // verify that the terminal job was not submitted or recovered
+        assertThat(submittedJobs).isEmpty();
+        assertThat(recoveredJobs).isEmpty();
+    }
+
+    @Test
+    void testRecoveredRunningJobsAreRecovered() throws Exception {
+        final JobID recoveredRunningJobId = new JobID();
+
+        final Configuration configuration = getConfiguration();
+        configuration.set(
+                PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, recoveredRunningJobId.toHexString());
+
+        final List<JobID> submittedJobs = new ArrayList<>();
+        final List<JobID> recoveredJobs = new ArrayList<>();
+
+        final TestingDispatcherGateway.Builder dispatcherBuilder =
+                finishedJobGatewayBuilder()
+                        .setSubmitFunction(
+                                jobGraph -> {
+                                    submittedJobs.add(jobGraph.getJobID());
+                                    return CompletableFuture.completedFuture(Acknowledge.get());
+                                })
+                        .setRecoverJobFunction(
+                                jobId -> {
+                                    recoveredJobs.add(jobId);
+                                    return CompletableFuture.completedFuture(Acknowledge.get());
+                                });
+
+        // create application with a recovered running job
+        final JobInfo recoveredRunningJobInfo =
+                new JobInfoImpl(recoveredRunningJobId, DEFAULT_STREAMING_JOB_NAME);
+        final PackagedProgramApplication application =
+                new PackagedProgramApplication(
+                        new ApplicationID(),
+                        getProgram(1),
+                        Collections.singletonList(recoveredRunningJobInfo),
+                        Collections.emptyList(),
+                        configuration,
+                        true,
+                        false,
+                        false,
+                        true);
+
+        executeApplication(
+                application, dispatcherBuilder.build(), scheduledExecutor, exception -> {});
+
+        application.getFinishApplicationFuture().get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+        assertApplicationFinished(application);
+
+        // verify that the running job was recovered, not submitted
+        assertThat(submittedJobs).isEmpty();
+        assertThat(recoveredJobs).containsExactly(recoveredRunningJobId);
+    }
+
     private TestingDispatcherGateway.Builder finishedJobGatewayBuilder() {
         return dispatcherGatewayBuilder(JobStatus.FINISHED);
     }
diff --git a/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/history/HistoryServerTest.java b/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/history/HistoryServerTest.java
index e5045af1468..22ad693e686 100644
--- a/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/history/HistoryServerTest.java
+++ b/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/history/HistoryServerTest.java
@@ -161,7 +161,7 @@ class HistoryServerTest {
             assertThat(getJobsOverview(baseUrl).getJobs()).isEmpty();
 
             for (int x = 0; x < numJobs; x++) {
-                runJob();
+                mockJobArchive(createExecutionGraphInfo(), null);
             }
             createLegacyArchive(jmDirectory.toPath(), versionLessThan14);
             waitForArchivesCreation(numJobs + numLegacyJobs);
@@ -338,7 +338,7 @@ class HistoryServerTest {
         int numExpiredJobs = cleanupExpiredJobs ? 1 : 0;
         int numJobs = 3;
         for (int x = 0; x < numJobs; x++) {
-            runJob();
+            mockJobArchive(createExecutionGraphInfo(), null);
         }
         waitForArchivesCreation(numJobs);
 
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/ApplicationBootstrap.java b/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/ApplicationBootstrap.java
index f781dedff1e..52fac1f417d 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/ApplicationBootstrap.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/ApplicationBootstrap.java
@@ -33,7 +33,7 @@ public class ApplicationBootstrap implements DispatcherBootstrap {
 
     @Override
     public void stop() throws Exception {
-        application.cancel();
+        application.dispose();
     }
 
     public AbstractApplication getApplication() {
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java b/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java
index d7cdfb7c417..d0c0f224245 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java
@@ -113,6 +113,7 @@ import org.apache.flink.util.FlinkException;
 import org.apache.flink.util.MdcUtils;
 import org.apache.flink.util.MdcUtils.MdcCloseable;
 import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.SerializedThrowable;
 import org.apache.flink.util.SerializedValue;
 import org.apache.flink.util.concurrent.FutureUtils;
 import org.apache.flink.util.function.FunctionUtils;
@@ -184,9 +185,20 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
 
     private final OnMainThreadJobManagerRunnerRegistry jobManagerRunnerRegistry;
 
-    private final Collection<ExecutionPlan> recoveredJobs;
+    /**
+     * Map of jobs that were suspended in a previous application execution attempt, which may be
+     * recovered or deprecated in the current execution attempt.
+     */
+    private final Map<JobID, ExecutionPlan> suspendedJobs = new HashMap<>();
+
+    /**
+     * Map of jobs by application that were suspended in a previous application execution attempt,
+     * which may be recovered or deprecated in the current execution attempt.
+     */
+    private final Map<ApplicationID, Set<JobID>> suspendedJobIdsByApplicationId = new HashMap<>();
 
-    private final Collection<JobResult> recoveredDirtyJobs;
+    private final Map<ApplicationID, Collection<JobResult>>
+            recoveredDirtyJobResultsByApplicationId = new HashMap<>();
 
     private final DispatcherBootstrapFactory dispatcherBootstrapFactory;
 
@@ -230,15 +242,15 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
 
     private final Map<ApplicationID, AbstractApplication> applications = new HashMap<>();
 
-    private final Map<ApplicationID, Set<JobID>> recoveredApplicationJobIds = new HashMap<>();
-
     /** ExecutionGraphInfo for the terminated job whose application is not terminated yet. */
     private final Map<JobID, CompletableFuture<ExecutionGraphInfo>> partialExecutionGraphInfoStore =
             new HashMap<>();
 
-    private final Map<ApplicationID, CompletableFuture<?>> applicationArchivingFutures =
+    private final Map<ApplicationID, CompletableFuture<?>> applicationTerminationFutures =
             new HashMap<>();
 
+    private final Map<JobID, ApplicationID> jobIdsToApplicationIds = new HashMap<>();
+
     /** Enum to distinguish between initial job submission and re-submission for recovery. */
     protected enum ExecutionType {
         SUBMISSION,
@@ -335,9 +347,33 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
 
         this.dispatcherBootstrapFactory = checkNotNull(dispatcherBootstrapFactory);
 
-        this.recoveredJobs = new HashSet<>(recoveredJobs);
+        for (ExecutionPlan executionPlan : recoveredJobs) {
+            final JobID jobId = executionPlan.getJobID();
+            final ApplicationID applicationId =
+                    executionPlan
+                            .getApplicationId()
+                            .orElseThrow(
+                                    () ->
+                                            new IllegalStateException(
+                                                    "Application ID is missing in the recovered execution plan. This suggests the job was submitted through an unsupported or incomplete path."));
+            this.suspendedJobs.put(jobId, executionPlan);
+            this.suspendedJobIdsByApplicationId
+                    .computeIfAbsent(applicationId, ignored -> new HashSet<>())
+                    .add(jobId);
+        }
 
-        this.recoveredDirtyJobs = new HashSet<>(recoveredDirtyJobs);
+        for (JobResult jobResult : recoveredDirtyJobs) {
+            final ApplicationID applicationId =
+                    jobResult
+                            .getApplicationId()
+                            .orElseThrow(
+                                    () ->
+                                            new IllegalStateException(
+                                                    "Application ID is missing in the recovered job result. This suggests the job was submitted through an unsupported or incomplete path."));
+            this.recoveredDirtyJobResultsByApplicationId
+                    .computeIfAbsent(applicationId, ignored -> new ArrayList<>())
+                    .add(jobResult);
+        }
 
         this.blobServer.retainJobs(
                 recoveredJobs.stream().map(ExecutionPlan::getJobID).collect(Collectors.toSet()),
@@ -385,8 +421,6 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
             throw exception;
         }
 
-        startCleanupRetries();
-
         this.dispatcherBootstrap =
                 this.dispatcherBootstrapFactory.create(
                         getSelfGateway(DispatcherGateway.class),
@@ -394,11 +428,23 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
                         this::onFatalError);
 
         if (dispatcherBootstrap instanceof ApplicationBootstrap) {
-            startRecoveredJobs(false);
+            // defer starting recovered jobs, as they might be skipped based on user logic
             internalSubmitApplication(((ApplicationBootstrap) dispatcherBootstrap).getApplication())
                     .get();
         } else {
-            startRecoveredJobs(true);
+            // Jobs cannot be associated with applications because applications do not yet exist
+            // during recovery. This is a temporary workaround and will be removed once application
+            // recovery is supported.
+            recoveredDirtyJobResultsByApplicationId.values().stream()
+                    .flatMap(Collection::stream)
+                    .forEach(jobResult -> runJobWithCleanupRunner(jobResult, false));
+
+            // start recovered jobs by wrapping them into a SingleJobApplication
+            for (ExecutionPlan recoveredJob : suspendedJobs.values()) {
+                runRecoveredJob(recoveredJob, true);
+            }
+            suspendedJobs.clear();
+            suspendedJobIdsByApplicationId.clear();
         }
     }
 
@@ -434,13 +480,6 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
                 "There should be no overlap between the recovered ExecutionPlans and the passed dirty JobResults based on their job ID.");
     }
 
-    private void startRecoveredJobs(boolean wrapIntoApplication) {
-        for (ExecutionPlan recoveredJob : recoveredJobs) {
-            runRecoveredJob(recoveredJob, wrapIntoApplication);
-        }
-        recoveredJobs.clear();
-    }
-
     /**
      * Runs a recovered job in HA mode.
      *
@@ -461,25 +500,19 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
 
         initJobClientExpiredTime(recoveredJob);
 
-        try (MdcCloseable ignored =
-                MdcUtils.withContext(MdcUtils.asContextData(recoveredJob.getJobID()))) {
-            if (recoveredJob.getApplicationId().isPresent()) {
-                recoveredApplicationJobIds
-                        .computeIfAbsent(
-                                recoveredJob.getApplicationId().get(),
-                                applicationId -> new HashSet<>())
-                        .add(recoveredJob.getJobID());
-                if (wrapIntoApplication) {
-                    internalSubmitApplication(new SingleJobApplication(recoveredJob, true)).get();
-                }
+        final JobID jobId = recoveredJob.getJobID();
+        try (MdcCloseable ignored = MdcUtils.withContext(MdcUtils.asContextData(jobId))) {
+            if (wrapIntoApplication) {
+                internalSubmitApplication(new SingleJobApplication(recoveredJob, true)).get();
             }
-            runJob(createJobMasterRunner(recoveredJob), ExecutionType.RECOVERY);
+            runJob(
+                    createJobMasterRunner(recoveredJob),
+                    ExecutionType.RECOVERY,
+                    recoveredJob.getApplicationId().orElse(null));
         } catch (Throwable throwable) {
             onFatalError(
                     new DispatcherException(
-                            String.format(
-                                    "Could not start recovered job %s.", recoveredJob.getJobID()),
-                            throwable));
+                            String.format("Could not start recovered job %s.", jobId), throwable));
         }
     }
 
@@ -509,16 +542,19 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
         }
     }
 
-    private void startCleanupRetries() {
-        recoveredDirtyJobs.forEach(this::runCleanupRetry);
-        recoveredDirtyJobs.clear();
+    private void runJobWithCleanupRunner(final JobResult jobResult) {
+        runJobWithCleanupRunner(jobResult, true);
     }
 
-    private void runCleanupRetry(final JobResult jobResult) {
+    private void runJobWithCleanupRunner(
+            final JobResult jobResult, final boolean associateJobWithApplication) {
         checkNotNull(jobResult);
-
         try {
-            runJob(createJobCleanupRunner(jobResult), ExecutionType.RECOVERY);
+            runJob(
+                    createJobCleanupRunner(jobResult),
+                    ExecutionType.RECOVERY,
+                    jobResult.getApplicationId().orElse(null),
+                    associateJobWithApplication);
         } catch (Throwable throwable) {
             onFatalError(
                     new DispatcherException(
@@ -551,15 +587,12 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
         final CompletableFuture<Void> allJobsTerminationFuture =
                 terminateRunningJobsAndGetTerminationFuture();
 
+        terminateRunningApplications();
+
         return FutureUtils.runAfterwards(
                 allJobsTerminationFuture,
                 () -> {
                     dispatcherBootstrap.stop();
-
-                    for (AbstractApplication application : applications.values()) {
-                        application.dispose();
-                    }
-
                     stopDispatcherServices();
 
                     log.info("Stopped dispatcher {}.", getAddress());
@@ -607,7 +640,8 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
                                         DuplicateJobSubmissionException.ofGloballyTerminated(
                                                 jobID));
                             } else if (jobManagerRunnerRegistry.isRegistered(jobID)
-                                    || submittedAndWaitingTerminationJobIDs.contains(jobID)) {
+                                    || submittedAndWaitingTerminationJobIDs.contains(jobID)
+                                    || suspendedJobs.containsKey(jobID)) {
                                 // job with the given jobID is not terminated, yet
                                 return FutureUtils.completedExceptionally(
                                         DuplicateJobSubmissionException.of(jobID));
@@ -618,6 +652,13 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
                                                 "Currently jobs is not supported if parts of the vertices "
                                                         + "have resources configured. The limitation will be "
                                                         + "removed in future versions."));
+                            } else if (executionPlan.getApplicationId().isEmpty()
+                                    || !applications.containsKey(
+                                            executionPlan.getApplicationId().get())) {
+                                return FutureUtils.completedExceptionally(
+                                        new JobSubmissionException(
+                                                jobID,
+                                                "Failed to find the associated application for the job. This suggests the job is submitted through an unsupported or incomplete path."));
                             } else {
                                 return internalSubmitJob(executionPlan);
                             }
@@ -625,6 +666,36 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
                         getMainThreadExecutor(jobID));
     }
 
+    @Override
+    public CompletableFuture<Acknowledge> recoverJob(JobID jobId, Duration timeout) {
+        try (MdcCloseable ignored = MdcUtils.withContext(MdcUtils.asContextData(jobId))) {
+            log.info("Received job recovery request for job {}.", jobId);
+        }
+        final ExecutionPlan executionPlan = suspendedJobs.remove(jobId);
+        if (executionPlan == null) {
+            return FutureUtils.completedExceptionally(
+                    new JobSubmissionException(jobId, "Cannot find the recovered job."));
+        }
+
+        final ApplicationID applicationId = executionPlan.getApplicationId().orElse(null);
+        if (applicationId == null || !suspendedJobIdsByApplicationId.containsKey(applicationId)) {
+            return FutureUtils.completedExceptionally(
+                    new JobSubmissionException(
+                            jobId,
+                            "Cannot find the associated application for the recovered job."));
+        }
+
+        runRecoveredJob(executionPlan, false);
+
+        Set<JobID> jobIds = suspendedJobIdsByApplicationId.get(applicationId);
+        jobIds.remove(jobId);
+        if (jobIds.isEmpty()) {
+            suspendedJobIdsByApplicationId.remove(applicationId);
+        }
+
+        return CompletableFuture.completedFuture(Acknowledge.get());
+    }
+
     @Override
     public CompletableFuture<Acknowledge> submitFailedJob(
             JobID jobId, String jobName, Throwable exception) {
@@ -665,11 +736,18 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
         log.info("Submitting application '{}' ({}).", application.getName(), applicationId);
 
         applications.put(applicationId, application);
-        Set<JobID> jobs = recoveredApplicationJobIds.remove(applicationId);
-        if (jobs != null) {
-            jobs.forEach(application::addJob);
-        }
         application.registerStatusListener(this);
+        applicationTerminationFutures.put(applicationId, new CompletableFuture<>());
+
+        // cleanup dirty job results by creating a JobManagerRunner during application submission to
+        // ensure that the JobClient is available when the application execution skips resubmitting
+        // already-terminated jobs and retrieve the JobClient directly.
+        Collection<JobResult> dirtyJobResults =
+                recoveredDirtyJobResultsByApplicationId.remove(applicationId);
+        if (dirtyJobResults != null) {
+            dirtyJobResults.forEach(this::runJobWithCleanupRunner);
+        }
+
         return application.execute(
                 getSelfGateway(DispatcherGateway.class),
                 getRpcService().getScheduledExecutor(),
@@ -686,12 +764,35 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
                     "Application %s does not exist.",
                     applicationId);
             checkState(
-                    !applicationArchivingFutures.containsKey(applicationId),
-                    "The application (" + applicationId + ") has already been archived.");
+                    !applicationTerminationFutures.get(applicationId).isDone(),
+                    "The application (" + applicationId + ") has already terminated.");
+
+            AbstractApplication application = applications.get(applicationId);
+            Set<JobID> remainingSuspendedJobIds =
+                    suspendedJobIdsByApplicationId.remove(applicationId);
+            if (remainingSuspendedJobIds != null) {
+                for (JobID jobId : remainingSuspendedJobIds) {
+                    final ExecutionPlan executionPlan = suspendedJobs.remove(jobId);
+                    checkNotNull(executionPlan);
+
+                    final JobResult jobResult =
+                            new JobResult.Builder()
+                                    .jobId(jobId)
+                                    .jobStatus(JobStatus.FAILED)
+                                    .netRuntime(0)
+                                    .serializedThrowable(
+                                            new SerializedThrowable(
+                                                    new FlinkException(
+                                                            "Job recovery is not needed.")))
+                                    .jobName(executionPlan.getName())
+                                    .applicationId(applicationId)
+                                    .build();
+                    runJobWithCleanupRunner(jobResult);
+                }
+            }
 
             log.info(
                     "Archiving application ({}) with terminal state {}.", applicationId, newStatus);
-            AbstractApplication application = applications.get(applicationId);
             long[] stateTimestamps = new long[ApplicationState.values().length];
             for (ApplicationState applicationState : ApplicationState.values()) {
                 final int ordinal = applicationState.ordinal();
@@ -767,7 +868,10 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
                                                         });
                                     },
                                     getMainThreadExecutor());
-            applicationArchivingFutures.put(applicationId, applicationArchivingFuture);
+
+            applicationArchivingFuture.thenRunAsync(
+                    () -> applicationTerminationFutures.get(applicationId).complete(null),
+                    getMainThreadExecutor());
         }
     }
 
@@ -789,8 +893,23 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
     }
 
     @VisibleForTesting
-    CompletableFuture<?> getApplicationArchivingFuture(ApplicationID applicationId) {
-        return applicationArchivingFutures.get(applicationId);
+    CompletableFuture<?> getApplicationTerminationFuture(ApplicationID applicationId) {
+        return applicationTerminationFutures.get(applicationId);
+    }
+
+    @VisibleForTesting
+    Map<JobID, ExecutionPlan> getSuspendedJobs() {
+        return suspendedJobs;
+    }
+
+    @VisibleForTesting
+    Map<ApplicationID, Set<JobID>> getSuspendedJobIdsByApplicationId() {
+        return suspendedJobIdsByApplicationId;
+    }
+
+    @VisibleForTesting
+    Map<ApplicationID, Collection<JobResult>> getRecoveredDirtyJobResultsByApplicationId() {
+        return recoveredDirtyJobResultsByApplicationId;
     }
 
     /**
@@ -811,34 +930,24 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
 
         final JobID jobId = executionPlan.getJobID();
         final String jobName = executionPlan.getName();
+        final ApplicationID applicationId = executionPlan.getApplicationId().orElse(null);
 
-        Optional<AbstractApplication> optionalApplication = getApplicationForJob(executionPlan);
-        if (optionalApplication.isPresent()) {
-            AbstractApplication application = optionalApplication.get();
-            log.info(
-                    "Submitting job '{}' ({}) with associated application ({}).",
-                    jobName,
-                    jobId,
-                    application.getApplicationId());
-        } else {
-            // This can only occur in tests for submitJob that submit jobs without an application
-            log.warn("Submitting job '{}' ({}) without associated application.", jobName, jobId);
-        }
+        log.info(
+                "Submitting job '{}' ({}) with associated application ({}).",
+                jobName,
+                jobId,
+                applicationId);
 
         // track as an outstanding job
-        submittedAndWaitingTerminationJobIDs.add(executionPlan.getJobID());
+        submittedAndWaitingTerminationJobIDs.add(jobId);
 
-        return waitForTerminatingJob(
-                        executionPlan.getJobID(), executionPlan, this::persistAndRunJob)
-                .handle(
-                        (ignored, throwable) ->
-                                handleTermination(executionPlan.getJobID(), throwable))
+        return waitForTerminatingJob(jobId, executionPlan, this::persistAndRunJob)
+                .handle((ignored, throwable) -> handleTermination(jobId, throwable))
                 .thenCompose(Function.identity())
                 .whenComplete(
                         (ignored, throwable) ->
                                 // job is done processing, whether failed or finished
-                                submittedAndWaitingTerminationJobIDs.remove(
-                                        executionPlan.getJobID()));
+                                submittedAndWaitingTerminationJobIDs.remove(jobId));
     }
 
     private void associateJobWithApplication(JobID jobId, ApplicationID applicationId) {
@@ -846,19 +955,7 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
         checkState(applications.containsKey(applicationId));
 
         applications.get(applicationId).addJob(jobId);
-    }
-
-    private Optional<AbstractApplication> getApplicationForJob(ExecutionPlan executionPlan) {
-        return executionPlan
-                .getApplicationId()
-                .map(
-                        applicationId -> {
-                            checkState(
-                                    applications.containsKey(applicationId),
-                                    "Application %s not found.",
-                                    applicationId);
-                            return applications.get(applicationId);
-                        });
+        jobIdsToApplicationIds.put(jobId, applicationId);
     }
 
     private CompletableFuture<Acknowledge> handleTermination(
@@ -935,15 +1032,19 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
                 getIoExecutor(dirtyJobResult.getJobId()));
     }
 
-    private void runJob(JobManagerRunner jobManagerRunner, ExecutionType executionType)
+    private void runJob(
+            JobManagerRunner jobManagerRunner,
+            ExecutionType executionType,
+            ApplicationID applicationId)
             throws Exception {
-        runJob(jobManagerRunner, executionType, null);
+        runJob(jobManagerRunner, executionType, applicationId, true);
     }
 
     private void runJob(
             JobManagerRunner jobManagerRunner,
             ExecutionType executionType,
-            @Nullable ApplicationID applicationId)
+            ApplicationID applicationId,
+            boolean associateJobWithApplication)
             throws Exception {
         jobManagerRunner.start();
         jobManagerRunnerRegistry.register(jobManagerRunner);
@@ -952,7 +1053,7 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
 
         partialExecutionGraphInfoStore.put(jobId, new CompletableFuture<>());
 
-        if (applicationId != null) {
+        if (associateJobWithApplication) {
             associateJobWithApplication(jobId, applicationId);
         }
 
@@ -1552,18 +1653,22 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
     }
 
     private CompletableFuture<Acknowledge> internalShutDownCluster(
-            final ApplicationStatus applicationStatus,
-            final boolean waitForAllJobTerminationFutures) {
+            final ApplicationStatus applicationStatus, final boolean waitForAllTerminationFutures) {
         final CompletableFuture<Void> allJobsTerminationFuture =
-                waitForAllJobTerminationFutures
+                waitForAllTerminationFutures
                         ? FutureUtils.completeAll(jobManagerRunnerTerminationFutures.values())
                         : CompletableFuture.completedFuture(null);
 
+        final CompletableFuture<Void> allApplicationsTerminationFuture =
+                waitForAllTerminationFutures
+                        ? FutureUtils.completeAll(applicationTerminationFutures.values())
+                        : CompletableFuture.completedFuture(null);
+
         FutureUtils.runAfterwards(
                 allJobsTerminationFuture,
                 () ->
                         FutureUtils.runAfterwards(
-                                FutureUtils.completeAll(applicationArchivingFutures.values()),
+                                allApplicationsTerminationFuture,
                                 () -> shutDownFuture.complete(applicationStatus)));
         return CompletableFuture.completedFuture(Acknowledge.get());
     }
@@ -1744,9 +1849,21 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
 
     private CompletableFuture<Void> removeJob(JobID jobId, CleanupJobState cleanupJobState) {
         if (cleanupJobState.isGlobalCleanup()) {
+            final ApplicationID applicationId = jobIdsToApplicationIds.get(jobId);
+            final CompletableFuture<?> applicationTerminationFuture;
+            if (applicationTerminationFutures.containsKey(applicationId)) {
+                applicationTerminationFuture = applicationTerminationFutures.get(applicationId);
+            } else {
+                // This can occur during cleanup for recovered dirty job results in session mode
+                applicationTerminationFuture = CompletableFuture.completedFuture(null);
+            }
+
+            // wait for the application termination before marking the job result as clean
             return globalResourceCleaner
                     .cleanupAsync(jobId)
-                    .thenCompose(unused -> jobResultStore.markResultAsCleanAsync(jobId))
+                    .thenCombine(
+                            applicationTerminationFuture,
+                            (unused1, unused2) -> jobResultStore.markResultAsCleanAsync(jobId))
                     .handle(
                             (unusedVoid, e) -> {
                                 if (e == null) {
@@ -1801,6 +1918,19 @@ public abstract class Dispatcher extends FencedRpcEndpoint<DispatcherId>
         return FutureUtils.completeAll(values);
     }
 
+    private void terminateRunningApplications() {
+        final Set<ApplicationID> applicationsToRemove = applications.keySet();
+        log.info(
+                "Stopping all currently running applications {} of dispatcher {}.",
+                applicationsToRemove,
+                getAddress());
+
+        for (ApplicationID applicationId : applicationsToRemove) {
+            applications.get(applicationId).dispose();
+            applicationTerminationFutures.get(applicationId).cancel(false);
+        }
+    }
+
     protected void onFatalError(Throwable throwable) {
         fatalErrorHandler.onFatalError(throwable);
     }
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/DispatcherGateway.java b/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/DispatcherGateway.java
index ba1cadd495b..c6d82fb0b02 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/DispatcherGateway.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/DispatcherGateway.java
@@ -47,6 +47,15 @@ public interface DispatcherGateway extends FencedRpcGateway<DispatcherId>, Restf
     CompletableFuture<Acknowledge> submitJob(
             ExecutionPlan executionPlan, @RpcTimeout Duration timeout);
 
+    /**
+     * Recover a previously submitted job.
+     *
+     * @param jobId JobID of the job to recover
+     * @param timeout RPC timeout
+     * @return A future acknowledge if the recover succeeded
+     */
+    CompletableFuture<Acknowledge> recoverJob(JobID jobId, @RpcTimeout Duration timeout);
+
     /**
      * Submit an application to the dispatcher.
      *
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/cleanup/CheckpointResourcesCleanupRunner.java b/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/cleanup/CheckpointResourcesCleanupRunner.java
index ece9c2bb8d6..0c6b263ac14 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/cleanup/CheckpointResourcesCleanupRunner.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/cleanup/CheckpointResourcesCleanupRunner.java
@@ -220,11 +220,15 @@ public class CheckpointResourcesCleanupRunner implements JobManagerRunner {
         return new ExecutionGraphInfo(
                 ArchivedExecutionGraph.createSparseArchivedExecutionGraph(
                         jobResult.getJobId(),
-                        "unknown",
+                        jobResult.getJobName(),
                         getJobStatus(jobResult),
                         null,
                         jobResult.getSerializedThrowable().orElse(null),
                         null,
-                        initializationTimestamp));
+                        jobResult.getStartTime() < 0
+                                ? initializationTimestamp
+                                : jobResult.getStartTime(),
+                        jobResult.getEndTime(),
+                        jobResult.getApplicationId().orElse(null)));
     }
 }
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/ArchivedExecutionGraph.java b/flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/ArchivedExecutionGraph.java
index ec50feaaca8..e259385507f 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/ArchivedExecutionGraph.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/ArchivedExecutionGraph.java
@@ -413,6 +413,28 @@ public class ArchivedExecutionGraph implements AccessExecutionGraph, Serializabl
             @Nullable Throwable throwable,
             @Nullable JobCheckpointingSettings checkpointingSettings,
             long initializationTimestamp) {
+        return createSparseArchivedExecutionGraph(
+                jobId,
+                jobName,
+                jobStatus,
+                jobType,
+                throwable,
+                checkpointingSettings,
+                initializationTimestamp,
+                -1,
+                null);
+    }
+
+    public static ArchivedExecutionGraph createSparseArchivedExecutionGraph(
+            JobID jobId,
+            String jobName,
+            JobStatus jobStatus,
+            @Nullable JobType jobType,
+            @Nullable Throwable throwable,
+            @Nullable JobCheckpointingSettings checkpointingSettings,
+            long initializationTimestamp,
+            long endTimestamp,
+            @Nullable ApplicationID applicationId) {
         return createSparseArchivedExecutionGraph(
                 jobId,
                 jobName,
@@ -422,7 +444,9 @@ public class ArchivedExecutionGraph implements AccessExecutionGraph, Serializabl
                 Collections.emptyList(),
                 throwable,
                 checkpointingSettings,
-                initializationTimestamp);
+                initializationTimestamp,
+                endTimestamp,
+                applicationId);
     }
 
     public static ArchivedExecutionGraph createSparseArchivedExecutionGraphWithJobVertices(
@@ -464,7 +488,9 @@ public class ArchivedExecutionGraph implements AccessExecutionGraph, Serializabl
                 archivedVerticesInCreationOrder,
                 throwable,
                 checkpointingSettings,
-                initializationTimestamp);
+                initializationTimestamp,
+                -1,
+                null);
     }
 
     private static ArchivedExecutionGraph createSparseArchivedExecutionGraph(
@@ -476,7 +502,9 @@ public class ArchivedExecutionGraph implements AccessExecutionGraph, Serializabl
             List<ArchivedExecutionJobVertex> archivedVerticesInCreationOrder,
             @Nullable Throwable throwable,
             @Nullable JobCheckpointingSettings checkpointingSettings,
-            long initializationTimestamp) {
+            long initializationTimestamp,
+            long endTimestamp,
+            @Nullable ApplicationID applicationId) {
         final Map<String, SerializedValue<OptionalFailure<Object>>> serializedUserAccumulators =
                 Collections.emptyMap();
         StringifiedAccumulatorResult[] archivedUserAccumulators =
@@ -491,9 +519,13 @@ public class ArchivedExecutionGraph implements AccessExecutionGraph, Serializabl
         if (throwable != null) {
             Preconditions.checkState(
                     jobStatus == JobStatus.FAILED || jobStatus == JobStatus.SUSPENDED);
-            long failureTime = System.currentTimeMillis();
+            // we use the current time as the failure time if the endTimestamp is not valid
+            long failureTime = endTimestamp < 0 ? System.currentTimeMillis() : endTimestamp;
             failureInfo = new ErrorInfo(throwable, failureTime);
             timestamps[jobStatus.ordinal()] = failureTime;
+        } else if (jobStatus.isGloballyTerminalState() && endTimestamp >= 0) {
+            // use the valid endTimestamp as the timestamp for the terminal state
+            timestamps[jobStatus.ordinal()] = endTimestamp;
         }
 
         return new ArchivedExecutionGraph(
@@ -522,6 +554,6 @@ public class ArchivedExecutionGraph implements AccessExecutionGraph, Serializabl
                 checkpointingSettings == null ? null : "Unknown",
                 null,
                 0,
-                null);
+                applicationId);
     }
 }
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/JobResult.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/JobResult.java
index 3db82f5d5c3..f6a0e85bd16 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/JobResult.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/JobResult.java
@@ -19,6 +19,7 @@
 package org.apache.flink.runtime.jobmaster;
 
 import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.ApplicationID;
 import org.apache.flink.api.common.JobExecutionResult;
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.JobStatus;
@@ -68,13 +69,22 @@ public class JobResult implements Serializable {
     /** Stores the cause of the job failure, or {@code null} if the job finished successfully. */
     @Nullable private final SerializedThrowable serializedThrowable;
 
+    @Nullable private final ApplicationID applicationId;
+
+    private final long startTime;
+
+    private final long endTime;
+
     private JobResult(
             final JobID jobId,
             final String jobName,
             @Nullable final JobStatus jobStatus,
             final Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults,
             final long netRuntime,
-            @Nullable final SerializedThrowable serializedThrowable) {
+            @Nullable final SerializedThrowable serializedThrowable,
+            @Nullable final ApplicationID applicationId,
+            final long startTime,
+            final long endTime) {
 
         checkArgument(netRuntime >= 0, "netRuntime must be greater than or equals 0");
         checkArgument(
@@ -87,6 +97,9 @@ public class JobResult implements Serializable {
         this.accumulatorResults = requireNonNull(accumulatorResults);
         this.netRuntime = netRuntime;
         this.serializedThrowable = serializedThrowable;
+        this.applicationId = applicationId;
+        this.startTime = startTime;
+        this.endTime = endTime;
     }
 
     /** Returns {@code true} if the job finished successfully. */
@@ -123,6 +136,18 @@ public class JobResult implements Serializable {
         return Optional.ofNullable(serializedThrowable);
     }
 
+    public Optional<ApplicationID> getApplicationId() {
+        return Optional.ofNullable(applicationId);
+    }
+
+    public long getStartTime() {
+        return startTime;
+    }
+
+    public long getEndTime() {
+        return endTime;
+    }
+
     /**
      * Converts the {@link JobResult} to a {@link JobExecutionResult}.
      *
@@ -183,6 +208,12 @@ public class JobResult implements Serializable {
 
         private SerializedThrowable serializedThrowable;
 
+        private ApplicationID applicationId;
+
+        private long startTime = -1;
+
+        private long endTime = -1;
+
         public Builder jobId(final JobID jobId) {
             this.jobId = jobId;
             return this;
@@ -214,6 +245,21 @@ public class JobResult implements Serializable {
             return this;
         }
 
+        public Builder applicationId(final ApplicationID applicationId) {
+            this.applicationId = applicationId;
+            return this;
+        }
+
+        public Builder startTime(final long startTime) {
+            this.startTime = startTime;
+            return this;
+        }
+
+        public Builder endTime(final long endTime) {
+            this.endTime = endTime;
+            return this;
+        }
+
         public JobResult build() {
             return new JobResult(
                     jobId,
@@ -221,7 +267,10 @@ public class JobResult implements Serializable {
                     jobStatus,
                     accumulatorResults == null ? Collections.emptyMap() : accumulatorResults,
                     netRuntime,
-                    serializedThrowable);
+                    serializedThrowable,
+                    applicationId,
+                    startTime,
+                    endTime);
         }
     }
 
@@ -253,9 +302,11 @@ public class JobResult implements Serializable {
 
         builder.jobStatus(jobStatus.isGloballyTerminalState() ? jobStatus : null);
 
-        final long netRuntime =
-                accessExecutionGraph.getStatusTimestamp(jobStatus)
-                        - accessExecutionGraph.getStatusTimestamp(JobStatus.INITIALIZING);
+        final long startTime = accessExecutionGraph.getStatusTimestamp(JobStatus.INITIALIZING);
+        final long endTime = accessExecutionGraph.getStatusTimestamp(jobStatus);
+        builder.startTime(startTime).endTime(endTime);
+
+        final long netRuntime = endTime - startTime;
         // guard against clock changes
         final long guardedNetRuntime = Math.max(netRuntime, 0L);
         builder.netRuntime(guardedNetRuntime);
@@ -268,6 +319,8 @@ public class JobResult implements Serializable {
             builder.serializedThrowable(errorInfo.getException());
         }
 
+        builder.applicationId(accessExecutionGraph.getApplicationId().orElse(null));
+
         return builder.build();
     }
 }
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
index a0327245bd1..7d2defb29fb 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
@@ -35,6 +35,7 @@ import org.apache.flink.core.execution.CheckpointType;
 import org.apache.flink.core.execution.RecoveryClaimMode;
 import org.apache.flink.core.execution.SavepointFormatType;
 import org.apache.flink.runtime.application.AbstractApplication;
+import org.apache.flink.runtime.application.SingleJobApplication;
 import org.apache.flink.runtime.blob.BlobCacheService;
 import org.apache.flink.runtime.blob.BlobClient;
 import org.apache.flink.runtime.blob.BlobServer;
@@ -1096,8 +1097,9 @@ public class MiniCluster implements AutoCloseableAsync {
                         .thenCombine(
                                 dispatcherGatewayFuture,
                                 (Void ack, DispatcherGateway dispatcherGateway) ->
-                                        dispatcherGateway.submitJob(
-                                                clonedExecutionPlan, rpcTimeout))
+                                        dispatcherGateway.submitApplication(
+                                                new SingleJobApplication(clonedExecutionPlan),
+                                                rpcTimeout))
                         .thenCompose(Function.identity());
         return acknowledgeCompletableFuture.thenApply(
                 (Acknowledge ignored) -> new JobSubmissionResult(clonedExecutionPlan.getJobID()));
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/job/JobDetailsInfo.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/job/JobDetailsInfo.java
index 096b8a188ea..56bbfc19e10 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/job/JobDetailsInfo.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/job/JobDetailsInfo.java
@@ -112,6 +112,7 @@ public class JobDetailsInfo implements ResponseBody {
     private final JobStatus jobStatus;
 
     @JsonProperty(FIELD_NAME_JOB_TYPE)
+    @Nullable
     private final JobType jobType;
 
     @Nullable
@@ -167,7 +168,7 @@ public class JobDetailsInfo implements ResponseBody {
             @JsonProperty(FIELD_NAME_JOB_NAME) String name,
             @JsonProperty(FIELD_NAME_IS_STOPPABLE) boolean isStoppable,
             @JsonProperty(FIELD_NAME_JOB_STATUS) JobStatus jobStatus,
-            @JsonProperty(FIELD_NAME_JOB_TYPE) JobType jobType,
+            @JsonProperty(FIELD_NAME_JOB_TYPE) @Nullable JobType jobType,
             @Nullable @JsonProperty(FIELD_NAME_JOB_SCHEDULER)
                     JobManagerOptions.SchedulerType schedulerType,
             @JsonProperty(FIELD_NAME_START_TIME) long startTime,
@@ -189,7 +190,7 @@ public class JobDetailsInfo implements ResponseBody {
         this.name = Preconditions.checkNotNull(name);
         this.isStoppable = isStoppable;
         this.jobStatus = Preconditions.checkNotNull(jobStatus);
-        this.jobType = Preconditions.checkNotNull(jobType);
+        this.jobType = jobType;
         this.schedulerType = schedulerType;
         this.startTime = startTime;
         this.endTime = endTime;
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/JobResultDeserializer.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/JobResultDeserializer.java
index 9a577235d7d..9b0df9940d9 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/JobResultDeserializer.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/JobResultDeserializer.java
@@ -18,6 +18,7 @@
 
 package org.apache.flink.runtime.rest.messages.json;
 
+import org.apache.flink.api.common.ApplicationID;
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.runtime.clusterframework.ApplicationStatus;
@@ -54,6 +55,9 @@ public class JobResultDeserializer extends StdDeserializer<JobResult> {
 
     private final JobIDDeserializer jobIdDeserializer = new JobIDDeserializer();
 
+    private final ApplicationIDDeserializer applicationIdDeserializer =
+            new ApplicationIDDeserializer();
+
     private final SerializedThrowableDeserializer serializedThrowableDeserializer =
             new SerializedThrowableDeserializer();
 
@@ -76,6 +80,9 @@ public class JobResultDeserializer extends StdDeserializer<JobResult> {
         long netRuntime = -1;
         SerializedThrowable serializedThrowable = null;
         Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;
+        ApplicationID applicationId = null;
+        long startTime = -1;
+        long endTime = -1;
 
         while (true) {
             final JsonToken jsonToken = p.nextToken();
@@ -116,6 +123,18 @@ public class JobResultDeserializer extends StdDeserializer<JobResult> {
                     assertNextToken(p, JsonToken.START_OBJECT);
                     serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
                     break;
+                case JobResultSerializer.FIELD_NAME_APPLICATION_ID:
+                    assertNextToken(p, JsonToken.VALUE_STRING);
+                    applicationId = applicationIdDeserializer.deserialize(p, ctxt);
+                    break;
+                case JobResultSerializer.FIELD_NAME_START_TIME:
+                    assertNextToken(p, JsonToken.VALUE_NUMBER_INT);
+                    startTime = p.getLongValue();
+                    break;
+                case JobResultSerializer.FIELD_NAME_END_TIME:
+                    assertNextToken(p, JsonToken.VALUE_NUMBER_INT);
+                    endTime = p.getLongValue();
+                    break;
                 default:
                     // ignore unknown fields
             }
@@ -129,6 +148,9 @@ public class JobResultDeserializer extends StdDeserializer<JobResult> {
                     .netRuntime(netRuntime)
                     .accumulatorResults(accumulatorResults)
                     .serializedThrowable(serializedThrowable)
+                    .applicationId(applicationId)
+                    .startTime(startTime)
+                    .endTime(endTime)
                     .build();
         } catch (final RuntimeException e) {
             throw new JsonMappingException(
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/JobResultSerializer.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/JobResultSerializer.java
index 181394a4eb8..2a2a31445d2 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/JobResultSerializer.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/json/JobResultSerializer.java
@@ -55,8 +55,16 @@ public class JobResultSerializer extends StdSerializer<JobResult> {
 
     static final String FIELD_NAME_FAILURE_CAUSE = "failure-cause";
 
+    static final String FIELD_NAME_APPLICATION_ID = "application-id";
+
+    static final String FIELD_NAME_START_TIME = "start-time";
+
+    static final String FIELD_NAME_END_TIME = "end-time";
+
     private final JobIDSerializer jobIdSerializer = new JobIDSerializer();
 
+    private final ApplicationIDSerializer applicationIdSerializer = new ApplicationIDSerializer();
+
     private final SerializedValueSerializer serializedValueSerializer;
 
     private final SerializedThrowableSerializer serializedThrowableSerializer =
@@ -111,6 +119,14 @@ public class JobResultSerializer extends StdSerializer<JobResult> {
             serializedThrowableSerializer.serialize(serializedThrowable, gen, provider);
         }
 
+        if (result.getApplicationId().isPresent()) {
+            gen.writeFieldName(FIELD_NAME_APPLICATION_ID);
+            applicationIdSerializer.serialize(result.getApplicationId().get(), gen, provider);
+        }
+
+        gen.writeNumberField(FIELD_NAME_START_TIME, result.getStartTime());
+        gen.writeNumberField(FIELD_NAME_END_TIME, result.getEndTime());
+
         gen.writeEndObject();
     }
 }
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherCleanupITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherCleanupITCase.java
index d07a38156d8..0bc934334a8 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherCleanupITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherCleanupITCase.java
@@ -22,6 +22,7 @@ import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.configuration.CleanupOptions;
 import org.apache.flink.core.execution.RecoveryClaimMode;
 import org.apache.flink.core.testutils.OneShotLatch;
+import org.apache.flink.runtime.application.SingleJobApplication;
 import org.apache.flink.runtime.checkpoint.EmbeddedCompletedCheckpointStore;
 import org.apache.flink.runtime.checkpoint.PerJobCheckpointRecoveryFactory;
 import org.apache.flink.runtime.deployment.TaskDeploymentDescriptor;
@@ -50,6 +51,7 @@ import org.apache.flink.runtime.testtasks.NoOpInvokable;
 import org.apache.flink.runtime.testutils.CommonTestUtils;
 import org.apache.flink.runtime.testutils.TestingExecutionPlanStore;
 import org.apache.flink.runtime.testutils.TestingJobResultStore;
+import org.apache.flink.streaming.api.graph.ExecutionPlan;
 import org.apache.flink.util.concurrent.FutureUtils;
 
 import org.junit.After;
@@ -179,7 +181,7 @@ public class DispatcherCleanupITCase extends AbstractDispatcherTest {
                 leaderElection.isLeader(UUID.randomUUID());
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
-        dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
+        submitApplicationWithJob(dispatcherGateway, jobGraph);
 
         waitForJobToFinish(confirmedLeaderInformation, dispatcherGateway, jobId);
 
@@ -288,7 +290,7 @@ public class DispatcherCleanupITCase extends AbstractDispatcherTest {
                 leaderElection.isLeader(UUID.randomUUID());
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
-        dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
+        submitApplicationWithJob(dispatcherGateway, jobGraph);
 
         waitForJobToFinish(confirmedLeaderInformation, dispatcherGateway, jobId);
         firstCleanupTriggered.await();
@@ -388,4 +390,9 @@ public class DispatcherCleanupITCase extends AbstractDispatcherTest {
                                 JobMasterId.fromUuidOrNull(leaderInformation.getLeaderSessionID()),
                                 JobMasterGateway.class));
     }
+
+    private void submitApplicationWithJob(
+            DispatcherGateway dispatcherGateway, ExecutionPlan executionPlan) throws Exception {
+        dispatcherGateway.submitApplication(new SingleJobApplication(executionPlan), TIMEOUT).get();
+    }
 }
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherResourceCleanupTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherResourceCleanupTest.java
index 682c9f84ea5..1d9b3e87475 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherResourceCleanupTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherResourceCleanupTest.java
@@ -18,11 +18,13 @@
 
 package org.apache.flink.runtime.dispatcher;
 
+import org.apache.flink.api.common.ApplicationID;
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.core.failure.FailureEnricher;
 import org.apache.flink.core.testutils.OneShotLatch;
+import org.apache.flink.runtime.application.SingleJobApplication;
 import org.apache.flink.runtime.blob.BlobServer;
 import org.apache.flink.runtime.blob.BlobUtils;
 import org.apache.flink.runtime.blob.TestingBlobStoreBuilder;
@@ -112,6 +114,10 @@ public class DispatcherResourceCleanupTest extends TestLogger {
 
     private JobGraph jobGraph;
 
+    private SingleJobApplication application;
+
+    private ApplicationID applicationId;
+
     private TestingDispatcher dispatcher;
 
     private DispatcherGateway dispatcherGateway;
@@ -130,6 +136,8 @@ public class DispatcherResourceCleanupTest extends TestLogger {
     public void setup() throws Exception {
         jobGraph = JobGraphTestUtils.singleNoOpJobGraph();
         jobId = jobGraph.getJobID();
+        application = new SingleJobApplication(jobGraph);
+        applicationId = application.getApplicationId();
 
         globalCleanupFuture = new CompletableFuture<>();
         localCleanupFuture = new CompletableFuture<>();
@@ -141,23 +149,23 @@ public class DispatcherResourceCleanupTest extends TestLogger {
                         new TestingBlobStoreBuilder().createTestingBlobStore());
     }
 
-    private TestingJobManagerRunnerFactory startDispatcherAndSubmitJob() throws Exception {
-        return startDispatcherAndSubmitJob(0);
+    private TestingJobManagerRunnerFactory startDispatcherAndSubmitApplication() throws Exception {
+        return startDispatcherAndSubmitApplication(0);
     }
 
-    private TestingJobManagerRunnerFactory startDispatcherAndSubmitJob(
+    private TestingJobManagerRunnerFactory startDispatcherAndSubmitApplication(
             int numBlockingJobManagerRunners) throws Exception {
-        return startDispatcherAndSubmitJob(
+        return startDispatcherAndSubmitApplication(
                 createTestingDispatcherBuilder(), numBlockingJobManagerRunners);
     }
 
-    private TestingJobManagerRunnerFactory startDispatcherAndSubmitJob(
+    private TestingJobManagerRunnerFactory startDispatcherAndSubmitApplication(
             TestingDispatcher.Builder dispatcherBuilder, int numBlockingJobManagerRunners)
             throws Exception {
         final TestingJobMasterServiceLeadershipRunnerFactory testingJobManagerRunnerFactoryNG =
                 new TestingJobMasterServiceLeadershipRunnerFactory(numBlockingJobManagerRunners);
         startDispatcher(dispatcherBuilder, testingJobManagerRunnerFactoryNG);
-        submitJobAndWait();
+        submitApplicationAndWait();
 
         return testingJobManagerRunnerFactoryNG;
     }
@@ -227,10 +235,10 @@ public class DispatcherResourceCleanupTest extends TestLogger {
     @Test
     public void testGlobalCleanupWhenJobFinished() throws Exception {
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob();
+                startDispatcherAndSubmitApplication();
 
         // complete the job
-        finishJob(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
+        finishJobAndApplication(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
 
         assertGlobalCleanupTriggered(jobId);
     }
@@ -238,7 +246,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
     @Test
     public void testGlobalCleanupWhenJobCanceled() throws Exception {
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob();
+                startDispatcherAndSubmitApplication();
 
         // complete the job
         cancelJob(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
@@ -246,18 +254,18 @@ public class DispatcherResourceCleanupTest extends TestLogger {
         assertGlobalCleanupTriggered(jobId);
     }
 
-    private CompletableFuture<Acknowledge> submitJob() {
-        return dispatcherGateway.submitJob(jobGraph, timeout);
+    private CompletableFuture<Acknowledge> submitApplication() {
+        return dispatcherGateway.submitApplication(application, timeout);
     }
 
-    private void submitJobAndWait() {
-        submitJob().join();
+    private void submitApplicationAndWait() {
+        submitApplication().join();
     }
 
     @Test
     public void testLocalCleanupWhenJobNotFinished() throws Exception {
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob();
+                startDispatcherAndSubmitApplication();
 
         // job not finished
         final TestingJobManagerRunner testingJobManagerRunner =
@@ -270,7 +278,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
     @Test
     public void testGlobalCleanupWhenJobSubmissionFails() throws Exception {
         startDispatcher(new FailingJobManagerRunnerFactory(new FlinkException("Test exception")));
-        final CompletableFuture<Acknowledge> submissionFuture = submitJob();
+        final CompletableFuture<Acknowledge> submissionFuture = submitApplication();
 
         assertThatThrownBy(submissionFuture::get).hasCauseInstanceOf(JobSubmissionException.class);
 
@@ -279,7 +287,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
 
     @Test
     public void testLocalCleanupWhenClosingDispatcher() throws Exception {
-        startDispatcherAndSubmitJob();
+        startDispatcherAndSubmitApplication();
 
         dispatcher.closeAsync().get();
 
@@ -298,7 +306,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
                 new ArrayDeque<>(Arrays.asList(testingJobManagerRunner));
 
         startDispatcher(new QueueJobManagerRunnerFactory(jobManagerRunners));
-        submitJobAndWait();
+        submitApplicationAndWait();
 
         final CompletableFuture<Void> dispatcherTerminationFuture = dispatcher.closeAsync();
 
@@ -340,9 +348,9 @@ public class DispatcherResourceCleanupTest extends TestLogger {
                                         .build());
 
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob(dispatcherBuilder, 0);
+                startDispatcherAndSubmitApplication(dispatcherBuilder, 0);
 
-        finishJob(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
+        finishJobAndApplication(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
 
         assertThatNoCleanupWasTriggered();
 
@@ -395,9 +403,9 @@ public class DispatcherResourceCleanupTest extends TestLogger {
                         .setResourceCleanerFactory(resourceCleanerFactory);
 
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob(dispatcherBuilder, 0);
+                startDispatcherAndSubmitApplication(dispatcherBuilder, 0);
 
-        finishJob(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
+        finishJobAndApplication(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
 
         assertThat(markAsCleanFuture.isDone(), is(false));
 
@@ -415,7 +423,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
     @Test
     public void testJobSubmissionUnderSameJobId() throws Exception {
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob(1);
+                startDispatcherAndSubmitApplication(1);
 
         final TestingJobManagerRunner testingJobManagerRunner =
                 jobManagerRunnerFactory.takeCreatedJobManagerRunner();
@@ -450,7 +458,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
     @Test
     public void testDuplicateJobSubmissionDoesNotDeleteJobMetaData() throws Exception {
         final TestingJobManagerRunnerFactory testingJobManagerRunnerFactoryNG =
-                startDispatcherAndSubmitJob();
+                startDispatcherAndSubmitApplication();
 
         final CompletableFuture<Acknowledge> submissionFuture =
                 dispatcherGateway.submitJob(jobGraph, timeout);
@@ -468,14 +476,18 @@ public class DispatcherResourceCleanupTest extends TestLogger {
 
             assertThatNoCleanupWasTriggered();
         } finally {
-            finishJob(testingJobManagerRunnerFactoryNG.takeCreatedJobManagerRunner());
+            finishJobAndApplication(testingJobManagerRunnerFactoryNG.takeCreatedJobManagerRunner());
         }
 
         assertGlobalCleanupTriggered(jobId);
     }
 
-    private void finishJob(TestingJobManagerRunner takeCreatedJobManagerRunner) {
+    private void finishJobAndApplication(TestingJobManagerRunner takeCreatedJobManagerRunner) {
         terminateJobWithState(takeCreatedJobManagerRunner, JobStatus.FINISHED);
+        application.jobStatusChanges(
+                takeCreatedJobManagerRunner.getJobID(),
+                JobStatus.FINISHED,
+                System.currentTimeMillis());
     }
 
     private void suspendJob(TestingJobManagerRunner takeCreatedJobManagerRunner) {
@@ -504,7 +516,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
     @Test
     public void testDispatcherTerminationTerminatesRunningJobMasters() throws Exception {
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob();
+                startDispatcherAndSubmitApplication();
 
         dispatcher.closeAsync().get();
 
@@ -517,7 +529,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
     @Test
     public void testDispatcherTerminationWaitsForJobMasterTerminations() throws Exception {
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob(1);
+                startDispatcherAndSubmitApplication(1);
 
         final CompletableFuture<Void> dispatcherTerminationFuture = dispatcher.closeAsync();
 
@@ -556,7 +568,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
                         .build();
 
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob(
+                startDispatcherAndSubmitApplication(
                         createTestingDispatcherBuilder().setJobResultStore(jobResultStore), 0);
 
         ArchivedExecutionGraph executionGraph =
@@ -592,7 +604,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
                         .build();
 
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob(
+                startDispatcherAndSubmitApplication(
                         createTestingDispatcherBuilder().setJobResultStore(jobResultStore), 0);
 
         ArchivedExecutionGraph executionGraph =
@@ -640,6 +652,10 @@ public class DispatcherResourceCleanupTest extends TestLogger {
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        // submit a mocked application to hold the job
+        dispatcherGateway.submitApplication(
+                TestingApplication.builder().setApplicationId(applicationId).build(), timeout);
+
         // submit and fail during job master runner construction
         queue.offer(Optional.of(testException));
         assertThatThrownBy(() -> dispatcherGateway.submitJob(jobGraph, Duration.ofMinutes(1)).get())
@@ -652,7 +668,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
         // don't fail this time
         queue.offer(Optional.empty());
         // submit job again
-        dispatcherGateway.submitJob(jobGraph, Duration.ofMinutes(1L)).get();
+        dispatcherGateway.submitJob(jobGraph, Duration.ofMinutes(1)).get();
         blockingJobManagerRunnerFactory.setJobStatus(JobStatus.RUNNING);
 
         // Ensure job is running
@@ -674,9 +690,9 @@ public class DispatcherResourceCleanupTest extends TestLogger {
                                         .build());
 
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob(testingDispatcherBuilder, 0);
+                startDispatcherAndSubmitApplication(testingDispatcherBuilder, 0);
 
-        finishJob(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
+        finishJobAndApplication(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
 
         // Before the archiving is finished, the cleanup is not finished and the job is not
         // terminated
@@ -710,7 +726,7 @@ public class DispatcherResourceCleanupTest extends TestLogger {
                                         .build());
 
         final TestingJobManagerRunnerFactory jobManagerRunnerFactory =
-                startDispatcherAndSubmitJob(testingDispatcherBuilder, 0);
+                startDispatcherAndSubmitApplication(testingDispatcherBuilder, 0);
 
         suspendJob(jobManagerRunnerFactory.takeCreatedJobManagerRunner());
 
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherTest.java
index ef838b8bbe6..a8ef8914463 100755
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/DispatcherTest.java
@@ -108,7 +108,6 @@ import org.apache.flink.util.FlinkException;
 import org.apache.flink.util.InstantiationUtil;
 import org.apache.flink.util.Preconditions;
 import org.apache.flink.util.concurrent.FutureUtils;
-import org.apache.flink.util.concurrent.ScheduledExecutor;
 
 import org.apache.flink.shaded.guava33.com.google.common.collect.ImmutableMap;
 import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
@@ -145,7 +144,6 @@ import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicReference;
@@ -159,7 +157,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThrows;
 
 /** Test for the {@link Dispatcher} component. */
@@ -169,6 +166,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
 
     private JobID jobId;
 
+    private ApplicationID applicationId;
+
     private TestingLeaderElection jobMasterLeaderElection;
 
     /** Instance under test. */
@@ -179,6 +178,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         super.setUp();
         jobGraph = JobGraphTestUtils.singleNoOpJobGraph();
         jobId = jobGraph.getJobID();
+        applicationId = ApplicationID.fromHexString(jobId.toHexString());
+        jobGraph.setApplicationId(applicationId);
         jobMasterLeaderElection = new TestingLeaderElection();
         haServices.setJobMasterLeaderElection(jobId, jobMasterLeaderElection);
     }
@@ -230,6 +231,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
                         new ExpectedJobIdJobManagerRunnerFactory(jobId));
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         jobMasterLeaderElection.getStartFuture().get();
@@ -267,6 +270,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         final int numThreads = 5;
         final CountDownLatch prepareLatch = new CountDownLatch(numThreads);
         final OneShotLatch startLatch = new OneShotLatch();
@@ -392,6 +397,9 @@ public class DispatcherTest extends AbstractDispatcherTest {
         dispatcher = createAndStartDispatcher(heartbeatServices, haServices, blockingJobMaster);
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
+
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         blockingJobMaster.waitForBlockingInit();
@@ -420,6 +428,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         dispatcher = createAndStartDispatcher(heartbeatServices, haServices, blockingJobMaster);
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         assertThat(dispatcherGateway.requestJobStatus(jobId, TIMEOUT).get())
@@ -449,6 +459,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         assertThatFuture(dispatcherGateway.submitJob(jobGraph, TIMEOUT)).eventuallySucceeds();
 
         assertThatFuture(dispatcherGateway.requestJobStatus(jobGraph.getJobID(), TIMEOUT))
@@ -485,6 +497,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         JobID jobId = jobGraph.getJobID();
 
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
@@ -496,6 +510,9 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                         .setState(JobStatus.CANCELED)
                                         .build())));
 
+        // mock application termination so that its jobs can be marked clean and terminate
+        mockApplicationStatusChange(ApplicationState.FINISHED);
+
         // wait for job to finish
         dispatcher.getJobTerminationFuture(jobId, TIMEOUT).get();
         // sanity check
@@ -519,6 +536,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         JobID jobId = jobGraph.getJobID();
 
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
@@ -530,6 +549,9 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                         .setState(JobStatus.FINISHED)
                                         .build())));
 
+        // mock application termination so that its jobs can be marked clean and terminate
+        mockApplicationStatusChange(ApplicationState.FINISHED);
+
         // wait for job to finish
         dispatcher.getJobTerminationFuture(jobId, TIMEOUT).get();
         // sanity check
@@ -567,6 +589,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         JobID jobId = jobGraph.getJobID();
 
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
@@ -603,10 +627,10 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                         .build())
                         .build(rpcService);
         dispatcher.start();
-        ApplicationID applicationId = mockApplicationStatusChange(ApplicationState.RUNNING);
+        submitApplicationAndMockApplicationStatusChange(ApplicationState.RUNNING);
         // verify that archive application is not called
         assertFalse(archiveApplicationFuture.isDone());
-        assertNull(dispatcher.getApplicationArchivingFuture(applicationId));
+        assertFalse(dispatcher.getApplicationTerminationFuture(applicationId).isDone());
     }
 
     @Test
@@ -625,11 +649,11 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                         .build())
                         .build(rpcService);
         dispatcher.start();
-        final ApplicationID applicationId = mockApplicationStatusChange(ApplicationState.FINISHED);
+        submitApplicationAndMockApplicationStatusChange(ApplicationState.FINISHED);
         // verify that archive application is called with the application id
         assertEquals(applicationId, archiveApplicationFuture.get());
         dispatcher
-                .getApplicationArchivingFuture(applicationId)
+                .getApplicationTerminationFuture(applicationId)
                 .get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
     }
 
@@ -637,10 +661,10 @@ public class DispatcherTest extends AbstractDispatcherTest {
     public void testApplicationStatusChange_ThrowsIfDuplicateTerminalStatus() throws Exception {
         dispatcher = createTestingDispatcherBuilder().build(rpcService);
         dispatcher.start();
-        final ApplicationID applicationId = mockApplicationStatusChange(ApplicationState.FINISHED);
+        submitApplicationAndMockApplicationStatusChange(ApplicationState.FINISHED);
         // wait for archive to complete
         dispatcher
-                .getApplicationArchivingFuture(applicationId)
+                .getApplicationTerminationFuture(applicationId)
                 .get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
         assertThrows(
                 IllegalStateException.class,
@@ -649,15 +673,22 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                 applicationId, ApplicationState.FAILED));
     }
 
-    private ApplicationID mockApplicationStatusChange(ApplicationState targetState) {
-        final ApplicationID applicationId = new ApplicationID();
+    private void submitApplicationAndMockApplicationStatusChange(ApplicationState targetState)
+            throws Exception {
+        submitApplication();
+        mockApplicationStatusChange(targetState);
+    }
+
+    private void submitApplication() throws Exception {
         dispatcher
-                .getApplications()
-                .put(
-                        applicationId,
-                        TestingApplication.builder().setApplicationId(applicationId).build());
+                .submitApplication(
+                        TestingApplication.builder().setApplicationId(applicationId).build(),
+                        TIMEOUT)
+                .get();
+    }
+
+    private void mockApplicationStatusChange(ApplicationState targetState) throws Exception {
         dispatcher.notifyApplicationStatusChange(applicationId, targetState);
-        return applicationId;
     }
 
     @Test
@@ -671,8 +702,11 @@ public class DispatcherTest extends AbstractDispatcherTest {
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         final JobGraph emptyJobGraph =
                 JobGraphBuilder.newStreamingJobGraphBuilder().setJobId(jobId).build();
+        emptyJobGraph.setApplicationId(applicationId);
 
         dispatcherGateway.submitJob(emptyJobGraph, TIMEOUT).get();
 
@@ -693,6 +727,9 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                         1L)),
                         testFailure));
 
+        // mock application termination so that its jobs can be marked clean and terminate
+        mockApplicationStatusChange(ApplicationState.FINISHED);
+
         // wait till job has failed
         dispatcher.getJobTerminationFuture(jobId, TIMEOUT).get();
 
@@ -763,6 +800,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                 testingJobMasterGateway));
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         CompletableFuture<CheckpointStatsSnapshot> resultsFuture =
@@ -936,7 +975,9 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                                                 null,
                                                                 actualError,
                                                                 jobGraph.getCheckpointingSettings(),
-                                                                1L)),
+                                                                1L,
+                                                                1L,
+                                                                applicationId)),
                                         actualError)));
     }
 
@@ -957,7 +998,7 @@ public class DispatcherTest extends AbstractDispatcherTest {
         dispatcher =
                 createTestingDispatcherBuilder()
                         .setJobManagerRunnerFactory(jobManagerRunnerFactory)
-                        .setRecoveredJobs(Collections.singleton(JobGraphTestUtils.emptyJobGraph()))
+                        .setRecoveredJobs(Collections.singleton(jobGraph))
                         .build(rpcService);
 
         dispatcher.start();
@@ -1007,6 +1048,7 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                                 .jobId(jobIdOfRecoveredDirtyJobs)
                                                 .jobStatus(JobStatus.FINISHED)
                                                 .netRuntime(1)
+                                                .applicationId(applicationId)
                                                 .build()))
                         .setDispatcherBootstrapFactory(
                                 (ignoredDispatcherGateway,
@@ -1035,7 +1077,6 @@ public class DispatcherTest extends AbstractDispatcherTest {
     @Test
     public void testApplicationBootstrap() throws Exception {
         final OneShotLatch bootstrapLatch = new OneShotLatch();
-        final ApplicationID applicationId = new ApplicationID();
         final AbstractApplication application =
                 TestingApplication.builder()
                         .setApplicationId(applicationId)
@@ -1065,13 +1106,12 @@ public class DispatcherTest extends AbstractDispatcherTest {
         assertThat(dispatcher.getApplications().size()).isEqualTo(1);
         assertThat(dispatcher.getApplications().keySet()).contains(applicationId);
 
-        jobGraph.setApplicationId(applicationId);
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         assertThat(application.getJobs().size()).isEqualTo(1);
-        assertThat(application.getJobs()).contains(jobGraph.getJobID());
+        assertThat(application.getJobs()).contains(jobId);
     }
 
     @Test
@@ -1081,7 +1121,6 @@ public class DispatcherTest extends AbstractDispatcherTest {
 
         final CompletableFuture<ApplicationID> submittedApplicationFuture =
                 new CompletableFuture<>();
-        final ApplicationID applicationId = new ApplicationID();
         final AbstractApplication application =
                 TestingApplication.builder()
                         .setApplicationId(applicationId)
@@ -1108,7 +1147,6 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
-        ApplicationID applicationId = new ApplicationID();
         final AbstractApplication application =
                 TestingApplication.builder().setApplicationId(applicationId).build();
         // submit application
@@ -1128,7 +1166,6 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
-        ApplicationID applicationId = new ApplicationID();
         final AbstractApplication application =
                 TestingApplication.builder().setApplicationId(applicationId).build();
 
@@ -1179,6 +1216,251 @@ public class DispatcherTest extends AbstractDispatcherTest {
                                                 DuplicateApplicationSubmissionException.class));
     }
 
+    @Test
+    public void testRecoverJobSuccessfully() throws Exception {
+        final TestingJobMasterServiceLeadershipRunnerFactory jobManagerRunnerFactory =
+                new TestingJobMasterServiceLeadershipRunnerFactory();
+
+        dispatcher =
+                createTestingDispatcherBuilder()
+                        .setJobManagerRunnerFactory(jobManagerRunnerFactory)
+                        .setRecoveredJobs(Collections.singleton(jobGraph))
+                        .setDispatcherBootstrapFactory(
+                                (ignoredDispatcherGateway,
+                                        ignoredScheduledExecutor,
+                                        ignoredFatalErrorHandler) ->
+                                        new ApplicationBootstrap(
+                                                TestingApplication.builder()
+                                                        .setApplicationId(applicationId)
+                                                        .build()))
+                        .build(rpcService);
+
+        dispatcher.start();
+        dispatcher.waitUntilStarted();
+
+        // verify that the recovered job is NOT recovered immediately
+        assertThat(jobManagerRunnerFactory.getQueueSize()).isZero();
+        assertThat(dispatcher.getSuspendedJobs().containsKey(jobId)).isTrue();
+        assertThat(dispatcher.getSuspendedJobIdsByApplicationId().containsKey(applicationId))
+                .isTrue();
+
+        // call recoverJob RPC
+        final DispatcherGateway dispatcherGateway =
+                dispatcher.getSelfGateway(DispatcherGateway.class);
+        dispatcherGateway.recoverJob(jobId, TIMEOUT).get();
+
+        // verify that the job is now recovered
+        final TestingJobManagerRunner jobManagerRunner =
+                jobManagerRunnerFactory.takeCreatedJobManagerRunner();
+        assertThat(jobManagerRunner.getJobID()).isEqualTo(jobId);
+        assertThat(dispatcher.getSuspendedJobs().containsKey(jobId)).isFalse();
+        assertThat(dispatcher.getSuspendedJobIdsByApplicationId().containsKey(applicationId))
+                .isFalse();
+    }
+
+    @Test
+    public void testRecoverJobFailsWhenJobNotFound() throws Exception {
+        dispatcher =
+                createTestingDispatcherBuilder()
+                        .setRecoveredJobs(Collections.singleton(jobGraph))
+                        .setDispatcherBootstrapFactory(
+                                (ignoredDispatcherGateway,
+                                        ignoredScheduledExecutor,
+                                        ignoredFatalErrorHandler) ->
+                                        new ApplicationBootstrap(
+                                                TestingApplication.builder()
+                                                        .setApplicationId(applicationId)
+                                                        .build()))
+                        .build(rpcService);
+
+        dispatcher.start();
+        dispatcher.waitUntilStarted();
+
+        // try to recover a job that doesn't exist
+        final JobID unknownJobId = new JobID();
+        final DispatcherGateway dispatcherGateway =
+                dispatcher.getSelfGateway(DispatcherGateway.class);
+        final CompletableFuture<Acknowledge> recoverFuture =
+                dispatcherGateway.recoverJob(unknownJobId, TIMEOUT);
+
+        assertThatThrownBy(recoverFuture::get)
+                .hasCauseInstanceOf(JobSubmissionException.class)
+                .hasMessageContaining("Cannot find the recovered job");
+    }
+
+    @Test
+    public void testRemainingRecoveredJobsCleanedWhenApplicationReachesTerminalState()
+            throws Exception {
+        final TestingJobMasterServiceLeadershipRunnerFactory jobManagerRunnerFactory =
+                new TestingJobMasterServiceLeadershipRunnerFactory();
+        final TestingCleanupRunnerFactory cleanupRunnerFactory = new TestingCleanupRunnerFactory();
+
+        dispatcher =
+                createTestingDispatcherBuilder()
+                        .setJobManagerRunnerFactory(jobManagerRunnerFactory)
+                        .setCleanupRunnerFactory(cleanupRunnerFactory)
+                        .setRecoveredJobs(Collections.singleton(jobGraph))
+                        .setDispatcherBootstrapFactory(
+                                (ignoredDispatcherGateway,
+                                        ignoredScheduledExecutor,
+                                        ignoredFatalErrorHandler) ->
+                                        new ApplicationBootstrap(
+                                                TestingApplication.builder()
+                                                        .setApplicationId(applicationId)
+                                                        .build()))
+                        .build(rpcService);
+
+        dispatcher.start();
+        dispatcher.waitUntilStarted();
+
+        // verify that the recovered job exists
+        assertThat(dispatcher.getSuspendedJobs().containsKey(jobId)).isTrue();
+        assertThat(dispatcher.getSuspendedJobIdsByApplicationId().containsKey(applicationId))
+                .isTrue();
+
+        // complete the application - this should trigger cleanup of the remaining recovered job
+        dispatcher
+                .callAsyncInMainThread(
+                        () -> {
+                            dispatcher.notifyApplicationStatusChange(
+                                    applicationId, ApplicationState.FINISHED);
+                            return CompletableFuture.completedFuture(Acknowledge.get());
+                        })
+                .get();
+
+        // verify that no jobs are recovered
+        assertThat(jobManagerRunnerFactory.getQueueSize()).isZero();
+
+        // verify that the remaining recovered job is cleaned up
+        final TestingJobManagerRunner cleanupRunner =
+                cleanupRunnerFactory.takeCreatedJobManagerRunner();
+        assertThat(cleanupRunner.getJobID()).isEqualTo(jobId);
+        assertThat(dispatcher.getSuspendedJobs().containsKey(jobId)).isFalse();
+        assertThat(dispatcher.getSuspendedJobIdsByApplicationId().containsKey(applicationId))
+                .isFalse();
+    }
+
+    @Test
+    public void testJobResultNotMarkedCleanUntilApplicationTerminates() throws Exception {
+        final TestingJobMasterServiceLeadershipRunnerFactory jobManagerRunnerFactory =
+                new TestingJobMasterServiceLeadershipRunnerFactory();
+
+        dispatcher =
+                createTestingDispatcherBuilder()
+                        .setJobManagerRunnerFactory(jobManagerRunnerFactory)
+                        .setDispatcherBootstrapFactory(
+                                (ignoredDispatcherGateway,
+                                        ignoredScheduledExecutor,
+                                        ignoredFatalErrorHandler) ->
+                                        new ApplicationBootstrap(
+                                                TestingApplication.builder()
+                                                        .setApplicationId(applicationId)
+                                                        .build()))
+                        .build(rpcService);
+
+        dispatcher.start();
+        dispatcher.waitUntilStarted();
+
+        // submit a job
+        final DispatcherGateway dispatcherGateway =
+                dispatcher.getSelfGateway(DispatcherGateway.class);
+        dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
+
+        // complete the job
+        final TestingJobManagerRunner jobManagerRunner =
+                jobManagerRunnerFactory.takeCreatedJobManagerRunner();
+        final ExecutionGraphInfo completedExecutionGraphInfo =
+                new ExecutionGraphInfo(
+                        new ArchivedExecutionGraphBuilder()
+                                .setJobID(jobId)
+                                .setState(JobStatus.FINISHED)
+                                .setApplicationId(applicationId)
+                                .build());
+        jobManagerRunner.completeResultFuture(completedExecutionGraphInfo);
+
+        // job termination future should not be completed
+        assertThatThrownBy(
+                        () ->
+                                dispatcher
+                                        .getJobTerminationFuture(jobId, TIMEOUT)
+                                        .get(10L, TimeUnit.MILLISECONDS))
+                .isInstanceOf(TimeoutException.class);
+
+        // verify that the job result is NOT marked clean yet
+        assertThat(
+                        haServices.getJobResultStore().getDirtyResults().stream()
+                                .anyMatch(r -> r.getJobId().equals(jobId)))
+                .isTrue();
+
+        // complete the application
+        dispatcher.notifyApplicationStatusChange(applicationId, ApplicationState.FINISHED);
+
+        // wait for application termination
+        dispatcher
+                .getApplicationTerminationFuture(applicationId)
+                .get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
+
+        // wait for job termination
+        dispatcher
+                .getJobTerminationFuture(jobId, TIMEOUT)
+                .get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
+
+        // verify that the job result is now marked clean
+        assertThat(
+                        haServices.getJobResultStore().getDirtyResults().stream()
+                                .noneMatch(r -> r.getJobId().equals(jobId)))
+                .isTrue();
+    }
+
+    @Test
+    public void testRecoveredDirtyJobResultsCleanedOnApplicationSubmission() throws Exception {
+        // create a dirty job result
+        final JobResult jobResult =
+                new JobResult.Builder()
+                        .jobId(jobId)
+                        .jobStatus(JobStatus.FINISHED)
+                        .netRuntime(1)
+                        .applicationId(applicationId)
+                        .build();
+
+        final TestingCleanupRunnerFactory cleanupRunnerFactory = new TestingCleanupRunnerFactory();
+
+        dispatcher =
+                createTestingDispatcherBuilder()
+                        .setCleanupRunnerFactory(cleanupRunnerFactory)
+                        .setRecoveredDirtyJobs(Collections.singleton(jobResult))
+                        .setDispatcherBootstrapFactory(
+                                (ignoredDispatcherGateway,
+                                        ignoredScheduledExecutor,
+                                        ignoredFatalErrorHandler) ->
+                                        new ApplicationBootstrap(
+                                                TestingApplication.builder()
+                                                        .setApplicationId(applicationId)
+                                                        .build()))
+                        .build(rpcService);
+
+        // verify that the dirty job result exists
+        assertThat(
+                        dispatcher
+                                .getRecoveredDirtyJobResultsByApplicationId()
+                                .containsKey(applicationId))
+                .isTrue();
+
+        // start application - this should trigger the cleanup of dirty job results
+        dispatcher.start();
+        dispatcher.waitUntilStarted();
+
+        // verify that the dirty job result was cleaned up
+        final TestingJobManagerRunner cleanupRunner =
+                cleanupRunnerFactory.takeCreatedJobManagerRunner();
+        assertThat(cleanupRunner.getJobID()).isEqualTo(jobId);
+        assertThat(
+                        dispatcher
+                                .getRecoveredDirtyJobResultsByApplicationId()
+                                .containsKey(applicationId))
+                .isFalse();
+    }
+
     @Test
     public void testApplicationCancellation() throws Exception {
         dispatcher = createAndStartDispatcher(heartbeatServices, haServices);
@@ -1186,7 +1468,6 @@ public class DispatcherTest extends AbstractDispatcherTest {
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
         final CompletableFuture<Void> canceledApplicationFuture = new CompletableFuture<>();
-        ApplicationID applicationId = new ApplicationID();
         final AbstractApplication application =
                 TestingApplication.builder()
                         .setApplicationId(applicationId)
@@ -1217,7 +1498,6 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
-        ApplicationID applicationId = new ApplicationID();
         final AbstractApplication application =
                 TestingApplication.builder()
                         .setApplicationId(applicationId)
@@ -1244,7 +1524,6 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
-        ApplicationID applicationId = new ApplicationID();
         final AbstractApplication application =
                 TestingApplication.builder()
                         .setApplicationId(applicationId)
@@ -1284,6 +1563,9 @@ public class DispatcherTest extends AbstractDispatcherTest {
 
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
+
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         assertThat(dispatcher.getNumberJobs(TIMEOUT).get()).isOne();
@@ -1304,6 +1586,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
 
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         final CompletableFuture<JobResult> jobResultFuture =
@@ -1327,8 +1611,12 @@ public class DispatcherTest extends AbstractDispatcherTest {
                 createAndStartDispatcher(heartbeatServices, haServices, jobManagerRunnerFactory);
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
+
+        submitApplication();
+
         final JobGraph blockedJobGraph = JobGraphTestUtils.singleNoOpJobGraph();
         blockedJobGraph.setJobID(blockingId);
+        blockedJobGraph.setApplicationId(applicationId);
 
         // Submit two jobs, one blocks forever
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
@@ -1408,7 +1696,7 @@ public class DispatcherTest extends AbstractDispatcherTest {
                         .build(rpcService);
         dispatcher.start();
 
-        mockApplicationStatusChange(ApplicationState.FINISHED);
+        submitApplicationAndMockApplicationStatusChange(ApplicationState.FINISHED);
 
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
@@ -1472,6 +1760,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         final long initializationTimestamp = initializationTimestampQueue.take();
@@ -1490,6 +1780,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
         dispatcher.getJobTerminationFuture(jobId, TIMEOUT).get();
 
@@ -1508,6 +1800,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
 
+        submitApplication();
+
         // run first job, which completes with SUSPENDED
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
         dispatcherGateway.requestJobResult(jobId, TIMEOUT).get();
@@ -1530,6 +1824,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
 
+        submitApplication();
+
         // run first job, which completes with SUSPENDED
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
         dispatcherGateway.requestJobResult(jobId, TIMEOUT).get();
@@ -1537,6 +1833,9 @@ public class DispatcherTest extends AbstractDispatcherTest {
         // run second job, which completes with FINISHED
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
+        // mock application termination so that its jobs can be marked clean and terminate
+        mockApplicationStatusChange(ApplicationState.FINISHED);
+
         dispatcher.getJobTerminationFuture(jobId, TIMEOUT).get();
 
         assertOnlyContainsSingleJobWithState(
@@ -1549,6 +1848,7 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final JobID secondJobID = new JobID();
         JobGraph secondJobGraph = JobGraphTestUtils.streamingJobGraph();
         secondJobGraph.setJobID(secondJobID);
+        secondJobGraph.setApplicationId(applicationId);
         final JobManagerRunnerFactory blockingJobMaster =
                 new QueuedJobManagerRunnerFactory(
                         runningJobManagerRunnerWithJobStatus(
@@ -1572,6 +1872,7 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final JobID secondJobID = new JobID();
         JobGraph secondJobGraph = JobGraphTestUtils.streamingJobGraph();
         secondJobGraph.setJobID(secondJobID);
+        secondJobGraph.setApplicationId(applicationId);
         final JobManagerRunnerFactory blockingJobMaster =
                 new QueuedJobManagerRunnerFactory(
                         runningJobManagerRunnerWithJobStatus(JobStatus.RUNNING, jobId, 10L),
@@ -1596,6 +1897,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
         dispatcher.getJobTerminationFuture(jobId, TIMEOUT).get();
 
@@ -1614,6 +1917,7 @@ public class DispatcherTest extends AbstractDispatcherTest {
         JobVertex v3 = new JobVertex("v3");
         v3.setParallelism(3);
         jobGraph = new JobGraph(jobGraph.getJobID(), "job", v1, v2, v3);
+        jobGraph.setApplicationId(applicationId);
 
         configuration.set(
                 PipelineOptions.PARALLELISM_OVERRIDES,
@@ -1640,6 +1944,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
                         new ExpectedJobIdJobManagerRunnerFactory(jobId));
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         assertEquals(jobGraph.findVertexByID(v1.getID()).getParallelism(), 1);
         assertEquals(jobGraph.findVertexByID(v2.getID()).getParallelism(), 2);
         assertEquals(jobGraph.findVertexByID(v3.getID()).getParallelism(), 3);
@@ -1713,6 +2019,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
                 createAndStartDispatcher(heartbeatServices, haServices, jobManagerRunnerFactory);
         DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
+
+        submitApplication();
         for (JobGraph jobGraph : jobGraphs) {
             dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
         }
@@ -1750,9 +2058,12 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final PermanentBlobKey blobKey1 = blobServer.putPermanent(jobId1, fileContent);
         final PermanentBlobKey blobKey2 = blobServer.putPermanent(jobId2, fileContent);
 
+        final JobGraph jobGraph1 = new JobGraph(jobId1, "foobar");
+        jobGraph1.setApplicationId(applicationId);
+
         dispatcher =
                 createTestingDispatcherBuilder()
-                        .setRecoveredJobs(Collections.singleton(new JobGraph(jobId1, "foobar")))
+                        .setRecoveredJobs(Collections.singleton(jobGraph1))
                         .build(rpcService);
 
         assertThat(blobServer.getFile(jobId1, blobKey1)).hasBinaryContent(fileContent);
@@ -1817,6 +2128,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
                 dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         // We can try updating the JRR once the scheduler has been started.
@@ -1861,6 +2174,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
                 dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
 
         // We can try updating the JRR once the scheduler has been started.
@@ -1900,6 +2215,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
                 dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
 
+        submitApplication();
+
         assertThatFuture(
                         dispatcherGateway.updateJobResourceRequirements(
                                 jobId, JobResourceRequirements.empty()))
@@ -1945,12 +2262,16 @@ public class DispatcherTest extends AbstractDispatcherTest {
         final DispatcherGateway dispatcherGateway =
                 dispatcher.getSelfGateway(DispatcherGateway.class);
 
+        submitApplication();
+
         // We intentionally perform the test on two jobs to make sure the
         // concurrent modification is only prevented on the per-job level.
         final JobGraph firstJobGraph = InstantiationUtil.clone(jobGraph);
         firstJobGraph.setJobID(JobID.generate());
+        firstJobGraph.setApplicationId(applicationId);
         final JobGraph secondJobGraph = InstantiationUtil.clone(jobGraph);
         secondJobGraph.setJobID(JobID.generate());
+        secondJobGraph.setApplicationId(applicationId);
 
         final CompletableFuture<?> firstPendingUpdateFuture =
                 testConcurrentModificationIsPrevented(
@@ -2013,6 +2334,8 @@ public class DispatcherTest extends AbstractDispatcherTest {
                 dispatcher.getSelfGateway(DispatcherGateway.class);
         jobMasterLeaderElection.isLeader(UUID.randomUUID());
 
+        submitApplication();
+
         dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
         blockingJobMaster.waitForBlockingInit();
         blockingJobMaster.unblockJobMasterInitialization();
@@ -2476,122 +2799,4 @@ public class DispatcherTest extends AbstractDispatcherTest {
             return runner;
         }
     }
-
-    private static class TestingApplication extends AbstractApplication {
-
-        private final Function<ExecuteParams, CompletableFuture<Acknowledge>> executeFunction;
-        private final Function<Void, Void> cancelFunction;
-        private final Function<Void, ApplicationState> getApplicationStatusFunction;
-
-        private TestingApplication(
-                ApplicationID applicationId,
-                Function<ExecuteParams, CompletableFuture<Acknowledge>> executeFunction,
-                Function<Void, Void> cancelFunction,
-                Function<Void, ApplicationState> getApplicationStatusFunction) {
-            super(applicationId);
-            this.executeFunction = executeFunction;
-            this.cancelFunction = cancelFunction;
-            this.getApplicationStatusFunction = getApplicationStatusFunction;
-        }
-
-        @Override
-        public CompletableFuture<Acknowledge> execute(
-                DispatcherGateway dispatcherGateway,
-                ScheduledExecutor scheduledExecutor,
-                Executor mainThreadExecutor,
-                FatalErrorHandler errorHandler) {
-
-            ExecuteParams params =
-                    new ExecuteParams(
-                            dispatcherGateway, scheduledExecutor, mainThreadExecutor, errorHandler);
-            return executeFunction.apply(params);
-        }
-
-        @Override
-        public void cancel() {
-            cancelFunction.apply(null);
-        }
-
-        @Override
-        public void dispose() {}
-
-        @Override
-        public String getName() {
-            return "TestingApplication";
-        }
-
-        @Override
-        public ApplicationState getApplicationStatus() {
-            return getApplicationStatusFunction.apply(null);
-        }
-
-        public static class ExecuteParams {
-            public final DispatcherGateway dispatcherGateway;
-            public final ScheduledExecutor scheduledExecutor;
-            public final Executor mainThreadExecutor;
-            public final FatalErrorHandler errorHandler;
-
-            public ExecuteParams(
-                    DispatcherGateway dispatcherGateway,
-                    ScheduledExecutor scheduledExecutor,
-                    Executor mainThreadExecutor,
-                    FatalErrorHandler errorHandler) {
-                this.dispatcherGateway = dispatcherGateway;
-                this.scheduledExecutor = scheduledExecutor;
-                this.mainThreadExecutor = mainThreadExecutor;
-                this.errorHandler = errorHandler;
-            }
-        }
-
-        public static TestingApplication.Builder builder() {
-            return new TestingApplication.Builder();
-        }
-
-        public static class Builder {
-
-            static final Function<ExecuteParams, CompletableFuture<Acknowledge>>
-                    DEFAULT_EXECUTE_FUNCTION =
-                            params -> CompletableFuture.completedFuture(Acknowledge.get());
-            static final Function<Void, Void> DEFAULT_CANCEL_FUNCTION = ignored -> null;
-            static final Function<Void, ApplicationState> DEFAULT_GET_APPLICATION_STATUS_FUNCTION =
-                    ignored -> ApplicationState.RUNNING;
-
-            private ApplicationID applicationId = new ApplicationID();
-            private Function<ExecuteParams, CompletableFuture<Acknowledge>> executeFunction =
-                    DEFAULT_EXECUTE_FUNCTION;
-            private Function<Void, Void> cancelFunction = DEFAULT_CANCEL_FUNCTION;
-            private Function<Void, ApplicationState> getApplicationStatusFunction =
-                    DEFAULT_GET_APPLICATION_STATUS_FUNCTION;
-
-            public Builder setApplicationId(ApplicationID applicationId) {
-                this.applicationId = applicationId;
-                return this;
-            }
-
-            public Builder setExecuteFunction(
-                    Function<ExecuteParams, CompletableFuture<Acknowledge>> executeFunction) {
-                this.executeFunction = executeFunction;
-                return this;
-            }
-
-            public Builder setCancelFunction(Function<Void, Void> cancelFunction) {
-                this.cancelFunction = cancelFunction;
-                return this;
-            }
-
-            public Builder setGetApplicationStatusFunction(
-                    Function<Void, ApplicationState> getApplicationStatusFunction) {
-                this.getApplicationStatusFunction = getApplicationStatusFunction;
-                return this;
-            }
-
-            public TestingApplication build() {
-                return new TestingApplication(
-                        applicationId,
-                        executeFunction,
-                        cancelFunction,
-                        getApplicationStatusFunction);
-            }
-        }
-    }
 }
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/TestingApplication.java b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/TestingApplication.java
new file mode 100644
index 00000000000..f27f1accf8f
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/TestingApplication.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.dispatcher;
+
+import org.apache.flink.api.common.ApplicationID;
+import org.apache.flink.api.common.ApplicationState;
+import org.apache.flink.runtime.application.AbstractApplication;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.rpc.FatalErrorHandler;
+import org.apache.flink.util.concurrent.ScheduledExecutor;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+import java.util.function.Function;
+
+/** {@code TestingApplication} implements {@link AbstractApplication} for testing purposes. */
+public class TestingApplication extends AbstractApplication {
+
+    private final Function<ExecuteParams, CompletableFuture<Acknowledge>> executeFunction;
+    private final Function<Void, Void> cancelFunction;
+    private final Function<Void, ApplicationState> getApplicationStatusFunction;
+
+    private TestingApplication(
+            ApplicationID applicationId,
+            Function<ExecuteParams, CompletableFuture<Acknowledge>> executeFunction,
+            Function<Void, Void> cancelFunction,
+            Function<Void, ApplicationState> getApplicationStatusFunction) {
+        super(applicationId);
+        this.executeFunction = executeFunction;
+        this.cancelFunction = cancelFunction;
+        this.getApplicationStatusFunction = getApplicationStatusFunction;
+    }
+
+    @Override
+    public CompletableFuture<Acknowledge> execute(
+            DispatcherGateway dispatcherGateway,
+            ScheduledExecutor scheduledExecutor,
+            Executor mainThreadExecutor,
+            FatalErrorHandler errorHandler) {
+
+        ExecuteParams params =
+                new ExecuteParams(
+                        dispatcherGateway, scheduledExecutor, mainThreadExecutor, errorHandler);
+        return executeFunction.apply(params);
+    }
+
+    @Override
+    public void cancel() {
+        cancelFunction.apply(null);
+    }
+
+    @Override
+    public void dispose() {}
+
+    @Override
+    public String getName() {
+        return "TestingApplication";
+    }
+
+    @Override
+    public ApplicationState getApplicationStatus() {
+        return getApplicationStatusFunction.apply(null);
+    }
+
+    public static class ExecuteParams {
+        public final DispatcherGateway dispatcherGateway;
+        public final ScheduledExecutor scheduledExecutor;
+        public final Executor mainThreadExecutor;
+        public final FatalErrorHandler errorHandler;
+
+        public ExecuteParams(
+                DispatcherGateway dispatcherGateway,
+                ScheduledExecutor scheduledExecutor,
+                Executor mainThreadExecutor,
+                FatalErrorHandler errorHandler) {
+            this.dispatcherGateway = dispatcherGateway;
+            this.scheduledExecutor = scheduledExecutor;
+            this.mainThreadExecutor = mainThreadExecutor;
+            this.errorHandler = errorHandler;
+        }
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static class Builder {
+
+        static final Function<ExecuteParams, CompletableFuture<Acknowledge>>
+                DEFAULT_EXECUTE_FUNCTION =
+                        params -> CompletableFuture.completedFuture(Acknowledge.get());
+        static final Function<Void, Void> DEFAULT_CANCEL_FUNCTION = ignored -> null;
+        static final Function<Void, ApplicationState> DEFAULT_GET_APPLICATION_STATUS_FUNCTION =
+                ignored -> ApplicationState.RUNNING;
+
+        private ApplicationID applicationId = new ApplicationID();
+        private Function<ExecuteParams, CompletableFuture<Acknowledge>> executeFunction =
+                DEFAULT_EXECUTE_FUNCTION;
+        private Function<Void, Void> cancelFunction = DEFAULT_CANCEL_FUNCTION;
+        private Function<Void, ApplicationState> getApplicationStatusFunction =
+                DEFAULT_GET_APPLICATION_STATUS_FUNCTION;
+
+        public Builder setApplicationId(ApplicationID applicationId) {
+            this.applicationId = applicationId;
+            return this;
+        }
+
+        public Builder setExecuteFunction(
+                Function<ExecuteParams, CompletableFuture<Acknowledge>> executeFunction) {
+            this.executeFunction = executeFunction;
+            return this;
+        }
+
+        public Builder setCancelFunction(Function<Void, Void> cancelFunction) {
+            this.cancelFunction = cancelFunction;
+            return this;
+        }
+
+        public Builder setGetApplicationStatusFunction(
+                Function<Void, ApplicationState> getApplicationStatusFunction) {
+            this.getApplicationStatusFunction = getApplicationStatusFunction;
+            return this;
+        }
+
+        public TestingApplication build() {
+            return new TestingApplication(
+                    applicationId, executeFunction, cancelFunction, getApplicationStatusFunction);
+        }
+    }
+}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/DefaultDispatcherRunnerITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/DefaultDispatcherRunnerITCase.java
index f11a6587a43..ab2b4f595d0 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/DefaultDispatcherRunnerITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/DefaultDispatcherRunnerITCase.java
@@ -21,6 +21,7 @@ package org.apache.flink.runtime.dispatcher.runner;
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.core.testutils.AllCallbackWrapper;
+import org.apache.flink.runtime.application.SingleJobApplication;
 import org.apache.flink.runtime.dispatcher.Dispatcher;
 import org.apache.flink.runtime.dispatcher.DispatcherBootstrapFactory;
 import org.apache.flink.runtime.dispatcher.DispatcherFactory;
@@ -93,6 +94,8 @@ class DefaultDispatcherRunnerITCase {
 
     private JobGraph jobGraph;
 
+    private SingleJobApplication application;
+
     private TestingLeaderElection dispatcherLeaderElection;
 
     private TestingFatalErrorHandler fatalErrorHandler;
@@ -111,6 +114,7 @@ class DefaultDispatcherRunnerITCase {
                 DefaultDispatcherRunnerFactory.createSessionRunner(
                         SessionDispatcherFactory.INSTANCE);
         jobGraph = createJobGraph();
+        application = new SingleJobApplication(jobGraph);
         dispatcherLeaderElection = new TestingLeaderElection();
         fatalErrorHandler = new TestingFatalErrorHandler();
         executionPlanStore = TestingExecutionPlanStore.newBuilder().build();
@@ -139,7 +143,7 @@ class DefaultDispatcherRunnerITCase {
             final DispatcherGateway firstDispatcherGateway =
                     electLeaderAndRetrieveGateway(firstLeaderSessionId);
 
-            firstDispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
+            firstDispatcherGateway.submitApplication(application, TIMEOUT).get();
 
             dispatcherLeaderElection.notLeader();
 
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/ZooKeeperDefaultDispatcherRunnerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/ZooKeeperDefaultDispatcherRunnerTest.java
index 0e4f14d1689..87dfa475795 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/ZooKeeperDefaultDispatcherRunnerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/ZooKeeperDefaultDispatcherRunnerTest.java
@@ -22,6 +22,7 @@ import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.configuration.HighAvailabilityOptions;
 import org.apache.flink.core.testutils.AllCallbackWrapper;
+import org.apache.flink.runtime.application.SingleJobApplication;
 import org.apache.flink.runtime.blob.BlobServer;
 import org.apache.flink.runtime.blob.BlobUtils;
 import org.apache.flink.runtime.blob.PermanentBlobKey;
@@ -210,7 +211,9 @@ class ZooKeeperDefaultDispatcherRunnerTest {
 
                 final JobGraph jobGraph = createJobGraphWithBlobs();
                 LOG.info("Initial job submission {}.", jobGraph.getJobID());
-                dispatcherGateway.submitJob(jobGraph, TESTING_TIMEOUT).get();
+                dispatcherGateway
+                        .submitApplication(new SingleJobApplication(jobGraph), TESTING_TIMEOUT)
+                        .get();
 
                 dispatcherLeaderElection.notLeader();
 
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/TestingJobResultStore.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/TestingJobResultStore.java
index cfe4712efba..5caa830f019 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/TestingJobResultStore.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/TestingJobResultStore.java
@@ -18,6 +18,7 @@
 
 package org.apache.flink.runtime.testutils;
 
+import org.apache.flink.api.common.ApplicationID;
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.runtime.highavailability.JobResultEntry;
@@ -51,6 +52,7 @@ public class TestingJobResultStore implements JobResultStore {
     public static JobResult createJobResult(JobID jobId, @Nullable JobStatus jobStatus) {
         return new JobResult.Builder()
                 .jobId(jobId)
+                .applicationId(ApplicationID.fromHexString(jobId.toHexString()))
                 .jobName(DEFAULT_STREAMING_JOB_NAME)
                 .jobStatus(jobStatus)
                 .netRuntime(1)
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/TestingDispatcherGateway.java b/flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/TestingDispatcherGateway.java
index 6e9362aba00..d18116fd079 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/TestingDispatcherGateway.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/TestingDispatcherGateway.java
@@ -65,6 +65,8 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
 
     static final Function<ExecutionPlan, CompletableFuture<Acknowledge>> DEFAULT_SUBMIT_FUNCTION =
             jobGraph -> CompletableFuture.completedFuture(Acknowledge.get());
+    static final Function<JobID, CompletableFuture<Acknowledge>> DEFAULT_RECOVER_JOB_FUNCTION =
+            jobId -> CompletableFuture.completedFuture(Acknowledge.get());
     static final Function<AbstractApplication, CompletableFuture<Acknowledge>>
             DEFAULT_SUBMIT_APPLICATION_FUNCTION =
                     application -> CompletableFuture.completedFuture(Acknowledge.get());
@@ -97,6 +99,7 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
                             FutureUtils.completedExceptionally(new UnsupportedOperationException());
 
     private final Function<ExecutionPlan, CompletableFuture<Acknowledge>> submitFunction;
+    private final Function<JobID, CompletableFuture<Acknowledge>> recoverJobFunction;
     private final Function<AbstractApplication, CompletableFuture<Acknowledge>>
             submitApplicationFunction;
     private final TriFunction<JobID, String, Throwable, CompletableFuture<Acknowledge>>
@@ -120,6 +123,7 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
     public TestingDispatcherGateway() {
         super();
         submitFunction = DEFAULT_SUBMIT_FUNCTION;
+        recoverJobFunction = DEFAULT_RECOVER_JOB_FUNCTION;
         submitApplicationFunction = DEFAULT_SUBMIT_APPLICATION_FUNCTION;
         submitFailedFunction = DEFAULT_SUBMIT_FAILED_FUNCTION;
         listFunction = DEFAULT_LIST_FUNCTION;
@@ -183,6 +187,7 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
             BiFunction<JobID, CheckpointType, CompletableFuture<Long>>
                     triggerCheckpointAndGetCheckpointIdFunction,
             Function<ExecutionPlan, CompletableFuture<Acknowledge>> submitFunction,
+            Function<JobID, CompletableFuture<Acknowledge>> recoverJobFunction,
             Function<AbstractApplication, CompletableFuture<Acknowledge>> submitApplicationFunction,
             TriFunction<JobID, String, Throwable, CompletableFuture<Acknowledge>>
                     submitFailedFunction,
@@ -224,6 +229,7 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
                 clusterShutdownSupplier,
                 deliverCoordinationRequestToCoordinatorFunction);
         this.submitFunction = submitFunction;
+        this.recoverJobFunction = recoverJobFunction;
         this.submitApplicationFunction = submitApplicationFunction;
         this.submitFailedFunction = submitFailedFunction;
         this.listFunction = listFunction;
@@ -247,6 +253,11 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
         return submitFunction.apply(executionPlan);
     }
 
+    @Override
+    public CompletableFuture<Acknowledge> recoverJob(JobID jobId, Duration timeout) {
+        return recoverJobFunction.apply(jobId);
+    }
+
     @Override
     public CompletableFuture<Acknowledge> submitApplication(
             AbstractApplication application, Duration timeout) {
@@ -323,6 +334,7 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
     public static final class Builder extends TestingRestfulGateway.AbstractBuilder<Builder> {
 
         private Function<ExecutionPlan, CompletableFuture<Acknowledge>> submitFunction;
+        private Function<JobID, CompletableFuture<Acknowledge>> recoverJobFunction;
         private Function<AbstractApplication, CompletableFuture<Acknowledge>>
                 submitApplicationFunction;
         private TriFunction<JobID, String, Throwable, CompletableFuture<Acknowledge>>
@@ -352,6 +364,12 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
             return this;
         }
 
+        public Builder setRecoverJobFunction(
+                Function<JobID, CompletableFuture<Acknowledge>> recoverJobFunction) {
+            this.recoverJobFunction = recoverJobFunction;
+            return this;
+        }
+
         public Builder setSubmitApplicationFunction(
                 Function<AbstractApplication, CompletableFuture<Acknowledge>>
                         submitApplicationFunction) {
@@ -456,6 +474,7 @@ public final class TestingDispatcherGateway extends TestingRestfulGateway
                     getSavepointStatusFunction,
                     triggerCheckpointAndGetCheckpointIdFunction,
                     submitFunction,
+                    recoverJobFunction,
                     submitApplicationFunction,
                     submitFailedFunction,
                     listFunction,