aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
authordavsad <david.sadlier@est.tech>2021-06-16 10:36:24 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-21 14:12:28 +0000
commita3da4a7625f75f719a0ef1ffe1c2bef87828d2f3 (patch)
tree2673985092a7ae9e2fb2acccdfa48afff6b2c4f1 /catalog-model/src
parent8a312e6cf2bc0a0c539712b03e75ca3fcfe909ff (diff)
Support for associating interface types to models
Issue-ID: SDC-3639 Change-Id: I5eaa9ffbe3c88416bf17ff9a94e76faad79fe888 Signed-off-by: davsad <david.sadlier@est.tech>
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java15
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java45
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java4
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java56
4 files changed, 96 insertions, 24 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java
index f4b0e8e522..13d80df4ea 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java
@@ -19,23 +19,30 @@
*/
package org.openecomp.sdc.be.model;
-import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Map;
import java.util.stream.Collectors;
+
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
/**
* Definition of the operations that can be performed on (instances of) a Node Type.
*
* @author esofer
*/
+@NoArgsConstructor
public class InterfaceDefinition extends InterfaceDataDefinition implements IOperationParameter {
- public InterfaceDefinition() {
- super();
- }
+ @Getter
+ @Setter
+ private String model;
public InterfaceDefinition(String type, String description, Map<String, Operation> operations) {
super(type, description);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
index a4d8ac9152..3fa1f8933d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java
@@ -19,7 +19,6 @@
*/
package org.openecomp.sdc.be.model.operations.impl;
-import fj.data.Either;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -28,8 +27,10 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -45,11 +46,15 @@ import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.ArtifactData;
import org.openecomp.sdc.be.resources.data.InterfaceData;
+import org.openecomp.sdc.be.resources.data.ModelData;
import org.openecomp.sdc.be.resources.data.OperationData;
import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
+import org.openecomp.sdc.be.resources.data.UniqueIdData;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;
+import fj.data.Either;
+
@Component("interface-operation")
public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation {
@@ -96,7 +101,9 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
private InterfaceDefinition convertInterfaceDataToInterfaceDefinition(InterfaceData interfaceData) {
log.debug("The object returned after create interface is {}", interfaceData);
- return new InterfaceDefinition(interfaceData.getInterfaceDataDefinition());
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition(interfaceData.getInterfaceDataDefinition());
+ interfaceDefinition.setModel(getModelAssociatedToInterface(interfaceData.getUniqueId()));
+ return interfaceDefinition;
}
private Operation convertOperationDataToOperation(OperationData operationData) {
@@ -743,8 +750,8 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
public Either<InterfaceDefinition, StorageOperationStatus> createInterfaceType(InterfaceDefinition interf, boolean inTransaction) {
Either<InterfaceDefinition, StorageOperationStatus> result = null;
try {
+ interf.setUniqueId(UniqueIdBuilder.buildInterfaceTypeUid(interf.getModel(), interf.getType()));
InterfaceData interfaceData = new InterfaceData(interf);
- interf.setUniqueId(interf.getType().toLowerCase());
Either<InterfaceData, JanusGraphOperationStatus> existInterface = janusGraphGenericDao
.getNode(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), InterfaceData.class);
if (existInterface.isLeft()) {
@@ -753,7 +760,6 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
result = Either.right(StorageOperationStatus.ENTITY_ALREADY_EXISTS);
return result;
}
- log.debug("Before adding interface type to graph {}", interfaceData);
Either<InterfaceData, JanusGraphOperationStatus> createNodeResult = janusGraphGenericDao.createNode(interfaceData, InterfaceData.class);
log.debug("After adding property type to graph {}", interfaceData);
if (createNodeResult.isRight()) {
@@ -782,6 +788,11 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
}
interfaceDefResult.setOperationsMap(newOperations);
}
+ final Either<GraphRelation, StorageOperationStatus> modelRelationship = addInterfaceTypeToModel(interf);
+ if (modelRelationship.isRight()) {
+ return Either.right(modelRelationship.right().value());
+ }
+
result = Either.left(interfaceDefResult);
return result;
} finally {
@@ -797,6 +808,17 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
}
}
+ private Either<GraphRelation, StorageOperationStatus> addInterfaceTypeToModel(final InterfaceDefinition interfaceDefinition) {
+ final String model = interfaceDefinition.getModel();
+ if (model == null) {
+ return Either.left(null);
+ }
+ final GraphNode from = new UniqueIdData(NodeTypeEnum.Model, UniqueIdBuilder.buildModelUid(model));
+ final GraphNode to = new UniqueIdData(NodeTypeEnum.Interface, interfaceDefinition.getUniqueId());
+ log.info("Connecting model {} to type {}", from, to);
+ return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right().map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus);
+ }
+
@Override
public Either<InterfaceDefinition, StorageOperationStatus> getInterface(String interfaceId) {
Either<InterfaceData, JanusGraphOperationStatus> getResult = janusGraphGenericDao
@@ -837,8 +859,9 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>();
List<InterfaceData> interfaceDataList = allInterfaceLifecycleTypes.left().value();
List<InterfaceDefinition> interfaceDefinitions = interfaceDataList.stream().map(this::convertInterfaceDataToInterfaceDefinition)
- .filter(interfaceDefinition -> interfaceDefinition.getUniqueId().equalsIgnoreCase((interfaceDefinition.getType())))
- .collect(Collectors.toList());
+ .filter(interfaceDefinition -> interfaceDefinition.getUniqueId()
+ .equalsIgnoreCase(UniqueIdBuilder.buildInterfaceTypeUid(interfaceDefinition.getModel(), interfaceDefinition.getType()))
+ ).collect(Collectors.toList());
for (InterfaceDefinition interfaceDefinition : interfaceDefinitions) {
Either<List<ImmutablePair<OperationData, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = janusGraphGenericDao
.getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), interfaceDefinition.getUniqueId(),
@@ -855,4 +878,14 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
}
return Either.left(interfaceTypes);
}
+
+ private String getModelAssociatedToInterface(String uid) {
+ final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> model = janusGraphGenericDao.getParentNode(
+ UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Interface), uid, GraphEdgeLabels.MODEL_ELEMENT,
+ NodeTypeEnum.Model, ModelData.class);
+ if (model.isLeft()) {
+ return model.left().value().getLeft().getName();
+ }
+ return null;
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
index a433698ce5..8f1cbae1bb 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
@@ -97,6 +97,10 @@ public class UniqueIdBuilder {
return StringUtils.isEmpty(modelName) ? type : modelName + DOT + type;
}
+ public static String buildInterfaceTypeUid(final String modelName, String type) {
+ return StringUtils.isEmpty(modelName) ? type : modelName + DOT + type;
+ }
+
public static String buildAttributeUid(String resourceId, String attName) {
return buildTypeUid(NodeTypeEnum.Attribute.getName(), resourceId, attName);
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java
index 8262d54bc4..0b5a7fae81 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java
@@ -20,7 +20,17 @@
package org.openecomp.sdc.be.model.operations.impl;
-import fj.data.Either;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Assert;
import org.junit.Before;
@@ -31,6 +41,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -42,6 +53,7 @@ import org.openecomp.sdc.be.model.ModelTestBase;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil;
import org.openecomp.sdc.be.resources.data.InterfaceData;
+import org.openecomp.sdc.be.resources.data.ModelData;
import org.openecomp.sdc.be.resources.data.OperationData;
import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
import org.openecomp.sdc.be.resources.data.UserData;
@@ -49,22 +61,15 @@ import org.openecomp.sdc.be.resources.data.category.CategoryData;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
+import fj.data.Either;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
public class InterfaceLifecycleOperationTest {
private static String USER_ID = "muUserId";
private static String CATEGORY_NAME = "category/mycategory";
+ private static String MODEL_NAME = "Test";
+ private static String INTERFACE_TYPE = "tosca.interfaces.standard";
JanusGraphGenericDao janusGraphGenericDao = Mockito.mock(JanusGraphGenericDao.class);
@InjectMocks
@@ -91,9 +96,9 @@ public class InterfaceLifecycleOperationTest {
private InterfaceDefinition buildInterfaceDefinition() {
InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
- interfaceDefinition.setType("tosca.interfaces.standard");
+ interfaceDefinition.setType(INTERFACE_TYPE);
interfaceDefinition.setCreationDate(101232L);
-
+ interfaceDefinition.setModel(MODEL_NAME);
return interfaceDefinition;
}
@@ -173,9 +178,32 @@ public class InterfaceLifecycleOperationTest {
List<ImmutablePair<OperationData, GraphEdge>> list = new ArrayList<>();
Either<List<ImmutablePair<OperationData, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = Either.left(list);
when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(childrenNodes);
-
+ when(janusGraphGenericDao.getParentNode(any(), any(), any(), any(), any()))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
Assert.assertEquals(types.left().value().size(),1);
}
+ @Test
+ public void testGetAllInterfaceLifecycleTypesWithModel() {
+ final var uid = UniqueIdBuilder.buildInterfaceTypeUid(MODEL_NAME, INTERFACE_TYPE);
+ final var modelData = new ModelData(MODEL_NAME, uid);
+ final ImmutablePair<GraphNode, GraphEdge> modelNode = new ImmutablePair<>(modelData, Mockito.mock(GraphEdge.class));
+
+ final InterfaceData interfaceData = new InterfaceData();
+ interfaceData.getInterfaceDataDefinition().setUniqueId(uid);
+ interfaceData.getInterfaceDataDefinition().setType(INTERFACE_TYPE);
+
+ final List<InterfaceData> interfaceTypes = new ArrayList<InterfaceData>();
+ interfaceTypes.add(interfaceData);
+
+ when(janusGraphGenericDao.getParentNode(any(), any(), any(), any(), any()))
+ .thenReturn(Either.left(modelNode));
+ when(janusGraphGenericDao
+ .getByCriteria(NodeTypeEnum.Interface, Collections.emptyMap(), InterfaceData.class)).thenReturn(Either.left(interfaceTypes));
+ when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(Either.left(Collections.emptyList()));
+
+ Assert.assertEquals(1, interfaceLifecycleOperation.getAllInterfaceLifecycleTypes().left().value().size());
+ }
+
}