use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.
the class JobExecutionResultHandler method handleRequest.
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
final CompletableFuture<JobStatus> jobStatusFuture = gateway.requestJobStatus(jobId, timeout);
return jobStatusFuture.thenCompose(jobStatus -> {
if (jobStatus.isGloballyTerminalState()) {
return gateway.requestJobResult(jobId, timeout).thenApply(JobExecutionResultResponseBody::created);
} else {
return CompletableFuture.completedFuture(JobExecutionResultResponseBody.inProgress());
}
}).exceptionally(throwable -> {
throw propagateException(throwable);
});
}
use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.
the class MultipartUploadResource method before.
@Override
public void before() throws Exception {
temporaryFolder.create();
Configuration config = new Configuration();
config.setString(RestOptions.BIND_PORT, "0");
config.setString(RestOptions.ADDRESS, "localhost");
// set this to a lower value on purpose to test that files larger than the content limit are
// still accepted
config.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, 1024 * 1024);
configuredUploadDir = temporaryFolder.newFolder().toPath();
config.setString(WebOptions.UPLOAD_DIR, configuredUploadDir.toString());
RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);
final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () -> CompletableFuture.completedFuture(mockRestfulGateway);
file1 = temporaryFolder.newFile();
try (RandomAccessFile rw = new RandomAccessFile(file1, "rw")) {
// magic value that reliably reproduced https://github.com/netty/netty/issues/11668
rw.setLength(5043444);
}
file2 = temporaryFolder.newFile();
Files.write(file2.toPath(), "world".getBytes(ConfigConstants.DEFAULT_CHARSET));
mixedHandler = new MultipartMixedHandler(mockGatewayRetriever);
jsonHandler = new MultipartJsonHandler(mockGatewayRetriever);
fileHandler = new MultipartFileHandler(mockGatewayRetriever);
serverEndpoint = TestRestServerEndpoint.builder(config).withHandler(mixedHandler).withHandler(jsonHandler).withHandler(fileHandler).buildAndStart();
serverAddress = serverEndpoint.getRestBaseUrl();
serverSocketAddress = serverEndpoint.getServerAddress();
this.setFileUploadVerifier((request, restfulGateway) -> {
// the default verifier checks for identiy (i.e. same name and content) of all
// uploaded files
List<Path> expectedFiles = getFilesToUpload().stream().map(File::toPath).collect(Collectors.toList());
List<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
assertEquals(expectedFiles.size(), uploadedFiles.size());
List<Path> expectedList = new ArrayList<>(expectedFiles);
List<Path> actualList = new ArrayList<>(uploadedFiles);
expectedList.sort(Comparator.comparing(Path::toString));
actualList.sort(Comparator.comparing(Path::toString));
for (int x = 0; x < expectedList.size(); x++) {
Path expected = expectedList.get(x);
Path actual = actualList.get(x);
assertEquals(expected.getFileName().toString(), actual.getFileName().toString());
byte[] originalContent = Files.readAllBytes(expected);
byte[] receivedContent = Files.readAllBytes(actual);
assertArrayEquals(originalContent, receivedContent);
}
});
}
use of org.apache.flink.runtime.webmonitor.RestfulGateway in project flink by apache.
the class MetricFetcherTest method testLongUpdateInterval.
@Test
public void testLongUpdateInterval() {
final long updateInterval = 1000L;
final AtomicInteger requestMetricQueryServiceGatewaysCounter = new AtomicInteger(0);
final RestfulGateway restfulGateway = createRestfulGateway(requestMetricQueryServiceGatewaysCounter);
final MetricFetcher fetcher = createMetricFetcher(updateInterval, restfulGateway);
fetcher.update();
fetcher.update();
assertThat(requestMetricQueryServiceGatewaysCounter.get(), is(1));
}
Aggregations