Search in sources :

Example 21 with ScheduleSecHubJob

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);
}
Also used : ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with ScheduleSecHubJob

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 */
}
Also used : UseCaseUserApprovesJob(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserApprovesJob) ScheduleJobStatus(com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 23 with ScheduleSecHubJob

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");
    }
}
Also used : BadRequestException(com.mercedesbenz.sechub.sharedkernel.error.BadRequestException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)

Example 24 with ScheduleSecHubJob

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

Example 25 with ScheduleSecHubJob

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);
}
Also used : ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UseCaseUserChecksJobStatus(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserChecksJobStatus) Validated(org.springframework.validation.annotation.Validated)

Aggregations

ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)30 Test (org.junit.Test)12 UUID (java.util.UUID)6 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)5 ScheduleJobStatus (com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus)4 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)4 NotAcceptableException (com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException)3 NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)3 AuditLogService (com.mercedesbenz.sechub.sharedkernel.logging.AuditLogService)3 LogSanitizer (com.mercedesbenz.sechub.sharedkernel.logging.LogSanitizer)3 ChecksumSHA256Service (com.mercedesbenz.sechub.sharedkernel.util.ChecksumSHA256Service)3 UserInputAssertion (com.mercedesbenz.sechub.sharedkernel.validation.UserInputAssertion)3 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)3 StorageService (com.mercedesbenz.sechub.storage.core.StorageService)3 InputStream (java.io.InputStream)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)3 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)2 UseCaseSchedulerStartsJob (com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseSchedulerStartsJob)2 UseCaseUserApprovesJob (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserApprovesJob)2