org.apache.flink.runtime.rest.handler.async.AsynchronousOperationResult Java Examples

The following examples show how to use org.apache.flink.runtime.rest.handler.async.AsynchronousOperationResult. 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: SavepointHandlersTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
		.getFailureCause()
		.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #2
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, SavepointDisposalStatusMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final TriggerId actualTriggerId = request.getPathParameter(TriggerIdPathParameter.class);

	if (actualTriggerId.equals(triggerId)) {
		final OptionalFailure<AsynchronousOperationInfo> nextResponse = responses.poll();

		if (nextResponse != null) {
			if (nextResponse.isFailure()) {
				throw new RestHandlerException("Failure", HttpResponseStatus.BAD_REQUEST, nextResponse.getFailureCause());
			} else {
				return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(nextResponse.getUnchecked()));
			}
		} else {
			throw new AssertionError();
		}
	} else {
		throw new AssertionError();
	}
}
 
Example #3
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
			.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
			triggerSavepointRequest(),
			testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
			savepointStatusRequest(triggerId),
			testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
			.getFailureCause()
			.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #4
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
			.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
			triggerSavepointRequest(),
			testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
			savepointStatusRequest(triggerId),
			testingRestfulGateway).get();

	assertThat(
			savepointResponseBody.queueStatus().getId(),
			equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
			savepointResponseBody.resource().getLocation(),
			equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #5
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
		.getFailureCause()
		.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #6
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(
		savepointResponseBody.queueStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
		savepointResponseBody.resource().getLocation(),
		equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #7
Source File: RestAPIDocGenerator.java    From flink with Apache License 2.0 6 votes vote down vote up
private static String createMessageHtmlEntry(Class<?> messageClass, @Nullable Class<?> nestedAsyncOperationResultClass, Class<?> emptyMessageClass) {
	JsonSchema schema = generateSchema(messageClass);

	if (nestedAsyncOperationResultClass != null) {
		JsonSchema innerSchema = generateSchema(nestedAsyncOperationResultClass);
		schema.asObjectSchema().getProperties().put(AsynchronousOperationResult.FIELD_NAME_OPERATION, innerSchema);
	}

	String json;
	if (messageClass == emptyMessageClass) {
		json = "{}";
	} else {
		try {
			json = mapper.writerWithDefaultPrettyPrinter()
				.writeValueAsString(schema);
		} catch (JsonProcessingException e) {
			LOG.error("Failed to write message schema for class {}.", messageClass.getCanonicalName(), e);
			throw new RuntimeException("Failed to write message schema for class " + messageClass.getCanonicalName() + ".", e);
		}
	}

	return json;
}
 
Example #8
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, SavepointDisposalStatusMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final TriggerId actualTriggerId = request.getPathParameter(TriggerIdPathParameter.class);

	if (actualTriggerId.equals(triggerId)) {
		final OptionalFailure<AsynchronousOperationInfo> nextResponse = responses.poll();

		if (nextResponse != null) {
			if (nextResponse.isFailure()) {
				throw new RestHandlerException("Failure", HttpResponseStatus.BAD_REQUEST, nextResponse.getFailureCause());
			} else {
				return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(nextResponse.getUnchecked()));
			}
		} else {
			throw new AssertionError();
		}
	} else {
		throw new AssertionError();
	}
}
 
Example #9
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
			.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
			triggerSavepointRequest(),
			testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
			savepointStatusRequest(triggerId),
			testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
			.getFailureCause()
			.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #10
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
			.setStopWithSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
			.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
			triggerSavepointRequest(),
			testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
			savepointStatusRequest(triggerId),
			testingRestfulGateway).get();

	assertThat(
			savepointResponseBody.queueStatus().getId(),
			equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
			savepointResponseBody.resource().getLocation(),
			equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #11
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedWithException() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(new RuntimeException("expected")))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
	final Throwable savepointError = savepointResponseBody.resource()
		.getFailureCause()
		.deserializeError(ClassLoader.getSystemClassLoader());
	assertThat(savepointError.getMessage(), equalTo("expected"));
	assertThat(savepointError, instanceOf(RuntimeException.class));
}
 
Example #12
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(
		savepointResponseBody.queueStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
		savepointResponseBody.resource().getLocation(),
		equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #13
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, SavepointDisposalStatusMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final TriggerId actualTriggerId = request.getPathParameter(TriggerIdPathParameter.class);

	if (actualTriggerId.equals(triggerId)) {
		final OptionalFailure<AsynchronousOperationInfo> nextResponse = responses.poll();

		if (nextResponse != null) {
			if (nextResponse.isFailure()) {
				throw new RestHandlerException("Failure", HttpResponseStatus.BAD_REQUEST, nextResponse.getFailureCause());
			} else {
				return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(nextResponse.getUnchecked()));
			}
		} else {
			throw new AssertionError();
		}
	} else {
		throw new AssertionError();
	}
}
 
Example #14
Source File: SavepointHandlersTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String targetDirectory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.build();

	final TriggerId triggerId = savepointTriggerHandler.handleRequest(
		triggerSavepointRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
	savepointResponseBody = savepointStatusHandler.handleRequest(
		savepointStatusRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(
		savepointResponseBody.queueStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(savepointResponseBody.resource(), notNullValue());
	assertThat(
		savepointResponseBody.resource().getLocation(),
		equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
 
Example #15
Source File: RestClusterClientSavepointTriggerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<SavepointInfo>> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, SavepointStatusMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {

	final TriggerId triggerId = request.getPathParameter(TriggerIdPathParameter.class);
	return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(savepointHandlerLogic.apply(triggerId)));
}
 
Example #16
Source File: RestClusterClientSavepointTriggerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<SavepointInfo>> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, SavepointStatusMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {

	final TriggerId triggerId = request.getPathParameter(TriggerIdPathParameter.class);
	return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(savepointHandlerLogic.apply(triggerId)));
}
 
Example #17
Source File: RestClusterClientSavepointTriggerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<SavepointInfo>> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, SavepointStatusMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {

	final TriggerId triggerId = request.getPathParameter(TriggerIdPathParameter.class);
	return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(savepointHandlerLogic.apply(triggerId)));
}
 
Example #18
Source File: RescalingHandlers.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody, RescalingStatusMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
	throw featureDisabledException();
}
 
Example #19
Source File: RescalingHandlers.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody, RescalingStatusMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
	throw featureDisabledException();
}