Search in sources :

Example 16 with DispatcherGateway

use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.

the class JobSubmitHandlerTest method testSerializationFailureHandling.

@Test
public void testSerializationFailureHandling() throws Exception {
    final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
    DispatcherGateway mockGateway = TestingDispatcherGateway.newBuilder().setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get())).build();
    JobSubmitHandler handler = new JobSubmitHandler(() -> CompletableFuture.completedFuture(mockGateway), RpcUtils.INF_TIMEOUT, Collections.emptyMap(), TestingUtils.defaultExecutor(), configuration);
    JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.toString(), Collections.emptyList(), Collections.emptyList());
    try {
        handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance()), mockGateway);
        Assert.fail();
    } catch (RestHandlerException rhe) {
        Assert.assertEquals(HttpResponseStatus.BAD_REQUEST, rhe.getHttpResponseStatus());
    }
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) BlobServer(org.apache.flink.runtime.blob.BlobServer) Tuple2(org.apache.flink.api.java.tuple.Tuple2) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) RunWith(org.junit.runner.RunWith) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) ArrayList(java.util.ArrayList) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) After(org.junit.After) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) ObjectOutputStream(java.io.ObjectOutputStream) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Parameterized(org.junit.runners.Parameterized) JobSubmitRequestBody(org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody) Before(org.junit.Before) VoidBlobStore(org.apache.flink.runtime.blob.VoidBlobStore) Files(java.nio.file.Files) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.Test) IOException(java.io.IOException) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) DistributedCache(org.apache.flink.api.common.cache.DistributedCache) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest) TestingUtils(org.apache.flink.testutils.TestingUtils) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) JobSubmitRequestBody(org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest)

Example 17 with DispatcherGateway

use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.

the class JobSubmitHandlerTest method testSuccessfulJobSubmission.

@Test
public void testSuccessfulJobSubmission() throws Exception {
    final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
    try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
        objectOut.writeObject(JobGraphTestUtils.emptyJobGraph());
    }
    TestingDispatcherGateway.Builder builder = TestingDispatcherGateway.newBuilder();
    builder.setBlobServerPort(blobServer.getPort()).setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get())).setHostname("localhost");
    DispatcherGateway mockGateway = builder.build();
    JobSubmitHandler handler = new JobSubmitHandler(() -> CompletableFuture.completedFuture(mockGateway), RpcUtils.INF_TIMEOUT, Collections.emptyMap(), TestingUtils.defaultExecutor(), configuration);
    JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());
    handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance(), Collections.singleton(jobGraphFile.toFile())), mockGateway).get();
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) BlobServer(org.apache.flink.runtime.blob.BlobServer) Tuple2(org.apache.flink.api.java.tuple.Tuple2) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) RunWith(org.junit.runner.RunWith) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) ArrayList(java.util.ArrayList) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) After(org.junit.After) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) ObjectOutputStream(java.io.ObjectOutputStream) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Parameterized(org.junit.runners.Parameterized) JobSubmitRequestBody(org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody) Before(org.junit.Before) VoidBlobStore(org.apache.flink.runtime.blob.VoidBlobStore) Files(java.nio.file.Files) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.Test) IOException(java.io.IOException) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) DistributedCache(org.apache.flink.api.common.cache.DistributedCache) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest) TestingUtils(org.apache.flink.testutils.TestingUtils) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) JobSubmitRequestBody(org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody) ObjectOutputStream(java.io.ObjectOutputStream) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Test(org.junit.Test) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest)

Example 18 with DispatcherGateway

use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.

the class AbstractMetricsHandlerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final MetricStore metricStore = new MetricStore();
    metricStore.add(new MetricDump.CounterDump(new QueryScopeInfo.JobManagerQueryScopeInfo(), TEST_METRIC_NAME, TEST_METRIC_VALUE));
    when(mockMetricFetcher.getMetricStore()).thenReturn(metricStore);
    testMetricsHandler = new TestMetricsHandler(new GatewayRetriever<DispatcherGateway>() {

        @Override
        public CompletableFuture<DispatcherGateway> getFuture() {
            return CompletableFuture.completedFuture(mockDispatcherGateway);
        }
    }, Time.milliseconds(50), Collections.emptyMap(), new TestMetricsHeaders(), mockMetricFetcher);
}
Also used : MetricStore(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore) MetricDump(org.apache.flink.runtime.metrics.dump.MetricDump) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Before(org.junit.Before)

Example 19 with DispatcherGateway

use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.

the class MetricsHandlerTestBase method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    this.leaderRetriever = new GatewayRetriever<DispatcherGateway>() {

        @Override
        public CompletableFuture<DispatcherGateway> getFuture() {
            return CompletableFuture.completedFuture(mockDispatcherGateway);
        }
    };
    this.pathParameters = getPathParameters();
    this.metricsHandler = getMetricsHandler();
    final MetricStore metricStore = new MetricStore();
    metricStore.add(new MetricDump.CounterDump(getQueryScopeInfo(), TEST_METRIC_NAME, TEST_METRIC_VALUE));
    when(mockMetricFetcher.getMetricStore()).thenReturn(metricStore);
}
Also used : MetricStore(org.apache.flink.runtime.rest.handler.legacy.metrics.MetricStore) CompletableFuture(java.util.concurrent.CompletableFuture) MetricDump(org.apache.flink.runtime.metrics.dump.MetricDump) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Before(org.junit.Before)

Example 20 with DispatcherGateway

use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.

the class DefaultDispatcherRunnerITCase method leaderChange_withBlockingJobManagerTermination_doesNotAffectNewLeader.

/**
 * See FLINK-11843. This is a probabilistic test which needs to be executed several times to
 * fail.
 */
@Test
public void leaderChange_withBlockingJobManagerTermination_doesNotAffectNewLeader() throws Exception {
    final TestingJobMasterServiceLeadershipRunnerFactory jobManagerRunnerFactory = new TestingJobMasterServiceLeadershipRunnerFactory(1);
    final TestingCleanupRunnerFactory cleanupRunnerFactory = new TestingCleanupRunnerFactory();
    dispatcherRunnerFactory = DefaultDispatcherRunnerFactory.createSessionRunner(new TestingDispatcherFactory(jobManagerRunnerFactory, cleanupRunnerFactory));
    jobGraphStore = new SingleJobJobGraphStore(jobGraph);
    try (final DispatcherRunner dispatcherRunner = createDispatcherRunner()) {
        // initial run
        dispatcherLeaderElectionService.isLeader(UUID.randomUUID()).get();
        final TestingJobManagerRunner testingJobManagerRunner = jobManagerRunnerFactory.takeCreatedJobManagerRunner();
        dispatcherLeaderElectionService.notLeader();
        LOG.info("Re-grant leadership first time.");
        dispatcherLeaderElectionService.isLeader(UUID.randomUUID());
        // give the Dispatcher some time to recover jobs
        Thread.sleep(1L);
        dispatcherLeaderElectionService.notLeader();
        LOG.info("Re-grant leadership second time.");
        final UUID leaderSessionId = UUID.randomUUID();
        final CompletableFuture<UUID> leaderFuture = dispatcherLeaderElectionService.isLeader(leaderSessionId);
        assertThat(leaderFuture.isDone(), is(false));
        LOG.info("Complete the termination of the first job manager runner.");
        testingJobManagerRunner.completeTerminationFuture();
        assertThat(leaderFuture.get(TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS), is(equalTo(leaderSessionId)));
        // Wait for job to recover...
        final DispatcherGateway leaderGateway = rpcServiceResource.getTestingRpcService().connect(dispatcherLeaderElectionService.getAddress(), DispatcherId.fromUuid(leaderSessionId), DispatcherGateway.class).get();
        assertEquals(jobGraph.getJobID(), Iterables.getOnlyElement(leaderGateway.listJobs(TIMEOUT).get()));
    }
}
Also used : TestingJobMasterServiceLeadershipRunnerFactory(org.apache.flink.runtime.dispatcher.TestingJobMasterServiceLeadershipRunnerFactory) SingleJobJobGraphStore(org.apache.flink.runtime.dispatcher.SingleJobJobGraphStore) TestingCleanupRunnerFactory(org.apache.flink.runtime.dispatcher.cleanup.TestingCleanupRunnerFactory) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) UUID(java.util.UUID) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Test(org.junit.Test)

Aggregations

DispatcherGateway (org.apache.flink.runtime.dispatcher.DispatcherGateway)23 Configuration (org.apache.flink.configuration.Configuration)15 CompletableFuture (java.util.concurrent.CompletableFuture)14 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)11 ExceptionUtils (org.apache.flink.util.ExceptionUtils)11 Collections (java.util.Collections)10 TestingDispatcherGateway (org.apache.flink.runtime.webmonitor.TestingDispatcherGateway)10 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)10 Test (org.junit.Test)10 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)9 JobID (org.apache.flink.api.common.JobID)7 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 Duration (java.time.Duration)6 Optional (java.util.Optional)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 Before (org.junit.Before)6 ObjectOutputStream (java.io.ObjectOutputStream)5 Files (java.nio.file.Files)5 ArrayList (java.util.ArrayList)5