ref 6078:TDM - Create a new widget to support operations's invocation on DataMiner

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

Updated to support DataMiner

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/data-miner-manager-cl@146607 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-04-06 10:20:56 +00:00
parent 48b63393a7
commit c956205b61
12 changed files with 275 additions and 34 deletions

View File

@ -12,7 +12,6 @@ import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStat
import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator;
import org.gcube.data.analysis.dataminermanagercl.shared.process.OperatorsClassification;
/**
*
* Client of service
@ -21,15 +20,14 @@ import org.gcube.data.analysis.dataminermanagercl.shared.process.OperatorsClassi
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public abstract class SClient implements Serializable{
public abstract class SClient implements Serializable {
private static final long serialVersionUID = 7087349607933493388L;
public SClient() {
super();
}
/**
* Retrieve the list of operators
*
@ -38,31 +36,44 @@ public abstract class SClient implements Serializable{
*/
public abstract List<OperatorsClassification> getOperatorsClassifications()
throws Exception;
/**
* Retrieve the operator by id
*
* @param id operator id
* @param id
* operator id
* @return
* @throws Exception
*/
public abstract Operator getOperatorById(String id) throws Exception;
/**
* Get input paramters of the operator
*
* @param operator operator
* @param operator
* operator
* @return
* @throws Exception
*/
public abstract List<Parameter> getInputParameters(Operator operator)
throws Exception;
/**
*
* Get output paramters of the operator
*
* @param operator
* @return
* @throws Exception
*/
public abstract List<Parameter> getOutputParameters(Operator operator)
throws Exception;
/**
* Start Computation
*
* @param operator operator
* @param operator
* operator
* @return
* @throws Exception
*/
@ -72,19 +83,19 @@ public abstract class SClient implements Serializable{
/**
* Cancel a computation
*
* @param computationId computation Id
* @param computationId
* computation Id
* @return
* @throws Exception
*/
public abstract String cancelComputation(ComputationId computationId)
throws Exception;
/**
* Get Computation Status
*
* @param computationId computation Id
* @param computationId
* computation Id
* @return
* @throws Exception
*/
@ -104,13 +115,14 @@ public abstract class SClient implements Serializable{
/**
* Get Computation Data by computation properties
*
* @param computationProperties computation properties
* @param computationProperties
* computation properties
* @return
* @throws Exception
*/
public abstract ComputationData getComputationDataByComputationProperties(
Map<String, String> computationProperties) throws Exception;
/**
* Resubmit a computation only by computation properties
*
@ -120,10 +132,10 @@ public abstract class SClient implements Serializable{
*/
public abstract ComputationId resubmitComputation(
Map<String, String> computationProperties) throws Exception;
@Override
public String toString() {
return "SClient";
}
}

View File

@ -783,7 +783,7 @@ public class SClient4WPS extends SClient {
public List<Parameter> getInputParameters(Operator operator)
throws ServiceException {
try {
logger.debug("Parameters of algorithm " + operator.getId());
logger.debug("Input Parameters of algorithm " + operator.getId());
ProcessInformations processInformations;
try {
@ -810,12 +810,50 @@ public class SClient4WPS extends SClient {
return parameters;
} catch (Throwable e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
logger.error("Error in getInputParameters: "+e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage());
}
}
@Override
public List<Parameter> getOutputParameters(Operator operator)
throws Exception {
try {
logger.debug("Output Parameters of algorithm " + operator.getId());
ProcessInformations processInformations;
try {
processInformations = describeProcess(operator.getId());
} catch (Throwable e) {
logger.error("GetParameters: " + e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage());
}
logger.debug("ProcessInformation: " + processInformations);
List<Parameter> parameters = new ArrayList<>();
Parameter outputParameter;
for (OutputDescriptionType outputDesc : processInformations
.getOutputs()) {
outputParameter = WPS2DM.convert2DMType(outputDesc);
logger.debug("OutputParameter: " + outputParameter);
parameters.add(outputParameter);
}
logger.debug("Parameters: " + parameters);
return parameters;
} catch (Throwable e) {
logger.error("Error in getOutputParameters: "+e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage());
}
}
@Override
public ComputationId startComputation(Operator operator)

View File

@ -38,7 +38,7 @@ public class BionymLocalTest extends TestCase {
DataMinerService dataMinerService = new DataMinerService();
SClient sClient = dataMinerService.getClient();
Operator operator = sClient
.getOperatorById("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.BIONYM_LOCAL");
.getOperatorById(OperatorId.BIONYM_LOCAL.toString());
if (operator == null) {
logger.error("Operator not found");

View File

@ -38,7 +38,7 @@ public class CsquareColumnCreatorTest extends TestCase {
DataMinerService dataMinerService = new DataMinerService();
SClient sClient = dataMinerService.getClient();
Operator csquareColumnCreatorOperator = sClient
.getOperatorById("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.CSQUARE_COLUMN_CREATOR");
.getOperatorById(OperatorId.CSQUARE_COLUMN_CREATOR.toString());
if (csquareColumnCreatorOperator == null) {
logger.error("Operator not found");

View File

@ -1,7 +1,11 @@
package org.gcube.data.analysis.dataminermanagercl.test;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.TestCase;
@ -12,6 +16,8 @@ import org.gcube.data.analysis.dataminermanagercl.server.monitor.DMMonitorListen
import org.gcube.data.analysis.dataminermanagercl.shared.Constants;
import org.gcube.data.analysis.dataminermanagercl.shared.data.OutputData;
import org.gcube.data.analysis.dataminermanagercl.shared.data.computations.ComputationId;
import org.gcube.data.analysis.dataminermanagercl.shared.data.output.FileResource;
import org.gcube.data.analysis.dataminermanagercl.shared.data.output.ImageResource;
import org.gcube.data.analysis.dataminermanagercl.shared.data.output.MapResource;
import org.gcube.data.analysis.dataminermanagercl.shared.data.output.Resource;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ColumnListParameter;
@ -39,7 +45,7 @@ public class DBScanTest extends TestCase {
DataMinerService dataMinerService = new DataMinerService();
SClient sClient = dataMinerService.getClient();
Operator dBScanOperator = sClient
.getOperatorById("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.clusterers.DBSCAN");
.getOperatorById(OperatorId.DBSCAN.toString());
if (dBScanOperator == null) {
logger.error("Operator not found");
@ -129,8 +135,43 @@ public class DBScanTest extends TestCase {
if (resource.isMap()) {
MapResource mapResource = (MapResource) resource;
for (String key : mapResource.getMap().keySet()) {
logger.debug("Entry: " + key + " = "
+ mapResource.getMap().get(key));
Resource res = mapResource.getMap().get(key);
switch (res.getResourceType()) {
case FILE:
FileResource fileResource = (FileResource) res;
String fileName=retrieveFileName(fileResource.getUrl());
logger.debug("Entry: " + key + " = "
+ mapResource.getMap().get(key)+", FileName="+fileName);
break;
case IMAGE:
ImageResource imageResource = (ImageResource) res;
String imageName=retrieveFileName(imageResource.getLink());
logger.debug("Entry: " + key + " = "
+ mapResource.getMap().get(key)+", ImageName="+imageName);
break;
case MAP:
logger.debug("Entry: " + key + " = "
+ mapResource.getMap().get(key));
break;
case OBJECT:
logger.debug("Entry: " + key + " = "
+ mapResource.getMap().get(key));
break;
case TABULAR:
//TableResource tableResource = (TableResource) res;
//String tableName=retrieveFileName(tableResource.getLink());
logger.debug("Entry: " + key + " = "
+ mapResource.getMap().get(key));
break;
default:
logger.debug("Entry: " + key + " = "
+ mapResource.getMap().get(key));
break;
}
}
}
@ -187,4 +228,36 @@ public class DBScanTest extends TestCase {
}
private String retrieveFileName(String url) {
String fileName = "output";
try {
URL urlObj;
urlObj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urlObj
.openConnection();
connection.setRequestMethod("GET");
String contentDisposition = connection
.getHeaderField("Content-Disposition");
Pattern regex = Pattern.compile("(?<=filename=\").*?(?=\")");
Matcher regexMatcher = regex.matcher(contentDisposition);
if (regexMatcher.find()) {
fileName = regexMatcher.group();
}
if (fileName == null || fileName.isEmpty()) {
fileName = "output";
}
return fileName;
} catch (Throwable e) {
logger.error(
"Error retrieving file name: " + e.getLocalizedMessage(), e);
return fileName;
}
}
}

View File

@ -0,0 +1,70 @@
package org.gcube.data.analysis.dataminermanagercl.test;
import java.util.List;
import junit.framework.TestCase;
import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService;
import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient;
import org.gcube.data.analysis.dataminermanagercl.shared.Constants;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter;
import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class DataMinerParametersTest extends TestCase {
private static Logger logger = LoggerFactory
.getLogger(DataMinerParametersTest.class);
public void testExecute() {
if (Constants.TEST_ENABLE) {
logger.debug("Test Parameters");
try {
DataMinerService dataMinerService = new DataMinerService();
SClient sClient = dataMinerService.getClient();
Operator dBScanOperator = sClient
.getOperatorById(OperatorId.DBSCAN.toString());
if (dBScanOperator == null) {
logger.error("Operator not found");
} else {
logger.debug("Operator Name: " + dBScanOperator.getName()
+ " (" + dBScanOperator.getId() + ")");
logger.debug("Operator: " + dBScanOperator);
List<Parameter> inputParameters = sClient
.getInputParameters(dBScanOperator);
logger.debug("Parameters: " + inputParameters);
for (Parameter parameter : inputParameters) {
logger.debug("Input Parameter:" + parameter);
}
List<Parameter> outputParameters = sClient
.getOutputParameters(dBScanOperator);
logger.debug("Output Parameters: " + inputParameters);
for (Parameter parameter : outputParameters) {
logger.debug("Output Parameter:" + parameter);
}
}
assertTrue("Success", true);
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(),e);
assertTrue("Error", false);
}
} else {
assertTrue("Success", true);
}
}
}

View File

@ -38,9 +38,11 @@ public class DataMinerServiceTest extends TestCase {
if(firstCategory.getOperators()!=null&& !firstCategory.getOperators().isEmpty()){
Operator operator=firstCategory.getOperators().get(0);
logger.debug("First Operator: "+operator);
List<Parameter> parameters=sClient.getInputParameters(operator);
logger.debug("Parameters: "+parameters);
List<Parameter> inputParameters=sClient.getInputParameters(operator);
logger.debug("Input Parameters: "+inputParameters);
List<Parameter> outputParameters=sClient.getOutputParameters(operator);
logger.debug("Output Parameters: "+outputParameters);
} else {
logger.debug("Operators void");
@ -67,7 +69,7 @@ public class DataMinerServiceTest extends TestCase {
public void testOperarorName() {
if (Constants.TEST_ENABLE) {
logger.debug("Test DBScan");
logger.debug("Test Operators Name");
try {
DataMinerService dataMinerService=new DataMinerService();
SClient sClient = dataMinerService.getClient();

View File

@ -37,7 +37,7 @@ public class ListDBInfoTest extends TestCase {
DataMinerService dataMinerService=new DataMinerService();
SClient sClient = dataMinerService.getClient();
Operator operator = sClient
.getOperatorById("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBINFO");
.getOperatorById(OperatorId.LISTDBINFO.toString());
if (operator == null) {
logger.error("Operator not found");

View File

@ -37,7 +37,7 @@ public class ListDBNameTest extends TestCase {
DataMinerService dataMinerService=new DataMinerService();
SClient sClient = dataMinerService.getClient();
Operator operator = sClient
.getOperatorById("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBNAMES");
.getOperatorById(OperatorId.LISTDBNAMES.toString());
if (operator == null) {
logger.error("Operator not found");

View File

@ -38,7 +38,7 @@ public class ListDBSchemaTest extends TestCase {
DataMinerService dataMinerService=new DataMinerService();
SClient sClient = dataMinerService.getClient();
Operator operator = sClient
.getOperatorById("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBSCHEMA");
.getOperatorById(OperatorId.LISTDBSCHEMA.toString());
if (operator == null) {
logger.error("Operator not found");

View File

@ -35,10 +35,10 @@ public class ListTablesTest extends TestCase {
if (Constants.TEST_ENABLE) {
logger.debug("Test ListTables");
try {
DataMinerService dataMinerService=new DataMinerService();
DataMinerService dataMinerService = new DataMinerService();
SClient sClient = dataMinerService.getClient();
Operator operator = sClient
.getOperatorById("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTTABLES");
.getOperatorById(OperatorId.LISTTABLES.toString());
if (operator == null) {
logger.error("Operator not found");

View File

@ -0,0 +1,46 @@
package org.gcube.data.analysis.dataminermanagercl.test;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum OperatorId {
DBSCAN(
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.clusterers.DBSCAN"), CSQUARE_COLUMN_CREATOR(
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.CSQUARE_COLUMN_CREATOR"), BIONYM_LOCAL(
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.BIONYM_LOCAL"), LISTDBINFO(
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBINFO"), LISTDBNAMES(
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBNAMES"), LISTDBSCHEMA(
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBSCHEMA"), LISTTABLES(
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTTABLES");
;
/**
* @param text
*/
private OperatorId(final String id) {
this.id = id;
}
private final String id;
@Override
public String toString() {
return id;
}
public String getLabel() {
return id;
}
public static OperatorId getOperatorIdFromId(String id) {
for (OperatorId operatorId : values()) {
if (operatorId.id.compareToIgnoreCase(id) == 0) {
return operatorId;
}
}
return null;
}
}