Search in sources :

Example 1 with EmptyRequestBody

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

the class JarUploadHandlerTest method testRejectNonJarFiles.

@Test
public void testRejectNonJarFiles() throws Exception {
    final Path uploadedFile = Files.createFile(jarDir.resolve("katrin.png"));
    final HandlerRequest<EmptyRequestBody> request = createRequest(uploadedFile);
    try {
        jarUploadHandler.handleRequest(request, mockDispatcherGateway).get();
        fail("Expected exception not thrown.");
    } catch (final ExecutionException e) {
        final Throwable throwable = ExceptionUtils.stripCompletionException(e.getCause());
        assertThat(throwable, instanceOf(RestHandlerException.class));
        final RestHandlerException restHandlerException = (RestHandlerException) throwable;
        assertThat(restHandlerException.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
    }
}
Also used : Path(java.nio.file.Path) ExecutionException(java.util.concurrent.ExecutionException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test)

Example 2 with EmptyRequestBody

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

the class JobManagerLogListHandler method handleRequest.

@Override
protected CompletableFuture<LogListInfo> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
    if (logDir == null) {
        return CompletableFuture.completedFuture(new LogListInfo(Collections.emptyList()));
    }
    final File[] logFiles = logDir.listFiles();
    if (logFiles == null) {
        return FutureUtils.completedExceptionally(new IOException("Could not list files in " + logDir));
    }
    final List<LogInfo> logs = Arrays.stream(logFiles).filter(File::isFile).map(logFile -> new LogInfo(logFile.getName(), logFile.length(), logFile.lastModified())).collect(Collectors.toList());
    return CompletableFuture.completedFuture(new LogListInfo(logs));
}
Also used : LogListInfo(org.apache.flink.runtime.rest.messages.LogListInfo) Arrays(java.util.Arrays) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) LogInfo(org.apache.flink.runtime.rest.messages.LogInfo) MessageHeaders(org.apache.flink.runtime.rest.messages.MessageHeaders) Collectors(java.util.stream.Collectors) File(java.io.File) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) List(java.util.List) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Map(java.util.Map) LogListInfo(org.apache.flink.runtime.rest.messages.LogListInfo) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) AbstractRestHandler(org.apache.flink.runtime.rest.handler.AbstractRestHandler) Nullable(javax.annotation.Nullable) LogInfo(org.apache.flink.runtime.rest.messages.LogInfo) IOException(java.io.IOException) File(java.io.File)

Example 3 with EmptyRequestBody

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

the class RestServerEndpointITCase method setup.

@Before
public void setup() throws Exception {
    config.setString(WebOptions.UPLOAD_DIR, temporaryFolder.newFolder().getCanonicalPath());
    defaultSSLContext = SSLContext.getDefault();
    defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
    final SSLContext sslClientContext = SSLUtils.createRestSSLContext(config, true);
    if (sslClientContext != null) {
        SSLContext.setDefault(sslClientContext);
        HttpsURLConnection.setDefaultSSLSocketFactory(sslClientContext.getSocketFactory());
    }
    RestfulGateway mockRestfulGateway = new TestingRestfulGateway.Builder().build();
    final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () -> CompletableFuture.completedFuture(mockRestfulGateway);
    testHandler = new TestHandler(mockGatewayRetriever, RpcUtils.INF_TIMEOUT);
    TestVersionHandler testVersionHandler = new TestVersionHandler(mockGatewayRetriever, RpcUtils.INF_TIMEOUT);
    TestRestHandler<RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> testVersionSelectionHandler1 = new TestRestHandler<>(mockGatewayRetriever, TestVersionSelectionHeaders1.INSTANCE, FutureUtils.completedExceptionally(new RestHandlerException("test failure 1", HttpResponseStatus.OK)));
    TestRestHandler<RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> testVersionSelectionHandler2 = new TestRestHandler<>(mockGatewayRetriever, TestVersionSelectionHeaders2.INSTANCE, FutureUtils.completedExceptionally(new RestHandlerException("test failure 2", HttpResponseStatus.ACCEPTED)));
    testUploadHandler = new TestUploadHandler(mockGatewayRetriever, RpcUtils.INF_TIMEOUT);
    final StaticFileServerHandler<RestfulGateway> staticFileServerHandler = new StaticFileServerHandler<>(mockGatewayRetriever, RpcUtils.INF_TIMEOUT, temporaryFolder.getRoot());
    serverEndpoint = TestRestServerEndpoint.builder(config).withHandler(new TestHeaders(), testHandler).withHandler(TestUploadHeaders.INSTANCE, testUploadHandler).withHandler(testVersionHandler).withHandler(testVersionSelectionHandler1).withHandler(testVersionSelectionHandler2).withHandler(WebContentHandlerSpecification.getInstance(), staticFileServerHandler).buildAndStart();
    restClient = new TestRestClient(config);
    serverAddress = serverEndpoint.getServerAddress();
}
Also used : SSLContext(javax.net.ssl.SSLContext) EmptyResponseBody(org.apache.flink.runtime.rest.messages.EmptyResponseBody) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) StaticFileServerHandler(org.apache.flink.runtime.rest.handler.legacy.files.StaticFileServerHandler) TestRestHandler(org.apache.flink.runtime.rest.util.TestRestHandler) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) Before(org.junit.Before)

Example 4 with EmptyRequestBody

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

the class JobConfigHandlerTest method handleRequest_executionConfigWithSecretValues_excludesSecretValuesFromResponse.

@Test
public void handleRequest_executionConfigWithSecretValues_excludesSecretValuesFromResponse() throws HandlerRequestException {
    final JobConfigHandler jobConfigHandler = new JobConfigHandler(() -> null, TestingUtils.TIMEOUT, Collections.emptyMap(), JobConfigHeaders.getInstance(), new DefaultExecutionGraphCache(TestingUtils.TIMEOUT, TestingUtils.TIMEOUT), TestingUtils.defaultExecutor());
    final Map<String, String> globalJobParameters = new HashMap<>();
    globalJobParameters.put("foobar", "barfoo");
    globalJobParameters.put("bar.secret.foo", "my secret");
    globalJobParameters.put("password.to.my.safe", "12345");
    final ArchivedExecutionConfig archivedExecutionConfig = new ArchivedExecutionConfigBuilder().setGlobalJobParameters(globalJobParameters).build();
    final AccessExecutionGraph archivedExecutionGraph = new ArchivedExecutionGraphBuilder().setArchivedExecutionConfig(archivedExecutionConfig).build();
    final HandlerRequest<EmptyRequestBody> handlerRequest = createRequest(archivedExecutionGraph.getJobID());
    final JobConfigInfo jobConfigInfoResponse = jobConfigHandler.handleRequest(handlerRequest, archivedExecutionGraph);
    final Map<String, String> filteredGlobalJobParameters = filterSecretValues(globalJobParameters);
    assertThat(jobConfigInfoResponse.getExecutionConfigInfo().getGlobalJobParameters(), is(equalTo(filteredGlobalJobParameters)));
}
Also used : JobConfigInfo(org.apache.flink.runtime.rest.messages.JobConfigInfo) ArchivedExecutionConfig(org.apache.flink.api.common.ArchivedExecutionConfig) HashMap(java.util.HashMap) DefaultExecutionGraphCache(org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache) AccessExecutionGraph(org.apache.flink.runtime.executiongraph.AccessExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) ArchivedExecutionConfigBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionConfigBuilder) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Test(org.junit.Test)

Example 5 with EmptyRequestBody

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

the class JobVertexBackPressureHandlerTest method testGetBackPressure.

@Test
public void testGetBackPressure() throws Exception {
    final Map<String, String> pathParameters = new HashMap<>();
    pathParameters.put(JobIDPathParameter.KEY, TEST_JOB_ID_BACK_PRESSURE_STATS_AVAILABLE.toString());
    pathParameters.put(JobVertexIdPathParameter.KEY, TEST_JOB_VERTEX_ID.toString());
    final HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new JobVertexMessageParameters(), pathParameters, Collections.emptyMap(), Collections.emptyList());
    final CompletableFuture<JobVertexBackPressureInfo> jobVertexBackPressureInfoCompletableFuture = jobVertexBackPressureHandler.handleRequest(request, restfulGateway);
    final JobVertexBackPressureInfo jobVertexBackPressureInfo = jobVertexBackPressureInfoCompletableFuture.get();
    assertThat(jobVertexBackPressureInfo.getStatus(), equalTo(VertexBackPressureStatus.OK));
    assertThat(jobVertexBackPressureInfo.getBackpressureLevel(), equalTo(HIGH));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getBackPressuredRatio).collect(Collectors.toList()), contains(1.0, 0.5, 0.1));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getIdleRatio).collect(Collectors.toList()), contains(0.0, 0.1, 0.2));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getBusyRatio).collect(Collectors.toList()), contains(0.0, 0.9, 0.7));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getBackpressureLevel).collect(Collectors.toList()), contains(HIGH, LOW, OK));
    assertThat(jobVertexBackPressureInfo.getSubtasks().stream().map(SubtaskBackPressureInfo::getSubtask).collect(Collectors.toList()), contains(0, 1, 3));
}
Also used : HashMap(java.util.HashMap) JobVertexBackPressureInfo(org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) SubtaskBackPressureInfo(org.apache.flink.runtime.rest.messages.JobVertexBackPressureInfo.SubtaskBackPressureInfo) JobVertexMessageParameters(org.apache.flink.runtime.rest.messages.JobVertexMessageParameters) Test(org.junit.Test)

Aggregations

EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)30 Test (org.junit.Test)23 HashMap (java.util.HashMap)12 List (java.util.List)8 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)7 AggregatedMetric (org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetric)7 AggregatedMetricsResponseBody (org.apache.flink.runtime.rest.messages.job.metrics.AggregatedMetricsResponseBody)7 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)6 JobExceptionsInfoWithHistory (org.apache.flink.runtime.rest.messages.JobExceptionsInfoWithHistory)5 ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)5 Map (java.util.Map)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Nonnull (javax.annotation.Nonnull)4 JobID (org.apache.flink.api.common.JobID)4 Time (org.apache.flink.api.common.time.Time)4 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)4 DefaultExecutionGraphCache (org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache)4 Path (java.nio.file.Path)3 CompletionException (java.util.concurrent.CompletionException)3 ExecutionException (java.util.concurrent.ExecutionException)3