use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class JarListHandler method handleRequest.
@Override
protected CompletableFuture<JarListInfo> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
final String localAddress;
Preconditions.checkState(localAddressFuture.isDone());
try {
localAddress = localAddressFuture.get();
} catch (Exception e) {
return FutureUtils.completedExceptionally(e);
}
return CompletableFuture.supplyAsync(() -> {
try {
final File[] list = getJarFiles();
final List<JarListInfo.JarFileInfo> jarFileList = new ArrayList<>(list.length);
for (File f : list) {
// separate the uuid and the name parts.
String id = f.getName();
int startIndex = id.indexOf("_");
if (startIndex < 0) {
continue;
}
String name = id.substring(startIndex + 1);
if (name.length() < 5 || !name.endsWith(".jar")) {
continue;
}
List<JarListInfo.JarEntryInfo> jarEntryList = new ArrayList<>();
String[] classes = new String[0];
try (JarFile jar = new JarFile(f)) {
Manifest manifest = jar.getManifest();
String assemblerClass = null;
if (manifest != null) {
assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS);
if (assemblerClass == null) {
assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS);
}
}
if (assemblerClass != null) {
classes = assemblerClass.split(",");
}
} catch (IOException ignored) {
// we simply show no entries here
}
// show every entry class that can be loaded later on.
for (String clazz : classes) {
clazz = clazz.trim();
try (PackagedProgram program = PackagedProgram.newBuilder().setJarFile(f).setEntryPointClassName(clazz).setConfiguration(configuration).build()) {
JarListInfo.JarEntryInfo jarEntryInfo = new JarListInfo.JarEntryInfo(clazz, program.getDescription());
jarEntryList.add(jarEntryInfo);
} catch (Exception ignored) {
// ignore jar files which throw an error upon creating a
// PackagedProgram
}
}
jarFileList.add(new JarListInfo.JarFileInfo(id, name, f.lastModified(), jarEntryList));
}
return new JarListInfo(localAddress, jarFileList);
} catch (Exception e) {
throw new CompletionException(new FlinkException("Failed to fetch jar list.", e));
}
}, executor);
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class RestClusterClientTest method testSendIsNotRetriableIfHttpNotFound.
/**
* Tests that the send operation is not being retried when receiving a NOT_FOUND return code.
*/
@Test
public void testSendIsNotRetriableIfHttpNotFound() throws Exception {
final String exceptionMessage = "test exception";
final PingRestHandler pingRestHandler = new PingRestHandler(FutureUtils.completedExceptionally(new RestHandlerException(exceptionMessage, HttpResponseStatus.NOT_FOUND)));
try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(pingRestHandler)) {
RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
try {
restClusterClient.sendRequest(PingRestHandlerHeaders.INSTANCE).get();
fail("The rest request should have failed.");
} catch (Exception e) {
assertThat(ExceptionUtils.findThrowableWithMessage(e, exceptionMessage).isPresent(), is(true));
} finally {
restClusterClient.close();
}
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class JobSubmitHandlerTest method testRejectionOnCountMismatch.
@Test
public void testRejectionOnCountMismatch() throws Exception {
final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
objectOut.writeObject(JobGraphTestUtils.emptyJobGraph());
}
final Path countExceedingFile = TEMPORARY_FOLDER.newFile().toPath();
TestingDispatcherGateway.Builder builder = TestingDispatcherGateway.newBuilder();
builder.setBlobServerPort(blobServer.getPort()).setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get())).setHostname("localhost");
DispatcherGateway mockGateway = builder.build();
JobSubmitHandler handler = new JobSubmitHandler(() -> CompletableFuture.completedFuture(mockGateway), RpcUtils.INF_TIMEOUT, Collections.emptyMap(), TestingUtils.defaultExecutor(), configuration);
JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());
try {
handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance(), Arrays.asList(jobGraphFile.toFile(), countExceedingFile.toFile())), mockGateway).get();
} catch (Exception e) {
ExceptionUtils.findThrowable(e, candidate -> candidate instanceof RestHandlerException && candidate.getMessage().contains("count"));
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class JobSubmitHandlerTest method testSerializationFailureHandling.
@Test
public void testSerializationFailureHandling() throws Exception {
final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
DispatcherGateway mockGateway = TestingDispatcherGateway.newBuilder().setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get())).build();
JobSubmitHandler handler = new JobSubmitHandler(() -> CompletableFuture.completedFuture(mockGateway), RpcUtils.INF_TIMEOUT, Collections.emptyMap(), TestingUtils.defaultExecutor(), configuration);
JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.toString(), Collections.emptyList(), Collections.emptyList());
try {
handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance()), mockGateway);
Assert.fail();
} catch (RestHandlerException rhe) {
Assert.assertEquals(HttpResponseStatus.BAD_REQUEST, rhe.getHttpResponseStatus());
}
}
use of org.apache.flink.runtime.rest.handler.RestHandlerException in project flink by apache.
the class StopWithSavepointHandlersTest method testTriggerSavepointNoDirectory.
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setStopWithSavepointFunction((AsynchronousJobOperationKey operationKey, String directory, SavepointFormatType formatType) -> CompletableFuture.completedFuture(Acknowledge.get())).build();
try {
savepointTriggerHandler.handleRequest(triggerSavepointRequestWithDefaultDirectory(), testingRestfulGateway).get();
fail("Expected exception not thrown.");
} catch (RestHandlerException rhe) {
assertThat(rhe.getMessage(), equalTo("Config key [state.savepoints.dir] is not set. " + "Property [targetDirectory] must be provided."));
assertThat(rhe.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
}
}
Aggregations