Skip to content

Commit ae06dfc

Browse files
franksn90ArefMT
andauthored
Adjust RestApi to handle MTL stimuli (#96)
* Add support for mtl specification * Change file names to work with the api specification * Adjust the api to accept the mtl spec as a file. * Fix a bug with the mtl file upload * Downgrade to Java 17 * Change to token with publishing permissions * Trace a bug when creating output folder. * Handle case of MiSim being part of another application * Change order of dependencies to avoid library version issues * Adjust the names of output files and minor refactorings --------- Co-authored-by: Aref El-Maarawi <arefm.ven@gmail.com>
1 parent 69989cb commit ae06dfc

12 files changed

Lines changed: 108 additions & 89 deletions

File tree

.github/workflows/dockerBuildAndPush.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
registry: ${{ env.REGISTRY }}
3434
username: ${{ github.actor }}
35-
password: ${{ secrets.GITHUB_TOKEN }}
35+
password: ${{ secrets.PUBLISH_PACKAGES }}
3636

3737
- name: Extract metadata (tags, labels) for Docker
3838
id: meta
@@ -53,5 +53,5 @@ jobs:
5353
labels: ${{ steps.meta.outputs.labels }}
5454
build-args: |
5555
EXECUTION_ENV=ci
56-
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
56+
GITHUB_TOKEN=${{ secrets.PUBLISH_PACKAGES }}
5757
GITHUB_USER=${{ github.actor }}

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG GITHUB_USER
66
ARG GITHUB_TOKEN
77

88
# Build stage
9-
FROM maven:3.9.6-amazoncorretto-21-debian AS build
9+
FROM maven:3.9.2-amazoncorretto-17-debian-bullseye AS build
1010
ARG GITHUB_USER
1111
ENV GITHUB_USER=$GITHUB_USER
1212
ARG GITHUB_TOKEN
@@ -25,7 +25,7 @@ RUN mvn -B install --settings settings.xml --file pom.xml -DskipTests=true -Dmav
2525
RUN mvn -B install --file ./restAPI/pom.xml -DskipTests=true -Dmaven.javadoc.skip=true -Dcheckstyle.skipExec=true
2626

2727
# Package stage
28-
FROM eclipse-temurin:21-jdk-alpine AS package
28+
FROM eclipse-temurin:17-jdk-jammy AS package
2929

3030
# gets the *.jar file from the api application from the build stage
3131
COPY --from=build /app/restAPI/target/*.jar app.jar

Examples/Tl-Tea-Integration/example_architecture_tltea_scenario1.json renamed to Examples/Tl-Tea-Integration/architecture_tltea_scenario1.json

File renamed without changes.
File renamed without changes.
File renamed without changes.

pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>cambio.simulator</groupId>
@@ -248,7 +249,8 @@
248249
<version>3.3.0</version>
249250
<configuration>
250251
<transformers>
251-
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
252+
<transformer
253+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
252254
<mainClass>cambio.simulator.Main</mainClass>
253255
</transformer>
254256
</transformers>

restAPI/pom.xml

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,76 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<parent>
6-
<groupId>org.springframework.boot</groupId>
7-
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.1.5</version>
9-
<relativePath/> <!-- lookup parent from repository -->
10-
</parent>
11-
<groupId>restAPI</groupId>
12-
<artifactId>restAPI</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
14-
<name>restAPI</name>
15-
<properties>
16-
<java.version>21</java.version>
17-
</properties>
18-
<dependencies>
19-
<dependency>
20-
<groupId>cambio.simulator</groupId>
21-
<artifactId>misim</artifactId>
22-
<version>3.4.0</version>
23-
</dependency>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.1.5</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>restAPI</groupId>
12+
<artifactId>restAPI</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>restAPI</name>
15+
<properties>
16+
<java.version>17</java.version>
17+
</properties>
18+
<dependencies>
19+
<!-- Take care of the order of dependencies. Tablesaw must come first -->
20+
<dependency>
21+
<groupId>tech.tablesaw</groupId>
22+
<artifactId>tablesaw-core</artifactId>
23+
<version>0.43.1</version>
24+
</dependency>
2425

25-
<dependency>
26-
<groupId>tech.tablesaw</groupId>
27-
<artifactId>tablesaw-core</artifactId>
28-
<version>0.43.1</version>
29-
</dependency>
26+
<dependency>
27+
<groupId>cambio.simulator</groupId>
28+
<artifactId>misim</artifactId>
29+
<version>3.4.0</version>
30+
</dependency>
3031

31-
<dependency>
32-
<groupId>com.google.code.gson</groupId>
33-
<artifactId>gson</artifactId>
34-
<version>2.9.1</version>
35-
</dependency>
32+
<dependency>
33+
<groupId>com.google.code.gson</groupId>
34+
<artifactId>gson</artifactId>
35+
<version>2.9.1</version>
36+
</dependency>
3637

37-
<dependency>
38-
<groupId>com.opencsv</groupId>
39-
<artifactId>opencsv</artifactId>
40-
<version>5.9</version>
41-
</dependency>
38+
<dependency>
39+
<groupId>com.opencsv</groupId>
40+
<artifactId>opencsv</artifactId>
41+
<version>5.9</version>
42+
</dependency>
4243

43-
<dependency>
44-
<groupId>org.springframework.boot</groupId>
45-
<artifactId>spring-boot-starter</artifactId>
46-
<exclusions>
47-
<exclusion>
48-
<groupId>ch.qos.logback</groupId>
49-
<artifactId>logback-classic</artifactId>
50-
</exclusion>
51-
</exclusions>
52-
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter</artifactId>
47+
<exclusions>
48+
<exclusion>
49+
<groupId>ch.qos.logback</groupId>
50+
<artifactId>logback-classic</artifactId>
51+
</exclusion>
52+
</exclusions>
53+
</dependency>
5354

54-
<dependency>
55-
<groupId>org.springframework.boot</groupId>
56-
<artifactId>spring-boot-starter-web</artifactId>
57-
</dependency>
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-starter-web</artifactId>
58+
</dependency>
5859

59-
<dependency>
60-
<groupId>org.springframework.boot</groupId>
61-
<artifactId>spring-boot-starter-test</artifactId>
62-
<scope>test</scope>
63-
</dependency>
64-
</dependencies>
60+
<dependency>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-starter-test</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
</dependencies>
6566

66-
<build>
67-
<plugins>
68-
<plugin>
69-
<groupId>org.springframework.boot</groupId>
70-
<artifactId>spring-boot-maven-plugin</artifactId>
71-
</plugin>
72-
</plugins>
73-
</build>
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-maven-plugin</artifactId>
72+
</plugin>
73+
</plugins>
74+
</build>
7475

7576
</project>

restAPI/src/main/java/restAPI/simulation_running/SimulationRunningController.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
import java.io.IOException;
18+
import java.nio.file.Files;
1819
import java.nio.file.Path;
1920

2021

@@ -30,13 +31,17 @@ public SimulationRunningController(SimulationRunningService simulationRunningSer
3031
this.simulationRunningService = simulationRunningService;
3132
}
3233

33-
34-
// TODO: Handle this call in a non-blocking manner, taking into account that this implementation is not
35-
// client friendly as it can time-out the request due to the long processing time.
3634
//For uploading the Multipart files and saving them to the file system. And then we run the simulation on them.
3735
@PostMapping("/simulate/upload")
3836
public ResponseEntity<String> handleMultipleFilesUpload(@RequestParam("files") MultipartFile[] files,
3937
@RequestParam("simulation_id") String id) throws IOException {
38+
return runSimulation(files, id);
39+
}
40+
41+
// TODO: Handle this call in a non-blocking manner, taking into account that this implementation is not
42+
// client friendly as it can time-out the request due to the long processing time.
43+
private ResponseEntity<String> runSimulation(MultipartFile[] files,
44+
String id) throws IOException {
4045
try {
4146
if (TempFileUtils.existsSimulationId(id)) {
4247
return new ResponseEntity<>(String.format("Simulation ID <%s> is already in use. " +
@@ -45,6 +50,7 @@ public ResponseEntity<String> handleMultipleFilesUpload(@RequestParam("files") M
4550
}
4651
Path tmpFolder = TempFileUtils.createDefaultTempDir("misim-");
4752
Path outputFolder = TempFileUtils.createOutputDir(TempFileUtils.RAW_OUTPUT_DIR, id);
53+
4854
Multimap<String, String> savedFiles = TempFileUtils.saveFiles(files, tmpFolder);
4955
//Block1
5056
simulationRunningService.runExperiment(savedFiles, outputFolder);

restAPI/src/main/java/restAPI/simulation_running/SimulationRunningService.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919

2020
@Service
2121
public class SimulationRunningService {
22-
private static final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
22+
private static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");
2323

24-
public void runExperiment(Multimap<String, String> inputFiles, Path outPutDir) throws Exception {
24+
public void runExperiment(Multimap<String, String> inputFiles,Path outPutDir) throws Exception {
2525
Collection<String> archDescPathCollection = inputFiles.get("architecture");
2626
Collection<String> expDescPathCollection = inputFiles.get("experiment");
2727
Collection<String> scenarioPathCollection = inputFiles.get("scenario");
28+
Collection<String> mtlPathCollection = inputFiles.get("mtl");
2829
List<String> load = inputFiles.get("load").stream().toList();
2930

3031

@@ -35,6 +36,7 @@ public void runExperiment(Multimap<String, String> inputFiles, Path outPutDir) t
3536
}
3637
String expDescPath = null;
3738
String scenarioPath = null;
39+
String mtlPath = null;
3840

3941
String archDescPath = archDescPathCollection.iterator().next();
4042
if (expDescPathCollection.iterator().hasNext()) {
@@ -49,12 +51,15 @@ public void runExperiment(Multimap<String, String> inputFiles, Path outPutDir) t
4951
adjustWorkloadPaths(load, scenarioPath);
5052
}
5153
}
54+
if (mtlPathCollection.iterator().hasNext()) {
55+
mtlPath = mtlPathCollection.iterator().next();
56+
}
5257

5358
ExperimentStartupConfig config = new ExperimentStartupConfig(archDescPath, expDescPath,
5459
scenarioPath,null, outPutDir.toString(), false,
55-
false, true);
60+
false, true, mtlPath);
5661
try {
57-
Experiment experiment = new ExperimentCreator().createSimulationExperiment(config);
62+
Experiment experiment = new ExperimentCreator().createSimulationExperiment(config);
5863
experiment.start();
5964
experiment.finish();
6065
// TODO check whether we need to reset the generator;
@@ -66,8 +71,8 @@ public void runExperiment(Multimap<String, String> inputFiles, Path outPutDir) t
6671
throw new Exception(e.getMessage());
6772
}
6873
}
69-
}
7074

75+
}
7176

7277
private void adjustWorkloadPaths(List<String> workloadsPath, String experimentFilePath)
7378
throws IOException {
@@ -77,7 +82,7 @@ private void adjustWorkloadPaths(List<String> workloadsPath, String experimentFi
7782
String workloadFileName;
7883
for(String path : workloadsPath) {
7984
workloadFileName = FilenameUtils.getName(path);
80-
content = content.replace(workloadFileName, isWindows ? path.replace("\\","\\\\") : path);
85+
content = content.replace(workloadFileName, IS_WINDOWS ? path.replace("\\","\\\\") : path);
8186
}
8287
Files.write(experimentFile, content.getBytes());
8388
}

restAPI/src/main/java/restAPI/util/ReportDataPointsManipulator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
public class ReportDataPointsManipulator {
2020

2121
private static final String[] DISCRETE_VALUED_METRICS = {"Requests_InSystem", "Requests_NotComputed",
22-
"Requests_WaitingForDependencies", "SendOff_Internal_Requests"};
22+
"Requests_WaitingForDependencies", "SendOff_Internal_Requests", "FailedRequests", "SuccessfulRequests",
23+
"Load."};
2324
private static final String[] CONTINUOUS_VALUED_METRICS = {"RelativeUtilization", "Utilization",
2425
"UtilizationBinned", "NL_latency", "ResponseTimes"};
2526

@@ -67,7 +68,7 @@ private static String createColumnNameFromFileName(String fileName) {
6768
String regex = ".+\\[.+\\].+\\.csv";
6869
if (fileName.matches(regex)) {
6970
String serviceName = StringUtils.substringBetween(fileName, "[", "]")
70-
.replace('#','_');
71+
.replaceAll("[#-]","_");
7172
String metricName = StringUtils.substringBetween(fileName, "]", ".csv");
7273
return String.format("%s%s",serviceName, metricName);
7374
} else {

0 commit comments

Comments
 (0)