Enhancement on Project Activity #11690
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@167295 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
caa1debb49
commit
4978626ce7
|
@ -2,7 +2,7 @@ package org.gcube.common.workspacetaskexecutor.dataminer;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||||
import org.gcube.common.workspacetaskexecutor.shared.CheckableTask;
|
import org.gcube.common.workspacetaskexecutor.shared.IsItemExecutable;
|
||||||
import org.gcube.common.workspacetaskexecutor.shared.ConfigurableTask;
|
import org.gcube.common.workspacetaskexecutor.shared.ConfigurableTask;
|
||||||
import org.gcube.common.workspacetaskexecutor.shared.ExecutableTask;
|
import org.gcube.common.workspacetaskexecutor.shared.ExecutableTask;
|
||||||
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
|
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
|
||||||
|
@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* May 2, 2018
|
* May 2, 2018
|
||||||
*/
|
*/
|
||||||
public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfiguration, TaskExecutionStatus>, ConfigurableTask<TaskConfiguration>, CheckableTask<TaskConfiguration>{
|
public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfiguration, TaskExecutionStatus>, ConfigurableTask<TaskConfiguration>, IsItemExecutable<TaskConfiguration>{
|
||||||
|
|
||||||
/** The logger. */
|
/** The logger. */
|
||||||
private static Logger logger = LoggerFactory.getLogger(WorkspaceDataMinerTaskExecutor.class);
|
private static Logger logger = LoggerFactory.getLogger(WorkspaceDataMinerTaskExecutor.class);
|
||||||
|
@ -211,7 +211,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
||||||
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#doRun(org.gcube.common.workspacetaskexecutor.BaseTaskConfiguration)
|
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#doRun(org.gcube.common.workspacetaskexecutor.BaseTaskConfiguration)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TaskExecutionStatus doRun(TaskConfiguration taskConfiguration)
|
public TaskExecutionStatus executeRun(TaskConfiguration taskConfiguration)
|
||||||
throws ItemNotExecutableException, TaskNotExecutableException, Exception {
|
throws ItemNotExecutableException, TaskNotExecutableException, Exception {
|
||||||
|
|
||||||
ValidateTaskConfiguration(taskConfiguration);
|
ValidateTaskConfiguration(taskConfiguration);
|
||||||
|
@ -227,7 +227,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
||||||
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#stopRun(org.gcube.common.workspacetaskexecutor.BaseTaskConfiguration)
|
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#stopRun(org.gcube.common.workspacetaskexecutor.BaseTaskConfiguration)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean stopRun(TaskConfiguration taskConfiguration)
|
public Boolean abortRun(TaskConfiguration taskConfiguration)
|
||||||
throws TaskErrorException, Exception {
|
throws TaskErrorException, Exception {
|
||||||
|
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
|
@ -51,7 +51,7 @@ public interface BaseTaskConfiguration {
|
||||||
*
|
*
|
||||||
* @return the access key
|
* @return the access key
|
||||||
*/
|
*/
|
||||||
String getAccessKey();
|
String getConfigurationKey();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +59,7 @@ public interface BaseTaskConfiguration {
|
||||||
*
|
*
|
||||||
* @param accessKey the access key
|
* @param accessKey the access key
|
||||||
*/
|
*/
|
||||||
void setAccessKey(String accessKey);
|
void setConfigurationKey(String accessKey);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,25 +16,25 @@ public interface ExecutableTask<I extends BaseTaskConfiguration, O extends BaseT
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do run.
|
* Execute run.
|
||||||
*
|
*
|
||||||
* @param taskConfiguration the base task configuration
|
* @param taskConfiguration the task configuration
|
||||||
* @return the o
|
* @return the o
|
||||||
* @throws ItemNotExecutableException the item not executable exception
|
* @throws ItemNotExecutableException the item not executable exception
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
O doRun(I taskConfiguration) throws ItemNotExecutableException, Exception;
|
O executeRun(I taskConfiguration) throws ItemNotExecutableException, Exception;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop run.
|
* Abort run.
|
||||||
*
|
*
|
||||||
* @param taskConfiguration the task configuration
|
* @param taskConfiguration the task configuration
|
||||||
* @return the boolean
|
* @return the boolean
|
||||||
* @throws TaskErrorException the task error exception
|
* @throws TaskErrorException the task error exception
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
Boolean stopRun(I taskConfiguration) throws TaskErrorException, Exception;
|
Boolean abortRun(I taskConfiguration) throws TaskErrorException, Exception;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,13 +7,13 @@ import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotExecutable
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Interface DoCheckTask.
|
* The Interface IsItemExecutable.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* Apr 26, 2018
|
* May 3, 2018
|
||||||
* @param <T> the generic type
|
* @param <T> the generic type must exteds {@link BaseTaskConfiguration}
|
||||||
*/
|
*/
|
||||||
public interface CheckableTask<T extends BaseTaskConfiguration> {
|
public interface IsItemExecutable<T extends BaseTaskConfiguration> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -6,6 +6,7 @@ package org.gcube.common.workspacetaskexecutor.shared.dataminer;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration;
|
import org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration;
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
|
||||||
@JsonIgnoreProperties
|
@JsonIgnoreProperties
|
||||||
private Map<String, String> mapParameters; //optional
|
private Map<String, String> mapParameters; //optional
|
||||||
@JsonIgnoreProperties
|
@JsonIgnoreProperties
|
||||||
private String accessKey;
|
private String configurationKey;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,21 +66,21 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
|
||||||
* @see org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration#getAccessKey()
|
* @see org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration#getAccessKey()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getAccessKey() {
|
public String getConfigurationKey() {
|
||||||
|
|
||||||
if(accessKey==null)
|
if(configurationKey==null)
|
||||||
accessKey = hashCode()+"";
|
configurationKey = hashCode()+"";
|
||||||
|
|
||||||
return accessKey;
|
return configurationKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration#setAccessKey(java.lang.String)
|
* @see org.gcube.common.workspacetaskexecutor.shared.BaseTaskConfiguration#setAccessKey(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setAccessKey(String accessKey) {
|
public void setConfigurationKey(String configurationKey) {
|
||||||
|
|
||||||
this.accessKey = accessKey;
|
this.configurationKey = configurationKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -206,6 +207,7 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
|
||||||
int hash = 1;
|
int hash = 1;
|
||||||
hash = hash * 13 + (taskId == null ? 0 : taskId.hashCode());
|
hash = hash * 13 + (taskId == null ? 0 : taskId.hashCode());
|
||||||
hash = hash * 17 + (workspaceItemId == null ? 0 : workspaceItemId.hashCode());
|
hash = hash * 17 + (workspaceItemId == null ? 0 : workspaceItemId.hashCode());
|
||||||
|
hash = hash * new Random().nextInt();
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,14 +228,12 @@ public class TaskConfiguration implements BaseTaskConfiguration, Serializable {
|
||||||
builder.append(workspaceItemId);
|
builder.append(workspaceItemId);
|
||||||
builder.append(", mapParameters=");
|
builder.append(", mapParameters=");
|
||||||
builder.append(mapParameters);
|
builder.append(mapParameters);
|
||||||
builder.append(", accessKey=");
|
builder.append(", configurationKey=");
|
||||||
builder.append(accessKey);
|
builder.append(configurationKey);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,16 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||||
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||||
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||||
|
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
||||||
|
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.workspacetaskexecutor.dataminer.WorkspaceDataMinerTaskExecutor;
|
import org.gcube.common.workspacetaskexecutor.dataminer.WorkspaceDataMinerTaskExecutor;
|
||||||
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
|
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
|
||||||
import org.gcube.common.workspacetaskexecutor.util.JsonUtil;
|
import org.gcube.common.workspacetaskexecutor.util.JsonUtil;
|
||||||
|
import org.gcube.common.workspacetaskexecutor.util.WsUtil;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
@ -32,13 +38,17 @@ public class TestDataMinerTaskExecutor {
|
||||||
|
|
||||||
public static String WORKSPACE_FOLDER_ID = "f5c2f5ab-5c35-4418-8e60-d48d173538ed";
|
public static String WORKSPACE_FOLDER_ID = "f5c2f5ab-5c35-4418-8e60-d48d173538ed";
|
||||||
|
|
||||||
|
private static JsonUtil jUtil = new JsonUtil();
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
ScopeProvider.instance.set(SCOPE);
|
ScopeProvider.instance.set(SCOPE);
|
||||||
WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
|
WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
|
||||||
exec.withOwner(USERNAME);
|
exec.withOwner(USERNAME);
|
||||||
jsonCheck();
|
//jsonCheck();
|
||||||
|
|
||||||
|
checkGubeProperties(gelDummyListOfConfigurations());
|
||||||
|
|
||||||
|
|
||||||
// try {
|
// try {
|
||||||
|
@ -85,20 +95,62 @@ public class TestDataMinerTaskExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void checkGubeProperties(List<TaskConfiguration> listConfigurations){
|
||||||
|
|
||||||
|
//SET
|
||||||
|
try {
|
||||||
|
WorkspaceItem workspaceItem = WsUtil.getItem(USERNAME, WORKSPACE_FOLDER_ID);
|
||||||
|
|
||||||
|
String jsonArray = jUtil.toJSONArray(listConfigurations);
|
||||||
|
System.out.println("Json array to save: "+jsonArray);
|
||||||
|
WsUtil.setPropertyValue(workspaceItem, WorkspaceDataMinerTaskExecutor.WS_DM_TASK_TASK_CONF, jsonArray);
|
||||||
|
|
||||||
|
//GET
|
||||||
|
jsonArray = WsUtil.getPropertyValue(workspaceItem, WorkspaceDataMinerTaskExecutor.WS_DM_TASK_TASK_CONF);
|
||||||
|
System.out.println("Json array read from "+WorkspaceDataMinerTaskExecutor.WS_DM_TASK_TASK_CONF+": "+jsonArray);
|
||||||
|
|
||||||
|
|
||||||
|
TypeReference<List<TaskConfiguration>> mapType = new TypeReference<List<TaskConfiguration>>() {};
|
||||||
|
List<TaskConfiguration> listUnM = jUtil.readList(jsonArray, mapType);
|
||||||
|
System.out.println("Json array to listUnM...");
|
||||||
|
for (TaskConfiguration taskConfiguration : listUnM) {
|
||||||
|
System.out.println(taskConfiguration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (WorkspaceFolderNotFoundException | ItemNotFoundException
|
||||||
|
| InternalErrorException | HomeNotFoundException | JsonProcessingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static TaskConfiguration createDummyConfiguration(){
|
public static TaskConfiguration createDummyConfiguration(){
|
||||||
Map<String, String> mapParameters = new HashMap<String, String>();
|
Map<String, String> mapParameters = new HashMap<String, String>();
|
||||||
mapParameters.put("publiclink", "this is the public link");
|
mapParameters.put("publiclink", "this is the public link");
|
||||||
return new TaskConfiguration(UUID.randomUUID().toString(), null, "my token", WORKSPACE_FOLDER_ID, mapParameters);
|
return new TaskConfiguration(UUID.randomUUID().toString(), null, "my token", WORKSPACE_FOLDER_ID, mapParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void jsonCheck(){
|
|
||||||
|
public static List<TaskConfiguration> gelDummyListOfConfigurations(){
|
||||||
TaskConfiguration c1 = createDummyConfiguration();
|
TaskConfiguration c1 = createDummyConfiguration();
|
||||||
TaskConfiguration c2 = createDummyConfiguration();
|
TaskConfiguration c2 = createDummyConfiguration();
|
||||||
List<TaskConfiguration> listConfigurations = new ArrayList<>();
|
List<TaskConfiguration> listConfigurations = new ArrayList<>();
|
||||||
listConfigurations.add(c1);
|
listConfigurations.add(c1);
|
||||||
listConfigurations.add(c2);
|
listConfigurations.add(c2);
|
||||||
JsonUtil jUtil = new JsonUtil();
|
return listConfigurations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void jsonCheck(){
|
||||||
|
|
||||||
|
|
||||||
|
List<TaskConfiguration> listConfigurations = gelDummyListOfConfigurations();
|
||||||
try {
|
try {
|
||||||
String jsonArray = jUtil.toJSONArray(listConfigurations);
|
String jsonArray = jUtil.toJSONArray(listConfigurations);
|
||||||
System.out.println("Json array: "+jsonArray);
|
System.out.println("Json array: "+jsonArray);
|
||||||
|
|
Loading…
Reference in New Issue