enhancement on Project Activity #11690: Execute Data Miner processes from Workspace
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@167242 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9a9dab6c1e
commit
d10213b897
6
pom.xml
6
pom.xml
|
@ -46,6 +46,12 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.common.workspacetaskexecutor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class JsonUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 26, 2018
|
||||
* @param <T> the generic type
|
||||
*/
|
||||
public class JsonUtil<T> {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
|
||||
/**
|
||||
* To json.
|
||||
*
|
||||
* @param obj the obj
|
||||
* @return the string
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
public String toJSON(T obj) throws JsonProcessingException{
|
||||
|
||||
// Convert object to JSON string
|
||||
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read object.
|
||||
*
|
||||
* @param json the json
|
||||
* @param obj the obj
|
||||
* @return the t
|
||||
* @throws JsonParseException the json parse exception
|
||||
* @throws JsonMappingException the json mapping exception
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public T readObject(String json, Class<T> obj) throws JsonParseException, JsonMappingException, IOException{
|
||||
// Convert JSON string from file to Object
|
||||
return mapper.readValue(json, obj);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ 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.ItemNotExecutable;
|
||||
|
@ -29,6 +30,8 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
|
||||
private String usernameOwner;
|
||||
|
||||
private JsonUtil<AlgorithmConfiguration> jsonUtil = new JsonUtil<AlgorithmConfiguration>();
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new workspace data miner task executor.
|
||||
|
@ -76,18 +79,25 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
* @see org.gcube.common.workspacetaskexecutor.CheckableTask#checkItemExecutable(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmConfiguration checkItemExecutable(String itemId) throws ItemNotExecutable, Exception {
|
||||
public AlgorithmConfiguration checkItemExecutable(String workspaceItemId) throws ItemNotExecutable, Exception {
|
||||
|
||||
AlgorithmConfiguration conf = null;
|
||||
checkOwner();
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, itemId);
|
||||
String propConfig = WsUtil.getPropertyValue(item, WS_TASK_TASK_CONF);
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
|
||||
String propConfigValue = WsUtil.getPropertyValue(item, WS_TASK_TASK_CONF);
|
||||
|
||||
if(propConfig==null)
|
||||
throw new ItemNotExecutable("The item id "+itemId+" has not a "+TaskConfiguration.class.getSimpleName());
|
||||
if(propConfigValue==null || propConfigValue.isEmpty())
|
||||
throw new ItemNotExecutable("The item id "+workspaceItemId+" has not a "+TaskConfiguration.class.getSimpleName());
|
||||
|
||||
//ObjectMapper mapper = new ObjectMapper();
|
||||
try{
|
||||
conf = jsonUtil.readObject(propConfigValue, AlgorithmConfiguration.class);
|
||||
}catch(Exception e){
|
||||
throw new ItemNotExecutable("The item id "+workspaceItemId+" has a wrong "+AlgorithmConfiguration.class.getSimpleName()+". Do you want create a new one?");
|
||||
}
|
||||
|
||||
return null;
|
||||
logger.info("Found configuration: "+conf);
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,8 +107,16 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
@Override
|
||||
public Boolean removeTaskConfig(String workspaceItemId) throws ItemNotExecutable, Exception {
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
|
||||
String propConfig = WsUtil.getPropertyValue(item, WS_TASK_TASK_CONF);
|
||||
|
||||
if(propConfig==null || propConfig.isEmpty())
|
||||
throw new ItemNotExecutable("The item id "+workspaceItemId+" has not a "+AlgorithmConfiguration.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);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -107,16 +125,28 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
|
|||
@Override
|
||||
public Boolean addTaskConfig(AlgorithmConfiguration config) throws ItemNotExecutable, Exception {
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, config.getWorkspaceItemId());
|
||||
String jsonConfValue = null;
|
||||
|
||||
try{
|
||||
jsonConfValue = jsonUtil.toJSON(config);
|
||||
}catch(Exception e){
|
||||
throw new Exception("This "+config+" is wrong!. Please create a new one");
|
||||
}
|
||||
|
||||
if(jsonConfValue!=null){
|
||||
WsUtil.setPropertyValue(item, WS_TASK_TASK_CONF, jsonConfValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.common.workspacetaskexecutor.ExecutableTask#doRun(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public AlgorithmConfiguration doRun(String itemId)
|
||||
throws ItemNotExecutable, Exception {
|
||||
public AlgorithmConfiguration doRun(String itemId) throws ItemNotExecutable, Exception {
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue