Merge branch 'feature/JAL-3686_slivka_client_js_update' into alpha/JAL-3066_Jalview_2...
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 9 Jul 2020 13:23:51 +0000 (14:23 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 9 Jul 2020 13:23:51 +0000 (14:23 +0100)
j11lib/slivka-client.jar
src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java
src/jalview/ws/slivkaws/SlivkaWSInstance.java

index 6c289d1..34d2de9 100644 (file)
Binary files a/j11lib/slivka-client.jar and b/j11lib/slivka-client.jar differ
index 925cd55..7a41431 100644 (file)
@@ -10,7 +10,6 @@ import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -24,7 +23,7 @@ public class SlivkaWSDiscoverer implements WSDiscovererI
 {
   private static final String SLIVKA_HOST_URLS = "SLIVKAHOSTURLS";
 
-  private static final String COMPBIO_SLIVKA = "https://www.compbio.dundee.ac.uk/slivka";
+  private static final String COMPBIO_SLIVKA = "https://www.compbio.dundee.ac.uk/slivka/";
 
   private static SlivkaWSDiscoverer instance = null;
 
@@ -121,14 +120,7 @@ public class SlivkaWSDiscoverer implements WSDiscovererI
     {
       Cache.log.info(url);
       SlivkaClient client;
-      try
-      {
-        client = new SlivkaClient(url);
-      } catch (URISyntaxException e)
-      {
-        e.printStackTrace();
-        continue;
-      }
+      client = new SlivkaClient(url);
       try
       {
         for (SlivkaService service : client.getServices())
@@ -241,8 +233,9 @@ public class SlivkaWSDiscoverer implements WSDiscovererI
     {
       List<?> services = new SlivkaClient(url).getServices();
       return services.isEmpty() ? STATUS_NO_SERVICES : STATUS_OK;
-    } catch (IOException | URISyntaxException e)
+    } catch (IOException e)
     {
+      Cache.log.error("Slivka could not retrieve services list", e);
       return STATUS_INVALID;
     }
   }
index fd89a2e..8a16edb 100644 (file)
@@ -15,10 +15,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;
@@ -122,7 +122,7 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters
         }
         else
         {
-          form.insert(fieldName, field.valueOf(arg.getValue()));
+          form.insert(fieldName, arg.getValue());
         }
       }
     }
@@ -146,44 +146,37 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters
   {
     List<RemoteFile> files = client.getJobResults(job.getJobId());
     Optional<RemoteFile> 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<RemoteFile> 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)
   {