Added functions to also get the workflow execution's results with a pluggable results parser, ref. impl. for `Conductor`
parent
3f01b590f2
commit
a49e030d71
@ -0,0 +1,48 @@
|
||||
package org.gcube.event.publisher;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ConductorResultsParser implements ResultsParser {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(ConductorResultsParser.class);
|
||||
|
||||
public ConductorResultsParser() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventStatus parseResults(JSONObject results) {
|
||||
EventStatus eventStatus = null;
|
||||
if (results != null) {
|
||||
JSONObject input = (JSONObject) results.get("input");
|
||||
JSONObject output = (JSONObject) results.get("output");
|
||||
switch ((String) results.get("status")) {
|
||||
case "COMPLETED":
|
||||
eventStatus = EventStatus.COMPLETED(input, output);
|
||||
break;
|
||||
case "FAILED":
|
||||
eventStatus = EventStatus.FAILED(input, output);
|
||||
break;
|
||||
case "NOT_FOUND":
|
||||
eventStatus = EventStatus.NOT_FOUND();
|
||||
break;
|
||||
case "PAUSED":
|
||||
eventStatus = EventStatus.PAUSED(input);
|
||||
break;
|
||||
case "RUNNING":
|
||||
eventStatus = EventStatus.RUNNING(input);
|
||||
break;
|
||||
case "TERMINATED":
|
||||
eventStatus = EventStatus.TERMINATED(input, output);
|
||||
break;
|
||||
default:
|
||||
eventStatus = EventStatus.NOT_FOUND();
|
||||
}
|
||||
} else {
|
||||
logger.warn("Nothing to parse since JSON object is null");
|
||||
}
|
||||
return eventStatus;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,13 @@
|
||||
package org.gcube.event.publisher;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public interface EventSender {
|
||||
|
||||
void send(Event event);
|
||||
|
||||
String sendAndGetResult(Event event);
|
||||
|
||||
JSONObject retrive(String id);
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package org.gcube.event.publisher;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class EventStatus {
|
||||
|
||||
public enum Status {
|
||||
RUNNING, COMPLETED, FAILED, TIMED_OUT, TERMINATED, PAUSED, NOT_FOUND;
|
||||
}
|
||||
|
||||
public static EventStatus RUNNING(JSONObject input) {
|
||||
return new EventStatus(Status.RUNNING, input);
|
||||
}
|
||||
|
||||
public static EventStatus COMPLETED(JSONObject input, JSONObject output) {
|
||||
return new EventStatus(Status.COMPLETED, input, output);
|
||||
}
|
||||
|
||||
public static EventStatus FAILED(JSONObject input, JSONObject output) {
|
||||
return new EventStatus(Status.FAILED, input, output);
|
||||
}
|
||||
|
||||
public static EventStatus TIMED_OUT(JSONObject input) {
|
||||
return new EventStatus(Status.TIMED_OUT, input);
|
||||
}
|
||||
|
||||
public static EventStatus TERMINATED(JSONObject input, JSONObject output) {
|
||||
return new EventStatus(Status.TERMINATED, input, output);
|
||||
}
|
||||
|
||||
public static EventStatus PAUSED(JSONObject input) {
|
||||
return new EventStatus(Status.PAUSED, input);
|
||||
}
|
||||
|
||||
public static EventStatus NOT_FOUND() {
|
||||
return new EventStatus(Status.NOT_FOUND);
|
||||
}
|
||||
|
||||
private Status status;
|
||||
private JSONObject input;
|
||||
private JSONObject output;
|
||||
|
||||
private EventStatus(Status status) {
|
||||
this(status, null);
|
||||
}
|
||||
|
||||
private EventStatus(Status status, JSONObject input) {
|
||||
this(status, input, null);
|
||||
}
|
||||
|
||||
private EventStatus(Status status, JSONObject input, JSONObject output) {
|
||||
setStatus(status);
|
||||
setInput(input);
|
||||
setOutput(output);
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setInput(JSONObject input) {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public JSONObject getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
public void setOutput(JSONObject output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public JSONObject getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[%s]\ninput: %s\noutput: %s", status, input != null ? input.toJSONString() : "<No input>",
|
||||
output != null ? output.toJSONString() : "<No output>");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package org.gcube.event.publisher;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public interface ResultsParser {
|
||||
|
||||
EventStatus parseResults(JSONObject results);
|
||||
|
||||
}
|
Loading…
Reference in New Issue