Skip to content

Commit f8bc32f

Browse files
committed
Minor refactoring and cleanup
1 parent 15ee084 commit f8bc32f

9 files changed

Lines changed: 124 additions & 43 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018-2021 The Chronos Project
3+
Copyright (c) 2018-2022 The Chronos Project
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Reference implementation of an agent library written in Java. This library handl
55
## Getting Started
66

77
* Chronos Agent is published to Maven Central. Make sure that you have `mavenCentral()` to the `repositories` in your gradle build file.
8-
* Add `implementation group: 'org.chronos-eaas', name: 'chronos-agent', version: '2.3.4'` to your `dependencies`.
8+
* Add `implementation group: 'org.chronos-eaas', name: 'chronos-agent', version: '2.3.5'` to your `dependencies`.
99
* Extend the `AbstractChronosAgent` class, call `YourClass.start()` in your `main` method, and you are good to go!
1010
> Assuming that you already have a running [Chronos Control](https://github.com/Chronos-EaaS/Chronos-Control/) instance
1111

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ plugins {
44
id 'signing'
55
id 'idea'
66
id 'maven-publish'
7-
//id 'com.github.johnrengelman.shadow' version '7.1.0'
87
id 'io.freefair.lombok' version '6.4.3'
98
}
109

@@ -30,7 +29,7 @@ java {
3029

3130

3231
dependencies {
33-
api group: 'com.konghq', name: 'unirest-java', version: '3.13.10'
32+
implementation group: 'com.konghq', name: 'unirest-java', version: '3.13.10'
3433
implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'
3534

3635
implementation group: 'commons-validator', name: 'commons-validator', version: '1.7'

src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
The MIT License (MIT)
33
4-
Copyright (c) 2018 Databases and Information Systems Research Group, University of Basel, Switzerland
4+
Copyright (c) 2018-2022 The Chronos Project
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal
@@ -45,7 +45,6 @@ of this software and associated documentation files (the "Software"), to deal
4545
import java.util.TimerTask;
4646
import java.util.concurrent.ConcurrentHashMap;
4747
import java.util.concurrent.TimeUnit;
48-
import kong.unirest.json.JSONObject;
4948
import lombok.extern.slf4j.Slf4j;
5049
import net.lingala.zip4j.ZipFile;
5150
import net.lingala.zip4j.model.ZipParameters;
@@ -59,10 +58,7 @@ of this software and associated documentation files (the "Software"), to deal
5958
* uploading of the results of a job provided by a Chronos HTTP API.
6059
*
6160
* If problems with SSL occur: https://confluence.atlassian.com/kb/connecting-to-ssl-services-802171215.html
62-
* Or use non secure connections.
63-
*
64-
* @author Marco Vogt (marco.vogt@unibas.ch)
65-
* @author Alexander Stiemer (alexander.stiemer@unibas.ch)
61+
* Or use non-secure connections.
6662
*/
6763
@Slf4j
6864
public abstract class AbstractChronosAgent extends Thread {
@@ -524,20 +520,7 @@ protected abstract Object clean(
524520
*/
525521
protected void saveResults( final Properties executionResults, final File outputDirectory ) throws IllegalStateException {
526522
final File resultsJsonFile = new File( outputDirectory, "results.json" );
527-
528-
JSONObject resultsJsonObject = new JSONObject();
529-
for ( Map.Entry<Object, Object> result : executionResults.entrySet() ) {
530-
resultsJsonObject.put( result.getKey().toString(), result.getValue().toString() );
531-
}
532-
533-
try ( PrintWriter out = new PrintWriter( resultsJsonFile, UTF_8.name() ) ) {
534-
out.println( resultsJsonObject.toString() );
535-
out.flush();
536-
} catch ( FileNotFoundException ex ) {
537-
throw new IllegalStateException( ex );
538-
} catch ( UnsupportedEncodingException ex ) {
539-
throw new RuntimeException( ex );
540-
}
523+
Utils.saveResults( executionResults, resultsJsonFile );
541524
}
542525

543526

src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosException.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2018-2022 The Chronos Project
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
125
package ch.unibas.dmi.dbis.chronos.agent;
226

327

428
public class ChronosException extends Exception {
529

630
/**
7-
* Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to {@link #initCause}.
31+
* Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently be
32+
* initialized by a call to {@link #initCause}.
833
*
934
* @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method.
1035
*/
@@ -14,8 +39,8 @@ public ChronosException( String message ) {
1439

1540

1641
/**
17-
* Constructs a new exception with the specified detail message and cause.
18-
* Note that the detail message associated with {@code cause} is <i>not</i> automatically incorporated in this exception's detail message.
42+
* Constructs a new exception with the specified detail message and cause. Note that the detail message associated
43+
* with {@code cause} is <i>not</i> automatically incorporated in this exception's detail message.
1944
*
2045
* @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
2146
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A "null" value is permitted, and indicates that the cause is nonexistent or unknown.)
@@ -26,8 +51,9 @@ public ChronosException( String message, Throwable cause ) {
2651

2752

2853
/**
29-
* Constructs a new exception with the specified cause and a detail message of "(cause==null ? null : cause.toString())" (which typically contains the class and detail message of "cause").
30-
* This constructor is useful for exceptions that are little more than wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}).
54+
* Constructs a new exception with the specified cause and a detail message of "(cause==null ? null : cause.toString())"
55+
* (which typically contains the class and detail message of "cause"). This constructor is useful for exceptions that
56+
* are little more than wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}).
3157
*
3258
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A "null" value is permitted, and indicates that the cause is nonexistent or unknown.)
3359
*/

src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
The MIT License (MIT)
33
4-
Copyright (c) 2018 Databases and Information Systems Research Group, University of Basel, Switzerland
4+
Copyright (c) 2018-2022 The Chronos Project
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal
@@ -53,10 +53,6 @@ of this software and associated documentation files (the "Software"), to deal
5353
import org.apache.commons.validator.routines.InetAddressValidator;
5454

5555

56-
/**
57-
* @author Alexander Stiemer (alexander.stiemer@unibas.ch)
58-
* @author Marco Vogt (marco.vogt@unibas.ch)
59-
*/
6056
@Slf4j
6157
public class ChronosHttpClient {
6258

src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosJob.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
The MIT License (MIT)
33
4-
Copyright (c) 2018 Databases and Information Systems Research Group, University of Basel, Switzerland
4+
Copyright (c) 2018-2022 The Chronos Project
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal
@@ -48,9 +48,6 @@ of this software and associated documentation files (the "Software"), to deal
4848

4949
/**
5050
* Representation of a Job of the Chronos System.
51-
*
52-
* @author Alexander Stiemer (alexander.stiemer@unibas.ch)
53-
* @author Marco Vogt (marco.vogt@unibas.ch)
5451
*/
5552
public class ChronosJob implements Serializable {
5653

src/main/java/ch/unibas/dmi/dbis/chronos/agent/ExecutionException.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2018-2022 The Chronos Project
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
125
package ch.unibas.dmi.dbis.chronos.agent;
226

327

428
public class ExecutionException extends Exception {
529

630
/**
7-
* Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to {@link #initCause}.
31+
* Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently be
32+
* initialized by a call to {@link #initCause}.
833
*
934
* @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method.
1035
*/
@@ -14,8 +39,8 @@ public ExecutionException( String message ) {
1439

1540

1641
/**
17-
* Constructs a new exception with the specified detail message and cause.
18-
* Note that the detail message associated with {@code cause} is <i>not</i> automatically incorporated in this exception's detail message.
42+
* Constructs a new exception with the specified detail message and cause. Note that the detail message associated with
43+
* {@code cause} is <i>not</i> automatically incorporated in this exception's detail message.
1944
*
2045
* @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
2146
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A "null" value is permitted, and indicates that the cause is nonexistent or unknown.)
@@ -26,8 +51,9 @@ public ExecutionException( String message, Throwable cause ) {
2651

2752

2853
/**
29-
* Constructs a new exception with the specified cause and a detail message of "(cause==null ? null : cause.toString())" (which typically contains the class and detail message of "cause").
30-
* This constructor is useful for exceptions that are little more than wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}).
54+
* Constructs a new exception with the specified cause and a detail message of "(cause==null ? null : cause.toString())"
55+
* (which typically contains the class and detail message of "cause"). This constructor is useful for exceptions that
56+
* are little more than wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}).
3157
*
3258
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A "null" value is permitted, and indicates that the cause is nonexistent or unknown.)
3359
*/
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2018-2022 The Chronos Project
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
package ch.unibas.dmi.dbis.chronos.agent;
26+
27+
import java.io.File;
28+
import java.io.FileNotFoundException;
29+
import java.io.PrintWriter;
30+
import java.io.UnsupportedEncodingException;
31+
import java.nio.charset.StandardCharsets;
32+
import java.util.Map;
33+
import java.util.Properties;
34+
import kong.unirest.json.JSONObject;
35+
36+
class Utils {
37+
38+
static void saveResults( final Properties executionResults, final File resultsJsonFile ) throws IllegalStateException {
39+
JSONObject resultsJsonObject = new JSONObject();
40+
for ( Map.Entry<Object, Object> result : executionResults.entrySet() ) {
41+
resultsJsonObject.put( result.getKey().toString(), result.getValue().toString() );
42+
}
43+
44+
try ( PrintWriter out = new PrintWriter( resultsJsonFile, StandardCharsets.UTF_8.name() ) ) {
45+
out.println( resultsJsonObject );
46+
out.flush();
47+
} catch ( FileNotFoundException ex ) {
48+
throw new IllegalStateException( ex );
49+
} catch ( UnsupportedEncodingException ex ) {
50+
throw new RuntimeException( ex );
51+
}
52+
}
53+
54+
}

0 commit comments

Comments
 (0)