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.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;

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.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;

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.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<HostingNode, EService> 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<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.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<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfList = hostingNode.getConsistsOf();
for (ConsistsOf<? extends Resource, ? extends Facet> 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<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfToRemove = new ArrayList<>();
List<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfList = hostingNode.getConsistsOf();
for (ConsistsOf<? extends Resource, ? extends Facet> 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<HostingNode, MemoryFacet> hasVolatileRAMMemory = new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(
@ -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) {