Switched to gCube Jackson and Moving to new resource-registry
This commit is contained in:
parent
44b6e6e237
commit
89b7c3013f
2
pom.xml
2
pom.xml
|
@ -33,7 +33,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.1.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<ScheduledTask> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public class SmartExecutorPersistenceConfiguration {
|
|||
List<ServiceEndpoint> 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);
|
||||
|
|
|
@ -18,58 +18,75 @@ import org.slf4j.LoggerFactory;
|
|||
public abstract class SmartExecutorPersistenceFactory {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SmartExecutorPersistenceFactory.class);
|
||||
|
||||
|
||||
private static Map<String, SmartExecutorPersistenceConnector> persistenceConnectors;
|
||||
|
||||
|
||||
static {
|
||||
persistenceConnectors = new HashMap<String, SmartExecutorPersistenceConnector>();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String,Object> params = new HashMap<String,Object>();
|
||||
params.put(UUID, uuid.toString());
|
||||
params.put(SCOPE, ContextUtility.getCurrentScope());
|
||||
params.put(CONTEXT, ContextUtility.getCurrentContext());
|
||||
|
||||
OSQLSynchQuery<ODocument> query = null;
|
||||
if(iterationNumber != null && iterationNumber > 0) {
|
||||
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,
|
||||
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<ODocument>(
|
||||
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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class SmartExecutorScheduler {
|
|||
private static Logger logger = LoggerFactory.getLogger(SmartExecutorScheduler.class);
|
||||
|
||||
protected Set<UUID> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue