use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SecHubJobSafeUpdater method safeUpdateOfSecHubJob.
/**
* Saves the job and also ensures we got a NEW transaction - this is necessary
* when one of the former db actions did come to an ROLLBACK. We want to ensure
* the job will be updated even in such case! This is the reason for the
* REQUIRES_NEW <br>
*
* @see https://www.ibm.com/developerworks/java/library/j-ts1/index.html for
* more details about usage of Propagation.REQUIRES_NEW
* @param secHubJob
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void safeUpdateOfSecHubJob(UUID sechubUUID, ExecutionResult result, String trafficLightString) {
Optional<ScheduleSecHubJob> secHubJobOptional = repository.findById(sechubUUID);
if (!secHubJobOptional.isPresent()) {
LOG.error("Sechub job with UUID:{} not found! Maybe deleted in meantime?", sechubUUID);
return;
}
ScheduleSecHubJob secHubJob = secHubJobOptional.get();
if (ExecutionState.CANCEL_REQUESTED.equals(secHubJob.getExecutionState())) {
LOG.warn("Did not store sechub job data, because cancel requested");
return;
}
secHubJob.setExecutionState(ExecutionState.ENDED);
secHubJob.setExecutionResult(result);
secHubJob.setTrafficLight(TrafficLight.fromString(trafficLightString));
secHubJob.setEnded(LocalDateTime.now());
repository.save(secHubJob);
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerRestControllerRestDocTest method restDoc_userApprovesJob.
@Test
@UseCaseRestDoc(useCase = UseCaseUserApprovesJob.class)
public void restDoc_userApprovesJob() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildApproveJobUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
Class<? extends Annotation> useCase = UseCaseUserApprovesJob.class;
ScheduleSecHubJob job = new ScheduleSecHubJob() {
public UUID getUUID() {
return randomUUID;
}
};
job.setExecutionResult(ExecutionResult.OK);
job.setStarted(LocalDateTime.now().minusMinutes(15));
job.setEnded(LocalDateTime.now());
job.setExecutionState(ExecutionState.ENDED);
job.setOwner("CREATOR1");
job.setTrafficLight(TrafficLight.GREEN);
ScheduleJobStatus status = new ScheduleJobStatus(job);
when(mockedScheduleJobStatusService.getJobStatus(PROJECT1_ID, randomUUID)).thenReturn(status);
/* execute + test @formatter:off */
this.mockMvc.perform(put(apiEndpoint, PROJECT1_ID, randomUUID).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName("projectId").description("The id of the project where sechub job shall be approved"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerBinariesUploadService method assertJobFoundAndStillInitializing.
private void assertJobFoundAndStillInitializing(String projectId, UUID jobUUID) {
ScheduleSecHubJob secHubJob = assertService.assertJob(projectId, jobUUID);
ExecutionState state = secHubJob.getExecutionState();
if (!ExecutionState.INITIALIZING.equals(state)) {
// upload only possible when in initializing state
throw new BadRequestException("Not in correct state");
}
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerCancelJobService method cancelJob.
/**
* This service will cancel given JOB. There is NO check if current user has
* access - this must be done before.
*
* @param jobUUID
* @param ownerEmailAddress
*/
@UseCaseAdminCancelsJob(@Step(number = 3, name = "Try to find job and mark as being canceled", description = "When job is found and user has access the state will be updated and marked as canceled"))
public void cancelJob(UUID jobUUID, String ownerEmailAddress) {
assertion.assertIsValidJobUUID(jobUUID);
Optional<ScheduleSecHubJob> optJob = jobRepository.findById(jobUUID);
if (!optJob.isPresent()) {
LOG.warn("Job {} not present, so not able to cancel!", jobUUID);
return;
}
ScheduleSecHubJob secHubJob = optJob.get();
cancelBatchJobService.stopAllRunningBatchJobsForSechubJobUUID(jobUUID);
markJobAsCanceled(secHubJob);
LOG.info("job {} has been canceled", jobUUID);
sendJobCanceled(secHubJob, ownerEmailAddress);
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerGetJobStatusService method getJobStatus.
@Validated
@UseCaseUserChecksJobStatus(@Step(number = 2, name = "Try to find project and fail or return job status"))
public ScheduleJobStatus getJobStatus(String projectId, UUID jobUUID) {
assertion.assertIsValidProjectId(projectId);
assertion.assertIsValidJobUUID(jobUUID);
scheduleAssert.assertUserHasAccessToProject(projectId);
scheduleAssert.assertProjectAllowsReadAccess(projectId);
ScheduleSecHubJob secHubJob = scheduleAssert.assertJob(projectId, jobUUID);
return new ScheduleJobStatus(secHubJob);
}
Aggregations