Search in sources :

Example 1 with JobSubmitRequestBody

use of org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody in project flink by apache.

the class JobSubmitHandler method handleRequest.

@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
    final Collection<File> uploadedFiles = request.getUploadedFiles();
    final Map<String, Path> nameToFile = uploadedFiles.stream().collect(Collectors.toMap(File::getName, Path::fromLocalFile));
    if (uploadedFiles.size() != nameToFile.size()) {
        throw new RestHandlerException(String.format("The number of uploaded files was %s than the expected count. Expected: %s Actual %s", uploadedFiles.size() < nameToFile.size() ? "lower" : "higher", nameToFile.size(), uploadedFiles.size()), HttpResponseStatus.BAD_REQUEST);
    }
    final JobSubmitRequestBody requestBody = request.getRequestBody();
    if (requestBody.jobGraphFileName == null) {
        throw new RestHandlerException(String.format("The %s field must not be omitted or be null.", JobSubmitRequestBody.FIELD_NAME_JOB_GRAPH), HttpResponseStatus.BAD_REQUEST);
    }
    CompletableFuture<JobGraph> jobGraphFuture = loadJobGraph(requestBody, nameToFile);
    Collection<Path> jarFiles = getJarFilesToUpload(requestBody.jarFileNames, nameToFile);
    Collection<Tuple2<String, Path>> artifacts = getArtifactFilesToUpload(requestBody.artifactFileNames, nameToFile);
    CompletableFuture<JobGraph> finalizedJobGraphFuture = uploadJobGraphFiles(gateway, jobGraphFuture, jarFiles, artifacts, configuration);
    CompletableFuture<Acknowledge> jobSubmissionFuture = finalizedJobGraphFuture.thenCompose(jobGraph -> gateway.submitJob(jobGraph, timeout));
    return jobSubmissionFuture.thenCombine(jobGraphFuture, (ack, jobGraph) -> new JobSubmitResponseBody("/jobs/" + jobGraph.getJobID()));
}
Also used : Path(org.apache.flink.core.fs.Path) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) JobSubmitResponseBody(org.apache.flink.runtime.rest.messages.job.JobSubmitResponseBody) JobSubmitRequestBody(org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) Tuple2(org.apache.flink.api.java.tuple.Tuple2) File(java.io.File)

Example 2 with JobSubmitRequestBody

use of org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody in project flink by apache.

the class JobSubmitHandlerTest method testFailedJobSubmission.

@Test
public void testFailedJobSubmission() throws Exception {
    final String errorMessage = "test";
    DispatcherGateway mockGateway = TestingDispatcherGateway.newBuilder().setSubmitFunction(jobgraph -> FutureUtils.completedExceptionally(new Exception(errorMessage))).build();
    JobSubmitHandler handler = new JobSubmitHandler(() -> CompletableFuture.completedFuture(mockGateway), RpcUtils.INF_TIMEOUT, Collections.emptyMap(), TestingUtils.defaultExecutor(), configuration);
    final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
    JobGraph jobGraph = JobGraphTestUtils.emptyJobGraph();
    try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
        objectOut.writeObject(jobGraph);
    }
    JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());
    try {
        handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance(), Collections.singletonList(jobGraphFile.toFile())), mockGateway).get();
    } catch (Exception e) {
        Throwable t = ExceptionUtils.stripExecutionException(e);
        Assert.assertEquals(errorMessage, t.getMessage());
    }
}
Also used : 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) Path(java.nio.file.Path) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) 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) IOException(java.io.IOException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest)

Example 3 with JobSubmitRequestBody

use of org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody in project flink by apache.

the class JobSubmitHandlerTest method testFileHandling.

@Test
public void testFileHandling() throws Exception {
    final String dcEntryName = "entry";
    CompletableFuture<JobGraph> submittedJobGraphFuture = new CompletableFuture<>();
    DispatcherGateway dispatcherGateway = TestingDispatcherGateway.newBuilder().setBlobServerPort(blobServer.getPort()).setSubmitFunction(submittedJobGraph -> {
        submittedJobGraphFuture.complete(submittedJobGraph);
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).build();
    JobSubmitHandler handler = new JobSubmitHandler(() -> CompletableFuture.completedFuture(dispatcherGateway), RpcUtils.INF_TIMEOUT, Collections.emptyMap(), TestingUtils.defaultExecutor(), configuration);
    final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
    final Path jarFile = TEMPORARY_FOLDER.newFile().toPath();
    final Path artifactFile = TEMPORARY_FOLDER.newFile().toPath();
    final JobGraph jobGraph = JobGraphTestUtils.emptyJobGraph();
    // the entry that should be updated
    jobGraph.addUserArtifact(dcEntryName, new DistributedCache.DistributedCacheEntry("random", false));
    try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
        objectOut.writeObject(jobGraph);
    }
    JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.singletonList(jarFile.getFileName().toString()), Collections.singleton(new JobSubmitRequestBody.DistributedCacheFile(dcEntryName, artifactFile.getFileName().toString())));
    handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance(), Arrays.asList(jobGraphFile.toFile(), jarFile.toFile(), artifactFile.toFile())), dispatcherGateway).get();
    Assert.assertTrue("No JobGraph was submitted.", submittedJobGraphFuture.isDone());
    final JobGraph submittedJobGraph = submittedJobGraphFuture.get();
    Assert.assertEquals(1, submittedJobGraph.getUserJarBlobKeys().size());
    Assert.assertEquals(1, submittedJobGraph.getUserArtifacts().size());
    Assert.assertNotNull(submittedJobGraph.getUserArtifacts().get(dcEntryName).blobKey);
}
Also used : 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) Path(java.nio.file.Path) 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) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CompletableFuture(java.util.concurrent.CompletableFuture) DistributedCache(org.apache.flink.api.common.cache.DistributedCache) Test(org.junit.Test) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest)

Example 4 with JobSubmitRequestBody

use of org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody in project flink by apache.

the class JobSubmitHandlerTest method testRejectionOnCountMismatch.

@Test
public void testRejectionOnCountMismatch() throws Exception {
    final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
    try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
        objectOut.writeObject(JobGraphTestUtils.emptyJobGraph());
    }
    final Path countExceedingFile = TEMPORARY_FOLDER.newFile().toPath();
    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());
    try {
        handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance(), Arrays.asList(jobGraphFile.toFile(), countExceedingFile.toFile())), mockGateway).get();
    } catch (Exception e) {
        ExceptionUtils.findThrowable(e, candidate -> candidate instanceof RestHandlerException && candidate.getMessage().contains("count"));
    }
}
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) IOException(java.io.IOException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test) SSLUtilsTest(org.apache.flink.runtime.net.SSLUtilsTest)

Example 5 with JobSubmitRequestBody

use of org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody 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)

Aggregations

Tuple2 (org.apache.flink.api.java.tuple.Tuple2)7 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)7 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)7 JobSubmitRequestBody (org.apache.flink.runtime.rest.messages.job.JobSubmitRequestBody)7 IOException (java.io.IOException)6 ObjectOutputStream (java.io.ObjectOutputStream)6 Files (java.nio.file.Files)6 ArrayList (java.util.ArrayList)6 Collections (java.util.Collections)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 DistributedCache (org.apache.flink.api.common.cache.DistributedCache)6 Configuration (org.apache.flink.configuration.Configuration)6 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)6 EmptyMessageParameters (org.apache.flink.runtime.rest.messages.EmptyMessageParameters)6 HttpResponseStatus (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus)6 ExceptionUtils (org.apache.flink.util.ExceptionUtils)6 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)6 Path (java.nio.file.Path)5 Arrays (java.util.Arrays)5 BlobServer (org.apache.flink.runtime.blob.BlobServer)5