org.apache.flink.runtime.rest.messages.job.JobSubmitResponseBody Java Examples

The following examples show how to use org.apache.flink.runtime.rest.messages.job.JobSubmitResponseBody. 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 5 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> 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()));
}
 
Example #2
Source File: JobSubmitHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> 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()));
}
 
Example #3
Source File: JobSubmitHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> 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()));
}
 
Example #4
Source File: JobSubmitResponseBodyTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<JobSubmitResponseBody> getTestResponseClass() {
	return JobSubmitResponseBody.class;
}
 
Example #5
Source File: JobSubmitResponseBodyTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected JobSubmitResponseBody getTestResponseInstance() throws Exception {
	return new JobSubmitResponseBody("/url");
}
 
Example #6
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	jobSubmitted = true;
	return CompletableFuture.completedFuture(new JobSubmitResponseBody("/url"));
}
 
Example #7
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(
		@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	throw new RestHandlerException("expected", HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
 
Example #8
Source File: JobSubmitResponseBodyTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<JobSubmitResponseBody> getTestResponseClass() {
	return JobSubmitResponseBody.class;
}
 
Example #9
Source File: JobSubmitResponseBodyTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JobSubmitResponseBody getTestResponseInstance() throws Exception {
	return new JobSubmitResponseBody("/url");
}
 
Example #10
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	jobSubmitted = true;
	return CompletableFuture.completedFuture(new JobSubmitResponseBody("/url"));
}
 
Example #11
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(
		@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	throw new RestHandlerException("expected", HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
 
Example #12
Source File: JobSubmitResponseBodyTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<JobSubmitResponseBody> getTestResponseClass() {
	return JobSubmitResponseBody.class;
}
 
Example #13
Source File: JobSubmitResponseBodyTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JobSubmitResponseBody getTestResponseInstance() throws Exception {
	return new JobSubmitResponseBody("/url");
}
 
Example #14
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	jobSubmitted = true;
	return CompletableFuture.completedFuture(new JobSubmitResponseBody("/url"));
}
 
Example #15
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(
		@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	throw new RestHandlerException("expected", HttpResponseStatus.INTERNAL_SERVER_ERROR);
}