2016-09-14 14:27:54 +02:00
|
|
|
package org.gcube.portlets.user.dataminermanager.server.dmservice;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-05-05 18:54:15 +02:00
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.InputStream;
|
2017-02-20 17:05:19 +01:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2016-04-06 18:28:32 +02:00
|
|
|
import java.math.BigInteger;
|
|
|
|
import java.net.URL;
|
2017-02-20 17:05:19 +01:00
|
|
|
import java.net.URLEncoder;
|
2016-04-06 18:28:32 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2016-05-10 17:58:09 +02:00
|
|
|
import java.util.Date;
|
2016-04-27 18:41:39 +02:00
|
|
|
import java.util.HashMap;
|
2016-04-06 18:28:32 +02:00
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2017-03-27 18:55:23 +02:00
|
|
|
import net.opengis.ows.x11.OperationDocument.Operation;
|
2016-04-06 18:28:32 +02:00
|
|
|
import net.opengis.wps.x100.CapabilitiesDocument;
|
|
|
|
import net.opengis.wps.x100.ComplexDataType;
|
|
|
|
import net.opengis.wps.x100.ExecuteDocument;
|
|
|
|
import net.opengis.wps.x100.ExecuteResponseDocument;
|
|
|
|
import net.opengis.wps.x100.ExecuteResponseDocument.ExecuteResponse.ProcessOutputs;
|
|
|
|
import net.opengis.wps.x100.InputDescriptionType;
|
|
|
|
import net.opengis.wps.x100.InputType;
|
|
|
|
import net.opengis.wps.x100.OutputDataType;
|
|
|
|
import net.opengis.wps.x100.OutputDescriptionType;
|
|
|
|
import net.opengis.wps.x100.ProcessBriefType;
|
|
|
|
import net.opengis.wps.x100.ProcessDescriptionType;
|
|
|
|
import net.opengis.wps.x100.ResponseDocumentType;
|
|
|
|
import net.opengis.wps.x100.StatusType;
|
|
|
|
import net.opengis.wps.x100.SupportedComplexDataInputType;
|
|
|
|
import net.opengis.wps.x100.impl.ExecuteResponseDocumentImpl;
|
|
|
|
|
|
|
|
import org.apache.xmlbeans.XmlString;
|
2016-09-14 14:27:54 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.server.dmservice.wps.ProcessInformations;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.server.dmservice.wps.ResponseWPS;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.server.dmservice.wps.SClient4WPSSession;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.server.dmservice.wps.WPS2DM;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.server.dmservice.wps.computationsvalue.ComputationValueBuilder;
|
2016-04-06 18:28:32 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.server.is.InformationSystemUtils;
|
2016-05-05 18:54:15 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil;
|
2016-11-25 16:10:40 +01:00
|
|
|
import org.gcube.portlets.user.dataminermanager.server.util.ServiceCredentials;
|
2016-04-06 18:28:32 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.Constants;
|
2016-05-10 17:58:09 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.OutputData;
|
2016-05-12 19:20:39 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationData;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationId;
|
2016-08-04 16:48:38 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationItemPropertiesValue;
|
2016-05-12 19:20:39 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationValue;
|
2016-05-10 17:58:09 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.output.FileResource;
|
2016-05-12 19:20:39 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.output.ImageResource;
|
2016-05-10 17:58:09 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.output.MapResource;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.output.ObjectResource;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.data.output.Resource;
|
2016-10-06 14:54:25 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException;
|
2017-11-09 18:04:16 +01:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.parameters.FileParameter;
|
2016-05-10 17:58:09 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.parameters.ObjectParameter;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.parameters.Parameter;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.parameters.TabularListParameter;
|
2016-09-14 14:27:54 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.process.ComputationStatus;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.process.Operator;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.process.OperatorCategory;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.process.OperatorsClassification;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.process.ComputationStatus.Status;
|
2016-04-06 18:28:32 +02:00
|
|
|
import org.n52.wps.client.ExecuteRequestBuilder;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.w3c.dom.NamedNodeMap;
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
import org.w3c.dom.NodeList;
|
|
|
|
|
|
|
|
/**
|
2016-09-14 14:27:54 +02:00
|
|
|
* Client 4 WPS Service
|
2016-04-06 18:28:32 +02:00
|
|
|
*
|
|
|
|
*
|
2017-05-12 11:58:15 +02:00
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
2016-04-06 18:28:32 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class SClient4WPS extends SClient {
|
|
|
|
|
2016-05-19 19:35:48 +02:00
|
|
|
private static final long serialVersionUID = 1909871837115147159L;
|
2016-04-06 18:28:32 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(SClient4WPS.class);
|
2016-04-27 18:41:39 +02:00
|
|
|
// private static final int OPERATOR_BRIEF_DESCRIPTION_MAX_LENGHT = 170;
|
2016-04-06 18:28:32 +02:00
|
|
|
private static final String OTHERS = "OTHERS";
|
|
|
|
|
|
|
|
private String wpsToken;
|
|
|
|
private String wpsUser;
|
|
|
|
// private String wpsServiceURL;
|
|
|
|
private String wpsProcessingServlet;
|
|
|
|
private String wpsCancelComputationServlet;
|
|
|
|
|
|
|
|
private ProcessDescriptionType[] processesDescriptionType;
|
2016-04-27 18:41:39 +02:00
|
|
|
private ProcessBriefType[] processesBriefs;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-04-27 18:41:39 +02:00
|
|
|
private HashMap<String, ProcessInformations> process;
|
|
|
|
private HashMap<ComputationId, ProcessInformations> runningProcess;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-09-14 14:27:54 +02:00
|
|
|
private SClient4WPSSession wpsClient;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param serviceCredentials
|
|
|
|
* sevice credentials
|
|
|
|
* @throws ServiceException
|
|
|
|
* ServiceException
|
|
|
|
*/
|
|
|
|
public SClient4WPS(ServiceCredentials serviceCredentials) throws ServiceException {
|
2016-04-06 18:28:32 +02:00
|
|
|
super();
|
2016-04-27 18:41:39 +02:00
|
|
|
process = new HashMap<>();
|
|
|
|
runningProcess = new HashMap<>();
|
2017-11-09 18:04:16 +01:00
|
|
|
if (serviceCredentials == null) {
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.error("Error credetials are null!");
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Error credetials are null!");
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
String token = serviceCredentials.getToken();
|
2016-04-06 18:28:32 +02:00
|
|
|
if (token == null || token.isEmpty()) {
|
|
|
|
logger.error("Error authorization token invalid: " + token);
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Error authorization token invalid: " + token);
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
|
|
|
wpsToken = token;
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
String userName = serviceCredentials.getUserName();
|
2016-04-06 18:28:32 +02:00
|
|
|
if (userName == null || userName.isEmpty()) {
|
|
|
|
logger.error("Error invalid user name: " + userName);
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Error invalid user name: " + userName);
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
|
|
|
wpsUser = userName;
|
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
List<String> serviceAddress;
|
|
|
|
try {
|
|
|
|
serviceAddress = InformationSystemUtils.retrieveServiceAddress(Constants.DATAMINER_SERVICE_CATEGORY,
|
|
|
|
Constants.DATA_MINER_SERVICE_NAME, serviceCredentials.getScope());
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error retrieving service address: " + e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("Service Address retrieved:" + serviceAddress);
|
|
|
|
if (serviceAddress == null || serviceAddress.size() < 1) {
|
|
|
|
logger.error("No DataMiner service address available!");
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("No DataMiner service address available!");
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.info("DataMiner service address found: " + serviceAddress.get(0));
|
2016-04-06 18:28:32 +02:00
|
|
|
wpsProcessingServlet = serviceAddress.get(0);
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
int wpsWebProcessingServiceIndex = wpsProcessingServlet.indexOf(Constants.WPSWebProcessingService);
|
2016-04-06 18:28:32 +02:00
|
|
|
if (wpsWebProcessingServiceIndex > 0) {
|
2017-11-09 18:04:16 +01:00
|
|
|
String wpsServiceUrl = wpsProcessingServlet.substring(0, wpsWebProcessingServiceIndex);
|
|
|
|
wpsCancelComputationServlet = wpsServiceUrl + Constants.WPSCancelComputationServlet;
|
|
|
|
logger.debug("Cancel computation servlet: " + wpsCancelComputationServlet);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
logger.error("Cancel computation servlet not available!");
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Cancel computation servlet not available!");
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:27:54 +02:00
|
|
|
private SClient4WPSSession createWPSClientSession() {
|
2016-04-06 18:28:32 +02:00
|
|
|
if (wpsClient == null) {
|
2016-09-14 14:27:54 +02:00
|
|
|
wpsClient = new SClient4WPSSession(wpsUser, wpsToken);
|
2016-05-19 19:35:48 +02:00
|
|
|
logger.debug("Created StatWPSClientSession");
|
2016-04-06 18:28:32 +02:00
|
|
|
return wpsClient;
|
|
|
|
} else {
|
2016-05-19 19:35:48 +02:00
|
|
|
logger.debug("Use already created StatWPSClientSession");
|
2016-04-06 18:28:32 +02:00
|
|
|
return wpsClient;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-09 18:04:16 +01:00
|
|
|
public List<OperatorsClassification> getOperatorsClassifications() throws ServiceException {
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
LinkedHashMap<String, String> operatorsToCategoriesMap = new LinkedHashMap<>();
|
|
|
|
LinkedHashMap<String, List<Operator>> categoriesToOperatorsMap = new LinkedHashMap<>();
|
|
|
|
|
2016-04-27 18:41:39 +02:00
|
|
|
requestCapability();
|
|
|
|
if (processesBriefs == null || processesDescriptionType == null) {
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Algorithms WPS not available!");
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
2016-04-27 18:41:39 +02:00
|
|
|
for (ProcessBriefType processBrief : processesBriefs) {
|
2016-04-06 18:28:32 +02:00
|
|
|
String categoryTitle = processBrief.getTitle().getStringValue();
|
|
|
|
String categoryName;
|
|
|
|
if (categoryTitle == null || categoryTitle.isEmpty()) {
|
|
|
|
categoryName = OTHERS;
|
|
|
|
} else {
|
|
|
|
String[] categorySplitted = categoryTitle.split(":");
|
|
|
|
if (categorySplitted.length < 1) {
|
|
|
|
categoryName = OTHERS;
|
|
|
|
} else {
|
|
|
|
categoryName = categorySplitted[0];
|
|
|
|
}
|
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
operatorsToCategoriesMap.put(processBrief.getIdentifier().getStringValue(), categoryName);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String briefDescription;
|
|
|
|
for (ProcessBriefType processDescriptionType : processesDescriptionType) {
|
2017-11-09 18:04:16 +01:00
|
|
|
briefDescription = processDescriptionType.getAbstract().getStringValue();
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
String categoryName = operatorsToCategoriesMap.get(processDescriptionType.getIdentifier().getStringValue());
|
2016-04-06 18:28:32 +02:00
|
|
|
if (categoryName == null || categoryName.isEmpty()) {
|
|
|
|
categoryName = OTHERS;
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
List<Operator> listOperators = categoriesToOperatorsMap.get(categoryName);
|
2016-04-06 18:28:32 +02:00
|
|
|
if (listOperators == null) {
|
|
|
|
listOperators = new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
listOperators.add(new Operator(processDescriptionType.getIdentifier().getStringValue(),
|
|
|
|
processDescriptionType.getTitle().getStringValue(), briefDescription,
|
|
|
|
processDescriptionType.getAbstract().getStringValue(), null));
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
categoriesToOperatorsMap.put(categoryName, listOperators);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<OperatorCategory> categories = new ArrayList<>();
|
|
|
|
List<Operator> operators = new ArrayList<>();
|
|
|
|
|
|
|
|
Comparator<OperatorCategory> categoriesComparator = new Comparator<OperatorCategory>() {
|
|
|
|
public int compare(OperatorCategory c1, OperatorCategory c2) {
|
|
|
|
return c1.getName().compareTo(c2.getName()); // use your logic
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Comparator<Operator> operatorsComparator = new Comparator<Operator>() {
|
|
|
|
public int compare(Operator c1, Operator c2) {
|
|
|
|
return c1.getName().compareTo(c2.getName()); // use your logic
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (String categoryName : categoriesToOperatorsMap.keySet()) {
|
2017-11-09 18:04:16 +01:00
|
|
|
OperatorCategory category = new OperatorCategory(categoryName, categoryName, categoryName);
|
|
|
|
List<Operator> listOperators = categoriesToOperatorsMap.get(categoryName);
|
2016-04-06 18:28:32 +02:00
|
|
|
for (Operator operator : listOperators) {
|
|
|
|
operator.setCategory(category);
|
|
|
|
}
|
|
|
|
Collections.sort(listOperators, operatorsComparator);
|
|
|
|
category.setOperators(listOperators);
|
|
|
|
operators.addAll(listOperators);
|
|
|
|
categories.add(category);
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(operators, operatorsComparator);
|
|
|
|
Collections.sort(categories, categoriesComparator);
|
|
|
|
|
|
|
|
List<OperatorsClassification> operatorsClass = new ArrayList<>();
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
OperatorsClassification op = new OperatorsClassification(Constants.UserClassificationName, categories,
|
|
|
|
operators);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
operatorsClass.add(op);
|
|
|
|
|
2016-08-04 15:34:52 +02:00
|
|
|
// logger.debug("OperatorClass: " + operatorsClass);
|
2016-04-06 18:28:32 +02:00
|
|
|
return operatorsClass;
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private ProcessInformations describeProcess(String processId) throws ServiceException {
|
2016-04-27 18:41:39 +02:00
|
|
|
return describeProcess(processId, null);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private ProcessInformations describeProcess(String processId, URL processDescriptionURL) throws ServiceException {
|
2016-04-27 18:41:39 +02:00
|
|
|
if (process.containsKey(processId)) {
|
|
|
|
return process.get(processId);
|
|
|
|
}
|
|
|
|
|
2016-09-14 14:27:54 +02:00
|
|
|
SClient4WPSSession wpsClient = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
|
|
|
wpsClient = createWPSClientSession();
|
|
|
|
|
|
|
|
logger.debug("Describe Process WPS URL: " + wpsProcessingServlet);
|
|
|
|
ProcessDescriptionType processDescription = null;
|
|
|
|
for (int k = 0; k <= 3; k++) {
|
|
|
|
try {
|
2017-11-09 18:04:16 +01:00
|
|
|
processDescription = wpsClient.getProcessDescription(wpsProcessingServlet, processId);
|
2016-05-06 18:26:00 +02:00
|
|
|
} catch (Throwable e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error getProcessDescription for process " + processId + " with WPS URL: "
|
2016-04-06 18:28:32 +02:00
|
|
|
+ wpsProcessingServlet);
|
|
|
|
if (k == 3)
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
if (processDescription != null)
|
|
|
|
break;
|
|
|
|
}
|
2016-04-27 18:41:39 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
ProcessInformations processInformations = new ProcessInformations(processDescription);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
if (processDescriptionURL != null)
|
2017-11-09 18:04:16 +01:00
|
|
|
processDescription.set(XmlString.Factory.parse(processDescriptionURL));
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-05-09 18:57:18 +02:00
|
|
|
logger.debug("ProcessDescription: " + processDescription);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
InputDescriptionType[] inputList = processDescription.getDataInputs().getInputArray();
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("WPSClient->Fetching Inputs");
|
|
|
|
for (InputDescriptionType input : inputList) {
|
|
|
|
logger.debug("WPSClient->Input: " + input);
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
OutputDescriptionType[] outputList = processDescription.getProcessOutputs().getOutputArray();
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("WPSClient->Fetching Outputs");
|
|
|
|
for (OutputDescriptionType output : outputList) {
|
|
|
|
logger.debug("WPSClient->Output: " + output);
|
|
|
|
}
|
|
|
|
|
2016-04-27 18:41:39 +02:00
|
|
|
processInformations.setInputs(inputList);
|
|
|
|
processInformations.setOutputs(outputList);
|
|
|
|
|
|
|
|
process.put(processId, processInformations);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-04-27 18:41:39 +02:00
|
|
|
return processInformations;
|
2016-05-04 20:24:07 +02:00
|
|
|
} catch (Throwable e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error(e.getLocalizedMessage(),e);
|
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-04-06 18:28:32 +02:00
|
|
|
} finally {
|
|
|
|
wpsClient.disconnect(wpsProcessingServlet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private void requestCapability() throws ServiceException {
|
2016-09-14 14:27:54 +02:00
|
|
|
SClient4WPSSession wpsClient = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
processesDescriptionType = null;
|
2016-04-27 18:41:39 +02:00
|
|
|
processesBriefs = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
wpsClient = createWPSClientSession();
|
|
|
|
|
|
|
|
wpsClient.connect(wpsProcessingServlet);
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
processesDescriptionType = wpsClient.getAllProcessDescriptions(wpsProcessingServlet);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
CapabilitiesDocument capabilitiesDocument = wpsClient.getWPSCaps(wpsProcessingServlet);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
Operation[] operations = capabilitiesDocument.getCapabilities().getOperationsMetadata().getOperationArray();
|
2017-03-27 18:55:23 +02:00
|
|
|
for (Operation operation : operations) {
|
2017-11-09 18:04:16 +01:00
|
|
|
operation.getDCPArray()[0].getHTTP().getPostArray()[0].setHref(wpsProcessingServlet + "?");
|
2017-03-27 18:55:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
processesBriefs = capabilitiesDocument.getCapabilities().getProcessOfferings().getProcessArray();
|
2016-04-06 18:28:32 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
2016-08-04 15:34:52 +02:00
|
|
|
logger.error("RequestCapability(): " + e.getLocalizedMessage());
|
2016-04-06 18:28:32 +02:00
|
|
|
e.printStackTrace();
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-04-06 18:28:32 +02:00
|
|
|
} finally {
|
|
|
|
if (wpsClient != null) {
|
|
|
|
wpsClient.disconnect(wpsProcessingServlet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private String executeProcessAsync(ExecuteRequestBuilder executeBuilder, ProcessDescriptionType processDescription)
|
|
|
|
throws ServiceException {
|
2016-09-14 14:27:54 +02:00
|
|
|
SClient4WPSSession wpsClient = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
OutputDescriptionType[] odts = processDescription.getProcessOutputs().getOutputArray();
|
2016-04-06 18:28:32 +02:00
|
|
|
for (OutputDescriptionType odt : odts) {
|
|
|
|
// executeBuilder.setMimeTypeForOutput("text/xml",
|
|
|
|
// "result");
|
|
|
|
if (odt.isSetComplexOutput())
|
2017-11-09 18:04:16 +01:00
|
|
|
executeBuilder.setMimeTypeForOutput("text/xml", odt.getIdentifier().getStringValue());
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.debug("Execute Process-> Warning, no xml structured objects will be provided: "
|
|
|
|
+ e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
// executeBuilder.setSchemaForOutput("http://schemas.opengis.net/gml/3.1.1/base/feature.xsd",
|
|
|
|
// "result");
|
|
|
|
|
|
|
|
ExecuteDocument execute = executeBuilder.getExecute();
|
|
|
|
execute.getExecute().setService("WPS");
|
2017-11-09 18:04:16 +01:00
|
|
|
// System.out.println("RESPONSE
|
|
|
|
// FORM:"+execute.getExecute().getResponseForm());
|
2016-04-06 18:28:32 +02:00
|
|
|
wpsClient = createWPSClientSession();
|
|
|
|
wpsClient.connect(wpsProcessingServlet);
|
|
|
|
logger.debug("Sending: " + execute);
|
|
|
|
if (execute.getExecute().getResponseForm() != null) {
|
2017-11-09 18:04:16 +01:00
|
|
|
ResponseDocumentType documentType = execute.getExecute().getResponseForm().getResponseDocument();
|
2016-04-06 18:28:32 +02:00
|
|
|
documentType.setStoreExecuteResponse(true);
|
|
|
|
documentType.setStatus(true);
|
|
|
|
documentType.setLineage(false);
|
2017-11-09 18:04:16 +01:00
|
|
|
execute.getExecute().getResponseForm().setResponseDocument(documentType);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
Object responseObject = wpsClient.execute(wpsProcessingServlet, execute);
|
2016-04-06 18:28:32 +02:00
|
|
|
String processLocation = null;
|
2016-05-10 17:58:09 +02:00
|
|
|
Date creationData = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
if (responseObject != null) {
|
2016-05-04 20:24:07 +02:00
|
|
|
if (responseObject instanceof ExecuteResponseDocumentImpl) {
|
2016-05-10 17:58:09 +02:00
|
|
|
ExecuteResponseDocumentImpl executeResponseDocumentImpl = ((ExecuteResponseDocumentImpl) responseObject);
|
2017-11-09 18:04:16 +01:00
|
|
|
processLocation = executeResponseDocumentImpl.getExecuteResponse().getStatusLocation();
|
|
|
|
creationData = executeResponseDocumentImpl.getExecuteResponse().getStatus().getCreationTime()
|
2016-05-10 17:58:09 +02:00
|
|
|
.getTime();
|
2016-05-04 20:24:07 +02:00
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Invalid response from service, "
|
|
|
|
+ "response isn't instance of ExecuteResponseDocumentImpl, class is "
|
|
|
|
+ responseObject.getClass());
|
2016-05-04 20:24:07 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Invalid Response from service, " + responseObject);
|
2016-05-04 20:24:07 +02:00
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("Retrieved: [ProcessLocation=" + processLocation + ", CreationDate=" + creationData + "]");
|
2016-04-06 18:28:32 +02:00
|
|
|
return processLocation;
|
|
|
|
|
2016-05-04 20:24:07 +02:00
|
|
|
} catch (Throwable e) {
|
|
|
|
logger.error("ExecuteProcessAsync: " + e.getLocalizedMessage());
|
2016-04-06 18:28:32 +02:00
|
|
|
e.printStackTrace();
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-04-06 18:28:32 +02:00
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (wpsClient != null)
|
|
|
|
wpsClient.disconnect(wpsProcessingServlet);
|
|
|
|
} catch (Exception e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("Problems in wps disconnect! " + e.getLocalizedMessage());
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private ProcessOutputs retrieveProcessResult(String processLocation) throws ServiceException {
|
2016-09-14 14:27:54 +02:00
|
|
|
SClient4WPSSession wpsClient = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
|
|
|
logger.debug("RetrieveProcessResult: " + processLocation);
|
|
|
|
wpsClient = createWPSClientSession();
|
|
|
|
// wpsClient.connectForMonitoring(webProcessingService);
|
|
|
|
// wpsClient.connect(url)
|
|
|
|
|
|
|
|
Object responseObject = null;
|
|
|
|
if (processLocation != null && processLocation.length() > 0)
|
|
|
|
responseObject = wpsClient.executeViaGET(processLocation, "");
|
|
|
|
else
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Process Location is null!");
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
logger.debug("Response:\n" + responseObject);
|
2017-11-09 18:04:16 +01:00
|
|
|
return ((ExecuteResponseDocument) responseObject).getExecuteResponse().getProcessOutputs();
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-05-04 20:24:07 +02:00
|
|
|
} catch (Throwable e) {
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("RetrieveProcessResult: " + e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-04-06 18:28:32 +02:00
|
|
|
} finally {
|
|
|
|
wpsClient.disconnect(wpsProcessingServlet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int calculateBBDimensions(String bbstring) {
|
|
|
|
String[] bbinput = bbstring.split(",");
|
|
|
|
int dimcounter = 0;
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < bbinput.length; i++) {
|
|
|
|
Double.parseDouble(bbinput[i]);
|
|
|
|
dimcounter++;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.debug("Dimensions Count: " + dimcounter);
|
|
|
|
}
|
|
|
|
return dimcounter;
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private static void addBoundingBoxInput(org.n52.wps.client.ExecuteRequestBuilder executeBuilder, String identifier,
|
|
|
|
String BBstring) {
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
ExecuteDocument executor = executeBuilder.getExecute();
|
|
|
|
InputType input1 = executor.getExecute().getDataInputs().addNewInput();
|
|
|
|
input1.addNewIdentifier().setStringValue(identifier);
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
net.opengis.ows.x11.BoundingBoxType bbtype = input1.addNewData().addNewBoundingBoxData();
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
// bboxInput=46,102,47,103,urn:ogc:def:crs:EPSG:6.6:4326,2
|
|
|
|
String[] bbinput = BBstring.split(",");
|
|
|
|
int dimensions = calculateBBDimensions(BBstring);
|
|
|
|
List<String> lc = new ArrayList<String>();
|
|
|
|
for (int i = 0; i < dimensions / 2; i++) {
|
|
|
|
lc.add(bbinput[i]);
|
|
|
|
}
|
|
|
|
List<String> uc = new ArrayList<String>();
|
|
|
|
for (int i = dimensions / 2; i < dimensions; i++) {
|
|
|
|
uc.add(bbinput[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bbtype.setLowerCorner(lc);
|
|
|
|
bbtype.setUpperCorner(uc);
|
|
|
|
|
|
|
|
// int crsidx = bbinput[dimensions].indexOf("crs:");
|
|
|
|
String crs = bbinput[dimensions];
|
|
|
|
/*
|
|
|
|
* if (crsidx>=0) crs = bbinput[dimensions].substring(crsidx+4);
|
|
|
|
*/
|
|
|
|
bbtype.setCrs(crs);
|
|
|
|
bbtype.setDimensions(new BigInteger("" + dimensions / 2));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private static LinkedHashMap<String, ResponseWPS> retrieveURLsFromWPSResponse(ComplexDataType cdt) {
|
2016-04-06 18:28:32 +02:00
|
|
|
org.w3c.dom.Node node = cdt.getDomNode();
|
|
|
|
LinkedHashMap<String, ResponseWPS> urls = new LinkedHashMap<>();
|
|
|
|
getURLFromXML(node, urls);
|
|
|
|
for (String key : urls.keySet()) {
|
|
|
|
logger.debug("ResponseWPS Map: " + key + "-->" + urls.get(key));
|
|
|
|
}
|
|
|
|
return urls;
|
|
|
|
}
|
2016-05-05 18:54:15 +02:00
|
|
|
|
2016-05-04 20:24:07 +02:00
|
|
|
/*
|
2016-05-05 18:54:15 +02:00
|
|
|
* private static String getExceptionText(String exceptionText) { try {
|
|
|
|
* String excText = "ExceptionText>"; int idx =
|
|
|
|
* exceptionText.indexOf(excText); if (idx >= 0) { String exception =
|
|
|
|
* exceptionText.substring(idx + excText.length()); exception =
|
|
|
|
* exception.substring(0, exception.indexOf("</")); exception = exception
|
|
|
|
* .replace("<", "") .replace(">", "") .replace("/", " ") .replace("\\",
|
|
|
|
* " ") .replaceAll( "[\\]\\[!\"#$%&'\\(\\)*+/:;<=>?@\\^_`{\\|}~-]",
|
|
|
|
* "_").trim(); exception = exception.replaceAll("[ ]+", " "); if
|
|
|
|
* (exception.length() > 200) exception = exception.substring(0, 200) +
|
|
|
|
* "..."; return exception; } else return "Process error in WPS Execution";
|
|
|
|
* } catch (Exception e) { e.printStackTrace(); return
|
|
|
|
* "Backend error in WPS Execution"; } }
|
|
|
|
*/
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private static void getURLFromXML(org.w3c.dom.Node node, ResponseWPS responseWPS) {
|
2016-04-06 18:28:32 +02:00
|
|
|
if (node == null)
|
|
|
|
return;
|
|
|
|
|
2016-10-25 11:43:04 +02:00
|
|
|
logger.debug("Node Name: " + node.getNodeName());
|
2016-04-06 18:28:32 +02:00
|
|
|
if (node.getNodeName() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-20 17:05:19 +01:00
|
|
|
|
2016-10-25 11:43:04 +02:00
|
|
|
if (node.getFirstChild() != null) {
|
|
|
|
logger.debug("Node Value: " + node.getFirstChild().getNodeValue());
|
|
|
|
} else {
|
|
|
|
logger.debug("FirstChild is NULL");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
String text;
|
|
|
|
switch (node.getNodeName()) {
|
|
|
|
case "d4science:Data":
|
|
|
|
text = node.getFirstChild().getNodeValue();
|
|
|
|
responseWPS.setData(text);
|
|
|
|
break;
|
|
|
|
case "d4science:Description":
|
|
|
|
text = node.getFirstChild().getNodeValue();
|
|
|
|
responseWPS.setDescription(text);
|
|
|
|
break;
|
|
|
|
case "d4science:MimeType":
|
|
|
|
text = node.getFirstChild().getNodeValue();
|
|
|
|
responseWPS.setMimeType(text);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* logger.debug("ResponseWPS:"+responseWPS); */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private static void getURLFromXML(org.w3c.dom.Node node, LinkedHashMap<String, ResponseWPS> urls) {
|
2016-04-06 18:28:32 +02:00
|
|
|
if (node == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
logger.debug("Node Name: " + node.getNodeName());
|
|
|
|
|
|
|
|
if (node.getNodeName() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseWPS responseWPS = null;
|
|
|
|
NodeList listnodes = node.getChildNodes();
|
|
|
|
int nChildren = listnodes.getLength();
|
|
|
|
|
|
|
|
switch (node.getNodeName()) {
|
|
|
|
case "ogr:Result":
|
|
|
|
NamedNodeMap attrs = node.getAttributes();
|
|
|
|
Node n = attrs.getNamedItem("fid");
|
|
|
|
String key = n.getNodeValue();
|
|
|
|
responseWPS = new ResponseWPS();
|
|
|
|
urls.put(key, responseWPS);
|
|
|
|
if (nChildren == 0) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < nChildren; i++) {
|
|
|
|
getURLFromXML(listnodes.item(i), responseWPS);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (nChildren == 0) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < nChildren; i++) {
|
|
|
|
getURLFromXML(listnodes.item(i), urls);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* NodeList listnodes = node.getChildNodes(); int nChildren =
|
|
|
|
* listnodes.getLength();
|
|
|
|
*
|
|
|
|
* if (nChildren == 0) { String text = node.getNodeValue(); if (text !=
|
|
|
|
* null && (text.startsWith("https:") || text.startsWith("http:") ||
|
|
|
|
* text.startsWith("ftp:") || text.startsWith("smp:") || text
|
|
|
|
* .startsWith("file:"))) urls.add(text.trim()); else if (text != null
|
|
|
|
* && text.trim().length() > 0) urls.add(text.trim()); } else { for (int
|
|
|
|
* i = 0; i < nChildren; i++) { List<String> childrenurls =
|
|
|
|
* getURLFromXML(listnodes.item(i)); urls.addAll(childrenurls);
|
|
|
|
*
|
|
|
|
* } } return urls;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
@Override
|
2017-11-09 18:04:16 +01:00
|
|
|
public List<Parameter> getInputParameters(Operator operator) throws ServiceException {
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("Input Parameters of algorithm " + operator.getId());
|
2016-05-03 18:03:00 +02:00
|
|
|
|
2016-04-27 18:41:39 +02:00
|
|
|
ProcessInformations processInformations;
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
2016-05-03 18:03:00 +02:00
|
|
|
processInformations = describeProcess(operator.getId());
|
2016-04-06 18:28:32 +02:00
|
|
|
} catch (Throwable e) {
|
|
|
|
logger.error("GetParameters: " + e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException(e.getLocalizedMessage());
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
2016-05-19 19:35:48 +02:00
|
|
|
|
|
|
|
logger.debug("ProcessInformation: " + processInformations);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
List<Parameter> parameters = new ArrayList<>();
|
|
|
|
|
|
|
|
Parameter inputParameter;
|
2017-11-09 18:04:16 +01:00
|
|
|
for (InputDescriptionType inputDesc : processInformations.getInputs()) {
|
2016-09-14 14:27:54 +02:00
|
|
|
inputParameter = WPS2DM.convert2DMType(inputDesc);
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("InputParameter: " + inputParameter);
|
|
|
|
parameters.add(inputParameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.debug("Parameters: " + parameters);
|
|
|
|
return parameters;
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error in getInputParameters: " + e.getLocalizedMessage(), e);
|
|
|
|
throw new ServiceException(e.getLocalizedMessage());
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-09 18:04:16 +01:00
|
|
|
public ComputationId startComputation(Operator operator) throws ServiceException {
|
2016-04-27 18:41:39 +02:00
|
|
|
ProcessInformations processInformations;
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
2016-05-03 18:03:00 +02:00
|
|
|
processInformations = describeProcess(operator.getId());
|
2016-04-06 18:28:32 +02:00
|
|
|
} catch (Throwable e) {
|
|
|
|
logger.error("GetParameters: " + e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LinkedHashMap<String, Parameter> inputParameters = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
Parameter inputParameter;
|
2016-04-27 18:41:39 +02:00
|
|
|
for (InputDescriptionType inputDesc : processInformations.getInputs()) {
|
2016-09-14 14:27:54 +02:00
|
|
|
inputParameter = WPS2DM.convert2DMType(inputDesc);
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("InputParameter: " + inputParameter);
|
|
|
|
inputParameters.put(inputParameter.getName(), inputParameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Parameter> params = operator.getOperatorParameters();
|
|
|
|
Map<String, String> userInputs = new LinkedHashMap<>();
|
|
|
|
for (Parameter parm : params) {
|
|
|
|
userInputs.put(parm.getName(), parm.getValue());
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("UserInputs[key=" + parm.getName() + ", value=" + parm.getValue() + "]");
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 15:23:40 +02:00
|
|
|
LinkedHashMap<String, String> equivalentRequestMap = new LinkedHashMap<>();
|
2017-11-09 18:04:16 +01:00
|
|
|
String processUrl = compute(processInformations, userInputs, inputParameters, equivalentRequestMap);
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("Stated Computation ProcessLocation:" + processUrl);
|
|
|
|
|
|
|
|
int idIndex = processUrl.lastIndexOf("?id=");
|
|
|
|
String id;
|
|
|
|
if (idIndex > -1) {
|
|
|
|
id = processUrl.substring(idIndex + 4, processUrl.length());
|
|
|
|
} else {
|
|
|
|
logger.error("Invalid processLocation: " + processUrl);
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Invalid processLocation: " + processUrl);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
2016-05-16 15:23:40 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
String equivalentRequest = extractEquivalentRequestForComputation(operator, equivalentRequestMap);
|
2016-05-16 15:23:40 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
ComputationId computationId = new ComputationId(id, processUrl, operator.getId(), operator.getName(),
|
|
|
|
equivalentRequest);
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("ComputationId: " + computationId);
|
2016-05-03 18:03:00 +02:00
|
|
|
|
2016-04-27 18:41:39 +02:00
|
|
|
runningProcess.put(computationId, processInformations);
|
2016-05-03 18:03:00 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
return computationId;
|
|
|
|
}
|
|
|
|
|
2017-02-20 17:05:19 +01:00
|
|
|
private String extractEquivalentRequestForComputation(Operator operator,
|
|
|
|
LinkedHashMap<String, String> equivalentRequestMap) {
|
2017-11-09 18:04:16 +01:00
|
|
|
String equivalentRequest = wpsProcessingServlet + "?" + "request=Execute&service=WPS&Version=1.0.0&gcube-token="
|
|
|
|
+ wpsToken + "&lang=en-US&Identifier=" + operator.getId() + "&DataInputs=";
|
2017-02-20 17:05:19 +01:00
|
|
|
|
|
|
|
for (String key : equivalentRequestMap.keySet()) {
|
2017-02-20 17:49:40 +01:00
|
|
|
String keyEncoded = "";
|
2017-02-20 17:05:19 +01:00
|
|
|
try {
|
2017-02-20 17:49:40 +01:00
|
|
|
keyEncoded = URLEncoder.encode(key, "UTF-8");
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error in equivalent request creation: Unsupported Encoding for parameter=" + key, e);
|
2017-02-20 17:49:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
String valueEncoded = "";
|
|
|
|
try {
|
2017-11-09 18:04:16 +01:00
|
|
|
valueEncoded = URLEncoder.encode(equivalentRequestMap.get(key), "UTF-8");
|
2017-02-20 17:05:19 +01:00
|
|
|
} catch (UnsupportedEncodingException e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error in equivalent request creation: Unsupported Encoding for value="
|
|
|
|
+ equivalentRequestMap.get(key) + " of parameter=" + key, e);
|
2017-02-20 17:49:40 +01:00
|
|
|
break;
|
2017-02-20 17:05:19 +01:00
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
equivalentRequest = equivalentRequest + keyEncoded + "=" + valueEncoded + ";";
|
2017-02-20 17:05:19 +01:00
|
|
|
}
|
2017-02-20 17:49:40 +01:00
|
|
|
|
2017-02-20 17:05:19 +01:00
|
|
|
return equivalentRequest;
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private String compute(ProcessInformations processInformations, Map<String, String> userInputs,
|
|
|
|
Map<String, Parameter> inputParameters, LinkedHashMap<String, String> equivalentRequestMap)
|
|
|
|
throws ServiceException {
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
|
|
|
// setup the inputs
|
|
|
|
org.n52.wps.client.ExecuteRequestBuilder executeBuilder = new org.n52.wps.client.ExecuteRequestBuilder(
|
2016-04-27 18:41:39 +02:00
|
|
|
processInformations.getProcessDescription());
|
|
|
|
for (InputDescriptionType input : processInformations.getInputs()) {
|
2017-11-09 18:04:16 +01:00
|
|
|
String value = userInputs.get(input.getIdentifier().getStringValue());
|
2016-04-06 18:28:32 +02:00
|
|
|
if (value != null && value.trim().length() > 0) {
|
|
|
|
if (input.isSetLiteralData()) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug(
|
|
|
|
"Configuring Literal: " + input.getIdentifier().getStringValue() + " to: " + value);
|
|
|
|
equivalentRequestMap.put(input.getIdentifier().getStringValue(), value);
|
|
|
|
executeBuilder.addLiteralData(input.getIdentifier().getStringValue(), value);
|
2016-05-05 18:54:15 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
} else if (input.isSetBoundingBoxData()) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("Configuring Bounding Box: " + input.getIdentifier().getStringValue() + " to: "
|
|
|
|
+ value);
|
|
|
|
equivalentRequestMap.put(input.getIdentifier().getStringValue(), value);
|
|
|
|
addBoundingBoxInput(executeBuilder, input.getIdentifier().getStringValue(), value);
|
2016-05-05 18:54:15 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
2016-05-05 18:54:15 +02:00
|
|
|
if (input.isSetComplexData()) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug(
|
|
|
|
"Configuring Complex: " + input.getIdentifier().getStringValue() + " to: " + value);
|
|
|
|
SupportedComplexDataInputType complex = input.getComplexData();
|
|
|
|
Parameter par = inputParameters.get(input.getIdentifier().getStringValue());
|
2016-05-05 18:54:15 +02:00
|
|
|
|
|
|
|
String publicLink;
|
|
|
|
if (par instanceof TabularListParameter) {
|
|
|
|
// TabularListParameter tabularListParameter =
|
|
|
|
// ((TabularListParameter) par);
|
2017-11-09 18:04:16 +01:00
|
|
|
InputStream tablesStream = new ByteArrayInputStream(value.getBytes());
|
|
|
|
publicLink = StorageUtil.saveOnStorageInTemporalFile(tablesStream);
|
2016-05-05 18:54:15 +02:00
|
|
|
} else {
|
|
|
|
publicLink = value;
|
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
equivalentRequestMap.put(input.getIdentifier().getStringValue(), value);
|
|
|
|
executeBuilder.addComplexDataReference(input.getIdentifier().getStringValue(), publicLink,
|
|
|
|
complex.getDefault().getFormat().getSchema(),
|
|
|
|
complex.getDefault().getFormat().getEncoding(),
|
|
|
|
complex.getDefault().getFormat().getMimeType());
|
2016-05-05 18:54:15 +02:00
|
|
|
|
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("This input parameter type is not supported by client library: " + input);
|
|
|
|
throw new ServiceException(
|
|
|
|
"This input parameter is not supported by client library: " + input);
|
2016-05-05 18:54:15 +02:00
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Submit the execution
|
2017-11-09 18:04:16 +01:00
|
|
|
String statusLocation = executeProcessAsync(executeBuilder, processInformations.getProcessDescription());
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("Starting Process: " + statusLocation);
|
|
|
|
return statusLocation;
|
|
|
|
|
2016-05-04 20:24:07 +02:00
|
|
|
} catch (Throwable e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error(e.getLocalizedMessage(),e);
|
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-09 18:04:16 +01:00
|
|
|
public ComputationStatus getComputationStatus(ComputationId computationId) throws ServiceException {
|
2016-09-14 14:27:54 +02:00
|
|
|
SClient4WPSSession wpsClient = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("GetComputationStatus(): ComputationId=" + computationId);
|
2016-04-06 18:28:32 +02:00
|
|
|
wpsClient = createWPSClientSession();
|
|
|
|
wpsClient.connectForMonitoring(wpsProcessingServlet);
|
|
|
|
|
|
|
|
Object responseObject = null;
|
2017-11-09 18:04:16 +01:00
|
|
|
if (computationId == null || computationId.getUrlId() == null || computationId.getUrlId().isEmpty()) {
|
|
|
|
throw new ServiceException("Process Location is null!");
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
|
|
|
ComputationStatus computationStatus = null;
|
|
|
|
try {
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
responseObject = wpsClient.executeViaGET(computationId.getUrlId(), "");
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("ComputationStatus ResponseObject: " + responseObject);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
if (responseObject instanceof ExecuteResponseDocumentImpl) {
|
2017-11-09 18:04:16 +01:00
|
|
|
if (((ExecuteResponseDocumentImpl) responseObject).getExecuteResponse() == null) {
|
2016-05-16 15:23:40 +02:00
|
|
|
logger.debug("WPS FAILURE: ExecuteResponse is null");
|
2016-05-19 19:35:48 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
computationStatus = new ComputationStatus(Status.FAILED, 100f);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
StatusType statusType = ((ExecuteResponseDocumentImpl) responseObject).getExecuteResponse()
|
|
|
|
.getStatus();
|
2016-04-06 18:28:32 +02:00
|
|
|
if (statusType == null) {
|
2016-05-16 15:23:40 +02:00
|
|
|
logger.debug("WPS FAILURE: Status Type is null");
|
2016-05-24 16:16:41 +02:00
|
|
|
computationStatus = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
String failure = statusType.getProcessFailed() == null ? null
|
2017-11-09 18:04:16 +01:00
|
|
|
: statusType.getProcessFailed().getExceptionReport().toString();
|
2016-05-13 18:55:07 +02:00
|
|
|
if ((failure != null && !failure.isEmpty())) {
|
|
|
|
logger.debug("WPS FAILURE: " + failure);
|
2017-11-09 18:04:16 +01:00
|
|
|
computationStatus = new ComputationStatus(new ServiceException(failure));
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
String paused = statusType.getProcessPaused() == null ? null
|
|
|
|
: statusType.getProcessPaused().getStringValue();
|
2016-05-13 18:55:07 +02:00
|
|
|
if (paused != null && !paused.isEmpty()) {
|
|
|
|
logger.debug("WPS PAUSED: " + paused);
|
2017-11-09 18:04:16 +01:00
|
|
|
computationStatus = new ComputationStatus(new ServiceException(paused));
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
String success = statusType.getProcessSucceeded() == null ? null
|
|
|
|
: statusType.getProcessSucceeded();
|
2016-05-13 18:55:07 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
if (success != null && !success.isEmpty()) {
|
2016-04-06 18:28:32 +02:00
|
|
|
logger.debug("WPS SUCCESS");
|
2017-11-09 18:04:16 +01:00
|
|
|
computationStatus = new ComputationStatus(Status.COMPLETE, 100f);
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
String accepted = statusType.getProcessAccepted() == null ? null
|
|
|
|
: statusType.getProcessAccepted();
|
|
|
|
if (accepted != null && !accepted.isEmpty()) {
|
2016-05-13 18:55:07 +02:00
|
|
|
logger.debug("WPS ACCEPTED");
|
2017-11-09 18:04:16 +01:00
|
|
|
computationStatus = new ComputationStatus(Status.ACCEPTED, 0f);
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
int status = statusType.getProcessStarted() == null ? -1
|
|
|
|
: statusType.getProcessStarted().getPercentCompleted();
|
2016-05-13 18:55:07 +02:00
|
|
|
|
|
|
|
if (status >= 0) {
|
|
|
|
Float statusd = (float) status;
|
|
|
|
try {
|
2017-11-09 18:04:16 +01:00
|
|
|
statusd = Float.parseFloat(
|
|
|
|
statusType.getProcessStarted().getStringValue());
|
2016-05-13 18:55:07 +02:00
|
|
|
} catch (Exception e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug(e.getLocalizedMessage());
|
2016-05-13 18:55:07 +02:00
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("WPS STATUS:" + statusd);
|
|
|
|
computationStatus = new ComputationStatus(Status.RUNNING, statusd);
|
2016-05-13 18:55:07 +02:00
|
|
|
} else {
|
2016-05-24 16:16:41 +02:00
|
|
|
if (status == -1) {
|
|
|
|
logger.debug("WPS STATUS: Computation cancelled, "
|
2017-11-09 18:04:16 +01:00
|
|
|
+ statusType.getProcessStarted());
|
|
|
|
computationStatus = new ComputationStatus(Status.CANCELLED, -1);
|
2016-05-24 16:16:41 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
logger.debug("WPS STATUS: Not Started, "
|
2017-11-09 18:04:16 +01:00
|
|
|
+ statusType.getProcessStarted());
|
2016-05-24 16:16:41 +02:00
|
|
|
}
|
2016-05-13 18:55:07 +02:00
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.debug("ComputationStatus: " + computationStatus);
|
|
|
|
return computationStatus;
|
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error in ResponceObject: " + responseObject);
|
2016-05-16 15:23:40 +02:00
|
|
|
logger.error("WPS FAILURE: ");
|
2017-11-09 18:04:16 +01:00
|
|
|
computationStatus = new ComputationStatus(Status.FAILED, 100f);
|
2016-04-06 18:28:32 +02:00
|
|
|
return computationStatus;
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
logger.error("WPS FAILURE: " + e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
2017-11-09 18:04:16 +01:00
|
|
|
computationStatus = new ComputationStatus(Status.FAILED, 100f);
|
2016-04-06 18:28:32 +02:00
|
|
|
return computationStatus;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 20:24:07 +02:00
|
|
|
} catch (Throwable e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("MonitorProcess: " + e.getLocalizedMessage(),e);
|
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-04-06 18:28:32 +02:00
|
|
|
} finally {
|
|
|
|
wpsClient.disconnect(wpsProcessingServlet);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-09 18:04:16 +01:00
|
|
|
public OutputData getOutputDataByComputationId(ComputationId computationId) throws ServiceException {
|
2016-08-04 15:34:52 +02:00
|
|
|
LinkedHashMap<String, Resource> resources = retrieveOutput(computationId);
|
2017-11-09 18:04:16 +01:00
|
|
|
MapResource mapResource = new MapResource("mapResource", "Resources", "Resources", resources);
|
2016-05-10 17:58:09 +02:00
|
|
|
OutputData outputData = new OutputData(computationId, mapResource);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-05-10 17:58:09 +02:00
|
|
|
return outputData;
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private LinkedHashMap<String, Resource> retrieveOutput(ComputationId computationId) throws ServiceException {
|
2016-08-04 15:34:52 +02:00
|
|
|
LinkedHashMap<String, Resource> outputResource = new LinkedHashMap<>();
|
|
|
|
LinkedHashMap<String, Parameter> outputParameters = new LinkedHashMap<>();
|
2017-11-09 18:04:16 +01:00
|
|
|
ProcessInformations processInformations = runningProcess.get(computationId);
|
2016-05-03 18:03:00 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
Parameter outputParameter;
|
2017-11-09 18:04:16 +01:00
|
|
|
if (processInformations != null && processInformations.getOutputs() != null) {
|
|
|
|
for (OutputDescriptionType outputDesc : processInformations.getOutputs()) {
|
2016-09-14 14:27:54 +02:00
|
|
|
outputParameter = WPS2DM.convert2DMType(outputDesc);
|
2016-05-03 18:03:00 +02:00
|
|
|
logger.debug("OutputParameter: " + outputParameter);
|
2017-11-09 18:04:16 +01:00
|
|
|
outputParameters.put(outputParameter.getName(), outputParameter);
|
2016-05-03 18:03:00 +02:00
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
retrieveProcessOutput(computationId.getUrlId(), outputParameters, outputResource);
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
return outputResource;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private void retrieveProcessOutput(String processLocation, Map<String, Parameter> outputParameters,
|
|
|
|
Map<String, Resource> outputResource) throws ServiceException {
|
2016-04-06 18:28:32 +02:00
|
|
|
ProcessOutputs outs = retrieveProcessResult(processLocation);
|
|
|
|
logger.debug("Process Executed");
|
|
|
|
// retrieve the output objs
|
|
|
|
if (outs == null)
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Error during the execution of the WPS process: returned an empty document");
|
2016-04-06 18:28:32 +02:00
|
|
|
else {
|
|
|
|
OutputDataType[] outputData = outs.getOutputArray();
|
|
|
|
|
|
|
|
for (OutputDataType out : outputData) {
|
|
|
|
String outputID = out.getIdentifier().getStringValue();
|
|
|
|
String value = "";
|
|
|
|
if (out.getData().isSetLiteralData()) {
|
|
|
|
value = out.getData().getLiteralData().getStringValue();
|
|
|
|
Parameter paramLiteral = outputParameters.get(outputID);
|
|
|
|
if (paramLiteral != null) {
|
|
|
|
paramLiteral.setValue(value);
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("Assigning value: " + value + " to output named: " + outputID);
|
|
|
|
Resource resource = new ObjectResource(outputID, paramLiteral.getName(),
|
|
|
|
paramLiteral.getDescription(), paramLiteral.getValue());
|
2016-04-06 18:28:32 +02:00
|
|
|
outputResource.put(outputID, resource);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (out.getData().isSetComplexData()) {
|
|
|
|
if (out.getReference() != null) {
|
|
|
|
value = out.getReference().getHref();
|
2017-11-09 18:04:16 +01:00
|
|
|
Parameter paramComplexData = outputParameters.get(outputID);
|
2016-04-06 18:28:32 +02:00
|
|
|
if (paramComplexData != null) {
|
|
|
|
paramComplexData.setValue(value);
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("Assigning value: " + value + " to output named: " + outputID);
|
|
|
|
Resource resource = new ObjectResource(outputID, paramComplexData.getName(),
|
|
|
|
paramComplexData.getDescription(), paramComplexData.getValue());
|
2016-04-06 18:28:32 +02:00
|
|
|
outputResource.put(outputID, resource);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
// remove the element name, which is not useful
|
|
|
|
outputParameters.remove(outputID);
|
|
|
|
|
|
|
|
ComplexDataType cdt = out.getData().getComplexData();
|
|
|
|
LinkedHashMap<String, ResponseWPS> urls = retrieveURLsFromWPSResponse(cdt);
|
|
|
|
|
|
|
|
for (String key : urls.keySet()) {
|
|
|
|
logger.debug("Adding OBJ:" + key);
|
|
|
|
ResponseWPS responseWPS = urls.get(key);
|
2017-11-09 18:04:16 +01:00
|
|
|
ObjectParameter objP = new ObjectParameter(key, responseWPS.getDescription(),
|
2016-04-06 18:28:32 +02:00
|
|
|
String.class.getName(), " ");
|
|
|
|
objP.setValue(responseWPS.getData());
|
|
|
|
logger.debug("ObjectParameter: " + objP);
|
|
|
|
outputParameters.put(key, objP);
|
2017-11-09 18:04:16 +01:00
|
|
|
if (responseWPS != null && responseWPS.getMimeType() != null) {
|
2016-04-06 18:28:32 +02:00
|
|
|
Resource resource;
|
|
|
|
switch (responseWPS.getMimeType()) {
|
|
|
|
case "image/bmp":
|
|
|
|
case "image/gif":
|
|
|
|
case "image/jpeg":
|
|
|
|
case "image/png":
|
2017-11-09 18:04:16 +01:00
|
|
|
resource = new ImageResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData(),
|
2016-04-06 18:28:32 +02:00
|
|
|
responseWPS.getMimeType());
|
|
|
|
outputResource.put(key, resource);
|
|
|
|
break;
|
|
|
|
case "text/csv":
|
2017-11-09 18:04:16 +01:00
|
|
|
if (responseWPS.getData() != null && !responseWPS.getData().isEmpty()) {
|
|
|
|
if (responseWPS.getData().startsWith("http:")
|
|
|
|
|| responseWPS.getData().startsWith("https:")
|
|
|
|
|| responseWPS.getData().startsWith("smp:")) {
|
|
|
|
|
|
|
|
Parameter complexParameter = outputParameters.get(outputID);
|
|
|
|
if (complexParameter instanceof FileParameter) {
|
|
|
|
FileParameter fileParameter = (FileParameter) complexParameter;
|
|
|
|
if (fileParameter.isNetcdf()) {
|
|
|
|
resource = new FileResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData(),
|
|
|
|
responseWPS.getMimeType(), true);
|
|
|
|
} else {
|
|
|
|
resource = new FileResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData(),
|
|
|
|
responseWPS.getMimeType(), false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
resource = new FileResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData(),
|
|
|
|
responseWPS.getMimeType(), false);
|
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
outputResource.put(key, resource);
|
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
resource = new ObjectResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData());
|
2016-04-06 18:28:32 +02:00
|
|
|
outputResource.put(key, resource);
|
|
|
|
}
|
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
resource = new ObjectResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData());
|
2016-04-06 18:28:32 +02:00
|
|
|
outputResource.put(key, resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
2017-11-09 18:04:16 +01:00
|
|
|
if (responseWPS.getData() != null && !responseWPS.getData().isEmpty()) {
|
|
|
|
if (responseWPS.getData().startsWith("http:")
|
|
|
|
|| responseWPS.getData().startsWith("https:")
|
|
|
|
|| responseWPS.getData().startsWith("smp:")) {
|
|
|
|
Parameter complexParameter = outputParameters.get(outputID);
|
|
|
|
if (complexParameter instanceof FileParameter) {
|
|
|
|
FileParameter fileParameter = (FileParameter) complexParameter;
|
|
|
|
if (fileParameter.isNetcdf()) {
|
|
|
|
resource = new FileResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData(),
|
|
|
|
responseWPS.getMimeType(), true);
|
|
|
|
} else {
|
|
|
|
resource = new FileResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData(),
|
|
|
|
responseWPS.getMimeType(), false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
resource = new FileResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData(),
|
|
|
|
responseWPS.getMimeType(), false);
|
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
outputResource.put(key, resource);
|
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
resource = new ObjectResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData());
|
2016-04-06 18:28:32 +02:00
|
|
|
outputResource.put(key, resource);
|
|
|
|
}
|
|
|
|
} else {
|
2017-11-09 18:04:16 +01:00
|
|
|
resource = new ObjectResource(key, responseWPS.getDescription(),
|
|
|
|
responseWPS.getDescription(), responseWPS.getData());
|
2016-04-06 18:28:32 +02:00
|
|
|
outputResource.put(key, resource);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
value = out.getData().getLiteralData().getStringValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-09 18:04:16 +01:00
|
|
|
public String cancelComputation(ComputationId computationId) throws ServiceException {
|
2016-09-14 14:27:54 +02:00
|
|
|
SClient4WPSSession wpsClient = null;
|
2016-04-06 18:28:32 +02:00
|
|
|
try {
|
|
|
|
wpsClient = createWPSClientSession();
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
String result = wpsClient.cancelComputation(wpsCancelComputationServlet, computationId.getId());
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error(e.getLocalizedMessage(), e);
|
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-04-06 18:28:32 +02:00
|
|
|
} finally {
|
|
|
|
if (wpsClient != null) {
|
|
|
|
wpsClient.disconnect(wpsProcessingServlet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-21 21:42:53 +02:00
|
|
|
@Override
|
2017-11-09 18:04:16 +01:00
|
|
|
public ComputationId resubmitComputation(Map<String, String> computationProperties) throws ServiceException {
|
2016-05-06 18:26:00 +02:00
|
|
|
ProcessInformations processInformations;
|
2016-05-09 18:57:18 +02:00
|
|
|
if (computationProperties == null || computationProperties.isEmpty()) {
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Invalid computation properties: " + computationProperties);
|
2016-05-09 18:57:18 +02:00
|
|
|
}
|
2016-05-06 18:26:00 +02:00
|
|
|
try {
|
2017-11-09 18:04:16 +01:00
|
|
|
processInformations = describeProcess(computationProperties.get("operator_id"));
|
2016-05-06 18:26:00 +02:00
|
|
|
} catch (Throwable e) {
|
|
|
|
logger.error("GetParameters: " + e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-05-06 18:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LinkedHashMap<String, Parameter> inputParameters = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
Parameter inputParameter;
|
|
|
|
for (InputDescriptionType inputDesc : processInformations.getInputs()) {
|
2016-09-14 14:27:54 +02:00
|
|
|
inputParameter = WPS2DM.convert2DMType(inputDesc);
|
2016-05-06 18:26:00 +02:00
|
|
|
logger.debug("InputParameter: " + inputParameter);
|
|
|
|
inputParameters.put(inputParameter.getName(), inputParameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, String> userInputs = new LinkedHashMap<>();
|
2016-05-10 17:58:09 +02:00
|
|
|
for (String key : computationProperties.keySet()) {
|
|
|
|
if (key.startsWith("input")) {
|
|
|
|
int inputSeparatorIndex = key.indexOf("_");
|
|
|
|
String inputKey = key.substring(inputSeparatorIndex + 1);
|
2017-11-09 18:04:16 +01:00
|
|
|
if (inputKey.compareToIgnoreCase("user.name") != 0 && inputKey.compareToIgnoreCase("scope") != 0) {
|
2016-05-10 17:58:09 +02:00
|
|
|
userInputs.put(inputKey, computationProperties.get(key));
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.debug("UserInputs[key=" + inputKey + ", value=" + computationProperties.get(key) + "]");
|
2016-05-09 18:57:18 +02:00
|
|
|
}
|
|
|
|
|
2016-05-06 18:26:00 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
|
|
|
|
if (userInputs.isEmpty()) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Attention no inputs parameters retrieved for this computation: " + computationProperties);
|
|
|
|
throw new ServiceException(
|
|
|
|
"Attention no inputs parameters retrieved for this computation: " + computationProperties);
|
2016-05-09 18:57:18 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 15:23:40 +02:00
|
|
|
LinkedHashMap<String, String> equivalentRequestMap = new LinkedHashMap<>();
|
2017-11-09 18:04:16 +01:00
|
|
|
String processUrl = compute(processInformations, userInputs, inputParameters, equivalentRequestMap);
|
2016-05-06 18:26:00 +02:00
|
|
|
logger.debug("Stated Computation ProcessLocation:" + processUrl);
|
|
|
|
|
|
|
|
int idIndex = processUrl.lastIndexOf("?id=");
|
|
|
|
String id;
|
|
|
|
if (idIndex > -1) {
|
|
|
|
id = processUrl.substring(idIndex + 4, processUrl.length());
|
|
|
|
} else {
|
|
|
|
logger.error("Invalid processLocation: " + processUrl);
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException("Invalid processLocation: " + processUrl);
|
2016-05-06 18:26:00 +02:00
|
|
|
}
|
2016-05-16 15:23:40 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
String equivalentRequest = extractEquivalentRequestForResubmit(computationProperties, equivalentRequestMap);
|
2016-05-16 15:23:40 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
ComputationId computationId = new ComputationId(id, processUrl, computationProperties.get("operator_id"),
|
2016-05-16 15:23:40 +02:00
|
|
|
computationProperties.get("operator_name"), equivalentRequest);
|
2016-05-06 18:26:00 +02:00
|
|
|
logger.debug("ComputationId: " + computationId);
|
|
|
|
|
|
|
|
runningProcess.put(computationId, processInformations);
|
|
|
|
|
|
|
|
return computationId;
|
2016-04-21 21:42:53 +02:00
|
|
|
}
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
private String extractEquivalentRequestForResubmit(Map<String, String> computationProperties,
|
2017-02-20 17:05:19 +01:00
|
|
|
LinkedHashMap<String, String> equivalentRequestMap) {
|
2017-11-09 18:04:16 +01:00
|
|
|
String equivalentRequest = wpsProcessingServlet + "?" + "request=Execute&service=WPS&Version=1.0.0&gcube-token="
|
|
|
|
+ wpsToken + "&lang=en-US&Identifier=" + computationProperties.get("operator_id") + "&DataInputs=";
|
2017-02-20 17:05:19 +01:00
|
|
|
|
|
|
|
for (String key : equivalentRequestMap.keySet()) {
|
2017-02-20 17:49:40 +01:00
|
|
|
String keyEncoded = "";
|
2017-02-20 17:05:19 +01:00
|
|
|
try {
|
2017-02-20 17:49:40 +01:00
|
|
|
keyEncoded = URLEncoder.encode(key, "UTF-8");
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error in equivalent request creation: Unsupported Encoding for parameter=" + key, e);
|
2017-02-20 17:49:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
String valueEncoded = "";
|
|
|
|
try {
|
2017-11-09 18:04:16 +01:00
|
|
|
valueEncoded = URLEncoder.encode(equivalentRequestMap.get(key), "UTF-8");
|
2017-02-20 17:05:19 +01:00
|
|
|
} catch (UnsupportedEncodingException e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error in equivalent request creation: Unsupported Encoding for value="
|
|
|
|
+ equivalentRequestMap.get(key) + " of parameter=" + key, e);
|
2017-02-20 17:49:40 +01:00
|
|
|
break;
|
2017-02-20 17:05:19 +01:00
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
equivalentRequest = equivalentRequest + keyEncoded + "=" + valueEncoded + ";";
|
2017-02-20 17:05:19 +01:00
|
|
|
}
|
2017-02-20 17:49:40 +01:00
|
|
|
|
2017-02-20 17:05:19 +01:00
|
|
|
return equivalentRequest;
|
|
|
|
}
|
|
|
|
|
2016-05-09 18:57:18 +02:00
|
|
|
@Override
|
2017-11-09 18:04:16 +01:00
|
|
|
public ComputationData getComputationDataByComputationProperties(Map<String, String> computationProperties)
|
|
|
|
throws ServiceException {
|
2016-08-04 15:34:52 +02:00
|
|
|
try {
|
2017-11-09 18:04:16 +01:00
|
|
|
if (computationProperties == null || computationProperties.isEmpty()) {
|
|
|
|
throw new Exception("Invalid computation properties: " + computationProperties);
|
2016-08-04 15:34:52 +02:00
|
|
|
}
|
2016-05-10 17:58:09 +02:00
|
|
|
|
2016-08-04 15:34:52 +02:00
|
|
|
String compId = computationProperties.get("computation_id");
|
|
|
|
|
|
|
|
String operatorId = computationProperties.get("operator_id");
|
|
|
|
String operatorName = computationProperties.get("operator_name");
|
2017-11-09 18:04:16 +01:00
|
|
|
String operatorDescritpion = computationProperties.get("operator_description");
|
2016-08-04 15:34:52 +02:00
|
|
|
String vre = computationProperties.get("VRE");
|
|
|
|
String startDate = computationProperties.get("start_date");
|
|
|
|
String endDate = computationProperties.get("end_date");
|
|
|
|
String status = computationProperties.get("status");
|
|
|
|
String executionType = computationProperties.get("execution_type");
|
|
|
|
|
|
|
|
ComputationId computationId = new ComputationId();
|
|
|
|
computationId.setId(compId);
|
|
|
|
computationId.setOperatorId(operatorId);
|
|
|
|
computationId.setOperatorName(operatorName);
|
|
|
|
|
2016-08-04 16:48:38 +02:00
|
|
|
ArrayList<ComputationItemPropertiesValue> inputParametersAsProperties = new ArrayList<>();
|
|
|
|
ArrayList<ComputationItemPropertiesValue> outputParametersAsProperties = new ArrayList<>();
|
2016-08-04 15:34:52 +02:00
|
|
|
|
|
|
|
for (String key : computationProperties.keySet()) {
|
|
|
|
if (key != null) {
|
|
|
|
if (key.startsWith("input")) {
|
|
|
|
int inputSeparatorIndex = key.indexOf("_");
|
2017-11-09 18:04:16 +01:00
|
|
|
String inputKey = key.substring(inputSeparatorIndex + 1);
|
2016-08-04 15:34:52 +02:00
|
|
|
if (inputKey.compareToIgnoreCase("user.name") != 0
|
|
|
|
&& inputKey.compareToIgnoreCase("scope") != 0) {
|
2017-11-09 18:04:16 +01:00
|
|
|
String inputOrder = key.substring(5, inputSeparatorIndex);
|
2016-08-04 16:48:38 +02:00
|
|
|
Integer order;
|
|
|
|
try {
|
|
|
|
order = Integer.parseInt(inputOrder);
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
order = 0;
|
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
ComputationItemPropertiesValue inputProps = new ComputationItemPropertiesValue(order,
|
|
|
|
inputKey, computationProperties.get(key));
|
2016-08-04 16:48:38 +02:00
|
|
|
inputParametersAsProperties.add(inputProps);
|
2016-05-10 17:58:09 +02:00
|
|
|
|
2016-08-04 15:34:52 +02:00
|
|
|
}
|
2016-05-10 17:58:09 +02:00
|
|
|
|
2016-08-04 15:34:52 +02:00
|
|
|
} else {
|
|
|
|
if (key.startsWith("output")) {
|
|
|
|
int outputSeparatorIndex = key.indexOf("_");
|
2017-11-09 18:04:16 +01:00
|
|
|
String outputKey = key.substring(outputSeparatorIndex + 1);
|
2016-08-04 16:48:38 +02:00
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
String outputOrder = key.substring(6, outputSeparatorIndex);
|
2016-08-04 16:48:38 +02:00
|
|
|
Integer order;
|
|
|
|
try {
|
|
|
|
order = Integer.parseInt(outputOrder);
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
order = 0;
|
|
|
|
}
|
2017-11-09 18:04:16 +01:00
|
|
|
ComputationItemPropertiesValue outputProps = new ComputationItemPropertiesValue(order,
|
|
|
|
outputKey, computationProperties.get(key));
|
2016-05-10 17:58:09 +02:00
|
|
|
|
2016-08-04 16:48:38 +02:00
|
|
|
outputParametersAsProperties.add(outputProps);
|
|
|
|
|
2016-08-04 15:34:52 +02:00
|
|
|
}
|
2016-05-10 17:58:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-04 15:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-08-04 16:48:38 +02:00
|
|
|
Collections.sort(inputParametersAsProperties);
|
|
|
|
Collections.sort(outputParametersAsProperties);
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
ComputationValueBuilder computationValueBuilder = new ComputationValueBuilder(inputParametersAsProperties);
|
|
|
|
LinkedHashMap<String, ComputationValue> inputParameters = computationValueBuilder.create();
|
|
|
|
computationValueBuilder = new ComputationValueBuilder(outputParametersAsProperties);
|
|
|
|
LinkedHashMap<String, ComputationValue> outputParameters = computationValueBuilder.create();
|
2016-08-04 15:34:52 +02:00
|
|
|
|
|
|
|
logger.debug("inputParameters: " + inputParameters);
|
|
|
|
logger.debug("outputParameters: " + outputParameters);
|
|
|
|
|
2017-11-09 18:04:16 +01:00
|
|
|
ComputationData computationData = new ComputationData(computationId, inputParameters, outputParameters,
|
|
|
|
operatorDescritpion, startDate, endDate, status, executionType, vre);
|
2016-08-04 15:34:52 +02:00
|
|
|
|
|
|
|
logger.debug("ComputationData: " + computationData);
|
|
|
|
return computationData;
|
|
|
|
|
2016-10-06 14:54:25 +02:00
|
|
|
} catch (ServiceException e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error in getComutationDataByComputationProperties: " + e.getLocalizedMessage());
|
2016-08-04 15:34:52 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable e) {
|
2017-11-09 18:04:16 +01:00
|
|
|
logger.error("Error in getComutationDataByComputationProperties: " + e.getLocalizedMessage());
|
2016-08-04 15:34:52 +02:00
|
|
|
e.printStackTrace();
|
2017-11-09 18:04:16 +01:00
|
|
|
throw new ServiceException(e.getLocalizedMessage(), e);
|
2016-08-04 15:34:52 +02:00
|
|
|
|
|
|
|
}
|
2016-05-10 17:58:09 +02:00
|
|
|
|
2016-05-13 18:55:07 +02:00
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|