summaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-03-02 14:42:45 +0000
committerJvD_Ericsson <jeff.van.dam@est.tech>2023-03-10 17:32:30 +0000
commit0606cf6d6dd2cd4630f4cdd14e2e1eee626ca377 (patch)
treefbf0ee90a49cc23ac3a65d325afb15e6c2613182 /catalog-model/src
parent86c6a41b4ecf80b9edf554120ddebf572599c679 (diff)
Support for delete of non normative interface types
Issue-ID: SDC-4423 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: Ic41a8d0e792f4f0c6effd7eb6c9bd74887a0506c
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java2
-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/ModelOperation.java2
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java15
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java8
5 files changed, 59 insertions, 13 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
index b8ddff9907..d8a2d44967 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
@@ -325,7 +325,7 @@ public class DataTypeOperation extends AbstractOperation {
}
public void removeDataTypeFromAdditionalType(final DataTypeDataDefinition dataTypeDataDefinition) {
- modelOperation.removeDataTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, dataTypeDataDefinition.getModel(),
+ modelOperation.removeTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, dataTypeDataDefinition.getModel(),
dataTypeDataDefinition.getName());
}
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 9299aec7e0..7fc97ccabc 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
@@ -17,8 +17,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.model.operations.impl;
+import fj.data.Either;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -27,8 +29,9 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
-
+import javax.annotation.Resource;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
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;
@@ -42,6 +45,7 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.normatives.ElementTypeEnum;
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;
@@ -53,8 +57,6 @@ 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 {
@@ -65,6 +67,9 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
private ArtifactOperation artifactOperation;
@javax.annotation.Resource
private JanusGraphGenericDao janusGraphGenericDao;
+ @Resource
+ private ModelOperation modelOperation;
+
public InterfaceLifecycleOperation() {
super();
}
@@ -816,7 +821,8 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
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);
+ return janusGraphGenericDao.createRelation(from, to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right()
+ .map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus);
}
@Override
@@ -860,7 +866,7 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
List<InterfaceData> interfaceDataList = allInterfaceLifecycleTypes.left().value();
List<InterfaceDefinition> interfaceDefinitions = interfaceDataList.stream().map(this::convertInterfaceDataToInterfaceDefinition)
.filter(interfaceDefinition -> interfaceDefinition.getUniqueId()
- .equalsIgnoreCase(UniqueIdBuilder.buildInterfaceTypeUid(interfaceDefinition.getModel(), interfaceDefinition.getType()))
+ .equalsIgnoreCase(UniqueIdBuilder.buildInterfaceTypeUid(interfaceDefinition.getModel(), interfaceDefinition.getType()))
).collect(Collectors.toList());
for (InterfaceDefinition interfaceDefinition : interfaceDefinitions) {
Either<List<ImmutablePair<OperationData, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = janusGraphGenericDao
@@ -881,11 +887,36 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation
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);
+ UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Interface), uid, GraphEdgeLabels.MODEL_ELEMENT,
+ NodeTypeEnum.Model, ModelData.class);
if (model.isLeft()) {
return model.left().value().getLeft().getName();
}
return null;
}
+
+ public void deleteInterfaceTypeById(String interfaceTypeId) {
+ try (final GraphTraversalSource traversal = janusGraphGenericDao.getJanusGraph().traversal()) {
+ traversal.V()
+ .has(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), interfaceTypeId)
+ .out(GraphEdgeLabels.INTERFACE_OPERATION.getProperty())
+ .toList()
+ .forEach(interfaceOperationVertex -> {
+ traversal.V(interfaceOperationVertex).out(GraphEdgeLabels.PROPERTY.getProperty()).drop().iterate();
+ interfaceOperationVertex.remove();
+ });
+ traversal.V().has(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), interfaceTypeId).toList()
+ .forEach(interfaceTypeVertex -> {
+ traversal.V(interfaceTypeVertex).out(GraphEdgeLabels.PROPERTY.getProperty()).drop().iterate();
+ interfaceTypeVertex.remove();
+ });
+ } catch (Exception e) {
+ log.error("Failed to delete interface type {} and interface operations in graph. {}", interfaceTypeId, e);
+ }
+ }
+
+ public void removeInterfaceTypeFromAdditionalType(InterfaceDefinition interfaceDefinition) {
+ modelOperation.removeTypeFromAdditionalType(ElementTypeEnum.INTERFACE_LIFECYCLE_TYPE, interfaceDefinition.getModel(),
+ interfaceDefinition.getType());
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
index b57c57a9cc..785ca41033 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
@@ -457,7 +457,7 @@ public class ModelOperation {
toscaModelImportCassandraDao.saveAll(modelName, rebuiltModelImportList);
}
- public void removeDataTypeFromAdditionalType(final ElementTypeEnum elementTypeEnum, final String modelName, final String name) {
+ public void removeTypeFromAdditionalType(final ElementTypeEnum elementTypeEnum, final String modelName, final String name) {
final List<ToscaImportByModel> modelImportList = toscaModelImportCassandraDao.findAllByModel(modelName);
final Optional<ToscaImportByModel> additionalTypeDefinitionsImportOptional = modelImportList.stream()
.filter(t -> ADDITIONAL_TYPE_DEFINITIONS_PATH.equals(Path.of(t.getFullPath()))).findAny();
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 b8230ff87a..d73e7092cc 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
@@ -24,6 +24,7 @@ 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.verify;
import static org.mockito.Mockito.when;
import fj.data.Either;
@@ -51,6 +52,7 @@ import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.normatives.ElementTypeEnum;
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;
@@ -70,6 +72,7 @@ public class InterfaceLifecycleOperationTest {
private static String INTERFACE_TYPE = "tosca.interfaces.standard";
JanusGraphGenericDao janusGraphGenericDao = Mockito.mock(JanusGraphGenericDao.class);
+ ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
@InjectMocks
private InterfaceLifecycleOperation interfaceLifecycleOperation = new InterfaceLifecycleOperation();
@@ -217,4 +220,16 @@ public class InterfaceLifecycleOperationTest {
Assert.assertEquals(1, interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(MODEL_NAME).left().value().size());
}
+
+ @Test
+ void removeInterfaceTypeFromAdditionalType() {
+ String modelName = "model";
+ String interfaceType = "tosca.artifact.interface.PreviouslyExistingType1";
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setModel(modelName);
+ interfaceDefinition.setType(interfaceType);
+
+ interfaceLifecycleOperation.removeInterfaceTypeFromAdditionalType(interfaceDefinition);
+ verify(modelOperation).removeTypeFromAdditionalType(ElementTypeEnum.INTERFACE_LIFECYCLE_TYPE, modelName, interfaceType);
+ }
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java
index c68ed71a07..5e9fc199f0 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java
@@ -646,7 +646,7 @@ class ModelOperationTest extends ModelTestBase {
when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(modelImports);
String dataTypeName = "tosca.datatypes.nfv.PreviouslyExistingType1";
- modelOperation.removeDataTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, modelName, dataTypeName);
+ modelOperation.removeTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, modelName, dataTypeName);
ArgumentCaptor<List<ToscaImportByModel>> importListArgumentCaptor = ArgumentCaptor.forClass(List.class);
verify(toscaModelImportCassandraDao).saveAll(eq(modelName), importListArgumentCaptor.capture());
@@ -658,7 +658,7 @@ class ModelOperationTest extends ModelTestBase {
expectedAdditionalTypesImport.setFullPath(ADDITIONAL_TYPE_DEFINITIONS_PATH.toString());
expectedAdditionalTypesImport.setContent(Files.readString(testResourcePath.resolve(Path.of("expected-additional_types-5.yaml"))));
final ToscaImportByModel actualAdditionalTypesImport =
- actualImportList.stream().filter(expectedAdditionalTypesImport::equals).findFirst().orElse(null);
+ actualImportList.stream().filter(expectedAdditionalTypesImport::equals).findFirst().orElse(null);
assertNotNull(actualAdditionalTypesImport);
assertEquals(expectedAdditionalTypesImport.getContent(), actualAdditionalTypesImport.getContent());
}
@@ -679,7 +679,7 @@ class ModelOperationTest extends ModelTestBase {
when(toscaModelImportCassandraDao.findAllByModel(modelName)).thenReturn(modelImports);
String dataTypeName = "tosca.datatypes.nfv.PreviouslyExistingType1";
- modelOperation.removeDataTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, modelName, dataTypeName);
+ modelOperation.removeTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, modelName, dataTypeName);
ArgumentCaptor<List<ToscaImportByModel>> importListArgumentCaptor = ArgumentCaptor.forClass(List.class);
verify(toscaModelImportCassandraDao).saveAll(eq(modelName), importListArgumentCaptor.capture());
@@ -691,7 +691,7 @@ class ModelOperationTest extends ModelTestBase {
expectedAdditionalTypesImport.setFullPath(ADDITIONAL_TYPE_DEFINITIONS_PATH.toString());
expectedAdditionalTypesImport.setContent(Files.readString(testResourcePath.resolve(Path.of("expected-additional_types-6.yaml"))));
final ToscaImportByModel actualAdditionalTypesImport =
- actualImportList.stream().filter(expectedAdditionalTypesImport::equals).findFirst().orElse(null);
+ actualImportList.stream().filter(expectedAdditionalTypesImport::equals).findFirst().orElse(null);
assertNotNull(actualAdditionalTypesImport);
assertEquals(expectedAdditionalTypesImport.getContent(), actualAdditionalTypesImport.getContent());
}