Skip to content

Commit 0dd2e77

Browse files
committed
Merged changes with master branch.
2 parents 8e0abee + 865c973 commit 0dd2e77

30 files changed

+996
-466
lines changed

.github/workflows/maven.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Java CI with Maven
10+
11+
on:
12+
push:
13+
branches: [ "master" ]
14+
pull_request:
15+
branches: [ "master" ]
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Set up JDK 17
25+
uses: actions/setup-java@v3
26+
with:
27+
java-version: '17'
28+
distribution: 'temurin'
29+
cache: maven
30+
- name: Compile project
31+
run: mvn clean compile -DskipTests=true -Dmaven.javadoc.skip=true -B -V
32+
- name: Set up test environment
33+
run: make start-rabbit
34+
- name: Run tests
35+
run: mvn jacoco:prepare-agent test -Dmaven.javadoc.skip=true -B jacoco:report verify
36+
- name: Upload test results to Codacy
37+
run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r target/site/jacoco/jacoco.xml
38+
env:
39+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
40+
41+
- name: Update dependency graph
42+
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Build Status](https://github.com/hobbit-project/core/workflows/build/badge.svg) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/cab3efc1ece64aa4ba189e3e3d465ede)](https://www.codacy.com/manual/MichaelRoeder/core/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=hobbit-project/core&amp;utm_campaign=Badge_Grade) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/cab3efc1ece64aa4ba189e3e3d465ede)](https://www.codacy.com/manual/MichaelRoeder/core/dashboard?utm_source=github.com&utm_medium=referral&utm_content=hobbit-project/core&utm_campaign=Badge_Coverage)
1+
[![Java CI with Maven](https://github.com/hobbit-project/core/actions/workflows/maven.yml/badge.svg)](https://github.com/hobbit-project/core/actions/workflows/maven.yml)[![Codacy Badge](https://app.codacy.com/project/badge/Grade/cb81b2831ce84a4287ff588e83881b0a)](https://app.codacy.com/gh/hobbit-project/core/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/cb81b2831ce84a4287ff588e83881b0a)](https://app.codacy.com/gh/hobbit-project/core/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
22

33
# core
44
This library offers some main functionalities and utilities for the Hobbit platform project. For more information take a look at the project web page (<http://www.project-hobbit.eu>) or at the Hobbit platform project on github (<https://github.com/hobbit-project/platform>).
@@ -31,7 +31,7 @@ Docker container with RabbitMQ can be started using `./start_test_environment.sh
3131
<dependency>
3232
<groupId>org.hobbit</groupId>
3333
<artifactId>core</artifactId>
34-
<version>1.0.3</version>
34+
<version>1.0.22</version>
3535
</dependency>
3636
...
3737
</dependencies>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<plugin>
124124
<groupId>org.apache.maven.plugins</groupId>
125125
<artifactId>maven-javadoc-plugin</artifactId>
126-
<version>2.10.1</version>
126+
<version>3.6.3</version>
127127
<configuration>
128128
<show>private</show>
129129
<nohelp>true</nohelp>

src/main/java/org/hobbit/core/Commands.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ private Commands() {
3333
*/
3434
public static final byte SYSTEM_READY_SIGNAL = 1;
3535
/**
36-
* The signal sent by the benchmark controller to indicate that the
37-
* benchmark is ready.
36+
* The signal sent by the benchmark controller to indicate that the benchmark is
37+
* ready.
3838
*/
3939
public static final byte BENCHMARK_READY_SIGNAL = 2;
4040
/**
@@ -64,23 +64,19 @@ private Commands() {
6464

6565
public static final byte BENCHMARK_FINISHED_SIGNAL = 11;
6666
/**
67-
* Command used to ask a docker managing component to start a certain
68-
* container.
67+
* Command used to ask a docker managing component to start a certain container.
6968
* <p>
70-
* The command is followed by a String containing the following JSON data:
71-
* <br>
69+
* The command is followed by a String containing the following JSON data: <br>
7270
* <code>
7371
* {<br>"image": "image-to-run",<br> "type": "system|benchmark",<br> "parent":"parent-container-id"<br>}
7472
* </code>
7573
* </p>
7674
*/
7775
public static final byte DOCKER_CONTAINER_START = 12;
7876
/**
79-
* Command used to ask a docker managing component to stop a certain
80-
* container.
77+
* Command used to ask a docker managing component to stop a certain container.
8178
* <p>
82-
* The command is followed by a String containing the following JSON data:
83-
* <br>
79+
* The command is followed by a String containing the following JSON data: <br>
8480
* <code>
8581
* {<br>"containerId": "container-to-stop"<br>}
8682
* </code>
@@ -95,8 +91,27 @@ private Commands() {
9591
public static final byte DOCKER_CONTAINER_TERMINATED = 16;
9692

9793
public static final byte START_BENCHMARK_SIGNAL = 17;
98-
94+
9995
public static final byte REQUEST_SYSTEM_RESOURCES_USAGE = 18;
96+
/**
97+
* Command used to report an error that should be persisted as part of the
98+
* experiment result data.
99+
* <p>
100+
* The command is followed by a String containing the following JSON data: <br>
101+
* <code>
102+
* {<br>"containerId": "container reporting the error",
103+
* <br>"errorType": "IRI of the error type (optional)",
104+
* <br>"label": "A string that can be used as short label of an error (optional, the error type label will be used as default)"
105+
* <br>"description": "A string that can be used as a short description of an error (optional, the error type description will be used as default)"
106+
* <br>"details": "A string that contains details about the error, e.g., a stack trace (optional)."
107+
* <br>}
108+
* </code>
109+
* </p>
110+
* <p>
111+
* The {@link org.hobbit.core.data.ErrorData} class can be used to represent
112+
* this data as Java object.</p>
113+
*/
114+
public static final byte REPORT_ERROR = 19;
100115

101116
private static final ImmutableMap<Byte, String> ID_TO_COMMAND_NAME_MAP = generateMap();
102117

@@ -116,13 +131,14 @@ private static ImmutableMap<Byte, String> generateMap() {
116131
}
117132

118133
/**
119-
* Returns the name of the command if it is defined inside the {@link Commands} class or its id as String.
134+
* Returns the name of the command if it is defined inside the {@link Commands}
135+
* class or its id as String.
120136
*
121137
* @param command the command that should be transformed into a String
122138
* @return the name of the command or its id if the name is not known
123139
*/
124140
public static String toString(byte command) {
125-
Byte commandObject = new Byte(command);
141+
Byte commandObject = Byte.valueOf(command);
126142
if (Commands.ID_TO_COMMAND_NAME_MAP.containsKey(commandObject)) {
127143
return ID_TO_COMMAND_NAME_MAP.get(commandObject);
128144
} else {

src/main/java/org/hobbit/core/components/AbstractBenchmarkController.java

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -156,40 +156,38 @@ public void init() throws Exception {
156156

157157
@Override
158158
public void run() throws Exception {
159-
sendToCmdQueue(Commands.BENCHMARK_READY_SIGNAL);
160-
// wait for the start signal
161-
startBenchmarkMutex.acquire();
162-
executeBenchmark();
159+
try {
160+
sendToCmdQueue(Commands.BENCHMARK_READY_SIGNAL);
161+
// wait for the start signal
162+
startBenchmarkMutex.acquire();
163+
executeBenchmark();
164+
} catch (Exception e) {
165+
throw reportAndWrap(e);
166+
}
163167
}
164168

165169
protected abstract void executeBenchmark() throws Exception;
166170

167171
/**
168-
* Creates the given number of data generators using the given image name
169-
* and environment variables.
172+
* Creates the given number of data generators using the given image name and
173+
* environment variables.
170174
*
171-
* @param dataGeneratorImageName
172-
* name of the data generator Docker image
173-
* @param numberOfDataGenerators
174-
* number of generators that should be created
175-
* @param envVariables
176-
* environment variables for the data generators
175+
* @param dataGeneratorImageName name of the data generator Docker image
176+
* @param numberOfDataGenerators number of generators that should be created
177+
* @param envVariables environment variables for the data generators
177178
*/
178179
protected void createDataGenerators(String dataGeneratorImageName, int numberOfDataGenerators,
179180
String[] envVariables) {
180181
createGenerator(dataGeneratorImageName, numberOfDataGenerators, envVariables, dataGenContainerIds);
181182
}
182183

183184
/**
184-
* Creates the given number of task generators using the given image name
185-
* and environment variables.
185+
* Creates the given number of task generators using the given image name and
186+
* environment variables.
186187
*
187-
* @param taskGeneratorImageName
188-
* name of the task generator Docker image
189-
* @param numberOfTaskGenerators
190-
* number of generators that should be created
191-
* @param envVariables
192-
* environment variables for the task generators
188+
* @param taskGeneratorImageName name of the task generator Docker image
189+
* @param numberOfTaskGenerators number of generators that should be created
190+
* @param envVariables environment variables for the task generators
193191
*/
194192
protected void createTaskGenerators(String taskGeneratorImageName, int numberOfTaskGenerators,
195193
String[] envVariables) {
@@ -199,14 +197,10 @@ protected void createTaskGenerators(String taskGeneratorImageName, int numberOfT
199197
/**
200198
* Internal method for creating generator components.
201199
*
202-
* @param generatorImageName
203-
* name of the generator Docker image
204-
* @param numberOfGenerators
205-
* number of generators that should be created
206-
* @param envVariables
207-
* environment variables for the task generators
208-
* @param generatorIds
209-
* set of generator container names
200+
* @param generatorImageName name of the generator Docker image
201+
* @param numberOfGenerators number of generators that should be created
202+
* @param envVariables environment variables for the task generators
203+
* @param generatorIds set of generator container names
210204
*/
211205
private void createGenerator(String generatorImageName, int numberOfGenerators, String[] envVariables,
212206
Set<String> generatorIds) {
@@ -216,7 +210,8 @@ private void createGenerator(String generatorImageName, int numberOfGenerators,
216210
// NOTE: Count only includes generators created within this method call.
217211
variables[variables.length - 2] = Constants.GENERATOR_COUNT_KEY + "=" + numberOfGenerators;
218212
for (int i = 0; i < numberOfGenerators; ++i) {
219-
// At the start generatorIds is empty, and new generators are added to it immediately.
213+
// At the start generatorIds is empty, and new generators are added to it
214+
// immediately.
220215
// Current size of that set is used to make IDs for new generators.
221216
variables[variables.length - 1] = Constants.GENERATOR_ID_KEY + "=" + generatorIds.size();
222217
containerId = createContainer(generatorImageName, variables);
@@ -234,10 +229,9 @@ private void createGenerator(String generatorImageName, int numberOfGenerators,
234229
* Creates the evaluate module using the given image name and environment
235230
* variables.
236231
*
237-
* @param evalModuleImageName
238-
* name of the evaluation module image
239-
* @param envVariables
240-
* environment variables that should be given to the module
232+
* @param evalModuleImageName name of the evaluation module image
233+
* @param envVariables environment variables that should be given to the
234+
* module
241235
*/
242236
protected void createEvaluationModule(String evalModuleImageName, String[] envVariables) {
243237
envVariables = ArrayUtils.add(envVariables, Constants.HOBBIT_EXPERIMENT_URI_KEY + "=" + experimentUri);
@@ -263,10 +257,9 @@ protected void createEvaluationStorage() {
263257
* Creates the evaluate storage using the given image name and environment
264258
* variables.
265259
*
266-
* @param evalStorageImageName
267-
* name of the evaluation storage image
268-
* @param envVariables
269-
* environment variables that should be given to the component
260+
* @param evalStorageImageName name of the evaluation storage image
261+
* @param envVariables environment variables that should be given to the
262+
* component
270263
*/
271264
protected void createEvaluationStorage(String evalStorageImageName, String[] envVariables) {
272265
evalStoreContainerId = createContainer(evalStorageImageName, Constants.CONTAINER_TYPE_DATABASE, envVariables);
@@ -353,13 +346,12 @@ protected void waitForTaskGenToFinish() {
353346
}
354347

355348
/**
356-
* This method waits for the benchmarked system to terminate or times out
357-
* after the given amount of time (in milliseconds).
349+
* This method waits for the benchmarked system to terminate or times out after
350+
* the given amount of time (in milliseconds).
358351
*
359-
* @param maxWaitingTime
360-
* maximum waiting time in milliseconds
361-
* @return {@code true} if the system has been terminated or {@code false}
362-
* if the method timed out
352+
* @param maxWaitingTime maximum waiting time in milliseconds
353+
* @return {@code true} if the system has been terminated or {@code false} if
354+
* the method timed out
363355
*/
364356
protected boolean waitForSystemToFinish(long maxWaitingTime) {
365357
LOGGER.debug("Waiting for the benchmarked system to finish.");
@@ -422,8 +414,7 @@ protected void waitForEvalComponentsToFinish() {
422414
* Uses the given model as result model if the result model is
423415
* <code>null</code>. Else, the two models are merged.
424416
*
425-
* @param resultModel
426-
* the new result model
417+
* @param resultModel the new result model
427418
*/
428419
protected void setResultModel(Model resultModel) {
429420
try {
@@ -445,9 +436,9 @@ protected void setResultModel(Model resultModel) {
445436

446437
/**
447438
* Generates a default model containing an error code and the benchmark
448-
* parameters if no result model has been received from the evaluation
449-
* module until now. If the model already has been received, the error is
450-
* added to the existing model.
439+
* parameters if no result model has been received from the evaluation module
440+
* until now. If the model already has been received, the error is added to the
441+
* existing model.
451442
*/
452443
protected void generateErrorResultModel() {
453444
try {
@@ -469,8 +460,7 @@ protected void generateErrorResultModel() {
469460
}
470461

471462
/**
472-
* Adds the {@link #benchmarkParamModel} triples to the {@link #resultModel}
473-
* .
463+
* Adds the {@link #benchmarkParamModel} triples to the {@link #resultModel} .
474464
*/
475465
protected void addParametersToResultModel() {
476466
try {
@@ -480,8 +470,7 @@ protected void addParametersToResultModel() {
480470
}
481471
try {
482472
Resource experimentResource = resultModel.getResource(experimentUri);
483-
StmtIterator iterator = benchmarkParamModel.listStatements(
484-
HobbitExperiments.New, null, (RDFNode) null);
473+
StmtIterator iterator = benchmarkParamModel.listStatements(HobbitExperiments.New, null, (RDFNode) null);
485474
Statement statement;
486475
while (iterator.hasNext()) {
487476
statement = iterator.next();
@@ -495,8 +484,7 @@ protected void addParametersToResultModel() {
495484
/**
496485
* Sends the result RDF model to the platform controller.
497486
*
498-
* @param model
499-
* model containing the results
487+
* @param model model containing the results
500488
*/
501489
protected void sendResultModel(Model model) {
502490
try {
@@ -558,14 +546,12 @@ public void receiveCommand(byte command, byte[] data) {
558546
}
559547

560548
/**
561-
* This method handles messages from the command bus containing the
562-
* information that a container terminated. It checks whether the container
563-
* belongs to the current benchmark and whether it has to react.
549+
* This method handles messages from the command bus containing the information
550+
* that a container terminated. It checks whether the container belongs to the
551+
* current benchmark and whether it has to react.
564552
*
565-
* @param containerName
566-
* the name of the terminated container
567-
* @param exitCode
568-
* the exit code of the terminated container
553+
* @param containerName the name of the terminated container
554+
* @param exitCode the exit code of the terminated container
569555
*/
570556
protected void containerTerminated(String containerName, int exitCode) {
571557
if (dataGenContainerIds.contains(containerName)) {

0 commit comments

Comments
 (0)