Web services refactoring & bug fixing
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Fri, 17 Jun 2011 15:45:17 +0000 (15:45 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Fri, 17 Jun 2011 15:45:17 +0000 (15:45 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4281 e3abac25-378b-4346-85de-24260fe3988d

13 files changed:
webservices/compbio/ws/server/AAConWS.java
webservices/compbio/ws/server/ClustalWS.java
webservices/compbio/ws/server/DisemblWS.java
webservices/compbio/ws/server/GenericMetadataService.java [moved from webservices/compbio/ws/server/SAService.java with 50% similarity]
webservices/compbio/ws/server/GlobPlotWS.java
webservices/compbio/ws/server/IUPredWS.java
webservices/compbio/ws/server/JronnWS.java
webservices/compbio/ws/server/MafftWS.java
webservices/compbio/ws/server/ProbconsWS.java
webservices/compbio/ws/server/SequenceAnnotationService.java [new file with mode: 0644]
webservices/compbio/ws/server/ShutdownEngines.java
webservices/compbio/ws/server/TcoffeeWS.java
webservices/compbio/ws/server/_MsaService.java [new file with mode: 0644]

index 4cbebf2..d9fd54f 100644 (file)
@@ -19,7 +19,7 @@ import compbio.metadata.UnsupportedRuntimeException;
 import compbio.runner.conservation.AACon;\r
 \r
 @WebService(endpointInterface = "compbio.data.msa.SequenceAnnotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "AAConWS")\r
-public class AAConWS extends SAService<AACon>\r
+public class AAConWS extends SequenceAnnotationService<AACon>\r
                implements\r
                        SequenceAnnotation<AACon> {\r
 \r
index 22fad0c..61944de 100644 (file)
@@ -31,6 +31,7 @@ import compbio.data.sequence.FastaSequence;
 import compbio.engine.AsyncExecutor;\r
 import compbio.engine.Configurator;\r
 import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.SkeletalExecutable;\r
 import compbio.metadata.ChunkHolder;\r
 import compbio.metadata.JobStatus;\r
 import compbio.metadata.JobSubmissionException;\r
@@ -71,6 +72,9 @@ public class ClustalWS implements MsaWS<ClustalW> {
        ConfiguredExecutable<ClustalW> init(List<FastaSequence> dataSet)\r
                        throws JobSubmissionException {\r
                ClustalW clustal = new ClustalW();\r
+               clustal.setInput(SkeletalExecutable.INPUT)\r
+                               .setOutput(SkeletalExecutable.OUTPUT)\r
+                               .setError(SkeletalExecutable.ERROR);\r
                ConfiguredExecutable<ClustalW> confClust = Configurator\r
                                .configureExecutable(clustal, dataSet);\r
                return confClust;\r
index 059695f..f609143 100644 (file)
@@ -17,7 +17,7 @@ import compbio.metadata.WrongParameterException;
 import compbio.runner.disorder.Disembl;\r
 \r
 @WebService(endpointInterface = "compbio.data.msa.SequenceAnnotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "DisemblWS")\r
-public class DisemblWS extends SAService<Disembl>\r
+public class DisemblWS extends SequenceAnnotationService<Disembl>\r
                implements\r
                        SequenceAnnotation<Disembl> {\r
 \r
@@ -5,7 +5,6 @@ import java.util.List;
 import org.apache.log4j.Logger;\r
 \r
 import compbio.data.sequence.FastaSequence;\r
-import compbio.data.sequence.ScoreManager;\r
 import compbio.engine.Configurator;\r
 import compbio.engine.client.ConfiguredExecutable;\r
 import compbio.engine.client.Executable;\r
@@ -14,41 +13,24 @@ import compbio.metadata.ChunkHolder;
 import compbio.metadata.JobStatus;\r
 import compbio.metadata.JobSubmissionException;\r
 import compbio.metadata.Limit;\r
-import compbio.metadata.LimitExceededException;\r
 import compbio.metadata.LimitsManager;\r
-import compbio.metadata.Option;\r
-import compbio.metadata.Preset;\r
 import compbio.metadata.PresetManager;\r
-import compbio.metadata.ResultNotAvailableException;\r
 import compbio.metadata.RunnerConfig;\r
-import compbio.metadata.UnsupportedRuntimeException;\r
-import compbio.metadata.WrongParameterException;\r
 import compbio.runner.Util;\r
-import compbio.runner.conservation.AACon;\r
 \r
-/**\r
- * Common methods for all SequenceAnnotation web services\r
- * \r
- * @author pvtroshin\r
- * \r
- * @param <T>\r
- * \r
- * @version 1.0 June 2011\r
- * @since 2.0\r
- */\r
-public abstract class SAService<T> {\r
+public abstract class GenericMetadataService<T> {\r
 \r
        private final RunnerConfig<T> aaconOptions;\r
        private final PresetManager<T> aaconPresets;\r
        private final LimitsManager<T> limitMan;\r
        private SkeletalExecutable<T> exec;\r
-       private final Logger log;\r
+       final Logger log;\r
 \r
        /*\r
         * FIXME - instances of the Runner (?) and their types should be defined in\r
         * Executable IF\r
         */\r
-       SAService(SkeletalExecutable<T> exec, Logger log) {\r
+       GenericMetadataService(SkeletalExecutable<T> exec, Logger log) {\r
                assert log != null;\r
                assert exec != null;\r
                this.log = log;\r
@@ -73,16 +55,12 @@ public abstract class SAService<T> {
                        log.error(e.getLocalizedMessage(), e);\r
                        throw new JobSubmissionException(e.getLocalizedMessage(), e);\r
                }\r
-               exec.setInput(SkeletalExecutable.INPUT).setOutput(\r
-                               SkeletalExecutable.OUTPUT);\r
+               exec.setInput(SkeletalExecutable.INPUT)\r
+                               .setOutput(SkeletalExecutable.OUTPUT)\r
+                               .setError(SkeletalExecutable.ERROR);\r
                return Configurator.configureExecutable(exec, sequences);\r
        }\r
 \r
-       public ScoreManager getAnnotation(String jobId)\r
-                       throws ResultNotAvailableException {\r
-               return WSUtil.getAnnotation(jobId, log);\r
-       }\r
-\r
        public boolean cancelJob(String jobId) {\r
                WSUtil.validateJobId(jobId);\r
                return WSUtil.cancelJob(jobId);\r
@@ -113,45 +91,6 @@ public abstract class SAService<T> {
                return aaconOptions;\r
        }\r
 \r
-       public String analize(List<FastaSequence> sequences)\r
-                       throws UnsupportedRuntimeException, LimitExceededException,\r
-                       JobSubmissionException {\r
-               WSUtil.validateFastaInput(sequences);\r
-               ConfiguredExecutable<T> confIUPred = init(sequences);\r
-               return WSUtil.analize(sequences, confIUPred, log, "analize",\r
-                               getLimit(""));\r
-       }\r
-\r
-       public String customAnalize(List<FastaSequence> sequences,\r
-                       List<Option<T>> options) throws UnsupportedRuntimeException,\r
-                       LimitExceededException, JobSubmissionException,\r
-                       WrongParameterException {\r
-               WSUtil.validateAAConInput(sequences);\r
-               ConfiguredExecutable<T> confAACon = init(sequences);\r
-               // Could not do that! Space separated values\r
-               // will all be treated as keys! thus duplicates removed\r
-               // String params = cbuilder.getCommand();\r
-               List<String> params = WSUtil.getCommands(options,\r
-                               AACon.KEY_VALUE_SEPARATOR);\r
-               confAACon.addParameters(params);\r
-               return WSUtil.analize(sequences, confAACon, log, "customAnalize",\r
-                               getLimit(""));\r
-       }\r
-\r
-       public String presetAnalize(List<FastaSequence> sequences, Preset<T> preset)\r
-                       throws UnsupportedRuntimeException, LimitExceededException,\r
-                       JobSubmissionException, WrongParameterException {\r
-               WSUtil.validateAAConInput(sequences);\r
-               if (preset == null) {\r
-                       throw new WrongParameterException("Preset must be provided!");\r
-               }\r
-               ConfiguredExecutable<T> confAAcon = init(sequences);\r
-               confAAcon.addParameters(preset.getOptions());\r
-               Limit<T> limit = getLimit(preset.getName());\r
-               return WSUtil\r
-                               .analize(sequences, confAAcon, log, "presetAnalize", limit);\r
-       }\r
-\r
        /**\r
         * Assume statistics is not supported\r
         * \r
index e7a76ec..5ed6331 100644 (file)
@@ -17,7 +17,7 @@ import compbio.metadata.WrongParameterException;
 import compbio.runner.disorder.GlobPlot;\r
 \r
 @WebService(endpointInterface = "compbio.data.msa.SequenceAnnotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "GlobPlotWS")\r
-public class GlobPlotWS extends SAService<GlobPlot>\r
+public class GlobPlotWS extends SequenceAnnotationService<GlobPlot>\r
                implements\r
                        SequenceAnnotation<GlobPlot> {\r
 \r
index bd86c81..bcc5faa 100644 (file)
@@ -16,7 +16,7 @@ import compbio.metadata.WrongParameterException;
 import compbio.runner.disorder.IUPred;\r
 \r
 @WebService(endpointInterface = "compbio.data.msa.SequenceAnnotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "IUPredWS")\r
-public class IUPredWS extends SAService<IUPred>\r
+public class IUPredWS extends SequenceAnnotationService<IUPred>\r
                implements\r
                        SequenceAnnotation<IUPred> {\r
 \r
index ea3c215..c3fe1f4 100644 (file)
@@ -13,7 +13,7 @@ import compbio.runner.conservation.AACon;
 import compbio.runner.disorder.Jronn;\r
 \r
 @WebService(endpointInterface = "compbio.data.msa.SequenceAnnotation", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "JronnWS")\r
-public class JronnWS extends SAService<Jronn>\r
+public class JronnWS extends SequenceAnnotationService<Jronn>\r
                implements\r
                        SequenceAnnotation<Jronn> {\r
 \r
index eda824a..12805af 100644 (file)
@@ -31,6 +31,7 @@ import compbio.data.sequence.FastaSequence;
 import compbio.engine.AsyncExecutor;\r
 import compbio.engine.Configurator;\r
 import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.SkeletalExecutable;\r
 import compbio.metadata.ChunkHolder;\r
 import compbio.metadata.JobStatus;\r
 import compbio.metadata.JobSubmissionException;\r
@@ -70,6 +71,9 @@ public class MafftWS implements MsaWS<Mafft> {
        ConfiguredExecutable<Mafft> init(List<FastaSequence> dataSet)\r
                        throws JobSubmissionException {\r
                Mafft mafft = new Mafft();\r
+               mafft.setInput(SkeletalExecutable.INPUT)\r
+                               .setOutput(SkeletalExecutable.OUTPUT)\r
+                               .setError(SkeletalExecutable.ERROR);\r
                return Configurator.configureExecutable(mafft, dataSet);\r
        }\r
 \r
index 1d5430d..4ab7a34 100644 (file)
@@ -31,6 +31,7 @@ import compbio.data.sequence.FastaSequence;
 import compbio.engine.AsyncExecutor;\r
 import compbio.engine.Configurator;\r
 import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.SkeletalExecutable;\r
 import compbio.metadata.ChunkHolder;\r
 import compbio.metadata.JobStatus;\r
 import compbio.metadata.JobSubmissionException;\r
@@ -68,6 +69,9 @@ public class ProbconsWS implements MsaWS<Probcons> {
        ConfiguredExecutable<Probcons> init(List<FastaSequence> dataSet)\r
                        throws JobSubmissionException {\r
                Probcons probcons = new Probcons();\r
+               probcons.setInput(SkeletalExecutable.INPUT)\r
+                               .setOutput(SkeletalExecutable.OUTPUT)\r
+                               .setError(SkeletalExecutable.ERROR);\r
                return Configurator.configureExecutable(probcons, dataSet);\r
        }\r
 \r
diff --git a/webservices/compbio/ws/server/SequenceAnnotationService.java b/webservices/compbio/ws/server/SequenceAnnotationService.java
new file mode 100644 (file)
index 0000000..973951e
--- /dev/null
@@ -0,0 +1,85 @@
+package compbio.ws.server;\r
+\r
+import java.util.List;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.ScoreManager;\r
+import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.SkeletalExecutable;\r
+import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.Limit;\r
+import compbio.metadata.LimitExceededException;\r
+import compbio.metadata.Option;\r
+import compbio.metadata.Preset;\r
+import compbio.metadata.ResultNotAvailableException;\r
+import compbio.metadata.UnsupportedRuntimeException;\r
+import compbio.metadata.WrongParameterException;\r
+import compbio.runner.conservation.AACon;\r
+\r
+/**\r
+ * Common methods for all SequenceAnnotation web services\r
+ * \r
+ * @author pvtroshin\r
+ * \r
+ * @param <T>\r
+ * \r
+ * @version 1.0 June 2011\r
+ * @since 2.0\r
+ */\r
+public abstract class SequenceAnnotationService<T> extends GenericMetadataService {\r
+\r
+       /*\r
+        * FIXME - instances of the Runner (?) and their types should be defined in\r
+        * Executable IF\r
+        */\r
+       SequenceAnnotationService(SkeletalExecutable<T> exec, Logger log) {\r
+               super(exec, log);\r
+       }\r
+\r
+       public ScoreManager getAnnotation(String jobId)\r
+                       throws ResultNotAvailableException {\r
+               return WSUtil.getAnnotation(jobId, log);\r
+       }\r
+\r
+       public String analize(List<FastaSequence> sequences)\r
+                       throws UnsupportedRuntimeException, LimitExceededException,\r
+                       JobSubmissionException {\r
+               WSUtil.validateFastaInput(sequences);\r
+               ConfiguredExecutable<T> confIUPred = init(sequences);\r
+               return WSUtil.analize(sequences, confIUPred, log, "analize",\r
+                               getLimit(""));\r
+       }\r
+\r
+       public String customAnalize(List<FastaSequence> sequences,\r
+                       List<Option<T>> options) throws UnsupportedRuntimeException,\r
+                       LimitExceededException, JobSubmissionException,\r
+                       WrongParameterException {\r
+               WSUtil.validateAAConInput(sequences);\r
+               ConfiguredExecutable<T> confAACon = init(sequences);\r
+               // Could not do that! Space separated values\r
+               // will all be treated as keys! thus duplicates removed\r
+               // String params = cbuilder.getCommand();\r
+               List<String> params = WSUtil.getCommands(options,\r
+                               AACon.KEY_VALUE_SEPARATOR);\r
+               confAACon.addParameters(params);\r
+               return WSUtil.analize(sequences, confAACon, log, "customAnalize",\r
+                               getLimit(""));\r
+       }\r
+\r
+       public String presetAnalize(List<FastaSequence> sequences, Preset<T> preset)\r
+                       throws UnsupportedRuntimeException, LimitExceededException,\r
+                       JobSubmissionException, WrongParameterException {\r
+               WSUtil.validateAAConInput(sequences);\r
+               if (preset == null) {\r
+                       throw new WrongParameterException("Preset must be provided!");\r
+               }\r
+               ConfiguredExecutable<T> confAAcon = init(sequences);\r
+               confAAcon.addParameters(preset.getOptions());\r
+               Limit<T> limit = getLimit(preset.getName());\r
+               return WSUtil\r
+                               .analize(sequences, confAAcon, log, "presetAnalize", limit);\r
+       }\r
+\r
+}\r
index dc5fae6..e5a6d66 100644 (file)
@@ -34,21 +34,21 @@ import compbio.engine.local.LocalExecutorService;
  */\r
 public class ShutdownEngines implements ServletContextListener {\r
 \r
-    private final Logger log = Logger.getLogger(ShutdownEngines.class);\r
-\r
-    @Override\r
-    public void contextDestroyed(ServletContextEvent ignored) {\r
-       // Shutdown local engine\r
-       log.info("JABAWS context is destroyed. Shutting down engines...");\r
-       LocalExecutorService.shutDown();\r
-       log.info("Local engine is shutdown OK");\r
-       ExecutableWrapper.shutdownService();\r
-       log.info("Individual executables stream engine is shutdown OK");\r
-    }\r
-\r
-    @Override\r
-    public void contextInitialized(ServletContextEvent arg0) {\r
-       // Do nothing\r
-    }\r
+       private final Logger log = Logger.getLogger(ShutdownEngines.class);\r
+\r
+       @Override\r
+       public void contextDestroyed(ServletContextEvent ignored) {\r
+               // Shutdown local engine\r
+               log.info("JABAWS context is destroyed. Shutting down engines...");\r
+               LocalExecutorService.shutDown();\r
+               log.info("Local engine is shutdown OK");\r
+               ExecutableWrapper.shutdownService();\r
+               log.info("Individual executables stream engine is shutdown OK");\r
+       }\r
+\r
+       @Override\r
+       public void contextInitialized(ServletContextEvent arg0) {\r
+               // Do nothing\r
+       }\r
 \r
 }\r
index 889efd8..59b4c19 100644 (file)
@@ -73,6 +73,10 @@ public class TcoffeeWS implements MsaWS<Tcoffee> {
        ConfiguredExecutable<Tcoffee> init(List<FastaSequence> sequences)\r
                        throws JobSubmissionException {\r
                Tcoffee tcoffee = new Tcoffee();\r
+               tcoffee.setInput(SkeletalExecutable.INPUT)\r
+                               .setOutput(SkeletalExecutable.OUTPUT)\r
+                               .setError(SkeletalExecutable.ERROR);\r
+\r
                ConfiguredExecutable<Tcoffee> confCoffee = Configurator\r
                                .configureExecutable(tcoffee, sequences);\r
                if (confCoffee.getExecProvider() == Executable.ExecProvider.Cluster) {\r
diff --git a/webservices/compbio/ws/server/_MsaService.java b/webservices/compbio/ws/server/_MsaService.java
new file mode 100644 (file)
index 0000000..3731473
--- /dev/null
@@ -0,0 +1,99 @@
+package compbio.ws.server;\r
+\r
+import java.io.File;\r
+import java.util.List;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.data.sequence.Alignment;\r
+import compbio.data.sequence.FastaSequence;\r
+import compbio.engine.AsyncExecutor;\r
+import compbio.engine.Configurator;\r
+import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.SkeletalExecutable;\r
+import compbio.metadata.ChunkHolder;\r
+import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.Limit;\r
+import compbio.metadata.Option;\r
+import compbio.metadata.Preset;\r
+import compbio.metadata.ResultNotAvailableException;\r
+import compbio.metadata.WrongParameterException;\r
+import compbio.runner.msa.ClustalW;\r
+\r
+/**\r
+ * \r
+ * TODO to complete after the approach is tested with SequenceAnnotation!\r
+ * \r
+ * Common methods for all SequenceAnnotation web services\r
+ * \r
+ * @author pvtroshin\r
+ * \r
+ * @param <T>\r
+ * \r
+ * @version 1.0 June 2011\r
+ * @since 2.0\r
+ */\r
+public abstract class _MsaService<T> extends GenericMetadataService {\r
+\r
+       /*\r
+        * FIXME - instances of the Runner (?) and their types should be defined in\r
+        * Executable IF\r
+        */\r
+       _MsaService(SkeletalExecutable<T> exec, Logger log) {\r
+               super(exec, log);\r
+       }\r
+\r
+       public String align(List<FastaSequence> sequences)\r
+                       throws JobSubmissionException {\r
+\r
+               WSUtil.validateFastaInput(sequences);\r
+               ConfiguredExecutable<T> confClust = init(sequences);\r
+               return WSUtil.align(sequences, confClust, log, "align", getLimit(""));\r
+       }\r
+\r
+       public String presetAlign(List<FastaSequence> sequences, Preset<T> preset)\r
+                       throws JobSubmissionException, WrongParameterException {\r
+               WSUtil.validateFastaInput(sequences);\r
+               if (preset == null) {\r
+                       throw new WrongParameterException("Preset must be provided!");\r
+               }\r
+               Limit<T> limit = getLimit(preset.getName());\r
+               ConfiguredExecutable<T> confClust = init(sequences);\r
+               confClust.addParameters(preset.getOptions());\r
+               return WSUtil.align(sequences, confClust, log, "presetAlign", limit);\r
+       }\r
+\r
+       public String customAlign(List<FastaSequence> sequences,\r
+                       List<Option<T>> options) throws JobSubmissionException,\r
+                       WrongParameterException {\r
+               WSUtil.validateFastaInput(sequences);\r
+               ConfiguredExecutable<T> confClust = init(sequences);\r
+               List<String> params = WSUtil.getCommands(options,\r
+                               ClustalW.KEY_VALUE_SEPARATOR);\r
+               confClust.addParameters(params);\r
+               log.info("Setting parameters: " + params);\r
+               return WSUtil.align(sequences, confClust, log, "customAlign",\r
+                               getLimit(""));\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public Alignment getResult(String jobId) throws ResultNotAvailableException {\r
+\r
+               WSUtil.validateJobId(jobId);\r
+               AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
+               ConfiguredExecutable<T> clustal = (ConfiguredExecutable<T>) asyncEngine\r
+                               .getResults(jobId);\r
+               Alignment al = clustal.getResults();\r
+               return al;\r
+       }\r
+\r
+       @Override\r
+       public ChunkHolder pullExecStatistics(String jobId, long position) {\r
+               WSUtil.validateJobId(jobId);\r
+               String file = Configurator.getWorkDirectory(jobId) + File.separator\r
+                               + ClustalW.getStatFile();\r
+               ChunkHolder cholder = WSUtil.pullFile(file, position);\r
+               return cholder;\r
+       }\r
+\r
+}\r