Added dryRun
This commit is contained in:
parent
a10323735d
commit
afbc42eb8b
|
@ -81,7 +81,7 @@ public class ContextUtility {
|
||||||
return includeInstanceContexts;
|
return includeInstanceContexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getCurrentContextFullName() {
|
public static String getCurrentContextFullName() {
|
||||||
String token = SecurityTokenProvider.instance.get();
|
String token = SecurityTokenProvider.instance.get();
|
||||||
AuthorizationEntry authorizationEntry = null;
|
AuthorizationEntry authorizationEntry = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -773,12 +773,12 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
Map<UUID,JsonNode> affecteElements = internalAddToContext(targetSecurityContext);
|
Map<UUID,JsonNode> affectedInstances = internalAddToContext(targetSecurityContext);
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
logger.info("{} with UUID {} successfully added to Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
|
|
||||||
return affecteElements;
|
return affectedInstances;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID);
|
logger.error("Unable to add {} with UUID {} to Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
if(oDatabaseDocument != null) {
|
if(oDatabaseDocument != null) {
|
||||||
|
@ -812,12 +812,12 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
Map<UUID,JsonNode> affecteElements = internalRemoveFromContext(targetSecurityContext);
|
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid, contextUUID);
|
logger.info("{} with UUID {} successfully removed from Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
|
|
||||||
return affecteElements;
|
return affectedInstances;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
logger.error("Unable to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
|
||||||
if(oDatabaseDocument != null) {
|
if(oDatabaseDocument != null) {
|
||||||
|
|
|
@ -196,10 +196,13 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
||||||
|
|
||||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
|
|
||||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
if(!dryRunContextSharing) {
|
||||||
|
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DO NOT UNCOMMENT
|
* DO NOT UNCOMMENT
|
||||||
* the instance is added internalAddToContext() function after
|
* the instance is added in internalAddToContext() function after
|
||||||
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||||
* affectedInstances.put(uuid, serializeSelfOnly());
|
* affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
*/
|
*/
|
||||||
|
@ -207,8 +210,8 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
||||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||||
|
|
||||||
for(OEdge edge : edges) {
|
for(OEdge edge : edges) {
|
||||||
@SuppressWarnings("rawtypes")
|
RelationManagement<?> relationManagement = getRelationManagement(edge);
|
||||||
RelationManagement relationManagement = getRelationManagement(edge);
|
relationManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||||
affectedInstances.putAll(relationManagement.internalAddToContext(targetSecurityContext));
|
affectedInstances.putAll(relationManagement.internalAddToContext(targetSecurityContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,12 +227,14 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
||||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||||
|
|
||||||
for(OEdge edge : edges) {
|
for(OEdge edge : edges) {
|
||||||
@SuppressWarnings("rawtypes")
|
RelationManagement<?> relationManagement = getRelationManagement(edge);
|
||||||
RelationManagement relationManagement = getRelationManagement(edge);
|
relationManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||||
affectedInstances.putAll(relationManagement.internalRemoveFromContext(targetSecurityContext));
|
affectedInstances.putAll(relationManagement.internalRemoveFromContext(targetSecurityContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
if(!dryRunContextSharing) {
|
||||||
|
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* DO NOT UNCOMMENT
|
* DO NOT UNCOMMENT
|
||||||
* the instance is added internalAddToContext() function after
|
* the instance is added internalAddToContext() function after
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.gcube.informationsystem.resourceregistry.instances.base.relations.Rel
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.utils.PropagationConstraintOrient;
|
import org.gcube.informationsystem.resourceregistry.utils.PropagationConstraintOrient;
|
||||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||||
import org.gcube.informationsystem.utils.ElementMapper;
|
import org.gcube.informationsystem.utils.ElementMapper;
|
||||||
|
@ -71,6 +72,8 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
setWorkingContext(workingContext);
|
setWorkingContext(workingContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PropagationConstraint propagationConstraint;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Needed for ResourceManagement.serializeAsJson() function to check that
|
* Needed for ResourceManagement.serializeAsJson() function to check that
|
||||||
* sourceEntityManagement is the same of the instance is creating this
|
* sourceEntityManagement is the same of the instance is creating this
|
||||||
|
@ -269,6 +272,27 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<UUID,JsonNode> internalAddToContext(SecurityContext targetSecurityContext)
|
||||||
|
throws ContextException, ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
Map<UUID,JsonNode> affectedInstances = reallyAddToContext(targetSecurityContext);
|
||||||
|
if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
|
||||||
|
if(!dryRunContextSharing) {
|
||||||
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
|
element.save();
|
||||||
|
}
|
||||||
|
affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
}
|
||||||
|
return affectedInstances;
|
||||||
|
} catch(ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new ResourceRegistryException(
|
||||||
|
"Error Adding " + elementType + " to " + targetSecurityContext.toString(), e.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
protected Map<UUID,JsonNode> reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
|
@ -279,7 +303,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
AddConstraint addConstraint = AddConstraint.unpropagate;
|
AddConstraint addConstraint = AddConstraint.unpropagate;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PropagationConstraint propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class, element,
|
propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class, element,
|
||||||
Relation.PROPAGATION_CONSTRAINT_PROPERTY);
|
Relation.PROPAGATION_CONSTRAINT_PROPERTY);
|
||||||
if(propagationConstraint.getAddConstraint() != null) {
|
if(propagationConstraint.getAddConstraint() != null) {
|
||||||
addConstraint = propagationConstraint.getAddConstraint();
|
addConstraint = propagationConstraint.getAddConstraint();
|
||||||
|
@ -304,12 +328,16 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
* The relation must be added only in the case the target vertex must be added.
|
* The relation must be added only in the case the target vertex must be added.
|
||||||
* Otherwise we have a relation which point to an entity outside of the context.
|
* Otherwise we have a relation which point to an entity outside of the context.
|
||||||
*/
|
*/
|
||||||
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext(targetSecurityContext));
|
T targetEntityManagement = getTargetEntityManagement();
|
||||||
|
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||||
|
affectedInstances.putAll(targetEntityManagement.internalAddToContext(targetSecurityContext));
|
||||||
|
|
||||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
if(!dryRunContextSharing) {
|
||||||
|
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* DO NOT UNCOMMENT
|
* DO NOT UNCOMMENT
|
||||||
* the instance is added internalAddToContext() function after
|
* the relation instance is added in internalAddToContext() function after
|
||||||
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||||
* affectedInstances.put(uuid, serializeSelfOnly());
|
* affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
*/
|
*/
|
||||||
|
@ -333,12 +361,18 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
|
|
||||||
/* Adding source to Context */
|
/* Adding source to Context */
|
||||||
affectedInstances.putAll(getSourceEntityManagement().internalAddToContext(targetSecurityContext));
|
ResourceManagement resourceManagement = getSourceEntityManagement();
|
||||||
|
resourceManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||||
|
affectedInstances.putAll(resourceManagement.internalAddToContext(targetSecurityContext));
|
||||||
|
|
||||||
/* Adding target to Context */
|
/* Adding target to Context */
|
||||||
|
T targetEntityManagement = getTargetEntityManagement();
|
||||||
|
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||||
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext(targetSecurityContext));
|
affectedInstances.putAll(getTargetEntityManagement().internalAddToContext(targetSecurityContext));
|
||||||
|
|
||||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
if(!dryRunContextSharing) {
|
||||||
|
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||||
|
}
|
||||||
affectedInstances.put(uuid, serializeSelfOnly());
|
affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
|
||||||
return affectedInstances;
|
return affectedInstances;
|
||||||
|
@ -354,7 +388,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
RemoveConstraint removeConstraint = RemoveConstraint.keep;
|
RemoveConstraint removeConstraint = RemoveConstraint.keep;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PropagationConstraint propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class, element,
|
propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class, element,
|
||||||
Relation.PROPAGATION_CONSTRAINT_PROPERTY);
|
Relation.PROPAGATION_CONSTRAINT_PROPERTY);
|
||||||
if(propagationConstraint.getRemoveConstraint() != null) {
|
if(propagationConstraint.getRemoveConstraint() != null) {
|
||||||
removeConstraint = propagationConstraint.getRemoveConstraint();
|
removeConstraint = propagationConstraint.getRemoveConstraint();
|
||||||
|
@ -378,16 +412,21 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
* In any removeConstraint value the relation MUST be removed from context to
|
* In any removeConstraint value the relation MUST be removed from context to
|
||||||
* avoid to have edge having a source outside of the context.
|
* avoid to have edge having a source outside of the context.
|
||||||
*/
|
*/
|
||||||
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
if(!dryRunContextSharing) {
|
||||||
|
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
||||||
|
}
|
||||||
affectedInstances.put(uuid, serializeSelfOnly());
|
affectedInstances.put(uuid, serializeSelfOnly());
|
||||||
|
|
||||||
|
T targetEntityManagement = getTargetEntityManagement();
|
||||||
|
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||||
|
|
||||||
switch(removeConstraint) {
|
switch(removeConstraint) {
|
||||||
case cascade:
|
case cascade:
|
||||||
affectedInstances.putAll(getTargetEntityManagement().internalRemoveFromContext(targetSecurityContext));
|
affectedInstances.putAll(targetEntityManagement.internalRemoveFromContext(targetSecurityContext));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case cascadeWhenOrphan:
|
case cascadeWhenOrphan:
|
||||||
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
OVertex target = (OVertex) targetEntityManagement.getElement();
|
||||||
|
|
||||||
Iterable<OEdge> iterable = target.getEdges(ODirection.IN);
|
Iterable<OEdge> iterable = target.getEdges(ODirection.IN);
|
||||||
Iterator<OEdge> iterator = iterable.iterator();
|
Iterator<OEdge> iterator = iterable.iterator();
|
||||||
|
@ -412,7 +451,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from {}.",
|
"{} point to {} which is not orphan ({} exists). Giving {} directive, it will be not remove from {}.",
|
||||||
element, target, edge, removeConstraint, targetSecurityContext);
|
element, target, edge, removeConstraint, targetSecurityContext);
|
||||||
} else {
|
} else {
|
||||||
affectedInstances.putAll(getTargetEntityManagement().internalRemoveFromContext(targetSecurityContext));
|
affectedInstances.putAll(targetEntityManagement.internalRemoveFromContext(targetSecurityContext));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -113,12 +113,10 @@ public class SharingManager {
|
||||||
String type = node.get(Element.CLASS_PROPERTY).asText();
|
String type = node.get(Element.CLASS_PROPERTY).asText();
|
||||||
String instanceId = node.get(IdentifiableElement.HEADER_PROPERTY).get(Header.UUID_PROPERTY).asText();
|
String instanceId = node.get(IdentifiableElement.HEADER_PROPERTY).get(Header.UUID_PROPERTY).asText();
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
|
||||||
elementManagement.setUUID(UUID.fromString(instanceId));
|
elementManagement.setUUID(UUID.fromString(instanceId));
|
||||||
elementManagement.setDryRunContextSharing(dryRun);
|
elementManagement.setDryRunContextSharing(dryRun);
|
||||||
|
|
||||||
ArrayNode ret = null;
|
|
||||||
if(operation == SharingOperation.ADD) {
|
if(operation == SharingOperation.ADD) {
|
||||||
affectedInstances.putAll(elementManagement.addToContext(UUID.fromString(contextId)));
|
affectedInstances.putAll(elementManagement.addToContext(UUID.fromString(contextId)));
|
||||||
}else {
|
}else {
|
||||||
|
@ -181,17 +179,18 @@ public class SharingManager {
|
||||||
|
|
||||||
CalledMethodProvider.instance.set(calledMethod.toString());
|
CalledMethodProvider.instance.set(calledMethod.toString());
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
ElementManagement<?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
|
||||||
elementManagement.setUUID(UUID.fromString(instanceId));
|
elementManagement.setUUID(UUID.fromString(instanceId));
|
||||||
elementManagement.setDryRunContextSharing(dryRun);
|
elementManagement.setDryRunContextSharing(dryRun);
|
||||||
|
|
||||||
|
UUID contextUUID = UUID.fromString(contextId);
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
Map<UUID,JsonNode> affectedInstances = null;
|
Map<UUID,JsonNode> affectedInstances = null;
|
||||||
if(operation == SharingOperation.ADD) {
|
if(operation == SharingOperation.ADD) {
|
||||||
affectedInstances = elementManagement.addToContext(UUID.fromString(contextId));
|
affectedInstances = elementManagement.addToContext(contextUUID);
|
||||||
}else {
|
}else {
|
||||||
affectedInstances = elementManagement.removeFromContext(UUID.fromString(contextId));
|
affectedInstances = elementManagement.removeFromContext(contextUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -8,21 +8,27 @@ import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||||
|
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||||
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
|
||||||
|
@ -42,6 +48,7 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ElementManage
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
||||||
|
import org.gcube.informationsystem.types.TypeMapper;
|
||||||
import org.gcube.informationsystem.utils.ElementMapper;
|
import org.gcube.informationsystem.utils.ElementMapper;
|
||||||
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.CPUFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||||
|
@ -179,10 +186,15 @@ public class BasicTest extends ContextTest {
|
||||||
Assert.assertTrue(deleted);
|
Assert.assertTrue(deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO test add to context to a resource with only one facet and add propagation constraint to unpropagate.
|
||||||
|
// TODO test remove from context to a facet which is the only facet that characterise a Resource.
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateEServiceHostingNode() throws Exception {
|
public void addRemoveDryRunTest() throws Exception {
|
||||||
EService eService = new EServiceImpl();
|
EService eService = new EServiceImpl();
|
||||||
|
|
||||||
|
// I add only one facet to have the possibility to define the tests easier
|
||||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||||
softwareFacet.setGroup("InformationSystem");
|
softwareFacet.setGroup("InformationSystem");
|
||||||
softwareFacet.setName("resource-registry");
|
softwareFacet.setName("resource-registry");
|
||||||
|
@ -191,30 +203,6 @@ public class BasicTest extends ContextTest {
|
||||||
eService, softwareFacet, null);
|
eService, softwareFacet, null);
|
||||||
eService.addFacet(isIdentifiedBy);
|
eService.addFacet(isIdentifiedBy);
|
||||||
|
|
||||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
|
||||||
accessPointFacet.setEndpoint(new URI("http://localhost"));
|
|
||||||
accessPointFacet.setEntryName("port1");
|
|
||||||
eService.addFacet(accessPointFacet);
|
|
||||||
|
|
||||||
EventFacet eventFacet = new EventFacetImpl();
|
|
||||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
|
||||||
ValueSchema event = new ValueSchemaImpl();
|
|
||||||
event.setValue("Created");
|
|
||||||
eventFacet.setEvent(event);
|
|
||||||
eService.addFacet(eventFacet);
|
|
||||||
|
|
||||||
StateFacet stateFacet = new StateFacetImpl();
|
|
||||||
stateFacet.setValue("ready");
|
|
||||||
eService.addFacet(stateFacet);
|
|
||||||
|
|
||||||
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
|
||||||
licenseFacet.setName("EUPL");
|
|
||||||
licenseFacet
|
|
||||||
.setTextURL(new URL(
|
|
||||||
"https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
|
||||||
eService.addFacet(licenseFacet);
|
|
||||||
|
|
||||||
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setElementType(EService.NAME);
|
resourceManagement.setElementType(EService.NAME);
|
||||||
resourceManagement.setJson(ElementMapper.marshal(eService));
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
||||||
|
@ -224,6 +212,14 @@ public class BasicTest extends ContextTest {
|
||||||
eService = ElementMapper.unmarshal(EService.class, json);
|
eService = ElementMapper.unmarshal(EService.class, json);
|
||||||
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
||||||
|
|
||||||
|
Map<UUID, IdentifiableElement> eServiceInstances = new HashMap<>();
|
||||||
|
eServiceInstances.put(eService.getHeader().getUUID(), eService);
|
||||||
|
for(ConsistsOf<?,?> consistsOf : eService.getConsistsOf()) {
|
||||||
|
eServiceInstances.put(consistsOf.getHeader().getUUID(), consistsOf);
|
||||||
|
eServiceInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HostingNode hostingNode = new HostingNodeImpl();
|
HostingNode hostingNode = new HostingNodeImpl();
|
||||||
|
|
||||||
|
@ -264,6 +260,8 @@ public class BasicTest extends ContextTest {
|
||||||
|
|
||||||
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(
|
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(
|
||||||
hostingNode, eService, null);
|
hostingNode, eService, null);
|
||||||
|
UUID activatedUUID = UUID.randomUUID();
|
||||||
|
activates.setHeader(new HeaderImpl(activatedUUID));
|
||||||
hostingNode.attachResource(activates);
|
hostingNode.attachResource(activates);
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
|
@ -274,7 +272,30 @@ public class BasicTest extends ContextTest {
|
||||||
logger.debug("Created : {}", hnJson);
|
logger.debug("Created : {}", hnJson);
|
||||||
hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
|
hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
|
||||||
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
||||||
UUID uuid = hostingNode.getHeader().getUUID();
|
UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
|
||||||
|
|
||||||
|
|
||||||
|
Map<UUID, IdentifiableElement> hostingNodeInstances = new HashMap<>();
|
||||||
|
hostingNodeInstances.put(hostingNodeUUID, hostingNode);
|
||||||
|
|
||||||
|
for(ConsistsOf<?,?> consistsOf : hostingNode.getConsistsOf()) {
|
||||||
|
hostingNodeInstances.put(consistsOf.getHeader().getUUID(), consistsOf);
|
||||||
|
hostingNodeInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
|
||||||
|
}
|
||||||
|
|
||||||
|
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
|
||||||
|
isRelatedToManagement.setElementType(Activates.NAME);
|
||||||
|
isRelatedToManagement.setUUID(activatedUUID);
|
||||||
|
String activatesString = isRelatedToManagement.read();
|
||||||
|
activates = ElementMapper.unmarshal(Activates.class, activatesString);
|
||||||
|
|
||||||
|
Map<UUID, IdentifiableElement> createdInstances = new HashMap<>();
|
||||||
|
createdInstances.putAll(hostingNodeInstances);
|
||||||
|
/* These should not be added due to default propagation constraint for IsRelatedTo relation
|
||||||
|
createdInstances.put(activatedUUID, activates);
|
||||||
|
createdInstances.putAll(eServiceInstances);
|
||||||
|
*/
|
||||||
|
Assert.assertTrue(createdInstances.size()==9);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
@ -282,18 +303,69 @@ public class BasicTest extends ContextTest {
|
||||||
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
|
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(uuid);
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
|
|
||||||
Map<UUID, JsonNode> affectedInstaces = resourceManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
resourceManagement.setDryRunContextSharing(true);
|
||||||
|
UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID();
|
||||||
Assert.assertTrue(affectedInstaces);
|
Map<UUID, JsonNode> testAffectedInstances = resourceManagement.addToContext(contextUUID);
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(uuid);
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
|
|
||||||
|
try {
|
||||||
|
resourceManagement.read();
|
||||||
|
logger.debug("You should not be able to read {} with UUID {} in {} with UUID {} (i.e., {})",
|
||||||
|
HostingNode.NAME, hostingNodeUUID.toString(), Context.NAME, contextUUID, ContextUtility.getCurrentContextFullName());
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
resourceManagement.setDryRunContextSharing(false);
|
||||||
|
Map<UUID, JsonNode> affectedInstances = resourceManagement.addToContext(contextUUID);
|
||||||
|
logger.debug("Add to Context afffects the following instances {}", affectedInstances.values());
|
||||||
|
|
||||||
|
SortedSet<UUID> testAffectedInstancesUUID = new TreeSet<>(testAffectedInstances.keySet());
|
||||||
|
SortedSet<UUID> affectedInstancesUUID = new TreeSet<>(affectedInstances.keySet());
|
||||||
|
SortedSet<UUID> createdInstancesUUID = new TreeSet<>(createdInstances.keySet());
|
||||||
|
|
||||||
|
logger.debug("Created Instances where {}", createdInstancesUUID);
|
||||||
|
logger.debug("Test Affected Instances where {}", testAffectedInstancesUUID);
|
||||||
|
logger.debug("Affected Instances are {}", affectedInstancesUUID);
|
||||||
|
|
||||||
|
Assert.assertTrue(testAffectedInstancesUUID.size()==affectedInstancesUUID.size());
|
||||||
|
Assert.assertTrue(createdInstancesUUID.size()==affectedInstancesUUID.size());
|
||||||
|
|
||||||
|
Assert.assertTrue(createdInstancesUUID.containsAll(testAffectedInstancesUUID));
|
||||||
|
Assert.assertTrue(testAffectedInstancesUUID.containsAll(createdInstancesUUID));
|
||||||
|
|
||||||
|
Assert.assertTrue(createdInstancesUUID.containsAll(affectedInstancesUUID));
|
||||||
|
Assert.assertTrue(affectedInstancesUUID.containsAll(createdInstancesUUID));
|
||||||
|
|
||||||
|
Assert.assertTrue(testAffectedInstancesUUID.containsAll(affectedInstancesUUID));
|
||||||
|
Assert.assertTrue(affectedInstancesUUID.containsAll(testAffectedInstancesUUID));
|
||||||
|
|
||||||
|
|
||||||
|
for(UUID uuid : affectedInstances.keySet()) {
|
||||||
|
JsonNode testAffectedJsonNode = testAffectedInstances.get(uuid);
|
||||||
|
String testAffectedType = testAffectedJsonNode.get(Element.CLASS_PROPERTY).asText();
|
||||||
|
|
||||||
|
JsonNode affectedJsonNode = affectedInstances.get(uuid);
|
||||||
|
String affectedType = affectedJsonNode.get(Element.CLASS_PROPERTY).asText();
|
||||||
|
|
||||||
|
IdentifiableElement identifiableElement = createdInstances.get(uuid);
|
||||||
|
String createdType = TypeMapper.getType(identifiableElement.getClass());
|
||||||
|
|
||||||
|
Assert.assertTrue(affectedType.compareTo(testAffectedType)==0);
|
||||||
|
Assert.assertTrue(affectedType.compareTo(createdType)==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
|
|
||||||
String hnString = resourceManagement.read();
|
String hnString = resourceManagement.read();
|
||||||
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, hnString);
|
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, hnString);
|
||||||
Assert.assertTrue(readHN.getHeader().getUUID().compareTo(uuid) == 0);
|
Assert.assertTrue(readHN.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||||
|
|
||||||
UUID eServiceUUID = eService.getHeader().getUUID();
|
UUID eServiceUUID = eService.getHeader().getUUID();
|
||||||
try {
|
try {
|
||||||
|
@ -321,7 +393,250 @@ public class BasicTest extends ContextTest {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(uuid);
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
|
boolean deleted = resourceManagement.delete();
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
logger.debug("Setting back default scope");
|
||||||
|
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(eServiceUUID);
|
||||||
|
deleted = resourceManagement.delete();
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateEServiceHostingNode() throws Exception {
|
||||||
|
EService eService = new EServiceImpl();
|
||||||
|
|
||||||
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||||
|
softwareFacet.setGroup("InformationSystem");
|
||||||
|
softwareFacet.setName("resource-registry");
|
||||||
|
softwareFacet.setVersion("1.1.0");
|
||||||
|
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
|
||||||
|
eService, softwareFacet, null);
|
||||||
|
eService.addFacet(isIdentifiedBy);
|
||||||
|
|
||||||
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||||
|
accessPointFacet.setEndpoint(new URI("http://localhost"));
|
||||||
|
accessPointFacet.setEntryName("port1");
|
||||||
|
eService.addFacet(accessPointFacet);
|
||||||
|
|
||||||
|
EventFacet eventFacet = new EventFacetImpl();
|
||||||
|
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||||
|
ValueSchema event = new ValueSchemaImpl();
|
||||||
|
event.setValue("Created");
|
||||||
|
eventFacet.setEvent(event);
|
||||||
|
eService.addFacet(eventFacet);
|
||||||
|
|
||||||
|
StateFacet stateFacet = new StateFacetImpl();
|
||||||
|
stateFacet.setValue("ready");
|
||||||
|
eService.addFacet(stateFacet);
|
||||||
|
|
||||||
|
LicenseFacet licenseFacet = new LicenseFacetImpl();
|
||||||
|
licenseFacet.setName("EUPL");
|
||||||
|
licenseFacet
|
||||||
|
.setTextURL(new URL(
|
||||||
|
"https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
|
||||||
|
eService.addFacet(licenseFacet);
|
||||||
|
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setElementType(EService.NAME);
|
||||||
|
resourceManagement.setJson(ElementMapper.marshal(eService));
|
||||||
|
|
||||||
|
String json = resourceManagement.create();
|
||||||
|
logger.debug("Created : {}", json);
|
||||||
|
eService = ElementMapper.unmarshal(EService.class, json);
|
||||||
|
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
|
||||||
|
|
||||||
|
Map<UUID, IdentifiableElement> eServiceInstances = new HashMap<>();
|
||||||
|
eServiceInstances.put(eService.getHeader().getUUID(), eService);
|
||||||
|
for(ConsistsOf<?,?> consistsOf : eService.getConsistsOf()) {
|
||||||
|
eServiceInstances.put(consistsOf.getHeader().getUUID(), consistsOf);
|
||||||
|
eServiceInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HostingNode hostingNode = new HostingNodeImpl();
|
||||||
|
|
||||||
|
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
|
||||||
|
networkingFacet.setIPAddress("146.48.87.183");
|
||||||
|
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
|
||||||
|
networkingFacet.setDomainName("isti.cnr.it");
|
||||||
|
networkingFacet.setMask("255.255.248.0");
|
||||||
|
networkingFacet.setBroadcastAddress("146.48.87.255");
|
||||||
|
|
||||||
|
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(
|
||||||
|
hostingNode, networkingFacet, null);
|
||||||
|
hostingNode.addFacet(isIdentifiedByHNNF);
|
||||||
|
|
||||||
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||||
|
cpuFacet.setClockSpeed("1 GHz");
|
||||||
|
cpuFacet.setModel("Opteron");
|
||||||
|
cpuFacet.setVendor("AMD");
|
||||||
|
hostingNode.addFacet(cpuFacet);
|
||||||
|
|
||||||
|
MemoryFacet ram = new MemoryFacetImpl();
|
||||||
|
ram.setSize(8);
|
||||||
|
ram.setUnit(MemoryUnit.GB);
|
||||||
|
ram.setUsed(2);
|
||||||
|
|
||||||
|
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory = new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(
|
||||||
|
hostingNode, ram, null);
|
||||||
|
hostingNode.addFacet(hasVolatileMemory);
|
||||||
|
|
||||||
|
MemoryFacet disk = new MemoryFacetImpl();
|
||||||
|
disk.setSize(256);
|
||||||
|
disk.setUnit(MemoryUnit.GB);
|
||||||
|
disk.setUsed(120);
|
||||||
|
|
||||||
|
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory = new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(
|
||||||
|
hostingNode, disk, null);
|
||||||
|
hostingNode.addFacet(hasPersistentMemory);
|
||||||
|
|
||||||
|
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(
|
||||||
|
hostingNode, eService, null);
|
||||||
|
UUID activatedUUID = UUID.randomUUID();
|
||||||
|
activates.setHeader(new HeaderImpl(activatedUUID));
|
||||||
|
hostingNode.attachResource(activates);
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setElementType(HostingNode.NAME);
|
||||||
|
resourceManagement.setJson(ElementMapper.marshal(hostingNode));
|
||||||
|
|
||||||
|
String hnJson = resourceManagement.create();
|
||||||
|
logger.debug("Created : {}", hnJson);
|
||||||
|
hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
|
||||||
|
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
|
||||||
|
UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
|
||||||
|
|
||||||
|
|
||||||
|
Map<UUID, IdentifiableElement> hostingNodeInstances = new HashMap<>();
|
||||||
|
hostingNodeInstances.put(hostingNodeUUID, hostingNode);
|
||||||
|
|
||||||
|
for(ConsistsOf<?,?> consistsOf : hostingNode.getConsistsOf()) {
|
||||||
|
hostingNodeInstances.put(consistsOf.getHeader().getUUID(), consistsOf);
|
||||||
|
hostingNodeInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
|
||||||
|
}
|
||||||
|
|
||||||
|
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
|
||||||
|
isRelatedToManagement.setElementType(Activates.NAME);
|
||||||
|
isRelatedToManagement.setUUID(activatedUUID);
|
||||||
|
String activatesString = isRelatedToManagement.read();
|
||||||
|
activates = ElementMapper.unmarshal(Activates.class, activatesString);
|
||||||
|
|
||||||
|
Map<UUID, IdentifiableElement> createdInstances = new HashMap<>();
|
||||||
|
createdInstances.putAll(hostingNodeInstances);
|
||||||
|
/* These should not be added due to default propagation constraint for IsRelatedTo relation
|
||||||
|
createdInstances.put(activatedUUID, activates);
|
||||||
|
createdInstances.putAll(eServiceInstances);
|
||||||
|
*/
|
||||||
|
Assert.assertTrue(createdInstances.size()==9);
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
logger.debug("Switching to another scope");
|
||||||
|
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
|
|
||||||
|
resourceManagement.setDryRunContextSharing(true);
|
||||||
|
UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID();
|
||||||
|
Map<UUID, JsonNode> testAffectedInstances = resourceManagement.addToContext(contextUUID);
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
|
|
||||||
|
try {
|
||||||
|
resourceManagement.read();
|
||||||
|
logger.debug("You should not be able to read {} with UUID {} in {} with UUID {} (i.e., {})",
|
||||||
|
HostingNode.NAME, hostingNodeUUID.toString(), Context.NAME, contextUUID, ContextUtility.getCurrentContextFullName());
|
||||||
|
}catch (AvailableInAnotherContextException e) {
|
||||||
|
// OK
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
resourceManagement.setDryRunContextSharing(false);
|
||||||
|
Map<UUID, JsonNode> affectedInstances = resourceManagement.addToContext(contextUUID);
|
||||||
|
logger.debug("Add to Context afffects the following instances {}", affectedInstances.values());
|
||||||
|
|
||||||
|
SortedSet<UUID> testAffectedInstancesUUID = new TreeSet<>(testAffectedInstances.keySet());
|
||||||
|
SortedSet<UUID> affectedInstancesUUID = new TreeSet<>(affectedInstances.keySet());
|
||||||
|
SortedSet<UUID> createdInstancesUUID = new TreeSet<>(createdInstances.keySet());
|
||||||
|
|
||||||
|
logger.debug("Created Instances where {}", createdInstancesUUID);
|
||||||
|
logger.debug("Test Affected Instances where {}", testAffectedInstancesUUID);
|
||||||
|
logger.debug("Affected Instances are {}", affectedInstancesUUID);
|
||||||
|
|
||||||
|
Assert.assertTrue(testAffectedInstancesUUID.size()==affectedInstancesUUID.size());
|
||||||
|
Assert.assertTrue(createdInstancesUUID.size()==affectedInstancesUUID.size());
|
||||||
|
|
||||||
|
Assert.assertTrue(createdInstancesUUID.containsAll(testAffectedInstancesUUID));
|
||||||
|
Assert.assertTrue(testAffectedInstancesUUID.containsAll(createdInstancesUUID));
|
||||||
|
|
||||||
|
Assert.assertTrue(createdInstancesUUID.containsAll(affectedInstancesUUID));
|
||||||
|
Assert.assertTrue(affectedInstancesUUID.containsAll(createdInstancesUUID));
|
||||||
|
|
||||||
|
Assert.assertTrue(testAffectedInstancesUUID.containsAll(affectedInstancesUUID));
|
||||||
|
Assert.assertTrue(affectedInstancesUUID.containsAll(testAffectedInstancesUUID));
|
||||||
|
|
||||||
|
|
||||||
|
for(UUID uuid : affectedInstances.keySet()) {
|
||||||
|
JsonNode testAffectedJsonNode = testAffectedInstances.get(uuid);
|
||||||
|
String testAffectedType = testAffectedJsonNode.get(Element.CLASS_PROPERTY).asText();
|
||||||
|
|
||||||
|
JsonNode affectedJsonNode = affectedInstances.get(uuid);
|
||||||
|
String affectedType = affectedJsonNode.get(Element.CLASS_PROPERTY).asText();
|
||||||
|
|
||||||
|
IdentifiableElement identifiableElement = createdInstances.get(uuid);
|
||||||
|
String createdType = TypeMapper.getType(identifiableElement.getClass());
|
||||||
|
|
||||||
|
Assert.assertTrue(affectedType.compareTo(testAffectedType)==0);
|
||||||
|
Assert.assertTrue(affectedType.compareTo(createdType)==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
|
|
||||||
|
String hnString = resourceManagement.read();
|
||||||
|
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, hnString);
|
||||||
|
Assert.assertTrue(readHN.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
|
||||||
|
|
||||||
|
UUID eServiceUUID = eService.getHeader().getUUID();
|
||||||
|
try {
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(eServiceUUID);
|
||||||
|
resourceManagement.read();
|
||||||
|
} catch (ResourceAvailableInAnotherContextException e) {
|
||||||
|
logger.debug("Resource with {} Not Found as Expected",
|
||||||
|
eServiceUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Commented because the behavior has been changed
|
||||||
|
try {
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(eServiceUUID);
|
||||||
|
resourceManagement.delete();
|
||||||
|
logger.debug("You should not be able to delete EService with UUID {}",
|
||||||
|
uuid);
|
||||||
|
throw new Exception(
|
||||||
|
"You should not be able to delete EService with UUID " + uuid);
|
||||||
|
} catch (ResourceAvailableInAnotherContextException e) {
|
||||||
|
logger.debug("Resource with {} Not Deleted as Expected",
|
||||||
|
eServiceUUID);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(hostingNodeUUID);
|
||||||
boolean deleted = resourceManagement.delete();
|
boolean deleted = resourceManagement.delete();
|
||||||
Assert.assertTrue(deleted);
|
Assert.assertTrue(deleted);
|
||||||
|
|
||||||
|
@ -443,8 +758,10 @@ public class BasicTest extends ContextTest {
|
||||||
|
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(hnUUID);
|
resourceManagement.setUUID(hnUUID);
|
||||||
Map<String,JsonNode> affectedInstaces = resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
Map<UUID,JsonNode> affectedInstances = resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||||
Assert.assertTrue(affectedInstaces);
|
logger.debug("Remove from Context afffects the following instances {}", affectedInstances.values());
|
||||||
|
|
||||||
|
// Assert.assertTrue(affectedInstaces);
|
||||||
|
|
||||||
/* The cascading MUST remove the relation and the target so that
|
/* The cascading MUST remove the relation and the target so that
|
||||||
* I MUST not be able to read Activates relation and EService
|
* I MUST not be able to read Activates relation and EService
|
||||||
|
|
Loading…
Reference in New Issue