Fix some deallocate issues 70/116670/1
authorzm330 <zhangminyj@chinamobile.com>
Thu, 7 Jan 2021 12:14:45 +0000 (20:14 +0800)
committerzm330 <zhangminyj@chinamobile.com>
Thu, 7 Jan 2021 12:14:58 +0000 (20:14 +0800)
Issue-ID: SO-3411

Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Change-Id: Ie61983b9e9567bd21e5cd12cda4d76ec422c5dee

adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationService.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteSliceService.groovy
bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteSliceService.bpmn
common/src/main/java/org/onap/so/beans/nsmf/NssmfRequest.java

index 96f2956..7c4bd50 100644 (file)
@@ -100,7 +100,7 @@ public abstract class ExternalNssmfManager extends BaseNssmfManager {
                 restUtil.createServiceInstance(nssiInstance, serviceInfo);
             } else if (ActionType.DEALLOCATE.equals(jobOperType)) {
                 // TODO
-                // restUtil.deleteServiceInstance(serviceInfo);
+                restUtil.deleteServiceInstance(serviceInfo);
             }
         }
     }
index b94c81b..d00f349 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.onap.so.bpmn.infrastructure.scripts
 
+import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri
 
 import static org.apache.commons.lang3.StringUtils.isBlank
 import javax.ws.rs.NotFoundException
@@ -319,12 +320,12 @@ class DeleteCommunicationService extends AbstractServiceTaskProcessor {
                 CommunicationServiceProfile csProfile = csProfiles.getCommunicationServiceProfile().get(0)
                 profileId = csProfile ? csProfile.getProfileId() : ""
             }
-            resourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId).communicationServiceProfile(profileId))
-            if (!getAAIClient().exists(resourceUri)) {
+            AAISimpleUri profileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId).communicationServiceProfile(profileId))
+            if (!getAAIClient().exists(profileUri)) {
                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "communication service profile was not found in aai")
             }
 
-            getAAIClient().delete(resourceUri)
+            getAAIClient().delete(profileUri)
             LOGGER.debug("end delete communication service profile from AAI")
         }
         catch (any)
index 2889f79..5fd06fd 100644 (file)
  */
 package org.onap.so.bpmn.infrastructure.scripts
 
-import org.onap.aai.domain.yang.SliceProfiles
-import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
-
-import static org.apache.commons.lang3.StringUtils.isBlank
-import javax.ws.rs.NotFoundException
-import javax.ws.rs.core.Response
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.onap.aai.domain.yang.AllottedResource
 import org.onap.aai.domain.yang.AllottedResources
 import org.onap.aai.domain.yang.Relationship
 import org.onap.aai.domain.yang.ServiceInstance
-import org.onap.aai.domain.yang.ServiceProfile
-import org.onap.aai.domain.yang.ServiceProfiles
 import org.onap.aaiclient.client.aai.AAIObjectName
 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
+import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
@@ -48,6 +41,11 @@ import org.onap.so.client.HttpClientFactory
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 
+import javax.ws.rs.NotFoundException
+import javax.ws.rs.core.Response
+
+import static org.apache.commons.lang3.StringUtils.isBlank
+
 /**
  * This groovy class supports the <class>DoDeleteSliceService.bpmn</class> process.
  *
@@ -193,13 +191,27 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor {
     {
         LOGGER.trace(" *****${PREFIX} Start getNSIFromAAI *****")
         String nsiId = execution.getVariable("nsiId")
+        List<String> nssiIdList = getNSSIIdList(execution, nsiId)
+        String msg = "nsiId: ${nsiId}, nssiIdList:"
+        msg+= nssiIdList.join(",")
+        LOGGER.info(msg)
+        execution.setVariable("nssiIdList", nssiIdList)
+        LOGGER.trace(" *****${PREFIX} Exit getNSIFromAAI *****")
+    }
+    /**
+     * Get NSSI Id from AAI
+     * @param execution
+     * @param nsiId
+     * @return
+     */
+    private List<String> getNSSIIdList(DelegateExecution execution, String nsiId){
+        List<String> nssiIdList = []
+
         try
         {
-            String errorMsg = "query nsi from aai failed."
+            String errorMsg = "query nssi from aai failed."
             AAIResultWrapper wrapper = queryAAI(execution, Types.SERVICE_INSTANCE, nsiId, errorMsg)
-            Optional<ServiceInstance> si =wrapper.asBean(ServiceInstance.class)
-            List<String> nssiIdList = []
-            String msg = "nsiId:${nsiId},nssiIdList:"
+            Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
             if(si.isPresent())
             {
                 List<Relationship> relationshipList = si.get().getRelationshipList()?.getRelationship()
@@ -217,15 +229,12 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor {
                             ServiceInstance instance = serviceInstance.get()
                             if ("nssi".equalsIgnoreCase(instance.getServiceRole())) {
                                 nssiId = instance.getServiceInstanceId()
+                                nssiIdList.add(nssiId)
                             }
                         }
-                        nssiIdList.add(nssiId)
-                        msg+="${nssiId}, "
                     }
                 }
             }
-            LOGGER.info(msg)
-            execution.setVariable("nssiIdList", nssiIdList)
         }
         catch(BpmnError e){
             throw e
@@ -235,7 +244,7 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor {
             LOGGER.error(msg)
             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
         }
-        LOGGER.trace(" *****${PREFIX} Exit getNSIFromAAI *****")
+        return nssiIdList
     }
 
     /**
@@ -396,6 +405,7 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor {
         LOGGER.debug("Start terminateNSIQuery")
 
         return
+
         //To test
         String requestId = execution.getVariable("msoRequestId")
         String nxlId = currentNSSI['nsiServiceInstanceId']
@@ -446,4 +456,26 @@ class DoDeleteSliceService extends AbstractServiceTaskProcessor {
         }
         LOGGER.debug("Finish terminateNSIQuery")
     }
+
+
+    /**
+     * If no nssi,delete NSI from AAI
+     * @param execution
+     */
+    void deleteNSIInstance(DelegateExecution execution){
+        def currentNSSI = execution.getVariable("currentNSSI")
+        def nsiId = currentNSSI['nsiServiceInstanceId']
+        List<String> nssiIdList = getNSSIIdList(execution, nsiId)
+        try
+        {
+            if(0 == nssiIdList.size()){
+                AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("serviceType")).serviceInstance(nsiId))
+                getAAIClient().delete(serviceInstanceUri)
+            }
+        } catch (Exception ex) {
+            LOGGER.debug( "Failed to delete NSI instance.")
+            exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Failed to delete NSI instance.")
+        }
+
+    }
 }
index 9edb612..f1534a0 100644 (file)
@@ -34,9 +34,9 @@ ddss.getNSSIListFromAAI(execution)</bpmn:script>
       <bpmn:outgoing>SequenceFlow_0926ghe</bpmn:outgoing>
     </bpmn:exclusiveGateway>
     <bpmn:endEvent id="EndEvent_0jaitqv" name="End">
-      <bpmn:incoming>SequenceFlow_1c4fjbv</bpmn:incoming>
+      <bpmn:incoming>SequenceFlow_1odnvjl</bpmn:incoming>
     </bpmn:endEvent>
-    <bpmn:sequenceFlow id="SequenceFlow_1c4fjbv" name="yes" sourceRef="ExclusiveGateway_1ogbunu" targetRef="EndEvent_0jaitqv">
+    <bpmn:sequenceFlow id="SequenceFlow_1c4fjbv" name="yes" sourceRef="ExclusiveGateway_1ogbunu" targetRef="Task_10yni6k">
       <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{(execution.getVariable("isAllNSSIFinished" )  == true)}</bpmn:conditionExpression>
     </bpmn:sequenceFlow>
     <bpmn:sequenceFlow id="SequenceFlow_0c58sw3" sourceRef="Task_1rc7mcw" targetRef="ScriptTask_159855t" />
@@ -96,6 +96,14 @@ dss.terminateNSIQuery(execution)</bpmn:script>
     <bpmn:sequenceFlow id="SequenceFlow_17tvomo" sourceRef="Task_1iomfas" targetRef="Task_1rc7mcw" />
     <bpmn:sequenceFlow id="SequenceFlow_1aa2ek0" sourceRef="Task_1u755sr" targetRef="Task_1iuls9p" />
     <bpmn:sequenceFlow id="SequenceFlow_1252rbf" sourceRef="Task_1iuls9p" targetRef="Task_1iomfas" />
+    <bpmn:sequenceFlow id="SequenceFlow_1odnvjl" sourceRef="Task_10yni6k" targetRef="EndEvent_0jaitqv" />
+    <bpmn:scriptTask id="Task_10yni6k" name="DeleteNSIFromAAI" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_1c4fjbv</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_1odnvjl</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def ddss= new DoDeleteSliceService()
+ddss.deleteNSIInstance(execution)</bpmn:script>
+    </bpmn:scriptTask>
   </bpmn:process>
   <bpmndi:BPMNDiagram id="BPMNDiagram_1">
     <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="DoDeleteSliceServiceV1">
@@ -138,9 +146,9 @@ dss.terminateNSIQuery(execution)</bpmn:script>
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="SequenceFlow_1c4fjbv_di" bpmnElement="SequenceFlow_1c4fjbv">
         <di:waypoint x="1765" y="140" />
-        <di:waypoint x="1802" y="140" />
+        <di:waypoint x="1830" y="140" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="1771" y="118" width="17" height="14" />
+          <dc:Bounds x="1793" y="118" width="17" height="14" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="SequenceFlow_1rgfzzy_di" bpmnElement="SequenceFlow_1rgfzzy">
@@ -177,9 +185,9 @@ dss.terminateNSIQuery(execution)</bpmn:script>
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="EndEvent_0jaitqv_di" bpmnElement="EndEvent_0jaitqv">
-        <dc:Bounds x="1802" y="122" width="36" height="36" />
+        <dc:Bounds x="2002" y="122" width="36" height="36" />
         <bpmndi:BPMNLabel>
-          <dc:Bounds x="1810" y="168" width="20" height="14" />
+          <dc:Bounds x="2010" y="168" width="20" height="14" />
         </bpmndi:BPMNLabel>
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="ScriptTask_0icszw6_di" bpmnElement="Task_0etki1p">
@@ -200,6 +208,13 @@ dss.terminateNSIQuery(execution)</bpmn:script>
       <bpmndi:BPMNShape id="Activity_1iuls9p_di" bpmnElement="Task_1iuls9p">
         <dc:Bounds x="1050" y="100" width="100" height="80" />
       </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_1odnvjl_di" bpmnElement="SequenceFlow_1odnvjl">
+        <di:waypoint x="1930" y="140" />
+        <di:waypoint x="2002" y="140" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ScriptTask_1qk9lnm_di" bpmnElement="Task_10yni6k">
+        <dc:Bounds x="1830" y="100" width="100" height="80" />
+      </bpmndi:BPMNShape>
     </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>
 </bpmn:definitions>
index 3292730..356c1cb 100644 (file)
@@ -37,7 +37,7 @@ public class NssmfRequest implements Serializable {
 
     private String globalSubscriberId;
 
-    private String serviceInstanceId;
+    private String serviceInstanceID;
 
     private String subscriptionServiceType;
 
@@ -54,7 +54,7 @@ public class NssmfRequest implements Serializable {
         this.subscriptionServiceType = serviceInfo.getSubscriptionServiceType();
         this.networkType = networkType;
         this.additionalProperties = additionalProperties;
-        this.serviceInstanceId = serviceInfo.getNssiId();
+        this.serviceInstanceID = serviceInfo.getNssiId();
         this.name = serviceInfo.getNssiName();
     }