Enhancement on Project Activity #11690
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@167246 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2c20aa6b53
commit
a570e260db
7
pom.xml
7
pom.xml
|
@ -57,6 +57,13 @@
|
|||
<artifactId>common-encryption</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.analysis</groupId>
|
||||
<artifactId>data-miner-manager-cl</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- FWS -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
package org.gcube.common.workspacetaskexecutor;
|
||||
|
||||
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -26,4 +26,16 @@ public interface CheckableTask<T> {
|
|||
*/
|
||||
T checkItemExecutable(String itemId) throws ItemNotExecutableException, Exception;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is item executable.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @return the boolean
|
||||
* @throws ItemNotExecutableException the item not executable exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
Boolean isItemExecutable(String itemId) throws ItemNotExecutableException, Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
package org.gcube.common.workspacetaskexecutor;
|
||||
|
||||
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -16,24 +16,26 @@ import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
|
|||
public interface ConfigurableTask<I> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes the task config.
|
||||
* Removes the task configuration.
|
||||
*
|
||||
* @param workspaceItemId the workspace item id
|
||||
* @return the boolean
|
||||
* @throws ItemNotExecutableException the item not executable
|
||||
* @throws ItemNotExecutableException the item not executable exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
Boolean removeTaskConfig(String workspaceItemId) throws ItemNotExecutableException, Exception;
|
||||
Boolean removeTaskConfiguration(String workspaceItemId) throws ItemNotExecutableException, Exception;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds the task config.
|
||||
* Sets the task configuration.
|
||||
*
|
||||
* @param config the config
|
||||
* @return the boolean
|
||||
* @throws ItemNotExecutableException the item not executable
|
||||
* @throws ItemNotExecutableException the item not executable exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
Boolean setTaskConfig(I config) throws ItemNotExecutableException, Exception;
|
||||
Boolean setTaskConfiguration(I config) throws ItemNotExecutableException, Exception;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package org.gcube.common.workspacetaskexecutor;
|
||||
|
||||
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Interface DoExcecutorTask.
|
||||
* The Interface ExecutableTask.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 26, 2018
|
||||
* @param <O> the generic type
|
||||
* Apr 27, 2018
|
||||
* @param <T> the generic type
|
||||
*/
|
||||
public interface ExecutableTask<O> {
|
||||
public interface ExecutableTask<T> {
|
||||
|
||||
|
||||
/**
|
||||
|
@ -21,37 +22,27 @@ public interface ExecutableTask<O> {
|
|||
* @throws ItemNotExecutableException the item not executable
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
O doRun(String itemId) throws ItemNotExecutableException, Exception;
|
||||
T doRun(String itemId) throws ItemNotExecutableException, Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Stop run.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @return the boolean
|
||||
* @throws ItemNotExecutableException the item not executable
|
||||
* @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 o
|
||||
* @throws ItemNotExecutableException the item not executable
|
||||
* @return the t
|
||||
* @throws ItemNotExecutableException the item not executable exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
O monitorRunStatus(String itemId) throws ItemNotExecutableException, Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Register callback for id.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
void registerCallbackForId(String itemId) throws Exception;
|
||||
|
||||
T monitorRunStatus(String itemId) throws ItemNotExecutableException, Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
*
|
||||
*/
|
||||
package org.gcube.common.workspacetaskexecutor.dataminer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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.exception.TaskNotExecutableException;
|
||||
import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService;
|
||||
import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient;
|
||||
import org.gcube.data.analysis.dataminermanagercl.server.monitor.DMMonitor;
|
||||
import org.gcube.data.analysis.dataminermanagercl.server.monitor.DMMonitorListener;
|
||||
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.process.Operator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class DataMinerAccessPoint.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 27, 2018
|
||||
*/
|
||||
public class DataMinerAccessPoint {
|
||||
|
||||
private DataMinerService dataMinerService;
|
||||
private static Logger logger = LoggerFactory.getLogger(DataMinerAccessPoint.class);
|
||||
|
||||
/** The map call back. */
|
||||
// Fully synchronized HashMap
|
||||
private Map<Integer, TaskExecutionStatus> mapCallBack = Collections.synchronizedMap(new HashMap<>());
|
||||
/**
|
||||
* Instantiates a new data miner access point.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public DataMinerAccessPoint() throws Exception {
|
||||
dataMinerService = new DataMinerService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save task.
|
||||
*
|
||||
* @param algConfiguration the alg configuration
|
||||
* @param taskStatus the task status
|
||||
*/
|
||||
private void saveTask(AlgorithmConfiguration algConfiguration, TaskExecutionStatus taskStatus){
|
||||
|
||||
mapCallBack.put(algConfiguration.hashCode(), taskStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the task.
|
||||
*
|
||||
* @param operatorId the operator id
|
||||
* @return the task
|
||||
*/
|
||||
private TaskExecutionStatus getTask(String operatorId){
|
||||
return mapCallBack.get(operatorId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do run task.
|
||||
*
|
||||
* @param algConfiguration the alg configuration
|
||||
* @throws TaskNotExecutableException the task not executable exception
|
||||
*/
|
||||
public void doRunTask(AlgorithmConfiguration algConfiguration) throws TaskNotExecutableException{
|
||||
|
||||
Operator operator;
|
||||
SClient sClient;
|
||||
try {
|
||||
sClient = dataMinerService.getClient();
|
||||
operator = sClient.getOperatorById(algConfiguration.getTaskId());
|
||||
}
|
||||
catch (Exception e) {
|
||||
String error = "Error on get Client or the Operator for id: "+algConfiguration.getTaskId();
|
||||
logger.error(error, e);
|
||||
throw new TaskNotExecutableException(error);
|
||||
}
|
||||
|
||||
if (operator == null) {
|
||||
logger.error("Operator not found");
|
||||
throw new TaskNotExecutableException("Data Miner operator not found");
|
||||
}
|
||||
|
||||
try {
|
||||
addParametersToOperator(operator, algConfiguration.getMapParameters());
|
||||
logger.debug("Start Computation");
|
||||
ComputationId computationId = sClient.startComputation(operator);
|
||||
logger.debug("Started ComputationId: " + computationId);
|
||||
startComputationOnDataMiner(algConfiguration, computationId, sClient);
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitoring computation.
|
||||
*
|
||||
* @param operatorId the operator id
|
||||
* @return the task execution status
|
||||
*/
|
||||
public TaskExecutionStatus getTaskStatus(String operatorId) {
|
||||
|
||||
TaskExecutionStatus task = getTask(operatorId);
|
||||
|
||||
if(task==null){
|
||||
//startComputationOnDM(computationId, sClient);
|
||||
}
|
||||
|
||||
return task;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start computation on dm.
|
||||
*
|
||||
* @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){
|
||||
|
||||
TaskExecutionStatus status = new TaskExecutionStatus();
|
||||
|
||||
DMMonitorListener listener = new DMMonitorListener() {
|
||||
|
||||
@Override
|
||||
public void running(double percentage) {
|
||||
logger.debug("Operation Running: " + percentage);
|
||||
status.setStatus(Status.ONGOING);
|
||||
status.setPercentCompleted((float) percentage);
|
||||
status.setCurrentMessage("Operation Running...");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(String message, Exception exception) {
|
||||
logger.error("Operation Failed");
|
||||
logger.error(message, exception);
|
||||
status.setStatus(Status.FAILED);
|
||||
status.setCurrentMessage(message);
|
||||
status.addLog(exception.getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(double percentage) {
|
||||
logger.debug("Operation Completed");
|
||||
logger.debug("Perc: " + percentage);
|
||||
String log = retrieveOutput(computationId, sClient);
|
||||
status.setStatus(Status.COMPLETED);
|
||||
status.setCurrentMessage("Operation Completed");
|
||||
status.addLog(log);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelled() {
|
||||
logger.debug("Operation Cancelled");
|
||||
status.setStatus(Status.COMPLETED);
|
||||
status.setCurrentMessage("Operation Cancelled");
|
||||
status.addLog("Operation Cancelled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accepted() {
|
||||
logger.debug("Operation Accepted");
|
||||
status.setStatus(Status.ACCEPTED);
|
||||
status.setCurrentMessage("Operation Accepted");
|
||||
status.addLog("Operation Accepted");
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
DMMonitor dmMonitor = new DMMonitor(computationId, sClient);
|
||||
dmMonitor.add(listener);
|
||||
dmMonitor.start();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve output.
|
||||
*
|
||||
* @param computationId the computation id
|
||||
* @param sClient the s client
|
||||
* @return the string
|
||||
*/
|
||||
private String retrieveOutput(ComputationId computationId, SClient sClient) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try {
|
||||
|
||||
OutputData output = sClient.getOutputDataByComputationId(computationId);
|
||||
logger.debug("Output: " + output);
|
||||
builder.append("Output: " + output);
|
||||
Resource resource = output.getResource();
|
||||
if (resource.isMap()) {
|
||||
MapResource mapResource = (MapResource) resource;
|
||||
for (String key : mapResource.getMap().keySet()) {
|
||||
logger.debug("Entry: " + key + " = "+ mapResource.getMap().get(key));
|
||||
builder.append("Entry: " + key + " = "+ mapResource.getMap().get(key));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the parameters to operator.
|
||||
*
|
||||
* @param operator the operator
|
||||
* @param parameters the parameters
|
||||
* @return the operator
|
||||
*/
|
||||
private Operator addParametersToOperator(Operator operator, Map<String, String> 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));
|
||||
|
||||
FileParameter fp=new FileParameter();
|
||||
fp.setName(key);
|
||||
fp.setValue(parameters.get(key));
|
||||
|
||||
listParameters.add(fp);
|
||||
}
|
||||
logger.debug("Parameters list is: " + listParameters);
|
||||
operator.setOperatorParameters(listParameters);
|
||||
return operator;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
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.JsonUtil;
|
||||
import org.gcube.common.workspacetaskexecutor.TaskConfiguration;
|
||||
import org.gcube.common.workspacetaskexecutor.WsUtil;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.TaskExecutionStatus;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.dataminer.AlgorithmConfiguration;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException;
|
||||
import org.gcube.common.workspacetaskexecutor.util.JsonUtil;
|
||||
import org.gcube.common.workspacetaskexecutor.util.WsUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -19,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 26, 2018
|
||||
*/
|
||||
public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmConfiguration>, ConfigurableTask<AlgorithmConfiguration>, CheckableTask<AlgorithmConfiguration>{
|
||||
public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskExecutionStatus>, ConfigurableTask<AlgorithmConfiguration>, CheckableTask<AlgorithmConfiguration>{
|
||||
|
||||
/** The logger. */
|
||||
private static Logger logger = LoggerFactory.getLogger(WorkspaceDataMinerTaskExecutor.class);
|
||||
|
@ -30,6 +31,8 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
|
||||
private String usernameOwner;
|
||||
|
||||
private DataMinerAccessPoint dataMinerAP;
|
||||
|
||||
private JsonUtil<AlgorithmConfiguration> jsonUtil = new JsonUtil<AlgorithmConfiguration>();
|
||||
|
||||
|
||||
|
@ -89,7 +92,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
logger.info("Read "+WS_TASK_TASK_CONF+" value: "+propConfigValue);
|
||||
|
||||
if(propConfigValue==null || propConfigValue.isEmpty())
|
||||
throw new ItemNotExecutableException("The item id "+workspaceItemId+" has not a "+TaskConfiguration.class.getSimpleName());
|
||||
throw new ItemNotExecutableException("The item id "+workspaceItemId+" has not a "+AlgorithmConfiguration.class.getSimpleName());
|
||||
|
||||
try{
|
||||
conf = jsonUtil.readObject(propConfigValue, AlgorithmConfiguration.class);
|
||||
|
@ -103,13 +106,42 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
return conf;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.workspacetaskexecutor.CheckableTask#isItemExecutable(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Boolean isItemExecutable(String workspaceItemId) throws ItemNotExecutableException, Exception {
|
||||
|
||||
checkOwner();
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
|
||||
String propConfigValue = WsUtil.getPropertyValue(item, WS_TASK_TASK_CONF);
|
||||
|
||||
if(propConfigValue==null || propConfigValue.isEmpty()){
|
||||
logger.debug("The item: "+workspaceItemId+" has not a configuration "+WS_TASK_TASK_CONF);
|
||||
return false;
|
||||
}
|
||||
|
||||
try{
|
||||
jsonUtil.readObject(propConfigValue, AlgorithmConfiguration.class);
|
||||
logger.debug("The item: "+workspaceItemId+" has a valid "+WS_TASK_TASK_CONF+" configuration");
|
||||
return true;
|
||||
}catch(Exception e){
|
||||
logger.error("Error on serializing configuration: "+propConfigValue, e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.workspacetaskexecutor.ConfigurableTask#removeTaskConfig(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Boolean removeTaskConfig(String workspaceItemId) throws ItemNotExecutableException, Exception {
|
||||
public Boolean removeTaskConfiguration(String workspaceItemId) throws ItemNotExecutableException, Exception {
|
||||
|
||||
Validate.notNull(workspaceItemId, "The worksapce item id is null");
|
||||
|
||||
checkOwner();
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
|
||||
String propConfig = WsUtil.getPropertyValue(item, WS_TASK_TASK_CONF);
|
||||
|
||||
|
@ -126,8 +158,10 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
* @see org.gcube.common.workspacetaskexecutor.ConfigurableTask#addTaskConfig(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Boolean setTaskConfig(AlgorithmConfiguration config) throws Exception {
|
||||
public Boolean setTaskConfiguration(AlgorithmConfiguration config) throws Exception {
|
||||
|
||||
Validate.notNull(config, "The "+AlgorithmConfiguration.class.getSimpleName()+" instance is null");
|
||||
checkOwner();
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, config.getWorkspaceItemId());
|
||||
String jsonConfValue = null;
|
||||
|
||||
|
@ -150,12 +184,22 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#doRun(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmConfiguration doRun(String itemId) throws ItemNotExecutableException, Exception {
|
||||
public TaskExecutionStatus doRun(String workspaceItemId) throws ItemNotExecutableException, Exception {
|
||||
|
||||
Validate.notNull(workspaceItemId, "The worksapce item id is null");
|
||||
checkOwner();
|
||||
|
||||
AlgorithmConfiguration conf = checkItemExecutable(workspaceItemId);
|
||||
|
||||
if(dataMinerAP==null)
|
||||
dataMinerAP = new DataMinerAccessPoint();
|
||||
|
||||
dataMinerAP.doRunTask(conf);
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#stopRun(java.lang.String)
|
||||
*/
|
||||
|
@ -167,26 +211,18 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#monitorRunStatus(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmConfiguration monitorRunStatus(String itemId)
|
||||
public TaskExecutionStatus monitorRunStatus(String itemId)
|
||||
throws ItemNotExecutableException, Exception {
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#registerCallbackForId(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void registerCallbackForId(String itemId)
|
||||
throws Exception {
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package org.gcube.common.workspacetaskexecutor.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* The Enum Status.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 27, 2018
|
||||
*/
|
||||
public enum Status implements Serializable{
|
||||
INITIALIZING("INITIALIZING"),
|
||||
ONGOING("ONGOING"),
|
||||
ACCEPTED("ACCEPTED"),
|
||||
CANCELLED("CANCELLED"),
|
||||
FAILED("FAILED"),
|
||||
COMPLETED("COMPLETED");
|
||||
|
||||
/**
|
||||
* Instantiates a new status.
|
||||
*/
|
||||
Status(){}
|
||||
|
||||
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* Instantiates a new status.
|
||||
*
|
||||
* @param label the label
|
||||
*/
|
||||
Status(String label){
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the label.
|
||||
*
|
||||
* @return the label
|
||||
*/
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
package org.gcube.common.workspacetaskexecutor.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class TaskExecutionStatus.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 27, 2018
|
||||
*/
|
||||
public class TaskExecutionStatus implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6733806455721902864L;
|
||||
|
||||
private Long errorCount;
|
||||
private Status status;
|
||||
private float percentCompleted = 0;
|
||||
private String log;
|
||||
private String currentMessage="Waiting to start..";
|
||||
|
||||
/**
|
||||
* Instantiates a new task exection status.
|
||||
*/
|
||||
public TaskExecutionStatus() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new task execution status.
|
||||
*
|
||||
* @param errorCount the error count
|
||||
* @param status the status
|
||||
* @param log the log
|
||||
* @param currentMessage the current message
|
||||
* @param percentCompleted the percent completed
|
||||
*/
|
||||
public TaskExecutionStatus(Long errorCount, Status status,
|
||||
String log, String currentMessage, float percentCompleted) {
|
||||
super();
|
||||
this.errorCount = errorCount;
|
||||
this.status = status;
|
||||
this.log = log;
|
||||
this.currentMessage = currentMessage;
|
||||
this.percentCompleted = percentCompleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the error count.
|
||||
*
|
||||
* @return the error count
|
||||
*/
|
||||
public Long getErrorCount() {
|
||||
return errorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the error count.
|
||||
*
|
||||
* @param errorCount the new error count
|
||||
*/
|
||||
public void setErrorCount(Long errorCount) {
|
||||
this.errorCount = errorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status.
|
||||
*
|
||||
* @return the status
|
||||
*/
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status.
|
||||
*
|
||||
* @param status the new status
|
||||
*/
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the log builder.
|
||||
*
|
||||
* @return the log builder
|
||||
*/
|
||||
public String getLog() {
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the log.
|
||||
*
|
||||
* @param logMessage the log message
|
||||
*/
|
||||
public void addLog(String logMessage) {
|
||||
if(log==null)
|
||||
this.log = logMessage;
|
||||
else
|
||||
log+=logMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current message.
|
||||
*
|
||||
* @return the current message
|
||||
*/
|
||||
public String getCurrentMessage() {
|
||||
return currentMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current message.
|
||||
*
|
||||
* @param currentMessage the new current message
|
||||
*/
|
||||
public void setCurrentMessage(String currentMessage) {
|
||||
this.currentMessage = currentMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the percent completed.
|
||||
*
|
||||
* @return the percent completed
|
||||
*/
|
||||
public float getPercentCompleted() {
|
||||
return percentCompleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the percent completed.
|
||||
*
|
||||
* @param percentCompleted the new percent completed
|
||||
*/
|
||||
public void setPercentCompleted(float percentCompleted) {
|
||||
this.percentCompleted = percentCompleted;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("RunningTaskStatus [errorCount=");
|
||||
builder.append(errorCount);
|
||||
builder.append(", status=");
|
||||
builder.append(status);
|
||||
builder.append(", percentCompleted=");
|
||||
builder.append(percentCompleted);
|
||||
builder.append(", log=");
|
||||
builder.append(log);
|
||||
builder.append(", currentMessage=");
|
||||
builder.append(currentMessage);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package org.gcube.common.workspacetaskexecutor.shared;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class WorkspaceFolderLocked.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Mar 13, 2018
|
||||
*/
|
||||
public class WorkspaceFolderLocked extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -778037901117579435L;
|
||||
private String folderId;
|
||||
|
||||
/**
|
||||
* Instantiates a new item not synched.
|
||||
*/
|
||||
public WorkspaceFolderLocked() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new item not synched.
|
||||
*
|
||||
* @param arg0 the arg 0
|
||||
*/
|
||||
public WorkspaceFolderLocked(String folderId, String arg0) {
|
||||
super(arg0);
|
||||
this.folderId = folderId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the folderId
|
||||
*/
|
||||
public String getFolderId() {
|
||||
|
||||
return folderId;
|
||||
}
|
||||
|
||||
}
|
|
@ -147,7 +147,6 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable {
|
|||
this.token = token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the workspace item id.
|
||||
*
|
||||
|
@ -169,6 +168,15 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable {
|
|||
this.mapParameters = mapParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int hash = 1;
|
||||
hash = hash * 13 + (taskId == null ? 0 : taskId.hashCode());
|
||||
hash = hash * 17 + (workspaceItemId == null ? 0 : workspaceItemId.hashCode());
|
||||
return hash;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package org.gcube.common.workspacetaskexecutor.shared;
|
||||
package org.gcube.common.workspacetaskexecutor.shared.exception;
|
||||
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class ItemNotSynched.
|
||||
* The Class ItemNotExecutableException.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Feb 8, 2018
|
||||
* Apr 27, 2018
|
||||
*/
|
||||
public class ItemNotExecutableException extends Exception {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = 3965350221961538838L;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new item not synched.
|
||||
*/
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.common.workspacetaskexecutor.shared.exception;
|
||||
|
||||
|
||||
/**
|
||||
* The Class TaskErrorException.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 27, 2018
|
||||
*/
|
||||
public class TaskErrorException extends Exception {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5809192288746340819L;
|
||||
|
||||
/**
|
||||
* Instantiates a new item not synched.
|
||||
*/
|
||||
public TaskErrorException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new item not synched.
|
||||
*
|
||||
* @param arg0 the arg 0
|
||||
*/
|
||||
public TaskErrorException(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.common.workspacetaskexecutor.shared.exception;
|
||||
|
||||
|
||||
/**
|
||||
* The Class TaskNotExecutableException.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 27, 2018
|
||||
*/
|
||||
public class TaskNotExecutableException extends Exception {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1266304637564891443L;
|
||||
|
||||
/**
|
||||
* Instantiates a new item not synched.
|
||||
*/
|
||||
public TaskNotExecutableException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new item not synched.
|
||||
*
|
||||
* @param arg0 the arg 0
|
||||
*/
|
||||
public TaskNotExecutableException(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.common.workspacetaskexecutor;
|
||||
package org.gcube.common.workspacetaskexecutor.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.common.workspacetaskexecutor;
|
||||
package org.gcube.common.workspacetaskexecutor.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
|
@ -8,8 +8,8 @@ import java.util.Map;
|
|||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.workspacetaskexecutor.dataminer.WorkspaceDataMinerTaskExecutor;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.dataminer.AlgorithmConfiguration;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutableException;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -32,8 +32,8 @@ public class TestDataMinerTaskExecutor {
|
|||
exec.withOwner(USERNAME);
|
||||
|
||||
try {
|
||||
exec.removeTaskConfig(WORKSPACE_FOLDER_ID);
|
||||
exec.checkItemExecutable(WORKSPACE_FOLDER_ID);
|
||||
exec.removeTaskConfiguration(WORKSPACE_FOLDER_ID);
|
||||
//exec.checkItemExecutable(WORKSPACE_FOLDER_ID);
|
||||
}
|
||||
catch (ItemNotExecutableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
@ -48,29 +48,29 @@ public class TestDataMinerTaskExecutor {
|
|||
|
||||
|
||||
|
||||
try {
|
||||
AlgorithmConfiguration config = createDummyConfiguration();
|
||||
exec.setTaskConfig(config);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
AlgorithmConfiguration conf = exec.checkItemExecutable(WORKSPACE_FOLDER_ID);
|
||||
|
||||
System.out.println("The conf is: "+conf);
|
||||
}
|
||||
catch (ItemNotExecutableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
// try {
|
||||
// AlgorithmConfiguration config = createDummyConfiguration();
|
||||
// exec.setTaskConfiguration(config);
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// try {
|
||||
// AlgorithmConfiguration conf = exec.checkItemExecutable(WORKSPACE_FOLDER_ID);
|
||||
//
|
||||
// System.out.println("The conf is: "+conf);
|
||||
// }
|
||||
// catch (ItemNotExecutableException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue