Fixing handlers

This commit is contained in:
Luca Frosini 2020-10-23 10:34:38 +02:00
parent b12b72e43d
commit f7e3baca07
4 changed files with 92 additions and 97 deletions

View File

@ -1,7 +1,6 @@
package org.gcube.smartgears.handler.resourceregistry; package org.gcube.smartgears.handler.resourceregistry;
import static org.gcube.common.events.Observes.Kind.resilient; import static org.gcube.common.events.Observes.Kind.resilient;
import static org.gcube.smartgears.handler.resourceregistry.Constants.RESOURCE_MANAGEMENT;
import static org.gcube.smartgears.handlers.ProfileEvents.addToContext; import static org.gcube.smartgears.handlers.ProfileEvents.addToContext;
import static org.gcube.smartgears.handlers.ProfileEvents.removeFromContext; import static org.gcube.smartgears.handlers.ProfileEvents.removeFromContext;
import static org.gcube.smartgears.lifecycle.application.ApplicationLifecycle.activation; import static org.gcube.smartgears.lifecycle.application.ApplicationLifecycle.activation;
@ -24,7 +23,7 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.smartgears.context.Property; import org.gcube.smartgears.context.Property;
import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.handler.resourceregistry.resourcemanager.EServiceManager; import org.gcube.smartgears.handler.resourceregistry.resourcemanager.EServiceManager;
import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent; import org.gcube.smartgears.handlers.application.ApplicationLifecycleEvent.Start;
import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler; import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler;
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle; import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
import org.gcube.smartgears.lifecycle.application.ApplicationState; import org.gcube.smartgears.lifecycle.application.ApplicationState;
@ -47,7 +46,7 @@ import org.slf4j.LoggerFactory;
* *
* @author Luca Frosini * @author Luca Frosini
*/ */
@XmlRootElement(name = RESOURCE_MANAGEMENT) @XmlRootElement(name = Constants.RESOURCE_MANAGEMENT)
public class EServiceHandler extends ApplicationLifecycleHandler { public class EServiceHandler extends ApplicationLifecycleHandler {
private static final Logger logger = LoggerFactory.getLogger(EServiceHandler.class); private static final Logger logger = LoggerFactory.getLogger(EServiceHandler.class);
@ -62,14 +61,14 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
} }
@Override @Override
public void onStart(ApplicationLifecycleEvent.Start e) { public void onStart(Start event) {
try { try {
logger.info("{} onStart started", this.getClass().getSimpleName()); logger.info("{} onStart started", this.getClass().getSimpleName());
this.applicationContext = e.context(); this.applicationContext = event.context();
init(); init();
registerObservers(); registerObservers();
schedulePeriodicUpdates(); schedulePeriodicUpdates();
logger.info("{} onStart finished", this.getClass().getSimpleName()); logger.info("{} onStart terminated", this.getClass().getSimpleName());
} catch (Throwable re) { } catch (Throwable re) {
logger.error("onStart failed", re); logger.error("onStart failed", re);
} }
@ -86,16 +85,16 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
ContextUtility.setContextFromToken(token); ContextUtility.setContextFromToken(token);
try { try {
if (create) { if (create) {
eServiceManager = new EServiceManager(); eServiceManager = new EServiceManager(applicationContext);
eServiceManager.createEService(applicationContext); eServiceManager.createEService();
applicationContext.properties() applicationContext.properties()
.add(new Property(Constants.ESERVICE_MANAGER_PROPERTY, eServiceManager)); .add(new Property(Constants.ESERVICE_MANAGER_PROPERTY, eServiceManager));
create = false; create = false;
} else { } else {
eServiceManager.addToContext(applicationContext); eServiceManager.addToContext();
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to add {} to current context ({})", eServiceManager.geteService(), logger.error("Unable to add {} to current context ({})", eServiceManager.getEService(),
ContextUtility.getContextName(token), e); ContextUtility.getContextName(token), e);
} }
} }
@ -116,18 +115,18 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
@Observes({ activation }) @Observes({ activation })
void onChanged(ApplicationLifecycle lc) { void onChanged(ApplicationLifecycle lc) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String currentToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
if (currentToken == null) { if (previousToken == null) {
currentToken = applicationContext.configuration().startTokens().iterator().next(); ContextUtility
.setContextFromToken(applicationContext.configuration().startTokens().iterator().next());
} }
ContextUtility.setContextFromToken(currentToken);
try { try {
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader()); Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
eServiceManager.updateServiceStateFacet(applicationContext); eServiceManager.updateServiceStateFacet();
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to update {} State", EService.NAME, e); logger.error("Failed to update {} State", EService.NAME, e);
} finally { } finally {
ContextUtility.setContextFromToken(previousToken);
Thread.currentThread().setContextClassLoader(contextCL); Thread.currentThread().setContextClassLoader(contextCL);
} }
@ -136,18 +135,18 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
@Observes({ stop, failure }) @Observes({ stop, failure })
void onStop(ApplicationLifecycle lc) { void onStop(ApplicationLifecycle lc) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String currentToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
if (currentToken == null) { if (previousToken == null) {
currentToken = applicationContext.configuration().startTokens().iterator().next(); ContextUtility
.setContextFromToken(applicationContext.configuration().startTokens().iterator().next());
} }
ContextUtility.setContextFromToken(currentToken);
try { try {
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader()); Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
eServiceManager.removeEService(applicationContext); eServiceManager.removeEService();
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to update Service State", e); logger.error("Failed to update {} State", EService.NAME, e);
} finally { } finally {
ContextUtility.setContextFromToken(previousToken);
Thread.currentThread().setContextClassLoader(contextCL); Thread.currentThread().setContextClassLoader(contextCL);
} }
@ -157,12 +156,16 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
void addTo(String token) { void addTo(String token) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String previousToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
if (previousToken == null) {
ContextUtility
.setContextFromToken(applicationContext.configuration().startTokens().iterator().next());
}
try { try {
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader()); Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
ContextUtility.setContextFromToken(token); ContextUtility.setContextFromToken(token);
eServiceManager.addToContext(applicationContext); eServiceManager.addToContext();
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to add HostingNode to current context ({})", logger.error("Failed to add {} to current context ({})", EService.NAME,
ContextUtility.getCurrentContextName(), e); ContextUtility.getCurrentContextName(), e);
} finally { } finally {
ContextUtility.setContextFromToken(previousToken); ContextUtility.setContextFromToken(previousToken);
@ -174,13 +177,16 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
void removeFrom(String token) { void removeFrom(String token) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String previousToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
if (previousToken == null) {
ContextUtility
.setContextFromToken(applicationContext.configuration().startTokens().iterator().next());
}
try { try {
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader()); Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
ContextUtility.setContextFromToken(token);
eServiceManager.removeFromContext(); eServiceManager.removeFromContext();
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to remove HostingNode from current context ({})", logger.error("Failed to remove {} from current context ({})",
ContextUtility.getCurrentContextName(), e); EService.NAME, ContextUtility.getCurrentContextName(), e);
} finally { } finally {
ContextUtility.setContextFromToken(previousToken); ContextUtility.setContextFromToken(previousToken);
Thread.currentThread().setContextClassLoader(contextCL); Thread.currentThread().setContextClassLoader(contextCL);
@ -218,16 +224,17 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
final Runnable updateTask = new Runnable() { final Runnable updateTask = new Runnable() {
public void run() { public void run() {
String previousToken = SecurityTokenProvider.instance.get();
if (previousToken == null) {
ContextUtility.setContextFromToken(
applicationContext.configuration().startTokens().iterator().next());
}
try { try {
String currentToken = SecurityTokenProvider.instance.get(); eServiceManager.updateServiceStateFacet();
if (currentToken == null)
currentToken = applicationContext.configuration().startTokens().iterator()
.next();
ContextUtility.setContextFromToken(currentToken);
eServiceManager.updateServiceStateFacet(applicationContext);
} catch (Exception e) { } catch (Exception e) {
logger.error("Cannot complete periodic update of EService", e); logger.error("Cannot complete periodic update of EService", e);
} finally {
ContextUtility.setContextFromToken(previousToken);
} }
} }
}; };
@ -242,14 +249,14 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
synchronized void cancelPeriodicUpdates(ContainerLifecycle ignore) { synchronized void cancelPeriodicUpdates(ContainerLifecycle ignore) {
if (periodicUpdates != null) { if (periodicUpdates != null) {
logger.trace("stopping periodic updates of application {} EService", logger.trace("stopping periodic updates of EService for application {} ",
applicationContext.name()); applicationContext.name());
try { try {
periodicUpdates.cancel(true); periodicUpdates.cancel(true);
periodicUpdates = null; periodicUpdates = null;
} catch (Exception e) { } catch (Exception e) {
logger.warn("could not stop periodic updates of application {}", logger.warn("could not stop periodic updates of EService for application {}",
applicationContext.name(), e); applicationContext.name(), e);
} }
} }
@ -261,7 +268,7 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
@Override @Override
public String toString() { public String toString() {
return RESOURCE_MANAGEMENT; return Constants.RESOURCE_MANAGEMENT;
} }
} }

View File

@ -70,7 +70,7 @@ public class HostingNodeHandler extends ContainerHandler {
public void onStart(Start event) { public void onStart(Start event) {
try { try {
logger.info("{} onStart started", this.getClass().getSimpleName()); logger.info("{} onStart started", this.getClass().getSimpleName());
containerContext = event.context(); this.containerContext = event.context();
init(); init();
registerObservers(); registerObservers();
schedulePeriodicUpdates(); schedulePeriodicUpdates();
@ -121,12 +121,10 @@ public class HostingNodeHandler extends ContainerHandler {
@Observes({ activation, part_activation}) @Observes({ activation, part_activation})
void onChanged(ContainerLifecycle cl) { void onChanged(ContainerLifecycle cl) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String currentToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
if (currentToken == null) { if (previousToken == null) {
currentToken = containerContext.configuration().startTokens().iterator().next(); ContextUtility.setContextFromToken(containerContext.configuration().startTokens().iterator().next());
} }
ContextUtility.setContextFromToken(currentToken);
try { try {
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader()); Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
ContainerState containerState = cl.state(); ContainerState containerState = cl.state();
@ -142,6 +140,7 @@ public class HostingNodeHandler extends ContainerHandler {
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to update {} State", HostingNode.NAME, e); logger.error("Failed to update {} State", HostingNode.NAME, e);
} finally { } finally {
ContextUtility.setContextFromToken(previousToken);
Thread.currentThread().setContextClassLoader(contextCL); Thread.currentThread().setContextClassLoader(contextCL);
} }
} }
@ -149,17 +148,18 @@ public class HostingNodeHandler extends ContainerHandler {
@Observes({ shutdown, stop, failure }) @Observes({ shutdown, stop, failure })
void onShutdown(ContainerLifecycle cl) { void onShutdown(ContainerLifecycle cl) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String currentToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
if (currentToken == null) if (previousToken == null) {
currentToken = containerContext.configuration().startTokens().iterator().next(); ContextUtility
.setContextFromToken(containerContext.configuration().startTokens().iterator().next());
ContextUtility.setContextFromToken(currentToken); }
try { try {
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader()); Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
hostingNodeManager.updateFacets(); hostingNodeManager.updateFacets();
} catch (Exception e) { } catch (Exception e) {
logger.error("cannot complete periodic update of {}", HostingNode.NAME, e); logger.error("cannot complete periodic update of {}", HostingNode.NAME, e);
} finally { } finally {
ContextUtility.setContextFromToken(previousToken);
Thread.currentThread().setContextClassLoader(contextCL); Thread.currentThread().setContextClassLoader(contextCL);
} }
} }
@ -167,18 +167,18 @@ public class HostingNodeHandler extends ContainerHandler {
@Observes(value = addToContext) @Observes(value = addToContext)
void addTo(String token) { void addTo(String token) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String currentToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
if (currentToken == null) { if (previousToken == null) {
currentToken = containerContext.configuration().startTokens().iterator().next(); ContextUtility
.setContextFromToken(containerContext.configuration().startTokens().iterator().next());
} }
ContextUtility.setContextFromToken(currentToken);
try { try {
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader()); Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
hostingNodeManager.addToContext(); hostingNodeManager.addToContext();
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to update Service State", e); logger.error("Failed to update Service State", e);
} finally { } finally {
ContextUtility.setContextFromToken(previousToken);
Thread.currentThread().setContextClassLoader(contextCL); Thread.currentThread().setContextClassLoader(contextCL);
} }
} }
@ -186,12 +186,11 @@ public class HostingNodeHandler extends ContainerHandler {
@Observes(value = removeFromContext) @Observes(value = removeFromContext)
void removeFrom(String token) { void removeFrom(String token) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String currentToken = SecurityTokenProvider.instance.get(); String previousToken = SecurityTokenProvider.instance.get();
if (currentToken == null) { if (previousToken == null) {
currentToken = containerContext.configuration().startTokens().iterator().next(); ContextUtility
.setContextFromToken(containerContext.configuration().startTokens().iterator().next());
} }
ContextUtility.setContextFromToken(currentToken);
try { try {
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader()); Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
hostingNodeManager.removeFromContext(); hostingNodeManager.removeFromContext();
@ -262,17 +261,6 @@ public class HostingNodeHandler extends ContainerHandler {
logger.warn("could not stop periodic updates of {}", HostingNode.NAME, e); logger.warn("could not stop periodic updates of {}", HostingNode.NAME, e);
} }
} }
String currentToken = SecurityTokenProvider.instance.get();
if (currentToken == null)
currentToken = containerContext.configuration().startTokens().iterator().next();
ContextUtility.setContextFromToken(currentToken);
try {
hostingNodeManager.updateFacets();
} catch (Exception e) {
logger.error("cannot complete periodic update of {}", HostingNode.NAME, e);
}
} }
}); });

View File

@ -58,16 +58,18 @@ public class EServiceManager {
private EService eService; private EService eService;
private ServiceStateFacet serviceStateFacet; private ServiceStateFacet serviceStateFacet;
public EServiceManager() { private ApplicationContext applicationContext;
public EServiceManager(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
} }
public EService geteService() { public EService getEService() {
return eService; return eService;
} }
public void addToContext(ApplicationContext applicationContext) public void addToContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
HostingNode hostingNode = applicationContext.container().properties() HostingNode hostingNode = applicationContext.container().properties()
.lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode(); .lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode();
boolean added = resourceRegistryPublisher.addResourceToCurrentContext(hostingNode); boolean added = resourceRegistryPublisher.addResourceToCurrentContext(hostingNode);
@ -92,31 +94,31 @@ public class EServiceManager {
} }
} }
private String getBaseAddress(ApplicationContext context) { private String getBaseAddress() {
ApplicationConfiguration configuration = context.configuration(); ApplicationConfiguration configuration = applicationContext.configuration();
ContainerConfiguration container = context.container().configuration(); ContainerConfiguration container = applicationContext.container().configuration();
String baseAddress; String baseAddress;
if (configuration.proxied()) { if (configuration.proxied()) {
String protocol = configuration.proxyAddress().protocol(); String protocol = configuration.proxyAddress().protocol();
String port = configuration.proxyAddress().port() != null ? ":" + configuration.proxyAddress().port() : ""; String port = configuration.proxyAddress().port() != null ? ":" + configuration.proxyAddress().port() : "";
baseAddress = String.format("%s://%s%s%s", protocol, configuration.proxyAddress().hostname(), port, baseAddress = String.format("%s://%s%s%s", protocol, configuration.proxyAddress().hostname(), port,
context.application().getContextPath()); applicationContext.application().getContextPath());
} else { } else {
String protocol = container.protocol(); String protocol = container.protocol();
int port = container.port(); int port = container.port();
baseAddress = String.format("%s://%s:%d%s", protocol, container.hostname(), port, baseAddress = String.format("%s://%s:%d%s", protocol, container.hostname(), port,
context.application().getContextPath()); applicationContext.application().getContextPath());
} }
return baseAddress; return baseAddress;
} }
public String getState(ApplicationContext applicationContext) { public String getState() {
return applicationContext.lifecycle().state().remoteForm().toLowerCase(); return applicationContext.lifecycle().state().remoteForm().toLowerCase();
} }
private EService instantiateEService(ApplicationContext applicationContext) { private EService instantiateEService() {
logger.info("Creating {} for {}", EService.NAME, applicationContext.name()); logger.info("Creating {} for {}", EService.NAME, applicationContext.name());
ApplicationConfiguration applicationConfiguration = applicationContext.configuration(); ApplicationConfiguration applicationConfiguration = applicationContext.configuration();
@ -137,7 +139,7 @@ public class EServiceManager {
eService, softwareFacet); eService, softwareFacet);
eService.addFacet(isIdentifiedBy); eService.addFacet(isIdentifiedBy);
String baseAddress = getBaseAddress(applicationContext); String baseAddress = getBaseAddress();
for (ServletRegistration servlet : applicationContext.application().getServletRegistrations().values()) { for (ServletRegistration servlet : applicationContext.application().getServletRegistrations().values()) {
if (!servletExcludes.contains(servlet.getName())) { if (!servletExcludes.contains(servlet.getName())) {
for (String mapping : servlet.getMappings()) { for (String mapping : servlet.getMappings()) {
@ -159,14 +161,14 @@ public class EServiceManager {
} }
serviceStateFacet = new ServiceStateFacetImpl(); serviceStateFacet = new ServiceStateFacetImpl();
String state = getState(applicationContext); String state = getState();
serviceStateFacet.setValue(state); serviceStateFacet.setValue(state);
eService.addFacet(serviceStateFacet); eService.addFacet(serviceStateFacet);
return eService; return eService;
} }
public EService createEService(ApplicationContext applicationContext) throws ResourceRegistryException { public EService createEService() throws ResourceRegistryException {
try { try {
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
UUID uuid = UUID.fromString(applicationContext.id()); UUID uuid = UUID.fromString(applicationContext.id());
@ -179,28 +181,28 @@ public class EServiceManager {
} catch (NotFoundException e) { } catch (NotFoundException e) {
// Fine we are going to create it again // Fine we are going to create it again
} }
eService = instantiateEService(applicationContext); eService = instantiateEService();
// eService = resourceRegistryPublisher.createResource(eService); // eService = resourceRegistryPublisher.createResource(eService);
activates = createActivatesRelation(applicationContext, eService); activates = createActivatesRelation(eService);
} catch (AvailableInAnotherContextException | AlreadyPresentException e) { } catch (AvailableInAnotherContextException | AlreadyPresentException e) {
// resourceRegistryPublisher.delete(eService); // resourceRegistryPublisher.delete(eService);
// eService = resourceRegistryPublisher.createResource(eService); // eService = resourceRegistryPublisher.createResource(eService);
resourceRegistryPublisher.delete(activates); resourceRegistryPublisher.delete(activates);
activates = createActivatesRelation(applicationContext, eService); activates = createActivatesRelation(eService);
} }
eService = activates.getTarget(); eService = activates.getTarget();
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0); serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0);
return eService; return eService;
} }
public void updateServiceStateFacet(ApplicationContext applicationContext) throws ResourceRegistryException { public void updateServiceStateFacet() throws ResourceRegistryException {
String state = getState(applicationContext); String state = getState();
serviceStateFacet.setValue(state); serviceStateFacet.setValue(state);
serviceStateFacet = resourceRegistryPublisher.updateFacet(serviceStateFacet); serviceStateFacet = resourceRegistryPublisher.updateFacet(serviceStateFacet);
} }
private Activates<HostingNode, EService> createActivatesRelation(ApplicationContext applicationContext, private Activates<HostingNode, EService> createActivatesRelation(EService eService)
EService eService) throws ResourceRegistryException { throws ResourceRegistryException {
HostingNode hostingNode = applicationContext.container().properties() HostingNode hostingNode = applicationContext.container().properties()
.lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode(); .lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode();
@ -226,13 +228,12 @@ public class EServiceManager {
} }
public void removeEService(ApplicationContext applicationContext) throws ResourceRegistryException { public void removeEService() throws ResourceRegistryException {
try { try {
resourceRegistryPublisher.delete(eService); resourceRegistryPublisher.delete(eService);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
logger.error("Unable to delete {}. Going to set the state to {}", applicationContext.name(), logger.error("Unable to delete {}. Going to set the state to {}", applicationContext.name(), getState());
getState(applicationContext)); updateServiceStateFacet();
updateServiceStateFacet(applicationContext);
} }
} }

View File

@ -70,7 +70,6 @@ import org.gcube.smartgears.configuration.container.Site;
import org.gcube.smartgears.configuration.library.SmartGearsConfiguration; import org.gcube.smartgears.configuration.library.SmartGearsConfiguration;
import org.gcube.smartgears.context.container.ContainerContext; import org.gcube.smartgears.context.container.ContainerContext;
import org.gcube.smartgears.handler.resourceregistry.ContextUtility; import org.gcube.smartgears.handler.resourceregistry.ContextUtility;
import org.gcube.smartgears.lifecycle.container.ContainerLifecycle;
import org.gcube.smartgears.provider.ProviderFactory; import org.gcube.smartgears.provider.ProviderFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -188,7 +187,7 @@ public class HostingNodeManager {
return hostingNode; return hostingNode;
} }
public HostingNode updateStatus(ContainerLifecycle cl) throws ResourceRegistryException { public HostingNode updateStatus() throws ResourceRegistryException {
logger.debug("Setting {} down", HostingNode.NAME); logger.debug("Setting {} down", HostingNode.NAME);
ContainerStateFacet containerStateFacet = null; ContainerStateFacet containerStateFacet = null;