@Test void whenJobSubmissionIsDisabledItThrowsCorrectError() { final String errorMessage = UUID.randomUUID().toString(); Mockito.when( this.environment.getProperty( JobConstants.JOB_SUBMISSION_ENABLED_PROPERTY_KEY, Boolean.class, true ) ).thenReturn(false); Mockito.when( this.environment.getProperty( JobConstants.JOB_SUBMISSION_DISABLED_MESSAGE_KEY, JobConstants.JOB_SUBMISSION_DISABLED_DEFAULT_MESSAGE ) ).thenReturn(errorMessage); Assertions .assertThatExceptionOfType(GenieServerUnavailableException.class) .isThrownBy(() -> this.controller.submitJob( Mockito.mock(JobRequest.class), null, null, Mockito.mock(HttpServletRequest.class) )) .withMessage(errorMessage); }
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public ResponseEntity<Void> submitJob( @Valid @RequestBody final JobRequest jobRequest, @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost, @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent, final HttpServletRequest httpServletRequest ) throws GenieException, GenieCheckedException { log.info("[submitJob] Called json method type to submit job: {}", jobRequest); this.submitJobWithoutAttachmentsRate.increment(); return this.handleSubmitJob(jobRequest, null, clientHost, userAgent, httpServletRequest); }
JobRestController { @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public ResponseEntity<Void> submitJob( @Valid @RequestBody final JobRequest jobRequest, @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost, @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent, final HttpServletRequest httpServletRequest ) throws GenieException, GenieCheckedException { log.info("[submitJob] Called json method type to submit job: {}", jobRequest); this.submitJobWithoutAttachmentsRate.increment(); return this.handleSubmitJob(jobRequest, null, clientHost, userAgent, httpServletRequest); } }
JobRestController { @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public ResponseEntity<Void> submitJob( @Valid @RequestBody final JobRequest jobRequest, @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost, @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent, final HttpServletRequest httpServletRequest ) throws GenieException, GenieCheckedException { log.info("[submitJob] Called json method type to submit job: {}", jobRequest); this.submitJobWithoutAttachmentsRate.increment(); return this.handleSubmitJob(jobRequest, null, clientHost, userAgent, httpServletRequest); } @Autowired @SuppressWarnings("checkstyle:parameternumber")  JobRestController(
        final JobLaunchService jobLaunchService,
        final DataServices dataServices,
        final EntityModelAssemblers entityModelAssemblers,
        final GenieHostInfo genieHostInfo,
        @Qualifier("genieRestTemplate") final RestTemplate restTemplate,
        final JobDirectoryServerService jobDirectoryServerService,
        final JobsProperties jobsProperties,
        final MeterRegistry registry,
        final AgentRoutingService agentRoutingService,
        final Environment environment,
        final AttachmentService attachmentService,
        final JobKillService jobKillService
    ); }
JobRestController { @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public ResponseEntity<Void> submitJob( @Valid @RequestBody final JobRequest jobRequest, @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost, @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent, final HttpServletRequest httpServletRequest ) throws GenieException, GenieCheckedException { log.info("[submitJob] Called json method type to submit job: {}", jobRequest); this.submitJobWithoutAttachmentsRate.increment(); return this.handleSubmitJob(jobRequest, null, clientHost, userAgent, httpServletRequest); } @Autowired @SuppressWarnings("checkstyle:parameternumber")  JobRestController(
        final JobLaunchService jobLaunchService,
        final DataServices dataServices,
        final EntityModelAssemblers entityModelAssemblers,
        final GenieHostInfo genieHostInfo,
        @Qualifier("genieRestTemplate") final RestTemplate restTemplate,
        final JobDirectoryServerService jobDirectoryServerService,
        final JobsProperties jobsProperties,
        final MeterRegistry registry,
        final AgentRoutingService agentRoutingService,
        final Environment environment,
        final AttachmentService attachmentService,
        final JobKillService jobKillService
    ); @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) ResponseEntity<Void> submitJob(
        @Valid @RequestBody final JobRequest jobRequest,
        @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost,
        @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent,
        final HttpServletRequest httpServletRequest
    ); @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) ResponseEntity<Void> submitJob(
        @Valid @RequestPart("request") final JobRequest jobRequest,
        @RequestPart("attachment") final MultipartFile[] attachments,
        @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost,
        @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent,
        final HttpServletRequest httpServletRequest
    ); @GetMapping(value = "/{id}", produces = MediaTypes.HAL_JSON_VALUE) EntityModel<Job> getJob(@PathVariable("id") final String id); @GetMapping(value = "/{id}/status", produces = MediaType.APPLICATION_JSON_VALUE) JsonNode getJobStatus(@PathVariable("id") final String id); @GetMapping(produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) @SuppressWarnings("checkstyle:parameternumber") PagedModel<EntityModel<JobSearchResult>> findJobs(
        @RequestParam(value = "id", required = false) @Nullable final String id,
        @RequestParam(value = "name", required = false) @Nullable final String name,
        @RequestParam(value = "user", required = false) @Nullable final String user,
        @RequestParam(value = "status", required = false) @Nullable final Set<String> statuses,
        @RequestParam(value = "tag", required = false) @Nullable final Set<String> tags,
        @RequestParam(value = "clusterName", required = false) @Nullable final String clusterName,
        @RequestParam(value = "clusterId", required = false) @Nullable final String clusterId,
        @RequestParam(value = "commandName", required = false) @Nullable final String commandName,
        @RequestParam(value = "commandId", required = false) @Nullable final String commandId,
        @RequestParam(value = "minStarted", required = false) @Nullable final Long minStarted,
        @RequestParam(value = "maxStarted", required = false) @Nullable final Long maxStarted,
        @RequestParam(value = "minFinished", required = false) @Nullable final Long minFinished,
        @RequestParam(value = "maxFinished", required = false) @Nullable final Long maxFinished,
        @RequestParam(value = "grouping", required = false) @Nullable final String grouping,
        @RequestParam(value = "groupingInstance", required = false) @Nullable final String groupingInstance,
        @PageableDefault(sort = {"created"}, direction = Sort.Direction.DESC) final Pageable page,
        final PagedResourcesAssembler<JobSearchResult> assembler
    ); @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.ACCEPTED) void killJob(
        @PathVariable("id") final String id,
        @RequestHeader(name = JobConstants.GENIE_FORWARDED_FROM_HEADER, required = false)
        @Nullable final String forwardedFrom,
        final HttpServletRequest request,
        final HttpServletResponse response
    ); @GetMapping(value = "/{id}/request", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<JobRequest> getJobRequest(
        @PathVariable("id") final String id); @GetMapping(value = "/{id}/execution", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<JobExecution> getJobExecution(
        @PathVariable("id") final String id
    ); @GetMapping(value = "/{id}/metadata", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<JobMetadata> getJobMetadata(@PathVariable("id") final String id); @GetMapping(value = "/{id}/cluster", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<Cluster> getJobCluster(@PathVariable("id") final String id); @GetMapping(value = "/{id}/command", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<Command> getJobCommand(@PathVariable("id") final String id); @GetMapping(value = "/{id}/applications", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) List<EntityModel<Application>> getJobApplications(
        @PathVariable("id") final String id
    ); @GetMapping( value = { "/{id}/output", "/{id}/output/", "/{id}/output/**" } ) void getJobOutput(
        @PathVariable("id") final String id,
        @RequestHeader(name = JobConstants.GENIE_FORWARDED_FROM_HEADER, required = false)
        @Nullable final String forwardedFrom,
        final HttpServletRequest request,
        final HttpServletResponse response
    ); }
JobRestController { @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public ResponseEntity<Void> submitJob( @Valid @RequestBody final JobRequest jobRequest, @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost, @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent, final HttpServletRequest httpServletRequest ) throws GenieException, GenieCheckedException { log.info("[submitJob] Called json method type to submit job: {}", jobRequest); this.submitJobWithoutAttachmentsRate.increment(); return this.handleSubmitJob(jobRequest, null, clientHost, userAgent, httpServletRequest); } @Autowired @SuppressWarnings("checkstyle:parameternumber")  JobRestController(
        final JobLaunchService jobLaunchService,
        final DataServices dataServices,
        final EntityModelAssemblers entityModelAssemblers,
        final GenieHostInfo genieHostInfo,
        @Qualifier("genieRestTemplate") final RestTemplate restTemplate,
        final JobDirectoryServerService jobDirectoryServerService,
        final JobsProperties jobsProperties,
        final MeterRegistry registry,
        final AgentRoutingService agentRoutingService,
        final Environment environment,
        final AttachmentService attachmentService,
        final JobKillService jobKillService
    ); @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) ResponseEntity<Void> submitJob(
        @Valid @RequestBody final JobRequest jobRequest,
        @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost,
        @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent,
        final HttpServletRequest httpServletRequest
    ); @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) ResponseEntity<Void> submitJob(
        @Valid @RequestPart("request") final JobRequest jobRequest,
        @RequestPart("attachment") final MultipartFile[] attachments,
        @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) @Nullable final String clientHost,
        @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) @Nullable final String userAgent,
        final HttpServletRequest httpServletRequest
    ); @GetMapping(value = "/{id}", produces = MediaTypes.HAL_JSON_VALUE) EntityModel<Job> getJob(@PathVariable("id") final String id); @GetMapping(value = "/{id}/status", produces = MediaType.APPLICATION_JSON_VALUE) JsonNode getJobStatus(@PathVariable("id") final String id); @GetMapping(produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) @SuppressWarnings("checkstyle:parameternumber") PagedModel<EntityModel<JobSearchResult>> findJobs(
        @RequestParam(value = "id", required = false) @Nullable final String id,
        @RequestParam(value = "name", required = false) @Nullable final String name,
        @RequestParam(value = "user", required = false) @Nullable final String user,
        @RequestParam(value = "status", required = false) @Nullable final Set<String> statuses,
        @RequestParam(value = "tag", required = false) @Nullable final Set<String> tags,
        @RequestParam(value = "clusterName", required = false) @Nullable final String clusterName,
        @RequestParam(value = "clusterId", required = false) @Nullable final String clusterId,
        @RequestParam(value = "commandName", required = false) @Nullable final String commandName,
        @RequestParam(value = "commandId", required = false) @Nullable final String commandId,
        @RequestParam(value = "minStarted", required = false) @Nullable final Long minStarted,
        @RequestParam(value = "maxStarted", required = false) @Nullable final Long maxStarted,
        @RequestParam(value = "minFinished", required = false) @Nullable final Long minFinished,
        @RequestParam(value = "maxFinished", required = false) @Nullable final Long maxFinished,
        @RequestParam(value = "grouping", required = false) @Nullable final String grouping,
        @RequestParam(value = "groupingInstance", required = false) @Nullable final String groupingInstance,
        @PageableDefault(sort = {"created"}, direction = Sort.Direction.DESC) final Pageable page,
        final PagedResourcesAssembler<JobSearchResult> assembler
    ); @DeleteMapping(value = "/{id}") @ResponseStatus(HttpStatus.ACCEPTED) void killJob(
        @PathVariable("id") final String id,
        @RequestHeader(name = JobConstants.GENIE_FORWARDED_FROM_HEADER, required = false)
        @Nullable final String forwardedFrom,
        final HttpServletRequest request,
        final HttpServletResponse response
    ); @GetMapping(value = "/{id}/request", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<JobRequest> getJobRequest(
        @PathVariable("id") final String id); @GetMapping(value = "/{id}/execution", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<JobExecution> getJobExecution(
        @PathVariable("id") final String id
    ); @GetMapping(value = "/{id}/metadata", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<JobMetadata> getJobMetadata(@PathVariable("id") final String id); @GetMapping(value = "/{id}/cluster", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<Cluster> getJobCluster(@PathVariable("id") final String id); @GetMapping(value = "/{id}/command", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) EntityModel<Command> getJobCommand(@PathVariable("id") final String id); @GetMapping(value = "/{id}/applications", produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) List<EntityModel<Application>> getJobApplications(
        @PathVariable("id") final String id
    ); @GetMapping( value = { "/{id}/output", "/{id}/output/", "/{id}/output/**" } ) void getJobOutput(
        @PathVariable("id") final String id,
        @RequestHeader(name = JobConstants.GENIE_FORWARDED_FROM_HEADER, required = false)
        @Nullable final String forwardedFrom,
        final HttpServletRequest request,
        final HttpServletResponse response
    );  }