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));
}
}
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));
}
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();
}
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)));
}
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));
}
Aggregations