From 6a5ee65cd9ee7b6e49df7fd0c6d2bf481fa164ff Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Wed, 2 May 2018 14:07:12 +0000 Subject: [PATCH] Enhancement on Project Activity #11690 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@167292 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../workspacetaskexecutor/ExecutableTask.java | 48 -------- .../dataminer/DataMinerAccessPoint.java | 45 +++++--- .../WorkspaceDataMinerTaskExecutor.java | 108 ++++++++++-------- .../BaseTaskConfiguration.java} | 27 +++-- .../shared/BaseTaskExecutionStatus.java | 57 +++++++++ .../{ => shared}/CheckableTask.java | 7 +- .../{ => shared}/ConfigurableTask.java | 12 +- .../shared/ExecutableTask.java | 50 ++++++++ ...figuration.java => TaskConfiguration.java} | 99 ++++++++-------- .../{ => dataminer}/TaskExecutionStatus.java | 55 +++++++-- .../TestDataMinerTaskExecutor.java | 36 +++--- 11 files changed, 330 insertions(+), 214 deletions(-) delete mode 100644 src/main/java/org/gcube/common/workspacetaskexecutor/ExecutableTask.java rename src/main/java/org/gcube/common/workspacetaskexecutor/{TaskConfiguration.java => shared/BaseTaskConfiguration.java} (71%) create mode 100644 src/main/java/org/gcube/common/workspacetaskexecutor/shared/BaseTaskExecutionStatus.java rename src/main/java/org/gcube/common/workspacetaskexecutor/{ => shared}/CheckableTask.java (79%) rename src/main/java/org/gcube/common/workspacetaskexecutor/{ => shared}/ConfigurableTask.java (74%) create mode 100644 src/main/java/org/gcube/common/workspacetaskexecutor/shared/ExecutableTask.java rename src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/{AlgorithmConfiguration.java => TaskConfiguration.java} (67%) rename src/main/java/org/gcube/common/workspacetaskexecutor/shared/{ => dataminer}/TaskExecutionStatus.java (67%) diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/ExecutableTask.java b/src/main/java/org/gcube/common/workspacetaskexecutor/ExecutableTask.java deleted file mode 100644 index 71acc2d..0000000 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/ExecutableTask.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.gcube.common.workspacetaskexecutor; - -import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException; - - - -/** - * The Interface ExecutableTask. - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Apr 27, 2018 - * @param the generic type - */ -public interface ExecutableTask { - - - /** - * Do run. - * - * @param itemId the item id - * @return the o - * @throws ItemNotExecutableException the item not executable - * @throws Exception the exception - */ - T doRun(String itemId) throws ItemNotExecutableException, Exception; - - - /** - * Stop run. - * - * @param itemId the item id - * @return the boolean - * @throws ItemNotExecutableException the item not executable exception - * @throws Exception the exception - */ - Boolean stopRun(String itemId) throws ItemNotExecutableException, Exception; - - /** - * Monitor run status. - * - * @param itemId the item id - * @return the t - * @throws ItemNotExecutableException the item not executable exception - * @throws Exception the exception - */ - T monitorRunStatus(String itemId) throws ItemNotExecutableException, Exception; - -} 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 737add0..5dd194b 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DataMinerAccessPoint.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/DataMinerAccessPoint.java @@ -9,9 +9,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration; import org.gcube.common.workspacetaskexecutor.shared.Status; -import org.gcube.common.workspacetaskexecutor.shared.TaskExecutionStatus; -import org.gcube.common.workspacetaskexecutor.shared.dataminer.AlgorithmConfiguration; +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.data.analysis.dataminermanagercl.server.DataMinerService; import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient; @@ -28,11 +30,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** * The Class DataMinerAccessPoint. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Apr 27, 2018 + * May 2, 2018 */ public class DataMinerAccessPoint { @@ -41,25 +44,26 @@ public class DataMinerAccessPoint { /** The map call back. */ // Fully synchronized HashMap - private Map mapCallBack = Collections.synchronizedMap(new HashMap<>()); + private Map mapExecutionTask = Collections.synchronizedMap(new HashMap<>()); + + /** * Instantiates a new data miner access point. - * - * @throws Exception the exception */ - public DataMinerAccessPoint() throws Exception { + public DataMinerAccessPoint() { dataMinerService = new DataMinerService(); } + /** * Save task. * * @param algConfiguration the alg configuration * @param taskStatus the task status */ - private void saveTask(AlgorithmConfiguration algConfiguration, TaskExecutionStatus taskStatus){ + private void saveTask(BaseTaskConfiguration algConfiguration, TaskExecutionStatus taskStatus){ - mapCallBack.put(algConfiguration.hashCode(), taskStatus); + mapExecutionTask.put(algConfiguration.hashCode(), taskStatus); } @@ -69,8 +73,8 @@ public class DataMinerAccessPoint { * @param algConfiguration the alg configuration * @return the task */ - private TaskExecutionStatus getTask(AlgorithmConfiguration algConfiguration){ - return mapCallBack.get(algConfiguration.hashCode()); + private TaskExecutionStatus getTask(BaseTaskConfiguration algConfiguration){ + return mapExecutionTask.get(algConfiguration.hashCode()); } @@ -82,7 +86,7 @@ public class DataMinerAccessPoint { * @return the task execution status * @throws TaskNotExecutableException the task not executable exception */ - public TaskExecutionStatus doRunTask(AlgorithmConfiguration algConfiguration) throws TaskNotExecutableException{ + public TaskExecutionStatus doRunTask(TaskConfiguration algConfiguration) throws TaskNotExecutableException{ Operator operator; SClient sClient; @@ -116,19 +120,22 @@ public class DataMinerAccessPoint { } } + /** - * Monitoring computation. + * Gets the task status. To monitor the task exection.. * - * @param operatorId the operator id - * @return the task execution status + * @param algConfiguration the alg configuration + * @return the task status + * @throws TaskErrorException the task error exception */ - public TaskExecutionStatus getTaskStatus(AlgorithmConfiguration algConfiguration) { + public TaskExecutionStatus getTaskStatus(BaseTaskConfiguration algConfiguration) throws TaskErrorException{ TaskExecutionStatus task = getTask(algConfiguration); if(task==null){ //TODO //startComputationOnDM(computationId, sClient); + throw new TaskErrorException("No Task running with configuration: "+algConfiguration); } return task; @@ -137,16 +144,16 @@ public class DataMinerAccessPoint { /** - * Start computation on dm. + * Start computation on data miner. * * @param algConfiguration the alg configuration * @param computationId the computation id * @param sClient the s client * @return the task execution status */ - private TaskExecutionStatus startComputationOnDataMiner(AlgorithmConfiguration algConfiguration, final ComputationId computationId, final SClient sClient){ + private TaskExecutionStatus startComputationOnDataMiner(BaseTaskConfiguration algConfiguration, final ComputationId computationId, final SClient sClient){ - TaskExecutionStatus status = new TaskExecutionStatus(); + TaskExecutionStatus status = new TaskExecutionStatus(algConfiguration); DMMonitorListener listener = new DMMonitorListener() { 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 7c30673..4efe2f9 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/dataminer/WorkspaceDataMinerTaskExecutor.java @@ -2,12 +2,14 @@ package org.gcube.common.workspacetaskexecutor.dataminer; import org.apache.commons.lang.Validate; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; -import org.gcube.common.workspacetaskexecutor.CheckableTask; -import org.gcube.common.workspacetaskexecutor.ConfigurableTask; -import org.gcube.common.workspacetaskexecutor.ExecutableTask; -import org.gcube.common.workspacetaskexecutor.shared.TaskExecutionStatus; -import org.gcube.common.workspacetaskexecutor.shared.dataminer.AlgorithmConfiguration; +import org.gcube.common.workspacetaskexecutor.shared.CheckableTask; +import org.gcube.common.workspacetaskexecutor.shared.ConfigurableTask; +import org.gcube.common.workspacetaskexecutor.shared.ExecutableTask; +import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration; +import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskExecutionStatus; import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException; +import org.gcube.common.workspacetaskexecutor.shared.exception.TaskErrorException; +import org.gcube.common.workspacetaskexecutor.shared.exception.TaskNotExecutableException; import org.gcube.common.workspacetaskexecutor.util.JsonUtil; import org.gcube.common.workspacetaskexecutor.util.WsUtil; import org.slf4j.Logger; @@ -20,7 +22,7 @@ import org.slf4j.LoggerFactory; * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * Apr 26, 2018 */ -public class WorkspaceDataMinerTaskExecutor implements ExecutableTask, ConfigurableTask, CheckableTask{ +public class WorkspaceDataMinerTaskExecutor implements ExecutableTask, ConfigurableTask, CheckableTask{ /** The logger. */ private static Logger logger = LoggerFactory.getLogger(WorkspaceDataMinerTaskExecutor.class); @@ -33,9 +35,16 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask jsonUtil = new JsonUtil(); + private JsonUtil jsonUtil = new JsonUtil(); + private DataMinerAccessPoint getDataMinerAccessPoint(){ + if(dataMinerAP==null) + dataMinerAP = new DataMinerAccessPoint(); + + return dataMinerAP; + } + /** * Instantiates a new workspace data miner task executor. */ @@ -78,13 +87,25 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask getMapParameters(); - /** - * Gets the workspace item id where execute the Task - * - * @return the workspace item id - */ - String getWorkspaceItemId(); - - - - } diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/BaseTaskExecutionStatus.java b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/BaseTaskExecutionStatus.java new file mode 100644 index 0000000..140aa9d --- /dev/null +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/BaseTaskExecutionStatus.java @@ -0,0 +1,57 @@ +package org.gcube.common.workspacetaskexecutor.shared; + + + +/** + * The Interface BaseTaskExecutionStatus. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * May 2, 2018 + */ +public interface BaseTaskExecutionStatus { + + + /** + * Gets the error count. + * + * @return the error count + */ + public Long getErrorCount(); + + /** + * Gets the status. + * + * @return the status + */ + public Status getStatus(); + + /** + * Gets the log. + * + * @return the log + */ + public String getLog(); + + /** + * Gets the current message. + * + * @return the current message + */ + public String getCurrentMessage(); + + + /** + * Gets the percent completed. + * + * @return the percent completed + */ + public Float getPercentCompleted(); + + + /** + * Gets the task configuration. + * + * @return the task configuration + */ + public BaseTaskConfiguration getTaskConfiguration(); +} diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/CheckableTask.java b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/CheckableTask.java similarity index 79% rename from src/main/java/org/gcube/common/workspacetaskexecutor/CheckableTask.java rename to src/main/java/org/gcube/common/workspacetaskexecutor/shared/CheckableTask.java index 3fc8cc5..4b0584c 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/CheckableTask.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/CheckableTask.java @@ -1,7 +1,7 @@ /* * */ -package org.gcube.common.workspacetaskexecutor; +package org.gcube.common.workspacetaskexecutor.shared; import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException; @@ -13,7 +13,7 @@ import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutable * Apr 26, 2018 * @param the generic type */ -public interface CheckableTask { +public interface CheckableTask { /** @@ -21,13 +21,12 @@ public interface CheckableTask { * * @param itemId the item id * @return the t - * @throws ItemNotExecutableException the item not executable + * @throws ItemNotExecutableException the item not executable exception * @throws Exception the exception */ T checkItemExecutable(String itemId) throws ItemNotExecutableException, Exception; - /** * Checks if is item executable. * diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/ConfigurableTask.java b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/ConfigurableTask.java similarity index 74% rename from src/main/java/org/gcube/common/workspacetaskexecutor/ConfigurableTask.java rename to src/main/java/org/gcube/common/workspacetaskexecutor/shared/ConfigurableTask.java index 0c6e218..cabed5d 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/ConfigurableTask.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/ConfigurableTask.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.common.workspacetaskexecutor; +package org.gcube.common.workspacetaskexecutor.shared; import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException; @@ -10,23 +10,21 @@ import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutable * The Interface ConfigurableTask. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Apr 26, 2018 + * May 2, 2018 * @param the generic type */ -public interface ConfigurableTask { - +public interface ConfigurableTask { /** * Removes the task configuration. * - * @param workspaceItemId the workspace item id + * @param config the config * @return the boolean * @throws ItemNotExecutableException the item not executable exception * @throws Exception the exception */ - Boolean removeTaskConfiguration(String workspaceItemId) throws ItemNotExecutableException, Exception; - + Boolean removeTaskConfiguration(I config) throws ItemNotExecutableException, Exception; /** diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/ExecutableTask.java b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/ExecutableTask.java new file mode 100644 index 0000000..e11e227 --- /dev/null +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/ExecutableTask.java @@ -0,0 +1,50 @@ +package org.gcube.common.workspacetaskexecutor.shared; + +import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException; +import org.gcube.common.workspacetaskexecutor.shared.exception.TaskErrorException; + + +/** + * The Interface ExecutableTask. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * May 2, 2018 + * @param the generic type must extend {@link BaseTaskConfiguration} + * @param the generic type must extend {@link BaseTaskExecutionStatus} + */ +public interface ExecutableTask { + + + /** + * Do run. + * + * @param taskConfiguration the base task configuration + * @return the o + * @throws ItemNotExecutableException the item not executable exception + * @throws Exception the exception + */ + O doRun(I taskConfiguration) throws ItemNotExecutableException, Exception; + + + /** + * Stop run. + * + * @param taskConfiguration the task configuration + * @return the boolean + * @throws TaskErrorException the task error exception + * @throws Exception the exception + */ + Boolean stopRun(I taskConfiguration) throws TaskErrorException, Exception; + + + /** + * Monitor run status. + * + * @param taskConfiguration the task configuration + * @return the o + * @throws TaskErrorException the task error exception + * @throws Exception the exception + */ + O monitorRunStatus(I taskConfiguration) throws TaskErrorException, Exception; + +} diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/AlgorithmConfiguration.java b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/TaskConfiguration.java similarity index 67% rename from src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/AlgorithmConfiguration.java rename to src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/TaskConfiguration.java index f7defb2..333e709 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/AlgorithmConfiguration.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/TaskConfiguration.java @@ -7,24 +7,24 @@ package org.gcube.common.workspacetaskexecutor.shared.dataminer; import java.io.Serializable; import java.util.Map; -import org.gcube.common.workspacetaskexecutor.TaskConfiguration; +import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** - * The Class AlgorithmConfiguration. + * The Class TaskConfiguration. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Apr 26, 2018 + * May 2, 2018 */ -public class AlgorithmConfiguration implements TaskConfiguration, Serializable { +public class TaskConfiguration implements BaseTaskConfiguration, Serializable { /** * */ private static final long serialVersionUID = -3380573762288127547L; - private String taskId; + private String algorithmId; @JsonIgnoreProperties private String taskDescription; //optional private String token; @@ -34,25 +34,26 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { /** * Instantiates a new run algorithm configuration. */ - public AlgorithmConfiguration() { + public TaskConfiguration() { } + /** - * Instantiates a new algorithm configuration. + * Instantiates a new task configuration. * - * @param taskId the task id + * @param algorithmId the algorithm id * @param taskDescription the task description * @param token the token * @param workspaceItemId the workspace item id * @param mapParameters the map parameters */ - public AlgorithmConfiguration( - String taskId, String taskDescription, String token, + public TaskConfiguration( + String algorithmId, String taskDescription, String token, String workspaceItemId, Map mapParameters) { super(); - this.taskId = taskId; + this.algorithmId = algorithmId; this.taskDescription = taskDescription; this.token = token; this.workspaceItemId = workspaceItemId; @@ -60,17 +61,28 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { } - /** - * Gets the task id. - * - * @return the taskId + /* (non-Javadoc) + * @see org.gcube.common.workspacetaskexecutor.TaskConfiguration#getTaskId() */ + @Override public String getTaskId() { - return taskId; + return algorithmId; } + /** + * Gets the algorithm id. + * + * @return the algorithmId + */ + public String getAlgorithmId() { + + return algorithmId; + } + + + /** * Gets the task description. * @@ -82,6 +94,7 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { } + /** * Gets the token. * @@ -93,6 +106,7 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { } + /** * Gets the workspace item id. * @@ -104,6 +118,7 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { } + /** * Gets the map parameters. * @@ -115,17 +130,19 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { } - /** - * Sets the task id. - * - * @param taskId the taskId to set - */ - public void setTaskId(String taskId) { - this.taskId = taskId; + /** + * Sets the algorithm id. + * + * @param algorithmId the algorithmId to set + */ + public void setAlgorithmId(String algorithmId) { + + this.algorithmId = algorithmId; } + /** * Sets the task description. * @@ -137,6 +154,7 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { } + /** * Sets the token. * @@ -147,6 +165,8 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { this.token = token; } + + /** * Sets the workspace item id. * @@ -158,6 +178,7 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { } + /** * Sets the map parameters. * @@ -168,36 +189,20 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable { this.mapParameters = mapParameters; } + + + + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ @Override public int hashCode() { int hash = 1; - hash = hash * 13 + (taskId == null ? 0 : taskId.hashCode()); + hash = hash * 13 + (algorithmId == null ? 0 : algorithmId.hashCode()); hash = hash * 17 + (workspaceItemId == null ? 0 : workspaceItemId.hashCode()); return hash; } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - StringBuilder builder = new StringBuilder(); - builder.append("AlgorithmConfiguration [taskId="); - builder.append(taskId); - builder.append(", taskDescription="); - builder.append(taskDescription); - builder.append(", token="); - builder.append(token); - builder.append(", workspaceItemId="); - builder.append(workspaceItemId); - builder.append(", mapParameters="); - builder.append(mapParameters); - builder.append("]"); - return builder.toString(); - } - - - } diff --git a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskExecutionStatus.java b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/TaskExecutionStatus.java similarity index 67% rename from src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskExecutionStatus.java rename to src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/TaskExecutionStatus.java index f290d85..ba9cc2b 100644 --- a/src/main/java/org/gcube/common/workspacetaskexecutor/shared/TaskExecutionStatus.java +++ b/src/main/java/org/gcube/common/workspacetaskexecutor/shared/dataminer/TaskExecutionStatus.java @@ -1,7 +1,11 @@ -package org.gcube.common.workspacetaskexecutor.shared; +package org.gcube.common.workspacetaskexecutor.shared.dataminer; import java.io.Serializable; +import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration; +import org.gcube.common.workspacetaskexecutor.shared.BaseTaskExecutionStatus; +import org.gcube.common.workspacetaskexecutor.shared.Status; + /** @@ -10,7 +14,7 @@ import java.io.Serializable; * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * Apr 27, 2018 */ -public class TaskExecutionStatus implements Serializable { +public class TaskExecutionStatus implements BaseTaskExecutionStatus, Serializable { /** * @@ -19,36 +23,51 @@ public class TaskExecutionStatus implements Serializable { private Long errorCount; private Status status; - private float percentCompleted = 0; + private Float percentCompleted = new Float(0); private String log; private String currentMessage="Waiting to start.."; + private BaseTaskConfiguration taskConfiguration; + /** - * Instantiates a new task exection status. + * Instantiates a new task execution status. */ public TaskExecutionStatus() { } + /** + * Instantiates a new task execution status. + * + * @param taskConfiguration the task configuration + */ + public TaskExecutionStatus(BaseTaskConfiguration taskConfiguration) { + this.taskConfiguration = taskConfiguration; + } + + /** * Instantiates a new task execution status. * * @param errorCount the error count * @param status the status + * @param percentCompleted the percent completed * @param log the log * @param currentMessage the current message - * @param percentCompleted the percent completed + * @param taskConfiguration the task configuration */ - public TaskExecutionStatus(Long errorCount, Status status, - String log, String currentMessage, float percentCompleted) { - super(); + public TaskExecutionStatus( + Long errorCount, Status status, Float percentCompleted, String log, + String currentMessage, TaskConfiguration taskConfiguration) { this.errorCount = errorCount; this.status = status; + this.percentCompleted = percentCompleted; this.log = log; this.currentMessage = currentMessage; - this.percentCompleted = percentCompleted; + this.taskConfiguration = taskConfiguration; } + /** * Gets the error count. * @@ -130,7 +149,7 @@ public class TaskExecutionStatus implements Serializable { * * @return the percent completed */ - public float getPercentCompleted() { + public Float getPercentCompleted() { return percentCompleted; } @@ -143,6 +162,18 @@ public class TaskExecutionStatus implements Serializable { this.percentCompleted = percentCompleted; } + + /** + * Gets the task configuration. + * + * @return the task configuration + */ + public BaseTaskConfiguration getTaskConfiguration() { + + return taskConfiguration; + } + + /* (non-Javadoc) * @see java.lang.Object#toString() */ @@ -150,7 +181,7 @@ public class TaskExecutionStatus implements Serializable { public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("RunningTaskStatus [errorCount="); + builder.append("TaskExecutionStatus [errorCount="); builder.append(errorCount); builder.append(", status="); builder.append(status); @@ -160,6 +191,8 @@ public class TaskExecutionStatus implements Serializable { builder.append(log); builder.append(", currentMessage="); builder.append(currentMessage); + builder.append(", taskConfiguration="); + builder.append(taskConfiguration); builder.append("]"); return builder.toString(); } diff --git a/src/test/java/org/gcube/common/workspacetaskexecutor/TestDataMinerTaskExecutor.java b/src/test/java/org/gcube/common/workspacetaskexecutor/TestDataMinerTaskExecutor.java index 54df43d..8ae3184 100644 --- a/src/test/java/org/gcube/common/workspacetaskexecutor/TestDataMinerTaskExecutor.java +++ b/src/test/java/org/gcube/common/workspacetaskexecutor/TestDataMinerTaskExecutor.java @@ -8,8 +8,7 @@ import java.util.Map; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.workspacetaskexecutor.dataminer.WorkspaceDataMinerTaskExecutor; -import org.gcube.common.workspacetaskexecutor.shared.dataminer.AlgorithmConfiguration; -import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException; +import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration; /** @@ -31,20 +30,21 @@ public class TestDataMinerTaskExecutor { WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance(); exec.withOwner(USERNAME); - try { - exec.removeTaskConfiguration(WORKSPACE_FOLDER_ID); - //exec.checkItemExecutable(WORKSPACE_FOLDER_ID); - } - catch (ItemNotExecutableException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - - System.out.println("The item is not executable..."); - } - catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } +// try { +// new TaskConfiguration(algorithmId, taskDescription, token, workspaceItemId, mapParameters) +// exec.removeTaskConfiguration(WORKSPACE_FOLDER_ID); +// //exec.checkItemExecutable(WORKSPACE_FOLDER_ID); +// } +// catch (ItemNotExecutableException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// +// System.out.println("The item is not executable..."); +// } +// catch (Exception e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } @@ -74,10 +74,10 @@ public class TestDataMinerTaskExecutor { } - public static AlgorithmConfiguration createDummyConfiguration(){ + public static TaskConfiguration createDummyConfiguration(){ Map mapParameters = new HashMap(); mapParameters.put("publiclink", "this is the public link"); - return new AlgorithmConfiguration("this is the task id", null, "my token", WORKSPACE_FOLDER_ID, mapParameters); + return new TaskConfiguration("this is the task id", null, "my token", WORKSPACE_FOLDER_ID, mapParameters); } }