From 8178c16a9fb31d1635adab5be9b5ef847014885c Mon Sep 17 00:00:00 2001 From: Albert Tregnaghi Date: Mon, 21 Oct 2024 15:29:15 +0200 Subject: [PATCH] Changed log output and level + renamed method name #3538 --- .../sechub/domain/schedule/ScheduleJobMarkerService.java | 9 +++++---- .../domain/schedule/job/SecHubJobRepositoryCustom.java | 4 ++-- .../domain/schedule/job/SecHubJobRepositoryImpl.java | 2 +- .../domain/schedule/job/SecHubJobRepositoryDBTest.java | 4 ++-- .../domain/schedule/ScheduleJobMarkerServiceTest.java | 8 ++++---- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/ScheduleJobMarkerService.java b/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/ScheduleJobMarkerService.java index 15839e8b8f..e71df34e45 100644 --- a/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/ScheduleJobMarkerService.java +++ b/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/ScheduleJobMarkerService.java @@ -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 secHubJobOptional = jobRepository.getJobWhenExecutable(nextJobId); + Optional 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(); diff --git a/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryCustom.java b/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryCustom.java index 1d6b5c97a6..14fd3b706f 100644 --- a/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryCustom.java +++ b/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryCustom.java @@ -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 null */ - Optional getJobWhenExecutable(UUID sechubJobUUID); + Optional getJobAndIncrementVersionWhenExecutable(UUID sechubJobUUID); Optional nextJobIdToExecuteFirstInFirstOut(Set acceptedEncryptiondPoolIds); diff --git a/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryImpl.java b/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryImpl.java index 673db8e58f..f475e32a50 100644 --- a/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryImpl.java +++ b/sechub-schedule/src/main/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryImpl.java @@ -95,7 +95,7 @@ public class SecHubJobRepositoryImpl implements SecHubJobRepositoryCustom { private EntityManager em; @Override - public Optional getJobWhenExecutable(UUID id) { + public Optional 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); diff --git a/sechub-schedule/src/test/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryDBTest.java b/sechub-schedule/src/test/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryDBTest.java index ed09a4021f..0c0acfeb13 100644 --- a/sechub-schedule/src/test/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryDBTest.java +++ b/sechub-schedule/src/test/java/com/mercedesbenz/sechub/domain/schedule/job/SecHubJobRepositoryDBTest.java @@ -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 result = jobRepository.getJobWhenExecutable(created.getUUID()); + Optional result = jobRepository.getJobAndIncrementVersionWhenExecutable(created.getUUID()); /* test */ assertFalse(result.isPresent()); @@ -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 result = jobRepository.getJobWhenExecutable(created.getUUID()); + Optional result = jobRepository.getJobAndIncrementVersionWhenExecutable(created.getUUID()); /* test */ assertTrue(result.isPresent()); diff --git a/sechub-server/src/test/java/com/mercedesbenz/sechub/domain/schedule/ScheduleJobMarkerServiceTest.java b/sechub-server/src/test/java/com/mercedesbenz/sechub/domain/schedule/ScheduleJobMarkerServiceTest.java index 293474815d..7aaa13dd1d 100644 --- a/sechub-server/src/test/java/com/mercedesbenz/sechub/domain/schedule/ScheduleJobMarkerServiceTest.java +++ b/sechub-server/src/test/java/com/mercedesbenz/sechub/domain/schedule/ScheduleJobMarkerServiceTest.java @@ -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(); @@ -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); @@ -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);