2016-02-12 18:57:59 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-02-06 10:35:18 +01:00
|
|
|
package org.gcube.vremanagement.executor;
|
|
|
|
|
|
|
|
import java.io.StringWriter;
|
2016-02-12 18:57:59 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashSet;
|
2015-02-06 10:35:18 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2016-02-12 18:57:59 +01:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import javax.xml.bind.annotation.XmlRootElement;
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
2015-02-06 10:35:18 +01:00
|
|
|
import org.gcube.common.resources.gcore.Resource;
|
|
|
|
import org.gcube.common.resources.gcore.Resources;
|
2016-02-12 18:57:59 +01:00
|
|
|
import org.gcube.common.resources.gcore.ScopeGroup;
|
2015-02-06 10:35:18 +01:00
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Profile;
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
2015-02-06 17:53:33 +01:00
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
|
2015-02-06 17:25:29 +01:00
|
|
|
import org.gcube.common.resources.gcore.common.Platform;
|
2015-02-06 10:35:18 +01:00
|
|
|
import org.gcube.common.resources.gcore.utils.Group;
|
2016-02-12 18:57:59 +01:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.informationsystem.publisher.AdvancedScopedPublisher;
|
2015-02-06 10:35:18 +01:00
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
2016-02-12 18:57:59 +01:00
|
|
|
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
2015-02-06 10:35:18 +01:00
|
|
|
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
2015-02-12 14:40:41 +01:00
|
|
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
|
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
|
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
|
|
|
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
2016-02-12 18:57:59 +01:00
|
|
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
|
|
|
import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent;
|
|
|
|
import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler;
|
2015-08-26 14:29:00 +02:00
|
|
|
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
|
2015-10-12 18:33:47 +02:00
|
|
|
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
|
2015-02-06 10:35:18 +01:00
|
|
|
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
|
|
|
|
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
|
2015-07-28 15:41:35 +02:00
|
|
|
import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler;
|
2015-02-06 10:35:18 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
|
|
*
|
|
|
|
*/
|
2016-02-12 18:57:59 +01:00
|
|
|
@XmlRootElement(name = "plugin-registration-handler")
|
|
|
|
public class SmartExecutorInitializator extends ApplicationLifecycleHandler {
|
2015-02-06 10:35:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Logger
|
|
|
|
*/
|
2015-10-12 11:53:46 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(SmartExecutorInitializator.class);
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2015-07-28 15:41:35 +02:00
|
|
|
public static final long JOIN_TIMEOUT = 1000;
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
/* *
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the configuredTasks
|
|
|
|
* /
|
|
|
|
public static ScheduledTaskConfiguration getConfiguredTasks() {
|
|
|
|
return launchConfiguration;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String getCurrentScope(){
|
|
|
|
return ScopeProvider.instance.get();
|
2016-02-09 15:20:26 +01:00
|
|
|
}
|
|
|
|
|
2015-02-06 10:35:18 +01:00
|
|
|
/**
|
|
|
|
* Publish the provided resource on all Service Scopes retrieved from
|
|
|
|
* Context
|
|
|
|
* @param resource to be published
|
|
|
|
* @throws RegistryNotFoundException if the Registry is not found so the
|
|
|
|
* resource has not be published
|
|
|
|
*/
|
2016-02-12 18:57:59 +01:00
|
|
|
private static void publishScopedResource(Resource resource, List<String> scopes) throws RegistryNotFoundException, Exception {
|
2015-02-06 10:35:18 +01:00
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
Resources.marshal(resource, stringWriter);
|
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
2015-02-06 10:35:18 +01:00
|
|
|
try {
|
2016-02-12 18:57:59 +01:00
|
|
|
logger.debug("Trying to publish to {}:\n{}", scopes, stringWriter);
|
|
|
|
scopedPublisher.create(resource, scopes);
|
|
|
|
} catch (RegistryNotFoundException e) {
|
2015-02-06 10:35:18 +01:00
|
|
|
logger.error("The resource was not published", e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the resource from IS
|
|
|
|
* @param resource to be unpublished
|
|
|
|
* @throws RegistryNotFoundException if the Registry is not found so the
|
|
|
|
* resource has not be published
|
|
|
|
*/
|
2016-02-12 18:57:59 +01:00
|
|
|
private static void unPublishScopedResource(Resource resource) throws RegistryNotFoundException, Exception {
|
2015-05-06 16:52:15 +02:00
|
|
|
//StringWriter stringWriter = new StringWriter();
|
|
|
|
//Resources.marshal(resource, stringWriter);
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
|
|
|
AdvancedScopedPublisher advancedScopedPublisher = new AdvancedScopedPublisher(scopedPublisher);
|
2015-05-06 16:52:15 +02:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
String id = resource.id();
|
|
|
|
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, ScopeProvider.instance.get());
|
2015-05-06 16:52:15 +02:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
//scopedPublisher.remove(resource, scopes);
|
|
|
|
advancedScopedPublisher.forceRemove(resource);
|
2015-05-06 16:52:15 +02:00
|
|
|
|
|
|
|
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
|
2015-02-06 10:35:18 +01:00
|
|
|
}
|
|
|
|
|
2015-02-12 14:40:41 +01:00
|
|
|
/**
|
|
|
|
* Return the parsed version string as array of short.
|
|
|
|
* @param version the version as String
|
|
|
|
* @param wantedLenght if the length is equals to dot (.) separated
|
|
|
|
* number in the string. Otherwise the version is padded or truncated to
|
|
|
|
* the required version
|
|
|
|
* @return the parsed version as array of short. If on slicing some of the
|
|
|
|
* version cannot be parsed as short 1 is used for the first number, 0 is
|
|
|
|
* used instead or for padding
|
|
|
|
*/
|
|
|
|
private static short[] getVersionSlice(String version, int wantedLenght){
|
|
|
|
logger.trace("Trying to parse {}", version);
|
|
|
|
|
|
|
|
short[] versionSlices = new short[wantedLenght];
|
|
|
|
for(int j=0; j<wantedLenght; j++){
|
|
|
|
versionSlices[j] = (short) (j==0 ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
String[] stringSlices = version.split("[.-]");
|
|
|
|
for(int i=0; i<stringSlices.length; i++){
|
|
|
|
logger.trace("Parsing version slice n. {} wich is '{}'", i, stringSlices[i]);
|
|
|
|
if(i>=wantedLenght){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
short n = Short.parseShort(stringSlices[i]);
|
|
|
|
versionSlices[i] = n;
|
|
|
|
logger.trace("Version slice n. {} wich is '{}' parsed as short {}", i, stringSlices[i], n);
|
|
|
|
} catch(NumberFormatException nfe){
|
|
|
|
logger.trace("Version slice n. {} wich is '{}' failed to parse. The default value {} will be used", i, stringSlices[i], versionSlices[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(Exception e){
|
|
|
|
logger.trace("Error parsing the supplied version the default will be used", versionSlices);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.trace("Version {} parsed as {}", version, versionSlices);
|
|
|
|
return versionSlices;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String getRunningOn(ContainerConfiguration containerConfiguration){
|
|
|
|
return String.format("%s:%s", containerConfiguration.hostname(), containerConfiguration.port());
|
|
|
|
}
|
|
|
|
|
2015-02-06 10:35:18 +01:00
|
|
|
/**
|
|
|
|
* Create the Service Endpoint using information related to discovered
|
2015-02-12 14:40:41 +01:00
|
|
|
* available plugins and their own discovered capabilities
|
2015-02-06 10:35:18 +01:00
|
|
|
* @return the created {@link ServiceEndpoint}
|
|
|
|
*/
|
|
|
|
protected static ServiceEndpoint createServiceEndpoint(){
|
|
|
|
logger.debug("Getting Available Plugins and their own supported capabilities");
|
|
|
|
PluginManager pluginManager = PluginManager.getInstance();
|
2015-10-12 18:33:47 +02:00
|
|
|
|
2015-02-06 10:35:18 +01:00
|
|
|
logger.debug("Creating ServiceEndpoint to publish on IS available plugins and their own supported capabilities");
|
|
|
|
ServiceEndpoint serviceEndpoint = new ServiceEndpoint();
|
|
|
|
Profile profile = serviceEndpoint.newProfile();
|
2016-02-12 18:57:59 +01:00
|
|
|
profile.category(SmartExecutorImpl.ctx.configuration().serviceClass());
|
|
|
|
profile.name(SmartExecutorImpl.ctx.configuration().name());
|
|
|
|
String version = SmartExecutorImpl.ctx.configuration().version();
|
2015-02-12 14:40:41 +01:00
|
|
|
profile.version(version);
|
2016-02-12 18:57:59 +01:00
|
|
|
profile.description(SmartExecutorImpl.ctx.configuration().description());
|
2015-02-06 17:53:33 +01:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
String runningOn = getRunningOn(SmartExecutorImpl.ctx.container().configuration());
|
2015-02-06 17:25:29 +01:00
|
|
|
Platform platform = profile.newPlatform();
|
2015-02-12 14:40:41 +01:00
|
|
|
platform.name(runningOn);
|
2015-02-11 16:48:04 +01:00
|
|
|
|
2015-02-12 14:40:41 +01:00
|
|
|
short[] versionSlices = getVersionSlice(version, 4);
|
|
|
|
platform.version(versionSlices[0]);
|
|
|
|
platform.minorVersion(versionSlices[1]);
|
|
|
|
platform.buildVersion(versionSlices[2]);
|
|
|
|
platform.revisionVersion(versionSlices[3]);
|
2015-02-06 17:53:33 +01:00
|
|
|
|
|
|
|
Runtime runtime = profile.newRuntime();
|
2015-02-12 14:40:41 +01:00
|
|
|
runtime.hostedOn(runningOn);
|
2016-02-12 18:57:59 +01:00
|
|
|
runtime.status(SmartExecutorImpl.ctx.configuration().mode().toString());
|
2015-02-06 10:35:18 +01:00
|
|
|
|
|
|
|
Group<AccessPoint> accessPoints = profile.accessPoints();
|
|
|
|
Map<String, PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins();
|
|
|
|
|
|
|
|
for(String pluginName : availablePlugins.keySet()){
|
|
|
|
AccessPoint accessPointElement = new AccessPoint();
|
|
|
|
accessPointElement.name(pluginName);
|
2015-02-06 17:16:22 +01:00
|
|
|
|
|
|
|
PluginDeclaration pluginDeclaration = availablePlugins.get(pluginName);
|
|
|
|
|
|
|
|
accessPointElement.description(pluginDeclaration.getDescription());
|
|
|
|
|
2015-02-06 10:35:18 +01:00
|
|
|
Group<Property> properties = accessPointElement.properties();
|
2015-02-06 17:53:33 +01:00
|
|
|
Property propertyVersionElement = new Property();
|
|
|
|
propertyVersionElement.nameAndValue("Version", pluginDeclaration.getVersion());
|
|
|
|
properties.add(propertyVersionElement);
|
|
|
|
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2015-09-28 17:44:12 +02:00
|
|
|
Map<String, String> pluginCapabilities = pluginDeclaration.getSupportedCapabilities();
|
|
|
|
for(String capabilityName : pluginCapabilities.keySet()){
|
2015-02-06 10:35:18 +01:00
|
|
|
Property propertyElement = new Property();
|
2015-09-28 17:44:12 +02:00
|
|
|
propertyElement.nameAndValue(capabilityName, pluginCapabilities.get(capabilityName));
|
2015-02-06 10:35:18 +01:00
|
|
|
properties.add(propertyElement);
|
|
|
|
}
|
|
|
|
accessPoints.add(accessPointElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
Resources.marshal(serviceEndpoint, stringWriter);
|
2015-02-12 14:40:41 +01:00
|
|
|
logger.debug("The created ServiceEndpoint profile is\n{}", stringWriter.toString());
|
2015-02-06 10:35:18 +01:00
|
|
|
|
|
|
|
return serviceEndpoint;
|
|
|
|
}
|
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
public static List<String> getScopes(ApplicationContext applicationContext){
|
|
|
|
Collection<String> scopes;
|
|
|
|
|
|
|
|
ScopeGroup<String> scopeGroup = applicationContext.profile(GCoreEndpoint.class).scopes();
|
|
|
|
if(scopeGroup==null || scopeGroup.isEmpty()){
|
|
|
|
Set<String> applicationScopes = applicationContext.configuration().startScopes();
|
|
|
|
Set<String> 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<String>(applicationScopes);
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
scopes = scopeGroup.asCollection();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ArrayList<String>(scopes);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void cleanServiceEndpoints(String scope){
|
2015-10-12 18:33:47 +02:00
|
|
|
try {
|
|
|
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class)
|
2016-02-12 18:57:59 +01:00
|
|
|
.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())))
|
2015-10-12 18:33:47 +02:00
|
|
|
.setResult("$resource");
|
|
|
|
|
|
|
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
|
|
|
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
|
|
|
|
|
|
|
for (ServiceEndpoint serviceEndpoint : serviceEndpoints) {
|
|
|
|
try {
|
|
|
|
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}",
|
2016-02-12 18:57:59 +01:00
|
|
|
serviceEndpoint.id(), scope);
|
|
|
|
unPublishScopedResource(serviceEndpoint);
|
2015-10-12 18:33:47 +02:00
|
|
|
} catch(Exception e){
|
|
|
|
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}",
|
2016-02-12 18:57:59 +01:00
|
|
|
serviceEndpoint.id(), scope, e);
|
2015-10-12 18:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.debug("An Exception occur while checking and/or unpublishing old ServiceEndpoint", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2015-02-06 10:35:18 +01:00
|
|
|
* The method discover the plugins available on classpath and their own
|
|
|
|
* supported capabilities and publish a ServiceEndpoint with the
|
|
|
|
* discovered information.
|
|
|
|
* Furthermore create/connect to DB
|
|
|
|
*/
|
|
|
|
@Override
|
2016-02-12 18:57:59 +01:00
|
|
|
public void onStart(ApplicationLifecycleEvent.Start applicationLifecycleEventStart) {
|
2015-08-31 17:02:11 +02:00
|
|
|
logger.trace(
|
2015-02-12 14:40:41 +01:00
|
|
|
"\n-------------------------------------------------------\n"
|
2016-02-12 18:57:59 +01:00
|
|
|
+ "Smart Executor is Starting\n"
|
|
|
|
+ "-------------------------------------------------------");
|
|
|
|
|
|
|
|
SmartExecutorImpl.ctx = applicationLifecycleEventStart.context();
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2015-10-12 18:33:47 +02:00
|
|
|
ServiceEndpoint serviceEndpoint = createServiceEndpoint();
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
// Checking if there are old unpublished ServiceEndpoints related to
|
|
|
|
// this vHN and trying to unpublish them
|
|
|
|
List<String> scopes = getScopes(SmartExecutorImpl.ctx);
|
2015-02-12 14:40:41 +01:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
for(String scope : scopes){
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
cleanServiceEndpoints(scope);
|
|
|
|
try {
|
|
|
|
SmartExecutorPersistenceFactory.getPersistenceConnector();
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Unable to isntantiate {} for scope {}",
|
|
|
|
SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2015-02-12 14:40:41 +01:00
|
|
|
}
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
// TODO set task that are still on running state on DB to have a clear
|
|
|
|
// room
|
2015-02-06 10:35:18 +01:00
|
|
|
|
|
|
|
try {
|
2016-02-12 18:57:59 +01:00
|
|
|
publishScopedResource(serviceEndpoint, scopes);
|
2015-02-06 10:35:18 +01:00
|
|
|
} catch (RegistryNotFoundException e) {
|
|
|
|
logger.error("Unable to Create ServiceEndpoint. the Service will be aborted", e);
|
|
|
|
return;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Unable to Create ServiceEndpoint. the Service will be aborted", e);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-12 18:33:47 +02:00
|
|
|
|
2015-08-31 17:02:11 +02:00
|
|
|
logger.trace(
|
2015-02-12 14:40:41 +01:00
|
|
|
"\n-------------------------------------------------------\n"
|
2016-02-12 18:57:59 +01:00
|
|
|
+ "Smart Executor Started Successfully\n"
|
|
|
|
+ "-------------------------------------------------------");
|
|
|
|
|
|
|
|
// TODO Launch initializer thread
|
|
|
|
|
2015-08-31 11:59:00 +02:00
|
|
|
|
2015-02-06 10:35:18 +01:00
|
|
|
}
|
|
|
|
|
2015-10-12 18:33:47 +02:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
2015-02-06 10:35:18 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
@Override
|
2016-02-12 18:57:59 +01:00
|
|
|
public void onStop(ApplicationLifecycleEvent.Stop applicationLifecycleEventStop) {
|
2015-08-31 17:02:11 +02:00
|
|
|
logger.trace(
|
2015-02-12 14:40:41 +01:00
|
|
|
"\n-------------------------------------------------------\n"
|
2016-02-12 18:57:59 +01:00
|
|
|
+ "Smart Executor is Stopping\n"
|
|
|
|
+ "-------------------------------------------------------");
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2015-10-12 11:51:21 +02:00
|
|
|
SmartExecutorScheduler.getInstance().stopAll();
|
2015-02-06 10:35:18 +01:00
|
|
|
|
2016-02-12 18:57:59 +01:00
|
|
|
List<String> scopes = getScopes(SmartExecutorImpl.ctx);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2015-02-06 10:35:18 +01:00
|
|
|
}
|
|
|
|
|
2015-08-31 17:02:11 +02:00
|
|
|
logger.trace(
|
2015-02-12 14:40:41 +01:00
|
|
|
"\n-------------------------------------------------------\n"
|
2016-02-12 18:57:59 +01:00
|
|
|
+ "Smart Executor Stopped Successfully\n"
|
|
|
|
+ "-------------------------------------------------------");
|
2015-02-12 14:40:41 +01:00
|
|
|
|
2015-02-06 10:35:18 +01:00
|
|
|
}
|
|
|
|
}
|