Enhancement on Task #10070

Added All Parameter Types

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@167333 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-05-07 14:47:33 +00:00
parent 2ad90c16ef
commit d45eeef5fe
10 changed files with 505 additions and 66 deletions

View File

@ -0,0 +1,100 @@
/**
*
*/
package org.gcube.common.workspacetaskexecutor.dataminer;
import org.gcube.common.workspacetaskexecutor.shared.TaskParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ColumnListParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ColumnParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.DateParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.EnumParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.FileParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ListParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ObjectParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ParameterType;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.TabularListParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.TabularParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.TimeParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.WKTParameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class DMConverter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 7, 2018
*/
public class DMConverter {
/** The logger. */
private static Logger logger = LoggerFactory.getLogger(DMConverter.class);
/**
* To dm parameter.
*
* @param taskParameter the task parameter
* @return the parameter
*/
public static Parameter toDMParameter(TaskParameter taskParameter){
ParameterType toParameterType = null;
try{
if(taskParameter==null || taskParameter.getType()==null)
return null;
toParameterType = ParameterType.valueOf(taskParameter.getType().getType());
Parameter p = null;
switch (toParameterType) {
case FILE:
p =new FileParameter();
break;
case OBJECT:
p = new ObjectParameter();
break;
case TABULAR:
p = new TabularParameter();
break;
case ENUM:
p = new EnumParameter();
break;
case LIST:
p = new ListParameter();
break;
case COLUMN:
p = new ColumnParameter();
break;
case COLUMN_LIST:
p = new ColumnListParameter();
break;
case DATE:
p = new DateParameter();
break;
case TABULAR_LIST:
p = new TabularListParameter();
break;
case TIME:
p = new TimeParameter();
break;
case WKT:
p = new WKTParameter();
break;
default:
break;
}
p.setName(taskParameter.getKey());
p.setValue(taskParameter.getValue());
return p;
}catch(Exception e){
logger.warn("Impossible to convert the value: "+taskParameter+" at one of values "+ParameterType.values());
return null;
}
}
}

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map;
import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration;
import org.gcube.common.workspacetaskexecutor.shared.TaskParameter;
import org.gcube.common.workspacetaskexecutor.shared.TaskStatus;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskComputation;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
@ -24,8 +25,8 @@ 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.MapResource;
import org.gcube.data.analysis.dataminermanagercl.shared.data.output.Resource;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.FileParameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ParameterType;
import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus;
import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus.Status;
import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator;
@ -384,21 +385,23 @@ public class DataMinerAccessPoint {
* @param parameters the parameters
* @return the operator
*/
private Operator addParametersToOperator(Operator operator, Map<String, String> parameters) {
private Operator addParametersToOperator(Operator operator, Map<String, TaskParameter> parameters) {
logger.debug("Adding parameters to operator");
List<Parameter> listParameters = new ArrayList<Parameter>();
for (String key : parameters.keySet()) {
// ObjectParameter op = new ObjectParameter();
// op.setName(key);
// op.setValue(parameters.get(key));
TaskParameter taskParameter = parameters.get(key);
ParameterType toParameterType = null;
if(taskParameter.getType()==null)
continue;
Parameter dmParameter = DMConverter.toDMParameter(taskParameter);
if(dmParameter!=null)
listParameters.add(dmParameter);
FileParameter fp=new FileParameter();
fp.setName(key);
fp.setValue(parameters.get(key));
listParameters.add(fp);
}
logger.debug("Parameters list is: " + listParameters);
operator.setOperatorParameters(listParameters);

View File

@ -7,6 +7,8 @@ import org.apache.commons.lang.Validate;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.workspacetaskexecutor.shared.ExecutableItem;
import org.gcube.common.workspacetaskexecutor.shared.ExecutableTask;
import org.gcube.common.workspacetaskexecutor.shared.TaskParameterAvailableTypes;
import org.gcube.common.workspacetaskexecutor.shared.TaskParameterType;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskComputation;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskExecutionStatus;
@ -16,8 +18,10 @@ import org.gcube.common.workspacetaskexecutor.shared.exception.TaskConfiguration
import org.gcube.common.workspacetaskexecutor.shared.exception.TaskErrorException;
import org.gcube.common.workspacetaskexecutor.shared.exception.TaskNotExecutableException;
import org.gcube.common.workspacetaskexecutor.shared.exception.WorkspaceFolderLocked;
import org.gcube.common.workspacetaskexecutor.util.Converter;
import org.gcube.common.workspacetaskexecutor.util.JsonUtil;
import org.gcube.common.workspacetaskexecutor.util.WsUtil;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ParameterType;
import org.json.JSONArray;
import org.json.JSONException;
import org.slf4j.Logger;
@ -183,6 +187,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
* @param workspaceItemId the workspace item id
* @return the list
* @throws ItemNotConfiguredException the item not configured exception
* @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception
*/
public List<TaskConfiguration> checkItemConfigurations(String workspaceItemId) throws ItemNotConfiguredException, WorkspaceFolderLocked, Exception{
@ -207,24 +212,14 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
*/
@Override
public Boolean isItemExecutable(String workspaceItemId) throws Exception {
logger.debug("Is Item "+workspaceItemId+" Executable starts...");
checkOwner();
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
String propConfigValue = WsUtil.getPropertyValue(item, WS_DM_TASK_TASK_CONF);
List<TaskConfiguration> confs = getListOfTaskConfigurations(workspaceItemId);
if(propConfigValue==null || propConfigValue.isEmpty()){
logger.debug("The item: "+workspaceItemId+" has not a configuration "+WS_DM_TASK_TASK_CONF);
return false;
}
try{
jsonUtil.readObject(propConfigValue, TaskConfiguration.class);
logger.debug("The item: "+workspaceItemId+" has a valid "+WS_DM_TASK_TASK_CONF+" configuration");
return true;
}catch(Exception e){
logger.error("Error on serializing configuration: "+propConfigValue, e);
if(confs==null || confs.isEmpty()){
logger.debug("The item: "+workspaceItemId+" has not a (valid) configuration "+WS_DM_TASK_TASK_CONF);
return false;
}
logger.debug("The item: "+workspaceItemId+" has a valid "+WS_DM_TASK_TASK_CONF+" with "+confs.size()+" configuration/s");
return true;
}
@ -325,6 +320,22 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
}
}
/**
* Gets the parameter types.
*
* @return the parameter types
*/
public TaskParameterAvailableTypes getParameterTypes(){
String[] typeNames = Converter.convertEnumNamesToArraString(ParameterType.class);
List<TaskParameterType> types = new ArrayList<TaskParameterType>();
for (String string : typeNames) {
types.add(new TaskParameterType(string));
}
return new TaskParameterAvailableTypes(types);
}
/* (non-Javadoc)
* @see org.gcube.common.workspacetaskexecutor.shared.ExecutableItem#eraseAllExecutableConfigurations()
*/

View File

@ -42,8 +42,7 @@ public interface BaseTaskConfiguration {
*
* @return the map parameters
*/
Map<String, String> getMapParameters();
Map<String, TaskParameter> getMapParameters();
/**

View File

@ -0,0 +1,146 @@
/**
*
*/
package org.gcube.common.workspacetaskexecutor.shared;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* The Class TaskParameter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 7, 2018
*/
public class TaskParameter implements Serializable{
/**
*
*/
private static final long serialVersionUID = 3607328256110736864L;
private String key;
private String value;
@JsonIgnoreProperties
private String defaultValue; //optional
private TaskParameterType type;
/**
* Instantiates a new task parameter.
*/
public TaskParameter() {
}
/**
* Instantiates a new task parameter.
*
* @param key the key
* @param value the value
* @param type the type
*/
public TaskParameter(String key, String value, String defaultValue, TaskParameterType type) {
super();
this.key = key;
this.defaultValue = defaultValue;
this.value = value;
this.type = type;
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @return the defaultValue
*/
public String getDefaultValue() {
return defaultValue;
}
/**
* @return the type
*/
public TaskParameterType getType() {
return type;
}
/**
* @param key the key to set
*/
public void setKey(String key) {
this.key = key;
}
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* @param defaultValue the defaultValue to set
*/
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
/**
* @param type the type to set
*/
public void setType(TaskParameterType type) {
this.type = type;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("TaskParameter [key=");
builder.append(key);
builder.append(", value=");
builder.append(value);
builder.append(", defaultValue=");
builder.append(defaultValue);
builder.append(", type=");
builder.append(type);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,67 @@
/**
*
*/
package org.gcube.common.workspacetaskexecutor.shared;
import java.io.Serializable;
import java.util.List;
/**
* The Class TaskParameterAvailableTypes.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 7, 2018
*/
public class TaskParameterAvailableTypes implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5005902773845652944L;
public List<TaskParameterType> parametersTypes;
/**
* Instantiates a new base task parameter types.
*/
public TaskParameterAvailableTypes() {
}
/**
* Instantiates a new task parameter available types.
*
* @param availableParameterTypes the available parameter types
*/
public TaskParameterAvailableTypes(List<TaskParameterType> availableParameterTypes) {
this.parametersTypes = availableParameterTypes;
}
/**
* Gets the parameters types.
*
* @return the parameters types
*/
public List<TaskParameterType> getParametersTypes() {
return parametersTypes;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("TaskParameterTypes [parametersTypes=");
builder.append(parametersTypes);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,65 @@
/**
*
*/
package org.gcube.common.workspacetaskexecutor.shared;
import java.io.Serializable;
/**
* The Class TaskParameterType.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 7, 2018
*/
public final class TaskParameterType implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5084714477390724544L;
private String type;
/**
* Instantiates a new task parameter type.
*/
public TaskParameterType() {
}
/**
* Instantiates a new task parameter type.
*
* @param type the type
*/
public TaskParameterType(String type) {
this.type = type;
}
/**
* Gets the type.
*
* @return the type
*/
public String getType() {
return type;
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("TaskParameterType [type=");
builder.append(type);
builder.append("]");
return builder.toString();
}
}

View File

@ -9,6 +9,7 @@ import java.util.Map;
import java.util.Random;
import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration;
import org.gcube.common.workspacetaskexecutor.shared.TaskParameter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -39,7 +40,7 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
private String maskedToken;
private String workspaceItemId;
@JsonIgnoreProperties
private Map<String, String> mapParameters; // optional
private Map<String, TaskParameter> mapParameters; // optional
private String configurationKey;
/**
@ -63,7 +64,7 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
public TaskConfiguration(
String configurationKey, String taskId, String taskDescription, String scope,
String maskedToken, String workspaceItemId,
Map<String, String> mapParameters) {
Map<String, TaskParameter> mapParameters) {
setConfigurationKey(configurationKey);
this.taskId = taskId;
@ -146,16 +147,24 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
return workspaceItemId;
}
/**
* Gets the map parameters.
*
* @return the mapParameters
*/
public Map<String, String> getMapParameters() {
public Map<String, TaskParameter> getMapParameters() {
return mapParameters;
}
/**
* @param mapParameters the mapParameters to set
*/
public void setMapParameters(Map<String, TaskParameter> mapParameters) {
this.mapParameters = mapParameters;
}
/**
* Sets the task description.
*
@ -189,16 +198,7 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
this.workspaceItemId = workspaceItemId;
}
/**
* Sets the map parameters.
*
* @param mapParameters
* the mapParameters to set
*/
public void setMapParameters(Map<String, String> mapParameters) {
this.mapParameters = mapParameters;
}
/*
* (non-Javadoc)
@ -234,6 +234,8 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
this.maskedToken = maskedToken;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/

View File

@ -3,11 +3,14 @@
*/
package org.gcube.common.workspacetaskexecutor.util;
import java.util.Arrays;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskComputation;
import org.gcube.data.analysis.dataminermanagercl.shared.data.computations.ComputationId;
/**
* The Class Converter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 3, 2018
@ -44,4 +47,15 @@ public class Converter {
return new ComputationId(computationId.getId(), computationId.getUrlId(), computationId.getOperatorId(), computationId.getOperatorName(), computationId.getEquivalentRequest());
}
/**
* Convert enum names to arra string.
*
* @param e the e
* @return the string[]
*/
public static String[] convertEnumNamesToArraString(Class<? extends Enum<?>> e){
return Arrays.stream(e.getEnumConstants()).map(Enum::name).toArray(String[]::new);
}
}

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
@ -17,9 +18,14 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundExcept
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.workspacetaskexecutor.dataminer.WorkspaceDataMinerTaskExecutor;
import org.gcube.common.workspacetaskexecutor.shared.TaskParameter;
import org.gcube.common.workspacetaskexecutor.shared.TaskParameterAvailableTypes;
import org.gcube.common.workspacetaskexecutor.shared.TaskParameterType;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
import org.gcube.common.workspacetaskexecutor.util.Converter;
import org.gcube.common.workspacetaskexecutor.util.JsonUtil;
import org.gcube.common.workspacetaskexecutor.util.WsUtil;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ParameterType;
import org.json.JSONArray;
import org.json.JSONException;
@ -95,35 +101,38 @@ public class TestDataMinerTaskExecutor {
exec.withOwner(USERNAME);
//jsonCheck();
//GET LIST CONFIGURATIONS
getConfigurations(exec);
//ERASE ALL CONFIGURATIONS
eraseAllTaskConfigurations(exec);
//GET LIST CONFIGURATIONS
//getConfigurations(exec);
//ERASE ALL CONFIGURATIONS
//eraseAllTaskConfigurations(exec);
//SET TASK CONFIGURATION
setDummyTaskConfigurations(exec);
deleteConfiguration(exec, listDummyConf.get(1));
//
//// deleteConfiguration(exec, listDummyConf.get(1));
////
getConfigurations(exec);
listDummyConf.get(2).setTaskId("Updated task id");
HashMap<String, String> map = new HashMap<String, String>();
map.put("Pippo", "Value Pippo");
map.put("Paperino", "Value Paperino");
listDummyConf.get(2).setMapParameters(map);
try {
exec.setTaskConfiguration(listDummyConf.get(2));
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
};
getConfigurations(exec);
// listDummyConf.get(2).setTaskId("Updated task id");
// HashMap<String, String> map = new HashMap<String, String>();
// map.put("Pippo", "Value Pippo");
// map.put("Paperino", "Value Paperino");
// listDummyConf.get(2).setMapParameters(map);
//
// try {
// exec.setTaskConfiguration(listDummyConf.get(2));
// }
// catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// };
//
// getConfigurations(exec);
//
// //UPDATE TASK CONFIGURATION
@ -212,14 +221,37 @@ public class TestDataMinerTaskExecutor {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static TaskConfiguration createDummyConfiguration(int index){
Map<String, String> mapParameters = new HashMap<String, String>();
mapParameters.put("publiclink", "this is the public link "+index);
String[] availableTypes = Converter.convertEnumNamesToArraString(ParameterType.class);
List<TaskParameterType> types = new ArrayList<TaskParameterType>();
for (String string : availableTypes) {
types.add(new TaskParameterType(string));
}
TaskParameterAvailableTypes tpt = new TaskParameterAvailableTypes(types);
System.out.println(tpt.toString());
// for (String availableType : tpt.getParametersTypes()) {
// System.out.println(availableType);
// }
Map<String, TaskParameter> mapParameters = new HashMap<String, TaskParameter>();
TaskParameter tp = new TaskParameter();
tp.setKey("publiclink");
tp.setValue("this is the public link "+index);
tp.setType(new TaskParameterType(ParameterType.FILE.toString()));
mapParameters.put("publiclink", tp);
TaskParameter tp2 = new TaskParameter();
tp2.setKey("key"+index);
tp2.setValue("value "+index);
tp2.setType(tpt.getParametersTypes().get(new Random().nextInt(tpt.getParametersTypes().size())));
mapParameters.put("publiclink", tp2);
return new TaskConfiguration(index+"", UUID.randomUUID().toString(), null, SCOPE, "my token", WORKSPACE_FOLDER_ID, mapParameters);
}