org.apache.flink.runtime.blob.BlobClient Java Examples

The following examples show how to use org.apache.flink.runtime.blob.BlobClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobSubmitHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<JobGraph> uploadJobGraphFiles(
		DispatcherGateway gateway,
		CompletableFuture<JobGraph> jobGraphFuture,
		Collection<Path> jarFiles,
		Collection<Tuple2<String, Path>> artifacts,
		Configuration configuration) {
	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	return jobGraphFuture.thenCombine(blobServerPortFuture, (JobGraph jobGraph, Integer blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.uploadJobGraphFiles(jobGraph, jarFiles, artifacts, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(new RestHandlerException(
				"Could not upload job files.",
				HttpResponseStatus.INTERNAL_SERVER_ERROR,
				e));
		}
		return jobGraph;
	});
}
 
Example #2
Source File: ClientUtilsTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void uploadAndSetUserJars() throws Exception {
	java.nio.file.Path tmpDir = temporaryFolder.newFolder().toPath();
	JobGraph jobGraph = new JobGraph();

	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);
	}
}
 
Example #3
Source File: JobSubmitHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<JobGraph> uploadJobGraphFiles(
		DispatcherGateway gateway,
		CompletableFuture<JobGraph> jobGraphFuture,
		Collection<Path> jarFiles,
		Collection<Tuple2<String, Path>> artifacts,
		Configuration configuration) {
	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	return jobGraphFuture.thenCombine(blobServerPortFuture, (JobGraph jobGraph, Integer blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.uploadJobGraphFiles(jobGraph, jarFiles, artifacts, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(new RestHandlerException(
				"Could not upload job files.",
				HttpResponseStatus.INTERNAL_SERVER_ERROR,
				e));
		}
		return jobGraph;
	});
}
 
Example #4
Source File: ClientUtilsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void uploadAndSetUserJars() throws Exception {
	java.nio.file.Path tmpDir = temporaryFolder.newFolder().toPath();
	JobGraph jobGraph = new JobGraph();

	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);
	}
}
 
Example #5
Source File: JobSubmitHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<JobGraph> uploadJobGraphFiles(
		DispatcherGateway gateway,
		CompletableFuture<JobGraph> jobGraphFuture,
		Collection<Path> jarFiles,
		Collection<Tuple2<String, Path>> artifacts,
		Configuration configuration) {
	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	return jobGraphFuture.thenCombine(blobServerPortFuture, (JobGraph jobGraph, Integer blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.uploadJobGraphFiles(jobGraph, jarFiles, artifacts, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(new RestHandlerException(
				"Could not upload job files.",
				HttpResponseStatus.INTERNAL_SERVER_ERROR,
				e));
		}
		return jobGraph;
	});
}
 
Example #6
Source File: ClientUtilsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void uploadAndSetUserJars() throws Exception {
	java.nio.file.Path tmpDir = temporaryFolder.newFolder().toPath();
	JobGraph jobGraph = new JobGraph();

	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);
	}
}
 
Example #7
Source File: EmbeddedExecutor.java    From flink with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #8
Source File: JarRunHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JarRunResponseBody> handleRequest(
		@Nonnull final HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request,
		@Nonnull final DispatcherGateway gateway) throws RestHandlerException {
	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);

	final SavepointRestoreSettings savepointRestoreSettings = getSavepointRestoreSettings(request);

	final CompletableFuture<JobGraph> jobGraphFuture = getJobGraphAsync(context, savepointRestoreSettings);

	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	CompletableFuture<JobGraph> jarUploadFuture = jobGraphFuture.thenCombine(blobServerPortFuture, (jobGraph, blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(e);
		}

		return jobGraph;
	});

	CompletableFuture<Acknowledge> jobSubmissionFuture = jarUploadFuture.thenCompose(jobGraph -> {
		// we have to enable queued scheduling because slots will be allocated lazily
		jobGraph.setAllowQueuedScheduling(true);
		return gateway.submitJob(jobGraph, timeout);
	});

	return jobSubmissionFuture
		.thenCombine(jarUploadFuture, (ack, jobGraph) -> new JarRunResponseBody(jobGraph.getJobID()));
}
 
Example #9
Source File: MiniCluster.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Void> uploadAndSetJobFiles(final CompletableFuture<InetSocketAddress> blobServerAddressFuture, final JobGraph job) {
	return blobServerAddressFuture.thenAccept(blobServerAddress -> {
		try {
			ClientUtils.extractAndUploadJobGraphFiles(job, () -> new BlobClient(blobServerAddress, miniClusterConfiguration.getConfiguration()));
		} catch (FlinkException e) {
			throw new CompletionException(e);
		}
	});
}
 
Example #10
Source File: JarRunHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JarRunResponseBody> handleRequest(
		@Nonnull final HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request,
		@Nonnull final DispatcherGateway gateway) throws RestHandlerException {
	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);

	final SavepointRestoreSettings savepointRestoreSettings = getSavepointRestoreSettings(request);

	final CompletableFuture<JobGraph> jobGraphFuture = getJobGraphAsync(context, savepointRestoreSettings);

	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	CompletableFuture<JobGraph> jarUploadFuture = jobGraphFuture.thenCombine(blobServerPortFuture, (jobGraph, blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(e);
		}

		return jobGraph;
	});

	CompletableFuture<Acknowledge> jobSubmissionFuture = jarUploadFuture.thenCompose(jobGraph -> {
		// we have to enable queued scheduling because slots will be allocated lazily
		jobGraph.setAllowQueuedScheduling(true);
		return gateway.submitJob(jobGraph, timeout);
	});

	return jobSubmissionFuture
		.thenCombine(jarUploadFuture, (ack, jobGraph) -> new JarRunResponseBody(jobGraph.getJobID()));
}
 
Example #11
Source File: MiniCluster.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Void> uploadAndSetJobFiles(final CompletableFuture<InetSocketAddress> blobServerAddressFuture, final JobGraph job) {
	return blobServerAddressFuture.thenAccept(blobServerAddress -> {
		try {
			ClientUtils.extractAndUploadJobGraphFiles(job, () -> new BlobClient(blobServerAddress, miniClusterConfiguration.getConfiguration()));
		} catch (FlinkException e) {
			throw new CompletionException(e);
		}
	});
}
 
Example #12
Source File: MiniCluster.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Void> uploadAndSetJobFiles(final CompletableFuture<InetSocketAddress> blobServerAddressFuture, final JobGraph job) {
	return blobServerAddressFuture.thenAccept(blobServerAddress -> {
		try {
			ClientUtils.extractAndUploadJobGraphFiles(job, () -> new BlobClient(blobServerAddress, miniClusterConfiguration.getConfiguration()));
		} catch (FlinkException e) {
			throw new CompletionException(e);
		}
	});
}