From: Mateusz Warowny Date: Wed, 8 Jul 2020 14:27:01 +0000 (+0100) Subject: JAL-3683 retrieve job status to output stream X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Ffeature%2FJAL-3686_slivka_client_js_update;p=jalview.git JAL-3683 retrieve job status to output stream --- diff --git a/src/jalview/ws/slivkaws/SlivkaWSInstance.java b/src/jalview/ws/slivkaws/SlivkaWSInstance.java index a21354e..33c1205 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaWSInstance.java @@ -13,10 +13,10 @@ import jalview.ws.params.ParamManager; import jalview.ws.params.WsParamSetI; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; 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; @@ -130,44 +130,37 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters { List files = client.getJobResults(job.getJobId()); Optional logFile = files.stream() - .filter(f -> f.getLabel().equals("log")).findFirst(); + .filter(f -> f.getLabel().equals("log")).findFirst(); boolean newContent = false; if (logFile.isPresent()) { - InputStream stream = logFile.get().getContent(); - long nextChunk = stream.skip(job.getNextChunk()); - int len = appendJobStatus(job, stream); - job.setnextChunk(nextChunk + len); - newContent |= len > 0; + ByteArrayOutputStream output = new ByteArrayOutputStream(); + logFile.get().writeTo(output); + if (output.size() > job.getNextChunk()) + { + newContent = true; + job.setStatus(output.toString("UTF-8")); + job.setnextChunk(output.size()); + } } if (failedStates.contains(job.getJobState())) { Optional errLogFile = files.stream() - .filter(f -> f.getLabel().equals("error-log")).findFirst(); + .filter(f -> f.getLabel().equals("error-log")).findFirst(); if (errLogFile.isPresent()) { - newContent |= appendJobStatus(job, errLogFile.get().getContent()) > 0; + ByteArrayOutputStream output = new ByteArrayOutputStream(); + errLogFile.get().writeTo(output); + if (output.size() > 0) + { + newContent = true; + job.setStatus(job.getStatus() + "\n" + output.toString("UTF-8")); + } } } return newContent; } - 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) {