From f8bc32ff0a1f324495f86008ad33a5271c515238 Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Tue, 7 Jun 2022 11:41:17 +0200 Subject: [PATCH] Minor refactoring and cleanup --- LICENSE | 2 +- README.md | 2 +- build.gradle | 3 +- .../chronos/agent/AbstractChronosAgent.java | 23 ++------ .../dbis/chronos/agent/ChronosException.java | 36 +++++++++++-- .../dbis/chronos/agent/ChronosHttpClient.java | 6 +-- .../dmi/dbis/chronos/agent/ChronosJob.java | 5 +- .../chronos/agent/ExecutionException.java | 36 +++++++++++-- .../unibas/dmi/dbis/chronos/agent/Utils.java | 54 +++++++++++++++++++ 9 files changed, 124 insertions(+), 43 deletions(-) create mode 100644 src/main/java/ch/unibas/dmi/dbis/chronos/agent/Utils.java diff --git a/LICENSE b/LICENSE index 524fa1d..6efae62 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018-2021 The Chronos Project +Copyright (c) 2018-2022 The Chronos Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 97f5194..c5cc017 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Reference implementation of an agent library written in Java. This library handl ## Getting Started * Chronos Agent is published to Maven Central. Make sure that you have `mavenCentral()` to the `repositories` in your gradle build file. -* Add `implementation group: 'org.chronos-eaas', name: 'chronos-agent', version: '2.3.4'` to your `dependencies`. +* Add `implementation group: 'org.chronos-eaas', name: 'chronos-agent', version: '2.3.5'` to your `dependencies`. * Extend the `AbstractChronosAgent` class, call `YourClass.start()` in your `main` method, and you are good to go! > Assuming that you already have a running [Chronos Control](https://github.com/Chronos-EaaS/Chronos-Control/) instance diff --git a/build.gradle b/build.gradle index 146e3c4..6d4e7e6 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,6 @@ plugins { id 'signing' id 'idea' id 'maven-publish' - //id 'com.github.johnrengelman.shadow' version '7.1.0' id 'io.freefair.lombok' version '6.4.3' } @@ -30,7 +29,7 @@ java { dependencies { - api group: 'com.konghq', name: 'unirest-java', version: '3.13.10' + implementation group: 'com.konghq', name: 'unirest-java', version: '3.13.10' implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre' implementation group: 'commons-validator', name: 'commons-validator', version: '1.7' diff --git a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java index ef68eab..92fa147 100644 --- a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java +++ b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/AbstractChronosAgent.java @@ -1,7 +1,7 @@ /* The MIT License (MIT) -Copyright (c) 2018 Databases and Information Systems Research Group, University of Basel, Switzerland +Copyright (c) 2018-2022 The Chronos Project Permission is hereby granted, free of charge, to any person obtaining a copy 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 import java.util.TimerTask; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; -import kong.unirest.json.JSONObject; import lombok.extern.slf4j.Slf4j; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.model.ZipParameters; @@ -59,10 +58,7 @@ of this software and associated documentation files (the "Software"), to deal * uploading of the results of a job provided by a Chronos HTTP API. * * If problems with SSL occur: https://confluence.atlassian.com/kb/connecting-to-ssl-services-802171215.html - * Or use non secure connections. - * - * @author Marco Vogt (marco.vogt@unibas.ch) - * @author Alexander Stiemer (alexander.stiemer@unibas.ch) + * Or use non-secure connections. */ @Slf4j public abstract class AbstractChronosAgent extends Thread { @@ -524,20 +520,7 @@ protected abstract Object clean( */ protected void saveResults( final Properties executionResults, final File outputDirectory ) throws IllegalStateException { final File resultsJsonFile = new File( outputDirectory, "results.json" ); - - JSONObject resultsJsonObject = new JSONObject(); - for ( Map.Entry result : executionResults.entrySet() ) { - resultsJsonObject.put( result.getKey().toString(), result.getValue().toString() ); - } - - try ( PrintWriter out = new PrintWriter( resultsJsonFile, UTF_8.name() ) ) { - out.println( resultsJsonObject.toString() ); - out.flush(); - } catch ( FileNotFoundException ex ) { - throw new IllegalStateException( ex ); - } catch ( UnsupportedEncodingException ex ) { - throw new RuntimeException( ex ); - } + Utils.saveResults( executionResults, resultsJsonFile ); } diff --git a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosException.java b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosException.java index a6b6dca..1270fa1 100644 --- a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosException.java +++ b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosException.java @@ -1,10 +1,35 @@ +/* +The MIT License (MIT) + +Copyright (c) 2018-2022 The Chronos Project + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + package ch.unibas.dmi.dbis.chronos.agent; public class ChronosException extends Exception { /** - * 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}. + * 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}. * * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. */ @@ -14,8 +39,8 @@ public ChronosException( String message ) { /** - * Constructs a new exception with the specified detail message and cause. - * Note that the detail message associated with {@code cause} is not automatically incorporated in this exception's detail message. + * Constructs a new exception with the specified detail message and cause. Note that the detail message associated + * with {@code cause} is not automatically incorporated in this exception's detail message. * * @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method). * @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 ) { /** - * 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"). - * This constructor is useful for exceptions that are little more than wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}). + * 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"). This constructor is useful for exceptions that + * are little more than wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}). * * @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.) */ diff --git a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java index b499779..f40e2d2 100644 --- a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java +++ b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosHttpClient.java @@ -1,7 +1,7 @@ /* The MIT License (MIT) -Copyright (c) 2018 Databases and Information Systems Research Group, University of Basel, Switzerland +Copyright (c) 2018-2022 The Chronos Project Permission is hereby granted, free of charge, to any person obtaining a copy 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 import org.apache.commons.validator.routines.InetAddressValidator; -/** - * @author Alexander Stiemer (alexander.stiemer@unibas.ch) - * @author Marco Vogt (marco.vogt@unibas.ch) - */ @Slf4j public class ChronosHttpClient { diff --git a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosJob.java b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosJob.java index f04732b..c48acd3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosJob.java +++ b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ChronosJob.java @@ -1,7 +1,7 @@ /* The MIT License (MIT) -Copyright (c) 2018 Databases and Information Systems Research Group, University of Basel, Switzerland +Copyright (c) 2018-2022 The Chronos Project Permission is hereby granted, free of charge, to any person obtaining a copy 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 /** * Representation of a Job of the Chronos System. - * - * @author Alexander Stiemer (alexander.stiemer@unibas.ch) - * @author Marco Vogt (marco.vogt@unibas.ch) */ public class ChronosJob implements Serializable { diff --git a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ExecutionException.java b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ExecutionException.java index bb9e330..aec1d9e 100644 --- a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ExecutionException.java +++ b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/ExecutionException.java @@ -1,10 +1,35 @@ +/* +The MIT License (MIT) + +Copyright (c) 2018-2022 The Chronos Project + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + package ch.unibas.dmi.dbis.chronos.agent; public class ExecutionException extends Exception { /** - * 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}. + * 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}. * * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. */ @@ -14,8 +39,8 @@ public ExecutionException( String message ) { /** - * Constructs a new exception with the specified detail message and cause. - * Note that the detail message associated with {@code cause} is not automatically incorporated in this exception's detail message. + * Constructs a new exception with the specified detail message and cause. Note that the detail message associated with + * {@code cause} is not automatically incorporated in this exception's detail message. * * @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method). * @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 ) { /** - * 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"). - * This constructor is useful for exceptions that are little more than wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}). + * 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"). This constructor is useful for exceptions that + * are little more than wrappers for other throwables (for example, {@link java.security.PrivilegedActionException}). * * @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.) */ diff --git a/src/main/java/ch/unibas/dmi/dbis/chronos/agent/Utils.java b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/Utils.java new file mode 100644 index 0000000..5fa53fd --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/chronos/agent/Utils.java @@ -0,0 +1,54 @@ +/* +The MIT License (MIT) + +Copyright (c) 2018-2022 The Chronos Project + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + +package ch.unibas.dmi.dbis.chronos.agent; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.Properties; +import kong.unirest.json.JSONObject; + +class Utils { + + static void saveResults( final Properties executionResults, final File resultsJsonFile ) throws IllegalStateException { + JSONObject resultsJsonObject = new JSONObject(); + for ( Map.Entry result : executionResults.entrySet() ) { + resultsJsonObject.put( result.getKey().toString(), result.getValue().toString() ); + } + + try ( PrintWriter out = new PrintWriter( resultsJsonFile, StandardCharsets.UTF_8.name() ) ) { + out.println( resultsJsonObject ); + out.flush(); + } catch ( FileNotFoundException ex ) { + throw new IllegalStateException( ex ); + } catch ( UnsupportedEncodingException ex ) { + throw new RuntimeException( ex ); + } + } + +}