Java Code Examples for org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus#BAD_REQUEST
The following examples show how to use
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus#BAD_REQUEST .
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: RestClusterClientTest.java From flink with Apache License 2.0 | 6 votes |
@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 2
Source File: SavepointHandlers.java From flink with Apache License 2.0 | 6 votes |
@Override protected CompletableFuture<String> triggerOperation( final HandlerRequest<StopWithSavepointRequestBody, SavepointTriggerMessageParameters> request, final 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(), StopWithSavepointRequestBody.FIELD_NAME_TARGET_DIRECTORY), HttpResponseStatus.BAD_REQUEST); } final boolean advanceToEndOfEventTime = request.getRequestBody().shouldDrain(); final String targetDirectory = requestedTargetDirectory != null ? requestedTargetDirectory : defaultSavepointDir; return gateway.stopWithSavepoint(jobId, targetDirectory, advanceToEndOfEventTime, RpcUtils.INF_TIMEOUT); }
Example 3
Source File: SavepointHandlers.java From flink with Apache License 2.0 | 6 votes |
@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 4
Source File: JarHandlerUtils.java From flink with Apache License 2.0 | 6 votes |
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 5
Source File: JarHandlerUtils.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
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 6
Source File: SavepointHandlers.java From flink with Apache License 2.0 | 6 votes |
@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: RestClusterClientTest.java From flink with Apache License 2.0 | 6 votes |
@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 8
Source File: RescalingHandlers.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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 9
Source File: SavepointHandlers.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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 10
Source File: JarHandlerUtils.java From flink with Apache License 2.0 | 6 votes |
public PackagedProgram toPackagedProgram(Configuration configuration) { checkNotNull(configuration); if (!Files.exists(jarFile)) { throw new CompletionException(new RestHandlerException( String.format("Jar file %s does not exist", jarFile), HttpResponseStatus.BAD_REQUEST)); } try { return PackagedProgram.newBuilder() .setJarFile(jarFile.toFile()) .setEntryPointClassName(entryClass) .setConfiguration(configuration) .setArguments(programArgs.toArray(new String[0])) .build(); } catch (final ProgramInvocationException e) { throw new CompletionException(e); } }
Example 11
Source File: SavepointDisposalHandlers.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override protected CompletableFuture<Acknowledge> triggerOperation(HandlerRequest<SavepointDisposalRequest, EmptyMessageParameters> request, RestfulGateway gateway) throws RestHandlerException { final String savepointPath = request.getRequestBody().getSavepointPath(); if (savepointPath == null) { throw new RestHandlerException( String.format("Field %s must not be omitted or be null.", SavepointDisposalRequest.FIELD_NAME_SAVEPOINT_PATH), HttpResponseStatus.BAD_REQUEST); } return gateway.disposeSavepoint(savepointPath, RpcUtils.INF_TIMEOUT); }
Example 12
Source File: RestServerEndpointITCase.java From flink with Apache License 2.0 | 5 votes |
@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()); }
Example 13
Source File: JobSubmitHandler.java From flink with Apache License 2.0 | 5 votes |
@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 14
Source File: JarUploadHandler.java From flink with Apache License 2.0 | 5 votes |
@Override protected CompletableFuture<JarUploadResponseBody> handleRequest( @Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException { Collection<File> uploadedFiles = request.getUploadedFiles(); if (uploadedFiles.size() != 1) { throw new RestHandlerException("Exactly 1 file must be sent, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST); } final Path fileUpload = uploadedFiles.iterator().next().toPath(); return CompletableFuture.supplyAsync(() -> { if (!fileUpload.getFileName().toString().endsWith(".jar")) { throw new CompletionException(new RestHandlerException( "Only Jar files are allowed.", HttpResponseStatus.BAD_REQUEST)); } else { final Path destination = jarDir.resolve(UUID.randomUUID() + "_" + fileUpload.getFileName()); try { Files.move(fileUpload, destination); } catch (IOException e) { throw new CompletionException(new RestHandlerException( String.format("Could not move uploaded jar file [%s] to [%s].", fileUpload, destination), HttpResponseStatus.INTERNAL_SERVER_ERROR, e)); } return new JarUploadResponseBody(destination .normalize() .toString()); } }, executor); }
Example 15
Source File: JobSubmitHandler.java From flink with Apache License 2.0 | 5 votes |
@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 16
Source File: JarUploadHandler.java From flink with Apache License 2.0 | 5 votes |
@Override protected CompletableFuture<JarUploadResponseBody> handleRequest( @Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException { Collection<File> uploadedFiles = request.getUploadedFiles(); if (uploadedFiles.size() != 1) { throw new RestHandlerException("Exactly 1 file must be sent, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST); } final Path fileUpload = uploadedFiles.iterator().next().toPath(); return CompletableFuture.supplyAsync(() -> { if (!fileUpload.getFileName().toString().endsWith(".jar")) { throw new CompletionException(new RestHandlerException( "Only Jar files are allowed.", HttpResponseStatus.BAD_REQUEST)); } else { final Path destination = jarDir.resolve(UUID.randomUUID() + "_" + fileUpload.getFileName()); try { Files.move(fileUpload, destination); } catch (IOException e) { throw new CompletionException(new RestHandlerException( String.format("Could not move uploaded jar file [%s] to [%s].", fileUpload, destination), HttpResponseStatus.INTERNAL_SERVER_ERROR, e)); } return new JarUploadResponseBody(destination .normalize() .toString()); } }, executor); }
Example 17
Source File: JarUploadHandler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override protected CompletableFuture<JarUploadResponseBody> handleRequest( @Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException { Collection<File> uploadedFiles = request.getUploadedFiles(); if (uploadedFiles.size() != 1) { throw new RestHandlerException("Exactly 1 file must be sent, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST); } final Path fileUpload = uploadedFiles.iterator().next().toPath(); return CompletableFuture.supplyAsync(() -> { if (!fileUpload.getFileName().toString().endsWith(".jar")) { throw new CompletionException(new RestHandlerException( "Only Jar files are allowed.", HttpResponseStatus.BAD_REQUEST)); } else { final Path destination = jarDir.resolve(UUID.randomUUID() + "_" + fileUpload.getFileName()); try { Files.move(fileUpload, destination); } catch (IOException e) { throw new CompletionException(new RestHandlerException( String.format("Could not move uploaded jar file [%s] to [%s].", fileUpload, destination), HttpResponseStatus.INTERNAL_SERVER_ERROR, e)); } return new JarUploadResponseBody(destination .normalize() .toString()); } }, executor); }
Example 18
Source File: SavepointDisposalHandlers.java From flink with Apache License 2.0 | 5 votes |
@Override protected CompletableFuture<Acknowledge> triggerOperation(HandlerRequest<SavepointDisposalRequest, EmptyMessageParameters> request, RestfulGateway gateway) throws RestHandlerException { final String savepointPath = request.getRequestBody().getSavepointPath(); if (savepointPath == null) { throw new RestHandlerException( String.format("Field %s must not be omitted or be null.", SavepointDisposalRequest.FIELD_NAME_SAVEPOINT_PATH), HttpResponseStatus.BAD_REQUEST); } return gateway.disposeSavepoint(savepointPath, RpcUtils.INF_TIMEOUT); }
Example 19
Source File: RestServerEndpointITCase.java From flink with Apache License 2.0 | 5 votes |
@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()); }
Example 20
Source File: JobSubmitHandler.java From flink with Apache License 2.0 | 4 votes |
MissingFileException(String type, String fileName) { super(type + " file " + fileName + " could not be found on the server.", HttpResponseStatus.BAD_REQUEST); }