use of org.apache.flink.runtime.rest.handler.RestHandlerException 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.handler.RestHandlerException in project flink by apache.
the class AbstractAsynchronousOperationHandlersTest method testUnknownTriggerId.
/**
* Tests that an querying an unknown trigger id will return an exceptionally completed future.
*/
@Test
public void testUnknownTriggerId() throws Exception {
try {
testingStatusHandler.handleRequest(statusOperationRequest(new TriggerId()), DUMMY_GATEWAY).get();
fail("This should have failed with a RestHandlerException.");
} catch (ExecutionException ee) {
final Optional<RestHandlerException> optionalRestHandlerException = ExceptionUtils.findThrowable(ee, RestHandlerException.class);
assertThat(optionalRestHandlerException.isPresent(), is(true));
final RestHandlerException restHandlerException = optionalRestHandlerException.get();
assertThat(restHandlerException.getMessage(), containsString("Operation not found"));
assertThat(restHandlerException.getHttpResponseStatus(), is(HttpResponseStatus.NOT_FOUND));
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class JobExecutionResultHandlerTest method testPropagateFlinkJobNotFoundExceptionAsRestHandlerException.
@Test
public void testPropagateFlinkJobNotFoundExceptionAsRestHandlerException() throws Exception {
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId))).build();
try {
jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
fail("Expected exception not thrown");
} catch (final ExecutionException e) {
final Throwable cause = ExceptionUtils.stripCompletionException(e.getCause());
assertThat(cause, instanceOf(RestHandlerException.class));
assertThat(((RestHandlerException) cause).getHttpResponseStatus(), equalTo(HttpResponseStatus.NOT_FOUND));
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class JarRunHandler method handleRequest.
@Override
@VisibleForTesting
public CompletableFuture<JarRunResponseBody> handleRequest(@Nonnull final HandlerRequest<JarRunRequestBody> request, @Nonnull final DispatcherGateway gateway) throws RestHandlerException {
final Configuration effectiveConfiguration = new Configuration(configuration);
effectiveConfiguration.set(DeploymentOptions.ATTACHED, false);
effectiveConfiguration.set(DeploymentOptions.TARGET, EmbeddedExecutor.NAME);
final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);
context.applyToConfiguration(effectiveConfiguration);
SavepointRestoreSettings.toConfiguration(getSavepointRestoreSettings(request), effectiveConfiguration);
final PackagedProgram program = context.toPackagedProgram(effectiveConfiguration);
return CompletableFuture.supplyAsync(() -> applicationRunner.run(gateway, program, effectiveConfiguration), executor).handle((jobIds, throwable) -> {
program.close();
if (throwable != null) {
throw new CompletionException(new RestHandlerException("Could not execute application.", HttpResponseStatus.BAD_REQUEST, throwable));
} else if (jobIds.isEmpty()) {
throw new CompletionException(new RestHandlerException("No jobs included in application.", HttpResponseStatus.BAD_REQUEST));
}
return new JarRunResponseBody(jobIds.get(0));
});
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class JarUploadHandlerTest method testFailedUpload.
@Test
public void testFailedUpload() throws Exception {
final Path uploadedFile = jarDir.resolve("FooBazzleExample.jar");
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.getMessage(), containsString("Could not move uploaded jar file"));
assertThat(restHandlerException.getHttpResponseStatus(), equalTo(HttpResponseStatus.INTERNAL_SERVER_ERROR));
}
}
Aggregations