Interface Operation disappears on VSP update 69/67669/2
authorpriyanshu <pagarwal@amdocs.com>
Wed, 19 Sep 2018 10:30:48 +0000 (16:00 +0530)
committerAvi Gaffa <avi.gaffa@amdocs.com>
Thu, 27 Sep 2018 10:41:36 +0000 (10:41 +0000)
Interface Operation disappears on VSP update

Change-Id: I209e8a41292aa2ccfa4466b3f383d53005b7b08b
Issue-ID: SDC-1772
Signed-off-by: priyanshu <pagarwal@amdocs.com>
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java

index 6bb8c5c..4bceb0c 100644 (file)
@@ -3306,6 +3306,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
             if (newResource.getToscaArtifacts() == null || newResource.getToscaArtifacts().isEmpty()) {
                 setToscaArtifactsPlaceHolders(newResource, user);
             }
+
+            if (newResource.getInterfaces() == null || newResource.getInterfaces().isEmpty()) {
+                newResource.setInterfaces(oldResource.getInterfaces());
+            }
+
             Either<Resource, StorageOperationStatus> overrideResource = toscaOperationFacade
                     .overrideComponent(newResource, oldResource);
 
index 0f124fd..9a87874 100644 (file)
@@ -173,7 +173,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
             return result;
         }
 
-        StorageOperationStatus associateInterfaces = associateInterfacesToResource(topologyTemplateVertex, topologyTemplate);
+        StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
         if (associateInterfaces != StorageOperationStatus.OK) {
             result = Either.right(associateInterfaces);
         return result;
@@ -721,19 +721,23 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
       }
       return TitanOperationStatus.OK;
     }
-    
-    private StorageOperationStatus associateInterfacesToResource(GraphVertex topologyTemplateVertex,
-        TopologyTemplate topologyTemplate) {
-      Map<String, InterfaceDataDefinition> interfaces = topologyTemplate.getInterfaces();
-      return associateInterfacesToComponent(topologyTemplateVertex,interfaces);
-    }
-    
-    public StorageOperationStatus associateInterfacesToComponent(GraphVertex nodeTypeVertex, Map<String, InterfaceDataDefinition> interfaceMap) {
+
+    private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
+      Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
       if (interfaceMap != null && !interfaceMap.isEmpty()) {
-        Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
+        Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
         if (assosiateElementToData.isRight()) {
           return assosiateElementToData.right().value();
         }
+        else {
+          Map<String, OperationDataDefinition> operationMap = interfaceMap.values().stream().filter(op -> MapUtils.isNotEmpty(op.getOperations())).flatMap(a -> a.getOperations().entrySet().stream()).collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));
+          if(MapUtils.isNotEmpty(operationMap)) {
+            Either<GraphVertex, StorageOperationStatus> assosiateOpToInterface = associateElementToData(assosiateElementToData.left().value(), VertexTypeEnum.INTERFACE_OPERATION, EdgeLabelEnum.INTERFACE_OPERATION, operationMap);
+            if (assosiateOpToInterface.isRight()) {
+              return assosiateOpToInterface.right().value();
+            }
+          }
+        }
       }
       return StorageOperationStatus.OK;
     }
@@ -1059,6 +1063,23 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
             Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
         }
 
+        Either<GraphVertex, TitanOperationStatus> getInterfaceVertex = titanDao.getChildVertex(toscaElementVertex, EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.NoParse);
+        if (getInterfaceVertex.isLeft()) {
+            status = titanDao.disassociateAndDeleteLast(getInterfaceVertex.left().value(), Direction.OUT, EdgeLabelEnum.INTERFACE_OPERATION);
+            if (status != TitanOperationStatus.OK) {
+                log.debug("Failed to disassociate interface operations for {} error {}", getInterfaceVertex.left().value().getUniqueId(), status);
+                Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+            }
+            else {
+                status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
+                if (status != TitanOperationStatus.OK) {
+                    log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
+                    Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+                }
+            }
+
+        }
+
         titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
         toscaElementVertex.getVertex().remove();
         log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());