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@167243 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-04-26 16:01:56 +00:00
parent d10213b897
commit f17d119cce
9 changed files with 119 additions and 50 deletions

View File

@ -3,7 +3,7 @@
*/
package org.gcube.common.workspacetaskexecutor;
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutable;
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
/**
@ -21,9 +21,9 @@ public interface CheckableTask<T> {
*
* @param itemId the item id
* @return the t
* @throws ItemNotExecutable the item not executable
* @throws ItemNotExecutableException the item not executable
* @throws Exception the exception
*/
T checkItemExecutable(String itemId) throws ItemNotExecutable, Exception;
T checkItemExecutable(String itemId) throws ItemNotExecutableException, Exception;
}

View File

@ -3,7 +3,7 @@
*/
package org.gcube.common.workspacetaskexecutor;
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutable;
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
/**
@ -21,10 +21,10 @@ public interface ConfigurableTask<I> {
*
* @param workspaceItemId the workspace item id
* @return the boolean
* @throws ItemNotExecutable the item not executable
* @throws ItemNotExecutableException the item not executable
* @throws Exception the exception
*/
Boolean removeTaskConfig(String workspaceItemId) throws ItemNotExecutable, Exception;
Boolean removeTaskConfig(String workspaceItemId) throws ItemNotExecutableException, Exception;
/**
@ -32,8 +32,8 @@ public interface ConfigurableTask<I> {
*
* @param config the config
* @return the boolean
* @throws ItemNotExecutable the item not executable
* @throws ItemNotExecutableException the item not executable
* @throws Exception the exception
*/
Boolean addTaskConfig(I config) throws ItemNotExecutable, Exception;
Boolean setTaskConfig(I config) throws ItemNotExecutableException, Exception;
}

View File

@ -1,6 +1,6 @@
package org.gcube.common.workspacetaskexecutor;
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutable;
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
/**
@ -18,20 +18,20 @@ public interface ExecutableTask<O> {
*
* @param itemId the item id
* @return the o
* @throws ItemNotExecutable the item not executable
* @throws ItemNotExecutableException the item not executable
* @throws Exception the exception
*/
O doRun(String itemId) throws ItemNotExecutable, Exception;
O doRun(String itemId) throws ItemNotExecutableException, Exception;
/**
* Stop run.
*
* @param itemId the item id
* @return the boolean
* @throws ItemNotExecutable the item not executable
* @throws ItemNotExecutableException the item not executable
* @throws Exception the exception
*/
Boolean stopRun(String itemId) throws ItemNotExecutable, Exception;
Boolean stopRun(String itemId) throws ItemNotExecutableException, Exception;
/**
@ -39,10 +39,10 @@ public interface ExecutableTask<O> {
*
* @param itemId the item id
* @return the o
* @throws ItemNotExecutable the item not executable
* @throws ItemNotExecutableException the item not executable
* @throws Exception the exception
*/
O monitorRunStatus(String itemId) throws ItemNotExecutable, Exception;
O monitorRunStatus(String itemId) throws ItemNotExecutableException, Exception;
/**

View File

@ -5,8 +5,6 @@ package org.gcube.common.workspacetaskexecutor;
import java.util.Map;
import org.apache.http.HttpRequest;
/**
* The Interface DoTaskConfiguration.
*
@ -48,14 +46,5 @@ public interface TaskConfiguration {
/**
* Gets the http request.
*
* @return the http request
*/
HttpRequest getHttpRequest();
}

View File

@ -126,6 +126,7 @@ public class WsUtil {
Properties propertiesOBJ = item.getProperties();
properties.put(propertyName, propertyValue);
propertiesOBJ.addProperties(properties);
logger.debug("Added properties "+properties+" to item: "+item);
return true;
}
catch (InternalErrorException e) {

View File

@ -7,7 +7,7 @@ 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;
import org.gcube.common.workspacetaskexecutor.shared.ItemNotExecutableException;
import org.gcube.common.workspacetaskexecutor.shared.dataminer.AlgorithmConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -79,20 +79,23 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
* @see org.gcube.common.workspacetaskexecutor.CheckableTask#checkItemExecutable(java.lang.String)
*/
@Override
public AlgorithmConfiguration checkItemExecutable(String workspaceItemId) throws ItemNotExecutable, Exception {
public AlgorithmConfiguration checkItemExecutable(String workspaceItemId) throws ItemNotExecutableException, Exception {
AlgorithmConfiguration conf = null;
checkOwner();
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
String propConfigValue = WsUtil.getPropertyValue(item, WS_TASK_TASK_CONF);
logger.info("Read "+WS_TASK_TASK_CONF+" value: "+propConfigValue);
if(propConfigValue==null || propConfigValue.isEmpty())
throw new ItemNotExecutable("The item id "+workspaceItemId+" has not a "+TaskConfiguration.class.getSimpleName());
throw new ItemNotExecutableException("The item id "+workspaceItemId+" has not a "+TaskConfiguration.class.getSimpleName());
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?");
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?");
}
logger.info("Found configuration: "+conf);
@ -105,13 +108,13 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
* @see org.gcube.common.workspacetaskexecutor.ConfigurableTask#removeTaskConfig(java.lang.Object)
*/
@Override
public Boolean removeTaskConfig(String workspaceItemId) throws ItemNotExecutable, Exception {
public Boolean removeTaskConfig(String workspaceItemId) throws ItemNotExecutableException, Exception {
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());
throw new ItemNotExecutableException("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);
@ -123,13 +126,14 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
* @see org.gcube.common.workspacetaskexecutor.ConfigurableTask#addTaskConfig(java.lang.Object)
*/
@Override
public Boolean addTaskConfig(AlgorithmConfiguration config) throws ItemNotExecutable, Exception {
public Boolean setTaskConfig(AlgorithmConfiguration config) throws ItemNotExecutableException, Exception {
WorkspaceItem item = WsUtil.getItem(usernameOwner, config.getWorkspaceItemId());
String jsonConfValue = null;
try{
jsonConfValue = jsonUtil.toJSON(config);
logger.debug("The json configuration is: "+jsonConfValue);
}catch(Exception e){
throw new Exception("This "+config+" is wrong!. Please create a new one");
}
@ -146,7 +150,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
* @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 ItemNotExecutableException, Exception {
// TODO Auto-generated method stub
return null;
@ -157,7 +161,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
*/
@Override
public Boolean stopRun(String itemId)
throws ItemNotExecutable, Exception {
throws ItemNotExecutableException, Exception {
// TODO Auto-generated method stub
return null;
@ -168,7 +172,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<AlgorithmC
*/
@Override
public AlgorithmConfiguration monitorRunStatus(String itemId)
throws ItemNotExecutable, Exception {
throws ItemNotExecutableException, Exception {
// TODO Auto-generated method stub
return null;

View File

@ -8,7 +8,7 @@ package org.gcube.common.workspacetaskexecutor.shared;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 8, 2018
*/
public class ItemNotExecutable extends Exception {
public class ItemNotExecutableException extends Exception {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 3965350221961538838L;
@ -16,7 +16,7 @@ public class ItemNotExecutable extends Exception {
/**
* Instantiates a new item not synched.
*/
public ItemNotExecutable() {
public ItemNotExecutableException() {
super();
}
@ -25,7 +25,7 @@ public class ItemNotExecutable extends Exception {
*
* @param arg0 the arg 0
*/
public ItemNotExecutable(String arg0) {
public ItemNotExecutableException(String arg0) {
super(arg0);
}

View File

@ -7,7 +7,6 @@ package org.gcube.common.workspacetaskexecutor.shared.dataminer;
import java.io.Serializable;
import java.util.Map;
import org.apache.http.HttpRequest;
import org.gcube.common.workspacetaskexecutor.TaskConfiguration;
@ -146,16 +145,6 @@ public class AlgorithmConfiguration implements TaskConfiguration, Serializable {
this.mapParameters = mapParameters;
}
/* (non-Javadoc)
* @see org.gcube.common.workspacetaskexecutor.TaskConfiguration#getHttpRequest()
*/
@Override
public HttpRequest getHttpRequest() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/

View File

@ -0,0 +1,86 @@
/**
*
*/
package org.gcube.common.workspacetaskexecutor;
import java.util.HashMap;
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;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Apr 26, 2018
*/
public class TestDataMinerTaskExecutor {
public static String USERNAME = "francesco.mangiacrapa";
public static String SCOPE = "/gcube/devsec";
public static String WORKSPACE_FOLDER_ID = "f5c2f5ab-5c35-4418-8e60-d48d173538ed";
public static void main(String[] args) {
ScopeProvider.instance.set(SCOPE);
WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
exec.withOwner(USERNAME);
try {
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 {
AlgorithmConfiguration config = createDummyConfiguration();
exec.setTaskConfig(config);
}
catch (ItemNotExecutableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
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();
}
}
public static AlgorithmConfiguration 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", "this is the task description", "my token", WORKSPACE_FOLDER_ID, mapParameters);
}
}