use of org.apache.flink.runtime.operators.coordination.CoordinationResponse in project flink by apache.
the class RestClusterClientTest method testSendCoordinationRequest.
@Test
public void testSendCoordinationRequest() throws Exception {
final TestClientCoordinationHandler handler = new TestClientCoordinationHandler();
try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(handler)) {
RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
String payload = "testing payload";
TestCoordinationRequest<String> request = new TestCoordinationRequest<>(payload);
try {
CompletableFuture<CoordinationResponse> future = restClusterClient.sendCoordinationRequest(jobId, new OperatorID(), request);
TestCoordinationResponse response = (TestCoordinationResponse) future.get();
assertEquals(payload, response.payload);
} finally {
restClusterClient.close();
}
}
}
use of org.apache.flink.runtime.operators.coordination.CoordinationResponse in project flink by apache.
the class TestJobClient method sendCoordinationRequest.
@Override
public CompletableFuture<CoordinationResponse> sendCoordinationRequest(OperatorID operatorId, CoordinationRequest request) {
if (jobStatus.isGloballyTerminalState()) {
throw new RuntimeException("Job terminated");
}
Assert.assertEquals(this.operatorId, operatorId);
CoordinationResponse response;
try {
response = handler.handleCoordinationRequest(request).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
if (infoProvider.isJobFinished()) {
jobStatus = JobStatus.FINISHED;
jobExecutionResult = new JobExecutionResult(jobId, 0, infoProvider.getAccumulatorResults());
}
return CompletableFuture.completedFuture(response);
}
use of org.apache.flink.runtime.operators.coordination.CoordinationResponse in project flink by apache.
the class AbstractTestCoordinationRequestHandler method handleCoordinationRequest.
@Override
public CompletableFuture<CoordinationResponse> handleCoordinationRequest(CoordinationRequest request) {
if (closed) {
throw new RuntimeException("Handler closed");
}
Assert.assertTrue(request instanceof CollectCoordinationRequest);
CollectCoordinationRequest collectRequest = (CollectCoordinationRequest) request;
updateBufferedResults();
Assert.assertTrue(offset <= collectRequest.getOffset());
List<T> subList = Collections.emptyList();
if (collectRequest.getVersion().equals(version)) {
while (buffered.size() > 0 && collectRequest.getOffset() > offset) {
buffered.removeFirst();
offset++;
}
subList = new ArrayList<>();
Iterator<T> iterator = buffered.iterator();
for (int i = 0; i < BATCH_SIZE && iterator.hasNext(); i++) {
subList.add(iterator.next());
}
}
List<byte[]> nextBatch = CollectTestUtils.toBytesList(subList, serializer);
CoordinationResponse response;
if (random.nextBoolean()) {
// with 50% chance we return valid result
response = new CollectCoordinationResponse(version, checkpointedOffset, nextBatch);
} else {
// with 50% chance we return invalid result
response = new CollectCoordinationResponse(collectRequest.getVersion(), -1, Collections.emptyList());
}
return CompletableFuture.completedFuture(response);
}
use of org.apache.flink.runtime.operators.coordination.CoordinationResponse in project flink by apache.
the class ClientCoordinationHandler method handleRequest.
@Override
protected CompletableFuture<ClientCoordinationResponseBody> handleRequest(@Nonnull HandlerRequest<ClientCoordinationRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
JobID jobId = request.getPathParameter(JobIDPathParameter.class);
OperatorID operatorId = request.getPathParameter(OperatorIDPathParameter.class);
SerializedValue<CoordinationRequest> serializedRequest = request.getRequestBody().getSerializedCoordinationRequest();
CompletableFuture<CoordinationResponse> responseFuture = gateway.deliverCoordinationRequestToCoordinator(jobId, operatorId, serializedRequest, timeout);
return responseFuture.thenApply(coordinationResponse -> {
try {
return new ClientCoordinationResponseBody(new SerializedValue<>(coordinationResponse));
} catch (IOException e) {
throw new CompletionException(new RestHandlerException("Failed to serialize coordination response", HttpResponseStatus.INTERNAL_SERVER_ERROR, e));
}
});
}
Aggregations