Enhancement on Task #10070

Added Parameters as a List

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@167360 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-05-08 10:20:36 +00:00
parent 3e6a514b97
commit cce789d2a6
5 changed files with 28 additions and 35 deletions

View File

@ -26,7 +26,6 @@ import org.gcube.data.analysis.dataminermanagercl.shared.data.computations.Compu
import org.gcube.data.analysis.dataminermanagercl.shared.data.output.MapResource; 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.data.output.Resource;
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter; 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;
import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus.Status; import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus.Status;
import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator; import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator;
@ -150,7 +149,7 @@ public class DataMinerAccessPoint {
} }
try { try {
addParametersToOperator(operator, taskConfiguration.getMapParameters()); addParametersToOperator(operator, taskConfiguration.getListParameters());
logger.debug("Start Computation"); logger.debug("Start Computation");
ComputationId computationId = sClient.startComputation(operator); ComputationId computationId = sClient.startComputation(operator);
logger.debug("Started ComputationId: " + computationId); logger.debug("Started ComputationId: " + computationId);
@ -385,14 +384,11 @@ public class DataMinerAccessPoint {
* @param parameters the parameters * @param parameters the parameters
* @return the operator * @return the operator
*/ */
private Operator addParametersToOperator(Operator operator, Map<String, TaskParameter> parameters) { private Operator addParametersToOperator(Operator operator, List<TaskParameter> parameters) {
logger.debug("Adding parameters to operator"); logger.debug("Adding parameters to operator");
List<Parameter> listParameters = new ArrayList<Parameter>(); List<Parameter> listParameters = new ArrayList<Parameter>();
for (String key : parameters.keySet()) { for (TaskParameter taskParameter : parameters) {
TaskParameter taskParameter = parameters.get(key);
ParameterType toParameterType = null;
if(taskParameter.getType()==null) if(taskParameter.getType()==null)
continue; continue;

View File

@ -166,9 +166,9 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
TypeReference<List<TaskConfiguration>> mapType = new TypeReference<List<TaskConfiguration>>() {}; TypeReference<List<TaskConfiguration>> mapType = new TypeReference<List<TaskConfiguration>>() {};
conf = jsonUtil.readList(arrayConf, mapType); conf = jsonUtil.readList(arrayConf, mapType);
}catch(Exception e){ }catch(Exception e){
logger.warn("The item id "+workspaceItemId+" has a wrong "+TaskConfiguration.class.getSimpleName()+" saved");
logger.error("Error on serializing configuration: "+arrayConf, e); logger.error("Error on serializing configuration: "+arrayConf, e);
logger.info("The item id "+workspaceItemId+" has a wrong "+TaskConfiguration.class.getSimpleName()+" saved. Deleting them.."); //eraseAllTaskConfigurations(workspaceItemId);
eraseAllTaskConfigurations(workspaceItemId);
} }
logger.debug("Found configuration/s: "+conf); logger.debug("Found configuration/s: "+conf);

View File

@ -3,7 +3,8 @@
*/ */
package org.gcube.common.workspacetaskexecutor.shared; package org.gcube.common.workspacetaskexecutor.shared;
import java.util.Map; import java.util.List;
/** /**
@ -38,11 +39,11 @@ public interface BaseTaskConfiguration {
/** /**
* Gets the map parameters. * Gets the list parameters.
* *
* @return the map parameters * @return the list parameters
*/ */
Map<String, TaskParameter> getMapParameters(); List<TaskParameter> getListParameters();
/** /**

View File

@ -5,7 +5,7 @@
package org.gcube.common.workspacetaskexecutor.shared.dataminer; package org.gcube.common.workspacetaskexecutor.shared.dataminer;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.List;
import java.util.Random; import java.util.Random;
import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration; import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration;
@ -40,7 +40,7 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
private String maskedToken; private String maskedToken;
private String workspaceItemId; private String workspaceItemId;
@JsonIgnoreProperties @JsonIgnoreProperties
private Map<String, TaskParameter> mapParameters; // optional private List<TaskParameter> listParameters; // optional
private String configurationKey; private String configurationKey;
/** /**
@ -59,12 +59,12 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
* @param scope the scope * @param scope the scope
* @param maskedToken the token * @param maskedToken the token
* @param workspaceItemId the workspace item id * @param workspaceItemId the workspace item id
* @param mapParameters the map parameters * @param listParameters the map parameters
*/ */
public TaskConfiguration( public TaskConfiguration(
String configurationKey, String taskId, String taskDescription, String scope, String configurationKey, String taskId, String taskDescription, String scope,
String maskedToken, String workspaceItemId, String maskedToken, String workspaceItemId,
Map<String, TaskParameter> mapParameters) { List<TaskParameter> listParameters) {
setConfigurationKey(configurationKey); setConfigurationKey(configurationKey);
this.taskId = taskId; this.taskId = taskId;
@ -72,7 +72,7 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
this.scope = scope; this.scope = scope;
this.maskedToken = maskedToken; this.maskedToken = maskedToken;
this.workspaceItemId = workspaceItemId; this.workspaceItemId = workspaceItemId;
this.mapParameters = mapParameters; this.listParameters = listParameters;
} }
@ -149,20 +149,20 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
/** /**
* @return the mapParameters * @return the listParameters
*/ */
public Map<String, TaskParameter> getMapParameters() { public List<TaskParameter> getListParameters() {
return mapParameters; return listParameters;
} }
/** /**
* @param mapParameters the mapParameters to set * @param listParameters the listParameters to set
*/ */
public void setMapParameters(Map<String, TaskParameter> mapParameters) { public void setListParameters(List<TaskParameter> listParameters) {
this.mapParameters = mapParameters; this.listParameters = listParameters;
} }
/** /**
@ -234,8 +234,6 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
this.maskedToken = maskedToken; this.maskedToken = maskedToken;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@ -253,8 +251,8 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
builder.append(maskedToken); builder.append(maskedToken);
builder.append(", workspaceItemId="); builder.append(", workspaceItemId=");
builder.append(workspaceItemId); builder.append(workspaceItemId);
builder.append(", mapParameters="); builder.append(", listParameters=");
builder.append(mapParameters); builder.append(listParameters);
builder.append(", configurationKey="); builder.append(", configurationKey=");
builder.append(configurationKey); builder.append(configurationKey);
builder.append("]"); builder.append("]");

View File

@ -5,9 +5,7 @@ package org.gcube.common.workspacetaskexecutor;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
@ -101,7 +99,7 @@ public class TestDataMinerTaskExecutor {
//jsonCheck(); //jsonCheck();
//ERASE ALL CONFIGURATIONS //ERASE ALL CONFIGURATIONS
eraseAllTaskConfigurations(exec); //eraseAllTaskConfigurations(exec);
//GET LIST CONFIGURATIONS //GET LIST CONFIGURATIONS
//getConfigurations(exec); //getConfigurations(exec);
@ -235,22 +233,22 @@ public class TestDataMinerTaskExecutor {
// System.out.println(availableType); // System.out.println(availableType);
// } // }
Map<String, TaskParameter> mapParameters = new HashMap<String, TaskParameter>(); List<TaskParameter> listParameters = new ArrayList<TaskParameter>();
TaskParameter tp = new TaskParameter(); TaskParameter tp = new TaskParameter();
tp.setKey("publiclink"); tp.setKey("publiclink");
tp.setValue("this is the public link "+index); tp.setValue("this is the public link "+index);
tp.setType(new TaskParameterType(ParameterType.FILE.toString())); tp.setType(new TaskParameterType(ParameterType.FILE.toString()));
mapParameters.put("publiclink", tp); listParameters.add(tp);
TaskParameter tp2 = new TaskParameter(); TaskParameter tp2 = new TaskParameter();
tp2.setKey("key"+index); tp2.setKey("key"+index);
tp2.setValue("value "+index); tp2.setValue("value "+index);
tp2.setType(types.get(new Random().nextInt(types.size()))); tp2.setType(types.get(new Random().nextInt(types.size())));
mapParameters.put("publiclink", tp2); listParameters.add(tp2);
return new TaskConfiguration(index+"", UUID.randomUUID().toString(), null, SCOPE, "my token", WORKSPACE_FOLDER_ID, mapParameters); return new TaskConfiguration(index+"", UUID.randomUUID().toString(), null, SCOPE, "my token", WORKSPACE_FOLDER_ID, listParameters);
} }