From: Mateusz Warowny Date: Wed, 10 May 2023 09:23:01 +0000 (+0200) Subject: JAL-3954 Implement job dispatcher service discoverer X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2bf65e89ad86e9900a4891a0d0e9bb2cdd54cd5b;p=jalview.git JAL-3954 Implement job dispatcher service discoverer --- diff --git a/src/jalview/ws2/client/ebi/JobDispatcherWSDiscoverer.java b/src/jalview/ws2/client/ebi/JobDispatcherWSDiscoverer.java new file mode 100644 index 0000000..11fbf2a --- /dev/null +++ b/src/jalview/ws2/client/ebi/JobDispatcherWSDiscoverer.java @@ -0,0 +1,106 @@ +package jalview.ws2.client.ebi; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.List; + +import jalview.bin.Console; +import jalview.ws.params.ParamManager; +import jalview.ws2.actions.NullAction; +import jalview.ws2.actions.api.ActionI; +import jalview.ws2.api.WebService; +import jalview.ws2.client.api.AbstractWebServiceDiscoverer; +import uk.ac.dundee.compbio.hmmerclient.PhmmerClient; + +public final class JobDispatcherWSDiscoverer extends AbstractWebServiceDiscoverer +{ + + private static final URL DEFAULT_URL; + static + { + try + { + DEFAULT_URL = new URL("https://www.ebi.ac.uk/Tools/services/rest/hmmer3_phmmer/"); + } catch (MalformedURLException e) + { + throw new ExceptionInInitializerError(e); + } + } + + private static JobDispatcherWSDiscoverer instance = null; + private static ParamManager paramManager = null; + + private JobDispatcherWSDiscoverer() {} + + public static JobDispatcherWSDiscoverer getInstance() { + if (instance == null) + instance = new JobDispatcherWSDiscoverer(); + return instance; + } + + public static void setParamManager(ParamManager manager) + { + paramManager = manager; + } + + @Override + public int getStatusForUrl(URL url) + { + try + { + return new PhmmerClient(url).testEndpoint() ? STATUS_OK : STATUS_INVALID; + } catch (URISyntaxException e) + { + Console.error(e.getMessage()); + return STATUS_INVALID; + } + } + + @Override + protected String getUrlsPropertyKey() + { + return null; + } + + @Override + protected URL getDefaultUrl() + { + return DEFAULT_URL; + } + + @Override + protected List> fetchServices(URL url) throws IOException + { + PhmmerClient client; + try { + client = new PhmmerClient(url); + } + catch (URISyntaxException e) { + throw new MalformedURLException(e.getMessage()); + } + if (!client.testEndpoint()) + throw new IOException( + "unable to reach dispatcher server at " + url); + // TODO change once a concrete action is implemented + var wsBuilder = WebService. newBuilder(); + wsBuilder.url(url); + wsBuilder.clientName("job dispatcher"); + wsBuilder.category("Database search"); + wsBuilder.name("pHMMER"); + wsBuilder.description("Hmmer3 phmmer is used to search one or more query sequences against a sequence database."); + wsBuilder.interactive(false); + wsBuilder.paramDatastore(ParamStores.newPhmmerDatastore(url, paramManager)); + wsBuilder.actionClass(NullAction.class); + var webService = wsBuilder.build(); + + var actionBuilder = NullAction.newBuilder(); + actionBuilder.webService(webService); + actionBuilder.name(""); + webService.addAction(actionBuilder.build()); + + return List.of(webService); + } + +}