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;
stateMap.put(JobState.ERROR, WsJob.JobState.SERVERERROR);
stateMap.put(JobState.UNKNOWN, WsJob.JobState.UNKNOWN);
}
+ protected final Set<WsJob.JobState> 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)
{
}
@Override
- public final boolean updateJobProgress(WsJob job)
+ public final boolean updateJobProgress(WsJob job) throws IOException
{
+ Optional<RemoteFile> 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<RemoteFile> 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)
{