fixing corner cases
This commit is contained in:
parent
5947a095f8
commit
c09eba8a57
|
@ -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.
|
||||
// */
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<HostingNode, EService> 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;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue