org.apache.flink.runtime.rest.handler.HandlerRequest Java Examples

The following examples show how to use org.apache.flink.runtime.rest.handler.HandlerRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractMetricsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMetrics() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList(TEST_METRIC_NAME))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(TEST_METRIC_NAME));
	assertThat(metric.getValue(), equalTo(Integer.toString(TEST_METRIC_VALUE)));
}
 
Example #2
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnEmptyListIfRequestedMetricIsUnknown() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList("unknown_metric"))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), empty());
}
 
Example #3
Source File: AggregatingJobsMetricsHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
Collection<? extends MetricStore.ComponentMetricStore> getStores(MetricStore store, HandlerRequest<EmptyRequestBody, AggregatedJobMetricsParameters> request) {
	List<JobID> jobs = request.getQueryParameter(JobsFilterQueryParameter.class);
	if (jobs.isEmpty()) {
		return store.getJobs().values();
	} else {
		Collection<MetricStore.ComponentMetricStore> jobStores = new ArrayList<>(jobs.size());
		for (JobID job : jobs) {
			MetricStore.ComponentMetricStore jobMetricStore = store.getJobMetricStore(job.toString());
			if (jobMetricStore != null) {
				jobStores.add(jobMetricStore);
			}
		}
		return jobStores;
	}
}
 
Example #4
Source File: JobExecutionResultHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull final HandlerRequest<EmptyRequestBody, JobMessageParameters> 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);
		});
}
 
Example #5
Source File: JarRunHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private SavepointRestoreSettings getSavepointRestoreSettings(
		final @Nonnull HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request)
			throws RestHandlerException {

	final JarRunRequestBody requestBody = request.getRequestBody();

	final boolean allowNonRestoredState = fromRequestBodyOrQueryParameter(
		requestBody.getAllowNonRestoredState(),
		() -> getQueryParameter(request, AllowNonRestoredStateQueryParameter.class),
		false,
		log);
	final String savepointPath = fromRequestBodyOrQueryParameter(
		emptyToNull(requestBody.getSavepointPath()),
		() -> emptyToNull(getQueryParameter(request, SavepointPathQueryParameter.class)),
		null,
		log);
	final SavepointRestoreSettings savepointRestoreSettings;
	if (savepointPath != null) {
		savepointRestoreSettings = SavepointRestoreSettings.forPath(
			savepointPath,
			allowNonRestoredState);
	} else {
		savepointRestoreSettings = SavepointRestoreSettings.none();
	}
	return savepointRestoreSettings;
}
 
Example #6
Source File: SavepointHandlers.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<String> triggerOperation(HandlerRequest<SavepointTriggerRequestBody, SavepointTriggerMessageParameters> request, RestfulGateway gateway) throws RestHandlerException {
	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
	final String requestedTargetDirectory = request.getRequestBody().getTargetDirectory();

	if (requestedTargetDirectory == null && defaultSavepointDir == null) {
		throw new RestHandlerException(
				String.format("Config key [%s] is not set. Property [%s] must be provided.",
					CheckpointingOptions.SAVEPOINT_DIRECTORY.key(),
					SavepointTriggerRequestBody.FIELD_NAME_TARGET_DIRECTORY),
				HttpResponseStatus.BAD_REQUEST);
	}

	final boolean cancelJob = request.getRequestBody().isCancelJob();
	final String targetDirectory = requestedTargetDirectory != null ? requestedTargetDirectory : defaultSavepointDir;
	return gateway.triggerSavepoint(jobId, targetDirectory, cancelJob, RpcUtils.INF_TIMEOUT);
}
 
Example #7
Source File: AbstractMetricsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnEmptyListIfRequestedMetricIsUnknown() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.singletonMap(METRICS_FILTER_QUERY_PARAM, Collections.singletonList("unknown_metric"))),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), empty());
}
 
Example #8
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, SavepointDisposalStatusMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final TriggerId actualTriggerId = request.getPathParameter(TriggerIdPathParameter.class);

	if (actualTriggerId.equals(triggerId)) {
		final OptionalFailure<AsynchronousOperationInfo> nextResponse = responses.poll();

		if (nextResponse != null) {
			if (nextResponse.isFailure()) {
				throw new RestHandlerException("Failure", HttpResponseStatus.BAD_REQUEST, nextResponse.getFailureCause());
			} else {
				return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(nextResponse.getUnchecked()));
			}
		} else {
			throw new AssertionError();
		}
	} else {
		throw new AssertionError();
	}
}
 
Example #9
Source File: JobSubmitHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializationFailureHandling() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	DispatcherGateway mockGateway = new TestingDispatcherGateway.Builder()
		.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(new HandlerRequest<>(request, EmptyMessageParameters.getInstance()), mockGateway);
		Assert.fail();
	} catch (RestHandlerException rhe) {
		Assert.assertEquals(HttpResponseStatus.BAD_REQUEST, rhe.getHttpResponseStatus());
	}
}
 
Example #10
Source File: TaskManagerLogListHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<LogListInfo> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, TaskManagerMessageParameters> request,
		@Nonnull ResourceManagerGateway gateway) throws RestHandlerException {
	final ResourceID taskManagerId = request.getPathParameter(TaskManagerIdPathParameter.class);
	final ResourceManagerGateway resourceManagerGateway = getResourceManagerGateway(resourceManagerGatewayRetriever);
	final CompletableFuture<Collection<LogInfo>> logsWithLengthFuture = resourceManagerGateway.requestTaskManagerLogList(taskManagerId, timeout);

	return logsWithLengthFuture.thenApply(LogListInfo::new).exceptionally(
		(throwable) -> {
			final Throwable strippedThrowable = ExceptionUtils.stripCompletionException(throwable);
			if (strippedThrowable instanceof UnknownTaskExecutorException) {
				throw new CompletionException(
					new RestHandlerException(
						"Could not find TaskExecutor " + taskManagerId,
						HttpResponseStatus.NOT_FOUND,
						strippedThrowable
					));
			} else {
				throw new CompletionException(throwable);
			}
		});
}
 
Example #11
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	if (jobExecutionResults.hasNext()) {
		lastJobExecutionResult = jobExecutionResults.next();
	}
	checkState(lastJobExecutionResult != null);
	if (lastJobExecutionResult instanceof JobExecutionResultResponseBody) {
		return CompletableFuture.completedFuture((JobExecutionResultResponseBody) lastJobExecutionResult);
	} else if (lastJobExecutionResult instanceof RestHandlerException) {
		return FutureUtils.completedExceptionally((RestHandlerException) lastJobExecutionResult);
	} else {
		throw new AssertionError();
	}
}
 
Example #12
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testListMetrics() throws Exception {
	final CompletableFuture<MetricCollectionResponseBody> completableFuture =
		testMetricsHandler.handleRequest(
			new HandlerRequest<>(
				EmptyRequestBody.getInstance(),
				new TestMessageParameters(),
				Collections.emptyMap(),
				Collections.emptyMap()),
			mockDispatcherGateway);

	assertTrue(completableFuture.isDone());

	final MetricCollectionResponseBody metricCollectionResponseBody = completableFuture.get();
	assertThat(metricCollectionResponseBody.getMetrics(), hasSize(1));

	final Metric metric = metricCollectionResponseBody.getMetrics().iterator().next();
	assertThat(metric.getId(), equalTo(TEST_METRIC_NAME));
	assertThat(metric.getValue(), equalTo(null));
}
 
Example #13
Source File: JobExecutionResultHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull final HandlerRequest<EmptyRequestBody, JobMessageParameters> 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);
		});
}
 
Example #14
Source File: AbstractAsynchronousOperationHandlers.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<AsynchronousOperationResult<V>> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, M> request, @Nonnull T gateway) throws RestHandlerException {

	final K key = getOperationKey(request);

	final Either<Throwable, R> operationResultOrError;
	try {
		operationResultOrError = completedOperationCache.get(key);
	} catch (UnknownOperationKeyException e) {
		return FutureUtils.completedExceptionally(
			new NotFoundException("Operation not found under key: " + key, e));
	}

	if (operationResultOrError != null) {
		if (operationResultOrError.isLeft()) {
			return CompletableFuture.completedFuture(
				AsynchronousOperationResult.completed(exceptionalOperationResultResponse(operationResultOrError.left())));
		} else {
			return CompletableFuture.completedFuture(
				AsynchronousOperationResult.completed(operationResultResponse(operationResultOrError.right())));
		}
	} else {
		return CompletableFuture.completedFuture(AsynchronousOperationResult.inProgress());
	}
}
 
Example #15
Source File: AggregatingSubtasksMetricsHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
Collection<? extends MetricStore.ComponentMetricStore> getStores(MetricStore store, HandlerRequest<EmptyRequestBody, AggregatedSubtaskMetricsParameters> request) {
	JobID jobID = request.getPathParameter(JobIDPathParameter.class);
	JobVertexID taskID = request.getPathParameter(JobVertexIdPathParameter.class);

	Collection<String> subtaskRanges = request.getQueryParameter(SubtasksFilterQueryParameter.class);
	if (subtaskRanges.isEmpty()) {
		MetricStore.TaskMetricStore taskMetricStore = store.getTaskMetricStore(jobID.toString(), taskID.toString());
		if (taskMetricStore != null) {
			return taskMetricStore.getAllSubtaskMetricStores();
		} else {
			return Collections.emptyList();
		}
	} else {
		Iterable<Integer> subtasks = getIntegerRangeFromString(subtaskRanges);
		Collection<MetricStore.ComponentMetricStore> subtaskStores = new ArrayList<>(8);
		for (int subtask : subtasks) {
			MetricStore.ComponentMetricStore subtaskMetricStore = store.getSubtaskMetricStore(jobID.toString(), taskID.toString(), subtask);
			if (subtaskMetricStore != null) {
				subtaskStores.add(subtaskMetricStore);
			}
		}
		return subtaskStores;
	}
}
 
Example #16
Source File: SavepointHandlers.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<String> triggerOperation(HandlerRequest<SavepointTriggerRequestBody, SavepointTriggerMessageParameters> request, RestfulGateway gateway) throws RestHandlerException {
	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
	final String requestedTargetDirectory = request.getRequestBody().getTargetDirectory();

	if (requestedTargetDirectory == null && defaultSavepointDir == null) {
		throw new RestHandlerException(
				String.format("Config key [%s] is not set. Property [%s] must be provided.",
					CheckpointingOptions.SAVEPOINT_DIRECTORY.key(),
					SavepointTriggerRequestBody.FIELD_NAME_TARGET_DIRECTORY),
				HttpResponseStatus.BAD_REQUEST);
	}

	final boolean cancelJob = request.getRequestBody().isCancelJob();
	final String targetDirectory = requestedTargetDirectory != null ? requestedTargetDirectory : defaultSavepointDir;
	return gateway.triggerSavepoint(jobId, targetDirectory, cancelJob, RpcUtils.INF_TIMEOUT);
}
 
Example #17
Source File: JobVertexDetailsHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected JobVertexDetailsInfo handleRequest(
		HandlerRequest<EmptyRequestBody, JobVertexMessageParameters> request,
		AccessExecutionGraph executionGraph) throws NotFoundException {
	JobID jobID = request.getPathParameter(JobIDPathParameter.class);
	JobVertexID jobVertexID = request.getPathParameter(JobVertexIdPathParameter.class);
	AccessExecutionJobVertex jobVertex = executionGraph.getJobVertex(jobVertexID);

	if (jobVertex == null) {
		throw new NotFoundException(String.format("JobVertex %s not found", jobVertexID));
	}

	return createJobVertexDetailsInfo(jobVertex, jobID, metricFetcher);
}
 
Example #18
Source File: RestClusterClientSavepointTriggerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<SavepointInfo>> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, SavepointStatusMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {

	final TriggerId triggerId = request.getPathParameter(TriggerIdPathParameter.class);
	return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(savepointHandlerLogic.apply(triggerId)));
}
 
Example #19
Source File: AbstractJobVertexHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected R handleRequest(
		HandlerRequest<EmptyRequestBody, M> request,
		AccessExecutionGraph executionGraph) throws RestHandlerException {

	final JobVertexID jobVertexID = request.getPathParameter(JobVertexIdPathParameter.class);
	final AccessExecutionJobVertex jobVertex = executionGraph.getJobVertex(jobVertexID);

	if (jobVertex == null) {
		throw new RestHandlerException("No vertex with ID '" + jobVertexID + "' exists.", HttpResponseStatus.NOT_FOUND);
	}

	return handleRequest(request, jobVertex);
}
 
Example #20
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final CompletableFuture<EmptyResponseBody> result = responseQueue.poll();

	if (result != null) {
		return result;
	} else {
		return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
	}
}
 
Example #21
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static HandlerRequest<EmptyRequestBody, TriggerMessageParameters> statusOperationRequest(TriggerId triggerId) throws HandlerRequestException {
	return new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new TriggerMessageParameters(),
		Collections.singletonMap(TriggerIdPathParameter.KEY, triggerId.toString()),
		Collections.emptyMap());
}
 
Example #22
Source File: JobMetricsHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected MetricStore.ComponentMetricStore getComponentMetricStore(
	final HandlerRequest<EmptyRequestBody, JobMetricsMessageParameters> request,
	final MetricStore metricStore) {
	return metricStore.getJobMetricStore(request.getPathParameter(JobIDPathParameter.class).toString());
}
 
Example #23
Source File: SubtaskMetricsHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected MetricStore.ComponentMetricStore getComponentMetricStore(
		HandlerRequest<EmptyRequestBody, SubtaskMetricsMessageParameters> request,
		MetricStore metricStore) {

	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
	final JobVertexID vertexId = request.getPathParameter(JobVertexIdPathParameter.class);
	final int subtaskIndex = request.getPathParameter(SubtaskIndexPathParameter.class);

	return metricStore.getSubtaskMetricStore(jobId.toString(), vertexId.toString(), subtaskIndex);
}
 
Example #24
Source File: JobSubmitHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final Collection<File> uploadedFiles = request.getUploadedFiles();
	final Map<String, Path> nameToFile = uploadedFiles.stream().collect(Collectors.toMap(
		File::getName,
		Path::fromLocalFile
	));

	if (uploadedFiles.size() != nameToFile.size()) {
		throw new RestHandlerException(
			String.format("The number of uploaded files was %s than the expected count. Expected: %s Actual %s",
				uploadedFiles.size() < nameToFile.size() ? "lower" : "higher",
				nameToFile.size(),
				uploadedFiles.size()),
			HttpResponseStatus.BAD_REQUEST
		);
	}

	final JobSubmitRequestBody requestBody = request.getRequestBody();

	if (requestBody.jobGraphFileName == null) {
		throw new RestHandlerException(
			String.format("The %s field must not be omitted or be null.",
				JobSubmitRequestBody.FIELD_NAME_JOB_GRAPH),
			HttpResponseStatus.BAD_REQUEST);
	}

	CompletableFuture<JobGraph> jobGraphFuture = loadJobGraph(requestBody, nameToFile);

	Collection<Path> jarFiles = getJarFilesToUpload(requestBody.jarFileNames, nameToFile);

	Collection<Tuple2<String, Path>> artifacts = getArtifactFilesToUpload(requestBody.artifactFileNames, nameToFile);

	CompletableFuture<JobGraph> finalizedJobGraphFuture = uploadJobGraphFiles(gateway, jobGraphFuture, jarFiles, artifacts, configuration);

	CompletableFuture<Acknowledge> jobSubmissionFuture = finalizedJobGraphFuture.thenCompose(jobGraph -> gateway.submitJob(jobGraph, timeout));

	return jobSubmissionFuture.thenCombine(jobGraphFuture,
		(ack, jobGraph) -> new JobSubmitResponseBody("/jobs/" + jobGraph.getJobID()));
}
 
Example #25
Source File: RescalingHandlers.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected AsynchronousJobOperationKey getOperationKey(HandlerRequest<EmptyRequestBody, RescalingStatusMessageParameters> request) {
	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
	final TriggerId triggerId = request.getPathParameter(TriggerIdPathParameter.class);

	return AsynchronousJobOperationKey.of(triggerId, jobId);
}
 
Example #26
Source File: JobVertexBackPressureHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JobVertexBackPressureInfo> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, JobVertexMessageParameters> request,
		@Nonnull RestfulGateway gateway) throws RestHandlerException {
	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
	final JobVertexID jobVertexId = request.getPathParameter(JobVertexIdPathParameter.class);
	return gateway
		.requestOperatorBackPressureStats(jobId, jobVertexId)
		.thenApply(
			operatorBackPressureStats ->
				operatorBackPressureStats.getOperatorBackPressureStats().map(
					JobVertexBackPressureHandler::createJobVertexBackPressureInfo).orElse(
					JobVertexBackPressureInfo.deprecated()));
}
 
Example #27
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<TestResponse> handleRequest(@Nonnull HandlerRequest<TestRequest, TestParameters> request, RestfulGateway gateway) {
	assertEquals(request.getPathParameter(JobIDPathParameter.class), PATH_JOB_ID);
	assertEquals(request.getQueryParameter(JobIDQueryParameter.class).get(0), QUERY_JOB_ID);

	final int id = request.getRequestBody().id;
	return handlerBody.apply(id);
}
 
Example #28
Source File: TaskCheckpointStatisticDetailsHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected TaskCheckpointStatisticsWithSubtaskDetails handleCheckpointRequest(
		HandlerRequest<EmptyRequestBody, TaskCheckpointMessageParameters> request,
		AbstractCheckpointStats checkpointStats) throws RestHandlerException {

	final JobVertexID jobVertexId = request.getPathParameter(JobVertexIdPathParameter.class);

	final TaskStateStats taskStatistics = checkpointStats.getTaskStateStats(jobVertexId);

	if (taskStatistics == null) {
		throw new NotFoundException("There is no checkpoint statistics for task " + jobVertexId + '.');
	}

	return createCheckpointDetails(checkpointStats, taskStatistics);
}
 
Example #29
Source File: JobVertexBackPressureHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JobVertexBackPressureInfo> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, JobVertexMessageParameters> request,
		@Nonnull RestfulGateway gateway) throws RestHandlerException {
	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
	final JobVertexID jobVertexId = request.getPathParameter(JobVertexIdPathParameter.class);
	return gateway
		.requestOperatorBackPressureStats(jobId, jobVertexId)
		.thenApply(
			operatorBackPressureStats ->
				operatorBackPressureStats.getOperatorBackPressureStats().map(
					JobVertexBackPressureHandler::createJobVertexBackPressureInfo).orElse(
					JobVertexBackPressureInfo.deprecated()));
}
 
Example #30
Source File: JarHandlerUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static <R extends JarRequestBody> JarHandlerContext fromRequest(
		@Nonnull final HandlerRequest<R, ?> request,
		@Nonnull final Path jarDir,
		@Nonnull final Logger log) throws RestHandlerException {
	final JarRequestBody requestBody = request.getRequestBody();

	final String pathParameter = request.getPathParameter(JarIdPathParameter.class);
	Path jarFile = jarDir.resolve(pathParameter);

	String entryClass = fromRequestBodyOrQueryParameter(
		emptyToNull(requestBody.getEntryClassName()),
		() -> emptyToNull(getQueryParameter(request, EntryClassQueryParameter.class)),
		null,
		log);

	List<String> programArgs = JarHandlerUtils.getProgramArgs(request, log);

	int parallelism = fromRequestBodyOrQueryParameter(
		requestBody.getParallelism(),
		() -> getQueryParameter(request, ParallelismQueryParameter.class),
		ExecutionConfig.PARALLELISM_DEFAULT,
		log);

	JobID jobId = fromRequestBodyOrQueryParameter(
		requestBody.getJobId(),
		() -> null, // No support via query parameter
		null, // Delegate default job ID to actual JobGraph generation
		log);

	return new JarHandlerContext(jarFile, entryClass, programArgs, parallelism, jobId);
}