From bcb2c33dfed7ffefa3566af8af9383d08a9022ef Mon Sep 17 00:00:00 2001 From: pvtroshin Date: Mon, 13 Jun 2011 15:01:09 +0000 Subject: [PATCH 1/1] Command line options are described and added to the client. Registry is modified to perform test after 24 hours from last test git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4261 e3abac25-378b-4346-85de-24260fe3988d --- testsrc/testdata/aaconprm.txt | 2 ++ webservices/compbio/ws/client/CmdHelper.java | 22 +++++++++++++ webservices/compbio/ws/client/Jws2Client.java | 42 ++++++++++++++++++++++++- webservices/compbio/ws/client/Services.java | 14 +++++++++ webservices/compbio/ws/server/RegistryWS.java | 42 +++++++++++++++++++++++-- 5 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 testsrc/testdata/aaconprm.txt diff --git a/testsrc/testdata/aaconprm.txt b/testsrc/testdata/aaconprm.txt new file mode 100644 index 0000000..fa4f64a --- /dev/null +++ b/testsrc/testdata/aaconprm.txt @@ -0,0 +1,2 @@ +-m=LANDGRAF +-n diff --git a/webservices/compbio/ws/client/CmdHelper.java b/webservices/compbio/ws/client/CmdHelper.java index 1faf3dc..5b33aba 100644 --- a/webservices/compbio/ws/client/CmdHelper.java +++ b/webservices/compbio/ws/client/CmdHelper.java @@ -1,11 +1,13 @@ package compbio.ws.client; import static compbio.ws.client.Constraints.hostkey; import static compbio.ws.client.Constraints.limitList; +import static compbio.ws.client.Constraints.listServices; import static compbio.ws.client.Constraints.paramList; import static compbio.ws.client.Constraints.presetList; import static compbio.ws.client.Constraints.presetkey; import static compbio.ws.client.Constraints.pseparator; import static compbio.ws.client.Constraints.servicekey; +import static compbio.ws.client.Constraints.testKey; class CmdHelper { @@ -32,6 +34,26 @@ class CmdHelper { } /** + * list available services + * + * @param cmd + * @return + */ + static boolean listServices(String[] cmd) { + return keyFound(cmd, listServices); + } + + /** + * tests service + * + * @param cmd + * @return + */ + static boolean testService(String[] cmd) { + return keyFound(cmd, testKey); + } + + /** * Checks whether the key is in the command line * * @param cmd diff --git a/webservices/compbio/ws/client/Jws2Client.java b/webservices/compbio/ws/client/Jws2Client.java index 48d107d..c18f100 100644 --- a/webservices/compbio/ws/client/Jws2Client.java +++ b/webservices/compbio/ws/client/Jws2Client.java @@ -32,6 +32,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.List; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -42,6 +43,7 @@ import javax.xml.ws.WebServiceException; import compbio.data.msa.JABAService; import compbio.data.msa.Metadata; import compbio.data.msa.MsaWS; +import compbio.data.msa.RegistryWS; import compbio.data.msa.SequenceAnnotation; import compbio.data.sequence.Alignment; import compbio.data.sequence.FastaSequence; @@ -115,6 +117,13 @@ public class Jws2Client { System.err.println("Host name is not valid!"); printUsage(1); } + // Just list available services and quit + boolean listServices = CmdHelper.listServices(cmd); + if (listServices) { + listServices(hostname); + System.exit(0); + } + String serviceName = CmdHelper.getServiceName(cmd); if (serviceName == null) { System.err.println("Service name is no provided!"); @@ -123,10 +132,17 @@ public class Jws2Client { Services service = Services.getService(serviceName); if (service == null) { System.err.println("Service " + serviceName - + " is no supported! Valid values are: " + + " is no recognized! Valid values are: " + Arrays.toString(Services.values())); printUsage(1); } + // Test service and quit + boolean testService = CmdHelper.testService(cmd); + if (testService) { + testService(hostname, service); + System.exit(0); + } + File inputFile = IOHelper.getFile(cmd, inputkey, true); File outFile = IOHelper.getFile(cmd, outputkey, false); File parametersFile = IOHelper.getFile(cmd, paramFile, true); @@ -182,6 +198,30 @@ public class Jws2Client { ((Closeable) msaws).close(); log.fine("Disconnected successfully!"); } + + private void testService(String hostname, Services service) + throws IOException { + RegistryWS registry = connectToRegistry(hostname); + if (registry != null) { + String message = registry.testService(service); + System.out.println("Service " + service + " testing results: "); + System.out.println(message); + ((Closeable) registry).close(); + } + } + + private void listServices(String hostname) throws IOException { + RegistryWS registry = connectToRegistry(hostname); + if (registry != null) { + Set services = registry.getSupportedServices(); + System.out.println("Supported services are: " + + Services.toString(services)); + ((Closeable) registry).close(); + } else { + System.out.println("Failed to connect to the registry! "); + } + } + /** * Calculate conservation for sequences loaded from the file * diff --git a/webservices/compbio/ws/client/Services.java b/webservices/compbio/ws/client/Services.java index 01b4827..3c55c18 100644 --- a/webservices/compbio/ws/client/Services.java +++ b/webservices/compbio/ws/client/Services.java @@ -20,6 +20,7 @@ package compbio.ws.client; import java.io.File; import java.net.URL; +import java.util.Set; import javax.xml.namespace.QName; import javax.xml.ws.Service; @@ -132,6 +133,19 @@ public enum Services { return Service.create(url, qname); } + public static String toString(Set services) { + if (services == null || services.isEmpty()) { + return ""; + } + String value = ""; + String delim = ", "; + for (Services serv : services) { + value += serv.toString() + delim; + } + value = value.substring(0, value.length() - delim.length()); + return value; + } + Class getServiceType() { switch (this) { // deliberate leaking diff --git a/webservices/compbio/ws/server/RegistryWS.java b/webservices/compbio/ws/server/RegistryWS.java index dda265e..0ff4294 100644 --- a/webservices/compbio/ws/server/RegistryWS.java +++ b/webservices/compbio/ws/server/RegistryWS.java @@ -35,8 +35,16 @@ public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService { private static Logger log = Logger.getLogger(RegistryWS.class); + /** + * Stores tested and passed (the test) services and their testing time + */ private final static Map operating = new ConcurrentHashMap(); + /** + * Indicate whether the services were tested at all + */ + private static boolean allTested = false; + @Override public Set getSupportedServices() { init(); @@ -44,16 +52,44 @@ public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService { } private void init() { - // This should not be run concurrently - if (operating.isEmpty()) { + // Do not allow tests to run concurrently + if (timeToTest()) { synchronized (operating) { - if (operating.isEmpty()) { + if (timeToTest()) { testAllServices(); + allTested = true; } } } } + private boolean timeToTest() { + if (!allTested) { + return true; + } + // 24 h + if (getLongestUntestedServiceTime() > 3600 * 24) { + return true; + } + return false; + } + + /** + * Return time in seconds for the test for the oldest unchecked service + * + * @return + */ + private int getLongestUntestedServiceTime() { + int timePassed = 0; + for (Services serv : operating.keySet()) { + int lasttimepassed = getLastTested(serv); + if (timePassed < lasttimepassed) { + timePassed = lasttimepassed; + } + } + return timePassed; + } + @Override public int getLastTested(Services service) { Date testedOn = getLastTestedOn(service); -- 1.7.10.2