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");
}
}
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);
}
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);
}
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 */
}
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 */
}
Aggregations