Java源码示例:org.apache.flink.runtime.webmonitor.RestfulGateway
示例1
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(
@Nonnull final HandlerRequest<EmptyRequestBody, JarDeleteMessageParameters> request,
@Nonnull final RestfulGateway gateway) throws RestHandlerException {
final String jarId = request.getPathParameter(JarIdPathParameter.class);
return CompletableFuture.supplyAsync(() -> {
final Path jarToDelete = jarDir.resolve(jarId);
if (!Files.exists(jarToDelete)) {
throw new CompletionException(new RestHandlerException(
String.format("File %s does not exist in %s.", jarId, jarDir),
HttpResponseStatus.BAD_REQUEST));
} else {
try {
Files.delete(jarToDelete);
return EmptyResponseBody.getInstance();
} catch (final IOException e) {
throw new CompletionException(new RestHandlerException(
String.format("Failed to delete jar %s.", jarToDelete),
HttpResponseStatus.INTERNAL_SERVER_ERROR,
e));
}
}
}, executor);
}
示例2
public MiniDispatcherRestEndpoint(
RestServerEndpointConfiguration endpointConfiguration,
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Configuration clusterConfiguration,
RestHandlerConfiguration restConfiguration,
GatewayRetriever<ResourceManagerGateway> resourceManagerRetriever,
TransientBlobService transientBlobService,
ExecutorService executor,
MetricFetcher metricFetcher,
LeaderElectionService leaderElectionService,
FatalErrorHandler fatalErrorHandler) throws IOException {
super(
endpointConfiguration,
leaderRetriever,
clusterConfiguration,
restConfiguration,
resourceManagerRetriever,
transientBlobService,
executor,
metricFetcher,
leaderElectionService,
fatalErrorHandler);
}
示例3
public JarPlanHandler(
final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
final Time timeout,
final Map<String, String> responseHeaders,
final MessageHeaders<JarPlanRequestBody, JobPlanInfo, JarPlanMessageParameters> messageHeaders,
final Path jarDir,
final Configuration configuration,
final Executor executor) {
this(
leaderRetriever,
timeout,
responseHeaders,
messageHeaders,
jarDir,
configuration,
executor,
jobGraph -> new JobPlanInfo(JsonPlanGenerator.generatePlan(jobGraph)));
}
示例4
public JobExceptionsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, JobExceptionsInfo, JobExceptionsMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor) {
super(
leaderRetriever,
timeout,
responseHeaders,
messageHeaders,
executionGraphCache,
executor);
}
示例5
@Override
protected CompletableFuture<R> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, M> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
JobID jobId = request.getPathParameter(JobIDPathParameter.class);
CompletableFuture<AccessExecutionGraph> executionGraphFuture = executionGraphCache.getExecutionGraph(jobId, gateway);
return executionGraphFuture.thenApplyAsync(
executionGraph -> {
try {
return handleRequest(request, executionGraph);
} catch (RestHandlerException rhe) {
throw new CompletionException(rhe);
}
}, executor)
.exceptionally(throwable -> {
throwable = ExceptionUtils.stripCompletionException(throwable);
if (throwable instanceof FlinkJobNotFoundException) {
throw new CompletionException(
new NotFoundException(String.format("Job %s not found", jobId), throwable));
} else {
throw new CompletionException(throwable);
}
});
}
示例6
@Before
public void setUp() throws Exception {
MetricFetcher fetcher = new MetricFetcherImpl<RestfulGateway>(
mock(GatewayRetriever.class),
mock(MetricQueryServiceRetriever.class),
Executors.directExecutor(),
TestingUtils.TIMEOUT(),
MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
store = fetcher.getMetricStore();
Collection<MetricDump> metricDumps = getMetricDumps();
for (MetricDump dump : metricDumps) {
store.add(dump);
}
handler = getHandler(
LEADER_RETRIEVER,
TIMEOUT,
TEST_HEADERS,
EXECUTOR,
fetcher);
pathParameters = getPathParameters();
}
示例7
public CheckpointStatisticDetailsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, CheckpointStatistics, CheckpointMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor,
CheckpointStatsCache checkpointStatsCache) {
super(
leaderRetriever,
timeout,
responseHeaders,
messageHeaders,
executionGraphCache,
executor,
checkpointStatsCache);
}
示例8
@Test
public void testShortUpdateInterval() throws InterruptedException {
final long updateInterval = 1L;
final AtomicInteger requestMetricQueryServiceGatewaysCounter = new AtomicInteger(0);
final RestfulGateway restfulGateway = createRestfulGateway(requestMetricQueryServiceGatewaysCounter);
final MetricFetcher fetcher = createMetricFetcher(updateInterval, restfulGateway);
fetcher.update();
final long start = System.currentTimeMillis();
long difference = 0L;
while (difference <= updateInterval) {
Thread.sleep(2L * updateInterval);
difference = System.currentTimeMillis() - start;
}
fetcher.update();
assertThat(requestMetricQueryServiceGatewaysCounter.get(), is(2));
}
示例9
public JobVertexDetailsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, JobVertexDetailsInfo, JobVertexMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor,
MetricFetcher metricFetcher) {
super(
leaderRetriever,
timeout,
responseHeaders,
messageHeaders,
executionGraphCache,
executor);
this.metricFetcher = metricFetcher;
}
示例10
public TaskCheckpointStatisticDetailsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, TaskCheckpointStatisticsWithSubtaskDetails, TaskCheckpointMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor,
CheckpointStatsCache checkpointStatsCache) {
super(
leaderRetriever,
timeout,
responseHeaders,
messageHeaders,
executionGraphCache,
executor,
checkpointStatsCache);
}
示例11
public JobPlanHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> headers,
MessageHeaders<EmptyRequestBody, JobPlanInfo, JobMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor) {
super(
leaderRetriever,
timeout,
headers,
messageHeaders,
executionGraphCache,
executor);
}
示例12
public ShutdownHandler(
final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
final Time timeout,
final Map<String, String> responseHeaders,
final MessageHeaders<EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> messageHeaders) {
super(leaderRetriever, timeout, responseHeaders, messageHeaders);
}
示例13
public JarListHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, JarListInfo, EmptyMessageParameters> messageHeaders,
CompletableFuture<String> localAddressFuture,
File jarDir,
Executor executor) {
super(leaderRetriever, timeout, responseHeaders, messageHeaders);
this.localAddressFuture = localAddressFuture;
this.jarDir = requireNonNull(jarDir);
this.executor = requireNonNull(executor);
}
示例14
@Override
protected CompletableFuture<JobPlanInfo> handleRequest(
@Nonnull final HandlerRequest<JarPlanRequestBody, JarPlanMessageParameters> request,
@Nonnull final RestfulGateway gateway) throws RestHandlerException {
final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);
return CompletableFuture.supplyAsync(() -> {
final JobGraph jobGraph = context.toJobGraph(configuration);
return planGenerator.apply(jobGraph);
}, executor);
}
示例15
private static String uploadJar(JarUploadHandler handler, Path jar, RestfulGateway restfulGateway) throws Exception {
HandlerRequest<EmptyRequestBody, EmptyMessageParameters> uploadRequest = new HandlerRequest<>(
EmptyRequestBody.getInstance(),
EmptyMessageParameters.getInstance(),
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonList(jar.toFile()));
final JarUploadResponseBody uploadResponse = handler.handleRequest(uploadRequest, restfulGateway)
.get();
return uploadResponse.getFilename();
}
示例16
@Nonnull
public static <T extends RestfulGateway> MetricFetcherImpl<T> fromConfiguration(
final Configuration configuration,
final MetricQueryServiceRetriever metricQueryServiceGatewayRetriever, final GatewayRetriever<T> dispatcherGatewayRetriever,
final ExecutorService executor) {
final Time timeout = Time.milliseconds(configuration.getLong(WebOptions.TIMEOUT));
final long updateInterval = configuration.getLong(MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL);
return new MetricFetcherImpl<>(
dispatcherGatewayRetriever,
metricQueryServiceGatewayRetriever,
executor,
timeout,
updateInterval);
}
示例17
public JobMetricsHandler(
final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
final Time timeout,
final Map<String, String> headers,
final MetricFetcher metricFetcher) {
super(leaderRetriever, timeout, headers, JobMetricsHeaders.getInstance(), metricFetcher);
}
示例18
/**
* Instantiates a new Abstract job vertex handler.
*
* @param leaderRetriever the leader retriever
* @param timeout the timeout
* @param responseHeaders the response headers
* @param messageHeaders the message headers
* @param executionGraphCache the execution graph cache
* @param executor the executor
*/
public SubtaskExecutionAttemptAccumulatorsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, SubtaskExecutionAttemptAccumulatorsInfo, SubtaskAttemptMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor) {
super(leaderRetriever, timeout, responseHeaders, messageHeaders, executionGraphCache, executor);
}
示例19
public TaskManagerDetailsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, TaskManagerDetailsInfo, TaskManagerMessageParameters> messageHeaders,
GatewayRetriever<ResourceManagerGateway> resourceManagerGatewayRetriever,
MetricFetcher metricFetcher) {
super(leaderRetriever, timeout, responseHeaders, messageHeaders, resourceManagerGatewayRetriever);
this.metricFetcher = Preconditions.checkNotNull(metricFetcher);
this.metricStore = metricFetcher.getMetricStore();
}
示例20
public CheckpointConfigHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, CheckpointConfigInfo, JobMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor) {
super(
leaderRetriever,
timeout,
responseHeaders,
messageHeaders,
executionGraphCache,
executor);
}
示例21
@Override
protected AggregatingSubtasksMetricsHandler getHandler(GatewayRetriever<? extends RestfulGateway> leaderRetriever, Time timeout, Map<String, String> responseHeaders, Executor executor, MetricFetcher fetcher) {
return new AggregatingSubtasksMetricsHandler(
leaderRetriever,
timeout,
responseHeaders,
executor,
fetcher
);
}
示例22
public SubtasksTimesHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, SubtasksTimesInfo, JobVertexMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor) {
super(
leaderRetriever,
timeout,
responseHeaders,
messageHeaders,
executionGraphCache,
executor);
}
示例23
public JobAccumulatorsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, JobAccumulatorsInfo, JobAccumulatorsMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor) {
super(
leaderRetriever,
timeout,
responseHeaders,
messageHeaders,
executionGraphCache,
executor);
}
示例24
public CheckpointingStatisticsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, CheckpointingStatistics, JobMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor) {
super(leaderRetriever, timeout, responseHeaders, messageHeaders, executionGraphCache, executor);
}
示例25
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
if (uploadedFiles.size() != 1) {
throw new RestHandlerException("Expected 1 file, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST);
}
try {
lastUploadedFileContents = Files.readAllBytes(uploadedFiles.iterator().next());
} catch (IOException e) {
throw new RestHandlerException("Could not read contents of uploaded file.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
}
return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
示例26
public DashboardConfigHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, DashboardConfiguration, EmptyMessageParameters> messageHeaders,
long refreshInterval) {
super(leaderRetriever, timeout, responseHeaders, messageHeaders);
dashboardConfiguration = DashboardConfiguration.from(refreshInterval, ZonedDateTime.now());
}
示例27
private static void deleteJar(JarDeleteHandler handler, String jarName, RestfulGateway restfulGateway) throws Exception {
JarDeleteMessageParameters deleteParameters = JarDeleteHeaders.getInstance().getUnresolvedMessageParameters();
HandlerRequest<EmptyRequestBody, JarDeleteMessageParameters> deleteRequest = new HandlerRequest<>(
EmptyRequestBody.getInstance(),
deleteParameters,
Collections.singletonMap(deleteParameters.jarIdPathParameter.getKey(), jarName),
Collections.emptyMap(),
Collections.emptyList());
handler.handleRequest(deleteRequest, restfulGateway)
.get();
}
示例28
@Override
protected AggregatingJobsMetricsHandler getHandler(GatewayRetriever<? extends RestfulGateway> leaderRetriever, Time timeout, Map<String, String> responseHeaders, Executor executor, MetricFetcher fetcher) {
return new AggregatingJobsMetricsHandler(
leaderRetriever,
timeout,
responseHeaders,
executor,
fetcher
);
}
示例29
/**
* Instantiates a new Abstract job vertex handler.
*
* @param leaderRetriever the leader retriever
* @param timeout the timeout
* @param responseHeaders the response headers
* @param messageHeaders the message headers
* @param executionGraphCache the execution graph cache
* @param executor the executor
*/
public SubtaskExecutionAttemptAccumulatorsHandler(
GatewayRetriever<? extends RestfulGateway> leaderRetriever,
Time timeout,
Map<String, String> responseHeaders,
MessageHeaders<EmptyRequestBody, SubtaskExecutionAttemptAccumulatorsInfo, SubtaskAttemptMessageParameters> messageHeaders,
ExecutionGraphCache executionGraphCache,
Executor executor) {
super(leaderRetriever, timeout, responseHeaders, messageHeaders, executionGraphCache, executor);
}
示例30
private RestfulGateway createRestfulGateway(AtomicInteger requestMetricQueryServiceGatewaysCounter) {
return new TestingRestfulGateway.Builder()
.setRequestMetricQueryServiceGatewaysSupplier(() -> {
requestMetricQueryServiceGatewaysCounter.incrementAndGet();
return new CompletableFuture<>();
})
.build();
}