-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from mattflax/rre_external_file
Make server evaluation handling more generic
- Loading branch information
Showing
9 changed files
with
367 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...lugin/src/main/java/io/sease/rre/maven/plugin/report/formats/impl/UrlRREOutputFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.sease.rre.maven.plugin.report.formats.impl; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.sease.rre.maven.plugin.report.RREMavenReport; | ||
import io.sease.rre.maven.plugin.report.domain.EvaluationMetadata; | ||
import io.sease.rre.maven.plugin.report.formats.OutputFormat; | ||
import okhttp3.*; | ||
|
||
import java.io.File; | ||
import java.util.Locale; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* RRE server implementation of OutputFormat that sends a file URL to the | ||
* server, rather than bundling the whole evaluation output in one request. | ||
* | ||
* @author Matt Pearce ([email protected]) | ||
*/ | ||
public class UrlRREOutputFormat implements OutputFormat { | ||
|
||
@Override | ||
public void writeReport(JsonNode data, EvaluationMetadata metadata, Locale locale, RREMavenReport plugin) { | ||
try { | ||
Request request = new Request.Builder() | ||
.url(requireNonNull(HttpUrl.parse(plugin.getEndpoint() + "/evaluation"))) | ||
.post(RequestBody.create(MediaType.parse("application/json"), | ||
"{ \"url\": \"" + new File(plugin.getEvaluationFile()).toURI().toURL() + "\" }")) | ||
.build(); | ||
|
||
try (final Response response = new OkHttpClient().newCall(request).execute()) { | ||
if (response.code() != 200) { | ||
plugin.getLog().error("Exception while communicating with RREServer. Return code was: " + response.code()); | ||
} else { | ||
plugin.getLog().info("Evaluation data has been correctly sent to RRE Server located at " + plugin.getEndpoint()); | ||
} | ||
} | ||
} catch (final Exception exception) { | ||
plugin.getLog().error("RRE: Unable to connect to RRE Server. See below for further details.", exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
rre-server/src/main/java/io/sease/rre/server/services/EvaluationHandlerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.sease.rre.server.services; | ||
|
||
/** | ||
* Exception thrown during evaluation handling. | ||
* | ||
* @author Matt Pearce ([email protected]) | ||
*/ | ||
public class EvaluationHandlerException extends Exception { | ||
|
||
public EvaluationHandlerException() { | ||
} | ||
|
||
public EvaluationHandlerException(String message) { | ||
super(message); | ||
} | ||
|
||
public EvaluationHandlerException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public EvaluationHandlerException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
rre-server/src/main/java/io/sease/rre/server/services/EvaluationHandlerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.sease.rre.server.services; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.sease.rre.core.domain.Evaluation; | ||
import io.sease.rre.server.domain.EvaluationMetadata; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* An EvaluationHandlerService can be used to process an incoming evaluation | ||
* update request. It should extract the relevant details from the request, | ||
* and use them to build an Evaluation object that can be used to populate | ||
* the dashboard. | ||
* | ||
* The {@link #processEvaluationRequest(JsonNode)} method should ideally | ||
* return as quickly as possible, to avoid blocking the sender of the incoming | ||
* request. The evaluation data can then be retrieved using {@link #getEvaluation()} | ||
* where the evaluation contains the most recently processed data. | ||
* | ||
* @author Matt Pearce ([email protected]) | ||
*/ | ||
@Service | ||
public interface EvaluationHandlerService { | ||
|
||
/** | ||
* Update the currently held evaluation data. This may be done | ||
* asynchronously - the method should return as quickly as possible. | ||
* | ||
* @param requestData incoming data giving details of evaluation. | ||
* @throws EvaluationHandlerException if the data cannot be processed. | ||
*/ | ||
void processEvaluationRequest(final JsonNode requestData) throws EvaluationHandlerException; | ||
|
||
/** | ||
* Get the current evaluation data. | ||
* | ||
* @return the Evaluation. | ||
*/ | ||
Evaluation getEvaluation(); | ||
|
||
/** | ||
* Get the current evaluation metadata. | ||
* | ||
* @return the evaluation metadata. | ||
*/ | ||
EvaluationMetadata getEvaluationMetadata(); | ||
} |
Oops, something went wrong.