diff --git a/src/main/java/de/tum/cit/aet/artemis/core/config/MetricsBean.java b/src/main/java/de/tum/cit/aet/artemis/core/config/MetricsBean.java index 6d2bff114552..1bf84e3995b2 100644 --- a/src/main/java/de/tum/cit/aet/artemis/core/config/MetricsBean.java +++ b/src/main/java/de/tum/cit/aet/artemis/core/config/MetricsBean.java @@ -290,16 +290,15 @@ private void registerLocalCIMetrics() { } private static int extractRunningBuilds(Optional sharedQueueManagementService) { - return sharedQueueManagementService.map(queueManagementService -> queueManagementService.getBuildAgentInformation().stream() - .map(buildAgentInformation -> buildAgentInformation.runningBuildJobs().size()).reduce(0, Integer::sum)).orElse(0); + return sharedQueueManagementService.map(SharedQueueManagementService::getProcessingJobsSize).orElse(0); } private static int extractQueuedBuilds(Optional sharedQueueManagementService) { - return sharedQueueManagementService.map(queueManagementService -> queueManagementService.getQueuedJobs().size()).orElse(0); + return sharedQueueManagementService.map(SharedQueueManagementService::getQueuedJobsSize).orElse(0); } private static int extractBuildAgents(Optional sharedQueueManagementService) { - return sharedQueueManagementService.map(queueManagementService -> queueManagementService.getBuildAgentInformation().size()).orElse(0); + return sharedQueueManagementService.map(SharedQueueManagementService::getBuildAgentInformationSize).orElse(0); } private static int extractMaxConcurrentBuilds(Optional sharedQueueManagementService) { 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 059df76379da..4e29ec53fe73 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 @@ -116,6 +116,10 @@ public List getQueuedJobs() { return new ArrayList<>(queue); } + public int getQueuedJobsSize() { + return queue.size(); + } + /** * @return a copy of the processing jobs as ArrayList */ @@ -124,6 +128,10 @@ public List getProcessingJobs() { return new ArrayList<>(processingJobs.values()); } + public int getProcessingJobsSize() { + return processingJobs.size(); + } + public List getQueuedJobsForCourse(long courseId) { return getQueuedJobs().stream().filter(job -> job.courseId() == courseId).toList(); } @@ -145,6 +153,10 @@ public List getBuildAgentInformation() { return new ArrayList<>(buildAgentInformation.values()); } + public int getBuildAgentInformationSize() { + return buildAgentInformation.size(); + } + public List getBuildAgentInformationWithoutRecentBuildJobs() { return getBuildAgentInformation().stream().map(agent -> new BuildAgentInformation(agent.buildAgent(), agent.maxNumberOfConcurrentBuildJobs(), agent.numberOfCurrentBuildJobs(), agent.runningBuildJobs(), agent.status(), null, null)).toList(); @@ -303,5 +315,4 @@ public Page getFilteredFinishedBuildJobs(FinishedBuildJobPageableSearc return new PageImpl<>(orderedBuildJobs, buildJobIdsPage.getPageable(), buildJobIdsPage.getTotalElements()); } - }