refs 2521: Explore the possibility to port the StatMan interface onto Dataminer

https://support.d4science.org/issues/2521

Fixed WPS Service access by cache

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/data-miner-manager@128718 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-05-19 17:35:48 +00:00
parent 17fbaf90ca
commit 7309dd2a8f
10 changed files with 152 additions and 56 deletions

View File

@ -11,7 +11,10 @@ import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer;
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.HBoxLayoutAlign;
import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer.HorizontalLayoutData;
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
@ -35,7 +38,7 @@ public class HomePanel extends SimpleContainer {
setItemId("HomePanel");
setStylePrimaryName("smMenu");
//setBodyStyle("backgroundColor:white;");
addStyleName("smLayoutContainer");
//addStyleName("smLayoutContainer");
//setHeaderVisible(false);
setBorders(false);
//setBodyBorder(false);
@ -45,11 +48,17 @@ public class HomePanel extends SimpleContainer {
private void create() {
VerticalLayoutContainer lc = new VerticalLayoutContainer();
lc.setScrollMode(ScrollMode.AUTO);
VerticalLayoutData layoutTop = new VerticalLayoutData(-1, -1,
VerticalLayoutData layoutTop = new VerticalLayoutData(1, -1,
new Margins(20,0,10,0));
VerticalLayoutData layoutNext = new VerticalLayoutData(1, -1,
new Margins(10,0,10,0));
/*
VerticalLayoutData layoutTop = new VerticalLayoutData(1, -1,
new Margins(20, 90, 10, 90));
VerticalLayoutData layoutNext = new VerticalLayoutData(-1, -1,
VerticalLayoutData layoutNext = new VerticalLayoutData(1, -1,
new Margins(10, 90, 10, 90));
*/
SimpleContainer itemDataSpace = createMenuItem(
"Access to the Data Space",
"The data space contains the set of input and output data sets of the users. It is possible to upload and share tables. Data sources can be chosen from those hosted by the infrastructure. Outputs of the computations can be even saved in this space.",
@ -95,27 +104,36 @@ public class HomePanel extends SimpleContainer {
});
lc.add(itemComputations, layoutNext);
add(lc);
}
private SimpleContainer createMenuItem(String title, String description,
ImageResource imgResource, MouseDownHandler handle) {
HorizontalLayoutContainer horiz = new HorizontalLayoutContainer();
HBoxLayoutContainer horiz=new HBoxLayoutContainer(HBoxLayoutAlign.MIDDLE);
horiz.setPack(BoxLayoutPack.CENTER);
horiz.setEnableOverflow(false);
//HorizontalLayoutContainer horiz = new HorizontalLayoutContainer();
Image img = new Image(imgResource);
HTML text = new HTML("<b>" + title + "</b><br>" + description);
text.addStyleName("smMenuItemText");
text.setWidth("400px");
HorizontalLayoutData textLayoutData = new HorizontalLayoutData(400,
140, new Margins(10, 5, 10, 10));
HorizontalLayoutData imgLayoutData = new HorizontalLayoutData(140, 140,
new Margins(10, 10, 10, 5));
horiz.add(text, textLayoutData);
horiz.add(img, imgLayoutData);
//horiz.add(text, textLayoutData);
//horiz.add(img, imgLayoutData);
horiz.add(text, new BoxLayoutData(new Margins(0)));
horiz.add(img,new BoxLayoutData(new Margins(0)));
SimpleContainer container = new SimpleContainer();
container.addDomHandler(handle, MouseDownEvent.getType());
@ -124,7 +142,14 @@ public class HomePanel extends SimpleContainer {
container.addStyleName("smMenuItem");
container.addStyleOnOver(container.getElement(), "smMenuItem:HOVER");
container.add(horiz);
return container;
SimpleContainer container2 = new SimpleContainer();
HBoxLayoutContainer hbox=new HBoxLayoutContainer(HBoxLayoutAlign.MIDDLE);
hbox.setPack(BoxLayoutPack.CENTER);
hbox.setEnableOverflow(false);
hbox.add(container, new BoxLayoutData(new Margins(0)));
container2.add(hbox);
return container2;
}

View File

@ -7,9 +7,8 @@ package org.gcube.portlets.user.dataminermanager.client.dataspace;
*
*/
public enum DataSpacePropertiesType {
COMPUTATION_ID("computation_id"), DATA_DESCRIPTION("data_description"), CREATION_DATE(
"creation_date"), DATA_TYPE("data_type"), OPERATOR_NAME("operator_name"), VRE(
"VRE");
COMPUTATION_ID("computation_id"), DATA_DESCRIPTION("data_description"), DATA_TYPE(
"data_type"), OPERATOR_NAME("operator_name"), VRE("VRE");
/**
* @param text
*/

View File

@ -252,7 +252,7 @@ public class InputDataSetsPanel extends FramedPanel {
wsResourcesExplorerPanel.ensureDebugId("wsResourceExplorerPanel");
VerticalLayoutContainer vResourcesExplorerContainer = new VerticalLayoutContainer();
vResourcesExplorerContainer.setScrollMode(ScrollMode.AUTO);
vResourcesExplorerContainer.setScrollMode(ScrollMode.AUTOY);
vResourcesExplorerContainer.add(wsResourcesExplorerPanel,
new VerticalLayoutData(1, -1, new Margins(0)));

View File

@ -252,7 +252,7 @@ public class OutputDataSetsPanel extends FramedPanel {
wsResourcesExplorerPanel.ensureDebugId("wsResourceExplorerPanel");
VerticalLayoutContainer vResourcesExplorerContainer = new VerticalLayoutContainer();
vResourcesExplorerContainer.setScrollMode(ScrollMode.AUTO);
vResourcesExplorerContainer.setScrollMode(ScrollMode.AUTOY);
vResourcesExplorerContainer.add(wsResourcesExplorerPanel,
new VerticalLayoutData(1, -1, new Margins(0)));

View File

@ -94,7 +94,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
SClient smClient = SessionUtil.getSClient(session, aslSession);
return smClient.getOperatorsClassifications();
List<OperatorsClassification> list= smClient.getOperatorsClassifications();
SessionUtil.putSClient(session, smClient);
return list;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
throw e;
@ -116,8 +118,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
ASLSession aslSession = SessionUtil.getASLSession(session);
SClient smClient = SessionUtil.getSClient(session, aslSession);
return smClient.getInputParameters(operator);
List<Parameter> list=smClient.getInputParameters(operator);
SessionUtil.putSClient(session, smClient);
return list;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
throw e;
@ -137,7 +140,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
ASLSession aslSession = SessionUtil.getASLSession(session);
logger.debug("StartComputation(): [ operator=" + operator + "]");
SClient smClient = SessionUtil.getSClient(session, aslSession);
return smClient.startComputation(operator);
ComputationId computationId= smClient.startComputation(operator);
SessionUtil.putSClient(session, smClient);
return computationId;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
throw e;
@ -160,7 +165,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), itemDescription.getId());
logger.debug("Properties: " + properties);
SClient smClient = SessionUtil.getSClient(session, aslSession);
return smClient.resubmitComputation(properties);
ComputationId computationId= smClient.resubmitComputation(properties);
SessionUtil.putSClient(session, smClient);
return computationId;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
throw e;
@ -180,7 +187,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
ASLSession aslSession = SessionUtil.getASLSession(session);
SClient smClient = SessionUtil.getSClient(session, aslSession);
return smClient.getComputationStatus(computationId);
ComputationStatus computationStatus= smClient.getComputationStatus(computationId);
SessionUtil.putSClient(session, smClient);
return computationStatus;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
@ -205,6 +214,7 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
StorageUtil.deleteItem(aslSession.getUsername(),
itemDescription.getId());
return;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
throw e;
@ -285,7 +295,7 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
logger.debug("CancelComputation(): " + computationId);
SClient smClient = SessionUtil.getSClient(session, aslSession);
String result = smClient.cancelComputation(computationId);
SessionUtil.putSClient(session, smClient);
return result;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
@ -308,6 +318,7 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
SClient smClient = SessionUtil.getSClient(session, aslSession);
OutputData outputData = smClient
.getOutputDataByComputationId(computationId);
SessionUtil.putSClient(session, smClient);
Log.debug("OutputData: " + outputData);
return outputData;
} catch (ServiceException e) {
@ -334,7 +345,11 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
aslSession.getUsername(), itemDescription.getId());
logger.debug("Properties: " + properties);
SClient smClient = SessionUtil.getSClient(session, aslSession);
return smClient.getComputationDataByComputationProperties(properties);
ComputationData computationData= smClient.getComputationDataByComputationProperties(properties);
SessionUtil.putSClient(session, smClient);
return computationData;
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
throw e;

View File

@ -89,13 +89,27 @@ public class SessionUtil {
}
public static void putSClient(HttpSession session, SClient sClient)
throws Exception {
SClient sc = (SClient) session.getAttribute(Constants.SClient);
if (sc == null) {
session.setAttribute(Constants.SClient, sClient);
} else {
session.removeAttribute(Constants.SClient);
session.setAttribute(Constants.SClient, sClient);
}
}
public static SClient getSClient(HttpSession session, ASLSession aslSession)
throws Exception {
SClient sClient = (SClient) session.getAttribute(Constants.SClient);
if (sClient == null) {
logger.info("Created new SClient");
ServiceCredential serviceCredential=new ServiceCredential(aslSession.getUsername(), aslSession.getScope(),
SessionUtil.getToken(aslSession));
SClientBuilder sBuilder = new SClient4WPSBuilder(serviceCredential);
@ -105,6 +119,8 @@ public class SessionUtil {
director.constructSClient();
sClient = director.getSClient();
session.setAttribute(Constants.SClient, sClient);
} else {
logger.info("Use SClient in session");
}
return sClient;

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.dataminermanager.server.smservice;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@ -19,7 +20,10 @@ import org.gcube.portlets.user.dataminermanager.shared.parameters.Parameter;
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public abstract class SClient {
public abstract class SClient implements Serializable{
private static final long serialVersionUID = 7087349607933493388L;
public SClient() {
super();

View File

@ -74,6 +74,8 @@ import org.w3c.dom.NodeList;
*/
public class SClient4WPS extends SClient {
private static final long serialVersionUID = 1909871837115147159L;
private static Logger logger = LoggerFactory.getLogger(SClient4WPS.class);
// private static final int OPERATOR_BRIEF_DESCRIPTION_MAX_LENGHT = 170;
private static final String OTHERS = "OTHERS";
@ -92,6 +94,7 @@ public class SClient4WPS extends SClient {
private StatWPSClientSession wpsClient;
public SClient4WPS(ServiceCredential serviceCredential) throws Exception {
super();
process = new HashMap<>();
@ -155,12 +158,17 @@ public class SClient4WPS extends SClient {
private StatWPSClientSession createWPSClientSession() {
if (wpsClient == null) {
wpsClient = new StatWPSClientSession(wpsUser, wpsToken);
logger.debug("Created StatWPSClientSession");
return wpsClient;
} else {
logger.debug("Use already created StatWPSClientSession");
return wpsClient;
}
}
@Override
public List<OperatorsClassification> getOperatorsClassifications()
throws Exception {
@ -365,6 +373,7 @@ public class SClient4WPS extends SClient {
private String executeProcessAsync(ExecuteRequestBuilder executeBuilder,
ProcessDescriptionType processDescription) throws Exception {
StatWPSClientSession wpsClient = null;
try {
try {
@ -388,8 +397,6 @@ public class SClient4WPS extends SClient {
ExecuteDocument execute = executeBuilder.getExecute();
execute.getExecute().setService("WPS");
// System.out.println("RESPONSE FORM:"+execute.getExecute().getResponseForm());
StatWPSClientSession wpsClient = null;
wpsClient = createWPSClientSession();
wpsClient.connect(wpsProcessingServlet);
logger.debug("Sending: " + execute);
@ -445,6 +452,7 @@ public class SClient4WPS extends SClient {
private ProcessOutputs retrieveProcessResult(String processLocation)
throws Exception {
StatWPSClientSession wpsClient = null;
try {
logger.debug("RetrieveProcessResult: " + processLocation);
wpsClient = createWPSClientSession();
@ -655,8 +663,8 @@ public class SClient4WPS extends SClient {
e.printStackTrace();
throw new Exception(e.getLocalizedMessage());
}
logger.debug("ProcessInformation: "+processInformations);
logger.debug("ProcessInformation: " + processInformations);
List<Parameter> parameters = new ArrayList<>();
@ -831,6 +839,7 @@ public class SClient4WPS extends SClient {
@Override
public ComputationStatus getComputationStatus(ComputationId computationId)
throws Exception {
StatWPSClientSession wpsClient = null;
try {
logger.debug("GetComputationStatus(): ComputationId="
+ computationId);
@ -855,10 +864,9 @@ public class SClient4WPS extends SClient {
if (((ExecuteResponseDocumentImpl) responseObject)
.getExecuteResponse() == null) {
logger.debug("WPS FAILURE: ExecuteResponse is null");
computationStatus = new ComputationStatus(
Status.FAILED, 100f);
} else {
StatusType statusType = ((ExecuteResponseDocumentImpl) responseObject)
@ -1167,6 +1175,7 @@ public class SClient4WPS extends SClient {
@Override
public String cancelComputation(ComputationId computationId)
throws Exception {
StatWPSClientSession wpsClient = null;
try {
wpsClient = createWPSClientSession();

View File

@ -2,13 +2,13 @@ package org.gcube.portlets.user.dataminermanager.server.smservice.wps;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import javax.xml.parsers.DocumentBuilderFactory;
@ -41,18 +41,20 @@ import org.xml.sax.SAXException;
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class StatWPSClientSession {
public class StatWPSClientSession implements Serializable {
private static final long serialVersionUID = -1387670579312851370L;
private static Logger logger = LoggerFactory
.getLogger(StatWPSClientSession.class);
private static final String OGC_OWS_URI = "http://www.opengeospatial.net/ows";
private static String SUPPORTED_VERSION = "1.0.0";
// private static StatWPSClientSession session;
private Map<String, CapabilitiesDocument> loggedServices;
private HashMap<String, CapabilitiesDocument> loggedServices;
private XmlOptions options = null;
// a Map of <url, all available process descriptions>
public Map<String, ProcessDescriptionsDocument> processDescriptions;
public HashMap<String, ProcessDescriptionsDocument> processDescriptions;
private String user;
private String password;
@ -61,6 +63,9 @@ public class StatWPSClientSession {
*
*/
public StatWPSClientSession(String user, String password) {
super();
logger.debug("Create StatWPSClientSession: [user=" + user
+ ", password=" + password + "]");
this.user = user;
this.password = password;
options = new XmlOptions();
@ -80,20 +85,35 @@ public class StatWPSClientSession {
* @return true, if connect succeeded, false else.
* @throws WPSClientException
*/
public boolean connect(String url) throws WPSClientException {
logger.info("CONNECT");
logger.info("CONNECT: " + url);
logger.info("LoggedSevices: " + loggedServices.keySet());
if (loggedServices.containsKey(url)) {
logger.info("Service already registered: " + url);
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.info("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");
@ -127,11 +147,11 @@ public class StatWPSClientSession {
* @param url
*/
public void disconnect(String url) {
if (loggedServices.containsKey(url)) {
loggedServices.remove(url);
processDescriptions.remove(url);
logger.info("service removed successfully: " + url);
}
/*
* if (loggedServices.containsKey(url)) { loggedServices.remove(url);
* processDescriptions.remove(url);
* logger.info("service removed successfully: " + url); }
*/
}
/**
@ -140,7 +160,11 @@ public class StatWPSClientSession {
* @return
*/
public List<String> getLoggedServices() {
return new ArrayList<String>(loggedServices.keySet());
if (loggedServices != null && loggedServices.keySet() != null) {
return new ArrayList<String>(loggedServices.keySet());
} else {
return new ArrayList<String>();
}
}
/**
@ -334,8 +358,10 @@ public class StatWPSClientSession {
private CapabilitiesDocument retrieveCapsViaGET(String url)
throws WPSClientException {
logger.debug("retrieveCapsViaGET: " + url);
ClientCapabiltiesRequest req = new ClientCapabiltiesRequest();
url = req.getRequest(url);
try {
String authString = user + ":" + password;
logger.debug("auth string: " + authString);
@ -351,7 +377,9 @@ public class StatWPSClientSession {
connection.setRequestProperty("Authorization", "Basic " + encoded);
InputStream is = connection.getInputStream();
Document doc = checkInputStream(is);
return CapabilitiesDocument.Factory.parse(doc, options);
CapabilitiesDocument capabilitiesDocument = CapabilitiesDocument.Factory
.parse(doc, options);
return capabilitiesDocument;
} catch (MalformedURLException e) {
e.printStackTrace();
throw new WPSClientException(
@ -410,7 +438,8 @@ public class StatWPSClientSession {
} catch (Throwable e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new WPSClientException(e.getLocalizedMessage(), new Exception(e));
throw new WPSClientException(e.getLocalizedMessage(),
new Exception(e));
}
}
@ -602,11 +631,10 @@ public class StatWPSClientSession {
}
}
public String cancelComputation(String url,String computationId)
public String cancelComputation(String url, String computationId)
throws WPSClientException {
try {
String authString = user + ":" + password;
logger.debug("auth string: " + authString);
@ -614,14 +642,14 @@ public class StatWPSClientSession {
String encoded = new String(authEncBytes);
logger.debug("Base64 encoded auth string: " + encoded);
url+="?id="+computationId;
url += "?id=" + computationId;
URL urlObj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urlObj
.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + encoded);
String responseMessage= connection.getResponseMessage();
String responseMessage = connection.getResponseMessage();
return responseMessage;
} catch (MalformedURLException e) {
e.printStackTrace();
@ -634,6 +662,5 @@ public class StatWPSClientSession {
+ url, e);
}
}
}

View File

@ -31,10 +31,11 @@
}
.smMenu {
width: 720px !important;
height: 570px !important;
/*width: 720px !important;*/
/*height: 570px !important;*/
/*overflow: auto;
margin: auto;
margin-bottom: 20px;
margin-bottom: 20px;*/
}
.layoutContainerArea {