From 22b3cff88b85a5de0689193bacdc967a3b24ec67 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 8 May 2018 09:03:12 +0000 Subject: [PATCH] ref 11741: DataMiner - Add refresh button in operators panel https://support.d4science.org/issues/11741 Operators refresh support is added git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/data-miner-manager-cl@167359 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 1 + .../server/dmservice/SClient.java | 11 ++ .../server/dmservice/SClient4WPS.java | 19 ++- .../dmservice/wps/SClient4WPSSession.java | 130 ++++++++++++------ .../dataminermanagercl/shared/Constants.java | 7 - .../shared/perspective/PerspectiveType.java | 74 ++++++++++ 6 files changed, 187 insertions(+), 55 deletions(-) create mode 100644 src/main/java/org/gcube/data/analysis/dataminermanagercl/shared/perspective/PerspectiveType.java diff --git a/distro/changelog.xml b/distro/changelog.xml index 8cb5e3f..492dfa2 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -2,6 +2,7 @@ Updated to support netcdf files + Added support for operators refresh[ticket #11741] diff --git a/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/SClient.java b/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/SClient.java index 036266c..c4ea41c 100644 --- a/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/SClient.java +++ b/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/SClient.java @@ -37,6 +37,17 @@ public abstract class SClient implements Serializable { */ public abstract List getOperatorsClassifications() throws Exception; + /** + * Retrieve the list of operators and refresh them if required + * + * @param refresh + * refresh operators in cache + * @return list of operators classification + * @throws Exception + * exception + */ + public abstract List getOperatorsClassifications(boolean refresh) throws Exception; + /** * Retrieve the operator by id * diff --git a/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/SClient4WPS.java b/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/SClient4WPS.java index ad381cc..6bd4e7e 100644 --- a/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/SClient4WPS.java +++ b/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/SClient4WPS.java @@ -57,6 +57,7 @@ import org.gcube.data.analysis.dataminermanagercl.shared.parameters.FileParamete import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ObjectParameter; import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter; import org.gcube.data.analysis.dataminermanagercl.shared.parameters.TabularListParameter; +import org.gcube.data.analysis.dataminermanagercl.shared.perspective.PerspectiveType; import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus; import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus.Status; import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator; @@ -269,11 +270,16 @@ public class SClient4WPS extends SClient { @Override public List getOperatorsClassifications() throws ServiceException { - + return getOperatorsClassifications(false); + } + + @Override + public List getOperatorsClassifications(boolean refresh) throws ServiceException{ + logger.debug("getOperatorsClassifications: "+refresh); LinkedHashMap operatorsToCategoriesMap = new LinkedHashMap<>(); LinkedHashMap> categoriesToOperatorsMap = new LinkedHashMap<>(); - requestCapability(); + requestCapability(refresh); if (processesBriefs == null || processesDescriptionType == null) { throw new ServiceException("Algorithms WPS not available!"); } @@ -348,14 +354,15 @@ public class SClient4WPS extends SClient { List operatorsClass = new ArrayList<>(); - OperatorsClassification op = new OperatorsClassification(Constants.UserClassificationName, categories, + OperatorsClassification op = new OperatorsClassification(PerspectiveType.User.getPerspective(), categories, operators); operatorsClass.add(op); - // logger.debug("OperatorClass: " + operatorsClass); + logger.debug("OperatorClass: " + operatorsClass); return operatorsClass; } + private ProcessInformations describeProcess(String processId) throws ServiceException { return describeProcess(processId, null); @@ -418,7 +425,7 @@ public class SClient4WPS extends SClient { } } - private void requestCapability() throws ServiceException { + private void requestCapability(boolean refresh) throws ServiceException { SClient4WPSSession wpsClient = null; processesDescriptionType = null; processesBriefs = null; @@ -426,7 +433,7 @@ public class SClient4WPS extends SClient { try { wpsClient = createWPSClientSession(); - wpsClient.connect(wpsProcessingServlet); + wpsClient.connect(wpsProcessingServlet,refresh); processesDescriptionType = wpsClient.getAllProcessDescriptions(wpsProcessingServlet); diff --git a/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/wps/SClient4WPSSession.java b/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/wps/SClient4WPSSession.java index 03a395e..4f79f5a 100644 --- a/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/wps/SClient4WPSSession.java +++ b/src/main/java/org/gcube/data/analysis/dataminermanagercl/server/dmservice/wps/SClient4WPSSession.java @@ -66,8 +66,10 @@ public class SClient4WPSSession implements Serializable { /** * Initializes a WPS client session. * - * @param user user - * @param password password + * @param user + * user + * @param password + * password */ public SClient4WPSSession(String user, String password) { super(); @@ -94,35 +96,75 @@ public class SClient4WPSSession implements Serializable { */ public boolean connect(String url) throws WPSClientException { + return connect(url, false); + } + + public boolean connect(String url, boolean refresh) throws WPSClientException { logger.info("CONNECT: " + url); - logger.debug("LoggedSevices: " + loggedServices.keySet()); - if (loggedServices.containsKey(url)) { - logger.debug("Service already registered: " + url); + logger.info("Service refresh: " + refresh); + if (refresh) { + logger.debug("LoggedServices: " + loggedServices.keySet()); + if (loggedServices.containsKey(url)) { + loggedServices.remove(url); + } + if(processDescriptions.containsKey(url)){ + processDescriptions.remove(url); + } + + CapabilitiesDocument capsDoc = retrieveCapsViaGET(url); + if (capsDoc != null) { + logger.debug("Adding caps to logged services " + url); + loggedServices.put(url, capsDoc); + logger.debug("Logged Services key: " + loggedServices.keySet()); + } else { + logger.error("CapsDoc is null!"); + } + + ProcessDescriptionsDocument processDescs = describeAllProcesses(url); + if (processDescs != null && capsDoc != null) { + logger.debug("Adding processes descriptions to logged services " + url); + processDescriptions.put(url, processDescs); + logger.debug("ProcessDescriptions key: " + processDescriptions.keySet()); + return true; + + } else { + logger.error("ProcessDescs is null!"); + } + logger.warn("retrieving caps failed, caps are null"); + return false; + } else { + logger.debug("LoggedServices: " + loggedServices.keySet()); + boolean registered = loggedServices.containsKey(url); + if (registered) { + logger.debug("Service already registered: " + url); + return false; + } else { + logger.debug("Service not registered"); + } + + CapabilitiesDocument capsDoc = retrieveCapsViaGET(url); + if (capsDoc != null) { + logger.debug("Adding caps to logged services " + url); + loggedServices.put(url, capsDoc); + logger.debug("Logged Services key: " + loggedServices.keySet()); + } else { + logger.error("CapsDoc is null!"); + } + + ProcessDescriptionsDocument processDescs = describeAllProcesses(url); + if (processDescs != null && capsDoc != null) { + logger.debug("Adding processes descriptions to logged services " + url); + processDescriptions.put(url, processDescs); + logger.debug("ProcessDescriptions key: " + processDescriptions.keySet()); + return true; + + } else { + logger.error("ProcessDescs is null!"); + } + logger.warn("retrieving caps failed, caps are null"); return false; } - logger.debug("Service not registered"); - CapabilitiesDocument capsDoc = retrieveCapsViaGET(url); - if (capsDoc != null) { - logger.debug("Adding caps to logged services " + url); - loggedServices.put(url, capsDoc); - logger.debug("Logged Services key: " + loggedServices.keySet()); - } else { - logger.error("CapsDoc is null!"); - } - ProcessDescriptionsDocument processDescs = describeAllProcesses(url); - if (processDescs != null && capsDoc != null) { - logger.debug("Adding processes descriptions to logged services " + url); - processDescriptions.put(url, processDescs); - logger.debug("ProcessDescriptions key: " + processDescriptions.keySet()); - return true; - - } else { - logger.error("ProcessDescs is null!"); - } - - logger.warn("retrieving caps failed, caps are null"); - return false; } /** @@ -196,7 +238,8 @@ public class SClient4WPSSession implements Serializable { * @throws IOException * IOException */ - private ProcessDescriptionsDocument getProcessDescriptionsFromCache(String wpsUrl) throws IOException { + private ProcessDescriptionsDocument getProcessDescriptionsFromCache(String wpsUrl) + throws IOException { if (!descriptionsAvailableInCache(wpsUrl)) { try { connect(wpsUrl); @@ -329,7 +372,8 @@ public class SClient4WPSSession implements Serializable { * true if is raw data * @return either an ExecuteResponseDocument or an InputStream if asked for * RawData or an Exception Report - * @throws WPSClientException WPSClientException + * @throws WPSClientException + * WPSClientException */ private Object execute(String serverID, ExecuteDocument execute, boolean rawData) throws WPSClientException { CapabilitiesDocument caps = loggedServices.get(serverID); @@ -376,7 +420,7 @@ public class SClient4WPSSession implements Serializable { logger.debug("retrieveCapsViaGET: " + url); ClientCapabiltiesRequest req = new ClientCapabiltiesRequest(); url = req.getRequest(url); - + logger.debug("url req: "+url); try { String authString = user + ":" + password; logger.debug("auth string: " + authString); @@ -389,18 +433,19 @@ public class SClient4WPSSession implements Serializable { connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setRequestProperty("Authorization", "Basic " + encoded); + logger.debug("Request: "+connection.toString()); InputStream is = connection.getInputStream(); Document doc = checkInputStream(is); CapabilitiesDocument capabilitiesDocument = CapabilitiesDocument.Factory.parse(doc, options); return capabilitiesDocument; } catch (MalformedURLException e) { - e.printStackTrace(); + logger.error(e.getLocalizedMessage(),e); throw new WPSClientException("Capabilities URL seems to be unvalid: " + url, e); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getLocalizedMessage(),e); throw new WPSClientException("Error occured while retrieving capabilities from url: " + url, e); } catch (XmlException e) { - e.printStackTrace(); + logger.error(e.getLocalizedMessage(),e); throw new WPSClientException("Error occured while parsing XML", e); } } @@ -459,16 +504,17 @@ public class SClient4WPSSession implements Serializable { return processDescriptionsDocument; } catch (MalformedURLException e) { - logger.error("URL seems not to be valid: "+e.getLocalizedMessage(),e); - throw new WPSClientException("URL seems not to be valid: "+e.getLocalizedMessage(), e); + logger.error("URL seems not to be valid: " + e.getLocalizedMessage(), e); + throw new WPSClientException("URL seems not to be valid: " + e.getLocalizedMessage(), e); } catch (IOException e) { - logger.error("Error occured while receiving data: "+e.getLocalizedMessage(),e); - throw new WPSClientException("Error occured while receiving data: "+e.getLocalizedMessage(), e); + logger.error("Error occured while receiving data: " + e.getLocalizedMessage(), e); + throw new WPSClientException("Error occured while receiving data: " + e.getLocalizedMessage(), e); } catch (XmlException e) { - logger.error("Error occured while parsing ProcessDescription document: "+e.getLocalizedMessage(),e); - throw new WPSClientException("Error occured while parsing ProcessDescription document: "+e.getLocalizedMessage(), e); + logger.error("Error occured while parsing ProcessDescription document: " + e.getLocalizedMessage(), e); + throw new WPSClientException( + "Error occured while parsing ProcessDescription document: " + e.getLocalizedMessage(), e); } catch (Throwable e) { - logger.error(e.getLocalizedMessage(),e); + logger.error(e.getLocalizedMessage(), e); throw new WPSClientException(e.getLocalizedMessage(), new Exception(e)); } } @@ -537,7 +583,7 @@ public class SClient4WPSSession implements Serializable { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - + conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "Basic " + encoded); conn.setRequestProperty("Accept-Encoding", "gzip"); @@ -550,7 +596,7 @@ public class SClient4WPSSession implements Serializable { logger.debug("Read encoding GZIP"); input = new GZIPInputStream(conn.getInputStream()); } else { - logger.debug("Read encoding: "+encoding); + logger.debug("Read encoding: " + encoding); input = conn.getInputStream(); } return input; diff --git a/src/main/java/org/gcube/data/analysis/dataminermanagercl/shared/Constants.java b/src/main/java/org/gcube/data/analysis/dataminermanagercl/shared/Constants.java index ce4425d..d179601 100644 --- a/src/main/java/org/gcube/data/analysis/dataminermanagercl/shared/Constants.java +++ b/src/main/java/org/gcube/data/analysis/dataminermanagercl/shared/Constants.java @@ -16,13 +16,6 @@ public class Constants { public static final String DATAMINER_SERVICE_CATEGORY = "DataAnalysis"; public static final String DATA_MINER_SERVICE_NAME = "DataMiner"; - - - public static final String[] ClassificationNames = { "User Perspective" }; - // "Computation Perspective"}; - public static final String UserClassificationName = ClassificationNames[0]; - // public final static String computationClassificationName = - // classificationNames[1]; // WPS Data Miner public static final String WPSWebProcessingService = "WebProcessingService"; diff --git a/src/main/java/org/gcube/data/analysis/dataminermanagercl/shared/perspective/PerspectiveType.java b/src/main/java/org/gcube/data/analysis/dataminermanagercl/shared/perspective/PerspectiveType.java new file mode 100644 index 0000000..8cd0e28 --- /dev/null +++ b/src/main/java/org/gcube/data/analysis/dataminermanagercl/shared/perspective/PerspectiveType.java @@ -0,0 +1,74 @@ +package org.gcube.data.analysis.dataminermanagercl.shared.perspective; + +import java.util.Arrays; +import java.util.List; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public enum PerspectiveType { + + User("User", "User Perspective"), Computation("Computation", "Computation Persperctive"); + + /** + * + * @param label + * label + */ + private PerspectiveType(final String label, final String perspective) { + this.label = label; + this.perspective = perspective; + } + + private final String label; + private final String perspective; + + @Override + public String toString() { + return "PerspectiveType [label=" + label + ", perspective=" + perspective + "]"; + } + + public String getLabel() { + return label; + } + + public String getPerspective() { + return perspective; + } + + public String getId() { + return name(); + } + + public static PerspectiveType getFromLabel(String label) { + if (label == null || label.isEmpty()) + return null; + + for (PerspectiveType type : values()) { + if (type.label.compareToIgnoreCase(label) == 0) { + return type; + } + } + return null; + } + + public static PerspectiveType getFromPerspective(String perspective) { + if (perspective == null || perspective.isEmpty()) + return null; + + for (PerspectiveType type : values()) { + if (type.perspective.compareToIgnoreCase(perspective) == 0) { + return type; + } + } + return null; + } + + public static List asList() { + List list = Arrays.asList(values()); + return list; + } +}