org.apache.flink.runtime.rest.messages.EmptyResponseBody Java Examples

The following examples show how to use org.apache.flink.runtime.rest.messages.EmptyResponseBody. 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: RestClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidVersionRejection() throws Exception {
	try (final RestClient restClient = new RestClient(RestClientConfiguration.fromConfiguration(new Configuration()), Executors.directExecutor())) {
		CompletableFuture<EmptyResponseBody> invalidVersionResponse = restClient.sendRequest(
			unroutableIp,
			80,
			new TestMessageHeaders(),
			EmptyMessageParameters.getInstance(),
			EmptyRequestBody.getInstance(),
			Collections.emptyList(),
			RestAPIVersion.V0
		);
		Assert.fail("The request should have been rejected due to a version mismatch.");
	} catch (IllegalArgumentException e) {
		// expected
	}
}
 
Example #2
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the send operation is being retried.
 */
@Test
public void testRetriableSendOperationIfConnectionErrorOrServiceUnavailable() throws Exception {
	final PingRestHandler pingRestHandler = new PingRestHandler(
		FutureUtils.completedExceptionally(new RestHandlerException("test exception", HttpResponseStatus.SERVICE_UNAVAILABLE)),
		CompletableFuture.completedFuture(EmptyResponseBody.getInstance()));

	try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(pingRestHandler)) {
		RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());

		try {
			final AtomicBoolean firstPollFailed = new AtomicBoolean();
			failHttpRequest = (messageHeaders, messageParameters, requestBody) ->
				messageHeaders instanceof PingRestHandlerHeaders && !firstPollFailed.getAndSet(true);

			restClusterClient.sendRequest(PingRestHandlerHeaders.INSTANCE).get();
		} finally {
			restClusterClient.close();
		}
	}
}
 
Example #3
Source File: JarDeleteHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(
		@Nonnull final HandlerRequest<EmptyRequestBody, JarDeleteMessageParameters> request,
		@Nonnull final RestfulGateway gateway) throws RestHandlerException {

	final String jarId = request.getPathParameter(JarIdPathParameter.class);
	return CompletableFuture.supplyAsync(() -> {
		final Path jarToDelete = jarDir.resolve(jarId);
		if (!Files.exists(jarToDelete)) {
			throw new CompletionException(new RestHandlerException(
				String.format("File %s does not exist in %s.", jarId, jarDir),
				HttpResponseStatus.BAD_REQUEST));
		} else {
			try {
				Files.delete(jarToDelete);
				return EmptyResponseBody.getInstance();
			} catch (final IOException e) {
				throw new CompletionException(new RestHandlerException(
					String.format("Failed to delete jar %s.", jarToDelete),
					HttpResponseStatus.INTERNAL_SERVER_ERROR,
					e));
			}
		}
	}, executor);
}
 
Example #4
Source File: JarDeleteHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(
		@Nonnull final HandlerRequest<EmptyRequestBody, JarDeleteMessageParameters> request,
		@Nonnull final RestfulGateway gateway) throws RestHandlerException {

	final String jarId = request.getPathParameter(JarIdPathParameter.class);
	return CompletableFuture.supplyAsync(() -> {
		final Path jarToDelete = jarDir.resolve(jarId);
		if (!Files.exists(jarToDelete)) {
			throw new CompletionException(new RestHandlerException(
				String.format("File %s does not exist in %s.", jarId, jarDir),
				HttpResponseStatus.BAD_REQUEST));
		} else {
			try {
				Files.delete(jarToDelete);
				return EmptyResponseBody.getInstance();
			} catch (final IOException e) {
				throw new CompletionException(new RestHandlerException(
					String.format("Failed to delete jar %s.", jarToDelete),
					HttpResponseStatus.INTERNAL_SERVER_ERROR,
					e));
			}
		}
	}, executor);
}
 
Example #5
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersioning() throws Exception {
	CompletableFuture<EmptyResponseBody> unspecifiedVersionResponse = restClient.sendRequest(
		serverAddress.getHostName(),
		serverAddress.getPort(),
		TestVersionHeaders.INSTANCE,
		EmptyMessageParameters.getInstance(),
		EmptyRequestBody.getInstance(),
		Collections.emptyList()
	);

	unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);

	CompletableFuture<EmptyResponseBody> specifiedVersionResponse = restClient.sendRequest(
		serverAddress.getHostName(),
		serverAddress.getPort(),
		TestVersionHeaders.INSTANCE,
		EmptyMessageParameters.getInstance(),
		EmptyRequestBody.getInstance(),
		Collections.emptyList(),
		RestAPIVersion.V1
	);

	specifiedVersionResponse.get(5, TimeUnit.SECONDS);
}
 
Example #6
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersioning() throws Exception {
	CompletableFuture<EmptyResponseBody> unspecifiedVersionResponse = restClient.sendRequest(
		serverAddress.getHostName(),
		serverAddress.getPort(),
		TestVersionHeaders.INSTANCE,
		EmptyMessageParameters.getInstance(),
		EmptyRequestBody.getInstance(),
		Collections.emptyList()
	);

	unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);

	CompletableFuture<EmptyResponseBody> specifiedVersionResponse = restClient.sendRequest(
		serverAddress.getHostName(),
		serverAddress.getPort(),
		TestVersionHeaders.INSTANCE,
		EmptyMessageParameters.getInstance(),
		EmptyRequestBody.getInstance(),
		Collections.emptyList(),
		RestAPIVersion.V1
	);

	specifiedVersionResponse.get(5, TimeUnit.SECONDS);
}
 
Example #7
Source File: RestServerEndpointITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersioning() throws Exception {
	CompletableFuture<EmptyResponseBody> unspecifiedVersionResponse = restClient.sendRequest(
		serverAddress.getHostName(),
		serverAddress.getPort(),
		TestVersionHeaders.INSTANCE,
		EmptyMessageParameters.getInstance(),
		EmptyRequestBody.getInstance(),
		Collections.emptyList()
	);

	unspecifiedVersionResponse.get(5, TimeUnit.SECONDS);

	CompletableFuture<EmptyResponseBody> specifiedVersionResponse = restClient.sendRequest(
		serverAddress.getHostName(),
		serverAddress.getPort(),
		TestVersionHeaders.INSTANCE,
		EmptyMessageParameters.getInstance(),
		EmptyRequestBody.getInstance(),
		Collections.emptyList(),
		RestAPIVersion.V1
	);

	specifiedVersionResponse.get(5, TimeUnit.SECONDS);
}
 
Example #8
Source File: RestClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidVersionRejection() throws Exception {
	try (final RestClient restClient = new RestClient(RestClientConfiguration.fromConfiguration(new Configuration()), Executors.directExecutor())) {
		CompletableFuture<EmptyResponseBody> invalidVersionResponse = restClient.sendRequest(
			unroutableIp,
			80,
			new TestMessageHeaders(),
			EmptyMessageParameters.getInstance(),
			EmptyRequestBody.getInstance(),
			Collections.emptyList(),
			RestAPIVersion.V0
		);
		Assert.fail("The request should have been rejected due to a version mismatch.");
	} catch (IllegalArgumentException e) {
		// expected
	}
}
 
Example #9
Source File: RestClientMultipartTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testFileMultipart() throws Exception {
	Collection<FileUpload> files = MULTIPART_UPLOAD_RESOURCE.getFilesToUpload().stream()
		.map(file -> new FileUpload(file.toPath(), "application/octet-stream")).collect(Collectors.toList());

	CompletableFuture<EmptyResponseBody> responseFuture = restClient.sendRequest(
		MULTIPART_UPLOAD_RESOURCE.getServerSocketAddress().getHostName(),
		MULTIPART_UPLOAD_RESOURCE.getServerSocketAddress().getPort(),
		MULTIPART_UPLOAD_RESOURCE.getFileHandler().getMessageHeaders(),
		EmptyMessageParameters.getInstance(),
		EmptyRequestBody.getInstance(),
		files
	);

	responseFuture.get();
}
 
Example #10
Source File: RestClientMultipartTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testMixedMultipart() throws Exception {
	Collection<FileUpload> files = MULTIPART_UPLOAD_RESOURCE.getFilesToUpload().stream()
		.map(file -> new FileUpload(file.toPath(), "application/octet-stream")).collect(Collectors.toList());

	MultipartUploadResource.TestRequestBody json = new MultipartUploadResource.TestRequestBody();
	CompletableFuture<EmptyResponseBody> responseFuture = restClient.sendRequest(
		MULTIPART_UPLOAD_RESOURCE.getServerSocketAddress().getHostName(),
		MULTIPART_UPLOAD_RESOURCE.getServerSocketAddress().getPort(),
		MULTIPART_UPLOAD_RESOURCE.getMixedHandler().getMessageHeaders(),
		EmptyMessageParameters.getInstance(),
		json,
		files
	);

	responseFuture.get();
	Assert.assertEquals(json, MULTIPART_UPLOAD_RESOURCE.getMixedHandler().lastReceivedRequest);
}
 
Example #11
Source File: RestClientMultipartTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testFileMultipart() throws Exception {
	Collection<FileUpload> files = MULTIPART_UPLOAD_RESOURCE.getFilesToUpload().stream()
		.map(file -> new FileUpload(file.toPath(), "application/octet-stream")).collect(Collectors.toList());

	CompletableFuture<EmptyResponseBody> responseFuture = restClient.sendRequest(
		MULTIPART_UPLOAD_RESOURCE.getServerSocketAddress().getHostName(),
		MULTIPART_UPLOAD_RESOURCE.getServerSocketAddress().getPort(),
		MULTIPART_UPLOAD_RESOURCE.getFileHandler().getMessageHeaders(),
		EmptyMessageParameters.getInstance(),
		EmptyRequestBody.getInstance(),
		files
	);

	responseFuture.get();
}
 
Example #12
Source File: JobCancellationHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public JobCancellationHandler(
		GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		Time timeout,
		Map<String, String> headers,
		MessageHeaders<EmptyRequestBody, EmptyResponseBody, JobCancellationMessageParameters> messageHeaders,
		TerminationModeQueryParameter.TerminationMode defaultTerminationMode) {
	super(leaderRetriever, timeout, headers, messageHeaders);

	this.defaultTerminationMode = Preconditions.checkNotNull(defaultTerminationMode);
}
 
Example #13
Source File: RestClientMultipartTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonMultipart() throws Exception {
	MultipartUploadResource.TestRequestBody json = new MultipartUploadResource.TestRequestBody();
	CompletableFuture<EmptyResponseBody> responseFuture = restClient.sendRequest(
		MULTIPART_UPLOAD_RESOURCE.getServerSocketAddress().getHostName(),
		MULTIPART_UPLOAD_RESOURCE.getServerSocketAddress().getPort(),
		MULTIPART_UPLOAD_RESOURCE.getJsonHandler().getMessageHeaders(),
		EmptyMessageParameters.getInstance(),
		json,
		Collections.emptyList()
	);

	responseFuture.get();
	Assert.assertEquals(json, MULTIPART_UPLOAD_RESOURCE.getJsonHandler().lastReceivedRequest);
}
 
Example #14
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (uploadedFiles.size() != 1) {
		throw new RestHandlerException("Expected 1 file, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST);
	}

	try {
		lastUploadedFileContents = Files.readAllBytes(uploadedFiles.iterator().next());
	} catch (IOException e) {
		throw new RestHandlerException("Could not read contents of uploaded file.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example #15
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<TestRequestBody, EmptyMessageParameters> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (!uploadedFiles.isEmpty()) {
		throw new RestHandlerException("This handler should not have received file uploads.", HttpResponseStatus.INTERNAL_SERVER_ERROR);
	}
	this.lastReceivedRequest = request.getRequestBody();
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example #16
Source File: JarDeleteHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public JarDeleteHandler(
		final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders,
		final MessageHeaders<EmptyRequestBody, EmptyResponseBody, JarDeleteMessageParameters> messageHeaders,
		final Path jarDir,
		final Executor executor) {
	super(leaderRetriever, timeout, responseHeaders, messageHeaders);
	this.jarDir = requireNonNull(jarDir);
	this.executor = requireNonNull(executor);
}
 
Example #17
Source File: JarDeleteHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public JarDeleteHandler(
		final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders,
		final MessageHeaders<EmptyRequestBody, EmptyResponseBody, JarDeleteMessageParameters> messageHeaders,
		final Path jarDir,
		final Executor executor) {
	super(leaderRetriever, timeout, responseHeaders, messageHeaders);
	this.jarDir = requireNonNull(jarDir);
	this.executor = requireNonNull(executor);
}
 
Example #18
Source File: ShutdownHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public ShutdownHandler(
		final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders,
		final MessageHeaders<EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> messageHeaders) {
	super(leaderRetriever, timeout, responseHeaders, messageHeaders);
}
 
Example #19
Source File: RestClusterClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void stop(JobID jobID) throws Exception {
	JobTerminationMessageParameters params = new JobTerminationMessageParameters();
	params.jobPathParameter.resolve(jobID);
	params.terminationModeQueryParameter.resolve(Collections.singletonList(TerminationModeQueryParameter.TerminationMode.STOP));
	CompletableFuture<EmptyResponseBody> responseFuture = sendRequest(
		JobTerminationHeaders.getInstance(),
		params);
	responseFuture.get(timeout.toMillis(), TimeUnit.MILLISECONDS);
}
 
Example #20
Source File: RestClusterClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Acknowledge> cancel(JobID jobID) {
	JobCancellationMessageParameters params = new JobCancellationMessageParameters();
	params.jobPathParameter.resolve(jobID);
	params.terminationModeQueryParameter.resolve(Collections.singletonList(TerminationModeQueryParameter.TerminationMode.CANCEL));
	CompletableFuture<EmptyResponseBody> responseFuture = sendRequest(
		JobCancellationHeaders.getInstance(),
		params);
	return responseFuture.thenApply(ignore -> Acknowledge.get());
}
 
Example #21
Source File: JobCancellationHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public JobCancellationHandler(
		GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		Time timeout,
		Map<String, String> headers,
		MessageHeaders<EmptyRequestBody, EmptyResponseBody, JobCancellationMessageParameters> messageHeaders,
		TerminationModeQueryParameter.TerminationMode defaultTerminationMode) {
	super(leaderRetriever, timeout, headers, messageHeaders);

	this.defaultTerminationMode = Preconditions.checkNotNull(defaultTerminationMode);
}
 
Example #22
Source File: RestServerEndpointITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (uploadedFiles.size() != 1) {
		throw new RestHandlerException("Expected 1 file, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST);
	}

	try {
		lastUploadedFileContents = Files.readAllBytes(uploadedFiles.iterator().next());
	} catch (IOException e) {
		throw new RestHandlerException("Could not read contents of uploaded file.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example #23
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final CompletableFuture<EmptyResponseBody> result = responseQueue.poll();

	if (result != null) {
		return result;
	} else {
		return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
	}
}
 
Example #24
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final CompletableFuture<EmptyResponseBody> result = responseQueue.poll();

	if (result != null) {
		return result;
	} else {
		return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
	}
}
 
Example #25
Source File: ShutdownHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public ShutdownHandler(
		final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders,
		final MessageHeaders<EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> messageHeaders) {
	super(leaderRetriever, timeout, responseHeaders, messageHeaders);
}
 
Example #26
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Class<EmptyResponseBody> getResponseClass() {
	return EmptyResponseBody.class;
}
 
Example #27
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
	throw new RestHandlerException("test failure 2", HttpResponseStatus.ACCEPTED);
}
 
Example #28
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
default Class<EmptyResponseBody> getResponseClass() {
	return EmptyResponseBody.class;
}
 
Example #29
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example #30
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
	verifyFileUpload(expectedFiles, request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList()));
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}