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

The following examples show how to use org.apache.flink.runtime.rest.handler.RestHandlerException. 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: JobSubmitHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<JobGraph> uploadJobGraphFiles(
		DispatcherGateway gateway,
		CompletableFuture<JobGraph> jobGraphFuture,
		Collection<Path> jarFiles,
		Collection<Tuple2<String, Path>> artifacts,
		Configuration configuration) {
	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	return jobGraphFuture.thenCombine(blobServerPortFuture, (JobGraph jobGraph, Integer blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.uploadJobGraphFiles(jobGraph, jarFiles, artifacts, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(new RestHandlerException(
				"Could not upload job files.",
				HttpResponseStatus.INTERNAL_SERVER_ERROR,
				e));
		}
		return jobGraph;
	});
}
 
Example #2
Source File: CheckpointConfigHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
private static CheckpointConfigInfo createCheckpointConfigInfo(AccessExecutionGraph executionGraph) throws RestHandlerException {
	final CheckpointCoordinatorConfiguration checkpointCoordinatorConfiguration = executionGraph.getCheckpointCoordinatorConfiguration();

	if (checkpointCoordinatorConfiguration == null) {
		throw new RestHandlerException(
			"Checkpointing is not enabled for this job (" + executionGraph.getJobID() + ").",
			HttpResponseStatus.NOT_FOUND);
	} else {
		CheckpointRetentionPolicy retentionPolicy = checkpointCoordinatorConfiguration.getCheckpointRetentionPolicy();

		CheckpointConfigInfo.ExternalizedCheckpointInfo externalizedCheckpointInfo = new CheckpointConfigInfo.ExternalizedCheckpointInfo(
				retentionPolicy != CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION,
				retentionPolicy != CheckpointRetentionPolicy.RETAIN_ON_CANCELLATION);

		return new CheckpointConfigInfo(
			checkpointCoordinatorConfiguration.isExactlyOnce() ? CheckpointConfigInfo.ProcessingMode.EXACTLY_ONCE : CheckpointConfigInfo.ProcessingMode.AT_LEAST_ONCE,
			checkpointCoordinatorConfiguration.getCheckpointInterval(),
			checkpointCoordinatorConfiguration.getCheckpointTimeout(),
			checkpointCoordinatorConfiguration.getMinPauseBetweenCheckpoints(),
			checkpointCoordinatorConfiguration.getMaxConcurrentCheckpoints(),
			externalizedCheckpointInfo);
	}
}
 
Example #3
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 #4
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 #5
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the send operation is being retried.
 */
@Test
public void testRetriableSendOperationIfConnectionErrorOrServiceUnavailable() throws Exception {
	final PingRestHandler pingRestHandler = new PingRestHandler(
		FutureUtils.completedExceptionally(new RestHandlerException("test exception", HttpResponseStatus.SERVICE_UNAVAILABLE)),
		CompletableFuture.completedFuture(EmptyResponseBody.getInstance()));

	try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(pingRestHandler)) {
		RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());

		try {
			final AtomicBoolean firstPollFailed = new AtomicBoolean();
			failHttpRequest = (messageHeaders, messageParameters, requestBody) ->
				messageHeaders instanceof PingRestHandlerHeaders && !firstPollFailed.getAndSet(true);

			restClusterClient.sendRequest(PingRestHandlerHeaders.INSTANCE).get();
		} finally {
			restClusterClient.shutdown();
		}
	}
}
 
Example #6
Source File: SubtaskCurrentAttemptDetailsHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected SubtaskExecutionAttemptDetailsInfo handleRequest(
		HandlerRequest<EmptyRequestBody, SubtaskMessageParameters> request,
		AccessExecutionVertex executionVertex) throws RestHandlerException {

	final AccessExecution execution = executionVertex.getCurrentExecutionAttempt();

	final MutableIOMetrics ioMetrics = new MutableIOMetrics();

	final JobID jobID = request.getPathParameter(JobIDPathParameter.class);
	final JobVertexID jobVertexID = request.getPathParameter(JobVertexIdPathParameter.class);

	ioMetrics.addIOMetrics(
		execution,
		metricFetcher,
		jobID.toString(),
		jobVertexID.toString()
	);

	return SubtaskExecutionAttemptDetailsInfo.create(execution, ioMetrics);
}
 
Example #7
Source File: JarHandlerUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
public JobGraph toJobGraph(Configuration configuration) {
	if (!Files.exists(jarFile)) {
		throw new CompletionException(new RestHandlerException(
			String.format("Jar file %s does not exist", jarFile), HttpResponseStatus.BAD_REQUEST));
	}

	try {
		final PackagedProgram packagedProgram = new PackagedProgram(
			jarFile.toFile(),
			entryClass,
			programArgs.toArray(new String[0]));
		return PackagedProgramUtils.createJobGraph(packagedProgram, configuration, parallelism, jobId);
	} catch (final ProgramInvocationException e) {
		throw new CompletionException(e);
	}
}
 
Example #8
Source File: SubtaskCurrentAttemptDetailsHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected SubtaskExecutionAttemptDetailsInfo handleRequest(
		HandlerRequest<EmptyRequestBody, SubtaskMessageParameters> request,
		AccessExecutionVertex executionVertex) throws RestHandlerException {

	final AccessExecution execution = executionVertex.getCurrentExecutionAttempt();

	final MutableIOMetrics ioMetrics = new MutableIOMetrics();

	final JobID jobID = request.getPathParameter(JobIDPathParameter.class);
	final JobVertexID jobVertexID = request.getPathParameter(JobVertexIdPathParameter.class);

	ioMetrics.addIOMetrics(
		execution,
		metricFetcher,
		jobID.toString(),
		jobVertexID.toString()
	);

	return SubtaskExecutionAttemptDetailsInfo.create(execution, ioMetrics);
}
 
Example #9
Source File: JobSubmitHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<JobGraph> uploadJobGraphFiles(
		DispatcherGateway gateway,
		CompletableFuture<JobGraph> jobGraphFuture,
		Collection<Path> jarFiles,
		Collection<Tuple2<String, Path>> artifacts,
		Configuration configuration) {
	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	return jobGraphFuture.thenCombine(blobServerPortFuture, (JobGraph jobGraph, Integer blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.uploadJobGraphFiles(jobGraph, jarFiles, artifacts, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(new RestHandlerException(
				"Could not upload job files.",
				HttpResponseStatus.INTERNAL_SERVER_ERROR,
				e));
		}
		return jobGraph;
	});
}
 
Example #10
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the send operation is being retried.
 */
@Test
public void testRetriableSendOperationIfConnectionErrorOrServiceUnavailable() throws Exception {
	final PingRestHandler pingRestHandler = new PingRestHandler(
		FutureUtils.completedExceptionally(new RestHandlerException("test exception", HttpResponseStatus.SERVICE_UNAVAILABLE)),
		CompletableFuture.completedFuture(EmptyResponseBody.getInstance()));

	try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(pingRestHandler)) {
		RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());

		try {
			final AtomicBoolean firstPollFailed = new AtomicBoolean();
			failHttpRequest = (messageHeaders, messageParameters, requestBody) ->
				messageHeaders instanceof PingRestHandlerHeaders && !firstPollFailed.getAndSet(true);

			restClusterClient.sendRequest(PingRestHandlerHeaders.INSTANCE).get();
		} finally {
			restClusterClient.shutdown();
		}
	}
}
 
Example #11
Source File: AbstractCheckpointHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected R handleRequest(HandlerRequest<EmptyRequestBody, M> request, AccessExecutionGraph executionGraph) throws RestHandlerException {
	final long checkpointId = request.getPathParameter(CheckpointIdPathParameter.class);

	final CheckpointStatsSnapshot checkpointStatsSnapshot = executionGraph.getCheckpointStatsSnapshot();

	if (checkpointStatsSnapshot != null) {
		AbstractCheckpointStats checkpointStats = checkpointStatsSnapshot.getHistory().getCheckpointById(checkpointId);

		if (checkpointStats != null) {
			checkpointStatsCache.tryAdd(checkpointStats);
		} else {
			checkpointStats = checkpointStatsCache.tryGet(checkpointId);
		}

		if (checkpointStats != null) {
			return handleCheckpointRequest(request, checkpointStats);
		} else {
			throw new RestHandlerException("Could not find checkpointing statistics for checkpoint " + checkpointId + '.', HttpResponseStatus.NOT_FOUND);
		}
	} else {
		throw new RestHandlerException("Checkpointing was not enabled for job " + executionGraph.getJobID() + '.', HttpResponseStatus.NOT_FOUND);
	}
}
 
Example #12
Source File: AbstractCheckpointHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected R handleRequest(HandlerRequest<EmptyRequestBody, M> request, AccessExecutionGraph executionGraph) throws RestHandlerException {
	final long checkpointId = request.getPathParameter(CheckpointIdPathParameter.class);

	final CheckpointStatsSnapshot checkpointStatsSnapshot = executionGraph.getCheckpointStatsSnapshot();

	if (checkpointStatsSnapshot != null) {
		AbstractCheckpointStats checkpointStats = checkpointStatsSnapshot.getHistory().getCheckpointById(checkpointId);

		if (checkpointStats != null) {
			checkpointStatsCache.tryAdd(checkpointStats);
		} else {
			checkpointStats = checkpointStatsCache.tryGet(checkpointId);
		}

		if (checkpointStats != null) {
			return handleCheckpointRequest(request, checkpointStats);
		} else {
			throw new RestHandlerException("Could not find checkpointing statistics for checkpoint " + checkpointId + '.', HttpResponseStatus.NOT_FOUND);
		}
	} else {
		throw new RestHandlerException("Checkpointing was not enabled for job " + executionGraph.getJobID() + '.', HttpResponseStatus.NOT_FOUND);
	}
}
 
Example #13
Source File: JobVertexAccumulatorsHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected JobVertexAccumulatorsInfo handleRequest(
		HandlerRequest<EmptyRequestBody, JobVertexMessageParameters> request,
		AccessExecutionJobVertex jobVertex) throws RestHandlerException {

	StringifiedAccumulatorResult[] accs = jobVertex.getAggregatedUserAccumulatorsStringified();
	ArrayList<UserAccumulator> userAccumulatorList = new ArrayList<>(accs.length);

	for (StringifiedAccumulatorResult acc : accs) {
		userAccumulatorList.add(
			new UserAccumulator(
				acc.getName(),
				acc.getType(),
				acc.getValue()));
	}

	return new JobVertexAccumulatorsInfo(jobVertex.getJobVertexId().toString(), userAccumulatorList);
}
 
Example #14
Source File: JarHandlerUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public JobGraph toJobGraph(Configuration configuration) {
	if (!Files.exists(jarFile)) {
		throw new CompletionException(new RestHandlerException(
			String.format("Jar file %s does not exist", jarFile), HttpResponseStatus.BAD_REQUEST));
	}

	try {
		final PackagedProgram packagedProgram = new PackagedProgram(
			jarFile.toFile(),
			entryClass,
			programArgs.toArray(new String[0]));
		return PackagedProgramUtils.createJobGraph(packagedProgram, configuration, parallelism, jobId);
	} catch (final ProgramInvocationException e) {
		throw new CompletionException(e);
	}
}
 
Example #15
Source File: MultipartUploadResource.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
static void verifyFileUpload(Collection<Path> expectedFiles, Collection<Path> uploadedFiles) throws RestHandlerException {
	try {
		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);
		}
	} catch (Exception e) {
		// return 505 to differentiate from common BAD_REQUEST responses in this test
		throw new RestHandlerException("Test verification failed.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
}
 
Example #16
Source File: AbstractAsynchronousOperationHandlersTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that an querying an unknown trigger id will return an exceptionally completed
 * future.
 */
@Test
public void testUnknownTriggerId() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().build();

	try {
		testingStatusHandler.handleRequest(
			statusOperationRequest(new TriggerId()),
			testingRestfulGateway).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));
	}
}
 
Example #17
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 #18
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 #19
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 #20
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 #21
Source File: RescalingHandlers.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<Acknowledge> triggerOperation(HandlerRequest<EmptyRequestBody, RescalingTriggerMessageParameters> request, RestfulGateway gateway) throws RestHandlerException {
	final JobID jobId = request.getPathParameter(JobIDPathParameter.class);
	final List<Integer> queryParameter = request.getQueryParameter(RescalingParallelismQueryParameter.class);

	if (queryParameter.isEmpty()) {
		throw new RestHandlerException("No new parallelism was specified.", HttpResponseStatus.BAD_REQUEST);
	}

	final int newParallelism = queryParameter.get(0);

	final CompletableFuture<Acknowledge> rescalingFuture = gateway.rescaleJob(
		jobId,
		newParallelism,
		RescalingBehaviour.STRICT,
		RpcUtils.INF_TIMEOUT);

	return rescalingFuture;
}
 
Example #22
Source File: SavepointHandlersTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTriggerSavepointNoDirectory() throws Exception {
	TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder()
		.setTriggerSavepointFunction((JobID jobId, String directory) -> CompletableFuture.completedFuture(COMPLETED_SAVEPOINT_EXTERNAL_POINTER))
		.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 [target-directory] must be provided."));
		assertThat(rhe.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
	}
}
 
Example #23
Source File: AbstractSubtaskAttemptHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected R handleRequest(HandlerRequest<EmptyRequestBody, M> request, AccessExecutionVertex executionVertex) throws RestHandlerException {
	final Integer attemptNumber = request.getPathParameter(SubtaskAttemptPathParameter.class);

	final AccessExecution currentAttempt = executionVertex.getCurrentExecutionAttempt();
	if (attemptNumber == currentAttempt.getAttemptNumber()) {
		return handleRequest(request, currentAttempt);
	} else if (attemptNumber >= 0 && attemptNumber < currentAttempt.getAttemptNumber()) {
		final AccessExecution execution = executionVertex.getPriorExecutionAttempt(attemptNumber);

		if (execution != null) {
			return handleRequest(request, execution);
		} else {
			throw new RestHandlerException("Attempt " + attemptNumber + " not found in subtask " +
				executionVertex.getTaskNameWithSubtaskIndex(), HttpResponseStatus.NOT_FOUND);
		}
	} else {
		throw new RestHandlerException("Invalid attempt num " + attemptNumber, HttpResponseStatus.NOT_FOUND);
	}
}
 
Example #24
Source File: JarUploadHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailedUpload() throws Exception {
	final Path uploadedFile = jarDir.resolve("Kafka010Example.jar");
	final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> 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));
	}
}
 
Example #25
Source File: AbstractJobVertexHandler.java    From flink 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 #26
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 #27
Source File: JarDeleteHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteUnknownJar() throws Exception {
	final HandlerRequest<EmptyRequestBody, JarDeleteMessageParameters> request = createRequest("doesnotexist.jar");
	try {
		jarDeleteHandler.handleRequest(request, restfulGateway).get();
	} 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("File doesnotexist.jar does not exist in"));
		assertThat(restHandlerException.getHttpResponseStatus(), equalTo(HttpResponseStatus.BAD_REQUEST));
	}
}
 
Example #28
Source File: JarHandlerParameterTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurationViaQueryParametersFailWithProgArgsAsStringAndList() throws Exception {
	try {
		testConfigurationViaQueryParameters(ProgramArgsParType.Both);
		fail("RestHandlerException is excepted");
	} catch (RestHandlerException e) {
		assertEquals(HttpResponseStatus.BAD_REQUEST, e.getHttpResponseStatus());
	}
}
 
Example #29
Source File: JobSubmitHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectionOnCountMismatch() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
		objectOut.writeObject(new JobGraph("testjob"));
	}
	final Path countExceedingFile = TEMPORARY_FOLDER.newFile().toPath();

	TestingDispatcherGateway.Builder builder = new TestingDispatcherGateway.Builder();
	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(new HandlerRequest<>(request, EmptyMessageParameters.getInstance(), Collections.emptyMap(), Collections.emptyMap(), Arrays.asList(jobGraphFile.toFile(), countExceedingFile.toFile())), mockGateway)
			.get();
	} catch (Exception e) {
		ExceptionUtils.findThrowable(e, candidate -> candidate instanceof RestHandlerException && candidate.getMessage().contains("count"));
	}
}
 
Example #30
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);
}