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
This commit is contained in:
Francesco Mangiacrapa 2018-05-02 14:07:12 +00:00
parent dca15a6a93
commit 6a5ee65cd9
11 changed files with 330 additions and 214 deletions

View File

@ -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 <T> the generic type
*/
public interface ExecutableTask<T> {
/**
* 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;
}

View File

@ -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<Integer, TaskExecutionStatus> mapCallBack = Collections.synchronizedMap(new HashMap<>());
private Map<Integer, TaskExecutionStatus> 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() {

View File

@ -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<TaskExecutionStatus>, ConfigurableTask<AlgorithmConfiguration>, CheckableTask<AlgorithmConfiguration>{
public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfiguration, TaskExecutionStatus>, ConfigurableTask<TaskConfiguration>, CheckableTask<TaskConfiguration>{
/** The logger. */
private static Logger logger = LoggerFactory.getLogger(WorkspaceDataMinerTaskExecutor.class);
@ -33,9 +35,16 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskExecut
private DataMinerAccessPoint dataMinerAP;
private JsonUtil<AlgorithmConfiguration> jsonUtil = new JsonUtil<AlgorithmConfiguration>();
private JsonUtil<TaskConfiguration> jsonUtil = new JsonUtil<TaskConfiguration>();
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<TaskExecut
}
/**
* Validate task configuration.
*
* @param taskConfiguration the task configuration
*/
private static void ValidateTaskConfiguration(TaskConfiguration taskConfiguration) throws Exception {
Validate.notNull(taskConfiguration, "The "+TaskConfiguration.class.getSimpleName()+" is null");
Validate.notNull(taskConfiguration.getWorkspaceItemId(), "The WorkspaceItem Id in the configuration is null");
Validate.notNull(taskConfiguration.getTaskId(), "The Task Id in the configuration is null");
}
/* (non-Javadoc)
* @see org.gcube.common.workspacetaskexecutor.CheckableTask#checkItemExecutable(java.lang.String)
*/
@Override
public AlgorithmConfiguration checkItemExecutable(String workspaceItemId) throws ItemNotExecutableException, Exception {
public TaskConfiguration checkItemExecutable(String workspaceItemId) throws ItemNotExecutableException, Exception {
AlgorithmConfiguration conf = null;
TaskConfiguration conf = null;
checkOwner();
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
String propConfigValue = WsUtil.getPropertyValue(item, WS_TASK_TASK_CONF);
@ -92,13 +113,13 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskExecut
logger.info("Read "+WS_TASK_TASK_CONF+" value: "+propConfigValue);
if(propConfigValue==null || propConfigValue.isEmpty())
throw new ItemNotExecutableException("The item id "+workspaceItemId+" has not a "+AlgorithmConfiguration.class.getSimpleName());
throw new ItemNotExecutableException("The item id "+workspaceItemId+" has not a "+TaskConfiguration.class.getSimpleName());
try{
conf = jsonUtil.readObject(propConfigValue, AlgorithmConfiguration.class);
conf = jsonUtil.readObject(propConfigValue, TaskConfiguration.class);
}catch(Exception e){
logger.error("Error on serializing configuration: "+propConfigValue, e);
throw new ItemNotExecutableException("The item id "+workspaceItemId+" has a wrong "+AlgorithmConfiguration.class.getSimpleName()+". Do you want create a new one?");
throw new ItemNotExecutableException("The item id "+workspaceItemId+" has a wrong "+TaskConfiguration.class.getSimpleName()+". Do you want create a new one?");
}
logger.info("Found configuration: "+conf);
@ -122,7 +143,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskExecut
}
try{
jsonUtil.readObject(propConfigValue, AlgorithmConfiguration.class);
jsonUtil.readObject(propConfigValue, TaskConfiguration.class);
logger.debug("The item: "+workspaceItemId+" has a valid "+WS_TASK_TASK_CONF+" configuration");
return true;
}catch(Exception e){
@ -137,19 +158,19 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskExecut
* @see org.gcube.common.workspacetaskexecutor.ConfigurableTask#removeTaskConfig(java.lang.Object)
*/
@Override
public Boolean removeTaskConfiguration(String workspaceItemId) throws ItemNotExecutableException, Exception {
Validate.notNull(workspaceItemId, "The worksapce item id is null");
public Boolean removeTaskConfiguration(TaskConfiguration taskConfiguration) throws ItemNotExecutableException, Exception {
ValidateTaskConfiguration(taskConfiguration);
checkOwner();
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
WorkspaceItem item = WsUtil.getItem(usernameOwner, taskConfiguration.getWorkspaceItemId());
String propConfig = WsUtil.getPropertyValue(item, WS_TASK_TASK_CONF);
if(propConfig==null || propConfig.isEmpty())
throw new ItemNotExecutableException("The item id "+workspaceItemId+" has not a "+AlgorithmConfiguration.class.getSimpleName());
throw new ItemNotExecutableException("The item id "+taskConfiguration.getWorkspaceItemId()+" has not a "+TaskConfiguration.class.getSimpleName());
WsUtil.setPropertyValue(item, WS_TASK_TASK_CONF, null);
logger.info("Set property value "+WS_TASK_TASK_CONF+" as null for the workspace item id: "+workspaceItemId);
logger.info("Set property value "+WS_TASK_TASK_CONF+" as null for the workspace item id: "+taskConfiguration.getWorkspaceItemId());
return true;
}
@ -158,18 +179,18 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskExecut
* @see org.gcube.common.workspacetaskexecutor.ConfigurableTask#addTaskConfig(java.lang.Object)
*/
@Override
public Boolean setTaskConfiguration(AlgorithmConfiguration config) throws Exception {
public Boolean setTaskConfiguration(TaskConfiguration taskConfiguration) throws Exception {
Validate.notNull(config, "The "+AlgorithmConfiguration.class.getSimpleName()+" instance is null");
ValidateTaskConfiguration(taskConfiguration);
checkOwner();
WorkspaceItem item = WsUtil.getItem(usernameOwner, config.getWorkspaceItemId());
WorkspaceItem item = WsUtil.getItem(usernameOwner, taskConfiguration.getWorkspaceItemId());
String jsonConfValue = null;
try{
jsonConfValue = jsonUtil.toJSON(config);
jsonConfValue = jsonUtil.toJSON(taskConfiguration);
logger.debug("The json configuration is: "+jsonConfValue);
}catch(Exception e){
throw new Exception("This "+config+" is wrong!. Please create a new one");
throw new Exception("This "+taskConfiguration+" is wrong!. Please create a new one");
}
if(jsonConfValue!=null){
@ -181,48 +202,43 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskExecut
}
/* (non-Javadoc)
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#doRun(java.lang.String)
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#doRun(org.gcube.common.workspacetaskexecutor.BaseTaskConfiguration)
*/
@Override
public TaskExecutionStatus doRun(String workspaceItemId) throws ItemNotExecutableException, Exception {
public TaskExecutionStatus doRun(TaskConfiguration taskConfiguration)
throws ItemNotExecutableException, TaskNotExecutableException, Exception {
Validate.notNull(workspaceItemId, "The worksapce item id is null");
ValidateTaskConfiguration(taskConfiguration);
checkOwner();
AlgorithmConfiguration conf = checkItemExecutable(workspaceItemId);
TaskConfiguration conf = checkItemExecutable(taskConfiguration.getWorkspaceItemId());
if(dataMinerAP==null)
dataMinerAP = new DataMinerAccessPoint();
dataMinerAP.doRunTask(conf);
return null;
DataMinerAccessPoint dap = getDataMinerAccessPoint();
return dap.doRunTask(conf);
}
/* (non-Javadoc)
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#stopRun(java.lang.String)
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#stopRun(org.gcube.common.workspacetaskexecutor.BaseTaskConfiguration)
*/
@Override
public Boolean stopRun(String itemId)
throws ItemNotExecutableException, Exception {
public Boolean stopRun(TaskConfiguration taskConfiguration)
throws TaskErrorException, Exception {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#monitorRunStatus(java.lang.String)
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#monitorRunStatus(org.gcube.common.workspacetaskexecutor.BaseTaskConfiguration)
*/
@Override
public TaskExecutionStatus monitorRunStatus(String itemId)
throws ItemNotExecutableException, Exception {
public TaskExecutionStatus monitorRunStatus(
TaskConfiguration taskConfiguration)
throws TaskErrorException, Exception {
// TODO Auto-generated method stub
return null;
ValidateTaskConfiguration(taskConfiguration);
DataMinerAccessPoint dap = getDataMinerAccessPoint();
return dap.getTaskStatus(taskConfiguration);
}
}

View File

@ -1,17 +1,18 @@
/**
*
*/
package org.gcube.common.workspacetaskexecutor;
package org.gcube.common.workspacetaskexecutor.shared;
import java.util.Map;
/**
* The Interface DoTaskConfiguration.
* The Interface BaseTaskConfiguration.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Apr 26, 2018
* May 2, 2018
*/
public interface TaskConfiguration {
public interface BaseTaskConfiguration {
/**
@ -21,6 +22,14 @@ public interface TaskConfiguration {
*/
String getTaskId();
/**
* Gets the workspace item id where execute the Task.
*
* @return the workspace item id
*/
String getWorkspaceItemId();
/**
* Gets the task description.
*
@ -37,14 +46,4 @@ public interface TaskConfiguration {
Map<String, String> getMapParameters();
/**
* Gets the workspace item id where execute the Task
*
* @return the workspace item id
*/
String getWorkspaceItemId();
}

View File

@ -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();
}

View File

@ -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 <T> the generic type
*/
public interface CheckableTask<T> {
public interface CheckableTask<T extends BaseTaskConfiguration> {
/**
@ -21,13 +21,12 @@ public interface CheckableTask<T> {
*
* @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.
*

View File

@ -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 <I> the generic type
*/
public interface ConfigurableTask<I> {
public interface ConfigurableTask<I extends BaseTaskConfiguration> {
/**
* 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;
/**

View File

@ -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 <I> the generic type must extend {@link BaseTaskConfiguration}
* @param <O> the generic type must extend {@link BaseTaskExecutionStatus}
*/
public interface ExecutableTask<I extends BaseTaskConfiguration, O extends BaseTaskExecutionStatus> {
/**
* 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;
}

View File

@ -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<String, String> 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();
}
}

View File

@ -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();
}

View File

@ -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<String, String> mapParameters = new HashMap<String, String>();
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);
}
}