From: Mateusz Warowny Date: Mon, 7 Oct 2019 15:14:58 +0000 (+0100) Subject: Jal-3066 Retrieve job log and error log from the server. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=959709cf53e1cb865a772b25b0ef62963a73a57b;p=jalview.git Jal-3066 Retrieve job log and error log from the server. --- diff --git a/j11lib/slivka-client.jar b/j11lib/slivka-client.jar index a8e499a..0ee279e 100644 Binary files a/j11lib/slivka-client.jar and b/j11lib/slivka-client.jar differ diff --git a/src/jalview/ws/slivkaws/SlivkaWSInstance.java b/src/jalview/ws/slivkaws/SlivkaWSInstance.java index 9aae388..a75046d 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaWSInstance.java @@ -10,10 +10,17 @@ import jalview.ws.params.ParamManager; import java.io.IOError; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Arrays; import java.util.EnumMap; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; import uk.ac.dundee.compbio.slivkaclient.FormValidationException; import uk.ac.dundee.compbio.slivkaclient.JobState; +import uk.ac.dundee.compbio.slivkaclient.RemoteFile; import uk.ac.dundee.compbio.slivkaclient.SlivkaClient; import uk.ac.dundee.compbio.slivkaclient.SlivkaService; import uk.ac.dundee.compbio.slivkaclient.ValidationException; @@ -37,6 +44,10 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters stateMap.put(JobState.ERROR, WsJob.JobState.SERVERERROR); stateMap.put(JobState.UNKNOWN, WsJob.JobState.UNKNOWN); } + protected final Set failedStates = new HashSet<>(Arrays.asList( + WsJob.JobState.INVALID, WsJob.JobState.BROKEN, WsJob.JobState.FAILED, + WsJob.JobState.SERVERERROR, WsJob.JobState.CANCELLED + )); public SlivkaWSInstance(SlivkaClient client, SlivkaService service, String action) { @@ -58,11 +69,44 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters } @Override - public final boolean updateJobProgress(WsJob job) + public final boolean updateJobProgress(WsJob job) throws IOException { + Optional logFile = client.getJobResults(job.getJobId()).stream() + .filter(f -> f.getLabel() == "log").findFirst(); + if (logFile.isPresent()) + { + InputStream stream = logFile.get().getContent(); + long nextChunk = stream.skip(job.getNextChunk()); + job.setnextChunk(nextChunk + appendJobStatus(job, stream)); + } + if (failedStates.contains(job.getJobState())) + { + Optional errLogFile = client.getJobResults(job.getJobId()).stream() + .filter(f -> f.getLabel() == "error-log").findFirst(); + if (errLogFile.isPresent()) + { + appendJobStatus(job, errLogFile.get().getContent()); + } + } return false; } + private int appendJobStatus(WsJob job, InputStream stream) throws IOException + { + StringBuilder builder = new StringBuilder(job.getStatus()); + InputStreamReader reader = new InputStreamReader(stream); + char[] buffer = new char[4096]; + int chunkLen = 0; + int len = 0; + while ((len = reader.read(buffer)) != -1) + { + chunkLen += len; + builder.append(buffer, 0, len); + } + job.setStatus(builder.toString()); + return chunkLen; + } + @Override public final boolean handleSubmitError(Throwable _lex, WsJob j, WebserviceInfo wsInfo) {