Skip to content

Commit

Permalink
add missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
BBesrour committed Nov 28, 2024
1 parent fd07957 commit 575bee4
Showing 1 changed file with 59 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tum.cit.aet.artemis.programming.service.localci;

import java.util.ArrayList;
import java.util.List;

import jakarta.annotation.PostConstruct;
Expand All @@ -20,7 +21,9 @@
import com.hazelcast.map.listener.EntryUpdatedListener;

import de.tum.cit.aet.artemis.buildagent.dto.BuildAgentInformation;
import de.tum.cit.aet.artemis.buildagent.dto.BuildConfig;
import de.tum.cit.aet.artemis.buildagent.dto.BuildJobQueueItem;
import de.tum.cit.aet.artemis.buildagent.dto.RepositoryInfo;

/**
* This service is responsible for sending build job queue information over websockets.
Expand Down Expand Up @@ -68,53 +71,21 @@ public void init() {
}

private void sendQueuedJobsOverWebsocket(long courseId) {
var queuedJobs = sharedQueueManagementService.getQueuedJobs();
removeUnnecessaryInformation(queuedJobs);
var queuedJobs = removeUnnecessaryInformation(sharedQueueManagementService.getQueuedJobs());
var queuedJobsForCourse = queuedJobs.stream().filter(job -> job.courseId() == courseId).toList();
localCIWebsocketMessagingService.sendQueuedBuildJobs(queuedJobs);
localCIWebsocketMessagingService.sendQueuedBuildJobsForCourse(courseId, queuedJobsForCourse);
}

/**
* Removes unnecessary information (e.g. repository info, build config, result) from the queued jobs before sending them over the websocket.
*
* @param queuedJobs the queued jobs
*/
private static void removeUnnecessaryInformation(List<BuildJobQueueItem> queuedJobs) {
for (int i = 0; i < queuedJobs.size(); i++) {
var job = queuedJobs.get(i);
queuedJobs.set(i, new BuildJobQueueItem(job.id(), job.name(), job.buildAgent(), job.participationId(), job.courseId(), job.exerciseId(), job.retryCount(),
job.priority(), job.status(), null, job.jobTimingInfo(), null, null));

}
}

/**
* Removes unnecessary information (e.g. recent build jobs, public ssh key, result) from the running jobs before sending them over the websocket.
*
* @param buildAgentSummary the build agent summary
*/
private static void removeUnnecessaryInformationFromBuildAgentInformation(List<BuildAgentInformation> buildAgentSummary) {
for (int i = 0; i < buildAgentSummary.size(); i++) {
var agent = buildAgentSummary.get(i);
var runningJobs = agent.runningBuildJobs();
removeUnnecessaryInformation(runningJobs);
buildAgentSummary.set(i, new BuildAgentInformation(agent.buildAgent(), agent.maxNumberOfConcurrentBuildJobs(), agent.numberOfCurrentBuildJobs(), runningJobs,
agent.status(), null, null));
}
}

private void sendProcessingJobsOverWebsocket(long courseId) {
var processingJobs = sharedQueueManagementService.getProcessingJobs();
removeUnnecessaryInformation(processingJobs);
var processingJobs = removeUnnecessaryInformation(sharedQueueManagementService.getProcessingJobs());
var processingJobsForCourse = processingJobs.stream().filter(job -> job.courseId() == courseId).toList();
localCIWebsocketMessagingService.sendRunningBuildJobs(processingJobs);
localCIWebsocketMessagingService.sendRunningBuildJobsForCourse(courseId, processingJobsForCourse);
}

private void sendBuildAgentSummaryOverWebsocket() {
List<BuildAgentInformation> buildAgentSummary = sharedQueueManagementService.getBuildAgentInformationWithoutRecentBuildJobs();
removeUnnecessaryInformationFromBuildAgentInformation(buildAgentSummary);
var buildAgentSummary = removeUnnecessaryInformationFromBuildAgentInformation(sharedQueueManagementService.getBuildAgentInformationWithoutRecentBuildJobs());
localCIWebsocketMessagingService.sendBuildAgentSummary(buildAgentSummary);
}

Expand Down Expand Up @@ -177,4 +148,57 @@ public void entryUpdated(com.hazelcast.core.EntryEvent<String, BuildAgentInforma
sendBuildAgentInformationOverWebsocket(event.getValue().buildAgent().name());
}
}

/**
* Removes unnecessary information (e.g. repository info, build config, result) from the queued jobs before sending them over the websocket.
*
* @param queuedJobs the queued jobs
*/
private static List<BuildJobQueueItem> removeUnnecessaryInformation(List<BuildJobQueueItem> queuedJobs) {
var filteredQueuedJobs = new ArrayList<BuildJobQueueItem>(); // make list mutable in case it is not
for (BuildJobQueueItem job : queuedJobs) {
var buildConfig = removeUnnecessaryInformationFromBuildConfig(job.buildConfig());
var repositoryInfo = removeUnnecessaryInformationFromRepositoryInfo(job.repositoryInfo());
filteredQueuedJobs.add(new BuildJobQueueItem(job.id(), job.name(), job.buildAgent(), job.participationId(), job.courseId(), job.exerciseId(), job.retryCount(),
job.priority(), job.status(), repositoryInfo, job.jobTimingInfo(), buildConfig, null));

}
return filteredQueuedJobs;
}

/**
* Removes unnecessary information (e.g. build script, docker image) from the build config before sending it over the websocket.
*
* @param buildConfig the build config
*/
private static BuildConfig removeUnnecessaryInformationFromBuildConfig(BuildConfig buildConfig) {
// We pass "" instead of null strings to avoid errors when serializing to JSON
return new BuildConfig("", "", buildConfig.commitHashToBuild(), "", "", "", null, null, buildConfig.scaEnabled(), buildConfig.sequentialTestRunsEnabled(),
buildConfig.testwiseCoverageEnabled(), null, buildConfig.timeoutSeconds(), "", "", "");
}

/**
* Removes unnecessary information (RepositoryUris) from the repository info before sending it over the websocket.
*
* @param repositoryInfo the repository info
*/
private static RepositoryInfo removeUnnecessaryInformationFromRepositoryInfo(RepositoryInfo repositoryInfo) {
// We pass "" instead of null strings to avoid errors when serializing to JSON
return new RepositoryInfo(repositoryInfo.repositoryName(), repositoryInfo.repositoryType(), repositoryInfo.triggeredByPushTo(), "", "", "", null, null);
}

/**
* Removes unnecessary information (e.g. recent build jobs, public ssh key, result) from the running jobs before sending them over the websocket.
*
* @param buildAgentSummary the build agent summary
*/
private static List<BuildAgentInformation> removeUnnecessaryInformationFromBuildAgentInformation(List<BuildAgentInformation> buildAgentSummary) {
var filteredBuildAgentSummary = new ArrayList<BuildAgentInformation>(); // make list mutable in case it is not
for (BuildAgentInformation agent : buildAgentSummary) {
var runningJobs = removeUnnecessaryInformation(agent.runningBuildJobs());
filteredBuildAgentSummary.add(new BuildAgentInformation(agent.buildAgent(), agent.maxNumberOfConcurrentBuildJobs(), agent.numberOfCurrentBuildJobs(), runningJobs,
agent.status(), null, null));
}
return filteredBuildAgentSummary;
}
}

0 comments on commit 575bee4

Please sign in to comment.