[Task #17349] Migrate ws-task-executor components to SHUB
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@181580 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d784d26f70
commit
c08a18fd7c
|
@ -15,11 +15,13 @@
|
|||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
|
|
|
@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.7
|
|||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.common.workspace-task-executor-library.1-0-0"
|
||||
<Changeset
|
||||
component="org.gcube.common.workspace-task-executor-library.0-2-0"
|
||||
date="${buildDate}">
|
||||
<Change>[Task #17349] Migrate ws-task-executor components to SHUB</Change>
|
||||
</Changeset>
|
||||
<Changeset
|
||||
component="org.gcube.common.workspace-task-executor-library.0-1-0"
|
||||
date="2018-05-04">
|
||||
<Change>First Release</Change>
|
||||
</Changeset>
|
||||
|
|
41
pom.xml
41
pom.xml
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
@ -11,7 +12,7 @@
|
|||
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>workspace-task-executor-library</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<version>0.2.0-SNAPSHOT</version>
|
||||
<name>workspace-task-executor-library</name>
|
||||
<description>The workspace-task-executor-library is a library to execute data miner's algorithms from workspace </description>
|
||||
|
||||
|
@ -77,22 +78,28 @@
|
|||
</dependency>
|
||||
<!-- END FWS -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-wrapper</artifactId>
|
||||
<version>[0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- HOME LIBRARY -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-model</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-jcr</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.gcube.common</groupId> -->
|
||||
<!-- <artifactId>home-library-model</artifactId> -->
|
||||
<!-- <scope>provided</scope> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.gcube.common</groupId> -->
|
||||
<!-- <artifactId>home-library</artifactId> -->
|
||||
<!-- <scope>provided</scope> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.gcube.common</groupId> -->
|
||||
<!-- <artifactId>home-library-jcr</artifactId> -->
|
||||
<!-- <scope>provided</scope> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<!-- JSON PARSER -->
|
||||
<dependency>
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package org.gcube.common.workspacetaskexecutor.dataminer;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.ExecutableItem;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.ExecutableTask;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.FilterOperator;
|
||||
|
@ -33,12 +36,14 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
|
||||
/**
|
||||
* The Class WorkspaceDataMinerTaskExecutor.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 4, 2018
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* This class uses the scope by {@link ScopeProvider} and the User Token by {@link SecurityTokenProvider} to work correctly.
|
||||
*
|
||||
* Sep 9, 2019
|
||||
*/
|
||||
public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfiguration, TaskComputation, TaskExecutionStatus>, ExecutableItem<TaskConfiguration>{
|
||||
|
||||
|
@ -49,12 +54,14 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
|
||||
public static final String WS_DM_TASK_TASK_CONF = "WS-DM-TASK.TASK-CONF";
|
||||
|
||||
private String usernameOwner;
|
||||
//private String usernameOwner;
|
||||
|
||||
private DataMinerAccessPoint dataMinerAP;
|
||||
|
||||
private JsonUtil jsonUtil = new JsonUtil();
|
||||
|
||||
private WsUtil wsUtil = new WsUtil();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the data miner access point.
|
||||
|
@ -75,14 +82,14 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* With owner.
|
||||
*
|
||||
* @param usernameOwner the username owner
|
||||
*/
|
||||
public void withOwner(String usernameOwner){
|
||||
this.usernameOwner = usernameOwner;
|
||||
}
|
||||
// /**
|
||||
// * With owner.
|
||||
// *
|
||||
// * @param usernameOwner the username owner
|
||||
// */
|
||||
// public void withOwner(String usernameOwner){
|
||||
// this.usernameOwner = usernameOwner;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
@ -97,20 +104,6 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check owner.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private void checkOwner() throws Exception {
|
||||
|
||||
if(usernameOwner==null || usernameOwner.isEmpty())
|
||||
throw new Exception("You must set a valid 'usernameOwner'. Using the method #withOwner");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate task configuration.
|
||||
*
|
||||
|
@ -158,9 +151,12 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
public List<TaskConfiguration> getListOfTaskConfigurations(String workspaceItemId) throws Exception {
|
||||
logger.debug("Get list of Task Configurations for "+workspaceItemId+" starts...");
|
||||
List<TaskConfiguration> conf = null;
|
||||
checkOwner();
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, workspaceItemId);
|
||||
String arrayConf = WsUtil.getPropertyValue(item, WS_DM_TASK_TASK_CONF);
|
||||
|
||||
//TO-SHUB
|
||||
Workspace ws = wsUtil.getWorkspace();
|
||||
WorkspaceItem item = ws.getItem(workspaceItemId);
|
||||
String arrayConf = wsUtil.getPropertyValue(item, WS_DM_TASK_TASK_CONF);
|
||||
|
||||
logger.info("Read "+WS_DM_TASK_TASK_CONF+" value: "+arrayConf);
|
||||
if(arrayConf==null || arrayConf.isEmpty()){
|
||||
logger.warn("The item id "+workspaceItemId+" has not "+TaskConfiguration.class.getSimpleName() +" saved");
|
||||
|
@ -237,8 +233,12 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
public WSItemObject loadItem(String itemId){
|
||||
WorkspaceItem item = null;
|
||||
Validate.notNull(itemId, "Input parameter itemId is null");
|
||||
Workspace ws;
|
||||
try{
|
||||
item = WsUtil.getItem(usernameOwner, itemId);
|
||||
//TO-SHUB
|
||||
ws = wsUtil.getWorkspace();
|
||||
item = ws.getItem(itemId);
|
||||
//item = WsUtil.getItem(usernameOwner, itemId);
|
||||
}catch(Exception e){
|
||||
logger.error("Error during get item with id: "+itemId, e);
|
||||
throw new Error("Error during get item with id: "+itemId+". Eihter it does not exit or you have not permissions to read it");
|
||||
|
@ -249,15 +249,19 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
try {
|
||||
wsItem.setItemId(item.getId());
|
||||
wsItem.setItemName(item.getName());
|
||||
wsItem.setOwner(item.getOwner().getPortalLogin());
|
||||
//wsItem.setOwner(item.getOwner().getPortalLogin());
|
||||
wsItem.setOwner(item.getOwner());
|
||||
wsItem.setFolder(item.isFolder());
|
||||
if(!item.isFolder()){
|
||||
wsItem.setPublicLink(item.getPublicLink(false));
|
||||
URL publicLink = ws.getPublicLinkForFile(item.getId());
|
||||
if(publicLink!=null)
|
||||
wsItem.setPublicLink(publicLink.toString());
|
||||
//wsItem.setPublicLink(item.getPublicLink(false));
|
||||
}
|
||||
|
||||
return wsItem;
|
||||
}
|
||||
catch (InternalErrorException e) {
|
||||
catch (Exception e) {
|
||||
//silent
|
||||
logger.warn("Error during filling item properties for item id: "+itemId, e);
|
||||
try {
|
||||
|
@ -265,7 +269,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
wsItem.setItemName(item.getName());
|
||||
return wsItem;
|
||||
}
|
||||
catch (InternalErrorException e1) {
|
||||
catch (Exception e1) {
|
||||
logger.error("Error during filling id and name for item id: "+itemId, e);
|
||||
return null;
|
||||
}
|
||||
|
@ -283,10 +287,13 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
logger.info("Removing task configuration with key: "+taskConfiguration.getConfigurationKey() + " starts...");
|
||||
|
||||
ValidateTaskConfiguration(taskConfiguration);
|
||||
checkOwner();
|
||||
boolean found = false;
|
||||
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, taskConfiguration.getWorkspaceItemId());
|
||||
//TO SHUB
|
||||
Workspace ws = wsUtil.getWorkspace();
|
||||
WorkspaceItem item = ws.getItem(taskConfiguration.getWorkspaceItemId());
|
||||
|
||||
//WorkspaceItem item = WsUtil.getItem(usernameOwner, taskConfiguration.getWorkspaceItemId());
|
||||
List<TaskConfiguration> configurations = getListOfTaskConfigurations(taskConfiguration.getWorkspaceItemId());
|
||||
|
||||
if(configurations==null)
|
||||
|
@ -296,6 +303,7 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
List<TaskConfiguration> newConfigurations = new ArrayList<TaskConfiguration>(configurations.size());
|
||||
|
||||
for (TaskConfiguration tc : configurations) {
|
||||
//ADDING ALL THE CONFIGURATIONS EXCEPT THE INPUT ONE (THAT MUST BE BE REMOVED)
|
||||
if(tc.getConfigurationKey().compareTo(taskConfiguration.getConfigurationKey())!=0){
|
||||
newConfigurations.add(tc);
|
||||
}else{
|
||||
|
@ -306,8 +314,9 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
|
||||
if(found){
|
||||
JSONArray newConfgs = jsonUtil.toJSONArray(newConfigurations);
|
||||
WsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, newConfgs.toString());
|
||||
logger.info("Removed correclty the task configuration "+taskConfiguration+ " from saved configurations");
|
||||
wsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, newConfgs.toString());
|
||||
//WsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, newConfgs.toString());
|
||||
logger.info("Removed correctly the task configuration "+taskConfiguration+ " from saved configurations");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -334,10 +343,12 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
public void setTaskConfiguration(TaskConfiguration taskConfiguration) throws Exception {
|
||||
logger.debug("Set task configuration "+taskConfiguration+" starts...");
|
||||
ValidateTaskConfiguration(taskConfiguration);
|
||||
checkOwner();
|
||||
|
||||
boolean found = false;
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, taskConfiguration.getWorkspaceItemId());
|
||||
//TO SHUB
|
||||
Workspace ws = wsUtil.getWorkspace();
|
||||
WorkspaceItem item = ws.getItem(taskConfiguration.getWorkspaceItemId());
|
||||
//WorkspaceItem item = WsUtil.getItem(usernameOwner, taskConfiguration.getWorkspaceItemId());
|
||||
List<TaskConfiguration> configurations = getListOfTaskConfigurations(taskConfiguration.getWorkspaceItemId());
|
||||
|
||||
if(configurations==null)
|
||||
|
@ -362,7 +373,8 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
}
|
||||
try{
|
||||
JSONArray jsonConfigs = jsonUtil.toJSONArray(newConfigurations);
|
||||
WsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, jsonConfigs.toString());
|
||||
wsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, jsonConfigs.toString());
|
||||
//WsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, jsonConfigs.toString());
|
||||
logger.debug("Updated json configuration/s is/are: "+jsonConfigs.toString());
|
||||
logger.info(taskConfiguration +" added/updated");
|
||||
}catch(JSONException e){
|
||||
|
@ -389,11 +401,14 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
public Boolean eraseAllTaskConfigurations(String itemId) throws ItemNotExecutableException, Exception {
|
||||
logger.info("Erase all configurations starts...");
|
||||
Validate.notNull(itemId, "The itemId is null");
|
||||
checkOwner();
|
||||
//Check if the item is executable
|
||||
isItemExecutable(itemId);
|
||||
WorkspaceItem item = WsUtil.getItem(usernameOwner, itemId);
|
||||
WsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, null);
|
||||
//TO SHUB
|
||||
Workspace ws = wsUtil.getWorkspace();
|
||||
WorkspaceItem item = ws.getItem(itemId);
|
||||
wsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, null);
|
||||
//WorkspaceItem item = WsUtil.getItem(usernameOwner, itemId);
|
||||
//WsUtil.setPropertyValue(item, WS_DM_TASK_TASK_CONF, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -406,7 +421,6 @@ public class WorkspaceDataMinerTaskExecutor implements ExecutableTask<TaskConfig
|
|||
throws ItemNotExecutableException, TaskNotExecutableException, Exception {
|
||||
|
||||
ValidateTaskConfiguration(taskConfiguration);
|
||||
checkOwner();
|
||||
|
||||
TaskConfiguration taskConf = getConfigurationFromSaved(taskConfiguration.getWorkspaceItemId(), taskConfiguration.getConfigurationKey());
|
||||
DataMinerAccessPoint dap = getDataMinerAccessPoint();
|
||||
|
|
|
@ -7,14 +7,11 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Properties;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
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.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
||||
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -23,45 +20,58 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* The Class WsUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 26, 2018
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Sep 6, 2019
|
||||
*/
|
||||
public class WsUtil {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(WsUtil.class);
|
||||
|
||||
private Workspace theWorkspace;
|
||||
|
||||
/**
|
||||
* Gets the workspace from storage hub.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param token the token
|
||||
* @return the workspace from storage hub
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public Workspace getWorkspaceFromStorageHub(String scope, String token) throws Exception {
|
||||
StorageHubWrapper storageHubWrapper = new StorageHubWrapper(scope, token, false, false, true);
|
||||
return storageHubWrapper.getWorkspace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check owner.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private void checkInitParameters() throws Exception {
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
Validate.notNull(scope, "The scope is null. You must set a valid scope by "+ScopeProvider.class.getSimpleName());
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
Validate.notNull(token, "The user token is null. You must set a valid token by "+SecurityTokenProvider.class.getSimpleName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the workspace.
|
||||
*
|
||||
* @param username the username
|
||||
* @return the workspace
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws HomeNotFoundException the home not found exception
|
||||
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static Workspace getWorkspace(String username) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
|
||||
logger.trace("Get Workspace");
|
||||
Validate.notNull(username, "The username is null");
|
||||
return HomeLibrary.getUserWorkspace(username);
|
||||
}
|
||||
public Workspace getWorkspace() throws Exception{
|
||||
|
||||
|
||||
/**
|
||||
* Gets the item.
|
||||
*
|
||||
* @param username the username
|
||||
* @param itemId the item id
|
||||
* @return the item
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws HomeNotFoundException the home not found exception
|
||||
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||
* @throws ItemNotFoundException the item not found exception
|
||||
*/
|
||||
public static WorkspaceItem getItem(String username, String itemId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException, ItemNotFoundException{
|
||||
logger.trace("Get Workspace Item");
|
||||
Validate.notNull(itemId, "The itemId is null");
|
||||
return getWorkspace(username).getItem(itemId);
|
||||
if(theWorkspace==null) {
|
||||
checkInitParameters();
|
||||
String scope = ScopeProvider.instance.get();
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
theWorkspace = getWorkspaceFromStorageHub(scope, token);
|
||||
}
|
||||
return theWorkspace;
|
||||
|
||||
}
|
||||
|
||||
|
@ -71,31 +81,41 @@ public class WsUtil {
|
|||
*
|
||||
* @param item the item
|
||||
* @return the properties
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static Map<String, String> getProperties(WorkspaceItem item) {
|
||||
public Map<String, String> getProperties(WorkspaceItem item) throws Exception {
|
||||
|
||||
Properties properties;
|
||||
try {
|
||||
properties = item.getProperties();
|
||||
if (properties == null)
|
||||
Validate.notNull(item, "The input "+WorkspaceItem.class.getSimpleName()+" instance is null");
|
||||
Workspace workspace = getWorkspace();
|
||||
|
||||
Map<String, Object> map;
|
||||
if(item.getPropertyMap()==null) {
|
||||
try {
|
||||
map = workspace.getMetadata(item.getId());
|
||||
}
|
||||
catch (Exception e) {
|
||||
//silent
|
||||
return null;
|
||||
return properties.getProperties();
|
||||
}
|
||||
catch (InternalErrorException e) {
|
||||
return null;
|
||||
}
|
||||
}else {
|
||||
map = item.getPropertyMap().getValues();
|
||||
}
|
||||
|
||||
return toMapString(map);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the properties.
|
||||
* Gets the property value.
|
||||
*
|
||||
* @param item the item
|
||||
* @param propertyName the property name
|
||||
* @return the properties
|
||||
* @return the property value
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static String getPropertyValue(WorkspaceItem item, String propertyName){
|
||||
public String getPropertyValue(WorkspaceItem item, String propertyName) throws Exception{
|
||||
|
||||
Validate.notNull(item, "The input "+WorkspaceItem.class.getSimpleName()+" instance is null");
|
||||
Map<String, String> properties = getProperties(item);
|
||||
|
||||
if(properties==null)
|
||||
|
@ -113,8 +133,11 @@ public class WsUtil {
|
|||
* @param propertyName the property name
|
||||
* @param propertyValue the property value
|
||||
* @return true, if successful
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static boolean setPropertyValue(WorkspaceItem item, String propertyName, String propertyValue){
|
||||
public boolean setPropertyValue(WorkspaceItem item, String propertyName, String propertyValue) throws Exception{
|
||||
|
||||
Validate.notNull(item, "The input "+WorkspaceItem.class.getSimpleName()+" instance is null");
|
||||
|
||||
Map<String, String> properties = getProperties(item);
|
||||
try {
|
||||
|
@ -123,16 +146,53 @@ public class WsUtil {
|
|||
properties = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
Properties propertiesOBJ = item.getProperties();
|
||||
properties.put(propertyName, propertyValue);
|
||||
propertiesOBJ.addProperties(properties);
|
||||
logger.debug("Added properties "+properties+" to item: "+item.getId());
|
||||
Map<String, Object> map = toMapObject(properties);
|
||||
Workspace workspace = getWorkspace();
|
||||
workspace.updateMetadata(item.getId(), map);
|
||||
logger.info("Added properties "+properties+" to item: "+item.getId());
|
||||
return true;
|
||||
}
|
||||
catch (InternalErrorException e) {
|
||||
catch (Exception e) {
|
||||
logger.warn("Error occurred on updating the metadata for item id: "+item.getId(),e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To map object.
|
||||
*
|
||||
* @param map the map
|
||||
* @return the map
|
||||
*/
|
||||
public static Map<String, Object> toMapObject(Map<String, String> map) {
|
||||
|
||||
if(map==null)
|
||||
return null;
|
||||
|
||||
Map<String,Object> newMap = new HashMap<String, Object>(map.size());
|
||||
newMap.putAll(map);
|
||||
return newMap;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* To map string.
|
||||
*
|
||||
* @param map the map
|
||||
* @return the map
|
||||
*/
|
||||
public static Map<String, String> toMapString(Map<String, Object> map) {
|
||||
|
||||
Map<String, String> newMap = new HashMap<String, String>(map.size());
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
if (entry.getValue() instanceof String) {
|
||||
newMap.put(entry.getKey(), (String) entry.getValue());
|
||||
}
|
||||
}
|
||||
return newMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,20 @@
|
|||
package org.gcube.common.workspacetaskexecutor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.gcube.common.workspacetaskexecutor.dataminer.WorkspaceDataMinerTaskExecutor;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.TaskParameter;
|
||||
import org.gcube.common.workspacetaskexecutor.shared.TaskParameterType;
|
||||
|
@ -34,17 +40,58 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|||
*/
|
||||
public class TestDataMinerTaskExecutor {
|
||||
|
||||
|
||||
public static String USERNAME = "francesco.mangiacrapa";
|
||||
public static String SCOPE = "/gcube";
|
||||
|
||||
public static String WORKSPACE_FOLDER_ID = "682ff48e-0cc9-44df-884d-185fabe8909b";
|
||||
public static String USERNAME;
|
||||
public static String SCOPE;
|
||||
public static String TOKEN;
|
||||
public static String WORKSPACE_FOLDER_ID;
|
||||
|
||||
private static JsonUtil jUtil = new JsonUtil();
|
||||
|
||||
//CREATE DUMMY CONFIGURATIONS
|
||||
private static List<TaskConfiguration> listDummyConf;
|
||||
|
||||
private static WsUtil wsUtil = new WsUtil();
|
||||
|
||||
private static String TEST_CONF_PROPERTIES = "test-conf.properties";
|
||||
|
||||
|
||||
private static void loadTestConfig() {
|
||||
|
||||
try (InputStream input = TestDataMinerTaskExecutor.class.getClassLoader()
|
||||
.getResourceAsStream(TEST_CONF_PROPERTIES)) {
|
||||
|
||||
Properties prop = new Properties();
|
||||
|
||||
if (input == null) {
|
||||
System.out.println("Sorry, unable to find " + TEST_CONF_PROPERTIES);
|
||||
return;
|
||||
}
|
||||
|
||||
prop.load(input);
|
||||
/*
|
||||
Enumeration<?> e = prop.propertyNames();
|
||||
while (e.hasMoreElements()) {
|
||||
String key = (String) e.nextElement();
|
||||
String value = prop.getProperty(key);
|
||||
System.out.println("Key : " + key + ", Value : " + value);
|
||||
}
|
||||
*/
|
||||
|
||||
System.out.println("Loaded Configurations:");
|
||||
USERNAME = prop.getProperty("USERNAME").trim();
|
||||
System.out.println("USERNAME: " + USERNAME);
|
||||
SCOPE = prop.getProperty("SCOPE").trim();
|
||||
System.out.println("SCOPE: " + SCOPE);
|
||||
TOKEN = prop.getProperty("TOKEN").trim();
|
||||
System.out.println("TOKEN: " + TOKEN);
|
||||
WORKSPACE_FOLDER_ID = prop.getProperty("WORKSPACE_FOLDER_ID").trim();
|
||||
System.out.println("WORKSPACE_FOLDER_ID: " + WORKSPACE_FOLDER_ID);
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -63,6 +110,7 @@ public class TestDataMinerTaskExecutor {
|
|||
|
||||
private static void setDummyTaskConfigurations(WorkspaceDataMinerTaskExecutor exec){
|
||||
|
||||
System.out.println("\n\nSet Task configurations called...");
|
||||
|
||||
//SET TASK CONFIGURATION
|
||||
try {
|
||||
|
@ -78,6 +126,7 @@ public class TestDataMinerTaskExecutor {
|
|||
}
|
||||
|
||||
private static void deleteConfiguration(WorkspaceDataMinerTaskExecutor exec, TaskConfiguration conf){
|
||||
System.out.println("\n\nDelete configuration called...");
|
||||
try {
|
||||
Boolean done = exec.removeTaskConfiguration(conf);
|
||||
System.out.println("\n\nErase configuration done: "+done);
|
||||
|
@ -91,86 +140,37 @@ public class TestDataMinerTaskExecutor {
|
|||
|
||||
public static void main(String[] args) {
|
||||
|
||||
loadTestConfig();
|
||||
//jsonCheck();
|
||||
|
||||
ScopeProvider.instance.set(SCOPE);
|
||||
checkGubeProperties(null);
|
||||
SecurityTokenProvider.instance.set(TOKEN);
|
||||
// checkGubeProperties(null);
|
||||
listDummyConf = getDummyListOfConfigurations(3);
|
||||
checkGubeProperties(listDummyConf);
|
||||
// WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
|
||||
// checkGubeProperties(listDummyConf);
|
||||
WorkspaceDataMinerTaskExecutor exec = WorkspaceDataMinerTaskExecutor.getInstance();
|
||||
|
||||
// exec.withOwner(USERNAME);
|
||||
// //jsonCheck();
|
||||
|
||||
//TESTING SAVE CONFIGURATIONS
|
||||
setDummyTaskConfigurations(exec);
|
||||
|
||||
//GET LIST TASK CONFIGURATIONS
|
||||
List<TaskConfiguration> listTaskConfigs = getConfigurations(exec);
|
||||
|
||||
//TESTING DELETE ONE CONFIGURATIOn
|
||||
deleteConfiguration(exec, listTaskConfigs.get(1));
|
||||
//
|
||||
// //ERASE ALL CONFIGURATIONS
|
||||
// eraseAllTaskConfigurations(exec);
|
||||
|
||||
// eraseAllTaskConfigurations(exec);
|
||||
|
||||
//GET LIST CONFIGURATIONS
|
||||
//getConfigurations(exec);
|
||||
|
||||
//ERASE ALL CONFIGURATIONS
|
||||
//eraseAllTaskConfigurations(exec);
|
||||
|
||||
//SET TASK CONFIGURATION
|
||||
//setDummyTaskConfigurations(exec);
|
||||
//
|
||||
//// deleteConfiguration(exec, listDummyConf.get(1));
|
||||
////
|
||||
//getConfigurations(exec);
|
||||
|
||||
|
||||
// listDummyConf.get(2).setTaskId("Updated task id");
|
||||
// HashMap<String, String> map = new HashMap<String, String>();
|
||||
// map.put("Pippo", "Value Pippo");
|
||||
// map.put("Paperino", "Value Paperino");
|
||||
// listDummyConf.get(2).setMapParameters(map);
|
||||
//
|
||||
// try {
|
||||
// exec.setTaskConfiguration(listDummyConf.get(2));
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// };
|
||||
//
|
||||
// getConfigurations(exec);
|
||||
|
||||
//
|
||||
// //UPDATE TASK CONFIGURATION
|
||||
// HashMap<String, String> map = new HashMap<String, String>();
|
||||
// map.put("Pippo", "Value Pippo");
|
||||
// map.put("Paperino", "Value Paperino");
|
||||
// c2.setMapParameters(map);
|
||||
//
|
||||
// try {
|
||||
// exec.setTaskConfiguration(c2);
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// try {
|
||||
// //exec.removeTaskConfiguration(taskConfiguration)
|
||||
// //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();
|
||||
// }
|
||||
getConfigurations(exec);
|
||||
|
||||
}
|
||||
|
||||
public static List<TaskConfiguration> getConfigurations(WorkspaceDataMinerTaskExecutor exec){
|
||||
|
||||
System.out.println("\n\nGet configuration/s called...");
|
||||
try {
|
||||
List<TaskConfiguration> conf = exec.getListOfTaskConfigurations(WORKSPACE_FOLDER_ID);
|
||||
if(conf!=null){
|
||||
|
@ -178,8 +178,11 @@ public class TestDataMinerTaskExecutor {
|
|||
for (TaskConfiguration taskConfiguration : conf) {
|
||||
System.out.println(taskConfiguration);
|
||||
}
|
||||
}else {
|
||||
System.out.println("\n\n No configurations found");
|
||||
}
|
||||
|
||||
|
||||
return conf;
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -192,18 +195,20 @@ public class TestDataMinerTaskExecutor {
|
|||
|
||||
public static void checkGubeProperties(List<TaskConfiguration> listConfigurations){
|
||||
|
||||
//SET
|
||||
try {
|
||||
WorkspaceItem workspaceItem = WsUtil.getItem(USERNAME, WORKSPACE_FOLDER_ID);
|
||||
|
||||
try {
|
||||
Workspace workspace = wsUtil.getWorkspace();
|
||||
WorkspaceItem workspaceItem = workspace.getItem(WORKSPACE_FOLDER_ID);
|
||||
|
||||
//SET IF list of Configurations is not null
|
||||
if(listConfigurations!=null){
|
||||
JSONArray jsonArray = jUtil.toJSONArray(listConfigurations);
|
||||
System.out.println("Json array to save: "+jsonArray);
|
||||
WsUtil.setPropertyValue(workspaceItem, WorkspaceDataMinerTaskExecutor.WS_DM_TASK_TASK_CONF, jsonArray.toString());
|
||||
wsUtil.setPropertyValue(workspaceItem, WorkspaceDataMinerTaskExecutor.WS_DM_TASK_TASK_CONF, jsonArray.toString());
|
||||
}
|
||||
|
||||
//GET
|
||||
String jsonArrayConf = WsUtil.getPropertyValue(workspaceItem, WorkspaceDataMinerTaskExecutor.WS_DM_TASK_TASK_CONF);
|
||||
String jsonArrayConf = wsUtil.getPropertyValue(workspaceItem,WorkspaceDataMinerTaskExecutor.WS_DM_TASK_TASK_CONF);
|
||||
System.out.println("Json array read from "+WorkspaceDataMinerTaskExecutor.WS_DM_TASK_TASK_CONF+": "+jsonArrayConf);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue