Add NssmfAapterUtils to fix the auth problem of request to nssmf 31/107531/8
authorhetengjiao <hetengjiao@chinamobile.com>
Tue, 12 May 2020 09:16:25 +0000 (17:16 +0800)
committerHE TENGJIAO <hetengjiao@chinamobile.com>
Wed, 13 May 2020 02:59:36 +0000 (02:59 +0000)
Issue-ID: SO-2918

Change-Id: I8d5df8e1a2e390f24c8d38195d8c8f3696f81804
Signed-off-by: hetengjiao <hetengjiao@chinamobile.com>
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/NssmfAdapterUtils.groovy [new file with mode: 0644]
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoSendCommandToNSSMF.groovy

diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/NssmfAdapterUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/NssmfAdapterUtils.groovy
new file mode 100644 (file)
index 0000000..ba7a2d7
--- /dev/null
@@ -0,0 +1,141 @@
+/*-
+ * ============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.common.scripts
+
+import org.apache.commons.lang3.StringUtils
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.logging.filter.base.ONAPComponents
+import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import javax.ws.rs.core.Response
+
+/***
+ * Utilities for accessing Catalog DB Adapter to retrieve Networks, VNF/VFModules, AllottedResources and complete ServiceResources information
+ *
+ */
+
+class NssmfAdapterUtils {
+    private static final Logger logger = LoggerFactory.getLogger( NssmfAdapterUtils.class);
+
+       private HttpClientFactory httpClientFactory
+       private MsoUtils utils
+       private JsonUtils jsonUtils
+
+    NssmfAdapterUtils(HttpClientFactory httpClientFactory, JsonUtils jsonUtils) {
+               this.httpClientFactory = httpClientFactory
+               this.utils = new MsoUtils()
+               this.jsonUtils = jsonUtils
+       }
+
+
+    public <T> T sendPostRequestNSSMF (DelegateExecution execution, String endPoint, String nssmfRequest, Class<T> entityType) {
+        try {
+
+            String nssmfEndpoint = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint",execution)
+            String queryEndpoint = nssmfEndpoint + endPoint
+            def responseData
+            HttpClient client = httpClientFactory.newJsonClient(new URL(queryEndpoint), ONAPComponents.EXTERNAL)
+            String basicAuthCred = execution.getVariable("BasicAuthHeaderValue")
+            client.addAdditionalHeader("Authorization", StringUtils.defaultIfEmpty(basicAuthCred, getBasicDBAuthHeader(execution)))
+
+            logger.debug('sending POST to NSSMF endpoint: ' + endPoint)
+            Response response = client.post(nssmfRequest)
+
+            responseData = response.readEntity(entityType)
+            if (responseData != null) {
+                logger.debug("Received data from NSSMF: " + responseData)
+            }
+
+            logger.debug('Response code:' + response.getStatus())
+            logger.debug('Response:' + System.lineSeparator() + responseData)
+            if (response.getStatus() >= 200 && response.getStatus() < 300) {
+                // parse response as needed
+                return responseData
+            }
+            else {
+                return null
+            }
+        }
+        catch (Exception e) {
+            logger.debug("ERROR WHILE QUERYING CATALOG DB: " + e.message)
+            throw e
+        }
+
+    }
+
+       public String sendPostRequestNSSMF (DelegateExecution execution, String endPoint, String nssmfRequest) {
+               try {
+
+                       String nssmfEndpoint = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint",execution)
+                       String queryEndpoint = nssmfEndpoint + endPoint
+                       def responseData
+            HttpClient client = httpClientFactory.newJsonClient(new URL(queryEndpoint), ONAPComponents.EXTERNAL)
+                       String basicAuthCred = execution.getVariable("BasicAuthHeaderValue")
+                       client.addAdditionalHeader("Authorization", StringUtils.defaultIfEmpty(basicAuthCred, getBasicDBAuthHeader(execution)))
+
+                       logger.debug('sending POST to NSSMF endpoint: ' + endPoint)
+                       Response response = client.post(nssmfRequest)
+
+                       responseData = response.readEntity(String.class)
+                       if (responseData != null) {
+                               logger.debug("Received data from NSSMF: " + responseData)
+                       }
+
+                       logger.debug('Response code:' + response.getStatus())
+                       logger.debug('Response:' + System.lineSeparator() + responseData)
+                       if (response.getStatus() >= 200 && response.getStatus() < 300) {
+                               // parse response as needed
+                               return responseData
+                       }
+                       else {
+                               return null
+                       }
+               }
+               catch (Exception e) {
+                       logger.debug("ERROR WHILE QUERYING CATALOG DB: " + e.message)
+                       throw e
+               }
+
+       }
+
+
+       private String getBasicDBAuthHeader(DelegateExecution execution) {
+
+               String encodedString = null
+               try {
+                       String basicAuthValueDB = UrnPropertiesReader.getVariable("mso.adapters.db.auth", execution)
+                       logger.debug("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB)
+
+                       encodedString = utils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution))
+                       execution.setVariable("BasicAuthHeaderValue", encodedString)
+               } catch (IOException ex) {
+                       String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
+                       logger.error(dataErrorMessage)
+               }
+               return encodedString
+       }
+
+}
index 5acc016..52df140 100644 (file)
@@ -25,17 +25,13 @@ import com.google.gson.Gson
 import com.google.gson.reflect.TypeToken
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.onap.logging.filter.base.ONAPComponents
 import org.onap.so.beans.nsmf.*
 import org.onap.so.bpmn.common.scripts.*
-import org.onap.so.bpmn.common.util.OofInfraUtils
 import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.WorkflowException
 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.logging.filter.base.ErrorCode
 import org.onap.so.logger.LoggingAnchor
 import org.onap.so.logger.MessageEnum
@@ -43,7 +39,6 @@ import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import org.springframework.web.util.UriUtils
 
-import javax.ws.rs.core.Response
 import java.lang.reflect.Type
 
 /**
@@ -54,13 +49,13 @@ import java.lang.reflect.Type
  */
 class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
 
-    private static final Logger logger = LoggerFactory.getLogger( DoSendCommandToNSSMF.class);
+       private static final Logger logger = LoggerFactory.getLogger( DoSendCommandToNSSMF.class);
        String Prefix="DoCNSSMF_"
-    ExceptionUtil exceptionUtil = new ExceptionUtil()
-    JsonUtils jsonUtil = new JsonUtils()
-    VidUtils vidUtils = new VidUtils(this)
-    SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
-    OofInfraUtils oofInfraUtils = new OofInfraUtils()
+       ExceptionUtil exceptionUtil = new ExceptionUtil()
+       JsonUtils jsonUtil = new JsonUtils()
+       VidUtils vidUtils = new VidUtils(this)
+       SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
+       private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
 
        /**
         * This method gets and validates the incoming
@@ -81,7 +76,7 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                        String serviceInstanceId = execution.getVariable("e2eserviceInstanceId")
                        execution.setVariable("e2eserviceInstanceId", e2eserviceInstanceId)
                        execution.setVariable("serviceInstanceId", serviceInstanceId)
-                       logger.debug("Incoming e2eserviceInstanceId is: " + e2eserviceInstanceId)
+                       logger.debug("Incoming e2eserviceInstanceId is: " + e2eserviceInstanceId)
 
                        String NSIserviceid =  execution.getVariable("NSIserviceid")
                        execution.setVariable("NSIserviceid", NSIserviceid)
@@ -91,7 +86,7 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                        String nssiMap  = execution.getVariable("nssiMap")
                        Type type = new TypeToken<HashMap<String, NSSI>>(){}.getType()
                        Map<String, NSSI> DonssiMap = new Gson().fromJson(nssiMap,type)
-            String strDonssiMap = mapToJsonStr(DonssiMap)
+                       String strDonssiMap = mapToJsonStr(DonssiMap)
                        execution.setVariable("DonssiMap",strDonssiMap)
                        logger.debug("Incoming DonssiMap is: " + strDonssiMap)
 
@@ -99,10 +94,10 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                        execution.setVariable("msoRequestId", requestId)
 
                        String operationType = execution.getVariable("operationType")
-                       execution.setVariable("operationType", operationType)
+                       execution.setVariable("operationType", operationType.toLowerCase())
                        logger.debug("Incoming operationType is: " + operationType)
 
-            if (operationType == "activation") {
+                       if (operationType == "activation") {
                                execution.setVariable("activationSequence","an,tn,cn")
                        }else {
                                execution.setVariable("activationSequence","cn,tn,an")
@@ -123,23 +118,25 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                }
                logger.trace("COMPLETED DoSendCommandToNSSMF PreProcessRequest Process")
        }
-    private String mapToJsonStr(Map<String, NSSI> stringNSSIHashMap) {
-        HashMap<String, NSSI> map = new HashMap<String, NSSI>()
-        for(Map.Entry<String, NSSI> child:stringNSSIHashMap.entrySet())
-        {
-            map.put(child.getKey(), child.getValue())
-        }
-        return new Gson().toJson(map)
-    }
+
+       private String mapToJsonStr(Map<String, NSSI> stringNSSIHashMap) {
+               HashMap<String, NSSI> map = new HashMap<String, NSSI>()
+               for(Map.Entry<String, NSSI> child:stringNSSIHashMap.entrySet())
+               {
+                       map.put(child.getKey(), child.getValue())
+               }
+               return new Gson().toJson(map)
+       }
+
        public  void getNSSIformlist(DelegateExecution execution) {
 
                String  nssiMap = execution.getVariable("DonssiMap")
                Type type = new TypeToken<HashMap<String, NSSI>>(){}.getType()
-        Map<String, NSSI> DonssiMap = new Gson().fromJson(nssiMap,type)
+               Map<String, NSSI> DonssiMap = new Gson().fromJson(nssiMap,type)
                String isNSSIActivate = execution.getVariable("isNSSIActivate")
 
                String activationSequence01 = execution.getVariable("activationSequence")
-           String[] strlist = activationSequence01.split(",")
+               String[] strlist = activationSequence01.split(",")
 
                int  activationIndex = execution.getVariable("activationIndex")
                int indexcurrent = 0
@@ -159,10 +156,10 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                                String modelUuid = execution.getVariable("modelUuid")
                                //here modelVersion is not set, we use modelUuid to decompose the service.
                                String serviceModelInfo = """{
-            "modelInvariantUuid":"${modelInvariantUuid}",
-            "modelUuid":"${modelUuid}",
-            "modelVersion":""
-             }"""
+                       "modelInvariantUuid":"${modelInvariantUuid}",
+                       "modelUuid":"${modelUuid}",
+                       "modelVersion":""
+                        }"""
                                execution.setVariable("serviceModelInfo", serviceModelInfo)
                                indexcurrent = index
                                execution.setVariable("activationIndex", indexcurrent)
@@ -179,6 +176,7 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                        execution.setVariable("activationIndex", indexcurrent)}
 
        }
+
        /**
         * get vendor Info
         * @param execution
@@ -188,13 +186,13 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
 
                try {
                        ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") as ServiceDecomposition
-            ServiceArtifact serviceArtifact = serviceDecomposition.getServiceInfo().getServiceArtifact().get(0)
+                       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")
 
                        execution.setVariable("vendor", vendor)
-               //      currentNSSI['domainType'] = domainType
+                       //      currentNSSI['domainType'] = domainType
                        logger.info("processDecomposition, current vendor-domainType:" +  vendor)
 
                } catch (any) {
@@ -204,6 +202,7 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                }
                logger.debug("***** Exit processDecomposition *****")
        }
+
        public  void UpdateIndex(DelegateExecution execution) {
                def activationIndex = execution.getVariable("activationIndex")
                int activateNumberSlice = execution.getVariable("activateNumberSlice") as Integer
@@ -225,7 +224,7 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                        String operationId = UUID.randomUUID().toString()
                        String operationType =  execution.getVariable("operationType")
                        String userId = ""
-                       String result = (operationType.equals("activation"))? "ACTIVATING": "DEACTIVATING"
+                       String result = (operationType.equalsIgnoreCase("activation"))? "ACTIVATING": "DEACTIVATING"
                        int progress = rate
                        String reason = ""
                        String operationContent = "Service activation in progress"
@@ -241,21 +240,21 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
 
                        String payload =
                                        """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
-                        xmlns:ns="http://org.onap.so/requestsdb">
-                        <soapenv:Header/>
-                        <soapenv:Body>
-                            <ns:initServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
-                            <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
-                            <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
-                            <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
-                            <userId>${MsoUtils.xmlEscape(userId)}</userId>
-                            <result>${MsoUtils.xmlEscape(result)}</result>
-                            <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
-                            <progress>${MsoUtils.xmlEscape(progress)}</progress>
-                            <reason>${MsoUtils.xmlEscape(reason)}</reason>
-                        </ns:initServiceOperationStatus>
-                    </soapenv:Body>
-                </soapenv:Envelope>"""
+                                               xmlns:ns="http://org.onap.so/requestsdb">
+                                               <soapenv:Header/>
+                                               <soapenv:Body>
+                                                       <ns:initServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
+                                                       <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
+                                                       <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
+                                                       <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
+                                                       <userId>${MsoUtils.xmlEscape(userId)}</userId>
+                                                       <result>${MsoUtils.xmlEscape(result)}</result>
+                                                       <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
+                                                       <progress>${MsoUtils.xmlEscape(progress)}</progress>
+                                                       <reason>${MsoUtils.xmlEscape(reason)}</reason>
+                                               </ns:initServiceOperationStatus>
+                                       </soapenv:Body>
+                               </soapenv:Envelope>"""
 
                        payload = utils.formatXml(payload)
                        execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
@@ -269,24 +268,25 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                }
                logger.trace("finished Activate Slice")
        }
+
        public void WaitForReturn(DelegateExecution execution) {
                //logger.debug("Query : "+ Jobid)
-               def miniute=execution.getVariable("miniute")
+               String miniute = execution.getVariable("miniute")
                Thread.sleep(10000)
                int miniute01  = Integer.parseInt(miniute) + 1
                logger.debug("waiting for : "+ miniute + "miniutes")
                execution.setVariable("miniute", String.valueOf(miniute01))
        }
+
        public void GetTheStatusOfActivation(DelegateExecution execution) {
 
-               String snssai= execution.getVariable("snssai")
                String domaintype = execution.getVariable("domainType")
                String NSIserviceid=execution.getVariable("NSIserviceid")
                String nssiId = execution.getVariable("nssiId")
                String Jobid=execution.getVariable("JobId")
-               def miniute=execution.getVariable("miniute")
+               String miniute=execution.getVariable("miniute")
                String vendor = execution.getVariable("vendor")
-               String jobstatus ="error"
+               String jobstatus
 
 
                logger.debug("Query the jobid activation of SNSSAI: "+ Jobid)
@@ -294,9 +294,9 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                logger.debug("the NSSID is : "+nssiId)
                logger.debug("the NSIserviceid is : "+NSIserviceid)
 
-        JobStatusRequest jobStatusRequest = new JobStatusRequest()
+               JobStatusRequest jobStatusRequest = new JobStatusRequest()
 
-        EsrInfo info = new EsrInfo()
+               EsrInfo info = new EsrInfo()
                info.setNetworkType(NetworkType.fromString(domaintype))
                info.setVendor(vendor)
 
@@ -306,66 +306,46 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
 
 
                ObjectMapper mapper = new ObjectMapper()
-               String Reqjson = mapper.writeValueAsString(jobStatusRequest)
-               String isActivateSuccessfull=false
-
-               String urlString = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint", execution)
-               String nssmfRequest = urlString + "/api/rest/provMns/v1/NSS/jobs/" +Jobid
+               String nssmfRequest = mapper.writeValueAsString(jobStatusRequest)
+               String isActivateSuccessfull
 
-               //send request to active  NSSI TN option
-               URL url = new URL(nssmfRequest)
+               String urlString = "/api/rest/provMns/v1/NSS/jobs/" +Jobid
 
-        HttpClient httpClient = new HttpClientFactory().newJsonClient(url,  ONAPComponents.EXTERNAL)
-               Response httpResponse = httpClient.post(Reqjson)
+               JobStatusResponse jobStatusResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest, JobStatusResponse.class)
 
-               int responseCode = httpResponse.getStatus()
-               logger.debug("NSSMF activation response code is: " + responseCode)
-
-               if (responseCode == 404) {
-                       exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad job status Response from NSSMF.")
-                       isActivateSuccessfull = false
-                       execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
-                       jobstatus="error"
-               }else if(responseCode == 200) {
-                       if (httpResponse.hasEntity()) {
-                               JobStatusResponse jobStatusResponse = httpResponse.readEntity(JobStatusResponse.class)
-                               execution.setVariable("statusDescription", jobStatusResponse.getResponseDescriptor().getStatusDescription())
-                               jobstatus = jobStatusResponse.getResponseDescriptor().getStatus()
-                               switch(jobstatus) {
-                                       case "started":
-                                       case "processing":
-                                               isActivateSuccessfull = "waitting"
-                                               execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
-                                               break
-                                       case "finished":
-                                               isActivateSuccessfull = "true"
-                                               execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
-                                               execution.setVariable("activateNumberSlice",execution.getVariable("activateNumberSlice")+ 1)
-                                               break
-                                       case "error":
-                                       default:
-                                               isActivateSuccessfull = "false"
-                                               execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
-
-                               }
-                               if(Integer.parseInt(miniute) > 6 )
-                               {
+               if (jobStatusResponse != null) {
+                       execution.setVariable("statusDescription", jobStatusResponse.getResponseDescriptor().getStatusDescription())
+                       jobstatus = jobStatusResponse.getResponseDescriptor().getStatus()
+                       switch(jobstatus) {
+                               case "started":
+                               case "processing":
+                                       isActivateSuccessfull = "waitting"
+                                       execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
+                                       break
+                               case "finished":
+                                       isActivateSuccessfull = "true"
+                                       execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
+                                       execution.setVariable("activateNumberSlice",execution.getVariable("activateNumberSlice")+ 1)
+                                       break
+                               case "error":
+                               default:
                                        isActivateSuccessfull = "false"
                                        execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a timeout job status Response from NSSMF.")
-                               }
-                       }else
+
+                       }
+                       if(Integer.parseInt(miniute) > 6 )
                        {
-                               exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad job status Response from NSSMF.")
-                               isActivateSuccessfull = false
+                               isActivateSuccessfull = "false"
                                execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a timeout job status Response from NSSMF.")
                        }
                } else {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad job status Response from NSSMF.")
                        isActivateSuccessfull = false
                        execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
-                       exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad job status Response from NSSMF.")
                }
        }
+
        public void SendCommandToNssmf(DelegateExecution execution) {
 
                String snssai= execution.getVariable("snssai")
@@ -380,60 +360,39 @@ class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
                logger.debug("the NSSID is : "+nssiId)
                logger.debug("the NSIserviceid is : "+NSIserviceid)
 
-        EsrInfo esr = new EsrInfo();
+               EsrInfo esr = new EsrInfo();
                esr.setNetworkType(NetworkType.fromString(domaintype))
                esr.setVendor(vendor)
 
-        ActDeActNssi actNssi = new ActDeActNssi();
+               ActDeActNssi actNssi = new ActDeActNssi();
                actNssi.setNsiId(NSIserviceid);
                actNssi.setNssiId(nssiId);
-        NssiActDeActRequest actRequest = new NssiActDeActRequest();
+               NssiActDeActRequest actRequest = new NssiActDeActRequest();
                actRequest.setActDeActNssi(actNssi);
                actRequest.setEsrInfo(esr)
 
-               ObjectMapper mapper = new ObjectMapper();
-               String json = mapper.writeValueAsString(actRequest);
-
-
-               String urlString = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint", execution)
+               ObjectMapper mapper = new ObjectMapper()
+               String nssmfRequest = mapper.writeValueAsString(actRequest)
 
-               //Prepare auth for NSSMF - Begin
-               def authHeader = ""
-               String basicAuth = UrnPropertiesReader.getVariable("mso.nssmf.auth", execution)
                String operationType = execution.getVariable("operationType")
 
-               String nssmfRequest = urlString + "/api/rest/provMns/v1/NSS/" + snssai + "/" + operationType
-
-               //send request to active  NSSI TN option
-               URL url = new URL(nssmfRequest)
-
-        HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL)
-               Response httpResponse = httpClient.post(json)
-
-               int responseCode = httpResponse.getStatus()
-               logger.debug("NSSMF activate response code is: " + responseCode)
-               checkNssmfResponse(httpResponse, execution)
+               String urlString = "/api/rest/provMns/v1/NSS/" + snssai + "/" + operationType.toLowerCase()
 
-        NssiResponse nssmfResponse = httpResponse.readEntity(NssiResponse.class)
-               String jobId  = nssmfResponse.getJobId() ?: ""
-               execution.setVariable("JobId", jobId)
+               NssiResponse nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest, NssiResponse.class)
 
-       }
-       private void checkNssmfResponse(Response httpResponse, DelegateExecution execution) {
-               int responseCode = httpResponse.getStatus()
-               logger.debug("NSSMF response code is: " + responseCode)
-
-               if ( responseCode < 200 || responseCode > 202 || !httpResponse.hasEntity()) {
-                       exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Response from NSSMF.")
+               if (nssmfResponse != null) {
+                       String  isNSSIActivated = "true"
+                       execution.setVariable("isNSSIActivated", isNSSIActivated)
+                       String jobId  = nssmfResponse.getJobId() ?: ""
+                       execution.setVariable("JobId", jobId)
+               } else {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Response from NSSMF.")
                        String  isNSSIActivated = "false"
                        execution.setVariable("isNSSIActivated", isNSSIActivated)
                        execution.setVariable("isNSSIActivate","false")
-               }else{
-                       String  isNSSIActivated = "true"
-                       execution.setVariable("isNSSIActivated", isNSSIActivated)
                }
-       }
 
+       }
 
        void sendSyncError (DelegateExecution execution) {
                logger.trace("start sendSyncError")