From a2619dbd95b874abd03ae551c02524fe09e9f631 Mon Sep 17 00:00:00 2001 From: pvtroshin Date: Mon, 6 Jun 2011 18:16:36 +0000 Subject: [PATCH] Adding registry web service and changes to WStester and JWS2Client code. Bugs in input/ouput setup for a few web services fixed git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4223 e3abac25-378b-4346-85de-24260fe3988d --- TODO.txt | 3 + WEB-INF/sun-jaxws.xml | 4 + WEB-INF/web.xml | 11 + conf/Executable.properties | 4 +- .../compbio/engine/client/SkeletalExecutable.java | 10 +- testsrc/compbio/ws/client/WSTesterTester.java | 47 +++ testsrc/compbio/ws/server/RegistryWSTester.java | 25 ++ webservices/compbio/data/msa/RegistryWS.java | 18 ++ webservices/compbio/ws/client/Jws2Client.java | 98 ++++-- webservices/compbio/ws/client/Services.java | 3 +- webservices/compbio/ws/client/WSTester.java | 317 ++++++++++++++------ webservices/compbio/ws/server/AAConWS.java | 12 +- webservices/compbio/ws/server/DisemblWS.java | 2 + webservices/compbio/ws/server/GlobPlotWS.java | 3 +- webservices/compbio/ws/server/JronnWS.java | 3 + webservices/compbio/ws/server/MuscleWS.java | 4 + webservices/compbio/ws/server/RegistryWS.java | 126 ++++++++ 17 files changed, 556 insertions(+), 134 deletions(-) create mode 100644 testsrc/compbio/ws/client/WSTesterTester.java create mode 100644 testsrc/compbio/ws/server/RegistryWSTester.java create mode 100644 webservices/compbio/data/msa/RegistryWS.java create mode 100644 webservices/compbio/ws/server/RegistryWS.java diff --git a/TODO.txt b/TODO.txt index 539954e..74a7d13 100644 --- a/TODO.txt +++ b/TODO.txt @@ -4,6 +4,9 @@ webservices - 1 week client - 1 week docs - 1 week +make sure that aacon checks its input (must be alignment) and log errors/throws +exceptions if the input is not correct or absent! + Cluster stats: +cancelled should not be reported as incomplete! -Remove hyperlinks from tasks which workdirs were removed diff --git a/WEB-INF/sun-jaxws.xml b/WEB-INF/sun-jaxws.xml index 94da952..f3158ed 100644 --- a/WEB-INF/sun-jaxws.xml +++ b/WEB-INF/sun-jaxws.xml @@ -1,6 +1,10 @@ + diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml index 4f75bd5..2e44c07 100644 --- a/WEB-INF/web.xml +++ b/WEB-INF/web.xml @@ -59,6 +59,12 @@ + RegistryWS + com.sun.xml.ws.transport.http.servlet.WSServlet + 1 + + + ClustalWS com.sun.xml.ws.transport.http.servlet.WSServlet 1 @@ -133,6 +139,11 @@ + RegistryWS + /RegistryWS + + + ClustalWS /ClustalWS diff --git a/conf/Executable.properties b/conf/Executable.properties index fcd6057..d621a3b 100644 --- a/conf/Executable.properties +++ b/conf/Executable.properties @@ -61,7 +61,7 @@ probcons.limits.file=conf/settings/ProbconsLimits.xml probcons.cluster.settings=-l h_cpu=24:00:00 -l h_vmem=6000M -l ram=6000M ### Jronn configuration ### -local.jronn.bin.windows=D:\\Java\\jdk1.6.0_14\\bin\\java.exe +local.jronn.bin.windows=D:\\Java\\jdk1.6.0_24\\bin\\java.exe local.jronn.bin=/sw/java/latest/bin/java cluster.jronn.bin=/sw/java/latest/bin/java jronn.jar.file=binaries/jronn3.1.jar @@ -90,7 +90,7 @@ globplot.cluster.settings=-l h_cpu=24:00:00 -l h_vmem=6000M -l ram=6000M ### AACon configuration ### -local.aacon.bin.windows=D:\\Java\\jdk1.6.0_14\\bin\\java.exe +local.aacon.bin.windows=D:\\Java\\jdk1.6.0_24\\bin\\java.exe local.aacon.bin=/sw/java/latest/bin/java cluster.aacon.bin=/sw/java/latest/bin/java aacon.jar.file=binaries/aaconservation.jar diff --git a/engine/compbio/engine/client/SkeletalExecutable.java b/engine/compbio/engine/client/SkeletalExecutable.java index 0e6422d..f974302 100644 --- a/engine/compbio/engine/client/SkeletalExecutable.java +++ b/engine/compbio/engine/client/SkeletalExecutable.java @@ -42,9 +42,13 @@ public abstract class SkeletalExecutable implements Executable { // Cache for Limits information private LimitsManager limits; - protected String inputFile = "input.txt"; - protected String outputFile = "output.txt"; - protected String errorFile = "error.txt"; + public static final String INPUT = "input.txt"; + public static final String OUTPUT = "result.txt"; + public static final String ERROR = "error.txt"; + + protected String inputFile = INPUT; + protected String outputFile = OUTPUT; + protected String errorFile = ERROR; private boolean isInputSet = false; private boolean isOutputSet = false; diff --git a/testsrc/compbio/ws/client/WSTesterTester.java b/testsrc/compbio/ws/client/WSTesterTester.java new file mode 100644 index 0000000..43204e5 --- /dev/null +++ b/testsrc/compbio/ws/client/WSTesterTester.java @@ -0,0 +1,47 @@ +package compbio.ws.client; + +import static org.testng.Assert.assertTrue; + +import java.io.PrintWriter; + +import org.testng.annotations.Test; + +import compbio.data.msa.JABAService; +import compbio.metadata.AllTestSuit; + +public class WSTesterTester { + + public static final String SERVER = "http://localhost:8080/jabaws"; + + @Test(groups = {AllTestSuit.test_group_runner}) + public void testAllWindowsWS() { + WSTester tester = new WSTester(new PrintWriter(System.out, true)); + JABAService ws = Jws2Client.connect(SERVER, Services.AAConWS); + assertTrue(tester.checkService(ws)); + + ws = Jws2Client.connect(SERVER, Services.JronnWS); + assertTrue(tester.checkService(ws)); + + ws = Jws2Client.connect(SERVER, Services.ClustalWS); + assertTrue(tester.checkService(ws)); + + ws = Jws2Client.connect(SERVER, Services.MuscleWS); + assertTrue(tester.checkService(ws)); + + // Will throw UnsupportedRuntimeException on windows + // ws = Jws2Client.connect(SERVER, Services.MafftWS); + // assertTrue(tester.checkService(ws)); + + } + + @Test(groups = {AllTestSuit.test_group_non_windows}) + public void testAllWS() { + WSTester tester = new WSTester(new PrintWriter(System.out)); + + for (Services service : Services.values()) { + JABAService ws = Jws2Client.connect(SERVER, service); + assertTrue(tester.checkService(ws)); + } + } + +} diff --git a/testsrc/compbio/ws/server/RegistryWSTester.java b/testsrc/compbio/ws/server/RegistryWSTester.java new file mode 100644 index 0000000..4093626 --- /dev/null +++ b/testsrc/compbio/ws/server/RegistryWSTester.java @@ -0,0 +1,25 @@ +package compbio.ws.server; + +import org.testng.annotations.Test; + +import compbio.ws.client.Jws2Client; +import compbio.ws.client.Services; +import compbio.ws.client.WSTesterTester; + +public class RegistryWSTester { + + @Test + public void testGetSupportedServices() { + compbio.data.msa.RegistryWS reg = Jws2Client + .connectToRegistry(WSTesterTester.SERVER); + System.out.println(reg.getSupportedServices()); + } + + @Test + public void testTestService() { + compbio.data.msa.RegistryWS reg = Jws2Client + .connectToRegistry(WSTesterTester.SERVER); + System.out.println(reg.testService(Services.AAConWS)); + } + +} diff --git a/webservices/compbio/data/msa/RegistryWS.java b/webservices/compbio/data/msa/RegistryWS.java new file mode 100644 index 0000000..3dd89b5 --- /dev/null +++ b/webservices/compbio/data/msa/RegistryWS.java @@ -0,0 +1,18 @@ +package compbio.data.msa; + +import java.util.Date; +import java.util.Set; + +import javax.jws.WebService; + +import compbio.ws.client.Services; + +@WebService(targetNamespace = "http://msa.data.compbio/01/12/2010/") +public interface RegistryWS extends JABAService { + Set getSupportedServices(); + Date getLastTestedOn(Services service); + String testAllServices(); + String testService(Services service); + boolean isOperating(Services service); + +} diff --git a/webservices/compbio/ws/client/Jws2Client.java b/webservices/compbio/ws/client/Jws2Client.java index eda6533..ceb9501 100644 --- a/webservices/compbio/ws/client/Jws2Client.java +++ b/webservices/compbio/ws/client/Jws2Client.java @@ -41,6 +41,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import javax.xml.namespace.QName; import javax.xml.ws.Service; import javax.xml.ws.WebServiceException; @@ -68,8 +69,8 @@ import compbio.metadata.WrongParameterException; public class Jws2Client { /* - * Use java.util.Logger instead of log4j logger to reduce the size of the - * client package + * TODO Use java.util.Logger instead of log4j logger to reduce the size of + * the client package */ private static final Logger log = Logger.getLogger(Jws2Client.class .getCanonicalName()); @@ -201,15 +202,12 @@ public class Jws2Client { * @return Set the conservation scores * @throws UnknownFileFormatException */ - ScoreManager analize(File file, SequenceAnnotation wsproxy, - Preset preset, List> customOptions) { + static ScoreManager analize(List fastalist, + SequenceAnnotation wsproxy, Preset preset, + List> customOptions) { - List fastalist = null; ScoreManager scores = null; try { - fastalist = SequenceUtil.openInputStream(file.getAbsolutePath()); - assert !fastalist.isEmpty() : "Input is empty!"; - String jobId = null; if (customOptions != null && preset != null) { System.out @@ -220,19 +218,12 @@ public class Jws2Client { } else if (preset != null) { jobId = wsproxy.presetAnalize(fastalist, preset); } else { - System.out.println("\n\ncalling analise........."); jobId = wsproxy.analize(fastalist); } - Thread.sleep(2000); - + System.out.println("\n\ncalling analise........."); + Thread.sleep(1000); scores = wsproxy.getAnnotation(jobId); - } catch (IOException e) { - System.err - .println("Exception while reading the input file. " - + "Check that the input file contains a list of fasta formatted sequences! " - + "Exception details are below:"); - e.printStackTrace(); } catch (JobSubmissionException e) { System.err .println("Exception while submitting job to a web server. " @@ -242,14 +233,49 @@ public class Jws2Client { System.err.println("Exception while waiting for results. " + "Exception details are below:"); e.printStackTrace(); - } catch (InterruptedException ignored) { + } catch (InterruptedException e) { // ignore and propagate an interruption Thread.currentThread().interrupt(); + System.err.println("Exception while waiting for results. " + + "Exception details are below:"); + e.printStackTrace(); } catch (WrongParameterException e) { System.err .println("Exception while parsing the web method input parameters. " + "Exception details are below:"); e.printStackTrace(); + } + return scores; + + } + + /** + * Calculate conservation for sequences loaded from the file + * + * @param wsproxy + * a web service proxy + * @param file + * the file to read the results from + * @param preset + * Preset to use optional + * @param customOptions + * the list of options + * @return Set the conservation scores + * @throws IOException + * @throws UnknownFileFormatException + */ + static ScoreManager analize(File file, SequenceAnnotation wsproxy, + Preset preset, List> customOptions) { + List fastalist = null; + try { + fastalist = SequenceUtil.openInputStream(file.getAbsolutePath()); + assert !fastalist.isEmpty() : "Input is empty!"; + } catch (IOException e) { + System.err + .println("Exception while reading the input file. " + + "Check that the input file contains a list of fasta formatted sequences! " + + "Exception details are below:"); + e.printStackTrace(); } catch (UnknownFileFormatException e) { System.err .println("Exception while attempting to read the input file " @@ -257,9 +283,8 @@ public class Jws2Client { System.out.println(e.getMessage()); e.printStackTrace(); } - return scores; + return analize(fastalist, wsproxy, preset, customOptions); } - /** * Connects to a web service by the host and the service name * @@ -284,7 +309,7 @@ public class Jws2Client { try { serv = service.getService(url, QUALIFIED_SERVICE_NAME); } catch (WebServiceException wse) { - System.out.println("Conecting to JABAWS version 2 service"); + System.out.println("Connecting to JABAWS version 2 service"); if (isV2service(wse)) { serv = service.getService(url, V2_QUALIFIED_SERVICE_NAME); } @@ -311,6 +336,36 @@ public class Jws2Client { return false; } + public static compbio.data.msa.RegistryWS connectToRegistry(String host) + throws WebServiceException { + URL url = null; + String service = "RegistryWS"; + log.log(Level.FINE, "Attempting to connect..."); + + try { + url = new URL(host + "/" + service + "?wsdl"); + } catch (MalformedURLException e) { + e.printStackTrace(); + // ignore as the host name is already verified + } + QName qname = new QName(V2_QUALIFIED_SERVICE_NAME, service); + Service serv = Service.create(url, qname); + + if (serv == null) { + System.err.println("Could not connect to " + url + + " the server is down?"); + } + + QName portName = new QName(serv.getServiceName().getNamespaceURI(), + service + "Port"); + compbio.data.msa.RegistryWS serviceIF = serv.getPort(portName, + compbio.data.msa.RegistryWS.class); + + log.log(Level.INFO, "Connected to " + service + " successfully!"); + + return serviceIF; + } + /** * Align sequences from the file using MsaWS * @@ -347,6 +402,7 @@ public class Jws2Client { } else { jobId = msaws.align(fastalist); } + System.out.println("\n\ncalling align........."); Thread.sleep(1000); alignment = msaws.getResult(jobId); diff --git a/webservices/compbio/ws/client/Services.java b/webservices/compbio/ws/client/Services.java index bff43e3..01b4827 100644 --- a/webservices/compbio/ws/client/Services.java +++ b/webservices/compbio/ws/client/Services.java @@ -95,7 +95,8 @@ public enum Services { } } - public static Class> getRunnerByJobDirectory(File jobdir) { + public static Class> getRunnerByJobDirectory( + File jobdir) { Services service = getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir)); return service.getServiceImpl(); } diff --git a/webservices/compbio/ws/client/WSTester.java b/webservices/compbio/ws/client/WSTester.java index 544ecad..05bd0b8 100644 --- a/webservices/compbio/ws/client/WSTester.java +++ b/webservices/compbio/ws/client/WSTester.java @@ -25,19 +25,27 @@ import static compbio.ws.client.Constraints.servicekey; import java.io.ByteArrayInputStream; import java.io.Closeable; import java.io.IOException; +import java.io.PrintWriter; import java.util.Arrays; import java.util.List; import javax.xml.ws.WebServiceException; +import org.apache.log4j.Logger; + +import compbio.data.msa.JABAService; +import compbio.data.msa.Metadata; import compbio.data.msa.MsaWS; +import compbio.data.msa.SequenceAnnotation; import compbio.data.sequence.Alignment; import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.ScoreManager; import compbio.data.sequence.SequenceUtil; import compbio.metadata.JobStatus; import compbio.metadata.JobSubmissionException; import compbio.metadata.Limit; import compbio.metadata.LimitsManager; +import compbio.metadata.Option; import compbio.metadata.Preset; import compbio.metadata.PresetManager; import compbio.metadata.ResultNotAvailableException; @@ -54,21 +62,28 @@ import compbio.metadata.WrongParameterException; */ public class WSTester { + private static Logger log = Logger.getLogger(WSTester.class); /** * Sequences to be used as input for all WS */ - static final String fastaInput = ">Foobar\n" - + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAVARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDAGQAEAAAAAYTRAHQLLPEEPYITAQLLNWRRRLCDWRALDVLSAQVRAAVAQGVGAVEPFAFLSEDASAAEQLACARTRAQAIAASVRPLAPTRVRSKGPLRVGFVSNGFGAHPTGLLTVALFEALQRRQPDLQMHLFATSGDDGSTLRTRLAQASTLHDVTALGHLATAKHIRHHGIDLLFDLRGWGGGGRPEVFALRPAPVQVNWLAYPGTSGAPWMDYVLGDAFALPPALEPFYSEHVLRLQGAFQPSDTSRVVAEPPSRTQCGLPEQGVVLCCFNNSYKLNPQSMARMLAVLREVPDSVLWLLSGPGEADARLRAFAHAQGVDAQRLVFMPKLPHPQYLARYRHADLFLDTHPYNAHTTASDALWTGCPVLTTPGETFAARVAGSLNHHLGLDEMNVADDAAFVAKA" - + "\n>Barbar\n" - + "ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVAQGVGAVEPFAFLSEDASAAESVRPLAPTRVRSKGPLRVGFVSNGFGAHPTGLLTVALFEALQRRQPDLQMHLFATSGDDGSTLRTRLAQASTLHDVTALGHLATAKHIRHHGIDLLFDLRGWGGGGRPEVFALRPAPVQVNWLAYPGTSGAPWMDYVLGDAFALPPALEPFYSEHVLRLQGAFQPSDTSRVVAEPPSRTQCGLPEQGVVLCCFNNSYKLNPQSMARMLAVLREVPDSVLWLLSGPGEADARLRAFAHAQGVDAQRLVFMPKLPHPQYLARYRHADLFLDTHPYNAHTTASDALWTGCPVLTTPGETFAARVAGSLNHHLGLDEMNVADDAAFVAKAVALASDPAALTALHARVDVLRRESGVFEMDGFADDFGALLQALARRHGWLGI" - + "\n>Foofriend\n" - + "MTADGPRELLQLRAAVRHRPQDVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAVARLGRVRWTQQRHAEAAVLLQQASDAAPEHPGIALWLGHALEDHQLLPEEPYITAQLDVLSAQVRAAVAQGVGAVEPFAFLSEDASAAEQLACARTRAQAIAASVRPLAPTRVRSKGPLRVGFVSNGFGAHPTGLLTVALFEALQRRQPDLQMHLFATSGDDGSTLRTRLAQASTLHDVTALGHLATAKHIRHHGIDLLFDLRGWGGGGRPEVFALRPAPVQVNWLAYPGTSGAPWMDYVLGDAFALPPALEPFYSEHVLRLQGAFQPSDTSRVVAEPPSRTQCGLPEQGVVLCCFNNSYKLNPQSMARMLAVLREVPDSVLWLLSGPGEADARLRAFAHAQGVDAQRLVFMPKLPHPQYLARYRHADLFLDTHPYNAHTTASDALWTGCPVLTTPGETFAARVAGSLNHHLGLDEMNVADDAAFVAKAVALASDPAALTALHARVDVLRRESI\n"; + static final String fastaInput = ">Foo\n" + + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV" + + "\n>Bar\n" + + "ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA"; + + static final String fastaAlignment = ">Foo\r\n" + + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\r\n" + + ">Bar\r\n" + + "ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\r\n" + + ""; static final List seqs = loadSeqs(); private static final String FAILED = "FAILED"; private static final String OK = "OK"; + private static final String UNSUPPORTED = "UNSUPPORTED"; + /** * Converting input to a form accepted by WS * @@ -86,23 +101,43 @@ public class WSTester { } /** + * Converting input to a form accepted by WS + * + * @return List of FastaSequence records + */ + static List loadAlignment() { + try { + return SequenceUtil.readFasta(new ByteArrayInputStream( + fastaAlignment.getBytes())); + } catch (IOException ignored) { + // Should not happen as a source is not a external stream + ignored.printStackTrace(); + } + return null; + } + + private final PrintWriter writer; + + public WSTester(PrintWriter writer) { + this.writer = writer; + } + + /** * Prints usage */ - static void printUsage() { - System.out.println("Usage: " + hostkey + void printUsage() { + writer.println("Usage: " + hostkey + pseparator + "host_and_context " + "<" + servicekey + pseparator + "serviceName>"); - System.out.println(); - System.out - .println(hostkey - + pseparator - + " - a full URL to the JABAWS web server including context path e.g. http://10.31.1.159:8080/ws"); - System.out - .println(servicekey - + pseparator - + " - optional if unspecified all services are tested otherwise one of " - + Arrays.toString(Services.values())); - System.out.println(); + writer.println(); + writer.println(hostkey + + pseparator + + " - a full URL to the JABAWS web server including context path e.g. http://10.31.1.159:8080/ws"); + writer.println(servicekey + + pseparator + + " - optional if unspecified all services are tested otherwise one of " + + Arrays.toString(Services.values())); + writer.println(); } @@ -115,48 +150,66 @@ public class WSTester { * list of the Preset * @throws UnsupportedRuntimeException */ - static boolean presetAlign(MsaWS msaws, List> presets) + boolean presetAlign(MsaWS msaws, List> presets) throws UnsupportedRuntimeException { boolean succeed = false; for (Preset preset : presets) { - System.out.print("Aligning with preset '" + preset.getName() - + "'... "); + writer.print("Aligning with preset '" + preset.getName() + "'... "); Alignment al = null; try { String taskId = msaws.presetAlign(seqs, preset); al = msaws.getResult(taskId); if (al != null) { - System.out.println(OK); + writer.println(OK); } succeed = true; } catch (UnsupportedRuntimeException e) { - System.out.println(FAILED); + writer.println(FAILED); // If executable is not supported than none of the presets are // going to work throw new UnsupportedRuntimeException(e); } catch (JobSubmissionException e) { // TODO custom message - System.out.println(FAILED); - System.out.println(); - e.printStackTrace(); + writer.println(FAILED); + writer.println(); + writer.println(e.getLocalizedMessage()); + e.printStackTrace(writer); continue; } catch (WrongParameterException e) { // TODO custom message - System.out.println(FAILED); - System.out.println(); - e.printStackTrace(); + writer.println(FAILED); + writer.println(); + writer.println(e.getLocalizedMessage()); + e.printStackTrace(writer); continue; } catch (ResultNotAvailableException e) { // TODO custom message - System.out.println(FAILED); - System.out.println(); - e.printStackTrace(); + writer.println(FAILED); + writer.println(); + writer.println(e.getLocalizedMessage()); + e.printStackTrace(writer); continue; } } return succeed; } + private boolean testMsaWS(MsaWS msaws) + throws UnsupportedRuntimeException { + + boolean succeed = testDefaultAlignment(msaws); + + // If exception above is thrown than the tests below is not run + + PresetManager pmanager = msaws.getPresets(); + if (pmanager != null && pmanager.getPresets().size() > 0) { + writer.println("Testing alignment with presets:"); + List> plist = pmanager.getPresets(); + succeed = !succeed ? presetAlign(msaws, plist) : succeed; + } + testMetadata(msaws); + return succeed; + } /** * Call most of web services functions and check the output * @@ -168,54 +221,120 @@ public class WSTester { * the web service is not functional. e.g. when native * executable does not exists for a server platform */ - static boolean checkService(MsaWS msaws) + @SuppressWarnings("unchecked") + public boolean checkService(JABAService wservice) { + try { + if (wservice == null) { + throw new NullPointerException( + "JABAService instance must be provided!"); + } + if (wservice instanceof MsaWS) { + return testMsaWS((MsaWS) wservice); + } else if (wservice instanceof SequenceAnnotation) { + return testSequenceAnnotationWS((SequenceAnnotation) wservice); + } else { + throw new UnsupportedOperationException("The service: " + + wservice.getClass() + " is not supported! "); + } + } catch (UnsupportedRuntimeException e) { + writer.println(e.getLocalizedMessage()); + e.printStackTrace(writer); + return false; + } + } + + private boolean testSequenceAnnotationWS(SequenceAnnotation wservice) throws UnsupportedRuntimeException { + boolean success = testDefaultAnalyse(loadAlignment(), wservice, null, + null); + PresetManager presetman = wservice.getPresets(); + if (presetman != null) { + List> presets = presetman.getPresets(); + if (presets != null && !presets.isEmpty()) { + Preset preset = presets.get(0); + success = testDefaultAnalyse(loadAlignment(), wservice, preset, + null); + } + } + testMetadata(wservice); + return success; + } - boolean succeed = testDefaultAlignment(msaws); + boolean testDefaultAnalyse(List fastalist, + SequenceAnnotation wsproxy, Preset preset, + List> customOptions) throws UnsupportedRuntimeException { - // If exception above is thrown than the tests below is not run + ScoreManager scores = null; + try { + String jobId = null; + if (customOptions != null) { + jobId = wsproxy.customAnalize(fastalist, customOptions); + } else if (preset != null) { + jobId = wsproxy.presetAnalize(fastalist, preset); + } else { + jobId = wsproxy.analize(fastalist); + } + writer.println("\n\ncalling analise........."); + Thread.sleep(1000); + scores = wsproxy.getAnnotation(jobId); - PresetManager pmanager = msaws.getPresets(); - if (pmanager != null && pmanager.getPresets().size() > 0) { - System.out.println("Testing alignment with presets:"); - List> plist = pmanager.getPresets(); - succeed = !succeed ? presetAlign(msaws, plist) : succeed; + } catch (JobSubmissionException e) { + writer.println("Exception while submitting job to a web server. " + + "Exception details are below:"); + e.printStackTrace(writer); + } catch (ResultNotAvailableException e) { + writer.println("Exception while waiting for results. " + + "Exception details are below:"); + e.printStackTrace(writer); + } catch (InterruptedException e) { + // ignore and propagate an interruption + Thread.currentThread().interrupt(); + writer.println("Exception while waiting for results. " + + "Exception details are below:"); + e.printStackTrace(writer); + } catch (WrongParameterException e) { + writer.println("Exception while parsing the web method input parameters. " + + "Exception details are below:"); + e.printStackTrace(writer); } + return scores != null; + } - System.out.print("Querying presets..."); + private void testMetadata(Metadata msaws) + throws UnsupportedRuntimeException { + writer.print("Querying presets..."); + PresetManager pmanager = msaws.getPresets(); if (pmanager != null && pmanager.getPresets().size() > 0) { - System.out.println(OK); + writer.println(OK); } else { - System.out.println("UNSUPPORTED"); + writer.println(UNSUPPORTED); } - System.out.print("Querying Parameters..."); + writer.print("Querying Parameters..."); RunnerConfig options = msaws.getRunnerOptions(); if (options != null && options.getArguments().size() > 0) { - System.out.println(OK); + writer.println(OK); } else { - System.out.println(FAILED); - succeed = false; + writer.println(UNSUPPORTED); } - System.out.print("Querying Limits..."); + writer.print("Querying Limits..."); LimitsManager limits = msaws.getLimits(); if (limits != null && limits.getLimits().size() > 0) { - System.out.println(OK); + writer.println(OK); } else { - System.out.println("UNSUPPORTED"); + writer.println(UNSUPPORTED); } - System.out.print("Querying Local Engine Limits..."); + writer.print("Querying Local Engine Limits..."); Limit localLimit = msaws .getLimit(PresetManager.LOCAL_ENGINE_LIMIT_PRESET); if (localLimit != null) { - System.out.println(OK); + writer.println(OK); } else { - System.out.println("UNSUPPORTED"); + writer.println(UNSUPPORTED); } - return succeed; } /** @@ -225,37 +344,40 @@ public class WSTester { * @param msaws * @throws UnsupportedRuntimeException */ - static boolean testDefaultAlignment(MsaWS msaws) + public boolean testDefaultAlignment(MsaWS msaws) throws UnsupportedRuntimeException { - System.out.print("Testing alignment with default parameters:"); + writer.print("Testing alignment with default parameters:"); Alignment al = null; boolean succeed = false; try { String taskId = msaws.align(seqs); - System.out.print("\nQuerying job status..."); + writer.print("\nQuerying job status..."); JobStatus status = msaws.getJobStatus(taskId); while (status != JobStatus.FINISHED) { Thread.sleep(1000); status = msaws.getJobStatus(taskId); } - System.out.println(OK); - System.out.print("Retrieving results..."); + writer.println(OK); + writer.print("Retrieving results..."); al = msaws.getResult(taskId); succeed = true; } catch (ResultNotAvailableException e) { - System.out.println(FAILED); - e.printStackTrace(); + writer.println(FAILED); + writer.println(e.getLocalizedMessage()); + e.printStackTrace(writer); } catch (JobSubmissionException e) { - System.out.println(FAILED); - System.out.println(); - e.printStackTrace(); + writer.println(FAILED); + writer.println(); + writer.println(e.getLocalizedMessage()); + e.printStackTrace(writer); } catch (InterruptedException e) { - System.out.println(FAILED); - System.out.println(); - e.printStackTrace(); + writer.println(FAILED); + writer.println(); + writer.println(e.getLocalizedMessage()); + e.printStackTrace(writer); } if (al != null) { - System.out.println(OK); + writer.println(OK); } return succeed; } @@ -268,17 +390,19 @@ public class WSTester { * @param service * @return */ - static MsaWS connect(String host, Services service) { - MsaWS msaws = null; + JABAService connect(String host, Services service) { + JABAService jabaservice = null; try { - System.out.print("Connecting to service " + service + " on " + host + writer.print("Connecting to service " + service + " on " + host + " ... "); - msaws = (MsaWS) Jws2Client.connect(host, service); - System.out.println(OK); + jabaservice = Jws2Client.connect(host, service); + writer.println(OK); } catch (WebServiceException e) { - System.out.println(FAILED); + writer.println(FAILED); + writer.println(e.getLocalizedMessage()); + e.printStackTrace(writer); } - return msaws; + return jabaservice; } /** @@ -295,15 +419,15 @@ public class WSTester { * @throws IOException */ public static void main(String[] args) throws IOException { - + WSTester tester = new WSTester(new PrintWriter(System.out, true)); if (args == null || args.length < 1) { - printUsage(); + tester.printUsage(); System.exit(0); } String host = CmdHelper.getHost(args); String serviceName = CmdHelper.getServiceName(args); if (!Jws2Client.validURL(host)) { - System.out + tester.writer .println(" parameter is not provided or is incorrect!"); System.exit(1); } @@ -312,57 +436,52 @@ public class WSTester { if (serviceName != null) { Services service = Services.getService(serviceName); if (service == null) { - System.out.println("Service '" + serviceName + tester.writer.println("Service '" + serviceName + "' is not supported. Valid values are: " + Arrays.toString(Services.values())); - System.out.println(); - printUsage(); + tester.writer.println(); + tester.printUsage(); System.exit(1); } - msaws = connect(host, service); + msaws = (MsaWS) tester.connect(host, service); if (msaws == null) { System.exit(1); } try { - succeed = checkService(msaws); - } catch (UnsupportedRuntimeException ignored) { - System.exit(1); + succeed = tester.checkService(msaws); } finally { ((Closeable) msaws).close(); } - reportResults(service, succeed); + // TODO test results printing! + tester.reportResults(service, succeed); System.exit(0); } - System.out + tester.writer .println(" is not provided checking all known services..."); for (Services serv : Services.values()) { - System.out.println(); - msaws = connect(host, serv); + tester.writer.println(); + msaws = (MsaWS) tester.connect(host, serv); if (msaws == null) { continue; } try { - succeed = checkService(msaws); - } catch (UnsupportedRuntimeException ignored) { - System.out.println("Service " + serv + " IS NOT FUNCTIONAL"); - continue; + succeed = tester.checkService(msaws); } finally { ((Closeable) msaws).close(); } - reportResults(serv, succeed); + tester.reportResults(serv, succeed); } } - - private static void reportResults(Services serv, boolean succeed) { + private void reportResults(Services serv, boolean succeed) { if (succeed) { - System.out.println("Check is completed. The Service " + serv + writer.println("Check is completed. The Service " + serv + " IS WORKING"); } else { - System.out.println("Check is completed. The Service " + serv + writer.println("Check is completed. The Service " + serv + " HAS SOME PROBLEMS"); } } diff --git a/webservices/compbio/ws/server/AAConWS.java b/webservices/compbio/ws/server/AAConWS.java index 1ffbbf3..fab12b8 100644 --- a/webservices/compbio/ws/server/AAConWS.java +++ b/webservices/compbio/ws/server/AAConWS.java @@ -2,7 +2,6 @@ package compbio.ws.server; import java.io.File; import java.util.Arrays; -import java.util.HashSet; import java.util.List; import javax.annotation.Resource; @@ -13,11 +12,11 @@ import org.apache.log4j.Logger; import compbio.data.msa.SequenceAnnotation; import compbio.data.sequence.FastaSequence; -import compbio.data.sequence.Score; import compbio.data.sequence.ScoreManager; 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; @@ -57,6 +56,8 @@ public class AAConWS implements SequenceAnnotation { ConfiguredExecutable init(List sequences) throws JobSubmissionException { AACon aacon = new AACon(); + aacon.setInput(SkeletalExecutable.INPUT).setOutput( + SkeletalExecutable.OUTPUT); return Configurator.configureExecutable(aacon, sequences); } @@ -67,12 +68,9 @@ public class AAConWS implements SequenceAnnotation { AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); ConfiguredExecutable aacon = (ConfiguredExecutable) asyncEngine .getResults(jobId); - HashSet mas = aacon.getResults(); - // ScoreManager result = new HashMap>(); - // result.put("Alignment", mas); + ScoreManager mas = aacon.getResults(); log.trace(jobId + " getConservation : " + mas); - // FIXME - return null; + return mas; } /* * @SuppressWarnings("unchecked") public JalviewAnnotation diff --git a/webservices/compbio/ws/server/DisemblWS.java b/webservices/compbio/ws/server/DisemblWS.java index 213711c..50d249b 100644 --- a/webservices/compbio/ws/server/DisemblWS.java +++ b/webservices/compbio/ws/server/DisemblWS.java @@ -14,6 +14,7 @@ import compbio.data.sequence.ScoreManager; 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; @@ -53,6 +54,7 @@ public class DisemblWS implements SequenceAnnotation { ConfiguredExecutable init(List sequences) throws JobSubmissionException { Disembl disembl = new Disembl(); + disembl.setInput(SkeletalExecutable.INPUT); return Configurator.configureExecutable(disembl, sequences); } diff --git a/webservices/compbio/ws/server/GlobPlotWS.java b/webservices/compbio/ws/server/GlobPlotWS.java index affe48e..4c15b7c 100644 --- a/webservices/compbio/ws/server/GlobPlotWS.java +++ b/webservices/compbio/ws/server/GlobPlotWS.java @@ -14,6 +14,7 @@ import compbio.data.sequence.ScoreManager; 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; @@ -53,9 +54,9 @@ public class GlobPlotWS implements SequenceAnnotation { ConfiguredExecutable init(List sequences) throws JobSubmissionException { GlobPlot globPlot = new GlobPlot(); + globPlot.setInput(SkeletalExecutable.INPUT); return Configurator.configureExecutable(globPlot, sequences); } - @Override public ScoreManager getAnnotation(String jobId) throws ResultNotAvailableException { diff --git a/webservices/compbio/ws/server/JronnWS.java b/webservices/compbio/ws/server/JronnWS.java index 97d4ceb..dc37f3f 100644 --- a/webservices/compbio/ws/server/JronnWS.java +++ b/webservices/compbio/ws/server/JronnWS.java @@ -15,6 +15,7 @@ import compbio.data.sequence.ScoreManager; 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; @@ -55,6 +56,8 @@ public class JronnWS implements SequenceAnnotation { ConfiguredExecutable init(List sequences) throws JobSubmissionException { Jronn jronn = new Jronn(); + jronn.setInput(SkeletalExecutable.INPUT).setOutput( + SkeletalExecutable.OUTPUT); return Configurator.configureExecutable(jronn, sequences); } diff --git a/webservices/compbio/ws/server/MuscleWS.java b/webservices/compbio/ws/server/MuscleWS.java index 80f67b2..aea5bc0 100644 --- a/webservices/compbio/ws/server/MuscleWS.java +++ b/webservices/compbio/ws/server/MuscleWS.java @@ -33,6 +33,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; @@ -78,6 +79,9 @@ public class MuscleWS implements MsaWS { ConfiguredExecutable init(List sequences) throws JobSubmissionException { Muscle muscle = new Muscle(); + muscle.setInput(SkeletalExecutable.INPUT) + .setOutput(SkeletalExecutable.OUTPUT) + .setError(SkeletalExecutable.ERROR); return Configurator.configureExecutable(muscle, sequences); } diff --git a/webservices/compbio/ws/server/RegistryWS.java b/webservices/compbio/ws/server/RegistryWS.java new file mode 100644 index 0000000..869807b --- /dev/null +++ b/webservices/compbio/ws/server/RegistryWS.java @@ -0,0 +1,126 @@ +package compbio.ws.server; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Date; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import javax.annotation.Resource; +import javax.jws.WebService; +import javax.servlet.http.HttpServletRequest; +import javax.xml.ws.WebServiceContext; +import javax.xml.ws.handler.MessageContext; + +import org.apache.log4j.Logger; + +import compbio.data.msa.JABAService; +import compbio.ws.client.Jws2Client; +import compbio.ws.client.Services; +import compbio.ws.client.WSTester; + +/** + * TODO + * + * @author pvtroshin + * + */ +@WebService(endpointInterface = "compbio.data.msa.RegistryWS", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "RegistryWS") +public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService { + + // Ask for resource injection + @Resource + WebServiceContext wsContext; + + private static Logger statLog = Logger.getLogger("RegistryWS-stats"); + private static Logger log = Logger.getLogger(RegistryWS.class); + + private final static Map operating = new ConcurrentHashMap(); + + /** + * 1) Check that the actual executable is configured + * + * 2) Check whether the service is enabled? + * + * 3) Attempt to execute? + * + * @return + */ + @Override + public Set getSupportedServices() { + init(); + return operating.keySet(); + } + + private void init() { + // This can be run concurrently + if (operating.isEmpty()) { + testAllServices(); + } + } + @Override + public Date getLastTestedOn(Services service) { + return operating.get(service); + } + + @Override + public String testAllServices() { + Writer testlog = new StringWriter(); + PrintWriter writer = new PrintWriter(testlog, true); + WSTester tester = new WSTester(writer); + + for (Services service : Services.values()) { + JABAService ws = Jws2Client.connect(getServicePath(), service); + if (tester.checkService(ws)) { + operating.put(service, new Date()); + } + } + return testlog.toString(); + } + + private String getServicePath() { + assert wsContext != null : "WS context injection failed!"; + MessageContext msContext = wsContext.getMessageContext(); + HttpServletRequest request = (HttpServletRequest) msContext + .get(MessageContext.SERVLET_REQUEST); + + StringBuffer server = request.getRequestURL(); + server = server.delete(server.lastIndexOf("/"), server.length()); + return server.toString(); + } + + @Override + public String testService(Services service) { + String server = getServicePath(); + Writer testlog = new StringWriter(); + PrintWriter writer = new PrintWriter(testlog, true); + WSTester tester = new WSTester(writer); + writer.println("Attempting to connect to the service " + service + + " on the server " + server + "..."); + JABAService ws = Jws2Client.connect(server, service); + writer.println("Connected successfully!"); + try { + boolean succeed = tester.checkService(ws); + if (succeed) { + // TODO extract messages (see WSTester main) + writer.println("Check is completed. The Service " + + service.toString() + " IS WORKING"); + operating.put(service, new Date()); + } else { + writer.println("Check is completed. The Service " + + service.toString() + " HAS SOME PROBLEMS"); + } + } finally { + writer.close(); + } + return testlog.toString(); + } + @Override + public boolean isOperating(Services service) { + init(); + return operating.containsKey(service); + } + +} -- 1.7.10.2