diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DMConverter.java b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DMConverter.java index 99f3b29..8cf7f44 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DMConverter.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DMConverter.java @@ -3,7 +3,12 @@ */ package org.gcube.common.workspacetaskexecutor.dataminer; +import java.util.ArrayList; +import java.util.List; + +import org.gcube.common.workspacetaskexecutor.shared.TaskOperator; import org.gcube.common.workspacetaskexecutor.shared.TaskParameter; +import org.gcube.common.workspacetaskexecutor.shared.TaskParameterType; import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskComputation; import org.gcube.data.analysis.dataminermanagercl.shared.data.computations.ComputationId; import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ColumnListParameter; @@ -19,6 +24,7 @@ import org.gcube.data.analysis.dataminermanagercl.shared.parameters.TabularListP 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.gcube.data.analysis.dataminermanagercl.shared.process.Operator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +45,8 @@ public class DMConverter { * To dm computation id. * * @param computationId the computation id + * @param startTime the start time + * @param endTime the end time * @return the task computation */ public static TaskComputation toDMComputationId(ComputationId computationId, Long startTime, Long endTime){ @@ -66,14 +74,67 @@ public class DMConverter { } + /** + * To task operator. + * + * @param op the op + * @return the task operator + */ + public static TaskOperator toTaskOperator(Operator op){ + + if(op==null) + return null; + + List listOperator = null; + if(op.getOperatorParameters()!=null){ + listOperator = new ArrayList(op.getOperatorParameters().size()); + for (Parameter param : op.getOperatorParameters()) { + TaskParameter tp = toTaskParameter(param); + if(tp!=null) + listOperator.add(tp); + } + } + + return new TaskOperator(op.getId(), op.getName(), op.getBriefDescription(), op.getDescription(), listOperator,op.hasImage()); + } + /** - * To dm parameter. + * To task parameter. + * + * @param parameter the parameter + * @return the task parameter + */ + public static TaskParameter toTaskParameter(Parameter parameter){ + + if(parameter==null) + return null; + + return new TaskParameter(parameter.getName(), parameter.getValue(), parameter.getValue(), toTaskParameterType(parameter.getTypology())); + + } + + /** + * To task parameter type. + * + * @param type the type + * @return the task parameter type + */ + public static TaskParameterType toTaskParameterType(ParameterType type){ + if(type==null) + return null; + + return new TaskParameterType(type.name().toString()); + } + + + /** + * To task parameter. * * @param taskParameter the task parameter * @return the parameter */ - public static Parameter toDMParameter(TaskParameter taskParameter){ + public static Parameter toParameter(TaskParameter taskParameter){ ParameterType toParameterType = null; try{ diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DataMinerAccessPoint.java b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DataMinerAccessPoint.java index e995f3e..74b9113 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DataMinerAccessPoint.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DataMinerAccessPoint.java @@ -10,13 +10,16 @@ import java.util.List; import java.util.Map; import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration; +import org.gcube.common.workspacetaskexecutor.shared.TaskOperator; import org.gcube.common.workspacetaskexecutor.shared.TaskParameter; +import org.gcube.common.workspacetaskexecutor.shared.TaskParameterType; import org.gcube.common.workspacetaskexecutor.shared.TaskStatus; import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskComputation; import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration; import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskExecutionStatus; import org.gcube.common.workspacetaskexecutor.shared.exception.TaskErrorException; import org.gcube.common.workspacetaskexecutor.shared.exception.TaskNotExecutableException; +import org.gcube.common.workspacetaskexecutor.util.Converter; import org.gcube.common.workspacetaskexecutor.util.EncrypterUtil; import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService; import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient; @@ -25,9 +28,11 @@ 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.Resource; 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; +import org.gcube.data.analysis.dataminermanagercl.shared.process.OperatorsClassification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -204,13 +209,6 @@ public class DataMinerAccessPoint { */ private TaskExecutionStatus loadTaskExecutionStatus(TaskConfiguration taskConfiguration, final TaskComputation taskComputation) throws TaskErrorException, TaskNotExecutableException{ - TaskExecutionStatus oldTaskExecutionStatus = getRunningTask(taskConfiguration); - -// Long startTime = taskComputation.getStartTime(); -// if(oldTaskExecutionStatus!=null) -// startTime = oldTaskExecutionStatus.getTaskComputation().getStartTime(); //copyng start time from bean saved on server - - SClient sClient; ComputationId computationId = DMConverter.toComputationId(taskComputation); try { @@ -224,27 +222,6 @@ public class DataMinerAccessPoint { TaskExecutionStatus newTaskExecutionStatus = new TaskExecutionStatus(taskConfiguration, taskComputation); - /* - if(!isStart) - //adding previous log - if(oldTaskExecutionStatus.getLog().length()>maxLogSize){ - String confs=NEW_LINE+NEW_STATUS_CHARS+Converter.getCurrentFormattedDate(null)+NEW_LINE; - confs+="Cancelled previous logs"; - newTaskExecutionStatus.addLog(confs); - }else - newTaskExecutionStatus.addLog(oldTaskExecutionStatus.getLog()); - - else{ - //first time adding the configurations - String confs=NEW_LINE+NEW_STATUS_CHARS+Converter.getCurrentFormattedDate(null)+NEW_LINE; - confs+="Computation starts with configurations..."; - confs+=NEW_LINE+NEW_LINE+DASH+DASH+"Operator Id: "+NEW_LINE+newTaskExecutionStatus.getTaskComputation().getOperatorId(); - confs+=NEW_LINE+NEW_LINE+DASH+DASH+"Operator Name: "+NEW_LINE+newTaskExecutionStatus.getTaskComputation().getOperatorName(); - confs+=NEW_LINE+NEW_LINE+DASH+DASH+"EquivalentRequest: "+NEW_LINE+newTaskExecutionStatus.getTaskComputation().getEquivalentRequest(); - confs+=NEW_LINE+NEW_LINE+DASH+DASH+"URL ID: "+NEW_LINE+newTaskExecutionStatus.getTaskComputation().getUrlId(); - newTaskExecutionStatus.addLog(confs+NEW_LINE); - }*/ - logger.debug("Requesting operation progress"); ComputationStatus computationStatus = null; try { @@ -373,7 +350,7 @@ public class DataMinerAccessPoint { if(taskParameter.getType()==null) continue; - Parameter dmParameter = DMConverter.toDMParameter(taskParameter); + Parameter dmParameter = DMConverter.toParameter(taskParameter); if(dmParameter!=null) listParameters.add(dmParameter); @@ -385,5 +362,62 @@ public class DataMinerAccessPoint { } + /** + * Gets the parameter types. + * + * @return the parameter types + */ + public List getParameterTypes(){ + List typeNames = Converter.getEnumList(ParameterType.class); + List types = new ArrayList(); + for (ParameterType parameterType : typeNames) { + types.add(new TaskParameterType(parameterType.name())); + } + return types; + + } + + + /** + * Gets the list operators. + * + * @return the list operators + * @throws Exception the exception + */ + public List getListOperators() throws Exception { + SClient sClient = dataMinerService.getClient(); + List listOperator = new ArrayList(); + List operatorsClassifications = sClient.getOperatorsClassifications(); + + //logger.debug("OperatorsClassifications: " + operatorsClassifications); + + if(operatorsClassifications!=null && operatorsClassifications.size()>0){ + //GET THE FIRST CATEGORY + OperatorsClassification firstCategory=operatorsClassifications.get(0); + + if(firstCategory.getOperators()!=null&& !firstCategory.getOperators().isEmpty()){ + for (Operator operator : firstCategory.getOperators()) { + TaskOperator to = DMConverter.toTaskOperator(operator); + if(to!=null) + listOperator.add(to); + } + + //firstCategory.getOperators(); // RETURNS THE LIST OF ALGORITHMS +// Operator operator=firstCategory.getOperators().get(0); +// logger.debug("First Operator: "+operator); +// List inputParameters=sClient.getInputParameters(operator); +// logger.debug("Input Parameters: "+inputParameters); +// +// List outputParameters=sClient.getOutputParameters(operator); +// logger.debug("Output Parameters: "+outputParameters); + + } else { + logger.debug("Operators void"); + } + } + + return listOperator; + } + } diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java index bf755d5..a340d09 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java @@ -7,6 +7,7 @@ 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.TaskOperator; import org.gcube.common.workspacetaskexecutor.shared.TaskParameterType; import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskComputation; import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration; @@ -17,10 +18,8 @@ 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; @@ -320,18 +319,14 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask getParameterTypes(){ - List typeNames = Converter.getEnumList(ParameterType.class); - List types = new ArrayList(); - for (ParameterType parameterType : typeNames) { - types.add(new TaskParameterType(parameterType.name())); - } - return types; + return getDataMinerAccessPoint().getParameterTypes(); } @@ -394,6 +389,16 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask getListOperators() throws Exception{ + DataMinerAccessPoint dap = getDataMinerAccessPoint(); + return dap.getListOperators(); + } } diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskOperator.java b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskOperator.java new file mode 100644 index 0000000..0e30290 --- /dev/null +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskOperator.java @@ -0,0 +1,217 @@ +/** + * + */ +package org.gcube.common.workspacetaskexecutor.shared; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +/** + * The Class TaskOperator. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * May 17, 2018 + */ +public class TaskOperator implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 870261128077798937L; + private String id; + private String name; + private String briefDescription; + private String description; + private List operatorParameters = new ArrayList(); + private boolean hasImage = false; + + /** + * Instantiates a new task operator. + */ + public TaskOperator() { + + // TODO Auto-generated constructor stub + } + + /** + * Instantiates a new task operator. + * + * @param id the id + * @param name the name + * @param briefDescription the brief description + * @param description the description + * @param operatorParameters the operator parameters + * @param hasImage the has image + */ + public TaskOperator( + String id, String name, String briefDescription, String description, + List operatorParameters, boolean hasImage) { + + this.id = id; + this.name = name; + this.briefDescription = briefDescription; + this.description = description; + this.operatorParameters = operatorParameters; + this.hasImage = hasImage; + } + + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + + return id; + } + + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + + return name; + } + + + /** + * Gets the brief description. + * + * @return the briefDescription + */ + public String getBriefDescription() { + + return briefDescription; + } + + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + + return description; + } + + + /** + * Gets the operator parameters. + * + * @return the operatorParameters + */ + public List getOperatorParameters() { + + return operatorParameters; + } + + + /** + * Checks if is checks for image. + * + * @return the hasImage + */ + public boolean isHasImage() { + + return hasImage; + } + + + /** + * Sets the id. + * + * @param id the id to set + */ + public void setId(String id) { + + this.id = id; + } + + + /** + * Sets the name. + * + * @param name the name to set + */ + public void setName(String name) { + + this.name = name; + } + + + /** + * Sets the brief description. + * + * @param briefDescription the briefDescription to set + */ + public void setBriefDescription(String briefDescription) { + + this.briefDescription = briefDescription; + } + + + /** + * Sets the description. + * + * @param description the description to set + */ + public void setDescription(String description) { + + this.description = description; + } + + + /** + * Sets the operator parameters. + * + * @param operatorParameters the operatorParameters to set + */ + public void setOperatorParameters(List operatorParameters) { + + this.operatorParameters = operatorParameters; + } + + + /** + * Sets the checks for image. + * + * @param hasImage the hasImage to set + */ + public void setHasImage(boolean hasImage) { + + this.hasImage = hasImage; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("TaskOperator [id="); + builder.append(id); + builder.append(", name="); + builder.append(name); + builder.append(", briefDescription="); + builder.append(briefDescription); + builder.append(", description="); + builder.append(description); + builder.append(", operatorParameters="); + builder.append(operatorParameters); + builder.append(", hasImage="); + builder.append(hasImage); + builder.append("]"); + return builder.toString(); + } + + + +} diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskParameter.java b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskParameter.java index 8c68a74..aed913f 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskParameter.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskParameter.java @@ -42,7 +42,6 @@ public class TaskParameter implements Serializable{ */ public TaskParameter(String key, String value, String defaultValue, TaskParameterType type) { - super(); this.key = key; this.defaultValue = defaultValue; this.value = value;