use of org.apache.flink.runtime.webmonitor.RestfulGateway 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.webmonitor.RestfulGateway 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.webmonitor.RestfulGateway in project flink by apache.
the class RestServerSSLAuthITCase method testConnectFailure.
@Test
public void testConnectFailure() throws Exception {
RestClient restClient = null;
RestServerEndpoint serverEndpoint = null;
try {
RestfulGateway restfulGateway = new TestingRestfulGateway.Builder().build();
RestServerEndpointITCase.TestVersionHandler testVersionHandler = new RestServerEndpointITCase.TestVersionHandler(() -> CompletableFuture.completedFuture(restfulGateway), RpcUtils.INF_TIMEOUT);
serverEndpoint = TestRestServerEndpoint.builder(serverConfig).withHandler(testVersionHandler.getMessageHeaders(), testVersionHandler).buildAndStart();
restClient = new RestServerEndpointITCase.TestRestClient(clientConfig);
CompletableFuture<EmptyResponseBody> response = restClient.sendRequest(serverEndpoint.getServerAddress().getHostName(), serverEndpoint.getServerAddress().getPort(), RestServerEndpointITCase.TestVersionHeaders.INSTANCE, EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance(), Collections.emptyList());
response.get(60, TimeUnit.SECONDS);
fail("should never complete normally");
} catch (ExecutionException exception) {
// that is what we want
assertTrue(ExceptionUtils.findThrowable(exception, SSLException.class).isPresent());
} finally {
if (restClient != null) {
restClient.shutdown(timeout);
}
if (serverEndpoint != null) {
serverEndpoint.close();
}
}
}
use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.
the class AbstractHandlerTest method testFileCleanup.
@Test
public void testFileCleanup() throws Exception {
final Path dir = temporaryFolder.newFolder().toPath();
final Path file = dir.resolve("file");
Files.createFile(file);
RestfulGateway mockRestfulGateway = new TestingRestfulGateway.Builder().build();
final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () -> CompletableFuture.completedFuture(mockRestfulGateway);
CompletableFuture<Void> requestProcessingCompleteFuture = new CompletableFuture<>();
TestHandler handler = new TestHandler(requestProcessingCompleteFuture, mockGatewayRetriever);
RouteResult<?> routeResult = new RouteResult<>("", "", Collections.emptyMap(), Collections.emptyMap(), "");
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, TestHandler.TestHeaders.INSTANCE.getTargetRestEndpointURL(), Unpooled.wrappedBuffer(new byte[0]));
RoutedRequest<?> routerRequest = new RoutedRequest<>(routeResult, request);
Attribute<FileUploads> attribute = new SimpleAttribute();
attribute.set(new FileUploads(dir));
Channel channel = mock(Channel.class);
when(channel.attr(any(AttributeKey.class))).thenReturn(attribute);
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
when(context.channel()).thenReturn(channel);
handler.respondAsLeader(context, routerRequest, mockRestfulGateway);
// the (asynchronous) request processing is not yet complete so the files should still exist
Assert.assertTrue(Files.exists(file));
requestProcessingCompleteFuture.complete(null);
Assert.assertFalse(Files.exists(file));
}
use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.
the class JobCancellationHandlerTest method testResponse.
private static void testResponse(Function<JobID, CompletableFuture<Acknowledge>> cancelJobFunction, ThrowingConsumer<CompletableFuture<EmptyResponseBody>, Exception> assertion) throws Exception {
final RestfulGateway gateway = createGateway(cancelJobFunction);
final JobCancellationHandler jobCancellationHandler = createHandler(gateway);
final JobCancellationMessageParameters messageParameters = jobCancellationHandler.getMessageHeaders().getUnresolvedMessageParameters().resolveJobId(new JobID());
final CompletableFuture<EmptyResponseBody> cancellationFuture = jobCancellationHandler.handleRequest(HandlerRequest.create(EmptyRequestBody.getInstance(), messageParameters), gateway);
assertion.accept(cancellationFuture);
}
Aggregations