Backported fixes from version using authorization-utils
This commit is contained in:
parent
519a5d79fe
commit
fea428d51e
|
@ -120,7 +120,8 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
|
||||||
eServiceManager.addToContext();
|
eServiceManager.addToContext();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to add {} to current context ({})", eServiceManager.getEService(),
|
UUID uuid = UUID.fromString(applicationContext.id());
|
||||||
|
logger.error("Unable to add {} with UUID {} to current context ({})", EService.NAME, uuid,
|
||||||
ContextUtility.getContextName(token), e);
|
ContextUtility.getContextName(token), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,28 +161,6 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Observes({ stop, failure })
|
|
||||||
void onStop(ApplicationLifecycle lc) {
|
|
||||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
|
||||||
String previousToken = SecurityTokenProvider.instance.get();
|
|
||||||
if (previousToken == null) {
|
|
||||||
ContextUtility
|
|
||||||
.setContextFromToken(applicationContext.configuration().startTokens().iterator().next());
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Thread.currentThread().setContextClassLoader(EServiceHandler.class.getClassLoader());
|
|
||||||
eServiceManager.updateServiceStateFacet();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Failed to update {} State", EService.NAME, e);
|
|
||||||
} finally {
|
|
||||||
ContextUtility.setContextFromToken(previousToken);
|
|
||||||
Thread.currentThread().setContextClassLoader(contextCL);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Observes(value = addToContext)
|
@Observes(value = addToContext)
|
||||||
void addTo(String token) {
|
void addTo(String token) {
|
||||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||||
|
@ -245,11 +224,11 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lc.state() == ApplicationState.active) {
|
if (lc.state() == ApplicationState.active) {
|
||||||
logger.info("scheduling periodic updates of application {} EService",
|
logger.info("Scheduling periodic updates of {} from application {}",
|
||||||
applicationContext.name());
|
EService.NAME, applicationContext.name());
|
||||||
} else {
|
} else {
|
||||||
logger.info("resuming periodic updates of application {} EService",
|
logger.info("Resuming periodic updates of {} for application {}",
|
||||||
applicationContext.name());
|
EService.NAME, applicationContext.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
final Runnable updateTask = new Runnable() {
|
final Runnable updateTask = new Runnable() {
|
||||||
|
@ -262,7 +241,7 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
|
||||||
try {
|
try {
|
||||||
eServiceManager.updateServiceStateFacet();
|
eServiceManager.updateServiceStateFacet();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Cannot complete periodic update of EService", e);
|
logger.error("Cannot complete periodic update of {}", EService.NAME, e);
|
||||||
} finally {
|
} finally {
|
||||||
ContextUtility.setContextFromToken(previousToken);
|
ContextUtility.setContextFromToken(previousToken);
|
||||||
}
|
}
|
||||||
|
@ -279,15 +258,15 @@ 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 EService for application {} ",
|
logger.trace("Stopping periodic updates of {} for application {} ",
|
||||||
applicationContext.name());
|
EService.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 EService for application {}",
|
logger.warn("Could not stop periodic updates of {} for application {}",
|
||||||
applicationContext.name(), e);
|
EService.NAME, applicationContext.name(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,8 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
hostingNodeManager.addToContext();
|
hostingNodeManager.addToContext();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to add {} to current context ({})", hostingNodeManager.getHostingNode(),
|
UUID uuid = UUID.fromString(containerContext.id());
|
||||||
|
logger.error("Unable to add {} with UUID {} to current context ({})", HostingNode.NAME, uuid,
|
||||||
ContextUtility.getContextName(token), e);
|
ContextUtility.getContextName(token), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,8 +144,7 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
|
|
||||||
containerContext.events().subscribe(new Object() {
|
containerContext.events().subscribe(new Object() {
|
||||||
|
|
||||||
//@Observes({ activation, part_activation, shutdown, stop, failure })
|
@Observes({ activation, part_activation, shutdown, stop, failure })
|
||||||
@Observes({ activation, part_activation})
|
|
||||||
void onChanged(ContainerLifecycle cl) {
|
void onChanged(ContainerLifecycle cl) {
|
||||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||||
String previousToken = SecurityTokenProvider.instance.get();
|
String previousToken = SecurityTokenProvider.instance.get();
|
||||||
|
@ -171,25 +171,6 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Observes({ shutdown, stop, failure })
|
|
||||||
void onShutdown(ContainerLifecycle cl) {
|
|
||||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
|
||||||
String previousToken = SecurityTokenProvider.instance.get();
|
|
||||||
if (previousToken == null) {
|
|
||||||
ContextUtility
|
|
||||||
.setContextFromToken(containerContext.configuration().startTokens().iterator().next());
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Thread.currentThread().setContextClassLoader(HostingNodeHandler.class.getClassLoader());
|
|
||||||
hostingNodeManager.updateStatus();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("cannot complete periodic update of {}", HostingNode.NAME, e);
|
|
||||||
} finally {
|
|
||||||
ContextUtility.setContextFromToken(previousToken);
|
|
||||||
Thread.currentThread().setContextClassLoader(contextCL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Observes(value = addToContext)
|
@Observes(value = addToContext)
|
||||||
void addTo(String token) {
|
void addTo(String token) {
|
||||||
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
|
||||||
|
@ -249,9 +230,9 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cl.state() == active) {
|
if (cl.state() == active) {
|
||||||
logger.info("scheduling periodic updates of {}", HostingNode.NAME);
|
logger.info("Scheduling periodic updates of {}", HostingNode.NAME);
|
||||||
} else {
|
} else {
|
||||||
logger.info("resuming periodic updates of {}", HostingNode.NAME);
|
logger.info("Resuming periodic updates of {}", HostingNode.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Runnable updateTask = new Runnable() {
|
final Runnable updateTask = new Runnable() {
|
||||||
|
@ -264,7 +245,7 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
try {
|
try {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -278,13 +259,13 @@ public class HostingNodeHandler extends ContainerHandler {
|
||||||
synchronized void cancelPeriodicUpdates(ContainerLifecycle cl) {
|
synchronized void cancelPeriodicUpdates(ContainerLifecycle cl) {
|
||||||
|
|
||||||
if (periodicUpdates != null) {
|
if (periodicUpdates != null) {
|
||||||
logger.trace("stopping periodic updates of {}", HostingNode.NAME);
|
logger.trace("Stopping periodic updates of {}", HostingNode.NAME);
|
||||||
try {
|
try {
|
||||||
periodicUpdates.cancel(true);
|
periodicUpdates.cancel(true);
|
||||||
service.shutdownNow();
|
service.shutdownNow();
|
||||||
periodicUpdates = null;
|
periodicUpdates = null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("could not stop periodic updates of {}", HostingNode.NAME, e);
|
logger.warn("Could not stop periodic updates of {}", HostingNode.NAME, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.smartgears.handler.resourceregistry.resourcemanager;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -25,13 +27,16 @@ import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClien
|
||||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
||||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
|
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||||
|
@ -73,37 +78,47 @@ public class EServiceManager {
|
||||||
return eService;
|
return eService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
public void addEServiceToCurrentContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
HostingNode hostingNode = applicationContext.container().properties()
|
UUID uuid = UUID.fromString(applicationContext.id());
|
||||||
.lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode();
|
|
||||||
try {
|
try {
|
||||||
resourceRegistryPublisher.addResourceToCurrentContext(hostingNode, false);
|
resourceRegistryPublisher.addResourceToCurrentContext(EService.NAME, uuid, false);
|
||||||
logger.info("{} successfully added to current context ({})", eService, ContextUtility.getCurrentContextName());
|
logger.info("{} with UUID {} successfully added to current context ({})", EService.NAME, uuid, ContextUtility.getCurrentContextName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to add {} to current context ({})", eService, ContextUtility.getCurrentContextName(), e);
|
logger.error("Unable to add {} with UUID {} to current context ({})", EService.NAME, uuid, ContextUtility.getCurrentContextName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
UUID uuid = UUID.fromString(applicationContext.container().id());
|
||||||
|
try {
|
||||||
|
resourceRegistryPublisher.addResourceToCurrentContext(HostingNode.NAME, uuid, false);
|
||||||
|
logger.info("{} with UUID {} successfully added to current context ({})", HostingNode.NAME, uuid, ContextUtility.getCurrentContextName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Unable to add {} with UUID {} to current context ({})", HostingNode.NAME, uuid, ContextUtility.getCurrentContextName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeFromContext()
|
public void removeFromContext()
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
UUID uuid = UUID.fromString(applicationContext.container().id());
|
||||||
try {
|
try {
|
||||||
resourceRegistryPublisher.removeResourceFromCurrentContext(eService, false);
|
resourceRegistryPublisher.removeResourceFromCurrentContext(HostingNode.NAME, uuid, false);
|
||||||
logger.info("{} successfully removed from current context ({})", eService,
|
logger.info("{} with UUID {} successfully removed from current context ({})", HostingNode.NAME, uuid,
|
||||||
ContextUtility.getCurrentContextName());
|
ContextUtility.getCurrentContextName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to remove {} from current context ({})", eService,
|
logger.error("Unable to remove {} with UUID {} from current context ({})", HostingNode.NAME, uuid, ContextUtility.getCurrentContextName(), e);
|
||||||
ContextUtility.getCurrentContextName(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeFromContext(UUID contextUUID)
|
public void removeFromContext(UUID contextUUID)
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
|
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
|
||||||
|
UUID uuid = UUID.fromString(applicationContext.container().id());
|
||||||
try {
|
try {
|
||||||
resourceRegistryPublisher.removeResourceFromContext(eService, contextUUID, false);
|
resourceRegistryPublisher.removeResourceFromContext(HostingNode.NAME, uuid, contextUUID, false);
|
||||||
logger.info("{} successfully removed from context ({})", eService, contextFullName);
|
logger.info("{} with UUID {} successfully removed from context ({})", HostingNode.NAME, uuid, contextFullName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to remove {} from current context ({})", eService, contextFullName, e);
|
logger.error("Unable to remove {} from current context ({})", HostingNode.NAME, uuid, contextFullName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,11 +188,19 @@ public class EServiceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Date date = Calendar.getInstance().getTime();
|
||||||
|
|
||||||
stateFacet = new StateFacetImpl();
|
stateFacet = new StateFacetImpl();
|
||||||
String state = getState();
|
String state = getState();
|
||||||
stateFacet.setValue(state);
|
stateFacet.setValue(state);
|
||||||
eService.addFacet(stateFacet);
|
eService.addFacet(stateFacet);
|
||||||
|
stateFacet.setAdditionalProperty("date", date);
|
||||||
|
|
||||||
|
EventFacet eventFacet = new EventFacetImpl();
|
||||||
|
eventFacet.setEvent(state);
|
||||||
|
eventFacet.setDate(date);
|
||||||
|
eService.addFacet(eventFacet);
|
||||||
|
|
||||||
return eService;
|
return eService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,15 +211,7 @@ public class EServiceManager {
|
||||||
ResourceRegistryClientFactory.includeContextsInInstanceHeader(true);
|
ResourceRegistryClientFactory.includeContextsInInstanceHeader(true);
|
||||||
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||||
stateFacet = eService.getFacets(StateFacet.class).get(0);
|
stateFacet = eService.getFacets(StateFacet.class).get(0);
|
||||||
if (stateFacet == null) {
|
updateServiceStateFacet();
|
||||||
stateFacet = new StateFacetImpl();
|
|
||||||
String state = getState();
|
|
||||||
stateFacet.setValue(state);
|
|
||||||
eService.addFacet(stateFacet);
|
|
||||||
resourceRegistryPublisher.update(eService);
|
|
||||||
} else {
|
|
||||||
updateServiceStateFacet();
|
|
||||||
}
|
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
eService = instantiateEService();
|
eService = instantiateEService();
|
||||||
createActivatesRelation(eService);
|
createActivatesRelation(eService);
|
||||||
|
@ -206,7 +221,8 @@ public class EServiceManager {
|
||||||
try {
|
try {
|
||||||
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||||
} catch (AvailableInAnotherContextException ex) {
|
} catch (AvailableInAnotherContextException ex) {
|
||||||
resourceRegistryPublisher.addResourceToCurrentContext(eService, false);
|
addEServiceToCurrentContext();
|
||||||
|
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
|
||||||
// addToContext() is executed on HostingNode.
|
// addToContext() is executed on HostingNode.
|
||||||
// If the EService is still not available we need to create activates
|
// If the EService is still not available we need to create activates
|
||||||
// relation because does not exists otherwise the EService should
|
// relation because does not exists otherwise the EService should
|
||||||
|
@ -214,15 +230,7 @@ public class EServiceManager {
|
||||||
createActivatesRelation(eService);
|
createActivatesRelation(eService);
|
||||||
}
|
}
|
||||||
stateFacet = eService.getFacets(StateFacet.class).get(0);
|
stateFacet = eService.getFacets(StateFacet.class).get(0);
|
||||||
if (stateFacet == null) {
|
updateServiceStateFacet();
|
||||||
stateFacet = new StateFacetImpl();
|
|
||||||
String state = getState();
|
|
||||||
stateFacet.setValue(state);
|
|
||||||
eService.addFacet(stateFacet);
|
|
||||||
resourceRegistryPublisher.update(eService);
|
|
||||||
} else {
|
|
||||||
updateServiceStateFacet();
|
|
||||||
}
|
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -230,16 +238,38 @@ public class EServiceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateServiceStateFacet() throws ResourceRegistryException {
|
public void updateServiceStateFacet() throws ResourceRegistryException {
|
||||||
|
Date date = Calendar.getInstance().getTime();
|
||||||
|
|
||||||
String state = getState();
|
String state = getState();
|
||||||
stateFacet.setValue(state);
|
stateFacet.setValue(state);
|
||||||
stateFacet = resourceRegistryPublisher.updateFacet(stateFacet);
|
|
||||||
|
boolean found = false;
|
||||||
|
List<EventFacet> eventFacets = eService.getFacets(EventFacet.class);
|
||||||
|
for(EventFacet eventFacet : eventFacets) {
|
||||||
|
if(eventFacet.getEvent().compareTo(state)==0) {
|
||||||
|
found = true;
|
||||||
|
eventFacet.setDate(date);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!found) {
|
||||||
|
EventFacet eventFacet = new EventFacetImpl();
|
||||||
|
eventFacet.setDate(date);
|
||||||
|
eventFacet.setEvent(state);
|
||||||
|
eService.addFacet(eventFacet);
|
||||||
|
}
|
||||||
|
|
||||||
|
eService = resourceRegistryPublisher.updateResource(eService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Activates<HostingNode, EService> createActivatesRelation(EService eService)
|
private Activates<HostingNode, EService> createActivatesRelation(EService eService)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
|
|
||||||
HostingNode hostingNode = applicationContext.container().properties()
|
UUID hostingNodeUUID = UUID.fromString(applicationContext.container().id());
|
||||||
.lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value(HostingNodeManager.class).getHostingNode();
|
HostingNode hostingNode = new HostingNodeImpl();
|
||||||
|
Header header = new HeaderImpl(hostingNodeUUID);
|
||||||
|
hostingNode.setHeader(header);
|
||||||
|
|
||||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||||
|
|
|
@ -111,33 +111,36 @@ public class HostingNodeManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
public void addToContext() throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
UUID uuid = UUID.fromString(containerContext.id());
|
||||||
try {
|
try {
|
||||||
resourceRegistryPublisher.addResourceToCurrentContext(hostingNode, false);
|
resourceRegistryPublisher.addResourceToCurrentContext(HostingNode.NAME, uuid, false);
|
||||||
logger.info("{} successfully added to current context ({})", hostingNode, ContextUtility.getCurrentContextName());
|
logger.info("{} with UUID {} successfully added to current context ({})", HostingNode.NAME, uuid, ContextUtility.getCurrentContextName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to add {} to current context ({})", hostingNode, ContextUtility.getCurrentContextName(), e);
|
logger.error("Unable to add {} with UUID {} to current context ({})", HostingNode.NAME, uuid, ContextUtility.getCurrentContextName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeFromContext()
|
public void removeFromContext()
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
UUID uuid = UUID.fromString(containerContext.id());
|
||||||
try {
|
try {
|
||||||
resourceRegistryPublisher.removeResourceFromCurrentContext(hostingNode, false);
|
resourceRegistryPublisher.removeResourceFromCurrentContext(HostingNode.NAME, uuid, false);
|
||||||
logger.info("{} successfully removed from current context ({})", hostingNode,
|
logger.info("{} with UUID {} successfully removed from current context ({})", HostingNode.NAME, uuid,
|
||||||
ContextUtility.getCurrentContextName());
|
ContextUtility.getCurrentContextName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to remove {} from current context ({})", hostingNode, ContextUtility.getCurrentContextName(), e);
|
logger.error("Unable to remove {} with UUID {} from current context ({})", HostingNode.NAME, uuid, ContextUtility.getCurrentContextName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeFromContext(UUID contextUUID)
|
public void removeFromContext(UUID contextUUID)
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
|
String contextFullName = ContextCache.getInstance().getContextFullNameByUUID(contextUUID);
|
||||||
|
UUID uuid = UUID.fromString(containerContext.id());
|
||||||
try {
|
try {
|
||||||
resourceRegistryPublisher.removeResourceFromContext(hostingNode, contextUUID, false);
|
resourceRegistryPublisher.removeResourceFromContext(HostingNode.NAME, uuid, contextUUID, false);
|
||||||
logger.info("{} successfully removed from context ({})", hostingNode, contextFullName);
|
logger.info("{} with UUID {} successfully removed from context ({})", HostingNode.NAME, uuid, contextFullName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to remove {} from current context ({})", hostingNode, contextFullName, e);
|
logger.error("Unable to remove {} from current context ({})", HostingNode.NAME, uuid, contextFullName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +396,7 @@ public class HostingNodeManager {
|
||||||
locationFacet.setLongitude(site.longitude());
|
locationFacet.setLongitude(site.longitude());
|
||||||
hostingNode.addFacet(locationFacet);
|
hostingNode.addFacet(locationFacet);
|
||||||
|
|
||||||
logger.info("hostingNode instanciated");
|
logger.info("{} with UUID {} instantiated", HostingNode.NAME, uuid);
|
||||||
return hostingNode;
|
return hostingNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue