Search in sources :

Example 1 with UseCaseAdminCancelsJob

use of com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseAdminCancelsJob 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);
}
Also used : ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UseCaseAdminCancelsJob(com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseAdminCancelsJob)

Example 2 with UseCaseAdminCancelsJob

use of com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseAdminCancelsJob in project sechub by mercedes-benz.

the class JobCancelService method cancelJob.

@Validated
@UseCaseAdminCancelsJob(@Step(number = 2, name = "Cancel job", description = "Will trigger event that job cancel requested"))
public void cancelJob(UUID jobUUID) {
    assertion.assertIsValidJobUUID(jobUUID);
    auditLogService.log("Requested cancelation of job {}", jobUUID);
    JobMessage message = buildMessage(jobUUID);
    /* trigger event */
    informCancelJobRequested(message);
}
Also used : JobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage) Validated(org.springframework.validation.annotation.Validated) UseCaseAdminCancelsJob(com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseAdminCancelsJob)

Example 3 with UseCaseAdminCancelsJob

use of com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseAdminCancelsJob in project sechub by mercedes-benz.

the class InformUserThatJobHasBeenCanceledService method notify.

@UseCaseAdminCancelsJob(@Step(number = 4, name = "Inform user that her/his job has been canceled"))
public void notify(JobMessage jobMessage) {
    String ownerEmailAddress = jobMessage.getOwnerEmailAddress();
    if (ownerEmailAddress == null || ownerEmailAddress.isEmpty()) {
        LOG.warn("Event did not contain user email address of canceled job {}, so cannot inform!", jobMessage.getJobUUID());
        return;
    }
    SimpleMailMessage message = factory.createMessage("Your SecHub Job has been canceled");
    message.setTo(ownerEmailAddress);
    message.setText(createEmailContent(jobMessage));
    emailService.send(message);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) UseCaseAdminCancelsJob(com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseAdminCancelsJob)

Aggregations

UseCaseAdminCancelsJob (com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseAdminCancelsJob)3 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)1 JobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1 Validated (org.springframework.validation.annotation.Validated)1