refs #2112: Port SmartExecutor to be compliant with new Authorization
https://support.d4science.org/issues/2112 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@122953 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1ff064b7e6
commit
74806f6c2d
|
@ -25,7 +25,6 @@
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||||
|
|
|
@ -16,7 +16,6 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
|
||||||
import org.gcube.common.resources.gcore.common.Platform;
|
import org.gcube.common.resources.gcore.common.Platform;
|
||||||
import org.gcube.common.resources.gcore.utils.Group;
|
import org.gcube.common.resources.gcore.utils.Group;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
||||||
|
@ -47,6 +46,18 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
|
|
||||||
public static final long JOIN_TIMEOUT = 1000;
|
public static final long JOIN_TIMEOUT = 1000;
|
||||||
|
|
||||||
|
public static String getScope(){
|
||||||
|
String token = SecurityTokenProvider.instance.get();
|
||||||
|
AuthorizationEntry authorizationEntry;
|
||||||
|
try {
|
||||||
|
authorizationEntry = Constants.authorizationService().get(token);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
String scope = authorizationEntry.getContext();
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish the provided resource on all Service Scopes retrieved from
|
* Publish the provided resource on all Service Scopes retrieved from
|
||||||
* Context
|
* Context
|
||||||
|
@ -61,8 +72,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String scope = ScopeProvider.instance.get();
|
logger.debug("Trying to publish to {}:\n{}", getScope(), stringWriter);
|
||||||
logger.debug("Trying to publish to {}:\n{}", scope, stringWriter);
|
|
||||||
registryPublisher.create(resource);
|
registryPublisher.create(resource);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("The resource was not published", e);
|
logger.error("The resource was not published", e);
|
||||||
|
@ -83,7 +93,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
String id = resource.id();
|
String id = resource.id();
|
||||||
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, ScopeProvider.instance.get());
|
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, getScope());
|
||||||
|
|
||||||
registryPublisher.remove(resource);
|
registryPublisher.remove(resource);
|
||||||
|
|
||||||
|
@ -211,16 +221,14 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
||||||
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
|
||||||
|
|
||||||
for (ServiceEndpoint serviceEndpoint : serviceEndpoints) {
|
for (ServiceEndpoint serviceEndpoint : serviceEndpoints) {
|
||||||
try {
|
try {
|
||||||
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}",
|
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}",
|
||||||
serviceEndpoint.id(), scope);
|
serviceEndpoint.id(), getScope());
|
||||||
unPublishScopedResource(serviceEndpoint);
|
unPublishScopedResource(serviceEndpoint);
|
||||||
} catch(Exception e){
|
} catch(Exception e){
|
||||||
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}",
|
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}",
|
||||||
serviceEndpoint.id(), scope, e);
|
serviceEndpoint.id(), getScope(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
@ -292,19 +300,13 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onShutdown(){
|
public void onShutdown(){
|
||||||
String token = SecurityTokenProvider.instance.get();
|
|
||||||
AuthorizationEntry authorizationEntry;
|
|
||||||
try {
|
|
||||||
authorizationEntry = Constants.authorizationService().get(token);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
String scope = authorizationEntry.getContext();
|
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"\n-------------------------------------------------------\n"
|
"\n-------------------------------------------------------\n"
|
||||||
+ "Smart Executor is Stopping on scope {}\n"
|
+ "Smart Executor is Stopping on scope {}\n"
|
||||||
+ "-------------------------------------------------------", scope);
|
+ "-------------------------------------------------------",
|
||||||
|
getScope());
|
||||||
|
|
||||||
SmartExecutorScheduler.getInstance().stopAll();
|
SmartExecutorScheduler.getInstance().stopAll();
|
||||||
|
|
||||||
|
@ -314,13 +316,15 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
SmartExecutorPersistenceFactory.getPersistenceConnector().close();
|
SmartExecutorPersistenceFactory.getPersistenceConnector().close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to correctly close {} for scope {}",
|
logger.error("Unable to correctly close {} for scope {}",
|
||||||
SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e);
|
SmartExecutorPersistenceConnector.class.getSimpleName(),
|
||||||
|
getScope(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"\n-------------------------------------------------------\n"
|
"\n-------------------------------------------------------\n"
|
||||||
+ "Smart Executor Stopped Successfully on scope {}\n"
|
+ "Smart Executor Stopped Successfully on scope {}\n"
|
||||||
+ "-------------------------------------------------------", scope);
|
+ "-------------------------------------------------------",
|
||||||
|
getScope());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,6 @@ import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||||
import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
|
import org.gcube.vremanagement.executor.exception.SchedulePersistenceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every implementation MUST take in account to store/query the records
|
|
||||||
* on the current scope which is not passed as argument but MUST be retrieved
|
|
||||||
* using {#org.gcube.common.scope.api.ScopeProvider} facilities
|
|
||||||
* i.e. ScopeProvider.instance.get()
|
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
*/
|
*/
|
||||||
public interface ScheduledTaskConfiguration {
|
public interface ScheduledTaskConfiguration {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.text.ParseException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
|
||||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||||
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
||||||
import org.gcube.vremanagement.executor.exception.ScopeNotMatchException;
|
import org.gcube.vremanagement.executor.exception.ScopeNotMatchException;
|
||||||
|
@ -48,36 +48,36 @@ public class JSONLaunchParameter extends LaunchParameter {
|
||||||
|
|
||||||
public JSONLaunchParameter(String pluginName, Map<String, String> pluginCapabilities, Map<String, Object> inputs) {
|
public JSONLaunchParameter(String pluginName, Map<String, String> pluginCapabilities, Map<String, Object> inputs) {
|
||||||
super(pluginName, pluginCapabilities, inputs);
|
super(pluginName, pluginCapabilities, inputs);
|
||||||
this.scope = ScopeProvider.instance.get();
|
this.scope = SmartExecutorInitializator.getScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONLaunchParameter(String pluginName, Map<String, Object> inputs, Scheduling scheduling) throws ParseException {
|
public JSONLaunchParameter(String pluginName, Map<String, Object> inputs, Scheduling scheduling) throws ParseException {
|
||||||
super(pluginName, inputs, scheduling);
|
super(pluginName, inputs, scheduling);
|
||||||
this.scope = ScopeProvider.instance.get();
|
this.scope = SmartExecutorInitializator.getScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONLaunchParameter(String pluginName, Map<String, String> pluginCapabilities, Map<String, Object> inputs, Scheduling scheduling) throws ParseException {
|
public JSONLaunchParameter(String pluginName, Map<String, String> pluginCapabilities, Map<String, Object> inputs, Scheduling scheduling) throws ParseException {
|
||||||
super(pluginName, pluginCapabilities, inputs, scheduling);
|
super(pluginName, pluginCapabilities, inputs, scheduling);
|
||||||
this.scope = ScopeProvider.instance.get();
|
this.scope = SmartExecutorInitializator.getScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public JSONLaunchParameter(String pluginName, Map<String, Object> inputs, Scheduling scheduling, boolean persist) throws ParseException {
|
public JSONLaunchParameter(String pluginName, Map<String, Object> inputs, Scheduling scheduling, boolean persist) throws ParseException {
|
||||||
super(pluginName, inputs, scheduling, persist);
|
super(pluginName, inputs, scheduling, persist);
|
||||||
this.scope = ScopeProvider.instance.get();
|
this.scope = SmartExecutorInitializator.getScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public JSONLaunchParameter(String pluginName, Map<String, String> pluginCapabilities, Map<String, Object> inputs, Scheduling scheduling, boolean persist) throws ParseException {
|
public JSONLaunchParameter(String pluginName, Map<String, String> pluginCapabilities, Map<String, Object> inputs, Scheduling scheduling, boolean persist) throws ParseException {
|
||||||
super(pluginName, pluginCapabilities, inputs, scheduling, persist);
|
super(pluginName, pluginCapabilities, inputs, scheduling, persist);
|
||||||
this.scheduling = new JSONScheduling(scheduling);
|
this.scheduling = new JSONScheduling(scheduling);
|
||||||
this.scope = ScopeProvider.instance.get();
|
this.scope = SmartExecutorInitializator.getScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONLaunchParameter(LaunchParameter parameter) throws ParseException {
|
public JSONLaunchParameter(LaunchParameter parameter) throws ParseException {
|
||||||
super(parameter.getPluginName(), parameter.getPluginCapabilities(), parameter.getInputs(), parameter.getScheduling());
|
super(parameter.getPluginName(), parameter.getPluginCapabilities(), parameter.getInputs(), parameter.getScheduling());
|
||||||
this.scheduling = new JSONScheduling(parameter.getScheduling());
|
this.scheduling = new JSONScheduling(parameter.getScheduling());
|
||||||
this.scope = ScopeProvider.instance.get();
|
this.scope = SmartExecutorInitializator.getScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONLaunchParameter(JSONObject jsonObject) throws JSONException, ParseException, ScopeNotMatchException {
|
public JSONLaunchParameter(JSONObject jsonObject) throws JSONException, ParseException, ScopeNotMatchException {
|
||||||
|
@ -113,7 +113,7 @@ public class JSONLaunchParameter extends LaunchParameter {
|
||||||
this.usedBy = jsonObject.getString(USED_BY);
|
this.usedBy = jsonObject.getString(USED_BY);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scope = ScopeProvider.instance.get();
|
this.scope = SmartExecutorInitializator.getScope();
|
||||||
if(jsonObject.has(SCOPE)){
|
if(jsonObject.has(SCOPE)){
|
||||||
String jsonScope = jsonObject.getString(SCOPE);
|
String jsonScope = jsonObject.getString(SCOPE);
|
||||||
if(jsonScope.compareTo(scope)!=0){
|
if(jsonScope.compareTo(scope)!=0){
|
||||||
|
|
|
@ -15,10 +15,10 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
import org.gcube.common.resources.gcore.utils.Group;
|
import org.gcube.common.resources.gcore.utils.Group;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.gcube.resources.discovery.icclient.ICFactory;
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||||
|
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
|
@ -126,7 +126,7 @@ public class SmartExecutorPersistenceConfiguration {
|
||||||
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
||||||
if(serviceEndpoints.size()>1){
|
if(serviceEndpoints.size()>1){
|
||||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
|
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
|
||||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", ScopeProvider.instance.get()));
|
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", SmartExecutorInitializator.getScope()));
|
||||||
serviceEndpoints = client.submit(query);
|
serviceEndpoints = client.submit(query);
|
||||||
}
|
}
|
||||||
return serviceEndpoints.get(0);
|
return serviceEndpoints.get(0);
|
||||||
|
|
|
@ -11,10 +11,6 @@ import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model the connector which create or open the connection to DB.
|
* Model the connector which create or open the connection to DB.
|
||||||
* Every implementation MUST take in account to store/query the records
|
|
||||||
* on the current scope which is not passed as argument but MUSt be retrieved
|
|
||||||
* using {#org.gcube.common.scope.api.ScopeProvider} facilities
|
|
||||||
* i.e. ScopeProvider.instance.get()
|
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
*/
|
*/
|
||||||
public abstract class SmartExecutorPersistenceConnector implements PluginStateNotification {
|
public abstract class SmartExecutorPersistenceConnector implements PluginStateNotification {
|
||||||
|
|
|
@ -6,7 +6,7 @@ package org.gcube.vremanagement.executor.persistence;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
|
||||||
import org.gcube.vremanagement.executor.persistence.couchdb.CouchDBPersistenceConnector;
|
import org.gcube.vremanagement.executor.persistence.couchdb.CouchDBPersistenceConnector;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -42,28 +42,33 @@ public abstract class SmartExecutorPersistenceFactory {
|
||||||
* @return the persistenceConnector
|
* @return the persistenceConnector
|
||||||
*/
|
*/
|
||||||
public static synchronized SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception {
|
public static synchronized SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception {
|
||||||
String scope = ScopeProvider.instance.get();
|
SmartExecutorPersistenceConnector persistence =
|
||||||
SmartExecutorPersistenceConnector persistence = getPersistenceConnector(scope);
|
getPersistenceConnector(SmartExecutorInitializator.getScope());
|
||||||
|
|
||||||
if(persistence==null){
|
if(persistence==null){
|
||||||
logger.trace("Retrieving {} for scope {} not found on internal {}. Intializing it.",
|
logger.trace("Retrieving {} for scope {} not found on internal {}. Intializing it.",
|
||||||
SmartExecutorPersistenceConnector.class.getSimpleName(), scope, Map.class.getSimpleName());
|
SmartExecutorPersistenceConnector.class.getSimpleName(),
|
||||||
|
SmartExecutorInitializator.getScope(),
|
||||||
|
Map.class.getSimpleName());
|
||||||
|
|
||||||
|
String className = CouchDBPersistenceConnector.class.getSimpleName();
|
||||||
SmartExecutorPersistenceConfiguration configuration =
|
SmartExecutorPersistenceConfiguration configuration =
|
||||||
new SmartExecutorPersistenceConfiguration(CouchDBPersistenceConnector.class.getSimpleName());
|
new SmartExecutorPersistenceConfiguration(className);
|
||||||
|
|
||||||
persistence = new CouchDBPersistenceConnector(configuration);
|
persistence = new CouchDBPersistenceConnector(configuration);
|
||||||
persistenceConnectors.put(scope, persistence);
|
persistenceConnectors.put(SmartExecutorInitializator.getScope(),
|
||||||
|
persistence);
|
||||||
}
|
}
|
||||||
|
|
||||||
return persistence;
|
return persistence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void closePersistenceConnector() throws Exception {
|
public static synchronized void closePersistenceConnector() throws Exception {
|
||||||
String scope = ScopeProvider.instance.get();
|
SmartExecutorPersistenceConnector persistence =
|
||||||
SmartExecutorPersistenceConnector persistence = getPersistenceConnector(scope);
|
getPersistenceConnector(SmartExecutorInitializator.getScope());
|
||||||
if(persistence!=null){
|
if(persistence!=null){
|
||||||
persistence.close();
|
persistence.close();
|
||||||
persistenceConnectors.remove(scope);
|
persistenceConnectors.remove(SmartExecutorInitializator.getScope());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.ektorp.http.StdHttpClient;
|
||||||
import org.ektorp.http.StdHttpClient.Builder;
|
import org.ektorp.http.StdHttpClient.Builder;
|
||||||
import org.ektorp.impl.StdCouchDbConnector;
|
import org.ektorp.impl.StdCouchDbConnector;
|
||||||
import org.ektorp.impl.StdCouchDbInstance;
|
import org.ektorp.impl.StdCouchDbInstance;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
|
||||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||||
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
|
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
|
||||||
import org.gcube.vremanagement.executor.configuration.jsonbased.JSONLaunchParameter;
|
import org.gcube.vremanagement.executor.configuration.jsonbased.JSONLaunchParameter;
|
||||||
|
@ -205,7 +205,7 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
|
||||||
|
|
||||||
ViewQuery query = new ViewQuery().designDocId(String.format("%s%s", MAP_REDUCE__DESIGN, PLUGIN_STATE_DOCUMENT));
|
ViewQuery query = new ViewQuery().designDocId(String.format("%s%s", MAP_REDUCE__DESIGN, PLUGIN_STATE_DOCUMENT));
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = SmartExecutorInitializator.getScope();
|
||||||
ArrayNode startKey = new ObjectMapper().createArrayNode();
|
ArrayNode startKey = new ObjectMapper().createArrayNode();
|
||||||
startKey.add(scope);
|
startKey.add(scope);
|
||||||
ArrayNode endKey = new ObjectMapper().createArrayNode();
|
ArrayNode endKey = new ObjectMapper().createArrayNode();
|
||||||
|
@ -273,7 +273,7 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
|
||||||
ViewQuery query = new ViewQuery().designDocId(String.format("%s%s", MAP_REDUCE__DESIGN, SCHEDULED_TASKS_DOCUMENT));
|
ViewQuery query = new ViewQuery().designDocId(String.format("%s%s", MAP_REDUCE__DESIGN, SCHEDULED_TASKS_DOCUMENT));
|
||||||
query = query.viewName(ORPHAN_VIEW);
|
query = query.viewName(ORPHAN_VIEW);
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = SmartExecutorInitializator.getScope();
|
||||||
ArrayNode startKey = new ObjectMapper().createArrayNode();
|
ArrayNode startKey = new ObjectMapper().createArrayNode();
|
||||||
startKey.add(scope);
|
startKey.add(scope);
|
||||||
ArrayNode endKey = new ObjectMapper().createArrayNode();
|
ArrayNode endKey = new ObjectMapper().createArrayNode();
|
||||||
|
@ -316,7 +316,7 @@ public class CouchDBPersistenceConnector extends SmartExecutorPersistenceConnect
|
||||||
JSONObject obj = jlp.toJSON();
|
JSONObject obj = jlp.toJSON();
|
||||||
obj.append(TYPE_JSON_FIELD, SCHEDULED_TASK_TYPE);
|
obj.append(TYPE_JSON_FIELD, SCHEDULED_TASK_TYPE);
|
||||||
obj.append(USED_BY_FIELD, consumerID);
|
obj.append(USED_BY_FIELD, consumerID);
|
||||||
obj.append(ScheduledTaskConfiguration.SCOPE, ScopeProvider.instance.get());
|
obj.append(ScheduledTaskConfiguration.SCOPE, SmartExecutorInitializator.getScope());
|
||||||
createItem(obj, uuid.toString());
|
createItem(obj, uuid.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error Adding Scheduled Task UUID : {}, Consumer : {}, LaunchParameter : {}",
|
logger.error("Error Adding Scheduled Task UUID : {}, Consumer : {}, LaunchParameter : {}",
|
||||||
|
|
|
@ -9,8 +9,8 @@ import java.util.UUID;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.codehaus.jackson.node.ObjectNode;
|
import org.codehaus.jackson.node.ObjectNode;
|
||||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.smartgears.ContextProvider;
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.vremanagement.executor.SmartExecutorInitializator;
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
|
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class PluginStateEvolutionObjectNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addScope(ObjectNode objectNode){
|
public static void addScope(ObjectNode objectNode){
|
||||||
objectNode.put(SCOPE_FIELD, ScopeProvider.instance.get());
|
objectNode.put(SCOPE_FIELD, SmartExecutorInitializator.getScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObjectNode getObjectMapper(PluginStateEvolution pluginStateEvolution){
|
public static ObjectNode getObjectMapper(PluginStateEvolution pluginStateEvolution){
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.acme.HelloWorldPluginDeclaration;
|
import org.acme.HelloWorldPluginDeclaration;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||||
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
|
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
|
||||||
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfigurationFactory;
|
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfigurationFactory;
|
||||||
|
@ -17,6 +17,7 @@ import org.gcube.vremanagement.executor.persistence.couchdb.CouchDBPersistenceCo
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginState;
|
import org.gcube.vremanagement.executor.plugin.PluginState;
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -29,13 +30,14 @@ public class SmartExecutorPersistenceConnectorTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SmartExecutorPersistenceConnectorTest.class);
|
private static Logger logger = LoggerFactory.getLogger(SmartExecutorPersistenceConnectorTest.class);
|
||||||
|
|
||||||
public static final String[] SCOPES = new String[]{"/gcube", "/gcube/devsec"};
|
@Before
|
||||||
public static final String GCUBE_SCOPE = SCOPES[0];
|
public void before() throws Exception{
|
||||||
public static final String GCUBE_DEVSEC_SCOPE = SCOPES[1];
|
SecurityTokenProvider.instance.set("82a84741-debe-4c90-a907-c429c8272071");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectionTest() throws Exception {
|
public void getConnectionTest() throws Exception {
|
||||||
ScopeProvider.instance.set(GCUBE_DEVSEC_SCOPE);
|
|
||||||
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
|
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
|
||||||
Assert.assertNotNull(persistenceConnector);
|
Assert.assertNotNull(persistenceConnector);
|
||||||
Assert.assertEquals(CouchDBPersistenceConnector.class, persistenceConnector.getClass());
|
Assert.assertEquals(CouchDBPersistenceConnector.class, persistenceConnector.getClass());
|
||||||
|
@ -44,7 +46,6 @@ public class SmartExecutorPersistenceConnectorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPluginInstanceStateTest() throws Exception {
|
public void getPluginInstanceStateTest() throws Exception {
|
||||||
ScopeProvider.instance.set(GCUBE_DEVSEC_SCOPE);
|
|
||||||
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
|
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
|
@ -70,8 +71,6 @@ public class SmartExecutorPersistenceConnectorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailableScheduledTasksTest() throws Exception {
|
public void getAvailableScheduledTasksTest() throws Exception {
|
||||||
ScopeProvider.instance.set(GCUBE_DEVSEC_SCOPE);
|
|
||||||
|
|
||||||
ScheduledTaskConfiguration stc = ScheduledTaskConfigurationFactory.getLaunchConfiguration();
|
ScheduledTaskConfiguration stc = ScheduledTaskConfigurationFactory.getLaunchConfiguration();
|
||||||
Assert.assertNotNull(stc);
|
Assert.assertNotNull(stc);
|
||||||
Assert.assertEquals(CouchDBPersistenceConnector.class, stc.getClass());
|
Assert.assertEquals(CouchDBPersistenceConnector.class, stc.getClass());
|
||||||
|
|
|
@ -9,11 +9,10 @@ import java.util.UUID;
|
||||||
|
|
||||||
import org.acme.HelloWorldPlugin;
|
import org.acme.HelloWorldPlugin;
|
||||||
import org.acme.HelloWorldPluginDeclaration;
|
import org.acme.HelloWorldPluginDeclaration;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.vremanagement.executor.exception.InputsNullException;
|
import org.gcube.vremanagement.executor.exception.InputsNullException;
|
||||||
import org.gcube.vremanagement.executor.exception.InvalidInputsException;
|
import org.gcube.vremanagement.executor.exception.InvalidInputsException;
|
||||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
|
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
|
||||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnectorTest;
|
|
||||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
|
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginState;
|
import org.gcube.vremanagement.executor.plugin.PluginState;
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
|
import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
|
||||||
|
@ -34,7 +33,7 @@ public class RunnablePluginTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void prepare() throws Exception{
|
public static void prepare() throws Exception{
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set(SmartExecutorPersistenceConnectorTest.GCUBE_DEVSEC_SCOPE);
|
SecurityTokenProvider.instance.set("82a84741-debe-4c90-a907-c429c8272071");
|
||||||
SmartExecutorPersistenceFactory.getPersistenceConnector();
|
SmartExecutorPersistenceFactory.getPersistenceConnector();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to Create JDBCPersistenceConnector");
|
logger.error("Unable to Create JDBCPersistenceConnector");
|
||||||
|
|
|
@ -10,13 +10,12 @@ import java.util.UUID;
|
||||||
|
|
||||||
import org.acme.HelloWorldPlugin;
|
import org.acme.HelloWorldPlugin;
|
||||||
import org.acme.HelloWorldPluginDeclaration;
|
import org.acme.HelloWorldPluginDeclaration;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||||
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
||||||
import org.gcube.vremanagement.executor.exception.PluginStateNotRetrievedException;
|
import org.gcube.vremanagement.executor.exception.PluginStateNotRetrievedException;
|
||||||
import org.gcube.vremanagement.executor.exception.UnableToInterruptTaskException;
|
import org.gcube.vremanagement.executor.exception.UnableToInterruptTaskException;
|
||||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
|
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
|
||||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnectorTest;
|
|
||||||
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
|
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginState;
|
import org.gcube.vremanagement.executor.plugin.PluginState;
|
||||||
import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler;
|
import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler;
|
||||||
|
@ -43,7 +42,7 @@ public class SmartExecutorSchedulerTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void prepare() throws Exception{
|
public static void prepare() throws Exception{
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set(SmartExecutorPersistenceConnectorTest.GCUBE_DEVSEC_SCOPE);
|
SecurityTokenProvider.instance.set("82a84741-debe-4c90-a907-c429c8272071");
|
||||||
/*
|
/*
|
||||||
pc = new JDBCPersistenceConnector(".");
|
pc = new JDBCPersistenceConnector(".");
|
||||||
SmartExecutorPersistenceConnector.setPersistenceConnector(pc);
|
SmartExecutorPersistenceConnector.setPersistenceConnector(pc);
|
||||||
|
|
Loading…
Reference in New Issue