Switched to gCube Jackson and Moving to new resource-registry

This commit is contained in:
Luca Frosini 2020-12-02 11:22:48 +01:00
parent 44b6e6e237
commit 89b7c3013f
12 changed files with 141 additions and 121 deletions

View File

@ -33,7 +33,7 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId> <artifactId>gcube-smartgears-bom</artifactId>
<version>2.0.0-SNAPSHOT</version> <version>2.1.0</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>

View File

@ -20,7 +20,7 @@ public class ContextUtility {
private static Logger logger = LoggerFactory.getLogger(ContextUtility.class); private static Logger logger = LoggerFactory.getLogger(ContextUtility.class);
public static String getCurrentScope() { public static String getCurrentContext() {
String token = SecurityTokenProvider.instance.get(); String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry; AuthorizationEntry authorizationEntry;
try { try {
@ -36,7 +36,7 @@ public class ContextUtility {
return context; 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); AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext(); String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context); logger.info("Context of token {} is {}", token, context);
@ -45,7 +45,7 @@ public class ContextUtility {
public static void setContext(String token) throws ObjectNotFound, Exception { public static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token); SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(getCurrentScope(token)); ScopeProvider.instance.set(getCurrentContext(token));
} }
public static ClientInfo getClientInfo() { public static ClientInfo getClientInfo() {

View File

@ -42,13 +42,13 @@ public class SmartExecutorInitializator implements ApplicationManager {
*/ */
@Override @Override
public void onInit() { public void onInit() {
String scope = ContextUtility.getCurrentScope(); String context = ContextUtility.getCurrentContext();
logger.trace( logger.trace(
"\n-------------------------------------------------------\n" "\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"); logger.debug("Getting Available Plugins and their own supported capabilities");
@ -68,9 +68,9 @@ public class SmartExecutorInitializator implements ApplicationManager {
isPublisher.publishPlugins(availablePlugins); isPublisher.publishPlugins(availablePlugins);
}catch (Exception e) { }catch (Exception e) {
if(isPublisher instanceof RestISPublisher) { 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 { } 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); throw new RuntimeException(e);
} }
} }
@ -83,7 +83,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
smartExecutorPersistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); smartExecutorPersistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to instantiate {} for scope {}. The Service will be aborted", 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); throw new RuntimeException(e);
} }
@ -91,11 +91,11 @@ public class SmartExecutorInitializator implements ApplicationManager {
// Persistence to clean previous situation of a failure of HostingNode // Persistence to clean previous situation of a failure of HostingNode
try { try {
logger.debug("Going to get Orphan Scheduled Tasks in scope {}", scope); logger.debug("Going to get Orphan Scheduled Tasks in scope {}", context);
List<ScheduledTask> scheduledTasks = smartExecutorPersistenceConnector.getOrphanScheduledTasks(pluginManager.getAvailablePlugins().keySet()); List<ScheduledTask> scheduledTasks = smartExecutorPersistenceConnector.getOrphanScheduledTasks(pluginManager.getAvailablePlugins().keySet());
if(scheduledTasks.size()==0){ 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){ for(final ScheduledTask scheduledTask : scheduledTasks){
@ -106,7 +106,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
// Reserving the task. // Reserving the task.
smartExecutorPersistenceConnector.reserveScheduledTask(scheduledTask); smartExecutorPersistenceConnector.reserveScheduledTask(scheduledTask);
}catch (Exception e) { }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; continue;
} }
@ -117,7 +117,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
LaunchParameter launchParameter = scheduledTask.getLaunchParameter(); LaunchParameter launchParameter = scheduledTask.getLaunchParameter();
try { 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)); ExtendedSEMapper.getInstance().marshal(launchParameter));
} catch (Exception e1) { } catch (Exception e1) {
@ -132,11 +132,11 @@ public class SmartExecutorInitializator implements ApplicationManager {
smartExecutorPersistenceConnector.removeScheduledTask(scheduledTask); smartExecutorPersistenceConnector.removeScheduledTask(scheduledTask);
smartExecutorScheduler.schedule(launchParameter, scheduledTask.getUUID()); smartExecutorScheduler.schedule(launchParameter, scheduledTask.getUUID());
} catch (Exception e) { } 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 { try {
smartExecutorPersistenceConnector.addScheduledTask(scheduledTask); smartExecutorPersistenceConnector.addScheduledTask(scheduledTask);
} catch (Exception ex) { } 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) { } 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; return;
} }
logger.trace( logger.trace(
"\n-------------------------------------------------------\n" "\n-------------------------------------------------------\n"
+ "Smart Executor Started Successfully on scope {}\n" + "Smart Executor Started Successfully on context {}\n"
+ "-------------------------------------------------------", scope); + "-------------------------------------------------------", context);
} }
@ -172,16 +172,16 @@ public class SmartExecutorInitializator implements ApplicationManager {
logger.trace( logger.trace(
"\n-------------------------------------------------------\n" "\n-------------------------------------------------------\n"
+ "Smart Executor is Stopping on scope {}\n" + "Smart Executor is Stopping on context {}\n"
+ "-------------------------------------------------------", + "-------------------------------------------------------",
ContextUtility.getCurrentScope()); ContextUtility.getCurrentContext());
SmartExecutorScheduler scheduler; SmartExecutorScheduler scheduler;
try { try {
scheduler = SmartExecutorSchedulerFactory.getSmartExecutorScheduler(); scheduler = SmartExecutorSchedulerFactory.getSmartExecutorScheduler();
scheduler.stopAll(); scheduler.stopAll();
SmartExecutorSchedulerFactory.remove(); SmartExecutorSchedulerFactory.removeCurrentSmartExecutorScheduler();
} catch (SchedulerException e) { } catch (SchedulerException e) {
logger.error("", e); logger.error("", e);
} }
@ -192,22 +192,22 @@ public class SmartExecutorInitializator implements ApplicationManager {
try { try {
isPublisher.unpublishPlugins(false); isPublisher.unpublishPlugins(false);
}catch (Exception e) { }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 { try {
SmartExecutorPersistenceFactory.closePersistenceConnector(); SmartExecutorPersistenceFactory.closeCurrentPersistenceConnector();
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Unable to correctly close {} for scope {}", logger.error("Unable to correctly close {} for context {}",
SmartExecutorPersistenceConnector.class.getSimpleName(), SmartExecutorPersistenceConnector.class.getSimpleName(),
ContextUtility.getCurrentScope(), e); ContextUtility.getCurrentContext(), e);
} }
logger.trace( logger.trace(
"\n-------------------------------------------------------\n" "\n-------------------------------------------------------\n"
+ "Smart Executor Stopped Successfully on scope {}\n" + "Smart Executor Stopped Successfully on context {}\n"
+ "-------------------------------------------------------", + "-------------------------------------------------------",
ContextUtility.getCurrentScope()); ContextUtility.getCurrentContext());
} }
} }

View File

@ -53,7 +53,7 @@ public class GCoreISPublisher extends ISPublisher {
RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
try { try {
logger.debug("Trying to publish to {}:\n{}", ContextUtility.getCurrentScope(), stringWriter); logger.debug("Trying to publish to {}:\n{}", ContextUtility.getCurrentContext(), 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);
@ -75,7 +75,7 @@ public class GCoreISPublisher extends ISPublisher {
String id = resource.id(); String id = resource.id();
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id,
ContextUtility.getCurrentScope()); ContextUtility.getCurrentContext());
registryPublisher.remove(resource); registryPublisher.remove(resource);
@ -218,11 +218,11 @@ public class GCoreISPublisher extends ISPublisher {
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(), ContextUtility.getCurrentScope()); serviceEndpoint.id(), ContextUtility.getCurrentContext());
unPublishResource(serviceEndpoint); unPublishResource(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(), ContextUtility.getCurrentScope(), e); serviceEndpoint.id(), ContextUtility.getCurrentContext(), e);
} }
} }
} catch(Exception e) { } catch(Exception e) {
@ -238,7 +238,7 @@ public class GCoreISPublisher extends ISPublisher {
publishResource(serviceEndpoint); publishResource(serviceEndpoint);
} catch(Exception e) { } catch(Exception e) {
logger.error("Unable to Create ServiceEndpoint for scope {}. The Service will be aborted", logger.error("Unable to Create ServiceEndpoint for scope {}. The Service will be aborted",
ContextUtility.getCurrentScope(), e); ContextUtility.getCurrentContext(), e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View File

@ -131,7 +131,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'", ContextUtility.getCurrentScope())); query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", ContextUtility.getCurrentContext()));
serviceEndpoints = client.submit(query); serviceEndpoints = client.submit(query);
} }
return serviceEndpoints.get(0); return serviceEndpoints.get(0);

View File

@ -18,58 +18,75 @@ import org.slf4j.LoggerFactory;
public abstract class SmartExecutorPersistenceFactory { public abstract class SmartExecutorPersistenceFactory {
private static final Logger logger = LoggerFactory.getLogger(SmartExecutorPersistenceFactory.class); private static final Logger logger = LoggerFactory.getLogger(SmartExecutorPersistenceFactory.class);
private static Map<String, SmartExecutorPersistenceConnector> persistenceConnectors; private static Map<String, SmartExecutorPersistenceConnector> persistenceConnectors;
static { static {
persistenceConnectors = new HashMap<String, SmartExecutorPersistenceConnector>(); persistenceConnectors = new HashMap<String, SmartExecutorPersistenceConnector>();
} }
private static SmartExecutorPersistenceConnector getPersistenceConnector(String scope) throws Exception { private static synchronized SmartExecutorPersistenceConnector getPersistenceConnector(String context) throws Exception {
if(scope==null){ if (context == null) {
String error = "No Scope available."; String error = "No Context available.";
logger.error(error); logger.error(error);
throw new RuntimeException(error); throw new RuntimeException(error);
} }
logger.trace("Retrieving {} for scope {}", logger.trace("Retrieving {} for context {}", SmartExecutorPersistenceConnector.class.getSimpleName(), context);
SmartExecutorPersistenceConnector.class.getSimpleName(), scope);
SmartExecutorPersistenceConnector persistence = persistenceConnectors.get(context);
SmartExecutorPersistenceConnector persistence = persistenceConnectors.get(scope);
if (persistence == null) {
if(persistence==null){ logger.trace("Retrieving {} for context {} not found on internal {}. Intializing it.",
logger.trace("Retrieving {} for scope {} not found on internal {}. Intializing it.", SmartExecutorPersistenceConnector.class.getSimpleName(), context, Map.class.getSimpleName());
SmartExecutorPersistenceConnector.class.getSimpleName(),
scope, Map.class.getSimpleName());
String className = OrientDBPersistenceConnector.class.getSimpleName(); String className = OrientDBPersistenceConnector.class.getSimpleName();
SmartExecutorPersistenceConfiguration configuration = SmartExecutorPersistenceConfiguration configuration = new SmartExecutorPersistenceConfiguration(className);
new SmartExecutorPersistenceConfiguration(className);
persistence = new OrientDBPersistenceConnector(configuration); persistence = new OrientDBPersistenceConnector(configuration);
persistenceConnectors.put(ContextUtility.getCurrentScope(), persistenceConnectors.put(ContextUtility.getCurrentContext(), persistence);
persistence);
} }
return persistence; return persistence;
} }
/** /**
* @return the persistenceConnector * @return the persistenceConnector
*/ */
public static synchronized SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception { public static SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception {
String scope = ContextUtility.getCurrentScope(); String context = ContextUtility.getCurrentContext();
return getPersistenceConnector(scope); return getPersistenceConnector(context);
} }
public static synchronized void closePersistenceConnector() throws Exception { public static void closeCurrentPersistenceConnector() throws Exception {
String scope = ContextUtility.getCurrentScope(); String context = ContextUtility.getCurrentContext();
SmartExecutorPersistenceConnector persistence = closePersistenceConnector(context);
getPersistenceConnector(scope); }
if(persistence!=null){
private static synchronized void closePersistenceConnector(String context) throws Exception {
SmartExecutorPersistenceConnector persistence = getPersistenceConnector(context);
if (persistence != null) {
persistence.close(); 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();
}
} }

View File

@ -24,6 +24,7 @@ import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.db.ODatabasePool; import com.orientechnologies.orient.core.db.ODatabasePool;
import com.orientechnologies.orient.core.db.ODatabaseSession; import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.record.impl.ODocument; 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); private static final Logger logger = LoggerFactory.getLogger(OrientDBPersistenceConnector.class);
protected final String SCOPE = "scope"; protected final static String CONTEXT = "context";
protected final String UUID = "uuid"; protected final static String UUID = "uuid";
protected final String ITERATION = "iteration"; protected final static String ITERATION = "iteration";
protected final String TIMESTAMP = "timestamp"; protected final static String TIMESTAMP = "timestamp";
protected final String RUN_ON = "runOn"; protected final String RUN_ON = "runOn";
@ -52,6 +53,8 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} }
protected void prepareConnection(SmartExecutorPersistenceConfiguration configuration) throws Exception { protected void prepareConnection(SmartExecutorPersistenceConfiguration configuration) throws Exception {
Orient.instance().removeShutdownHook();
logger.debug("Preparing Connection for {}", this.getClass().getSimpleName()); logger.debug("Preparing Connection for {}", this.getClass().getSimpleName());
String url = configuration.getURL(); String url = configuration.getURL();
String username = configuration.getUsername(); String username = configuration.getUsername();
@ -63,6 +66,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
@Override @Override
public void close() throws Exception { public void close() throws Exception {
oDatabasePool.close(); oDatabasePool.close();
oDatabasePool = null;
} }
@Override @Override
@ -74,13 +78,13 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
String type = PluginStateEvolution.class.getSimpleName(); String type = PluginStateEvolution.class.getSimpleName();
Map<String,Object> params = new HashMap<String,Object>(); Map<String,Object> params = new HashMap<String,Object>();
params.put(UUID, uuid.toString()); params.put(UUID, uuid.toString());
params.put(SCOPE, ContextUtility.getCurrentScope()); params.put(CONTEXT, ContextUtility.getCurrentContext());
OSQLSynchQuery<ODocument> query = null; OSQLSynchQuery<ODocument> query = null;
if(iterationNumber != null && iterationNumber > 0) { if(iterationNumber != null && iterationNumber > 0) {
query = new OSQLSynchQuery<ODocument>(String.format( query = new OSQLSynchQuery<ODocument>(String.format(
"SELECT FROM %s WHERE %s = :%s AND %s = :%s AND %s = :%s ORDER BY %s DESC LIMIT 1", type, SCOPE, "SELECT FROM %s WHERE %s = :%s AND %s = :%s AND %s = :%s ORDER BY %s DESC LIMIT 1", type, CONTEXT,
SCOPE, UUID, UUID, ITERATION, ITERATION, TIMESTAMP)); CONTEXT, UUID, UUID, ITERATION, ITERATION, TIMESTAMP));
params.put(ITERATION, iterationNumber); params.put(ITERATION, iterationNumber);
} else { } else {
/* /*
@ -91,7 +95,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
*/ */
query = new OSQLSynchQuery<ODocument>( query = new OSQLSynchQuery<ODocument>(
String.format("SELECT FROM %s WHERE %s = :%s AND %s = :%s ORDER BY %s DESC, %s DESC LIMIT 1", 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<ODocument> result = query.execute(params); List<ODocument> result = query.execute(params);
@ -123,9 +127,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} catch(Exception e) { } catch(Exception e) {
throw new PluginInstanceNotFoundException(uuid); throw new PluginInstanceNotFoundException(uuid);
} finally { } finally {
if(oDatabaseSession != null) { closeDatabaseSession(oDatabaseSession);
oDatabaseSession.close();
}
} }
} }
@ -137,7 +139,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
ODocument doc = new ODocument(PluginStateEvolution.class.getSimpleName()); ODocument doc = new ODocument(PluginStateEvolution.class.getSimpleName());
String json = ExtendedSEMapper.getInstance().marshal(pluginStateEvolution); String json = ExtendedSEMapper.getInstance().marshal(pluginStateEvolution);
doc.fromJSON(json); doc.fromJSON(json);
doc.field(SCOPE, ContextUtility.getCurrentScope()); doc.field(CONTEXT, ContextUtility.getCurrentContext());
doc.save(); doc.save();
oDatabaseSession.commit(); oDatabaseSession.commit();
@ -147,9 +149,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} }
throw e; throw e;
} finally { } finally {
if(oDatabaseSession != null) { closeDatabaseSession(oDatabaseSession);
oDatabaseSession.close();
}
} }
} }
@ -175,9 +175,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} }
throw new SchedulePersistenceException(e); throw new SchedulePersistenceException(e);
} finally { } finally {
if(oDatabaseSession != null) { closeDatabaseSession(oDatabaseSession);
oDatabaseSession.close();
}
} }
} }
@ -191,7 +189,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
String type = ScheduledTask.class.getSimpleName(); String type = ScheduledTask.class.getSimpleName();
String queryString = String.format("SELECT * FROM %s WHERE %s = '%s'", type, "scope", String queryString = String.format("SELECT * FROM %s WHERE %s = '%s'", type, "scope",
ContextUtility.getCurrentScope()); ContextUtility.getCurrentContext());
if(plugins != null && plugins.size() != 0) { if(plugins != null && plugins.size() != 0) {
boolean first = true; boolean first = true;
for(String pluginName : plugins) { for(String pluginName : plugins) {
@ -233,9 +231,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} catch(Exception e) { } catch(Exception e) {
throw new SchedulePersistenceException(e); throw new SchedulePersistenceException(e);
} finally { } finally {
if(oDatabaseSession != null) { closeDatabaseSession(oDatabaseSession);
oDatabaseSession.close();
}
} }
} }
@ -278,9 +274,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} catch(Exception e) { } catch(Exception e) {
throw new SchedulePersistenceException(e); throw new SchedulePersistenceException(e);
} finally { } finally {
if(oDatabaseSession != null) { closeDatabaseSession(oDatabaseSession);
oDatabaseSession.close();
}
} }
} }
@ -303,9 +297,7 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} }
throw new SchedulePersistenceException(e); throw new SchedulePersistenceException(e);
} finally { } finally {
if(oDatabaseSession != null) { closeDatabaseSession(oDatabaseSession);
oDatabaseSession.close();
}
} }
} }
@ -328,9 +320,14 @@ public class OrientDBPersistenceConnector extends SmartExecutorPersistenceConnec
} }
throw new SchedulePersistenceException(e); throw new SchedulePersistenceException(e);
} finally { } finally {
if(oDatabaseSession != null) { closeDatabaseSession(oDatabaseSession);
oDatabaseSession.close(); }
} }
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 { public void releaseScheduledTask(ScheduledTask scheduledTask) throws SchedulePersistenceException {
releaseScheduledTask(scheduledTask.getUUID()); releaseScheduledTask(scheduledTask.getUUID());
} }
public static void shutdown(){
//Orient.OShutdownOrientDBInstancesHandler.
Orient.instance().shutdown();
}
} }

View File

@ -28,7 +28,7 @@ import org.gcube.vremanagement.executor.plugin.RunOn;
public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.ScheduledTask { public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.ScheduledTask {
protected String token; protected String token;
protected String scope; protected String context;
protected ClientInfo clientInfo; protected ClientInfo clientInfo;
protected ScheduledTask() { protected ScheduledTask() {
@ -42,7 +42,7 @@ public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.Sched
this.uuid = uuid; this.uuid = uuid;
this.launchParameter = launchParameter; this.launchParameter = launchParameter;
this.token = SecurityTokenProvider.instance.get(); this.token = SecurityTokenProvider.instance.get();
this.scope = ContextUtility.getCurrentScope(); this.context = ContextUtility.getCurrentContext();
this.clientInfo = ContextUtility.getClientInfo(); this.clientInfo = ContextUtility.getClientInfo();
this.runOn = runOn; this.runOn = runOn;
} }
@ -57,8 +57,8 @@ public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.Sched
/** /**
* @return the scope * @return the scope
*/ */
public String getScope() { public String getContext() {
return scope; return context;
} }
/** /**
@ -109,7 +109,7 @@ public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.Sched
try { try {
return ExtendedSEMapper.getInstance().marshal(this); return ExtendedSEMapper.getInstance().marshal(this);
} catch(Exception e) { } 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 + "]"; + uuid + ", launchParameter=" + launchParameter + ", runOn=" + runOn + "]";
} }
} }

View File

@ -49,7 +49,7 @@ public class SmartExecutorScheduler {
private static Logger logger = LoggerFactory.getLogger(SmartExecutorScheduler.class); private static Logger logger = LoggerFactory.getLogger(SmartExecutorScheduler.class);
protected Set<UUID> scheduledJobs; protected Set<UUID> scheduledJobs;
protected final Scheduler scheduler; protected Scheduler scheduler;
SmartExecutorScheduler(Scheduler scheduler) throws SchedulerException { SmartExecutorScheduler(Scheduler scheduler) throws SchedulerException {
this.scheduler = scheduler; this.scheduler = scheduler;
@ -319,6 +319,7 @@ public class SmartExecutorScheduler {
} }
scheduler.clear(); scheduler.clear();
scheduler.shutdown(); scheduler.shutdown();
scheduler = null;
} }
} }

View File

@ -25,27 +25,27 @@ public class SmartExecutorSchedulerFactory {
smartExecutorSchedulers = new HashMap<>(); smartExecutorSchedulers = new HashMap<>();
} }
private static SmartExecutorScheduler getSmartExecutorScheduler(String scope) throws SchedulerException { private static SmartExecutorScheduler getSmartExecutorScheduler(String context) throws SchedulerException {
if(scope==null){ if(context==null){
String error = "No Scope available."; String error = "No context available.";
logger.error(error); logger.error(error);
throw new RuntimeException(error); throw new RuntimeException(error);
} }
logger.trace("Retrieving {} for scope {}", 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){ if(smartExecutorScheduler==null){
logger.trace("Retrieving {} for scope {} not found on internal {}. Intializing it.", logger.trace("Retrieving {} for scope {} not found on internal {}. Intializing it.",
SmartExecutorScheduler.class.getSimpleName(), SmartExecutorScheduler.class.getSimpleName(),
scope, Map.class.getSimpleName()); context, Map.class.getSimpleName());
Scheduler scheduler = schedulerFactory.getScheduler(); Scheduler scheduler = schedulerFactory.getScheduler();
smartExecutorScheduler = new SmartExecutorScheduler(scheduler); smartExecutorScheduler = new SmartExecutorScheduler(scheduler);
smartExecutorSchedulers.put(ContextUtility.getCurrentScope(), smartExecutorSchedulers.put(ContextUtility.getCurrentContext(),
smartExecutorScheduler); smartExecutorScheduler);
} }
@ -57,13 +57,13 @@ public class SmartExecutorSchedulerFactory {
* @throws SchedulerException * @throws SchedulerException
*/ */
public static synchronized SmartExecutorScheduler getSmartExecutorScheduler() throws SchedulerException { public static synchronized SmartExecutorScheduler getSmartExecutorScheduler() throws SchedulerException {
String scope = ContextUtility.getCurrentScope(); String context = ContextUtility.getCurrentContext();
return getSmartExecutorScheduler(scope); return getSmartExecutorScheduler(context);
} }
public static void remove(){ public static void removeCurrentSmartExecutorScheduler(){
String scope = ContextUtility.getCurrentScope(); String context = ContextUtility.getCurrentContext();
smartExecutorSchedulers.remove(scope); smartExecutorSchedulers.remove(context);
} }
} }

View File

@ -67,11 +67,11 @@ public class SmartExecutorInizializatorTest {
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(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentScope()); serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentContext());
// unPublishResource(serviceEndpoint); // unPublishResource(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(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentScope(), e); serviceEndpoint.id(), serviceEndpoint.profile().runtime().hostedOn(), ContextUtility.getCurrentContext(), e);
} }
} }
}catch(Exception e){ }catch(Exception e){

View File

@ -35,7 +35,7 @@ public class SmartExecutorPersistenceConnectorTest extends ContextTest {
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
Assert.assertNotNull(persistenceConnector); Assert.assertNotNull(persistenceConnector);
Assert.assertEquals(OrientDBPersistenceConnector.class, persistenceConnector.getClass()); Assert.assertEquals(OrientDBPersistenceConnector.class, persistenceConnector.getClass());
SmartExecutorPersistenceFactory.closePersistenceConnector(); SmartExecutorPersistenceFactory.closeCurrentPersistenceConnector();
} }
@Test @Test
@ -65,7 +65,7 @@ public class SmartExecutorPersistenceConnectorTest extends ContextTest {
PluginState ps = pse.getPluginState(); PluginState ps = pse.getPluginState();
Assert.assertEquals(states[states.length-1], ps); Assert.assertEquals(states[states.length-1], ps);
SmartExecutorPersistenceFactory.closePersistenceConnector(); SmartExecutorPersistenceFactory.closeCurrentPersistenceConnector();
} }
@Test @Test