Skip to content

Commit

Permalink
Minor refactoring and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Jun 7, 2022
1 parent 15ee084 commit f8bc32f
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 43 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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 ([email protected])
* @author Alexander Stiemer ([email protected])
* Or use non-secure connections.
*/
@Slf4j
public abstract class AbstractChronosAgent extends Thread {
Expand Down Expand Up @@ -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<Object, Object> 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 );
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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 <i>not</i> 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 <i>not</i> 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.)
Expand All @@ -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.)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ([email protected])
* @author Marco Vogt ([email protected])
*/
@Slf4j
public class ChronosHttpClient {

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ([email protected])
* @author Marco Vogt ([email protected])
*/
public class ChronosJob implements Serializable {

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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 <i>not</i> 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 <i>not</i> 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.)
Expand All @@ -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.)
*/
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/ch/unibas/dmi/dbis/chronos/agent/Utils.java
Original file line number Diff line number Diff line change
@@ -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<Object, Object> 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 );
}
}

}

0 comments on commit f8bc32f

Please sign in to comment.