From 74a1d4c72530cdf5e0acfd6ea56ecf2154fa5905 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 21 Dec 2020 23:10:14 +0100 Subject: [PATCH] Fixed code to comply with fixed model --- .../resourceregistry/EServiceHandler.java | 4 +- .../resourceregistry/HostingNodeHandler.java | 1 - .../resourcemanager/EServiceManager.java | 38 +++++++++---------- .../resourcemanager/HostingNodeManager.java | 34 ++++++++--------- 4 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/gcube/smartgears/handler/resourceregistry/EServiceHandler.java b/src/main/java/org/gcube/smartgears/handler/resourceregistry/EServiceHandler.java index e62bd25..352957e 100644 --- a/src/main/java/org/gcube/smartgears/handler/resourceregistry/EServiceHandler.java +++ b/src/main/java/org/gcube/smartgears/handler/resourceregistry/EServiceHandler.java @@ -20,9 +20,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.events.Observes; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; -import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; -import org.gcube.resourcemanagement.model.reference.entities.facets.ServiceStateFacet; -import org.gcube.resourcemanagement.model.reference.entities.resources.EService; +import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.smartgears.context.Property; import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.handler.resourceregistry.resourcemanager.EServiceManager; 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 ab4bb7a..ca11f5f 100644 --- a/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java +++ b/src/main/java/org/gcube/smartgears/handler/resourceregistry/HostingNodeHandler.java @@ -29,7 +29,6 @@ import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.resourcemanagement.model.reference.entities.facets.ContainerStateFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; import org.gcube.smartgears.context.Property; import org.gcube.smartgears.context.container.ContainerContext; 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 02ab45b..a0ac7d7 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 @@ -25,15 +25,15 @@ import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClien import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher; import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory; import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.ServiceStateFacetImpl; 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.properties.ValueSchemaImpl; import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; 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.ServiceStateFacet; 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.resources.EService; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; @@ -65,7 +65,7 @@ public class EServiceManager { // private Activates activates; private EService eService; - private ServiceStateFacet serviceStateFacet; + private StateFacet stateFacet; private ApplicationContext applicationContext; @@ -181,10 +181,10 @@ public class EServiceManager { } } - serviceStateFacet = new ServiceStateFacetImpl(); + stateFacet = new StateFacetImpl(); String state = getState(); - serviceStateFacet.setValue(state); - eService.addFacet(serviceStateFacet); + stateFacet.setValue(state); + eService.addFacet(stateFacet); return eService; } @@ -195,12 +195,12 @@ public class EServiceManager { try { ResourceRegistryClientFactory.includeContextsInInstanceHeader(true); eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID); - serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0); - if(serviceStateFacet==null) { - serviceStateFacet = new ServiceStateFacetImpl(); + stateFacet = eService.getFacets(StateFacet.class).get(0); + if(stateFacet==null) { + stateFacet = new StateFacetImpl(); String state = getState(); - serviceStateFacet.setValue(state); - eService.addFacet(serviceStateFacet); + stateFacet.setValue(state); + eService.addFacet(stateFacet); resourceRegistryPublisher.update(eService); }else{ updateServiceStateFacet(); @@ -208,7 +208,7 @@ public class EServiceManager { } catch (NotFoundException e) { eService = instantiateEService(); createActivatesRelation(eService); - serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0); + stateFacet = eService.getFacets(StateFacet.class).get(0); } catch (AvailableInAnotherContextException e) { addToContext(); try { @@ -221,12 +221,12 @@ public class EServiceManager { // already be in the context due to propagation constraint. createActivatesRelation(eService); } - serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0); - if(serviceStateFacet==null) { - serviceStateFacet = new ServiceStateFacetImpl(); + stateFacet = eService.getFacets(StateFacet.class).get(0); + if(stateFacet==null) { + stateFacet = new StateFacetImpl(); String state = getState(); - serviceStateFacet.setValue(state); - eService.addFacet(serviceStateFacet); + stateFacet.setValue(state); + eService.addFacet(stateFacet); resourceRegistryPublisher.update(eService); }else{ updateServiceStateFacet(); @@ -239,8 +239,8 @@ public class EServiceManager { public void updateServiceStateFacet() throws ResourceRegistryException { String state = getState(); - serviceStateFacet.setValue(state); - serviceStateFacet = resourceRegistryPublisher.updateFacet(serviceStateFacet); + stateFacet.setValue(state); + stateFacet = resourceRegistryPublisher.updateFacet(stateFacet); } private Activates createActivatesRelation(EService eService) diff --git a/src/main/java/org/gcube/smartgears/handler/resourceregistry/resourcemanager/HostingNodeManager.java b/src/main/java/org/gcube/smartgears/handler/resourceregistry/resourcemanager/HostingNodeManager.java index d1349b9..6aed00d 100644 --- a/src/main/java/org/gcube/smartgears/handler/resourceregistry/resourcemanager/HostingNodeManager.java +++ b/src/main/java/org/gcube/smartgears/handler/resourceregistry/resourcemanager/HostingNodeManager.java @@ -44,24 +44,24 @@ import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClien import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher; import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory; import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.ContainerStateFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.LocationFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SimplePropertyFacetImpl; 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.HostingNodeImpl; import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl; import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl; import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.ContainerStateFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.LocationFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit; import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SimplePropertyFacet; 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.resources.HostingNode; import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory; import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory; @@ -138,7 +138,7 @@ public class HostingNodeManager { public HostingNode updateFacets() throws ResourceRegistryException { logger.debug("Updating {}", HostingNode.NAME); - ContainerStateFacet containerStateFacet = null; + StateFacet stateFacet = null; MemoryFacet ramFacet = null; MemoryFacet jvmMemoryFacet = null; MemoryFacet disk = null; @@ -147,9 +147,9 @@ public class HostingNodeManager { List> consistsOfList = hostingNode.getConsistsOf(); for (ConsistsOf c : consistsOfList) { - if (c.getTarget() instanceof ContainerStateFacet) { - containerStateFacet = (ContainerStateFacet) c.getTarget(); - containerStateFacet = getContainerStateFacet(containerStateFacet); + if (c.getTarget() instanceof StateFacet) { + stateFacet = (StateFacet) c.getTarget(); + stateFacet = getStateFacet(stateFacet); continue; } @@ -203,15 +203,15 @@ public class HostingNodeManager { public HostingNode updateStatus() throws ResourceRegistryException { logger.debug("Setting {} down", HostingNode.NAME); - ContainerStateFacet containerStateFacet = null; + StateFacet stateFacet = null; List> consistsOfToRemove = new ArrayList<>(); List> consistsOfList = hostingNode.getConsistsOf(); for (ConsistsOf c : consistsOfList) { - if (c.getTarget() instanceof ContainerStateFacet) { - containerStateFacet = (ContainerStateFacet) c.getTarget(); - containerStateFacet = getContainerStateFacet(containerStateFacet); + if (c.getTarget() instanceof StateFacet) { + stateFacet = (StateFacet) c.getTarget(); + stateFacet = getStateFacet(stateFacet); continue; } consistsOfToRemove.add(c); @@ -303,8 +303,8 @@ public class HostingNodeManager { SimplePropertyFacet simplePropertyFacet = addEnvironmentVariables(containerConfiguration); hostingNode.addFacet(simplePropertyFacet); - ContainerStateFacet containerStateFacet = getContainerStateFacet(null); - hostingNode.addFacet(containerStateFacet); + StateFacet stateFacet = getStateFacet(null); + hostingNode.addFacet(stateFacet); MemoryFacet ramFacet = getRamInfo(null); HasVolatileMemory hasVolatileRAMMemory = new HasVolatileMemoryImpl( @@ -351,13 +351,13 @@ public class HostingNodeManager { return hostingNode; } - private ContainerStateFacet getContainerStateFacet(ContainerStateFacet containerStateFacet) { - if (containerStateFacet == null) { - containerStateFacet = new ContainerStateFacetImpl(); + private StateFacet getStateFacet(StateFacet stateFacet) { + if (stateFacet == null) { + stateFacet = new StateFacetImpl(); } String state = containerContext.lifecycle().state().remoteForm().toLowerCase(); - containerStateFacet.setValue(state); - return containerStateFacet; + stateFacet.setValue(state); + return stateFacet; } private MemoryFacet getDiskSpace(MemoryFacet memoryFacet) {