Search in sources :

Example 11 with RestfulGateway

use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.

the class JobExecutionResultHandler method handleRequest.

@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
    final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
    final CompletableFuture<JobStatus> jobStatusFuture = gateway.requestJobStatus(jobId, timeout);
    return jobStatusFuture.thenCompose(jobStatus -> {
        if (jobStatus.isGloballyTerminalState()) {
            return gateway.requestJobResult(jobId, timeout).thenApply(JobExecutionResultResponseBody::created);
        } else {
            return CompletableFuture.completedFuture(JobExecutionResultResponseBody.inProgress());
        }
    }).exceptionally(throwable -> {
        throw propagateException(throwable);
    });
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) JobExecutionResultHeaders(org.apache.flink.runtime.rest.messages.job.JobExecutionResultHeaders) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) JobStatus(org.apache.flink.api.common.JobStatus) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Map(java.util.Map) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Nonnull(javax.annotation.Nonnull) Time(org.apache.flink.api.common.time.Time) AbstractRestHandler(org.apache.flink.runtime.rest.handler.AbstractRestHandler) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) JobID(org.apache.flink.api.common.JobID)

Example 12 with RestfulGateway

use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.

the class MultipartUploadResource method before.

@Override
public void before() throws Exception {
    temporaryFolder.create();
    Configuration config = new Configuration();
    config.setString(RestOptions.BIND_PORT, "0");
    config.setString(RestOptions.ADDRESS, "localhost");
    // set this to a lower value on purpose to test that files larger than the content limit are
    // still accepted
    config.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, 1024 * 1024);
    configuredUploadDir = temporaryFolder.newFolder().toPath();
    config.setString(WebOptions.UPLOAD_DIR, configuredUploadDir.toString());
    RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);
    final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () -> CompletableFuture.completedFuture(mockRestfulGateway);
    file1 = temporaryFolder.newFile();
    try (RandomAccessFile rw = new RandomAccessFile(file1, "rw")) {
        // magic value that reliably reproduced https://github.com/netty/netty/issues/11668
        rw.setLength(5043444);
    }
    file2 = temporaryFolder.newFile();
    Files.write(file2.toPath(), "world".getBytes(ConfigConstants.DEFAULT_CHARSET));
    mixedHandler = new MultipartMixedHandler(mockGatewayRetriever);
    jsonHandler = new MultipartJsonHandler(mockGatewayRetriever);
    fileHandler = new MultipartFileHandler(mockGatewayRetriever);
    serverEndpoint = TestRestServerEndpoint.builder(config).withHandler(mixedHandler).withHandler(jsonHandler).withHandler(fileHandler).buildAndStart();
    serverAddress = serverEndpoint.getRestBaseUrl();
    serverSocketAddress = serverEndpoint.getServerAddress();
    this.setFileUploadVerifier((request, restfulGateway) -> {
        // the default verifier checks for identiy (i.e. same name and content) of all
        // uploaded files
        List<Path> expectedFiles = getFilesToUpload().stream().map(File::toPath).collect(Collectors.toList());
        List<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
        assertEquals(expectedFiles.size(), uploadedFiles.size());
        List<Path> expectedList = new ArrayList<>(expectedFiles);
        List<Path> actualList = new ArrayList<>(uploadedFiles);
        expectedList.sort(Comparator.comparing(Path::toString));
        actualList.sort(Comparator.comparing(Path::toString));
        for (int x = 0; x < expectedList.size(); x++) {
            Path expected = expectedList.get(x);
            Path actual = actualList.get(x);
            assertEquals(expected.getFileName().toString(), actual.getFileName().toString());
            byte[] originalContent = Files.readAllBytes(expected);
            byte[] receivedContent = Files.readAllBytes(actual);
            assertArrayEquals(originalContent, receivedContent);
        }
    });
}
Also used : Path(java.nio.file.Path) Configuration(org.apache.flink.configuration.Configuration) RandomAccessFile(java.io.RandomAccessFile) ArrayList(java.util.ArrayList) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint)

Example 13 with RestfulGateway

use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.

the class MetricFetcherTest method testLongUpdateInterval.

@Test
public void testLongUpdateInterval() {
    final long updateInterval = 1000L;
    final AtomicInteger requestMetricQueryServiceGatewaysCounter = new AtomicInteger(0);
    final RestfulGateway restfulGateway = createRestfulGateway(requestMetricQueryServiceGatewaysCounter);
    final MetricFetcher fetcher = createMetricFetcher(updateInterval, restfulGateway);
    fetcher.update();
    fetcher.update();
    assertThat(requestMetricQueryServiceGatewaysCounter.get(), is(1));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) Test(org.junit.Test)

Aggregations

RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)13 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)8 Test (org.junit.Test)7 CompletableFuture (java.util.concurrent.CompletableFuture)5 JobID (org.apache.flink.api.common.JobID)5 Time (org.apache.flink.api.common.time.Time)5 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)5 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)4 EmptyResponseBody (org.apache.flink.runtime.rest.messages.EmptyResponseBody)4 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Nonnull (javax.annotation.Nonnull)3 FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)3 AbstractRestHandler (org.apache.flink.runtime.rest.handler.AbstractRestHandler)3 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)3 EmptyMessageParameters (org.apache.flink.runtime.rest.messages.EmptyMessageParameters)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2