SchedulerResource extends AbstractJaxRSResource { @POST @Path ( "/pauseJob" ) @Produces ( "text/plain" ) @Consumes ( { APPLICATION_XML, APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully paused the job." ), @ResponseCode ( code = 500, condition = "Invalid jobId." ) } ) public Response pauseJob( JobRequest jobRequest ) { try { JobState state = schedulerService.pauseJob( jobRequest.getJobId() ); return buildPlainTextOkResponse( state.name() ); } catch ( SchedulerException e ) { throw new RuntimeException( e ); } } SchedulerResource(); @POST @Path ( "/job" ) @Consumes ( { APPLICATION_JSON, APPLICATION_XML } ) @Produces ( "text/plain" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Schedule created successfully." ), @ResponseCode ( code = 401, condition = "User is not allowed to create schedules." ), @ResponseCode ( code = 403, condition = "Cannot create schedules for the specified file." ), @ResponseCode ( code = 500, condition = "An error occurred while creating a schedule." ) } ) Response createJob( JobScheduleRequest scheduleRequest ); @POST @Path ( "/job/update" ) @Consumes ( { APPLICATION_JSON, APPLICATION_XML } ) @Produces ( "text/plain" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Schedule updated successfully." ), @ResponseCode ( code = 401, condition = "User is not allowed to update schedules." ), @ResponseCode ( code = 403, condition = "Cannot update schedules for the specified file." ), @ResponseCode ( code = 500, condition = "An error occurred while updating a schedule." ) } ) Response updateJob( JobScheduleRequest scheduleRequest ); @POST @Path ( "/triggerNow" ) @Produces ( "text/plain" ) @Consumes ( { APPLICATION_XML, APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Job triggered successfully." ), @ResponseCode ( code = 400, condition = "Invalid input." ), @ResponseCode ( code = 500, condition = "Invalid jobId." ) } ) Response triggerNow( JobRequest jobRequest ); @GET @Path ( "/getContentCleanerJob" ) @Produces ( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Content cleaner job successfully retrieved." ), @ResponseCode ( code = 204, condition = "No content cleaner job exists." ), } ) Job getContentCleanerJob(); @Deprecated @GET @Path ( "/jobs" ) @Produces ( { APPLICATION_JSON, APPLICATION_XML } ) @Facet ( name = "Unsupported" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Jobs retrieved successfully." ), @ResponseCode ( code = 500, condition = "Error while retrieving jobs." ) } ) List<Job> getJobs( @DefaultValue ( "false" ) @QueryParam ( "asCronString" ) Boolean asCronString ); @GET @Path ( "/getJobs" ) @Produces ( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Jobs retrieved successfully." ), @ResponseCode ( code = 500, condition = "Error while retrieving jobs." ), } ) List<Job> getAllJobs(); @GET @Path ( "/isScheduleAllowed" ) @Produces ( TEXT_PLAIN ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved scheduling ability of repository file." ), @ResponseCode ( code = 500, condition = "Invalid repository file id." ), } ) String isScheduleAllowed( @QueryParam ( "id" ) String id ); @GET @Path ( "/canSchedule" ) @Produces ( APPLICATION_JSON ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successful retrieved the scheduling permission." ), @ResponseCode ( code = 500, condition = "Unable to retrieve the scheduling permission." ) } ) String doGetCanSchedule(); @GET @Path ( "/state" ) @Produces ( "text/plain" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the state of the scheduler." ), @ResponseCode ( code = 500, condition = "An error occurred when getting the state of the scheduler." ) } ) Response getState(); @POST @Path ( "/start" ) @Produces ( "text/plain" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully started the server." ), @ResponseCode ( code = 500, condition = "An error occurred when resuming the scheduler." ) } ) Response start(); @POST @Path ( "/pause" ) @Produces ( "text/plain" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully paused the server." ), @ResponseCode ( code = 500, condition = "An error occurred when pausing the scheduler." ) } ) Response pause(); @POST @Path ( "/shutdown" ) @Produces ( "text/plain" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully shut down the server." ), @ResponseCode ( code = 500, condition = "An error occurred when shutting down the scheduler." ) } ) Response shutdown(); @POST @Path ( "/jobState" ) @Produces ( "text/plain" ) @Consumes ( { APPLICATION_XML, APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the state of the requested job." ), @ResponseCode ( code = 500, condition = "Invalid jobId." ) } ) Response getJobState( JobRequest jobRequest ); @POST @Path ( "/pauseJob" ) @Produces ( "text/plain" ) @Consumes ( { APPLICATION_XML, APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully paused the job." ), @ResponseCode ( code = 500, condition = "Invalid jobId." ) } ) Response pauseJob( JobRequest jobRequest ); @POST @Path ( "/resumeJob" ) @Produces ( "text/plain" ) @Consumes ( { APPLICATION_XML, APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully resumed the job." ), @ResponseCode ( code = 500, condition = "Invalid jobId." ) } ) Response resumeJob( JobRequest jobRequest ); @Deprecated @DELETE @Path ( "/removeJob" ) @Produces ( "text/plain" ) @Consumes ( { APPLICATION_XML, APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully removed the job." ), @ResponseCode ( code = 500, condition = "Invalid jobId." ) } ) Response removeJob( JobRequest jobRequest ); @PUT @Path ( "/removeJob" ) @Produces ( "text/plain" ) @Consumes ( { APPLICATION_XML, APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully removed the job." ), @ResponseCode ( code = 500, condition = "Invalid jobId." ) } ) Response deleteJob( JobRequest jobRequest ); @GET @Path ( "/jobinfo" ) @Produces ( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the information for the requested job." ), @ResponseCode ( code = 204, condition = "jobId is valid, but the job is either finished or does not exists." ), @ResponseCode ( code = 500, condition = "Internal error or invalid jobId." ) } ) Response getJob( @QueryParam( "jobId" ) String jobId,
                     @DefaultValue( "false" ) @QueryParam( "asCronString" ) String asCronString ); @Deprecated @GET @Path ( "/jobinfotest" ) @Produces ( { APPLICATION_JSON } ) @Facet ( name = "Unsupported" ) JobScheduleRequest getJobInfo(); @Deprecated @Facet ( name = "Unsupported" ) List<Job> getJobs(); @GET @Path ( "/blockout/blockoutjobs" ) @Produces ( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved blockout jobs." ), } ) List<Job> getBlockoutJobs(); @GET @Path ( "/blockout/hasblockouts" ) @Produces ( { TEXT_PLAIN } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully determined whether or not the system contains blockouts." ), } ) Response hasBlockouts(); @POST @Path ( "/blockout/add" ) @Consumes ( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successful operation." ), @ResponseCode ( code = 401, condition = "User is not authorized to create blockout." ) } ) Response addBlockout( JobScheduleRequest jobScheduleRequest ); @POST @Path ( "/blockout/update" ) @Consumes ( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successful operation." ), @ResponseCode ( code = 401, condition = "User is not authorized to update blockout." ) } ) Response updateBlockout( @QueryParam ( "jobid" ) String jobId, JobScheduleRequest jobScheduleRequest ); @POST @Path ( "/blockout/willFire" ) @Consumes ( { APPLICATION_JSON, APPLICATION_XML } ) @Produces ( { TEXT_PLAIN } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successful operation." ), @ResponseCode ( code = 500, condition = "An error occurred while determining blockouts being fired." ) } ) Response blockoutWillFire( JobScheduleRequest jobScheduleRequest ); @GET @Path ( "/blockout/shouldFireNow" ) @Produces ( { TEXT_PLAIN } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successful operation." ) } ) Response shouldFireNow(); @POST @Path ( "/blockout/blockstatus" ) @Consumes ( { APPLICATION_JSON, APPLICATION_XML } ) @Produces ( { APPLICATION_JSON, APPLICATION_XML } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully got the blockout status." ), @ResponseCode ( code = 401, condition = "User is not authorized to get the blockout status." ) } ) Response getBlockStatus( JobScheduleRequest jobScheduleRequest ); @GET @Path ( "/generatedContentForSchedule" ) @Produces ( { APPLICATION_XML, APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully got the generated content for schedule" ) } ) List<RepositoryFileDto> doGetGeneratedContentForSchedule( @QueryParam ( "lineageId" ) String lineageId );  }
@Test public void testPauseJob() throws Exception { String jobId = "jobId"; JobRequest mockJobRequest = mock( JobRequest.class ); doReturn( jobId ).when( mockJobRequest ).getJobId(); Job.JobState state = Job.JobState.BLOCKED; doReturn( state ).when( schedulerResource.schedulerService ).pauseJob( jobId ); Response mockResponse = mock( Response.class ); doReturn( mockResponse ).when( schedulerResource ).buildPlainTextOkResponse( state.name() ); Response testResult = schedulerResource.pauseJob( mockJobRequest ); assertEquals( mockResponse, testResult ); verify( schedulerResource.schedulerService, times( 1 ) ).pauseJob( jobId ); verify( schedulerResource, times( 1 ) ).buildPlainTextOkResponse( state.name() ); }
@Test public void testPauseJobError() throws Exception { String jobId = "jobId"; JobRequest mockJobRequest = mock( JobRequest.class ); doReturn( jobId ).when( mockJobRequest ).getJobId(); SchedulerException mockSchedulerException = mock( SchedulerException.class ); doThrow( mockSchedulerException ).when( schedulerResource.schedulerService ).pauseJob( jobId ); try { schedulerResource.pauseJob( mockJobRequest ); fail(); } catch ( RuntimeException e ) { } verify( schedulerResource.schedulerService, times( 1 ) ).pauseJob( jobId ); }