diff --git a/src/main/java/de/tum/cit/aet/artemis/programming/service/localci/SharedQueueManagementService.java b/src/main/java/de/tum/cit/aet/artemis/programming/service/localci/SharedQueueManagementService.java index 939f60cf28e0..8a857143699e 100644 --- a/src/main/java/de/tum/cit/aet/artemis/programming/service/localci/SharedQueueManagementService.java +++ b/src/main/java/de/tum/cit/aet/artemis/programming/service/localci/SharedQueueManagementService.java @@ -5,7 +5,6 @@ import java.time.Duration; import java.time.ZonedDateTime; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Objects; @@ -115,39 +114,32 @@ public List getQueuedJobs() { } public List getProcessingJobs() { - Collection values = processingJobs.values(); - return new ArrayList<>(values); + return new ArrayList<>(processingJobs.values()); } public List getQueuedJobsForCourse(long courseId) { - List queuedJobs = new ArrayList<>(queue); - return queuedJobs.stream().filter(job -> job.courseId() == courseId).toList(); + return getQueuedJobs().stream().filter(job -> job.courseId() == courseId).toList(); } public List getProcessingJobsForCourse(long courseId) { - Collection values = processingJobs.values(); - return values.stream().filter(job -> job.courseId() == courseId).toList(); + return getProcessingJobs().stream().filter(job -> job.courseId() == courseId).toList(); } public List getQueuedJobsForParticipation(long participationId) { - List queuedJobs = new ArrayList<>(queue); - return queuedJobs.stream().filter(job -> job.participationId() == participationId).toList(); + return getQueuedJobs().stream().filter(job -> job.participationId() == participationId).toList(); } public List getProcessingJobsForParticipation(long participationId) { - Collection values = processingJobs.values(); - return values.stream().filter(job -> job.participationId() == participationId).toList(); + return getProcessingJobs().stream().filter(job -> job.participationId() == participationId).toList(); } public List getBuildAgentInformation() { - Collection values = buildAgentInformation.values(); - return values.stream().toList(); + return new ArrayList<>(buildAgentInformation.values()); } public List getBuildAgentInformationWithoutRecentBuildJobs() { - Collection values = buildAgentInformation.values(); - return values.stream().map(agent -> new BuildAgentInformation(agent.buildAgent(), agent.maxNumberOfConcurrentBuildJobs(), agent.numberOfCurrentBuildJobs(), - agent.runningBuildJobs(), agent.status(), null, agent.publicSshKey())).toList(); + return getBuildAgentInformation().stream().map(agent -> new BuildAgentInformation(agent.buildAgent(), agent.maxNumberOfConcurrentBuildJobs(), + agent.numberOfCurrentBuildJobs(), agent.runningBuildJobs(), agent.status(), null, agent.publicSshKey())).toList(); } public void pauseBuildAgent(String agent) { @@ -165,7 +157,7 @@ public void resumeBuildAgent(String agent) { */ public void cancelBuildJob(String buildJobId) { // Remove build job if it is queued - List queuedJobs = new ArrayList<>(queue); + List queuedJobs = getQueuedJobs(); if (queuedJobs.stream().anyMatch(job -> Objects.equals(job.id(), buildJobId))) { List toRemove = new ArrayList<>(); for (BuildJobQueueItem job : queuedJobs) { @@ -207,7 +199,7 @@ public void cancelAllQueuedBuildJobs() { * Cancel all running build jobs. */ public void cancelAllRunningBuildJobs() { - Collection values = processingJobs.values(); + List values = getProcessingJobs(); for (BuildJobQueueItem buildJob : values) { cancelBuildJob(buildJob.id()); } @@ -219,8 +211,7 @@ public void cancelAllRunningBuildJobs() { * @param agentName name of the agent */ public void cancelAllRunningBuildJobsForAgent(String agentName) { - Collection values = processingJobs.values(); - values.stream().filter(job -> Objects.equals(job.buildAgent().name(), agentName)).forEach(job -> cancelBuildJob(job.id())); + getProcessingJobs().stream().filter(job -> Objects.equals(job.buildAgent().name(), agentName)).forEach(job -> cancelBuildJob(job.id())); } /** @@ -229,8 +220,8 @@ public void cancelAllRunningBuildJobsForAgent(String agentName) { * @param courseId id of the course */ public void cancelAllQueuedBuildJobsForCourse(long courseId) { + List queuedJobs = getQueuedJobs(); List toRemove = new ArrayList<>(); - List queuedJobs = new ArrayList<>(queue); for (BuildJobQueueItem job : queuedJobs) { if (job.courseId() == courseId) { toRemove.add(job); @@ -245,7 +236,7 @@ public void cancelAllQueuedBuildJobsForCourse(long courseId) { * @param courseId id of the course */ public void cancelAllRunningBuildJobsForCourse(long courseId) { - Collection values = processingJobs.values(); + List values = getProcessingJobs(); for (BuildJobQueueItem buildJob : values) { if (buildJob.courseId() == courseId) { cancelBuildJob(buildJob.id()); @@ -260,7 +251,7 @@ public void cancelAllRunningBuildJobsForCourse(long courseId) { */ public void cancelAllJobsForParticipation(long participationId) { List toRemove = new ArrayList<>(); - List queuedJobs = new ArrayList<>(queue); + List queuedJobs = getQueuedJobs(); for (BuildJobQueueItem queuedJob : queuedJobs) { if (queuedJob.participationId() == participationId) { toRemove.add(queuedJob); @@ -268,7 +259,7 @@ public void cancelAllJobsForParticipation(long participationId) { } queue.removeAll(toRemove); - Collection values = this.processingJobs.values(); + List values = getProcessingJobs(); for (BuildJobQueueItem runningJob : values) { if (runningJob.participationId() == participationId) { cancelBuildJob(runningJob.id());