Search in sources :

Example 1 with BlobClient

use of org.apache.flink.runtime.blob.BlobClient in project flink by apache.

the class JobSubmitTest method testFailureWhenJarBlobsMissing.

@Test
public void testFailureWhenJarBlobsMissing() {
    try {
        // create a simple job graph
        JobVertex jobVertex = new JobVertex("Test Vertex");
        jobVertex.setInvokableClass(NoOpInvokable.class);
        JobGraph jg = new JobGraph("test job", jobVertex);
        // request the blob port from the job manager
        Future<Object> future = jmGateway.ask(JobManagerMessages.getRequestBlobManagerPort(), timeout);
        int blobPort = (Integer) Await.result(future, timeout);
        // upload two dummy bytes and add their keys to the job graph as dependencies
        BlobKey key1, key2;
        BlobClient bc = new BlobClient(new InetSocketAddress("localhost", blobPort), jmConfig);
        try {
            key1 = bc.put(new byte[10]);
            key2 = bc.put(new byte[10]);
            // delete one of the blobs to make sure that the startup failed
            bc.delete(key2);
        } finally {
            bc.close();
        }
        jg.addBlob(key1);
        jg.addBlob(key2);
        // submit the job
        Future<Object> submitFuture = jmGateway.ask(new JobManagerMessages.SubmitJob(jg, ListeningBehaviour.EXECUTION_RESULT), timeout);
        try {
            Await.result(submitFuture, timeout);
        } catch (JobExecutionException e) {
            // that is what we expect
            assertTrue(e.getCause() instanceof IOException);
        } catch (Exception e) {
            fail("Wrong exception type");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : BlobClient(org.apache.flink.runtime.blob.BlobClient) InetSocketAddress(java.net.InetSocketAddress) JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) IOException(java.io.IOException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) IOException(java.io.IOException) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) BlobKey(org.apache.flink.runtime.blob.BlobKey) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) Test(org.junit.Test)

Example 2 with BlobClient

use of org.apache.flink.runtime.blob.BlobClient in project flink by apache.

the class ClientUtilsTest method uploadAndSetUserArtifacts.

@Test
public void uploadAndSetUserArtifacts() throws Exception {
    java.nio.file.Path tmpDir = temporaryFolder.newFolder().toPath();
    JobGraph jobGraph = JobGraphTestUtils.emptyJobGraph();
    Collection<DistributedCache.DistributedCacheEntry> localArtifacts = Arrays.asList(new DistributedCache.DistributedCacheEntry(Files.createFile(tmpDir.resolve("art1")).toString(), true, true), new DistributedCache.DistributedCacheEntry(Files.createFile(tmpDir.resolve("art2")).toString(), true, false), new DistributedCache.DistributedCacheEntry(Files.createFile(tmpDir.resolve("art3")).toString(), false, true), new DistributedCache.DistributedCacheEntry(Files.createFile(tmpDir.resolve("art4")).toString(), true, false));
    Collection<DistributedCache.DistributedCacheEntry> distributedArtifacts = Arrays.asList(new DistributedCache.DistributedCacheEntry("hdfs://localhost:1234/test", true, false));
    for (DistributedCache.DistributedCacheEntry entry : localArtifacts) {
        jobGraph.addUserArtifact(entry.filePath, entry);
    }
    for (DistributedCache.DistributedCacheEntry entry : distributedArtifacts) {
        jobGraph.addUserArtifact(entry.filePath, entry);
    }
    final int totalNumArtifacts = localArtifacts.size() + distributedArtifacts.size();
    assertEquals(totalNumArtifacts, jobGraph.getUserArtifacts().size());
    assertEquals(0, jobGraph.getUserArtifacts().values().stream().filter(entry -> entry.blobKey != null).count());
    ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(new InetSocketAddress("localhost", blobServer.getPort()), new Configuration()));
    assertEquals(totalNumArtifacts, jobGraph.getUserArtifacts().size());
    assertEquals(localArtifacts.size(), jobGraph.getUserArtifacts().values().stream().filter(entry -> entry.blobKey != null).count());
    assertEquals(distributedArtifacts.size(), jobGraph.getUserArtifacts().values().stream().filter(entry -> entry.blobKey == null).count());
    // 1 unique key for each local artifact, and null for distributed artifacts
    assertEquals(localArtifacts.size() + 1, jobGraph.getUserArtifacts().values().stream().map(entry -> entry.blobKey).distinct().count());
    for (DistributedCache.DistributedCacheEntry original : localArtifacts) {
        assertState(original, jobGraph.getUserArtifacts().get(original.filePath), false, jobGraph.getJobID());
    }
    for (DistributedCache.DistributedCacheEntry original : distributedArtifacts) {
        assertState(original, jobGraph.getUserArtifacts().get(original.filePath), true, jobGraph.getJobID());
    }
}
Also used : AfterClass(org.junit.AfterClass) Arrays(java.util.Arrays) VoidBlobStore(org.apache.flink.runtime.blob.VoidBlobStore) BlobServer(org.apache.flink.runtime.blob.BlobServer) BeforeClass(org.junit.BeforeClass) Files(java.nio.file.Files) Collection(java.util.Collection) Configuration(org.apache.flink.configuration.Configuration) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) Test(org.junit.Test) IOException(java.io.IOException) DistributedCache(org.apache.flink.api.common.cache.DistributedCache) InetSocketAddress(java.net.InetSocketAddress) InstantiationUtil(org.apache.flink.util.InstantiationUtil) JobID(org.apache.flink.api.common.JobID) Path(org.apache.flink.core.fs.Path) PermanentBlobKey(org.apache.flink.runtime.blob.PermanentBlobKey) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) TestLogger(org.apache.flink.util.TestLogger) BlobClient(org.apache.flink.runtime.blob.BlobClient) ClassRule(org.junit.ClassRule) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) BlobClient(org.apache.flink.runtime.blob.BlobClient) Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) DistributedCache(org.apache.flink.api.common.cache.DistributedCache) Test(org.junit.Test)

Example 3 with BlobClient

use of org.apache.flink.runtime.blob.BlobClient in project flink by apache.

the class ClientUtilsTest method uploadAndSetUserJars.

@Test
public void uploadAndSetUserJars() throws Exception {
    java.nio.file.Path tmpDir = temporaryFolder.newFolder().toPath();
    JobGraph jobGraph = JobGraphTestUtils.emptyJobGraph();
    Collection<Path> jars = Arrays.asList(new Path(Files.createFile(tmpDir.resolve("jar1.jar")).toString()), new Path(Files.createFile(tmpDir.resolve("jar2.jar")).toString()));
    jars.forEach(jobGraph::addJar);
    assertEquals(jars.size(), jobGraph.getUserJars().size());
    assertEquals(0, jobGraph.getUserJarBlobKeys().size());
    ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(new InetSocketAddress("localhost", blobServer.getPort()), new Configuration()));
    assertEquals(jars.size(), jobGraph.getUserJars().size());
    assertEquals(jars.size(), jobGraph.getUserJarBlobKeys().size());
    assertEquals(jars.size(), jobGraph.getUserJarBlobKeys().stream().distinct().count());
    for (PermanentBlobKey blobKey : jobGraph.getUserJarBlobKeys()) {
        blobServer.getFile(jobGraph.getJobID(), blobKey);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) BlobClient(org.apache.flink.runtime.blob.BlobClient) Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) PermanentBlobKey(org.apache.flink.runtime.blob.PermanentBlobKey) Test(org.junit.Test)

Example 4 with BlobClient

use of org.apache.flink.runtime.blob.BlobClient in project flink by apache.

the class EmbeddedExecutor method submitJob.

private static CompletableFuture<JobID> submitJob(final Configuration configuration, final DispatcherGateway dispatcherGateway, final JobGraph jobGraph, final Time rpcTimeout) {
    checkNotNull(jobGraph);
    LOG.info("Submitting Job with JobId={}.", jobGraph.getJobID());
    return dispatcherGateway.getBlobServerPort(rpcTimeout).thenApply(blobServerPort -> new InetSocketAddress(dispatcherGateway.getHostname(), blobServerPort)).thenCompose(blobServerAddress -> {
        try {
            ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(blobServerAddress, configuration));
        } catch (FlinkException e) {
            throw new CompletionException(e);
        }
        return dispatcherGateway.submitJob(jobGraph, rpcTimeout);
    }).thenApply(ack -> jobGraph.getJobID());
}
Also used : FlinkException(org.apache.flink.util.FlinkException) PipelineExecutorUtils(org.apache.flink.client.deployment.executors.PipelineExecutorUtils) Pipeline(org.apache.flink.api.dag.Pipeline) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) PipelineExecutor(org.apache.flink.core.execution.PipelineExecutor) PipelineOptionsInternal(org.apache.flink.configuration.PipelineOptionsInternal) FunctionUtils(org.apache.flink.util.function.FunctionUtils) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) ClientOptions(org.apache.flink.client.cli.ClientOptions) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Collection(java.util.Collection) Configuration(org.apache.flink.configuration.Configuration) CompletionException(java.util.concurrent.CompletionException) ClientUtils(org.apache.flink.runtime.client.ClientUtils) InetSocketAddress(java.net.InetSocketAddress) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Optional(java.util.Optional) Internal(org.apache.flink.annotation.Internal) BlobClient(org.apache.flink.runtime.blob.BlobClient) Time(org.apache.flink.api.common.time.Time) BlobClient(org.apache.flink.runtime.blob.BlobClient) InetSocketAddress(java.net.InetSocketAddress) CompletionException(java.util.concurrent.CompletionException) FlinkException(org.apache.flink.util.FlinkException)

Example 5 with BlobClient

use of org.apache.flink.runtime.blob.BlobClient in project flink by apache.

the class JobGraph method uploadRequiredJarFiles.

/**
	 * Uploads the previously added user jar file to the job manager through the job manager's BLOB server.
	 *
	 * @param serverAddress
	 *        the network address of the BLOB server
	 * @param blobClientConfig
	 *        the blob client configuration
	 * @throws IOException
	 *         thrown if an I/O error occurs during the upload
	 */
public void uploadRequiredJarFiles(InetSocketAddress serverAddress, Configuration blobClientConfig) throws IOException {
    if (this.userJars.isEmpty()) {
        return;
    }
    BlobClient bc = null;
    try {
        bc = new BlobClient(serverAddress, blobClientConfig);
        for (final Path jar : this.userJars) {
            final FileSystem fs = jar.getFileSystem();
            FSDataInputStream is = null;
            try {
                is = fs.open(jar);
                final BlobKey key = bc.put(is);
                this.userJarBlobKeys.add(key);
            } finally {
                if (is != null) {
                    is.close();
                }
            }
        }
    } finally {
        if (bc != null) {
            bc.close();
        }
    }
}
Also used : Path(org.apache.flink.core.fs.Path) BlobKey(org.apache.flink.runtime.blob.BlobKey) BlobClient(org.apache.flink.runtime.blob.BlobClient) FileSystem(org.apache.flink.core.fs.FileSystem) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream)

Aggregations

BlobClient (org.apache.flink.runtime.blob.BlobClient)5 InetSocketAddress (java.net.InetSocketAddress)4 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)4 Configuration (org.apache.flink.configuration.Configuration)3 Path (org.apache.flink.core.fs.Path)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 JobID (org.apache.flink.api.common.JobID)2 BlobKey (org.apache.flink.runtime.blob.BlobKey)2 PermanentBlobKey (org.apache.flink.runtime.blob.PermanentBlobKey)2 MalformedURLException (java.net.MalformedURLException)1 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Internal (org.apache.flink.annotation.Internal)1 DistributedCache (org.apache.flink.api.common.cache.DistributedCache)1 Time (org.apache.flink.api.common.time.Time)1