Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.jdbc</groupId>
<artifactId>quarkus-jdbc-sqlite4j</artifactId>
<version>${sqlite4j.version}</version>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
49 changes: 49 additions & 0 deletions persistence/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.laprun.sustainability</groupId>
<artifactId>power-server-parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
</parent>

<artifactId>power-server-persistence</artifactId>
<name>power-server : persistence</name>
<description>Output measures to a database</description>

<dependencies>
<dependency>
<groupId>net.laprun.sustainability</groupId>
<artifactId>power-server-metadata</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.jdbc</groupId>
<artifactId>quarkus-jdbc-sqlite4j</artifactId>
<version>${sqlite4j.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<configuration>
<configFile>../contributing/eclipse-format.xml</configFile>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Singleton
public class SQLiteFilePersister {
private final AtomicBoolean executing = new AtomicBoolean(false);
@ConfigProperty(name = "power-server.db.backup.location")
@ConfigProperty(name = "power-server.db.backup.location", defaultValue = "power-server-db.sqlite")
String dbFilelocation;
@Inject
DataSource dataSource;
Expand Down
Empty file.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<module>server</module>
<module>cli</module>
<module>if-manifest-export</module>
<module>persistence</module>
</modules>

<dependencyManagement>
Expand Down
5 changes: 5 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<artifactId>power-server-backend</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.laprun.sustainability</groupId>
<artifactId>power-server-persistence</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import io.smallrye.mutiny.subscription.Cancellable;
import net.laprun.sustainability.power.persistence.Persistence;
import net.laprun.sustainability.power.sensors.Measures;
import net.laprun.sustainability.power.sensors.PowerSensor;
import net.laprun.sustainability.power.sensors.RegisteredPID;
Expand All @@ -22,9 +20,6 @@ public class PowerMeasurer {
@Inject
PowerSensor sensor;

@Inject
Persistence persistence;

@ConfigProperty(name = "net.laprun.sustainability.power.sampling-period", defaultValue = DEFAULT_SAMPLING_PERIOD)
Duration samplingPeriod;

Expand All @@ -40,14 +35,6 @@ public Multi<SensorMeasure> uncheckedStream(long pid) throws Exception {
return periodicSensorCheck.map(measures -> measures.getOrDefault(registeredPID));
}

public Cancellable startTrackingApp(String appName, long pid) throws Exception {
return uncheckedStream(pid).subscribe().with(m -> persistence.save(m, appName));
}

public Cancellable startTrackingProcess(Process process) throws Exception {
return startTrackingApp(process.info().commandLine().orElseThrow(), process.pid());
}

private RegisteredPID track(long pid) throws Exception {
if (!sensor.isStarted()) {
sensor.start(samplingPeriod.toMillis());
Expand Down Expand Up @@ -79,8 +66,4 @@ public SensorMetadata metadata() {
public Duration getSamplingPeriod() {
return samplingPeriod;
}

public Persistence persistence() {
return persistence;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
import io.quarkus.runtime.StartupEvent;
import io.smallrye.mutiny.Multi;
import net.laprun.sustainability.power.persistence.Measure;
import net.laprun.sustainability.power.persistence.Persistence;

@Path("/power")
public class PowerResource {
@Inject
PowerMeasurer measurer;

@Inject
Persistence persistence;

public void onStartup(@Observes StartupEvent event) {
Log.info("\nConfigured sampling period: " + samplingPeriod() +
"\nDetected metadata:\n" + metadata());
Expand All @@ -44,7 +48,7 @@ public Multi<SensorMeasure> streamMeasuresFor(@PathParam("pid") String pid) thro
@Path("start/{appName}/{pid}")
public void startMeasure(@PathParam("appName") String appName, @PathParam("pid") String pid) throws Exception {
try {
measurer.startTrackingApp(appName, measurer.validPIDOrFail(pid));
measurer.uncheckedStream(measurer.validPIDOrFail(pid)).subscribe().with(m -> persistence.save(m, appName));
} catch (IllegalArgumentException e) {
throw new NotFoundException("Unknown process: " + pid);
}
Expand Down
Loading