-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from ls1intum/develop
LocalCI Metrics
- Loading branch information
Showing
27 changed files
with
437 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package de.tum.cit.ase.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "local_ci_status") | ||
public class LocalCIStatus { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "is_finished") | ||
private boolean isFinished; | ||
|
||
@Column(name = "queued_jobs") | ||
private int queuedJobs; | ||
|
||
@Column(name = "total_jobs") | ||
private int totalJobs; | ||
|
||
@Column(name = "time_in_minutes") | ||
private int timeInMinutes; | ||
|
||
@Column(name = "avg_jobs_per_minute") | ||
private double avgJobsPerMinute; | ||
|
||
@OneToOne | ||
@JoinColumn(name = "simulation_run_id", nullable = false) | ||
@JsonIgnore | ||
private SimulationRun simulationRun; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public boolean isFinished() { | ||
return isFinished; | ||
} | ||
|
||
public void setFinished(boolean finished) { | ||
isFinished = finished; | ||
} | ||
|
||
public int getQueuedJobs() { | ||
return queuedJobs; | ||
} | ||
|
||
public void setQueuedJobs(int queuedJobs) { | ||
this.queuedJobs = queuedJobs; | ||
} | ||
|
||
public int getTotalJobs() { | ||
return totalJobs; | ||
} | ||
|
||
public void setTotalJobs(int totalJobs) { | ||
this.totalJobs = totalJobs; | ||
} | ||
|
||
public int getTimeInMinutes() { | ||
return timeInMinutes; | ||
} | ||
|
||
public void setTimeInMinutes(int timeInMinutes) { | ||
this.timeInMinutes = timeInMinutes; | ||
} | ||
|
||
public double getAvgJobsPerMinute() { | ||
return avgJobsPerMinute; | ||
} | ||
|
||
public void setAvgJobsPerMinute(double avgJobsPerMinute) { | ||
this.avgJobsPerMinute = avgJobsPerMinute; | ||
} | ||
|
||
public SimulationRun getSimulationRun() { | ||
return simulationRun; | ||
} | ||
|
||
public void setSimulationRun(SimulationRun simulationRun) { | ||
this.simulationRun = simulationRun; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/de/tum/cit/ase/repository/LocalCIStatusRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.tum.cit.ase.repository; | ||
|
||
import de.tum.cit.ase.domain.LocalCIStatus; | ||
import jakarta.transaction.Transactional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface LocalCIStatusRepository extends JpaRepository<LocalCIStatus, Long> { | ||
@Modifying | ||
@Transactional | ||
@Query(value = "delete from LocalCIStatus status where status.isFinished = false") | ||
void deleteAllNotFinished(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/de/tum/cit/ase/service/LocalCIStatusService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package de.tum.cit.ase.service; | ||
|
||
import de.tum.cit.ase.domain.LocalCIStatus; | ||
import de.tum.cit.ase.domain.SimulationRun; | ||
import de.tum.cit.ase.repository.LocalCIStatusRepository; | ||
import de.tum.cit.ase.service.artemis.interaction.SimulatedArtemisAdmin; | ||
import de.tum.cit.ase.web.websocket.SimulationWebsocketService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class LocalCIStatusService { | ||
|
||
private final Logger log = LoggerFactory.getLogger(LocalCIStatusService.class); | ||
private final LocalCIStatusRepository localCIStatusRepository; | ||
private final SimulationWebsocketService websocketService; | ||
|
||
public LocalCIStatusService(LocalCIStatusRepository localCIStatusRepository, SimulationWebsocketService websocketService) { | ||
this.localCIStatusRepository = localCIStatusRepository; | ||
this.websocketService = websocketService; | ||
cleanup(); | ||
} | ||
|
||
public LocalCIStatus createLocalCIStatus(SimulationRun simulationRun) { | ||
LocalCIStatus status = new LocalCIStatus(); | ||
status.setSimulationRun(simulationRun); | ||
status.setFinished(false); | ||
status.setAvgJobsPerMinute(0); | ||
status.setQueuedJobs(0); | ||
status.setTotalJobs(0); | ||
status.setTimeInMinutes(0); | ||
return localCIStatusRepository.save(status); | ||
} | ||
|
||
@Async | ||
public void subscribeToLocalCIStatus(SimulationRun simulationRun, SimulatedArtemisAdmin admin, long courseId) { | ||
log.info("Subscribing to local CI status for simulation run {}", simulationRun.getId()); | ||
LocalCIStatus status = createLocalCIStatus(simulationRun); | ||
|
||
int numberOfQueuedJobs = admin.getBuildQueue(courseId).size(); | ||
status.setTotalJobs(numberOfQueuedJobs); | ||
status.setQueuedJobs(numberOfQueuedJobs); | ||
status = localCIStatusRepository.save(status); | ||
websocketService.sendRunLocalCIUpdate(simulationRun.getId(), status); | ||
|
||
do { | ||
try { | ||
Thread.sleep(1000 * 60); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
log.debug("Updating local CI status for simulation run {}", simulationRun.getId()); | ||
numberOfQueuedJobs = admin.getBuildQueue(courseId).size(); | ||
status.setQueuedJobs(numberOfQueuedJobs); | ||
status.setTimeInMinutes(status.getTimeInMinutes() + 1); | ||
status.setAvgJobsPerMinute((double) (status.getTotalJobs() - status.getQueuedJobs()) / status.getTimeInMinutes()); | ||
status = localCIStatusRepository.save(status); | ||
websocketService.sendRunLocalCIUpdate(simulationRun.getId(), status); | ||
} while (numberOfQueuedJobs > 0); | ||
status.setFinished(true); | ||
status = localCIStatusRepository.save(status); | ||
websocketService.sendRunLocalCIUpdate(simulationRun.getId(), status); | ||
log.info("Finished subscribing to local CI status for simulation run {}", simulationRun.getId()); | ||
} | ||
|
||
private void cleanup() { | ||
log.info("Cleaning up local CI status"); | ||
localCIStatusRepository.deleteAllNotFinished(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.