summaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2020-09-04 15:27:00 +0100
committerSébastien Determe <sebastien.determe@intl.att.com>2020-09-07 13:28:22 +0000
commit3e9a9769dd21f0b16b3f238e42349cba3b1a78de (patch)
tree1517e5266d5b9ae8e5c386d06937eb503d59d431 /catalog-model
parent84a51513bca9c41c8757db017eb45b2d801da195 (diff)
Enable selection of requirements
Instead of all requirements of the component instances in a component being exposed outside the component, this change will enable the component designer to specifiy which should be exposed outside the component and which are to be internal to the component Change-Id: Ib063f7b8b0aca94896e78a46f069725bae3d494d Issue-ID: SDC-2771 Signed-off-by: MichaelMorris <michael.morris@est.tech> Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java70
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java4
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java52
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java16
4 files changed, 139 insertions, 3 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
index df1f8fd8bf..3cd46ba846 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
@@ -857,8 +857,10 @@ public class NodeTemplateOperation extends BaseOperation {
calculatedRequirements.forEach((key, value) -> {
Map<String, ListRequirementDataDefinition> mapByType =
value.getMapToscaDataDefinition();
- mapByType.forEach((key1, value1) -> value1.getListToscaDataDefinition().forEach(req -> {
+ mapByType.forEach((key1, value1) -> value1.getListToscaDataDefinition().stream()
+ .filter(RequirementDataDefinition::isExternal).forEach(req -> {
req.addToPath(componentInstance.getUniqueId());
+ req.setExternal(false);
allCalculatedReq.add(key1, req);
}));
});
@@ -927,6 +929,72 @@ public class NodeTemplateOperation extends BaseOperation {
}
return StorageOperationStatus.OK;
}
+
+ public StorageOperationStatus updateComponentInstanceRequirement(String componentId, String componentInstanceUniqueId, RequirementDataDefinition requirementDataDefinition) {
+ Either<GraphVertex, JanusGraphOperationStatus> containerVEither = janusGraphDao
+ .getVertexById(componentId, JsonParseFlagEnum.ParseAll);
+ if (containerVEither.isRight()) {
+ JanusGraphOperationStatus error = containerVEither.right().value();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_FETCH_CONTAINER_VERTEX_ERROR, componentId, error);
+ return StorageOperationStatus.GENERAL_ERROR;
+ }
+ GraphVertex containerV = containerVEither.left().value();
+ return updateComponentInstanceRequirement(componentId, componentInstanceUniqueId, requirementDataDefinition, containerV);
+ }
+
+ private StorageOperationStatus updateComponentInstanceRequirement(String componentId, String componentInstanceUniqueId, RequirementDataDefinition requirementDataDefinition, GraphVertex containerV) {
+ Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> existingReqs = getCalculatedRequirements(componentId);
+ if (existingReqs.isRight()) {
+ return existingReqs.right().value();
+ }
+ MapListRequirementDataDefinition componentInstanceRequirementsMap = existingReqs.left().value().getRight().get(componentInstanceUniqueId);
+ if (componentInstanceRequirementsMap == null) {
+ return StorageOperationStatus.NOT_FOUND;
+ }
+ ListRequirementDataDefinition listRequirementDataDefinition = componentInstanceRequirementsMap.getMapToscaDataDefinition().get(requirementDataDefinition.getCapability());
+
+ listRequirementDataDefinition.getListToscaDataDefinition().stream()
+ .filter(e -> requirementDataDefinition.getOwnerId().equals(e.getOwnerId()) && requirementDataDefinition.getName().equals(e.getName()))
+ .forEach(r -> r.setExternal(requirementDataDefinition.isExternal()));
+
+ return updateCalculatedReqOnGraph(componentId, containerV, existingReqs);
+ }
+
+ private Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> getCalculatedRequirements(String componentId) {
+ Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> result = null;
+ Either<GraphVertex, JanusGraphOperationStatus> containerVEither = janusGraphDao
+ .getVertexById(componentId, JsonParseFlagEnum.ParseAll);
+ if (containerVEither.isRight()) {
+ JanusGraphOperationStatus error = containerVEither.right().value();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_FETCH_CONTAINER_VERTEX_ERROR, componentId, error);
+ result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(error));
+ }
+ if (result == null) {
+ GraphVertex containerV = containerVEither.left().value();
+ result = fetchContainerCalculatedRequirement(containerV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
+ }
+ return result;
+ }
+
+ private StorageOperationStatus updateCalculatedReqOnGraph(String componentId, GraphVertex containerV, Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> reqResult
+ ) {
+ containerV.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis());
+ Either<GraphVertex, JanusGraphOperationStatus> updateElement = janusGraphDao.updateVertex(containerV);
+ if (updateElement.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update topology template {} with new relations error {}. ", componentId, updateElement.right().value());
+ return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateElement.right().value());
+ }
+
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Update calculated requirement for container {}", containerV.getUniqueId());
+ Either<GraphVertex, JanusGraphOperationStatus> status = updateOrCopyOnUpdate(reqResult.left().value().getLeft(), containerV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
+ if (status.isRight()) {
+ JanusGraphOperationStatus error = status.right().value();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update calculated requiremnt for container {} error {}", containerV.getUniqueId(), error);
+ return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(error);
+ }
+ return StorageOperationStatus.OK;
+ }
+
private StorageOperationStatus addComponentInstanceToscaDataToNodeTypeContainer(NodeType originNodeType,
ComponentInstanceDataDefinition componentInstance, GraphVertex updatedContainerVertex) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index aa03d761bf..dc9174e464 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -2586,6 +2586,10 @@ public class ToscaOperationFacade {
.map(instanceCapProps -> topologyTemplateOperation.updateComponentInstanceCapabilityProperties(containerComponent, componentInstanceUniqueId, instanceCapProps))
.orElse(StorageOperationStatus.NOT_FOUND);
}
+
+ public StorageOperationStatus updateComponentInstanceRequirement(String containerComponentId, String componentInstanceUniqueId, RequirementDataDefinition requirementDataDefinition) {
+ return nodeTemplateOperation.updateComponentInstanceRequirement(containerComponentId, componentInstanceUniqueId, requirementDataDefinition);
+ }
public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent, String componentInstanceUniqueId) {
MapInterfaceDataDefinition mapInterfaceDataDefinition =
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
index 1455d1e984..aea07799b2 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
@@ -32,6 +32,10 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
import com.google.common.collect.Lists;
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.janusgraph.core.JanusGraphVertex;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
@@ -46,9 +50,9 @@ import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.datatypes.elements.*;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.*;
-import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -56,6 +60,7 @@ import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -286,6 +291,51 @@ public class NodeTemplateOperationTest extends ModelTestBase {
result = operation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances);
Assert.assertEquals(StorageOperationStatus.OK, result);
}
+
+ @Test
+ public void testUpdateComponentInstanceRequirement() {
+ String componentId = "";
+ String componentInstanceId = "requirementOwnerId";
+
+ GraphVertex graphVertex = new GraphVertex();
+ graphVertex.setUniqueId("uniqueId");
+ when(janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(graphVertex));
+ when(janusGraphDao.updateVertex(graphVertex)).thenReturn(Either.left(graphVertex));
+
+ MapListRequirementDataDefinition mapListRequirementDataDefinition = new MapListRequirementDataDefinition();
+ mapListRequirementDataDefinition.add(requirement.getCapability(), requirement);
+ Map<String, MapListRequirementDataDefinition> mapOfRequirements = new HashMap<>();
+ mapOfRequirements.put(requirement.getOwnerId(), mapListRequirementDataDefinition);
+ GraphVertex childVertex = new GraphVertex();
+ childVertex.setJson(mapOfRequirements);
+ when(janusGraphDao.getChildVertex(graphVertex, EdgeLabelEnum.CALCULATED_REQUIREMENTS, JsonParseFlagEnum.ParseJson)).thenReturn(Either.left(childVertex));
+
+ JanusGraphVertex outVertex = Mockito.mock(JanusGraphVertex.class);
+ Edge edge = Mockito.mock(Edge.class);
+ when(edge.outVertex()).thenReturn(outVertex);
+ Iterator<Edge> edgeIterator = new Iterator<Edge>() {
+ private int counter = 0;
+ @Override
+ public boolean hasNext() {
+ return counter++ < 1;
+ }
+
+ @Override
+ public Edge next() {
+ return edge;
+ }
+ };
+ String outId = (String) janusGraphDao
+ .getProperty((JanusGraphVertex) outVertex, GraphPropertyEnum.UNIQUE_ID.getProperty());
+ when(janusGraphDao.getProperty(outVertex, GraphPropertyEnum.UNIQUE_ID.getProperty())).thenReturn("uniqueId");
+ when(janusGraphDao.updateVertex(childVertex)).thenReturn(Either.left(childVertex));
+ JanusGraphVertex janusGraphVertex = Mockito.mock(JanusGraphVertex.class);
+ childVertex.setVertex(janusGraphVertex);
+ when(janusGraphVertex.edges(Direction.IN, EdgeLabelEnum.CALCULATED_REQUIREMENTS.name())).thenReturn(edgeIterator);
+
+ StorageOperationStatus result = operation.updateComponentInstanceRequirement(componentId, componentInstanceId, requirement);
+ assertEquals(StorageOperationStatus.OK, result);
+ }
private ComponentInstance createCompInstance() {
ComponentInstance componentInstance = new ComponentInstance();
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
index 1c730e5718..0aaae48dc8 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadeTest.java
@@ -37,6 +37,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.ArgumentMatchers;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
@@ -70,7 +71,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
-
+import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
@@ -718,6 +719,19 @@ public class ToscaOperationFacadeTest {
.addComponentInstanceToTopologyTemplate(any(), any(), eq("1"), eq(componentInstance), eq(false), eq(user));
}
+ @Test
+ public void testUpdateComponentInstanceRequirement() {
+ String containerComponentId = "containerComponentId";
+ String componentInstanceUniqueId= "componentInstanceUniqueId";
+ RequirementDataDefinition requirementDataDefinition= Mockito.mock(RequirementDataDefinition.class);
+
+ when(nodeTemplateOperationMock.updateComponentInstanceRequirement(containerComponentId, componentInstanceUniqueId, requirementDataDefinition)).thenReturn(StorageOperationStatus.OK);
+ StorageOperationStatus result = testInstance.updateComponentInstanceRequirement(containerComponentId, componentInstanceUniqueId, requirementDataDefinition);
+ assertEquals(StorageOperationStatus.OK, result);
+ verify(nodeTemplateOperationMock, times(1)).updateComponentInstanceRequirement(containerComponentId, componentInstanceUniqueId, requirementDataDefinition);
+
+ }
+
private Either<PolicyDefinition, StorageOperationStatus> associatePolicyToComponentWithStatus(StorageOperationStatus status) {
PolicyDefinition policy = new PolicyDefinition();
String componentId = "componentId";