Skip to content

Commit

Permalink
Merge pull request #3540 from mercedes-benz/develop
Browse files Browse the repository at this point in the history
Merge `develop` into `master` for server release 2.3.1
  • Loading branch information
sven-dmlr authored Oct 21, 2024
2 parents 1d88595 + e15c856 commit c39468e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ public ScheduleSecHubJob markNextJobToExecuteByThisInstance() {
LOG.trace("Trigger execution of next job started");
}

UUID nextJobId = nextJobResolver.resolveNextJobUUID();
if (nextJobId == null) {
UUID nextJobUUID = nextJobResolver.resolveNextJobUUID();
if (nextJobUUID == null) {
return null;
}

Optional<ScheduleSecHubJob> secHubJobOptional = jobRepository.getJobWhenExecutable(nextJobId);
Optional<ScheduleSecHubJob> secHubJobOptional = jobRepository.getJobAndIncrementVersionWhenExecutable(nextJobUUID);
if (!secHubJobOptional.isPresent()) {
LOG.error("Did not found executablejob for next job UUID:{}. This is very problematic and should never happen!", nextJobId);
LOG.trace("Did not find executable job for next job uuid. Job UUID was {}. ", nextJobUUID);
return null;
}

ScheduleSecHubJob secHubJob = secHubJobOptional.get();
ExecutionState state = secHubJob.getExecutionState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public interface SecHubJobRepositoryCustom {

/**
* Returns job when in executable - means execution state is either
* READY_TO_START or SUSPENDED.
* READY_TO_START or SUSPENDED. Will also automatically increment version.
*
* @param sechubJobUUID job uuid to search for
* @return job or <code>null</code>
*/
Optional<ScheduleSecHubJob> getJobWhenExecutable(UUID sechubJobUUID);
Optional<ScheduleSecHubJob> getJobAndIncrementVersionWhenExecutable(UUID sechubJobUUID);

Optional<UUID> nextJobIdToExecuteFirstInFirstOut(Set<Long> acceptedEncryptiondPoolIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class SecHubJobRepositoryImpl implements SecHubJobRepositoryCustom {
private EntityManager em;

@Override
public Optional<ScheduleSecHubJob> getJobWhenExecutable(UUID id) {
public Optional<ScheduleSecHubJob> getJobAndIncrementVersionWhenExecutable(UUID id) {
Query query = em.createQuery(JPQL_STRING_SELECT_BY_JOB_ID);
query.setParameter(PARAM_EXECUTION_STATES, Set.of(ExecutionState.READY_TO_START, ExecutionState.SUSPENDED));
query.setParameter(PARAM_UUID, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ void custom_query_getJob_returns_not_created_job_because_not_in_accepted_state(E
ScheduleSecHubJob created = jobCreator.created(LocalDateTime.now().minusSeconds(5)).being(state).ended(LocalDateTime.now().minusSeconds(4)).create();

/* execute */
Optional<ScheduleSecHubJob> result = jobRepository.getJobWhenExecutable(created.getUUID());
Optional<ScheduleSecHubJob> result = jobRepository.getJobAndIncrementVersionWhenExecutable(created.getUUID());

/* test */
assertFalse(result.isPresent());
Expand All @@ -742,7 +742,7 @@ void custom_query_getJob_returns_created_job_because_in_accepted_state(Execution
ScheduleSecHubJob created = jobCreator.created(LocalDateTime.now().minusSeconds(5)).being(state).ended(LocalDateTime.now().minusSeconds(4)).create();

/* execute */
Optional<ScheduleSecHubJob> result = jobRepository.getJobWhenExecutable(created.getUUID());
Optional<ScheduleSecHubJob> result = jobRepository.getJobAndIncrementVersionWhenExecutable(created.getUUID());

/* test */
assertTrue(result.isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public void before() throws Exception {

secHubJob = mock(ScheduleSecHubJob.class);

when(jobRepository.getJobWhenExecutable(uuid)).thenReturn(Optional.of(secHubJob));
when(jobRepository.getJobAndIncrementVersionWhenExecutable(uuid)).thenReturn(Optional.of(secHubJob));
}

@Test
public void markNextJobExecutedByThisPOD__calls_nextJobResolver() throws Exception {
public void markNextJobExecutedByThisInstance__calls_nextJobResolver() throws Exception {
/* execute */
serviceToTest.markNextJobToExecuteByThisInstance();

Expand All @@ -53,7 +53,7 @@ public void markNextJobExecutedByThisPOD__calls_nextJobResolver() throws Excepti
}

@Test
public void markNextJobExecutedByThisPOD__next_job_found_updates_execution_state_to_started() throws Exception {
public void markNextJobExecutedByThisInstance__next_job_found_updates_execution_state_to_started() throws Exception {
/* prepare */
when(nextJobResolver.resolveNextJobUUID()).thenReturn(uuid);
when(jobRepository.save(secHubJob)).thenReturn(secHubJob);
Expand All @@ -72,7 +72,7 @@ public void markNextJobExecutedByThisPOD__next_job_found_updates_execution_state
}

@Test
public void markNextJobExecutedByThisPOD__next_job_not_found() throws Exception {
public void markNextJobExecutedByThisInstance__next_job_not_found() throws Exception {
/* prepare */
when(nextJobResolver.resolveNextJobUUID()).thenReturn(null);

Expand Down

0 comments on commit c39468e

Please sign in to comment.