org.apache.flink.runtime.rest.messages.queue.QueueStatus Java Examples

The following examples show how to use org.apache.flink.runtime.rest.messages.queue.QueueStatus. 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: RestClusterClient.java    From flink with Apache License 2.0 6 votes vote down vote up
private <R, A extends AsynchronouslyCreatedResource<R>> CompletableFuture<R> pollResourceAsync(
		final Supplier<CompletableFuture<A>> resourceFutureSupplier,
		final CompletableFuture<R> resultFuture,
		final long attempt) {

	resourceFutureSupplier.get().whenComplete((asynchronouslyCreatedResource, throwable) -> {
		if (throwable != null) {
			resultFuture.completeExceptionally(throwable);
		} else {
			if (asynchronouslyCreatedResource.queueStatus().getId() == QueueStatus.Id.COMPLETED) {
				resultFuture.complete(asynchronouslyCreatedResource.resource());
			} else {
				retryExecutorService.schedule(() -> {
					pollResourceAsync(resourceFutureSupplier, resultFuture, attempt + 1);
				}, waitStrategy.sleepTime(attempt), TimeUnit.MILLISECONDS);
			}
		}
	});

	return resultFuture;
}
 
Example #2
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 #3
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 #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: 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 #6
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the triggering and exceptional completion of an asynchronous operation.
 */
@Test
public void testOperationFailure() throws Exception {
	final FlinkException testException = new FlinkException("Test exception");
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(testException))
		.build();

	// trigger the operation
	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));

	final OperationResult resource = operationResult.resource();
	assertThat(resource.throwable, is(testException));
}
 
Example #7
Source File: RestClusterClient.java    From flink with Apache License 2.0 6 votes vote down vote up
private <R, A extends AsynchronouslyCreatedResource<R>> CompletableFuture<R> pollResourceAsync(
		final Supplier<CompletableFuture<A>> resourceFutureSupplier,
		final CompletableFuture<R> resultFuture,
		final long attempt) {

	resourceFutureSupplier.get().whenComplete((asynchronouslyCreatedResource, throwable) -> {
		if (throwable != null) {
			resultFuture.completeExceptionally(throwable);
		} else {
			if (asynchronouslyCreatedResource.queueStatus().getId() == QueueStatus.Id.COMPLETED) {
				resultFuture.complete(asynchronouslyCreatedResource.resource());
			} else {
				retryExecutorService.schedule(() -> {
					pollResourceAsync(resourceFutureSupplier, resultFuture, attempt + 1);
				}, waitStrategy.sleepTime(attempt), TimeUnit.MILLISECONDS);
			}
		}
	});

	return resultFuture;
}
 
Example #8
Source File: RestClusterClient.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private <R, A extends AsynchronouslyCreatedResource<R>> CompletableFuture<R> pollResourceAsync(
		final Supplier<CompletableFuture<A>> resourceFutureSupplier,
		final CompletableFuture<R> resultFuture,
		final long attempt) {

	resourceFutureSupplier.get().whenComplete((asynchronouslyCreatedResource, throwable) -> {
		if (throwable != null) {
			resultFuture.completeExceptionally(throwable);
		} else {
			if (asynchronouslyCreatedResource.queueStatus().getId() == QueueStatus.Id.COMPLETED) {
				resultFuture.complete(asynchronouslyCreatedResource.resource());
			} else {
				retryExecutorService.schedule(() -> {
					pollResourceAsync(resourceFutureSupplier, resultFuture, attempt + 1);
				}, waitStrategy.sleepTime(attempt), TimeUnit.MILLISECONDS);
			}
		}
	});

	return resultFuture;
}
 
Example #9
Source File: AbstractAsynchronousOperationHandlersTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the triggering and exceptional completion of an asynchronous operation.
 */
@Test
public void testOperationFailure() throws Exception {
	final FlinkException testException = new FlinkException("Test exception");
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(testException))
		.build();

	// trigger the operation
	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));

	final OperationResult resource = operationResult.resource();
	assertThat(resource.throwable, is(testException));
}
 
Example #10
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 #11
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 #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: 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 #14
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 #15
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 #16
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the triggering and exceptional completion of an asynchronous operation.
 */
@Test
public void testOperationFailure() throws Exception {
	final FlinkException testException = new FlinkException("Test exception");
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> FutureUtils.completedExceptionally(testException))
		.build();

	// trigger the operation
	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));

	final OperationResult resource = operationResult.resource();
	assertThat(resource.throwable, is(testException));
}
 
Example #17
Source File: AsynchronousOperationResult.java    From flink with Apache License 2.0 5 votes vote down vote up
@JsonCreator
private AsynchronousOperationResult(
		@JsonProperty(FIELD_NAME_STATUS) QueueStatus queueStatus,
		@JsonProperty(FIELD_NAME_OPERATION) @Nullable V value) {
	this.queueStatus = Preconditions.checkNotNull(queueStatus);
	this.value = value;
}
 
Example #18
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testResultInProgress() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setRequestJobStatusFunction(
			jobId -> CompletableFuture.completedFuture(JobStatus.RUNNING))
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.IN_PROGRESS));
}
 
Example #19
Source File: JobExecutionResultResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public JobExecutionResultResponseBody(
		@JsonProperty(value = "status", required = true) final QueueStatus status,
		@JsonProperty(value = "job-execution-result")
		@JsonDeserialize(using = JobResultDeserializer.class)
		@Nullable final JobResult jobExecutionResult) {
	this.status = requireNonNull(status);
	this.jobExecutionResult = jobExecutionResult;
}
 
Example #20
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompletedResult() throws Exception {
	final JobStatus jobStatus = JobStatus.FINISHED;
	final ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder()
		.setJobID(TEST_JOB_ID)
		.setState(jobStatus)
		.build();

	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setRequestJobStatusFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(jobStatus);
			})
		.setRequestJobResultFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(JobResult.createFrom(executionGraph));
			}
		)
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(responseBody.getJobExecutionResult(), not(nullValue()));
}
 
Example #21
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the triggering and successful completion of an asynchronous operation.
 */
@Test
public void testOperationCompletion() throws Exception {
	final CompletableFuture<String> savepointFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> savepointFuture)
		.build();

	// trigger the operation
	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.inProgress().getId()));

	// complete the operation
	final String savepointPath = "foobar";
	savepointFuture.complete(savepointPath);

	operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));

	assertThat(operationResult.resource().value, is(savepointPath));
}
 
Example #22
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the triggering and successful completion of an asynchronous operation.
 */
@Test
public void testOperationCompletion() throws Exception {
	final CompletableFuture<String> savepointFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> savepointFuture)
		.build();

	// trigger the operation
	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.inProgress().getId()));

	// complete the operation
	final String savepointPath = "foobar";
	savepointFuture.complete(savepointPath);

	operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));

	assertThat(operationResult.resource().value, is(savepointPath));
}
 
Example #23
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompletedResult() throws Exception {
	final JobStatus jobStatus = JobStatus.FINISHED;
	final ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder()
		.setJobID(TEST_JOB_ID)
		.setState(jobStatus)
		.build();

	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder()
		.setRequestJobStatusFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(jobStatus);
			})
		.setRequestJobResultFunction(
			jobId -> {
				assertThat(jobId, equalTo(TEST_JOB_ID));
				return CompletableFuture.completedFuture(JobResult.createFrom(executionGraph));
			}
		)
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.COMPLETED));
	assertThat(responseBody.getJobExecutionResult(), not(nullValue()));
}
 
Example #24
Source File: JobExecutionResultResponseBody.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public JobExecutionResultResponseBody(
		@JsonProperty(value = "status", required = true) final QueueStatus status,
		@JsonProperty(value = "job-execution-result")
		@JsonDeserialize(using = JobResultDeserializer.class)
		@Nullable final JobResult jobExecutionResult) {
	this.status = requireNonNull(status);
	this.jobExecutionResult = jobExecutionResult;
}
 
Example #25
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testResultInProgress() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder()
		.setRequestJobStatusFunction(
			jobId -> CompletableFuture.completedFuture(JobStatus.RUNNING))
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.IN_PROGRESS));
}
 
Example #26
Source File: AsynchronousOperationResult.java    From flink with Apache License 2.0 5 votes vote down vote up
@JsonCreator
private AsynchronousOperationResult(
		@JsonProperty(FIELD_NAME_STATUS) QueueStatus queueStatus,
		@JsonProperty(FIELD_NAME_OPERATION) @Nullable V value) {
	this.queueStatus = Preconditions.checkNotNull(queueStatus);
	this.value = value;
}
 
Example #27
Source File: AsynchronousOperationResult.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@JsonCreator
private AsynchronousOperationResult(
		@JsonProperty(FIELD_NAME_STATUS) QueueStatus queueStatus,
		@JsonProperty(FIELD_NAME_OPERATION) @Nullable V value) {
	this.queueStatus = Preconditions.checkNotNull(queueStatus);
	this.value = value;
}
 
Example #28
Source File: JobExecutionResultResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public JobExecutionResultResponseBody(
		@JsonProperty(value = "status", required = true) final QueueStatus status,
		@JsonProperty(value = "job-execution-result")
		@JsonDeserialize(using = JobResultDeserializer.class)
		@Nullable final JobResult jobExecutionResult) {
	this.status = requireNonNull(status);
	this.jobExecutionResult = jobExecutionResult;
}
 
Example #29
Source File: AbstractAsynchronousOperationHandlersTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the triggering and successful completion of an asynchronous operation.
 */
@Test
public void testOperationCompletion() throws Exception {
	final CompletableFuture<String> savepointFuture = new CompletableFuture<>();
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> savepointFuture)
		.build();

	// trigger the operation
	final TriggerId triggerId = testingTriggerHandler.handleRequest(
		triggerOperationRequest(),
		testingRestfulGateway).get().getTriggerId();

	AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.inProgress().getId()));

	// complete the operation
	final String savepointPath = "foobar";
	savepointFuture.complete(savepointPath);

	operationResult = testingStatusHandler.handleRequest(
		statusOperationRequest(triggerId),
		testingRestfulGateway).get();

	assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));

	assertThat(operationResult.resource().value, is(savepointPath));
}
 
Example #30
Source File: JobExecutionResultHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testResultInProgress() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder()
		.setRequestJobStatusFunction(
			jobId -> CompletableFuture.completedFuture(JobStatus.RUNNING))
		.build();

	final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(
		testRequest,
		testingRestfulGateway).get();

	assertThat(
		responseBody.getStatus().getId(),
		equalTo(QueueStatus.Id.IN_PROGRESS));
}