From 7d2f4c450d9a73fc1e97c3305641405839343ef4 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 12 Oct 2015 16:33:47 +0000 Subject: [PATCH] Fixing lifecycle management git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@119638 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../executor/SmartExecutorImpl.java | 16 +- .../executor/SmartExecutorInitializator.java | 166 +++++++++--------- .../ScheduledTaskConfigurationFactory.java | 4 +- .../FileScheduledTaskConfiguration.java | 4 +- .../SmartExecutorPersistenceConnector.java | 25 +-- .../SmartExecutorPersistenceFactory.java | 57 ++++++ .../PluginStateEvolutionObjectNode.java | 6 +- .../executor/scheduler/SmartExecutorJob.java | 4 +- .../scheduler/SmartExecutorScheduler.java | 4 +- ...SmartExecutorPersistenceConnectorTest.java | 4 +- .../pluginmanager/RunnablePluginTest.java | 11 +- .../SmartExecutorSchedulerTest.java | 3 +- 12 files changed, 176 insertions(+), 128 deletions(-) create mode 100644 src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceFactory.java diff --git a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorImpl.java b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorImpl.java index 8948004..5f2d728 100644 --- a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorImpl.java +++ b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorImpl.java @@ -4,6 +4,7 @@ import java.util.UUID; import javax.jws.WebService; +import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.vremanagement.executor.api.SmartExecutor; import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.exception.ExecutorException; @@ -14,6 +15,7 @@ import org.gcube.vremanagement.executor.exception.PluginNotFoundException; import org.gcube.vremanagement.executor.exception.SchedulePersistenceException; import org.gcube.vremanagement.executor.exception.SchedulerNotFoundException; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; +import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory; import org.gcube.vremanagement.executor.plugin.PluginState; import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler; import org.quartz.SchedulerException; @@ -36,6 +38,16 @@ public class SmartExecutorImpl implements SmartExecutor { */ private static Logger logger = LoggerFactory.getLogger(SmartExecutorImpl.class); + protected static ApplicationContext ctx; + + /** + * @return the ctx + */ + public static ApplicationContext getCtx() { + return ctx; + } + + /**{@inheritDoc}*/ @Override public String launch(LaunchParameter parameter) throws InputsNullException, @@ -76,7 +88,7 @@ public class SmartExecutorImpl implements SmartExecutor { public PluginState getState(String executionIdentifier) throws PluginInstanceNotFoundException, ExecutorException { try { - SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); return persistenceConnector.getLastPluginInstanceState(UUID.fromString(executionIdentifier)); } catch (Exception e) { throw new PluginInstanceNotFoundException(); @@ -88,7 +100,7 @@ public class SmartExecutorImpl implements SmartExecutor { public PluginState getIterationState(String executionIdentifier, int iterationNumber) throws PluginInstanceNotFoundException, ExecutorException { try { - SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); return persistenceConnector.getPluginInstanceState(UUID.fromString(executionIdentifier), iterationNumber); } catch (Exception e) { throw new PluginInstanceNotFoundException(); diff --git a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java index 9dd31e4..5aca0ae 100644 --- a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java +++ b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java @@ -6,8 +6,10 @@ package org.gcube.vremanagement.executor; import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.xml.bind.annotation.XmlRootElement; @@ -35,6 +37,7 @@ import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent; import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; +import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory; import org.gcube.vremanagement.executor.plugin.PluginDeclaration; import org.gcube.vremanagement.executor.pluginmanager.PluginManager; import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler; @@ -55,22 +58,24 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler { public static final long JOIN_TIMEOUT = 1000; - /** + /* * * Contains the ServiceEnpoint Resource to be published/unpublished on IS - */ + * / private static ServiceEndpoint serviceEndpoint; + */ - /** + /* * * The application context - */ + * / protected static ApplicationContext ctx; /** * @return the ctx - */ + * / public static ApplicationContext getCtx() { return ctx; } + */ /* protected static ScheduledTaskConfiguration launchConfiguration; @@ -179,17 +184,17 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler { protected static ServiceEndpoint createServiceEndpoint(){ logger.debug("Getting Available Plugins and their own supported capabilities"); PluginManager pluginManager = PluginManager.getInstance(); - + logger.debug("Creating ServiceEndpoint to publish on IS available plugins and their own supported capabilities"); ServiceEndpoint serviceEndpoint = new ServiceEndpoint(); Profile profile = serviceEndpoint.newProfile(); - profile.category(ctx.configuration().serviceClass()); - profile.name(ctx.configuration().name()); - String version = ctx.configuration().version(); + profile.category(SmartExecutorImpl.ctx.configuration().serviceClass()); + profile.name(SmartExecutorImpl.ctx.configuration().name()); + String version = SmartExecutorImpl.ctx.configuration().version(); profile.version(version); - profile.description(ctx.configuration().description()); + profile.description(SmartExecutorImpl.ctx.configuration().description()); - String runningOn = getRunningOn(ctx.container().configuration()); + String runningOn = getRunningOn(SmartExecutorImpl.ctx.container().configuration()); Platform platform = profile.newPlatform(); platform.name(runningOn); @@ -201,7 +206,7 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler { Runtime runtime = profile.newRuntime(); runtime.hostedOn(runningOn); - runtime.status(ctx.configuration().mode().toString()); + runtime.status(SmartExecutorImpl.ctx.configuration().mode().toString()); Group accessPoints = profile.accessPoints(); Map availablePlugins = pluginManager.getAvailablePlugins(); @@ -237,28 +242,55 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler { } public static List getScopes(ApplicationContext applicationContext){ + Collection scopes; ScopeGroup scopeGroup = applicationContext.profile(GCoreEndpoint.class).scopes(); - Collection scopes = scopeGroup.asCollection(); - - /* - Set applicationScopes = applicationContext.configuration().startScopes(); - Set containerScopes = applicationContext.container().configuration().startScopes(); - Set scopes; - if(applicationScopes==null || applicationScopes.isEmpty()){ - scopes = containerScopes; - logger.debug("Application Scopes ({}). The Container Scopes ({}) will be used.", applicationScopes, scopes); - } else{ - logger.debug("Container Scopes ({}). Application Scopes ({}) will be used.", containerScopes, applicationScopes); - scopes = new HashSet(applicationScopes); + if(scopeGroup==null || scopeGroup.isEmpty()){ + Set applicationScopes = applicationContext.configuration().startScopes(); + Set containerScopes = applicationContext.container().configuration().startScopes(); + + if(applicationScopes==null || applicationScopes.isEmpty()){ + scopes = containerScopes; + logger.debug("Application Scopes ({}). The Container Scopes ({}) will be used.", applicationScopes, scopes); + } else{ + logger.debug("Container Scopes ({}). Application Scopes ({}) will be used.", containerScopes, applicationScopes); + scopes = new HashSet(applicationScopes); + } + }else { + scopes = scopeGroup.asCollection(); } - **/ return new ArrayList(scopes); } - /** {@inheritDoc} */ - /* + private void cleanServiceEndpoints(String scope){ + try { + SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class) + .addCondition(String.format("$resource/Profile/Category/text() eq '%s'", SmartExecutorImpl.ctx.configuration().serviceClass())) + .addCondition(String.format("$resource/Profile/Name/text() eq '%s'", SmartExecutorImpl.ctx.configuration().name())) + .addCondition(String.format("$resource/Profile/RunTime/HostedOn/text() eq '%s'", getRunningOn(SmartExecutorImpl.ctx.container().configuration()))) + .setResult("$resource"); + + DiscoveryClient client = ICFactory.clientFor(ServiceEndpoint.class); + List serviceEndpoints = client.submit(query); + + for (ServiceEndpoint serviceEndpoint : serviceEndpoints) { + try { + logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}", + serviceEndpoint.id(), scope); + unPublishScopedResource(serviceEndpoint); + } catch(Exception e){ + logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}", + serviceEndpoint.id(), scope, e); + } + } + }catch(Exception e){ + logger.debug("An Exception occur while checking and/or unpublishing old ServiceEndpoint", e); + } + } + + /** + * {@inheritDoc} * The method discover the plugins available on classpath and their own * supported capabilities and publish a ServiceEndpoint with the * discovered information. @@ -271,41 +303,23 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler { + "Smart Executor is Starting\n" + "-------------------------------------------------------"); - ctx = applicationLifecycleEventStart.context(); + SmartExecutorImpl.ctx = applicationLifecycleEventStart.context(); - serviceEndpoint = createServiceEndpoint(); + ServiceEndpoint serviceEndpoint = createServiceEndpoint(); // Checking if there are old unpublished ServiceEndpoints related to // this vHN and trying to unpublish them - List scopes = getScopes(ctx); + List scopes = getScopes(SmartExecutorImpl.ctx); for(String scope : scopes){ - + ScopeProvider.instance.set(scope); + cleanServiceEndpoints(scope); try { - - ScopeProvider.instance.set(scope); - - SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class) - .addCondition(String.format("$resource/Profile/Category/text() eq '%s'", ctx.configuration().serviceClass())) - .addCondition(String.format("$resource/Profile/Name/text() eq '%s'", ctx.configuration().name())) - .addCondition(String.format("$resource/Profile/RunTime/HostedOn/text() eq '%s'", getRunningOn(ctx.container().configuration()))) - .setResult("$resource"); - - DiscoveryClient client = ICFactory.clientFor(ServiceEndpoint.class); - List serviceEndpoints = client.submit(query); - - for (ServiceEndpoint serviceEndpoint : serviceEndpoints) { - try { - logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}", - serviceEndpoint.id(), scope); - unPublishScopedResource(serviceEndpoint); - } catch(Exception e){ - logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}", - serviceEndpoint.id(), scope, e); - } - } - }catch(Exception e){ - logger.debug("An Exception occur while checking and/or unpublishing old ServiceEndpoint", e); + SmartExecutorPersistenceFactory.getPersistenceConnector(); + } catch (Exception e) { + logger.error("Unable to isntantiate {} for scope {}", + SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e); + throw new RuntimeException(e); } } @@ -321,28 +335,19 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler { logger.error("Unable to Create ServiceEndpoint. the Service will be aborted", e); return; } - - try { - SmartExecutorPersistenceConnector.getPersistenceConnector(); - } catch (Exception e) { - logger.error("Unable to initialize PersistenceConnector. The Service will be aborted", e); - return; - } + logger.trace( "\n-------------------------------------------------------\n" + "Smart Executor Started Successfully\n" + "-------------------------------------------------------"); - // TODO - // TODO // TODO Launch initializer thread - // TODO - // TODO + } - /** {@inheritDoc} */ - /* + /** + * {@inheritDoc} * This function is invoked before the service will stop and unpublish the * resource from the IS to maintain the infrastructure integrity. * Furthermore close the connection to DB. @@ -356,22 +361,17 @@ public class SmartExecutorInitializator extends ApplicationLifecycleHandler { SmartExecutorScheduler.getInstance().stopAll(); - try { - List scopes = getScopes(ctx); - for(String scope : scopes){ - ScopeProvider.instance.set(scope); - unPublishScopedResource(serviceEndpoint); - } - } catch (RegistryNotFoundException e) { - logger.error("Unable to unpublish Service Endpoint.", e); - } catch (Exception e) { - logger.error("Unable to unpublish Service Endpoint.", e); - } + List scopes = getScopes(SmartExecutorImpl.ctx); - try { - SmartExecutorPersistenceConnector.getPersistenceConnector().close(); - } catch (Exception e) { - logger.error("Unable to close Persistence", e); + for(String scope : scopes){ + ScopeProvider.instance.set(scope); + cleanServiceEndpoints(scope); + try { + SmartExecutorPersistenceFactory.getPersistenceConnector().close(); + } catch (Exception e) { + logger.error("Unable to correctly close {} for scope {}", + SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e); + } } logger.trace( diff --git a/src/main/java/org/gcube/vremanagement/executor/configuration/ScheduledTaskConfigurationFactory.java b/src/main/java/org/gcube/vremanagement/executor/configuration/ScheduledTaskConfigurationFactory.java index 5f7ccf8..32b0805 100644 --- a/src/main/java/org/gcube/vremanagement/executor/configuration/ScheduledTaskConfigurationFactory.java +++ b/src/main/java/org/gcube/vremanagement/executor/configuration/ScheduledTaskConfigurationFactory.java @@ -3,7 +3,7 @@ */ package org.gcube.vremanagement.executor.configuration; -import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; +import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ @@ -12,7 +12,7 @@ import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConn public class ScheduledTaskConfigurationFactory { public static ScheduledTaskConfiguration getLaunchConfiguration() throws Exception { - return (ScheduledTaskConfiguration) SmartExecutorPersistenceConnector.getPersistenceConnector(); + return (ScheduledTaskConfiguration) SmartExecutorPersistenceFactory.getPersistenceConnector(); } } diff --git a/src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileScheduledTaskConfiguration.java b/src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileScheduledTaskConfiguration.java index 23a14ed..aa43314 100644 --- a/src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileScheduledTaskConfiguration.java +++ b/src/main/java/org/gcube/vremanagement/executor/configuration/jsonbased/FileScheduledTaskConfiguration.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.UUID; import org.apache.commons.io.FileUtils; -import org.gcube.vremanagement.executor.SmartExecutorInitializator; +import org.gcube.vremanagement.executor.SmartExecutorImpl; import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration; @@ -44,7 +44,7 @@ public class FileScheduledTaskConfiguration implements ScheduledTaskConfiguratio public static final String CONFIG_TASK_FILENAME = "definedTasks.json"; public FileScheduledTaskConfiguration() throws Exception { - this(SmartExecutorInitializator.getCtx().persistence().location()); + this(SmartExecutorImpl.getCtx().persistence().location()); } public FileScheduledTaskConfiguration(String location) throws IOException, JSONException { diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnector.java b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnector.java index a1199e2..9d70800 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnector.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnector.java @@ -5,7 +5,6 @@ package org.gcube.vremanagement.executor.persistence; import java.util.UUID; -import org.gcube.vremanagement.executor.persistence.couchdb.CouchDBPersistenceConnector; import org.gcube.vremanagement.executor.plugin.Plugin; import org.gcube.vremanagement.executor.plugin.PluginState; import org.gcube.vremanagement.executor.plugin.PluginStateNotification; @@ -20,29 +19,7 @@ import org.gcube.vremanagement.executor.plugin.PluginStateNotification; */ public abstract class SmartExecutorPersistenceConnector implements PluginStateNotification { - protected static SmartExecutorPersistenceConnector persistenceConnector; - - /** - * @return the persistenceConnector - */ - public static synchronized SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception { - if(SmartExecutorPersistenceConnector.persistenceConnector==null){ - SmartExecutorPersistenceConfiguration configuration = - new SmartExecutorPersistenceConfiguration(CouchDBPersistenceConnector.class.getSimpleName()); - SmartExecutorPersistenceConnector.persistenceConnector = new CouchDBPersistenceConnector(configuration); - } - return SmartExecutorPersistenceConnector.persistenceConnector; - } - - /** - * @param persistenceConnector the persistenceConnector to set - */ - public static synchronized void setPersistenceConnector( - SmartExecutorPersistenceConnector persistenceConnector) { - SmartExecutorPersistenceConnector.persistenceConnector = persistenceConnector; - } - - /** + /** * Close the connection to DB * @throws Exception if fails */ diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceFactory.java b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceFactory.java new file mode 100644 index 0000000..2015738 --- /dev/null +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceFactory.java @@ -0,0 +1,57 @@ +/** + * + */ +package org.gcube.vremanagement.executor.persistence; + +import java.util.HashMap; +import java.util.Map; + +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.vremanagement.executor.persistence.couchdb.CouchDBPersistenceConnector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + * + */ +public abstract class SmartExecutorPersistenceFactory { + + private static final Logger logger = LoggerFactory.getLogger(SmartExecutorPersistenceFactory.class); + + private static Map persistenceConnectors; + + static { + persistenceConnectors = new HashMap(); + } + + /** + * @return the persistenceConnector + */ + public static synchronized SmartExecutorPersistenceConnector getPersistenceConnector() throws Exception { + String scope = ScopeProvider.instance.get(); + if(scope==null){ + String error = "No Scope available."; + logger.error(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()); + + SmartExecutorPersistenceConfiguration configuration = + new SmartExecutorPersistenceConfiguration(CouchDBPersistenceConnector.class.getSimpleName()); + persistence = new CouchDBPersistenceConnector(configuration); + persistenceConnectors.put(scope, persistence); + } + + return persistence; + } + +} diff --git a/src/main/java/org/gcube/vremanagement/executor/persistence/couchdb/PluginStateEvolutionObjectNode.java b/src/main/java/org/gcube/vremanagement/executor/persistence/couchdb/PluginStateEvolutionObjectNode.java index 53db3e1..ce05b64 100644 --- a/src/main/java/org/gcube/vremanagement/executor/persistence/couchdb/PluginStateEvolutionObjectNode.java +++ b/src/main/java/org/gcube/vremanagement/executor/persistence/couchdb/PluginStateEvolutionObjectNode.java @@ -10,7 +10,7 @@ import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.node.ObjectNode; import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.vremanagement.executor.SmartExecutorInitializator; +import org.gcube.vremanagement.executor.SmartExecutorImpl; import org.gcube.vremanagement.executor.plugin.PluginDeclaration; import org.gcube.vremanagement.executor.plugin.PluginStateEvolution; @@ -46,9 +46,9 @@ public class PluginStateEvolutionObjectNode { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode objectNode = objectMapper.createObjectNode(); try { - GCoreEndpoint gCoreEndpoint = SmartExecutorInitializator.getCtx().profile(GCoreEndpoint.class); + GCoreEndpoint gCoreEndpoint = SmartExecutorImpl.getCtx().profile(GCoreEndpoint.class); objectNode.put(GHN_ID_FIELD, gCoreEndpoint.profile().ghnId()); - objectNode.put(GHN_HOSTNAME_FIELD, SmartExecutorInitializator.getCtx().container().configuration().hostname()); + objectNode.put(GHN_HOSTNAME_FIELD, SmartExecutorImpl.getCtx().container().configuration().hostname()); }catch(Exception e){ objectNode.put(GHN_ID_FIELD, LOCALHOST + "_" + UUID.randomUUID()); objectNode.put(GHN_HOSTNAME_FIELD, LOCALHOST); diff --git a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorJob.java b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorJob.java index 187ae91..de5c08b 100644 --- a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorJob.java +++ b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorJob.java @@ -15,7 +15,7 @@ import org.gcube.vremanagement.executor.exception.AlreadyInFinalStateException; import org.gcube.vremanagement.executor.exception.InputsNullException; import org.gcube.vremanagement.executor.exception.PluginNotFoundException; import org.gcube.vremanagement.executor.exception.SchedulePersistenceException; -import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; +import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory; import org.gcube.vremanagement.executor.plugin.Plugin; import org.gcube.vremanagement.executor.plugin.PluginDeclaration; import org.gcube.vremanagement.executor.plugin.PluginState; @@ -127,7 +127,7 @@ public class SmartExecutorJob implements InterruptableJob { this.interrupted = false; this.initialized = false; pluginStateNotifications = new ArrayList(); - pluginStateNotifications.add(SmartExecutorPersistenceConnector.getPersistenceConnector()); + pluginStateNotifications.add(SmartExecutorPersistenceFactory.getPersistenceConnector()); } /** 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 4971e06..d467233 100644 --- a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java +++ b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java @@ -12,7 +12,7 @@ import java.util.Map; import java.util.UUID; import org.gcube.common.resources.gcore.GCoreEndpoint; -import org.gcube.vremanagement.executor.SmartExecutorInitializator; +import org.gcube.vremanagement.executor.SmartExecutorImpl; import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration; @@ -139,7 +139,7 @@ public class SmartExecutorScheduler { try { ScheduledTaskConfiguration stc = ScheduledTaskConfigurationFactory.getLaunchConfiguration(); - String runningInstanceID = SmartExecutorInitializator.getCtx().profile(GCoreEndpoint.class).id(); + String runningInstanceID = SmartExecutorImpl.getCtx().profile(GCoreEndpoint.class).id(); stc.addScheduledTask(uuid, runningInstanceID, parameter); } catch (Exception e) { logger.error("Unable to persist the scheduling", e.getCause()); 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 a96f177..4b88157 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 { @Test public void getConnectionTest() throws Exception { ScopeProvider.instance.set(GCUBE_DEVSEC_SCOPE); - SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); Assert.assertNotNull(persistenceConnector); Assert.assertEquals(CouchDBPersistenceConnector.class, persistenceConnector.getClass()); persistenceConnector.close(); @@ -44,7 +44,7 @@ public class SmartExecutorPersistenceConnectorTest { @Test public void getPluginInstanceStateTest() throws Exception { ScopeProvider.instance.set(GCUBE_DEVSEC_SCOPE); - SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); UUID uuid = UUID.randomUUID(); PluginState[] states = PluginState.values(); diff --git a/src/test/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePluginTest.java b/src/test/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePluginTest.java index d67aeac..6a997ef 100644 --- a/src/test/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePluginTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePluginTest.java @@ -13,6 +13,7 @@ import org.gcube.vremanagement.executor.exception.InputsNullException; import org.gcube.vremanagement.executor.exception.InvalidInputsException; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnectorTest; +import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory; import org.gcube.vremanagement.executor.plugin.PluginState; import org.gcube.vremanagement.executor.plugin.PluginStateNotification; import org.junit.AfterClass; @@ -33,7 +34,7 @@ public class RunnablePluginTest { public static void prepare() throws Exception{ try { ScopeProvider.instance.set(SmartExecutorPersistenceConnectorTest.GCUBE_DEVSEC_SCOPE); - SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceFactory.getPersistenceConnector(); } catch (Exception e) { logger.error("Unable to Create JDBCPersistenceConnector"); throw e; @@ -45,7 +46,7 @@ public class RunnablePluginTest { System.out.println("Testing Null inputs"); UUID uuid = UUID.randomUUID(); HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration(); - SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); List pluginStateNotifications = new ArrayList(); pluginStateNotifications.add(persistenceConnector); HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd); @@ -63,7 +64,7 @@ public class RunnablePluginTest { Map inputs = new HashMap(); UUID uuid = UUID.randomUUID(); HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration(); - SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); List pluginStateNotifications = new ArrayList(); pluginStateNotifications.add(persistenceConnector); HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd); @@ -87,7 +88,7 @@ public class RunnablePluginTest { UUID uuid = UUID.randomUUID(); HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration(); - SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); List pluginStateNotifications = new ArrayList(); pluginStateNotifications.add(persistenceConnector); HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd); @@ -102,7 +103,7 @@ public class RunnablePluginTest { @AfterClass public static void finish() throws Exception{ - SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceConnector.getPersistenceConnector(); + SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); persistenceConnector.close(); } } diff --git a/src/test/java/org/gcube/vremanagement/executor/pluginmanager/SmartExecutorSchedulerTest.java b/src/test/java/org/gcube/vremanagement/executor/pluginmanager/SmartExecutorSchedulerTest.java index ddad91a..7a811ac 100644 --- a/src/test/java/org/gcube/vremanagement/executor/pluginmanager/SmartExecutorSchedulerTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/pluginmanager/SmartExecutorSchedulerTest.java @@ -16,6 +16,7 @@ import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.exception.PluginStateNotRetrievedException; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnectorTest; +import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory; import org.gcube.vremanagement.executor.plugin.PluginState; import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler; import org.junit.AfterClass; @@ -46,7 +47,7 @@ public class SmartExecutorSchedulerTest { pc = new JDBCPersistenceConnector("."); SmartExecutorPersistenceConnector.setPersistenceConnector(pc); */ - pc = SmartExecutorPersistenceConnector.getPersistenceConnector(); + pc = SmartExecutorPersistenceFactory.getPersistenceConnector(); } catch (Exception e) { logger.error("Unable to Create SmartExecutorPersistenceConnector"); throw e;