Search in sources :

Example 1 with CoordinationResponse

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();
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Test(org.junit.Test)

Example 2 with CoordinationResponse

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);
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse)

Example 3 with CoordinationResponse

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);
}
Also used : CollectCoordinationRequest(org.apache.flink.streaming.api.operators.collect.CollectCoordinationRequest) CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse) CollectCoordinationResponse(org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse) CollectCoordinationResponse(org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse)

Example 4 with CoordinationResponse

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));
        }
    });
}
Also used : CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse) CoordinationRequest(org.apache.flink.runtime.operators.coordination.CoordinationRequest) CompletionException(java.util.concurrent.CompletionException) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) IOException(java.io.IOException) ClientCoordinationResponseBody(org.apache.flink.runtime.rest.messages.job.coordination.ClientCoordinationResponseBody) JobID(org.apache.flink.api.common.JobID) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException)

Aggregations

CoordinationResponse (org.apache.flink.runtime.operators.coordination.CoordinationResponse)4 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 IOException (java.io.IOException)1 CompletionException (java.util.concurrent.CompletionException)1 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)1 JobID (org.apache.flink.api.common.JobID)1 CoordinationRequest (org.apache.flink.runtime.operators.coordination.CoordinationRequest)1 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)1 ClientCoordinationResponseBody (org.apache.flink.runtime.rest.messages.job.coordination.ClientCoordinationResponseBody)1 TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)1 CollectCoordinationRequest (org.apache.flink.streaming.api.operators.collect.CollectCoordinationRequest)1 CollectCoordinationResponse (org.apache.flink.streaming.api.operators.collect.CollectCoordinationResponse)1 Test (org.junit.Test)1