Fixed code to comply with fixed model

This commit is contained in:
Luca Frosini 2020-12-21 23:10:14 +01:00
parent c3022ae344
commit 74a1d4c725
4 changed files with 37 additions and 40 deletions

View File

@ -20,9 +20,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.events.Observes; import org.gcube.common.events.Observes;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.facets.ServiceStateFacet;
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;

View File

@ -29,7 +29,6 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; 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.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.smartgears.context.Property; import org.gcube.smartgears.context.Property;
import org.gcube.smartgears.context.container.ContainerContext; import org.gcube.smartgears.context.container.ContainerContext;

View File

@ -25,15 +25,15 @@ 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.ServiceStateFacetImpl;
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.resources.EServiceImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
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.ServiceStateFacet;
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.resources.EService; import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
@ -65,7 +65,7 @@ public class EServiceManager {
// private Activates<HostingNode, EService> activates; // private Activates<HostingNode, EService> activates;
private EService eService; private EService eService;
private ServiceStateFacet serviceStateFacet; private StateFacet stateFacet;
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@ -181,10 +181,10 @@ public class EServiceManager {
} }
} }
serviceStateFacet = new ServiceStateFacetImpl(); stateFacet = new StateFacetImpl();
String state = getState(); String state = getState();
serviceStateFacet.setValue(state); stateFacet.setValue(state);
eService.addFacet(serviceStateFacet); eService.addFacet(stateFacet);
return eService; return eService;
} }
@ -195,12 +195,12 @@ public class EServiceManager {
try { try {
ResourceRegistryClientFactory.includeContextsInInstanceHeader(true); ResourceRegistryClientFactory.includeContextsInInstanceHeader(true);
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID); eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0); stateFacet = eService.getFacets(StateFacet.class).get(0);
if(serviceStateFacet==null) { if(stateFacet==null) {
serviceStateFacet = new ServiceStateFacetImpl(); stateFacet = new StateFacetImpl();
String state = getState(); String state = getState();
serviceStateFacet.setValue(state); stateFacet.setValue(state);
eService.addFacet(serviceStateFacet); eService.addFacet(stateFacet);
resourceRegistryPublisher.update(eService); resourceRegistryPublisher.update(eService);
}else{ }else{
updateServiceStateFacet(); updateServiceStateFacet();
@ -208,7 +208,7 @@ public class EServiceManager {
} catch (NotFoundException e) { } catch (NotFoundException e) {
eService = instantiateEService(); eService = instantiateEService();
createActivatesRelation(eService); createActivatesRelation(eService);
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0); stateFacet = eService.getFacets(StateFacet.class).get(0);
} catch (AvailableInAnotherContextException e) { } catch (AvailableInAnotherContextException e) {
addToContext(); addToContext();
try { try {
@ -221,12 +221,12 @@ public class EServiceManager {
// already be in the context due to propagation constraint. // already be in the context due to propagation constraint.
createActivatesRelation(eService); createActivatesRelation(eService);
} }
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0); stateFacet = eService.getFacets(StateFacet.class).get(0);
if(serviceStateFacet==null) { if(stateFacet==null) {
serviceStateFacet = new ServiceStateFacetImpl(); stateFacet = new StateFacetImpl();
String state = getState(); String state = getState();
serviceStateFacet.setValue(state); stateFacet.setValue(state);
eService.addFacet(serviceStateFacet); eService.addFacet(stateFacet);
resourceRegistryPublisher.update(eService); resourceRegistryPublisher.update(eService);
}else{ }else{
updateServiceStateFacet(); updateServiceStateFacet();
@ -239,8 +239,8 @@ public class EServiceManager {
public void updateServiceStateFacet() throws ResourceRegistryException { public void updateServiceStateFacet() throws ResourceRegistryException {
String state = getState(); String state = getState();
serviceStateFacet.setValue(state); stateFacet.setValue(state);
serviceStateFacet = resourceRegistryPublisher.updateFacet(serviceStateFacet); stateFacet = resourceRegistryPublisher.updateFacet(stateFacet);
} }
private Activates<HostingNode, EService> createActivatesRelation(EService eService) private Activates<HostingNode, EService> createActivatesRelation(EService eService)

View File

@ -44,24 +44,24 @@ 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.CPUFacetImpl; 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.LocationFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl; 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.NetworkingFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SimplePropertyFacetImpl; 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.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.entities.resources.HostingNodeImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl; 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.HasVolatileMemoryImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; 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.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.LocationFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet; 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.MemoryFacet.MemoryUnit;
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet; 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.SimplePropertyFacet;
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.resources.HostingNode; 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.HasPersistentMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory; import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
@ -138,7 +138,7 @@ public class HostingNodeManager {
public HostingNode updateFacets() throws ResourceRegistryException { public HostingNode updateFacets() throws ResourceRegistryException {
logger.debug("Updating {}", HostingNode.NAME); logger.debug("Updating {}", HostingNode.NAME);
ContainerStateFacet containerStateFacet = null; StateFacet stateFacet = null;
MemoryFacet ramFacet = null; MemoryFacet ramFacet = null;
MemoryFacet jvmMemoryFacet = null; MemoryFacet jvmMemoryFacet = null;
MemoryFacet disk = null; MemoryFacet disk = null;
@ -147,9 +147,9 @@ public class HostingNodeManager {
List<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfList = hostingNode.getConsistsOf(); List<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfList = hostingNode.getConsistsOf();
for (ConsistsOf<? extends Resource, ? extends Facet> c : consistsOfList) { for (ConsistsOf<? extends Resource, ? extends Facet> c : consistsOfList) {
if (c.getTarget() instanceof ContainerStateFacet) { if (c.getTarget() instanceof StateFacet) {
containerStateFacet = (ContainerStateFacet) c.getTarget(); stateFacet = (StateFacet) c.getTarget();
containerStateFacet = getContainerStateFacet(containerStateFacet); stateFacet = getStateFacet(stateFacet);
continue; continue;
} }
@ -203,15 +203,15 @@ public class HostingNodeManager {
public HostingNode updateStatus() throws ResourceRegistryException { public HostingNode updateStatus() throws ResourceRegistryException {
logger.debug("Setting {} down", HostingNode.NAME); logger.debug("Setting {} down", HostingNode.NAME);
ContainerStateFacet containerStateFacet = null; StateFacet stateFacet = null;
List<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfToRemove = new ArrayList<>(); List<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfToRemove = new ArrayList<>();
List<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfList = hostingNode.getConsistsOf(); List<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfList = hostingNode.getConsistsOf();
for (ConsistsOf<? extends Resource, ? extends Facet> c : consistsOfList) { for (ConsistsOf<? extends Resource, ? extends Facet> c : consistsOfList) {
if (c.getTarget() instanceof ContainerStateFacet) { if (c.getTarget() instanceof StateFacet) {
containerStateFacet = (ContainerStateFacet) c.getTarget(); stateFacet = (StateFacet) c.getTarget();
containerStateFacet = getContainerStateFacet(containerStateFacet); stateFacet = getStateFacet(stateFacet);
continue; continue;
} }
consistsOfToRemove.add(c); consistsOfToRemove.add(c);
@ -303,8 +303,8 @@ public class HostingNodeManager {
SimplePropertyFacet simplePropertyFacet = addEnvironmentVariables(containerConfiguration); SimplePropertyFacet simplePropertyFacet = addEnvironmentVariables(containerConfiguration);
hostingNode.addFacet(simplePropertyFacet); hostingNode.addFacet(simplePropertyFacet);
ContainerStateFacet containerStateFacet = getContainerStateFacet(null); StateFacet stateFacet = getStateFacet(null);
hostingNode.addFacet(containerStateFacet); hostingNode.addFacet(stateFacet);
MemoryFacet ramFacet = getRamInfo(null); MemoryFacet ramFacet = getRamInfo(null);
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileRAMMemory = new HasVolatileMemoryImpl<HostingNode, MemoryFacet>( HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileRAMMemory = new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(
@ -351,13 +351,13 @@ public class HostingNodeManager {
return hostingNode; return hostingNode;
} }
private ContainerStateFacet getContainerStateFacet(ContainerStateFacet containerStateFacet) { private StateFacet getStateFacet(StateFacet stateFacet) {
if (containerStateFacet == null) { if (stateFacet == null) {
containerStateFacet = new ContainerStateFacetImpl(); stateFacet = new StateFacetImpl();
} }
String state = containerContext.lifecycle().state().remoteForm().toLowerCase(); String state = containerContext.lifecycle().state().remoteForm().toLowerCase();
containerStateFacet.setValue(state); stateFacet.setValue(state);
return containerStateFacet; return stateFacet;
} }
private MemoryFacet getDiskSpace(MemoryFacet memoryFacet) { private MemoryFacet getDiskSpace(MemoryFacet memoryFacet) {