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