Search in sources :

Example 11 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerSourcecodeUploadService 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 NotAcceptableException("Not in correct state");
    }
}
Also used : NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)

Example 12 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class IntegrationTestSchedulerService method revertJobAsStillRunning.

/**
 * Reverts/Marks given job as still running - will reset result, state, end
 * timestamp and traffic light
 *
 * @param sechubJobUUID
 */
public void revertJobAsStillRunning(UUID sechubJobUUID) {
    Optional<ScheduleSecHubJob> found = repository.findById(sechubJobUUID);
    if (!found.isPresent()) {
        throw new NotFoundException("Job not found!");
    }
    ScheduleSecHubJob job = found.get();
    job.setExecutionResult(ExecutionResult.NONE);
    job.setExecutionState(ExecutionState.STARTED);
    job.setEnded(null);
    job.setTrafficLight(null);
    repository.save(job);
}
Also used : NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)

Example 13 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerApproveJobService method approveJob.

@UseCaseUserApprovesJob(@Step(number = 2, name = "Try to find job annd update execution state", description = "When job is found and user has access job will be marked as ready for execution"))
public void approveJob(String projectId, UUID jobUUID) {
    assertion.assertIsValidProjectId(projectId);
    assertion.assertIsValidJobUUID(jobUUID);
    assertService.assertUserHasAccessToProject(projectId);
    assertService.assertProjectAllowsWriteAccess(projectId);
    ScheduleSecHubJob secHubJob = assertService.assertJob(projectId, jobUUID);
    ExecutionState state = secHubJob.getExecutionState();
    if (!ExecutionState.INITIALIZING.equals(state)) {
        throw new NotAcceptableException("Not in correct state");
    }
    secHubJob.setExecutionState(ExecutionState.READY_TO_START);
    jobRepository.save(secHubJob);
    LOG.info("job {} now approved", jobUUID);
}
Also used : NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UseCaseUserApprovesJob(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserApprovesJob)

Example 14 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method restDoc_userChecksJobState.

@Test
@UseCaseRestDoc(useCase = UseCaseUserChecksJobStatus.class)
public void restDoc_userChecksJobState() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildGetJobStatusUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserChecksJobStatus.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(get(apiEndpoint, PROJECT1_ID, randomUUID).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().json("{jobUUID:" + randomUUID.toString() + ", result:OK, state:ENDED, trafficLight:GREEN}")).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.JOB_STATUS.getSchema()).and().document(pathParameters(parameterWithName("projectId").description("The id of the project where sechub job was started for"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID)), responseFields(fieldWithPath(ScheduleJobStatus.PROPERTY_JOBUUID).description("The job uuid"), fieldWithPath(ScheduleJobStatus.PROPERTY_CREATED).description("Creation timestamp of job"), fieldWithPath(ScheduleJobStatus.PROPERTY_STARTED).description("Start timestamp of job execution"), fieldWithPath(ScheduleJobStatus.PROPERTY_ENDED).description("End timestamp of job execution"), fieldWithPath(ScheduleJobStatus.PROPERTY_OWNER).description("Owner / initiator of job"), fieldWithPath(ScheduleJobStatus.PROPERTY_STATE).description("State of job"), fieldWithPath(ScheduleJobStatus.PROPERTY_RESULT).description("Result of job"), fieldWithPath(ScheduleJobStatus.PROPERTY_TRAFFICLIGHT).description("Trafficlight of job - but only available when job has been done. Possible states are " + StringUtils.arrayToDelimitedString(TrafficLight.values(), ", ")))));
/* @formatter:on */
}
Also used : UseCaseUserChecksJobStatus(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserChecksJobStatus) 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 15 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method restDoc_userUploadsBinaries.

@Test
@UseCaseRestDoc(useCase = UseCaseUserUploadsBinaries.class)
public void restDoc_userUploadsBinaries() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildUploadBinariesUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserUploadsBinaries.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.INITIALIZING);
    job.setOwner("CREATOR1");
    job.setTrafficLight(TrafficLight.GREEN);
    ScheduleJobStatus status = new ScheduleJobStatus(job);
    when(mockedScheduleJobStatusService.getJobStatus(PROJECT1_ID, randomUUID)).thenReturn(status);
    InputStream inputStreamTo = RestDocTestFileSupport.getTestfileSupport().getInputStreamTo("upload/tarfile_contains_only_test1.txt.tar");
    MockMultipartFile file1 = new MockMultipartFile("file", inputStreamTo);
    /* execute + test @formatter:off */
    this.mockMvc.perform(multipart(apiEndpoint, PROJECT1_ID, randomUUID).file(file1).param("checkSum", "mychecksum")).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName("projectId").description("The id of the project for which the binaries are uploaded for"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID)), requestParameters(parameterWithName("checkSum").description("A sha256 checksum for file upload validation")), // See: https://github.com/ePages-de/restdocs-api-spec/issues/105
    requestParts(partWithName("file").description("The binaries as tarfile to upload"))));
/* @formatter:on */
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) InputStream(java.io.InputStream) UseCaseUserUploadsBinaries(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserUploadsBinaries) 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)

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