Search in sources :

Example 6 with EmptyResponseBody

use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.

the class AbstractHandlerITCase method testOOMErrorMessageEnrichment.

@Test
public void testOOMErrorMessageEnrichment() throws Exception {
    final TestMessageHeaders<EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> messageHeaders = TestMessageHeaders.emptyBuilder().setTargetRestEndpointURL("/test-handler").build();
    final TestRestHandler<RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> testRestHandler = new TestRestHandler<>(mockGatewayRetriever, messageHeaders, FutureUtils.completedExceptionally(new OutOfMemoryError("Metaspace")));
    try (final TestRestServerEndpoint server = TestRestServerEndpoint.builder(REST_BASE_CONFIG).withHandler(messageHeaders, testRestHandler).buildAndStart();
        final RestClient restClient = createRestClient(server.getServerAddress().getPort())) {
        CompletableFuture<EmptyResponseBody> response = restClient.sendRequest(server.getServerAddress().getHostName(), server.getServerAddress().getPort(), messageHeaders, EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance());
        try {
            response.get();
            fail("An ExecutionException was expected here being caused by the OutOfMemoryError.");
        } catch (ExecutionException e) {
            assertThat(e.getMessage(), StringContains.containsString("Metaspace. The metaspace out-of-memory error has occurred. "));
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestClient(org.apache.flink.runtime.rest.RestClient) TestRestHandler(org.apache.flink.runtime.rest.util.TestRestHandler) EmptyResponseBody(org.apache.flink.runtime.rest.messages.EmptyResponseBody) ExecutionException(java.util.concurrent.ExecutionException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) Test(org.junit.Test)

Example 7 with EmptyResponseBody

use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.

the class RestClientTest method testRestClientClosedHandling.

/**
 * Tests that we fail the operation if the client closes.
 */
@Test
public void testRestClientClosedHandling() throws Exception {
    final Configuration config = new Configuration();
    config.setLong(RestOptions.IDLENESS_TIMEOUT, 5000L);
    Socket connectionSocket = null;
    try (final ServerSocket serverSocket = new ServerSocket(0);
        final RestClient restClient = new RestClient(config, TestingUtils.defaultExecutor())) {
        final String targetAddress = "localhost";
        final int targetPort = serverSocket.getLocalPort();
        // start server
        final CompletableFuture<Socket> socketCompletableFuture = CompletableFuture.supplyAsync(CheckedSupplier.unchecked(() -> NetUtils.acceptWithoutTimeout(serverSocket)));
        final CompletableFuture<EmptyResponseBody> responseFuture = restClient.sendRequest(targetAddress, targetPort, new TestMessageHeaders(), EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance(), Collections.emptyList());
        try {
            connectionSocket = socketCompletableFuture.get(TIMEOUT, TimeUnit.SECONDS);
        } catch (TimeoutException ignored) {
            // could not establish a server connection --> see that the response failed
            socketCompletableFuture.cancel(true);
        }
        restClient.close();
        try {
            responseFuture.get();
        } catch (ExecutionException ee) {
            if (!ExceptionUtils.findThrowable(ee, IOException.class).isPresent()) {
                throw ee;
            }
        }
    } finally {
        if (connectionSocket != null) {
            connectionSocket.close();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ServerSocket(java.net.ServerSocket) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) EmptyResponseBody(org.apache.flink.runtime.rest.messages.EmptyResponseBody) ExecutionException(java.util.concurrent.ExecutionException) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) TimeoutException(java.util.concurrent.TimeoutException) ConnectTimeoutException(org.apache.flink.shaded.netty4.io.netty.channel.ConnectTimeoutException) Test(org.junit.Test)

Example 8 with EmptyResponseBody

use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.

the class RestClusterClient method cancel.

@Override
public CompletableFuture<Acknowledge> cancel(JobID jobID) {
    JobCancellationMessageParameters params = new JobCancellationMessageParameters().resolveJobId(jobID).resolveTerminationMode(TerminationModeQueryParameter.TerminationMode.CANCEL);
    CompletableFuture<EmptyResponseBody> responseFuture = sendRequest(JobCancellationHeaders.getInstance(), params);
    return responseFuture.thenApply(ignore -> Acknowledge.get());
}
Also used : JobCancellationMessageParameters(org.apache.flink.runtime.rest.messages.JobCancellationMessageParameters) EmptyResponseBody(org.apache.flink.runtime.rest.messages.EmptyResponseBody)

Aggregations

EmptyResponseBody (org.apache.flink.runtime.rest.messages.EmptyResponseBody)8 Test (org.junit.Test)5 ExecutionException (java.util.concurrent.ExecutionException)4 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)4 Configuration (org.apache.flink.configuration.Configuration)3 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)3 IOException (java.io.IOException)2 ServerSocket (java.net.ServerSocket)2 Socket (java.net.Socket)2 TimeoutException (java.util.concurrent.TimeoutException)2 EmptyMessageParameters (org.apache.flink.runtime.rest.messages.EmptyMessageParameters)2 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)2 JobCancellationMessageParameters (org.apache.flink.runtime.rest.messages.JobCancellationMessageParameters)2 TestRestHandler (org.apache.flink.runtime.rest.util.TestRestHandler)2 TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)2 ConnectTimeoutException (org.apache.flink.shaded.netty4.io.netty.channel.ConnectTimeoutException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 SSLContext (javax.net.ssl.SSLContext)1 SSLException (javax.net.ssl.SSLException)1 JobID (org.apache.flink.api.common.JobID)1