From c09eba8a57e172a0abd0a1bfc49ed61bb1f47529 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 9 Jun 2022 16:30:59 +0200 Subject: [PATCH] fixing corner cases --- .../handler/resourceregistry/Constants.java | 6 ++++-- .../resourceregistry/HostingNodeHandler.java | 3 +++ .../resourcemanager/EServiceManager.java | 15 ++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/gcube/smartgears/handler/resourceregistry/Constants.java b/src/main/java/org/gcube/smartgears/handler/resourceregistry/Constants.java index b0d9109..57a4920 100644 --- a/src/main/java/org/gcube/smartgears/handler/resourceregistry/Constants.java +++ b/src/main/java/org/gcube/smartgears/handler/resourceregistry/Constants.java @@ -1,5 +1,7 @@ package org.gcube.smartgears.handler.resourceregistry; +import org.gcube.smartgears.handler.resourceregistry.resourcemanager.HostingNodeManager; + /** * Library-wide constants. * @author Luca Frosini @@ -7,8 +9,8 @@ package org.gcube.smartgears.handler.resourceregistry; */ public class Constants { -// public static final String HOSTING_NODE_MANAGER_PROPERT = HostingNodeManager.class.getSimpleName(); -// + public static final String HOSTING_NODE_MANAGER_PROPERTY = HostingNodeManager.class.getSimpleName(); + // /** // * The name of the context property that contains the EService Resource. // */ diff --git a/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java b/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java index 5e04f64..b61cce9 100644 --- a/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java +++ b/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java @@ -31,6 +31,7 @@ import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; +import org.gcube.smartgears.context.Property; import org.gcube.smartgears.context.container.ContainerContext; import org.gcube.smartgears.handler.resourceregistry.resourcemanager.HostingNodeManager; import org.gcube.smartgears.handlers.container.ContainerHandler; @@ -110,6 +111,8 @@ public class HostingNodeHandler extends ContainerHandler { ContextUtility.setContextFromToken(token); hostingNodeManager = new HostingNodeManager(containerContext); hostingNodeManager.createHostingNode(); + containerContext.properties().add(new Property(Constants.HOSTING_NODE_MANAGER_PROPERTY, hostingNodeManager)); + create = false; } else { try { diff --git a/src/main/java/org/gcube/smartgears/handler/resourceregistry/resourcemanager/EServiceManager.java b/src/main/java/org/gcube/smartgears/handler/resourceregistry/resourcemanager/EServiceManager.java index 11188fe..de9dbb1 100644 --- a/src/main/java/org/gcube/smartgears/handler/resourceregistry/resourcemanager/EServiceManager.java +++ b/src/main/java/org/gcube/smartgears/handler/resourceregistry/resourcemanager/EServiceManager.java @@ -4,7 +4,6 @@ import java.net.URI; import java.util.Arrays; import java.util.Calendar; import java.util.Date; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -34,7 +33,6 @@ 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.StateFacetImpl; 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.relations.consistsof.IsIdentifiedByImpl; import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl; @@ -50,6 +48,7 @@ import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activa import org.gcube.smartgears.configuration.application.ApplicationConfiguration; import org.gcube.smartgears.configuration.container.ContainerConfiguration; import org.gcube.smartgears.context.application.ApplicationContext; +import org.gcube.smartgears.handler.resourceregistry.Constants; import org.gcube.smartgears.handler.resourceregistry.ContextUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -247,8 +246,8 @@ public class EServiceManager { stateFacet = new StateFacetImpl(); String state = getState(); stateFacet.setValue(state); - eService.addFacet(stateFacet); stateFacet.setAdditionalProperty("date", date); + eService.addFacet(stateFacet); EventFacet eventFacet = new EventFacetImpl(); eventFacet.setEvent(state); @@ -269,7 +268,6 @@ public class EServiceManager { } catch (NotFoundException e) { eService = instantiateEService(); createActivatesRelation(eService); - stateFacet = eService.getFacets(StateFacet.class).get(0); } catch (AvailableInAnotherContextException e) { addHostingNodeToCurrentContext(); try { @@ -320,10 +318,7 @@ public class EServiceManager { private Activates createActivatesRelation(EService eService) throws ResourceRegistryException { - UUID hostingNodeUUID = UUID.fromString(applicationContext.container().id()); - HostingNode hostingNode = new HostingNodeImpl(); - Header header = new HeaderImpl(hostingNodeUUID); - hostingNode.setHeader(header); + HostingNode hostingNode = ((HostingNodeManager) applicationContext.container().properties().lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value()).getHostingNode(); PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade); @@ -332,7 +327,7 @@ public class EServiceManager { try { activates = resourceRegistryPublisher.createIsRelatedTo(activates); - this.eService = activates.getTarget(); + hostingNode.attachResource(activates); } catch (NotFoundException e) { logger.error("THIS IS REALLY STRANGE. YOU SHOULD NOT BE HERE. Error while creating {}.", activates, e); throw e; @@ -341,8 +336,6 @@ public class EServiceManager { throw e; } - hostingNode.attachResource(activates); - return activates; }