diff --git a/pom.xml b/pom.xml
index 2942803..4857da2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,7 @@
org.gcube.distribution
gcube-smartgears-bom
- 2.0.0-SNAPSHOT
+ 2.1.0
pom
import
diff --git a/src/main/java/org/gcube/vremanagement/executor/ContextUtility.java b/src/main/java/org/gcube/vremanagement/executor/ContextUtility.java
index 73e79bb..f09b547 100644
--- a/src/main/java/org/gcube/vremanagement/executor/ContextUtility.java
+++ b/src/main/java/org/gcube/vremanagement/executor/ContextUtility.java
@@ -20,7 +20,7 @@ public class ContextUtility {
private static Logger logger = LoggerFactory.getLogger(ContextUtility.class);
- public static String getCurrentScope() {
+ public static String getCurrentContext() {
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry;
try {
@@ -36,7 +36,7 @@ public class ContextUtility {
return context;
}
- public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
+ public static String getCurrentContext(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context);
@@ -45,7 +45,7 @@ public class ContextUtility {
public static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token);
- ScopeProvider.instance.set(getCurrentScope(token));
+ ScopeProvider.instance.set(getCurrentContext(token));
}
public static ClientInfo getClientInfo() {
diff --git a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java
index 3fdd6e4..fee3fcd 100644
--- a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java
+++ b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java
@@ -42,13 +42,13 @@ public class SmartExecutorInitializator implements ApplicationManager {
*/
@Override
public void onInit() {
- String scope = ContextUtility.getCurrentScope();
+ String context = ContextUtility.getCurrentContext();
logger.trace(
"\n-------------------------------------------------------\n"
- + "Smart Executor is Starting on scope {}\n"
+ + "Smart Executor is Starting on context {}\n"
+ "-------------------------------------------------------",
- scope);
+ context);
logger.debug("Getting Available Plugins and their own supported capabilities");
@@ -68,9 +68,9 @@ public class SmartExecutorInitializator implements ApplicationManager {
isPublisher.publishPlugins(availablePlugins);
}catch (Exception e) {
if(isPublisher instanceof RestISPublisher) {
- logger.warn("Unable to create RunningPlugin in context {}. {}", scope, e.getMessage());
+ logger.warn("Unable to create RunningPlugin in context {}. {}", context, e.getMessage());
} else {
- logger.error("Unable to create ServiceEndpoint in context {}. The Service will be aborted", scope, e);
+ logger.error("Unable to create ServiceEndpoint in context {}. The Service will be aborted", context, e);
throw new RuntimeException(e);
}
}
@@ -83,7 +83,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
smartExecutorPersistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
} catch (Exception e) {
logger.error("Unable to instantiate {} for scope {}. The Service will be aborted",
- SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e);
+ SmartExecutorPersistenceConnector.class.getSimpleName(), context, e);
throw new RuntimeException(e);
}
@@ -91,11 +91,11 @@ public class SmartExecutorInitializator implements ApplicationManager {
// Persistence to clean previous situation of a failure of HostingNode
try {
- logger.debug("Going to get Orphan Scheduled Tasks in scope {}", scope);
+ logger.debug("Going to get Orphan Scheduled Tasks in scope {}", context);
List scheduledTasks = smartExecutorPersistenceConnector.getOrphanScheduledTasks(pluginManager.getAvailablePlugins().keySet());
if(scheduledTasks.size()==0){
- logger.debug("No Orphan Scheduled Tasks this instance can take in charge in scope {}", scope);
+ logger.debug("No Orphan Scheduled Tasks this instance can take in charge in scope {}", context);
}
for(final ScheduledTask scheduledTask : scheduledTasks){
@@ -106,7 +106,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
// Reserving the task.
smartExecutorPersistenceConnector.reserveScheduledTask(scheduledTask);
}catch (Exception e) {
- logger.debug("({}) Someone else is going to take in charge the scheduled task {}. Skipping.", scope, taskAsString);
+ logger.debug("({}) Someone else is going to take in charge the scheduled task {}. Skipping.", context, taskAsString);
continue;
}
@@ -117,7 +117,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
LaunchParameter launchParameter = scheduledTask.getLaunchParameter();
try {
- logger.info("({}) Going to schedule an already scheduled task with the following parameters {}", scope,
+ logger.info("({}) Going to schedule an already scheduled task with the following parameters {}", context,
ExtendedSEMapper.getInstance().marshal(launchParameter));
} catch (Exception e1) {
@@ -132,11 +132,11 @@ public class SmartExecutorInitializator implements ApplicationManager {
smartExecutorPersistenceConnector.removeScheduledTask(scheduledTask);
smartExecutorScheduler.schedule(launchParameter, scheduledTask.getUUID());
} catch (Exception e) {
- logger.error("({}) Error while trying to relaunch scheduled task.", scope, e);
+ logger.error("({}) Error while trying to relaunch scheduled task.", context, e);
try {
smartExecutorPersistenceConnector.addScheduledTask(scheduledTask);
} catch (Exception ex) {
- logger.error("({}) Unable to add back scheduled task {}", scope, taskAsString);
+ logger.error("({}) Unable to add back scheduled task {}", context, taskAsString);
}
}
@@ -148,14 +148,14 @@ public class SmartExecutorInitializator implements ApplicationManager {
}
} catch (Exception e) {
- logger.error("Unable to get Orphan Scheduled Tasksfor scope {}.", scope, e);
+ logger.error("Unable to get Orphan Scheduled Tasksfor scope {}.", context, e);
return;
}
logger.trace(
"\n-------------------------------------------------------\n"
- + "Smart Executor Started Successfully on scope {}\n"
- + "-------------------------------------------------------", scope);
+ + "Smart Executor Started Successfully on context {}\n"
+ + "-------------------------------------------------------", context);
}
@@ -172,16 +172,16 @@ public class SmartExecutorInitializator implements ApplicationManager {
logger.trace(
"\n-------------------------------------------------------\n"
- + "Smart Executor is Stopping on scope {}\n"
+ + "Smart Executor is Stopping on context {}\n"
+ "-------------------------------------------------------",
- ContextUtility.getCurrentScope());
+ ContextUtility.getCurrentContext());
SmartExecutorScheduler scheduler;
try {
scheduler = SmartExecutorSchedulerFactory.getSmartExecutorScheduler();
scheduler.stopAll();
- SmartExecutorSchedulerFactory.remove();
+ SmartExecutorSchedulerFactory.removeCurrentSmartExecutorScheduler();
} catch (SchedulerException e) {
logger.error("", e);
}
@@ -192,22 +192,22 @@ public class SmartExecutorInitializator implements ApplicationManager {
try {
isPublisher.unpublishPlugins(false);
}catch (Exception e) {
- logger.error("unable to unpublish plugind from IS using {}", isPublisher.getClass().getName());
+ logger.error("unable to unpublish plugins from IS using {}", isPublisher.getClass().getName());
}
}
try {
- SmartExecutorPersistenceFactory.closePersistenceConnector();
+ SmartExecutorPersistenceFactory.closeCurrentPersistenceConnector();
} catch (Throwable e) {
- logger.error("Unable to correctly close {} for scope {}",
+ logger.error("Unable to correctly close {} for context {}",
SmartExecutorPersistenceConnector.class.getSimpleName(),
- ContextUtility.getCurrentScope(), e);
+ ContextUtility.getCurrentContext(), e);
}
logger.trace(
"\n-------------------------------------------------------\n"
- + "Smart Executor Stopped Successfully on scope {}\n"
+ + "Smart Executor Stopped Successfully on context {}\n"
+ "-------------------------------------------------------",
- ContextUtility.getCurrentScope());
+ ContextUtility.getCurrentContext());
}
}
diff --git a/src/main/java/org/gcube/vremanagement/executor/ispublisher/GCoreISPublisher.java b/src/main/java/org/gcube/vremanagement/executor/ispublisher/GCoreISPublisher.java
index 90fb0cf..9ef9865 100644
--- a/src/main/java/org/gcube/vremanagement/executor/ispublisher/GCoreISPublisher.java
+++ b/src/main/java/org/gcube/vremanagement/executor/ispublisher/GCoreISPublisher.java
@@ -53,7 +53,7 @@ public class GCoreISPublisher extends ISPublisher {
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
try {
- logger.debug("Trying to publish to {}:\n{}", ContextUtility.getCurrentScope(), stringWriter);
+ logger.debug("Trying to publish to {}:\n{}", ContextUtility.getCurrentContext(), stringWriter);
registryPublisher.create(resource);
} catch(Exception e) {
logger.error("The resource was not published", e);
@@ -75,7 +75,7 @@ public class GCoreISPublisher extends ISPublisher {
String id = resource.id();
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id,
- ContextUtility.getCurrentScope());
+ ContextUtility.getCurrentContext());
registryPublisher.remove(resource);
@@ -218,11 +218,11 @@ public class GCoreISPublisher extends ISPublisher {
for(ServiceEndpoint serviceEndpoint : serviceEndpoints) {
try {
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}",
- serviceEndpoint.id(), ContextUtility.getCurrentScope());
+ serviceEndpoint.id(), ContextUtility.getCurrentContext());
unPublishResource(serviceEndpoint);
} catch(Exception e) {
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}",
- serviceEndpoint.id(), ContextUtility.getCurrentScope(), e);
+ serviceEndpoint.id(), ContextUtility.getCurrentContext(), e);
}
}
} catch(Exception e) {
@@ -238,7 +238,7 @@ public class GCoreISPublisher extends ISPublisher {
publishResource(serviceEndpoint);
} catch(Exception e) {
logger.error("Unable to Create ServiceEndpoint for scope {}. The Service will be aborted",
- ContextUtility.getCurrentScope(), e);
+ ContextUtility.getCurrentContext(), e);
throw new RuntimeException(e);
}
}
diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java
index 7da12bd..a63ce1c 100644
--- a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java
+++ b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConfiguration.java
@@ -131,7 +131,7 @@ public class SmartExecutorPersistenceConfiguration {
List serviceEndpoints = client.submit(query);
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/Value/text() eq '%s'", ContextUtility.getCurrentScope()));
+ query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", ContextUtility.getCurrentContext()));
serviceEndpoints = client.submit(query);
}
return serviceEndpoints.get(0);
diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceFactory.java b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceFactory.java
index b95f03e..82a3a99 100644
--- a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceFactory.java
+++ b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceFactory.java
@@ -18,58 +18,75 @@ import org.slf4j.LoggerFactory;
public abstract class SmartExecutorPersistenceFactory {
private static final Logger logger = LoggerFactory.getLogger(SmartExecutorPersistenceFactory.class);
-
+
private static Map persistenceConnectors;
-
+
static {
persistenceConnectors = new HashMap();
}
-
- private static SmartExecutorPersistenceConnector getPersistenceConnector(String scope) throws Exception {
- if(scope==null){
- String error = "No Scope available.";
+
+ private static synchronized SmartExecutorPersistenceConnector getPersistenceConnector(String context) throws Exception {
+ if (context == null) {
+ String error = "No Context available.";
logger.error(error);
- throw new RuntimeException(error);
+ throw new RuntimeException(error);
}
- logger.trace("Retrieving {} for scope {}",
- SmartExecutorPersistenceConnector.class.getSimpleName(), scope);
-
- SmartExecutorPersistenceConnector persistence = persistenceConnectors.get(scope);
-
- if(persistence==null){
- logger.trace("Retrieving {} for scope {} not found on internal {}. Intializing it.",
- SmartExecutorPersistenceConnector.class.getSimpleName(),
- scope, Map.class.getSimpleName());
-
+ logger.trace("Retrieving {} for context {}", SmartExecutorPersistenceConnector.class.getSimpleName(), context);
+
+ SmartExecutorPersistenceConnector persistence = persistenceConnectors.get(context);
+
+ if (persistence == null) {
+ logger.trace("Retrieving {} for context {} not found on internal {}. Intializing it.",
+ SmartExecutorPersistenceConnector.class.getSimpleName(), context, Map.class.getSimpleName());
+
String className = OrientDBPersistenceConnector.class.getSimpleName();
- SmartExecutorPersistenceConfiguration configuration =
- new SmartExecutorPersistenceConfiguration(className);
-
+ SmartExecutorPersistenceConfiguration configuration = new SmartExecutorPersistenceConfiguration(className);
+
persistence = new OrientDBPersistenceConnector(configuration);
- persistenceConnectors.put(ContextUtility.getCurrentScope(),
- persistence);
+ persistenceConnectors.put(ContextUtility.getCurrentContext(), persistence);
}
-
+
return persistence;
}
-
+
/**
* @return the persistenceConnector
*/
- public static synchronized SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception {
- String scope = ContextUtility.getCurrentScope();
- return getPersistenceConnector(scope);
+ public static SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception {
+ String context = ContextUtility.getCurrentContext();
+ return getPersistenceConnector(context);
}
-
- public static synchronized void closePersistenceConnector() throws Exception {
- String scope = ContextUtility.getCurrentScope();
- SmartExecutorPersistenceConnector persistence =
- getPersistenceConnector(scope);
- if(persistence!=null){
+
+ public static void closeCurrentPersistenceConnector() throws Exception {
+ String context = ContextUtility.getCurrentContext();
+ closePersistenceConnector(context);
+ }
+
+ private static synchronized void closePersistenceConnector(String context) throws Exception {
+ SmartExecutorPersistenceConnector persistence = getPersistenceConnector(context);
+ if (persistence != null) {
persistence.close();
- persistenceConnectors.remove(scope);
+ persistenceConnectors.remove(context);
+ if(persistenceConnectors.isEmpty()) {
+
+ }
}
}
+ public static void closeAll() {
+ for (String context : persistenceConnectors.keySet()) {
+ try {
+ closePersistenceConnector(context);
+ } catch (Exception e) {
+ logger.error("Unable to close {} for context {}",
+ SmartExecutorPersistenceConnector.class.getSimpleName(), context);
+ }
+ }
+ }
+
+ public static void shutdown() {
+ OrientDBPersistenceConnector.shutdown();
+ }
+
}
diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/orientdb/OrientDBPersistenceConnector.java b/src/main/java/org/gcube/vremanagement/executor/persistence/orientdb/OrientDBPersistenceConnector.java
index 8f76ec0..42d4474 100644
--- a/src/main/java/org/gcube/vremanagement/executor/persistence/orientdb/OrientDBPersistenceConnector.java
+++ b/src/main/java/org/gcube/vremanagement/executor/persistence/orientdb/OrientDBPersistenceConnector.java
@@ -24,6 +24,7 @@ import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.db.ODatabasePool;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.record.impl.ODocument;
@@ -37,10 +38,10 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
private static final Logger logger = LoggerFactory.getLogger(OrientDBPersistenceConnector.class);
- protected final String SCOPE = "scope";
- protected final String UUID = "uuid";
- protected final String ITERATION = "iteration";
- protected final String TIMESTAMP = "timestamp";
+ protected final static String CONTEXT = "context";
+ protected final static String UUID = "uuid";
+ protected final static String ITERATION = "iteration";
+ protected final static String TIMESTAMP = "timestamp";
protected final String RUN_ON = "runOn";
@@ -52,6 +53,8 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
}
protected void prepareConnection(SmartExecutorPersistenceConfiguration configuration) throws Exception {
+ Orient.instance().removeShutdownHook();
+
logger.debug("Preparing Connection for {}", this.getClass().getSimpleName());
String url = configuration.getURL();
String username = configuration.getUsername();
@@ -63,6 +66,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
@Override
public void close() throws Exception {
oDatabasePool.close();
+ oDatabasePool = null;
}
@Override
@@ -74,13 +78,13 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
String type = PluginStateEvolution.class.getSimpleName();
Map params = new HashMap();
params.put(UUID, uuid.toString());
- params.put(SCOPE, ContextUtility.getCurrentScope());
+ params.put(CONTEXT, ContextUtility.getCurrentContext());
OSQLSynchQuery query = null;
if(iterationNumber != null && iterationNumber > 0) {
query = new OSQLSynchQuery(String.format(
- "SELECT FROM %s WHERE %s = :%s AND %s = :%s AND %s = :%s ORDER BY %s DESC LIMIT 1", type, SCOPE,
- SCOPE, UUID, UUID, ITERATION, ITERATION, TIMESTAMP));
+ "SELECT FROM %s WHERE %s = :%s AND %s = :%s AND %s = :%s ORDER BY %s DESC LIMIT 1", type, CONTEXT,
+ CONTEXT, UUID, UUID, ITERATION, ITERATION, TIMESTAMP));
params.put(ITERATION, iterationNumber);
} else {
/*
@@ -91,7 +95,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
*/
query = new OSQLSynchQuery(
String.format("SELECT FROM %s WHERE %s = :%s AND %s = :%s ORDER BY %s DESC, %s DESC LIMIT 1",
- type, SCOPE, SCOPE, UUID, UUID, ITERATION, TIMESTAMP));
+ type, CONTEXT, CONTEXT, UUID, UUID, ITERATION, TIMESTAMP));
}
List result = query.execute(params);
@@ -123,9 +127,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} catch(Exception e) {
throw new PluginInstanceNotFoundException(uuid);
} finally {
- if(oDatabaseSession != null) {
- oDatabaseSession.close();
- }
+ closeDatabaseSession(oDatabaseSession);
}
}
@@ -137,7 +139,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
ODocument doc = new ODocument(PluginStateEvolution.class.getSimpleName());
String json = ExtendedSEMapper.getInstance().marshal(pluginStateEvolution);
doc.fromJSON(json);
- doc.field(SCOPE, ContextUtility.getCurrentScope());
+ doc.field(CONTEXT, ContextUtility.getCurrentContext());
doc.save();
oDatabaseSession.commit();
@@ -147,9 +149,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
}
throw e;
} finally {
- if(oDatabaseSession != null) {
- oDatabaseSession.close();
- }
+ closeDatabaseSession(oDatabaseSession);
}
}
@@ -175,9 +175,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
}
throw new SchedulePersistenceException(e);
} finally {
- if(oDatabaseSession != null) {
- oDatabaseSession.close();
- }
+ closeDatabaseSession(oDatabaseSession);
}
}
@@ -191,7 +189,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
String type = ScheduledTask.class.getSimpleName();
String queryString = String.format("SELECT * FROM %s WHERE %s = '%s'", type, "scope",
- ContextUtility.getCurrentScope());
+ ContextUtility.getCurrentContext());
if(plugins != null && plugins.size() != 0) {
boolean first = true;
for(String pluginName : plugins) {
@@ -233,9 +231,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} catch(Exception e) {
throw new SchedulePersistenceException(e);
} finally {
- if(oDatabaseSession != null) {
- oDatabaseSession.close();
- }
+ closeDatabaseSession(oDatabaseSession);
}
}
@@ -278,9 +274,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} catch(Exception e) {
throw new SchedulePersistenceException(e);
} finally {
- if(oDatabaseSession != null) {
- oDatabaseSession.close();
- }
+ closeDatabaseSession(oDatabaseSession);
}
}
@@ -303,9 +297,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
}
throw new SchedulePersistenceException(e);
} finally {
- if(oDatabaseSession != null) {
- oDatabaseSession.close();
- }
+ closeDatabaseSession(oDatabaseSession);
}
}
@@ -328,9 +320,14 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
}
throw new SchedulePersistenceException(e);
} finally {
- if(oDatabaseSession != null) {
- oDatabaseSession.close();
- }
+ closeDatabaseSession(oDatabaseSession);
+ }
+ }
+
+ private void closeDatabaseSession(ODatabaseSession oDatabaseSession) {
+ if(oDatabaseSession != null) {
+ oDatabaseSession.close();
+ oDatabaseSession = null;
}
}
@@ -338,4 +335,9 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
public void releaseScheduledTask(ScheduledTask scheduledTask) throws SchedulePersistenceException {
releaseScheduledTask(scheduledTask.getUUID());
}
+
+ public static void shutdown(){
+ //Orient.OShutdownOrientDBInstancesHandler.
+ Orient.instance().shutdown();
+ }
}
diff --git a/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTask.java b/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTask.java
index fefadf6..ca28ea9 100644
--- a/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTask.java
+++ b/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTask.java
@@ -28,7 +28,7 @@ import org.gcube.vremanagement.executor.plugin.RunOn;
public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.ScheduledTask {
protected String token;
- protected String scope;
+ protected String context;
protected ClientInfo clientInfo;
protected ScheduledTask() {
@@ -42,7 +42,7 @@ public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.Sched
this.uuid = uuid;
this.launchParameter = launchParameter;
this.token = SecurityTokenProvider.instance.get();
- this.scope = ContextUtility.getCurrentScope();
+ this.context = ContextUtility.getCurrentContext();
this.clientInfo = ContextUtility.getClientInfo();
this.runOn = runOn;
}
@@ -57,8 +57,8 @@ public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.Sched
/**
* @return the scope
*/
- public String getScope() {
- return scope;
+ public String getContext() {
+ return context;
}
/**
@@ -109,7 +109,7 @@ public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.Sched
try {
return ExtendedSEMapper.getInstance().marshal(this);
} catch(Exception e) {
- return "ScheduledTask [token=" + token + ", scope=" + scope + ", clientInfo=" + clientInfo + ", uuid="
+ return "ScheduledTask [token=" + token + ", context=" + context + ", clientInfo=" + clientInfo + ", uuid="
+ uuid + ", launchParameter=" + launchParameter + ", runOn=" + runOn + "]";
}
}
diff --git a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java
index a15753b..9a5e213 100644
--- a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java
+++ b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java
@@ -49,7 +49,7 @@ public class SmartExecutorScheduler {
private static Logger logger = LoggerFactory.getLogger(SmartExecutorScheduler.class);
protected Set scheduledJobs;
- protected final Scheduler scheduler;
+ protected Scheduler scheduler;
SmartExecutorScheduler(Scheduler scheduler) throws SchedulerException {
this.scheduler = scheduler;
@@ -319,6 +319,7 @@ public class SmartExecutorScheduler {
}
scheduler.clear();
scheduler.shutdown();
+ scheduler = null;
}
}
diff --git a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorSchedulerFactory.java b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorSchedulerFactory.java
index 7628526..914b829 100644
--- a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorSchedulerFactory.java
+++ b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorSchedulerFactory.java
@@ -25,27 +25,27 @@ public class SmartExecutorSchedulerFactory {
smartExecutorSchedulers = new HashMap<>();
}
- private static SmartExecutorScheduler getSmartExecutorScheduler(String scope) throws SchedulerException {
- if(scope==null){
- String error = "No Scope available.";
+ private static SmartExecutorScheduler getSmartExecutorScheduler(String context) throws SchedulerException {
+ if(context==null){
+ String error = "No context available.";
logger.error(error);
throw new RuntimeException(error);
}
logger.trace("Retrieving {} for scope {}",
- SmartExecutorPersistenceConnector.class.getSimpleName(), scope);
+ SmartExecutorPersistenceConnector.class.getSimpleName(), context);
- SmartExecutorScheduler smartExecutorScheduler = smartExecutorSchedulers.get(scope);
+ SmartExecutorScheduler smartExecutorScheduler = smartExecutorSchedulers.get(context);
if(smartExecutorScheduler==null){
logger.trace("Retrieving {} for scope {} not found on internal {}. Intializing it.",
SmartExecutorScheduler.class.getSimpleName(),
- scope, Map.class.getSimpleName());
+ context, Map.class.getSimpleName());
Scheduler scheduler = schedulerFactory.getScheduler();
smartExecutorScheduler = new SmartExecutorScheduler(scheduler);
- smartExecutorSchedulers.put(ContextUtility.getCurrentScope(),
+ smartExecutorSchedulers.put(ContextUtility.getCurrentContext(),
smartExecutorScheduler);
}
@@ -57,13 +57,13 @@ public class SmartExecutorSchedulerFactory {
* @throws SchedulerException
*/
public static synchronized SmartExecutorScheduler getSmartExecutorScheduler() throws SchedulerException {
- String scope = ContextUtility.getCurrentScope();
- return getSmartExecutorScheduler(scope);
+ String context = ContextUtility.getCurrentContext();
+ return getSmartExecutorScheduler(context);
}
- public static void remove(){
- String scope = ContextUtility.getCurrentScope();
- smartExecutorSchedulers.remove(scope);
+ public static void removeCurrentSmartExecutorScheduler(){
+ String context = ContextUtility.getCurrentContext();
+ smartExecutorSchedulers.remove(context);
}
}
diff --git a/src/test/java/org/gcube/vremanagement/executor/SmartExecutorInizializatorTest.java b/src/test/java/org/gcube/vremanagement/executor/SmartExecutorInizializatorTest.java
index 8d34e7f..7357142 100644
--- a/src/test/java/org/gcube/vremanagement/executor/SmartExecutorInizializatorTest.java
+++ b/src/test/java/org/gcube/vremanagement/executor/SmartExecutorInizializatorTest.java
@@ -67,11 +67,11 @@ public class SmartExecutorInizializatorTest {
for (ServiceEndpoint serviceEndpoint : serviceEndpoints) {
try {
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} ({}) from scope {}",
- serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentScope());
+ serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentContext());
// unPublishResource(serviceEndpoint);
} catch(Exception e){
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} ({}) from scope {}",
- serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentScope(), e);
+ serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentContext(), e);
}
}
}catch(Exception e){
diff --git a/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java b/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java
index eb5269e..171299b 100644
--- a/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java
+++ b/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java
@@ -35,7 +35,7 @@ public class SmartExecutorPersistenceConnectorTest extends ContextTest {
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
Assert.assertNotNull(persistenceConnector);
Assert.assertEquals(OrientDBPersistenceConnector.class, persistenceConnector.getClass());
- SmartExecutorPersistenceFactory.closePersistenceConnector();
+ SmartExecutorPersistenceFactory.closeCurrentPersistenceConnector();
}
@Test
@@ -65,7 +65,7 @@ public class SmartExecutorPersistenceConnectorTest extends ContextTest {
PluginState ps = pse.getPluginState();
Assert.assertEquals(states[states.length-1], ps);
- SmartExecutorPersistenceFactory.closePersistenceConnector();
+ SmartExecutorPersistenceFactory.closeCurrentPersistenceConnector();
}
@Test