Merge "Add DeallocateNSSI Sub-process"
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceArtifact.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceArtifact.java
new file mode 100644
index 0000000..aefd70f
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceArtifact.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2019, CMCC Technologies Co., Ltd.
+ #
+ # Licensed under the Apache License, Version 2.0 (the "License")
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
+ #
+ #       http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.core.domain;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.annotation.JsonRootName;
+import java.io.Serializable;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"artifactUUID", "name", "version", "checksum", "type", "content", "description"})
+@JsonRootName("serviceArtifact")
+public class ServiceArtifact extends JsonWrapper implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    @JsonProperty("artifactUUID")
+    private String artifactUUID;
+    @JsonProperty("name")
+    private String name;
+    @JsonProperty("version")
+    private String version;
+    @JsonProperty("checksum")
+    private String checksum;
+    @JsonProperty("type")
+    private String type;
+    @JsonProperty("content")
+    private String content;
+    @JsonProperty("description")
+    private String description;
+
+    @JsonProperty("artifactUUID")
+    public String getArtifactUUID() {
+        return artifactUUID;
+    }
+
+    @JsonProperty("artifactUUID")
+    public void setArtifactUUID(String artifactUUID) {
+        this.artifactUUID = artifactUUID;
+    }
+
+    @JsonProperty("name")
+    public String getName() {
+        return name;
+    }
+
+    @JsonProperty("name")
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @JsonProperty("version")
+    public String getVersion() {
+        return version;
+    }
+
+    @JsonProperty("version")
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    @JsonProperty("checksum")
+    public String getChecksum() {
+        return checksum;
+    }
+
+    @JsonProperty("checksum")
+    public void setChecksum(String checksum) {
+        this.checksum = checksum;
+    }
+
+    @JsonProperty("type")
+    public String getType() {
+        return type;
+    }
+
+    @JsonProperty("type")
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    @JsonProperty("content")
+    public String getContent() {
+        return content;
+    }
+
+    @JsonProperty("content")
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    @JsonProperty("description")
+    public String getDescription() {
+        return description;
+    }
+
+    @JsonProperty("description")
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy
new file mode 100644
index 0000000..d8897a2
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy
@@ -0,0 +1,309 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2019, CMCC Technologies Co., Ltd.
+ #
+ # Licensed under the Apache License, Version 2.0 (the "License")
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
+ #
+ #       http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.infrastructure.scripts
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.logging.filter.base.ONAPComponents
+import org.onap.so.beans.nsmf.DeAllocateNssi
+import org.onap.so.beans.nsmf.EsrInfo
+import org.onap.so.beans.nsmf.JobStatusRequest
+import org.onap.so.beans.nsmf.JobStatusResponse
+import org.onap.so.beans.nsmf.NetworkType
+import org.onap.so.beans.nsmf.NssiDeAllocateRequest
+import org.onap.so.beans.nsmf.NssiResponse
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.RequestDBUtil
+import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.so.bpmn.core.domain.ServiceArtifact
+import org.onap.so.bpmn.core.domain.ServiceDecomposition
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.client.aai.AAIObjectType
+import org.onap.so.client.aai.AAIResourcesClient
+import org.onap.so.client.aai.entities.uri.AAIResourceUri
+import org.onap.so.client.aai.entities.uri.AAIUriFactory
+import org.onap.so.db.request.beans.OperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import javax.ws.rs.core.Response
+
+
+class DoDeallocateNSSI extends AbstractServiceTaskProcessor
+{
+    private final String PREFIX ="DoDeallocateNSSI"
+
+    private ExceptionUtil exceptionUtil = new ExceptionUtil()
+    private JsonUtils jsonUtil = new JsonUtils()
+    private RequestDBUtil requestDBUtil = new RequestDBUtil()
+    private static final Logger LOGGER = LoggerFactory.getLogger( DoDeallocateNSSI.class)
+
+    @Override
+    void preProcessRequest(DelegateExecution execution) {
+        LOGGER.trace(" ***** ${PREFIX} Start preProcessRequest *****")
+
+        def currentNSSI = execution.getVariable("currentNSSI")
+        if (!currentNSSI) {
+            String msg = "currentNSSI is null"
+            LOGGER.error(msg)
+            exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+        }
+
+        LOGGER.trace("***** ${PREFIX} Exit preProcessRequest *****")
+    }
+
+    /**
+     *
+     * @param execution
+     */
+    private void prepareDecomposeService(DelegateExecution execution)
+    {
+        LOGGER.trace(" *****${PREFIX} Start prepareDecomposeService *****")
+        try
+        {
+            def currentNSSI = execution.getVariable("currentNSSI")
+            String modelInvariantUuid = currentNSSI['modelInvariantId']
+            String modelVersionId = currentNSSI['modelVersionId']
+            String serviceModelInfo = """{
+            "modelInvariantUuid":"${modelInvariantUuid}",
+            "modelUuid":"${modelVersionId}",
+            "modelVersion":""
+             }"""
+            execution.setVariable("serviceModelInfo", serviceModelInfo)
+        }
+        catch (any)
+        {
+            String exceptionMessage = "Bpmn error encountered in deallocate nssi. Unexpected Error from method prepareDecomposeService() - " + any.getMessage()
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+        }
+        LOGGER.debug(" ***** ${PREFIX} Exit prepareDecomposeService *****")
+    }
+
+    /**
+     * get vendor Info
+     * @param execution
+     */
+    private void processDecomposition(DelegateExecution execution) {
+        LOGGER.debug("*****${PREFIX} start processDecomposition *****")
+
+        try {
+            ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") as ServiceDecomposition
+            ServiceArtifact serviceArtifact = serviceDecomposition ?.getServiceInfo()?.getServiceArtifact()?.get(0)
+            String content = serviceArtifact.getContent()
+            String vendor = jsonUtil.getJsonValue(content, "metadata.vendor")
+            String domainType  = jsonUtil.getJsonValue(content, "metadata.domainType")
+
+            def currentNSSI = execution.getVariable("currentNSSI")
+            currentNSSI['vendor'] = vendor
+            currentNSSI['domainType'] = domainType
+            LOGGER.info("processDecomposition, current vendor-domainType:" +String.join("-", vendor, domainType))
+
+        } catch (any) {
+            String exceptionMessage = "Bpmn error encountered in deallocate nssi. processDecomposition() - " + any.getMessage()
+            LOGGER.debug(exceptionMessage)
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+        }
+        LOGGER.debug("*****${PREFIX} Exit processDecomposition *****")
+    }
+
+    /**
+     * send deallocate request to nssmf
+     * @param execution
+     */
+    private void sendRequestToNSSMF(DelegateExecution execution)
+    {
+        LOGGER.debug("*****${PREFIX} start sendRequestToNSSMF *****")
+        def currentNSSI = execution.getVariable("currentNSSI")
+        String snssai= currentNSSI['snssai']
+        String profileId = currentNSSI['profileId']
+        String nssiId = currentNSSI['nssiServiceInstanceId']
+        String nsiId = currentNSSI['nsiServiceInstanceId']
+
+        DeAllocateNssi deAllocateNssi = new DeAllocateNssi()
+        deAllocateNssi.setNsiId(nsiId)
+        deAllocateNssi.setNssiId(nssiId)
+        deAllocateNssi.setTerminateNssiOption(0)
+        deAllocateNssi.setSnssaiList(Arrays.asList(snssai))
+
+        NssiDeAllocateRequest deAllocateRequest = new NssiDeAllocateRequest()
+        deAllocateRequest.setDeAllocateNssi(deAllocateNssi)
+        deAllocateRequest.setEsrInfo(getEsrInfo(currentNSSI))
+
+        ObjectMapper mapper = new ObjectMapper()
+        String json = mapper.writeValueAsString(deAllocateRequest)
+
+        //Prepare auth for NSSMF - Begin
+        String nssmfRequest = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint", execution)
+        nssmfRequest = nssmfRequest + String.format("/api/rest/provMns/v1/NSS/SliceProfiles/%s",profileId)
+        //nssmfRequest = nssmfRequest + String.format(NssmfAdapterUtil.NSSMI_DEALLOCATE_URL,profileId)
+        //send request to active  NSSI TN option
+        URL url = new URL(nssmfRequest)
+        LOGGER.info("deallocate nssmfRequest:${nssmfRequest}, reqBody: ${json}")
+
+        HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL)
+        Response httpResponse = httpClient.post(json)
+        checkNssmfResponse(httpResponse, execution)
+
+        NssiResponse nssmfResponse = httpResponse.readEntity(NssiResponse.class)
+        currentNSSI['jobId']= nssmfResponse.getJobId() ?: ""
+        currentNSSI['jobProgress'] = 0
+        execution.setVariable("currentNSSI", currentNSSI)
+
+        LOGGER.debug("*****${PREFIX} Exit sendRequestToNSSMF *****")
+    }
+
+    /**
+     * send to nssmf query progress
+     * @param execution
+     */
+    private void getJobStatus(DelegateExecution execution)
+    {
+        def currentNSSI = execution.getVariable("currentNSSI")
+        String jobId = currentNSSI['jobId']
+        String nssiId = currentNSSI['nssiServiceInstanceId']
+        String nsiId = currentNSSI['nsiServiceInstanceId']
+
+        JobStatusRequest jobStatusRequest = new JobStatusRequest()
+        jobStatusRequest.setNssiId(nssiId)
+        jobStatusRequest.setNsiId(nsiId)
+        jobStatusRequest.setEsrInfo(getEsrInfo(currentNSSI))
+
+        ObjectMapper mapper = new ObjectMapper()
+        String json = mapper.writeValueAsString(jobStatusRequest)
+
+        //Prepare auth for NSSMF - Begin
+        String nssmfRequest = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint", execution)
+        nssmfRequest = nssmfRequest + String.format("/api/rest/provMns/v1/NSS/jobs/%s",jobId)
+        //send request to active  NSSI TN option
+        URL url = new URL(nssmfRequest)
+        LOGGER.info("get deallocate job status, nssmfRequest:${nssmfRequest}, requestBody: ${json}")
+
+        HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL)
+        Response httpResponse = httpClient.post(json)
+        checkNssmfResponse(httpResponse, execution)
+
+        JobStatusResponse jobStatusResponse = httpResponse.readEntity(JobStatusResponse.class)
+        def progress = jobStatusResponse?.getResponseDescriptor()?.getProgress()
+        if(!progress)
+        {
+            LOGGER.error("job progress is null or empty!")
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Job progress from NSSMF.")
+        }
+        int oldProgress = currentNSSI['jobProgress']
+        int currentProgress = progress
+
+        execution.setVariable("isNSSIDeAllocated", (currentProgress == 100))
+        execution.setVariable("isNeedUpdateDB", (oldProgress != currentProgress))
+        currentNSSI['jobProgress'] = currentProgress
+
+        def statusDescription = jobStatusResponse?.getResponseDescriptor()?.getStatusDescription()
+        currentNSSI['statusDescription'] = statusDescription
+
+        LOGGER.debug("job status result: nsiId = ${nsiId}, nssiId=${nssiId}, oldProgress=${oldProgress}, progress = ${currentProgress}" )
+    }
+
+    private void checkNssmfResponse(Response httpResponse, DelegateExecution execution) {
+        int responseCode = httpResponse.getStatus()
+        LOGGER.debug("NSSMF response code is: " + responseCode)
+
+        if ( responseCode < 200 || responseCode > 204 || !httpResponse.hasEntity()) {
+            exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Response from NSSMF.")
+        }
+    }
+
+
+    private EsrInfo getEsrInfo(def currentNSSI)
+    {
+        String domaintype = currentNSSI['domainType']
+        String vendor = currentNSSI['vendor']
+
+        EsrInfo info = new EsrInfo()
+        info.setNetworkType(NetworkType.fromString(domaintype))
+        info.setVendor(vendor)
+        return info
+    }
+
+    /**
+     * handle job status
+     * prepare update requestdb
+     * @param execution
+     */
+    private void handleJobStatus(DelegateExecution execution)
+    {
+        def currentNSSI = execution.getVariable("currentNSSI")
+        int currentProgress = currentNSSI["jobProgress"]
+        def proportion = currentNSSI['proportion']
+        def statusDes = currentNSSI["statusDescription"]
+        int progress = (currentProgress as int) == 0 ? 0 : (currentProgress as int) / 100 * (proportion as int)
+
+        OperationStatus operationStatus = new OperationStatus()
+        operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String)
+        operationStatus.setOperationId(currentNSSI['operationId'] as String)
+        operationStatus.setOperation("DELETE")
+        operationStatus.setResult("processing")
+        operationStatus.setProgress(progress as String)
+        operationStatus.setOperationContent(statusDes as String)
+        requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus)
+        LOGGER.debug("update operation, currentProgress=${currentProgress}, proportion=${proportion}, progress = ${progress}" )
+    }
+
+    private void timeDelay(DelegateExecution execution) {
+        try {
+            Thread.sleep(10000);
+        } catch(InterruptedException e) {
+            LOGGER.error("Time Delay exception" + e)
+        }
+    }
+
+    /**
+     * delete slice profile from aai
+     * @param execution
+     */
+    private void delSliceProfileFromAAI(DelegateExecution execution)
+    {
+        LOGGER.debug("*****${PREFIX} start delSliceProfileFromAAI *****")
+        def currentNSSI = execution.getVariable("currentNSSI")
+        String nssiServiceInstanceId = currentNSSI['nssiServiceInstanceId']
+        String profileId = currentNSSI['profileId']
+        String globalSubscriberId = currentNSSI["globalSubscriberId"]
+        String serviceType = currentNSSI["serviceType"]
+
+        try
+        {
+            LOGGER.debug("delete nssiServiceInstanceId:${nssiServiceInstanceId}, profileId:${profileId}")
+            AAIResourcesClient resourceClient = new AAIResourcesClient()
+            AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiServiceInstanceId, profileId)
+            if (!resourceClient.exists(resourceUri)) {
+                exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
+            }
+            resourceClient.delete(resourceUri)
+        }
+        catch (any)
+        {
+            String msg = "delete slice profile from aai failed! cause-"+any.getCause()
+            LOGGER.error(any.printStackTrace())
+            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+        }
+        LOGGER.debug("*****${PREFIX} Exist delSliceProfileFromAAI *****")
+    }
+}
diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateNSSI.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateNSSI.bpmn
new file mode 100644
index 0000000..db805ec
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateNSSI.bpmn
@@ -0,0 +1,254 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0884541" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.4.1">
+  <bpmn:process id="DoDeallocateNSSIV1" name="DoDeallocateNSSIV1" isExecutable="true">
+    <bpmn:startEvent id="StartEvent_1" name="start">
+      <bpmn:outgoing>SequenceFlow_05jfhy6</bpmn:outgoing>
+    </bpmn:startEvent>
+    <bpmn:sequenceFlow id="SequenceFlow_05jfhy6" sourceRef="StartEvent_1" targetRef="Task_1vste9s" />
+    <bpmn:scriptTask id="Task_1m8upus" name="Prepare Decompose Service" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_0eug5nv</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_0wlyy5i</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def dnssi= new DoDeallocateNSSI()
+dnssi.prepareDecomposeService(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:sequenceFlow id="SequenceFlow_0wlyy5i" sourceRef="Task_1m8upus" targetRef="Task_1giechg" />
+    <bpmn:callActivity id="Task_1giechg" name="Call Decompose Service" calledElement="DecomposeService">
+      <bpmn:extensionElements>
+        <camunda:in source="msoRequestId" target="msoRequestId" />
+        <camunda:in source="serviceInstanceId" target="serviceInstanceId" />
+        <camunda:in source="serviceModelInfo" target="serviceModelInfo" />
+        <camunda:out source="serviceDecomposition" target="serviceDecomposition" />
+        <camunda:out source="serviceDecompositionString" target="serviceDecompositionString" />
+      </bpmn:extensionElements>
+      <bpmn:incoming>SequenceFlow_0wlyy5i</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_1e451y9</bpmn:outgoing>
+    </bpmn:callActivity>
+    <bpmn:sequenceFlow id="SequenceFlow_1e451y9" sourceRef="Task_1giechg" targetRef="Task_15ut397" />
+    <bpmn:scriptTask id="Task_15ut397" name="processDecomposition" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_1e451y9</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_1e7o57n</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def dnssi= new DoDeallocateNSSI()
+dnssi.processDecomposition(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:sequenceFlow id="SequenceFlow_1e7o57n" sourceRef="Task_15ut397" targetRef="Task_0vi4ijv" />
+    <bpmn:scriptTask id="Task_0vi4ijv" name="Send deallocate request to NSSMF" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_1e7o57n</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_03b0822</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def dnssi= new DoDeallocateNSSI()
+dnssi.sendRequestToNSSMF(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:sequenceFlow id="SequenceFlow_03b0822" sourceRef="Task_0vi4ijv" targetRef="Task_0kl6lcq" />
+    <bpmn:scriptTask id="Task_0kl6lcq" name="Query Job Status" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_03b0822</bpmn:incoming>
+      <bpmn:incoming>SequenceFlow_1anlirk</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_1jj0p5q</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def dnssi= new DoDeallocateNSSI()
+dnssi.getJobStatus(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:sequenceFlow id="SequenceFlow_1jj0p5q" sourceRef="Task_0kl6lcq" targetRef="ExclusiveGateway_0nhfsui" />
+    <bpmn:exclusiveGateway id="ExclusiveGateway_0nhfsui" name="Is deallocate finish?" default="SequenceFlow_0sfh52b">
+      <bpmn:incoming>SequenceFlow_1jj0p5q</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_0xq380j</bpmn:outgoing>
+      <bpmn:outgoing>SequenceFlow_0sfh52b</bpmn:outgoing>
+    </bpmn:exclusiveGateway>
+    <bpmn:scriptTask id="Task_13vaezk" name="Delete Slice Profile From AAI" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_0xq380j</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_1ii5002</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def dnssi= new DoDeallocateNSSI()
+dnssi.delSliceProfileFromAAI(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:endEvent id="EndEvent_1f579t4" name="end">
+      <bpmn:incoming>SequenceFlow_1ii5002</bpmn:incoming>
+    </bpmn:endEvent>
+    <bpmn:sequenceFlow id="SequenceFlow_1ii5002" sourceRef="Task_13vaezk" targetRef="EndEvent_1f579t4" />
+    <bpmn:sequenceFlow id="SequenceFlow_0xq380j" name="yes" sourceRef="ExclusiveGateway_0nhfsui" targetRef="Task_13vaezk">
+      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{(execution.getVariable("isNSSIDeAllocated" )  == true)}</bpmn:conditionExpression>
+    </bpmn:sequenceFlow>
+    <bpmn:sequenceFlow id="SequenceFlow_0eug5nv" sourceRef="Task_1vste9s" targetRef="Task_1m8upus" />
+    <bpmn:scriptTask id="Task_1vste9s" name="PreProcess Incoming Request" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_05jfhy6</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_0eug5nv</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def dnssi= new DoDeallocateNSSI()
+dnssi.preProcessRequest(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:sequenceFlow id="SequenceFlow_1anlirk" sourceRef="Task_0fxuz4i" targetRef="Task_0kl6lcq" />
+    <bpmn:scriptTask id="Task_0fxuz4i" name="TimeDelay" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_1ugva41</bpmn:incoming>
+      <bpmn:incoming>SequenceFlow_1u66wjs</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_1anlirk</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def dnssi= new DoDeallocateNSSI()
+dnssi.timeDelay(execution)</bpmn:script>
+    </bpmn:scriptTask>
+    <bpmn:serviceTask id="Task_0amt4hu" name="Update Service Operation Status">
+      <bpmn:extensionElements>
+        <camunda:connector>
+          <camunda:inputOutput>
+            <camunda:inputParameter name="url">${dbAdapterEndpoint}</camunda:inputParameter>
+            <camunda:inputParameter name="headers">
+              <camunda:map>
+                <camunda:entry key="content-type">application/soap+xml</camunda:entry>
+                <camunda:entry key="Authorization">Basic YnBlbDpwYXNzd29yZDEk</camunda:entry>
+              </camunda:map>
+            </camunda:inputParameter>
+            <camunda:inputParameter name="payload">${updateOperationStatus}</camunda:inputParameter>
+            <camunda:inputParameter name="method">POST</camunda:inputParameter>
+            <camunda:outputParameter name="DeNSSI_dbResponseCode">${statusCode}</camunda:outputParameter>
+            <camunda:outputParameter name="DeNSSI_dbResponse">${response}</camunda:outputParameter>
+          </camunda:inputOutput>
+          <camunda:connectorId>http-connector</camunda:connectorId>
+        </camunda:connector>
+      </bpmn:extensionElements>
+      <bpmn:incoming>SequenceFlow_04vg0c2</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_1ugva41</bpmn:outgoing>
+    </bpmn:serviceTask>
+    <bpmn:exclusiveGateway id="ExclusiveGateway_0y0w592" name="IsNeedUpdateDB?" default="SequenceFlow_1u66wjs">
+      <bpmn:incoming>SequenceFlow_0sfh52b</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_0r95j9m</bpmn:outgoing>
+      <bpmn:outgoing>SequenceFlow_1u66wjs</bpmn:outgoing>
+    </bpmn:exclusiveGateway>
+    <bpmn:sequenceFlow id="SequenceFlow_0sfh52b" sourceRef="ExclusiveGateway_0nhfsui" targetRef="ExclusiveGateway_0y0w592" />
+    <bpmn:sequenceFlow id="SequenceFlow_0r95j9m" sourceRef="ExclusiveGateway_0y0w592" targetRef="Task_1renmzf">
+      <bpmn:documentation>#{(execution.getVariable("isNeedUpdateDB" )  == true)}</bpmn:documentation>
+      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{(execution.getVariable("isNeedUpdateDB" )  == true)}</bpmn:conditionExpression>
+    </bpmn:sequenceFlow>
+    <bpmn:sequenceFlow id="SequenceFlow_04vg0c2" sourceRef="Task_1renmzf" targetRef="Task_0amt4hu" />
+    <bpmn:sequenceFlow id="SequenceFlow_1ugva41" sourceRef="Task_0amt4hu" targetRef="Task_0fxuz4i" />
+    <bpmn:sequenceFlow id="SequenceFlow_1u66wjs" sourceRef="ExclusiveGateway_0y0w592" targetRef="Task_0fxuz4i" />
+    <bpmn:scriptTask id="Task_1renmzf" name="Prepare Update Operation Status" scriptFormat="groovy">
+      <bpmn:incoming>SequenceFlow_0r95j9m</bpmn:incoming>
+      <bpmn:outgoing>SequenceFlow_04vg0c2</bpmn:outgoing>
+      <bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
+def dnssi= new DoDeallocateNSSI()
+dnssi.handleJobStatus(execution)</bpmn:script>
+    </bpmn:scriptTask>
+  </bpmn:process>
+  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
+    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="DoDeallocateNSSIV1">
+      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
+        <dc:Bounds x="192" y="112" width="36" height="36" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="199" y="155" width="22" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_05jfhy6_di" bpmnElement="SequenceFlow_05jfhy6">
+        <di:waypoint x="228" y="130" />
+        <di:waypoint x="310" y="130" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ScriptTask_159g5ey_di" bpmnElement="Task_1m8upus">
+        <dc:Bounds x="490" y="90" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_0wlyy5i_di" bpmnElement="SequenceFlow_0wlyy5i">
+        <di:waypoint x="590" y="130" />
+        <di:waypoint x="660" y="130" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="CallActivity_1ep4ama_di" bpmnElement="Task_1giechg">
+        <dc:Bounds x="660" y="90" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_1e451y9_di" bpmnElement="SequenceFlow_1e451y9">
+        <di:waypoint x="760" y="130" />
+        <di:waypoint x="820" y="130" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ScriptTask_1yt5s46_di" bpmnElement="Task_15ut397">
+        <dc:Bounds x="820" y="90" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_1e7o57n_di" bpmnElement="SequenceFlow_1e7o57n">
+        <di:waypoint x="920" y="130" />
+        <di:waypoint x="970" y="130" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ScriptTask_16dxpvz_di" bpmnElement="Task_0vi4ijv">
+        <dc:Bounds x="970" y="90" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_03b0822_di" bpmnElement="SequenceFlow_03b0822">
+        <di:waypoint x="1070" y="130" />
+        <di:waypoint x="1120" y="130" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ScriptTask_0arl3j9_di" bpmnElement="Task_0kl6lcq">
+        <dc:Bounds x="1120" y="90" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_1jj0p5q_di" bpmnElement="SequenceFlow_1jj0p5q">
+        <di:waypoint x="1220" y="130" />
+        <di:waypoint x="1505" y="130" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ExclusiveGateway_0nhfsui_di" bpmnElement="ExclusiveGateway_0nhfsui" isMarkerVisible="true">
+        <dc:Bounds x="1505" y="105" width="50" height="50" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1501" y="75" width="63" height="27" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="ScriptTask_1rfdrw3_di" bpmnElement="Task_13vaezk">
+        <dc:Bounds x="1690" y="90" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="EndEvent_1f579t4_di" bpmnElement="EndEvent_1f579t4">
+        <dc:Bounds x="1862" y="112" width="36" height="36" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1871" y="155" width="19" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_1ii5002_di" bpmnElement="SequenceFlow_1ii5002">
+        <di:waypoint x="1790" y="130" />
+        <di:waypoint x="1862" y="130" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="SequenceFlow_0xq380j_di" bpmnElement="SequenceFlow_0xq380j">
+        <di:waypoint x="1555" y="130" />
+        <di:waypoint x="1690" y="130" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1614" y="112" width="17" height="14" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="SequenceFlow_0eug5nv_di" bpmnElement="SequenceFlow_0eug5nv">
+        <di:waypoint x="410" y="130" />
+        <di:waypoint x="490" y="130" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ScriptTask_1dytya8_di" bpmnElement="Task_1vste9s">
+        <dc:Bounds x="310" y="90" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_1anlirk_di" bpmnElement="SequenceFlow_1anlirk">
+        <di:waypoint x="1170" y="190" />
+        <di:waypoint x="1170" y="170" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ScriptTask_0a4zalz_di" bpmnElement="Task_0fxuz4i">
+        <dc:Bounds x="1120" y="190" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="ServiceTask_0vegqix_di" bpmnElement="Task_0amt4hu">
+        <dc:Bounds x="1280" y="300" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="ExclusiveGateway_0y0w592_di" bpmnElement="ExclusiveGateway_0y0w592" isMarkerVisible="true">
+        <dc:Bounds x="1505" y="205" width="50" height="50" />
+        <bpmndi:BPMNLabel>
+          <dc:Bounds x="1567" y="216" width="86" height="27" />
+        </bpmndi:BPMNLabel>
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNEdge id="SequenceFlow_0sfh52b_di" bpmnElement="SequenceFlow_0sfh52b">
+        <di:waypoint x="1530" y="155" />
+        <di:waypoint x="1530" y="205" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="SequenceFlow_0r95j9m_di" bpmnElement="SequenceFlow_0r95j9m">
+        <di:waypoint x="1530" y="255" />
+        <di:waypoint x="1530" y="300" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="SequenceFlow_04vg0c2_di" bpmnElement="SequenceFlow_04vg0c2">
+        <di:waypoint x="1480" y="340" />
+        <di:waypoint x="1380" y="340" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="SequenceFlow_1ugva41_di" bpmnElement="SequenceFlow_1ugva41">
+        <di:waypoint x="1280" y="340" />
+        <di:waypoint x="1170" y="340" />
+        <di:waypoint x="1170" y="270" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="SequenceFlow_1u66wjs_di" bpmnElement="SequenceFlow_1u66wjs">
+        <di:waypoint x="1505" y="230" />
+        <di:waypoint x="1220" y="230" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="ScriptTask_10pw6ot_di" bpmnElement="Task_1renmzf">
+        <dc:Bounds x="1480" y="300" width="100" height="80" />
+      </bpmndi:BPMNShape>
+    </bpmndi:BPMNPlane>
+  </bpmndi:BPMNDiagram>
+</bpmn:definitions>