ddf2706635c68844937b7532a7a354f2a55473e8
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoDeleteVnfAndModules.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import static org.apache.commons.lang3.StringUtils.*;
24
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.json.JSONArray;
28 import org.json.JSONObject;
29 import org.onap.so.bpmn.common.scripts.AaiUtil
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
34 import org.onap.so.bpmn.common.scripts.VidUtils
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.domain.ModelInfo
38 import org.onap.so.bpmn.core.domain.ModuleResource
39 import org.onap.so.bpmn.core.domain.ServiceDecomposition
40 import org.onap.so.bpmn.core.domain.VnfResource
41 import org.onap.so.bpmn.core.json.JsonUtils
42 import org.onap.so.client.graphinventory.entities.uri.Depth
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory
45 import org.onap.so.client.aai.AAIObjectType
46 import org.onap.so.logger.MessageEnum
47 import org.onap.so.logger.MsoLogger
48 import org.onap.so.rest.APIResponse
49 import org.springframework.web.util.UriUtils;
50
51 /**
52  * This class supports the macro VID Flow
53  * with the deletion of a generic vnf and related VF modules.
54  */
55 class DoDeleteVnfAndModules extends AbstractServiceTaskProcessor {
56         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteVnfAndModules.class);
57
58         String Prefix="DDVAM_"
59         ExceptionUtil exceptionUtil = new ExceptionUtil()
60         JsonUtils jsonUtil = new JsonUtils()
61         VidUtils vidUtils = new VidUtils(this)
62         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
63
64         /**
65          * This method gets and validates the incoming
66          * request.
67          *
68          * @param - execution
69          *      
70          */
71         public void preProcessRequest(DelegateExecution execution) {
72
73                 execution.setVariable("prefix",Prefix)
74                 msoLogger.trace("STARTED DoDeleteVnfAndModules PreProcessRequest Process")
75
76                 try{
77                         // Get Variables                                
78                         
79                         String cloudConfiguration = execution.getVariable("cloudConfiguration")         
80                         msoLogger.debug("Cloud Configuration: " + cloudConfiguration)   
81                         
82                         String requestId = execution.getVariable("msoRequestId")
83                         execution.setVariable("requestId", requestId)                   
84                         execution.setVariable("mso-request-id", requestId)
85                         msoLogger.debug("Incoming Request Id is: " + requestId)
86
87                         String serviceInstanceId = execution.getVariable("serviceInstanceId")                   
88                         msoLogger.debug("Incoming Service Instance Id is: " + serviceInstanceId)
89
90                         String vnfId = execution.getVariable("vnfId")                   
91                         msoLogger.debug("Incoming Vnf Id is: " + vnfId)                 
92                         
93                         String source = "VID"
94                         execution.setVariable("DDVAM_source", source)
95                         msoLogger.debug("Incoming Source is: " + source)
96                         
97                         execution.setVariable("DDVAM_isVidRequest", "true")
98                         
99                         String sdncVersion = execution.getVariable("sdncVersion")
100                         if (sdncVersion == null) {
101                                 sdncVersion = "1702"
102                         }
103                         execution.setVariable("DDVAM_sdncVersion", sdncVersion)
104                         msoLogger.debug("Incoming Sdnc Version is: " + sdncVersion)
105                         
106                         // Set aLaCarte flag to false
107                         execution.setVariable("aLaCarte", false)
108                         
109                         String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback", execution)
110                         if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
111                                 def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
112                                 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception");
113                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
114                         }
115                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
116                         msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
117                         msoLogger.debug("SDNC Callback URL is: " + sdncCallbackUrl)     
118                         
119                         
120                         if (!sdncVersion.equals("1702")) {
121                                 //String vnfModelInfo = execution.getVariable("vnfModelInfo")
122                                 //String serviceModelInfo = execution.getVariable("serviceModelInfo")
123                                 
124                                 String serviceId = execution.getVariable("productFamilyId")
125                                 execution.setVariable("DDVAM_serviceId", serviceId)
126                                 msoLogger.debug("Incoming Service Id is: " + serviceId)
127                                 
128                                         
129                                 //String modelInvariantId = jsonUtil.getJsonValue(vnfModelInfo, "modelInvariantId")
130                                 //execution.setVariable("DDVAM_modelInvariantId", modelInvariantId)
131                                 //msoLogger.debug("Incoming Invariant Id is: " + modelInvariantId)
132                                 
133                                 //String modelVersionId = jsonUtil.getJsonValue(vnfModelInfo, "modelVersionId")
134                                 //if (modelVersionId == null) {
135                                 //      modelVersionId = ""
136                                 //}
137                                 //execution.setVariable("DDVAM_modelVersionId", modelVersionId)
138                                 //msoLogger.debug("Incoming Version Id is: " + modelVersionId)
139         
140                                 //String modelVersion = jsonUtil.getJsonValue(vnfModelInfo, "modelVersion")
141                                 //execution.setVariable("DDVAM_modelVersion", modelVersion)
142                                 //msoLogger.debug("Incoming Model Version is: " + modelVersion)
143                                 
144                                 //String modelName = jsonUtil.getJsonValue(vnfModelInfo, "modelName")
145                                 //execution.setVariable("DDVAM_modelName", modelName)
146                                 //msoLogger.debug("Incoming Model Name is: " + modelName)
147                                 
148                                 //String modelCustomizationId = jsonUtil.getJsonValue(vnfModelInfo, "modelCustomizationId")
149                                 //if (modelCustomizationId == null) {
150                                 //      modelCustomizationId = ""
151                                 //}
152                                 //execution.setVariable("DDVAM_modelCustomizationId", modelCustomizationId)
153                                 //msoLogger.debug("Incoming Model Customization Id is: " + modelCustomizationId)
154                                         
155                                 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
156                                 execution.setVariable("DDVAM_cloudSiteId", cloudSiteId)
157                                 msoLogger.debug("Incoming Cloud Site Id is: " + cloudSiteId)
158                                         
159                                 String tenantId = execution.getVariable("tenantId")
160                                 execution.setVariable("DDVAM_tenantId", tenantId)
161                                 msoLogger.debug("Incoming Tenant Id is: " + tenantId)
162                                 
163                                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
164                                 if (globalSubscriberId == null) {
165                                         globalSubscriberId = ""
166                                 }
167                                 execution.setVariable("DDVAM_globalSubscriberId", globalSubscriberId)
168                                 msoLogger.debug("Incoming Global Subscriber Id is: " + globalSubscriberId)              
169                                 
170                         }
171                         execution.setVariable("DDVAM_vfModulesFromDecomposition", null)
172                         // Retrieve serviceDecomposition if present
173                         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
174                         if (serviceDecomposition != null) {
175                                 msoLogger.debug("Getting Catalog DB data from ServiceDecomposition object: " + serviceDecomposition.toJsonString())
176                                 List<VnfResource> vnfs = serviceDecomposition.getVnfResources()
177                                 msoLogger.debug("Read vnfs")
178                                 if (vnfs == null) {
179                                         msoLogger.debug("Error - vnfs are empty in serviceDecomposition object")
180                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in preProcessRequest - vnfs are empty")
181                                 }
182                                 VnfResource vnf = vnfs[0]
183                                 
184                                 if (vnf == null) {
185                                         msoLogger.debug("Error - vnf is empty in serviceDecomposition object")
186                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in preProcessRequest - vnf is empty")
187                                 }
188                                 
189                                 List<ModuleResource> vfModules = vnf.getAllVfModuleObjects()
190                                 
191                                 execution.setVariable("DDVAM_vfModulesFromDecomposition", vfModules)                            
192                         }
193                         
194                         execution.setVariable("DDVAM_moduleCount", 0)
195                         execution.setVariable("DDVAM_nextModule", 0)
196                         
197                         
198                 }catch(BpmnError b){
199                         msoLogger.debug("Rethrowing MSOWorkflowException")
200                         throw b
201                 }catch(Exception e){
202                         msoLogger.debug(" Error Occured in DoCreateVnfAndModules PreProcessRequest method!" + e.getMessage())
203                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PreProcessRequest")
204
205                 }
206                 msoLogger.trace("COMPLETED DoDeleteVnfAndModules PreProcessRequest Process ")
207         }       
208
209         
210         
211         public void preProcessAddOnModule(DelegateExecution execution){
212
213                 execution.setVariable("prefix", Prefix)
214                 msoLogger.trace("STARTED preProcessAddOnModule ")
215                 
216                 try {                   
217                         JSONArray addOnModules = (JSONArray) execution.getVariable("addOnModules")
218                         int addOnIndex = (int) execution.getVariable("addOnModulesDeployed")
219                         
220                         JSONObject addOnModule = addOnModules[addOnIndex]
221                         
222                         def newVfModuleId = UUID.randomUUID().toString()
223                         execution.setVariable("addOnVfModuleId", newVfModuleId)
224                         
225                         execution.setVariable("instancesOfThisModelDeployed", 0)
226                         
227                         JSONObject addOnVfModuleModelInfoObject = jsonUtil.getJsonValueForKey(addOnModule, "modelInfo")
228                         String addOnVfModuleModelInfo = addOnVfModuleModelInfoObject.toString()
229                         execution.setVariable("addOnVfModuleModelInfo", addOnVfModuleModelInfo)
230                         String addOnVfModuleLabel = jsonUtil.getJsonValueForKey(addOnModule, "vfModuleLabel")
231                         execution.setVariable("addOnVfModuleLabel", addOnVfModuleLabel)
232                         String addOnPersonaModelId = jsonUtil.getJsonValueForKey(addOnVfModuleModelInfoObject, "modelInvariantUuid")
233                         execution.setVariable("addOnPersonaModelId", addOnPersonaModelId)
234                         String addOnInitialCount = jsonUtil.getJsonValueForKey(addOnModule, "initialCount")
235                         execution.setVariable("initialCount", addOnInitialCount)
236                                         
237                 
238                 }catch(Exception e){
239                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessAddOnModule." + e, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
240                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessAddOnModule Method:\n" + e.getMessage())
241                 }
242                 msoLogger.trace("COMPLETED preProcessSDNCAssignRequest ")
243         }
244         
245         /**
246          * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
247          * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
248          *
249          * @param execution The flow's execution instance.
250          */
251         public void queryAAIVfModule(DelegateExecution execution) {
252
253                 def method = getClass().getSimpleName() + '.queryAAIVfModule(' +
254                         'execution=' + execution.getId() +
255                         ')'
256                 msoLogger.trace('Entered ' + method)
257
258                 try {
259                         def vnfId = execution.getVariable('vnfId')
260                         
261                         AaiUtil aaiUriUtil = new AaiUtil(this)
262                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
263                         String endPoint = aaiUriUtil.createAaiUri(uri)
264                         
265                         msoLogger.debug("AAI endPoint: " + endPoint)
266
267                         try {
268                                 msoLogger.debug("createVfModule - invoking httpGet() to AAI")
269                                 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
270
271                                 def responseData = response.getResponseBodyAsString()
272                                 if (responseData != null) {
273                                         msoLogger.debug("Received generic VNF data: " + responseData)
274
275                                 }
276
277                                 msoLogger.debug("createVfModule - queryAAIVfModule Response: " + responseData)
278                                 msoLogger.debug("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatusCode())
279
280                                 execution.setVariable('DCVFM_queryAAIVfModuleResponseCode', response.getStatusCode())
281                                 execution.setVariable('DCVFM_queryAAIVfModuleResponse', responseData)
282                                 msoLogger.debug('Response code:' + response.getStatusCode())
283                                 msoLogger.debug('Response:' + System.lineSeparator() + responseData)
284                                 //Map<String, String>[] vfModules = new HashMap<String,String>[]
285                                 List<ModuleResource> vfModulesFromDecomposition = execution.getVariable("DDVAM_vfModulesFromDecomposition")
286                                 def vfModulesList = new ArrayList<Map<String,String>>()
287                                 def vfModules = null
288                                 def vfModuleBaseEntry = null
289                                 if (response.getStatusCode() == 200) {
290                                         // Parse the VNF record from A&AI to find base module info
291                                         msoLogger.debug('Parsing the VNF data to find base module info')
292                                         if (responseData != null) {
293                                                 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
294                                                 msoLogger.debug("vModulesText: " + vfModulesText)
295                                                 if (vfModulesText != null && !vfModulesText.trim().isEmpty()) {
296                                                         def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
297                                                         vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
298                                                         execution.setVariable("DDVAM_moduleCount", vfModules.size())
299                                                         int vfModulesSize = 0
300                                                         ModelInfo vfModuleModelInfo = null
301                                                         for (i in 0..vfModules.size()-1) {
302                                                                 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
303                                                         
304                                                                 Map<String, String> vfModuleEntry = new HashMap<String, String>()
305                                                                 def vfModuleId = utils.getNodeText(vfModuleXml, "vf-module-id")
306                                                                 vfModuleEntry.put("vfModuleId", vfModuleId)
307                                                                 def vfModuleName = utils.getNodeText(vfModuleXml, "vf-module-name")      
308                                                                 vfModuleEntry.put("vfModuleName", vfModuleName)
309                                                                 
310                                                                 // Find the model for this vf module in decomposition if specified
311                                                                 if (vfModulesFromDecomposition != null) {
312                                                                         msoLogger.debug("vfModulesFromDecomposition is not null")
313                                                                         def vfModuleUuid = utils.getNodeText(vfModuleXml, "model-version-id")
314                                                                         if (vfModuleUuid == null) {
315                                                                                 vfModuleUuid = utils.getNodeText(vfModuleXml, "persona-model-version")
316                                                                         }
317                                                                         msoLogger.debug("vfModule UUID is: " + vfModuleUuid)
318                                                                         for (j in 0..vfModulesFromDecomposition.size()-1) {
319                                                                                 ModuleResource mr = vfModulesFromDecomposition[j]
320                                                                                 if (mr.getModelInfo().getModelUuid() == vfModuleUuid) {
321                                                                                         msoLogger.debug("Found modelInfo")
322                                                                                         vfModuleModelInfo = mr.getModelInfo()
323                                                                                         break                                                                                   
324                                                                                 }
325                                                                                 
326                                                                         }                                                                       
327                                                                 }
328                                                                 if (vfModuleModelInfo != null) {
329                                                                         String vfModuleModelInfoString = vfModuleModelInfo.toString()
330                                                                         def vfModuleModelInfoValue = jsonUtil.getJsonValue(vfModuleModelInfoString, "modelInfo")
331                                                                         vfModuleEntry.put("vfModuleModelInfo", vfModuleModelInfoValue)
332                                                                 }
333                                                                 else {
334                                                                         vfModuleEntry.put("vfModuleModelInfo", null)
335                                                                 }
336                                                                 
337                                                                 
338                                                                 def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
339                                                                 // Save base vf module for last
340                                                                 if (isBaseVfModule == "true") {
341                                                                         vfModuleBaseEntry = vfModuleEntry
342                                                                 }
343                                                                 else {                                          
344                                                                         vfModulesList.add(vfModuleEntry)
345                                                                 }
346                                                         }
347                                                         if (vfModuleBaseEntry != null) {
348                                                                 vfModulesList.add(vfModuleBaseEntry)
349                                                         }                                       
350                                                 }
351                                                 
352                                         }                                       
353                                 }
354                                 execution.setVariable("DDVAM_vfModules", vfModulesList)
355                         } catch (Exception ex) {
356                                 ex.printStackTrace()
357                                 msoLogger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
358                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
359                         }
360                         msoLogger.trace('Exited ' + method)
361                 } catch (BpmnError e) {
362                         throw e;
363                 } catch (Exception e) {
364                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
365                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())
366                 }
367         }
368         
369         public void prepareNextModuleToDelete(DelegateExecution execution){
370
371                 execution.setVariable("prefix", Prefix)
372                 msoLogger.trace("STARTED prepareNextModuleToDelete ")
373                 
374                 try {
375                         int i = execution.getVariable("DDVAM_nextModule")
376                         def vfModules = execution.getVariable("DDVAM_vfModules")
377                         def vfModule = vfModules[i]
378                         
379                         def vfModuleId = vfModule.get("vfModuleId")
380                         execution.setVariable("DDVAM_vfModuleId", vfModuleId)
381                         
382                         def vfModuleName = vfModule.get("vfModuleName")
383                         execution.setVariable("DDVAM_vfModuleName", vfModuleName)                       
384                         
385                         def vfModuleModelInfo = vfModule.get("vfModuleModelInfo")
386                         msoLogger.debug("vfModuleModelInfo for module delete: " + vfModuleModelInfo)
387                         execution.setVariable("DDVAM_vfModuleModelInfo", vfModuleModelInfo)                     
388                         
389                 }catch(Exception e){
390                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessAddOnModule." + e, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
391                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareNextModuleToDelete Method:\n" + e.getMessage())
392                 }
393                 msoLogger.trace("COMPLETED prepareNextModuleToDelete ")
394         }
395         
396         public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
397
398                 execution.setVariable("prefix", Prefix)
399                 msoLogger.trace("STARTED preProcessSDNCDeactivateRequest ")
400                 def vnfId = execution.getVariable("vnfId")
401                 def serviceInstanceId = execution.getVariable("serviceInstanceId")              
402
403                 try{
404                         //Build SDNC Request
405                         
406                         String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
407
408                         deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
409                         execution.setVariable("DDVAM_deactivateSDNCRequest", deactivateSDNCRequest)
410                         msoLogger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
411                         msoLogger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
412
413                 }catch(Exception e){
414                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preProcessSDNCDeactivateRequest." + e, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
415                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
416                 }
417                 msoLogger.trace("COMPLETED preProcessSDNCDeactivateRequest ")
418         }
419         
420         public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
421                 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
422                         'execution=' + execution.getId() +
423                         ')'
424
425                 msoLogger.trace('Entered ' + method)
426                 execution.setVariable("prefix", Prefix)
427                 msoLogger.trace("STARTED preProcessSDNCUnassignRequest Process ")
428                 try{
429                         String vnfId = execution.getVariable("vnfId")
430                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
431
432                         String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
433
434                         execution.setVariable("DDVAM_unassignSDNCRequest", unassignSDNCRequest)
435                         msoLogger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
436                         msoLogger.debug("Outgoing UnassignSDNCRequest is: \n"  + unassignSDNCRequest)
437
438                 }catch(Exception e){
439                         msoLogger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
440                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
441                 }
442                 msoLogger.trace("COMPLETED  preProcessSDNCUnassignRequest Process ")
443         }
444         
445         public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
446                 
447                                 String uuid = execution.getVariable('testReqId') // for junits
448                                 if(uuid==null){
449                                         uuid = execution.getVariable("msoRequestId") + "-" +    System.currentTimeMillis()
450                                 }
451                                 def callbackURL = execution.getVariable("sdncCallbackUrl")
452                                 def requestId = execution.getVariable("msoRequestId")
453                                 def serviceId = execution.getVariable("DDVAM_serviceId")                                
454                                 def tenantId = execution.getVariable("DDVAM_tenantId")
455                                 def source = execution.getVariable("DDVAM_source")
456                                 def vnfId = execution.getVariable("vnfId")
457                                 def serviceInstanceId = execution.getVariable("serviceInstanceId")
458                                 def cloudSiteId = execution.getVariable("DDVAM_cloudSiteId")                            
459                                 def modelCustomizationId = execution.getVariable("DDVAM_modelCustomizationId")                          
460                                 //def serviceModelInfo = execution.getVariable("serviceModelInfo")
461                                 //def vnfModelInfo = execution.getVariable("vnfModelInfo")
462                                 //String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
463                                 //String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)                             
464                                 def globalSubscriberId = execution.getVariable("DDVAM_globalSubscriberId")
465                                 def sdncVersion = execution.getVariable("DDVAM_sdncVersion")                                            
466                                 
467                                 String sdncRequest =
468                                 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
469                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
470                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
471            <sdncadapter:RequestHeader>
472                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
473                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
474                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
475                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
476                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
477                                 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
478                 </sdncadapter:RequestHeader>
479         <sdncadapterworkflow:SDNCRequestData>
480                 <request-information>
481                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
482                         <request-action>DeleteVnfInstance</request-action>
483                         <source>${MsoUtils.xmlEscape(source)}</source>
484                         <notification-url/>
485                         <order-number/>
486                         <order-version/>
487                 </request-information>
488                 <service-information>
489                         <service-id/>
490                         <subscription-service-type/>                    
491                         <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
492                         <global-customer-id/>
493                 </service-information>
494                 <vnf-information>
495                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
496                         <vnf-type/>                     
497                 </vnf-information>
498                 <vnf-request-input>                     
499                         <vnf-name/>
500                         <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
501                         <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>                 
502                 </vnf-request-input>
503         </sdncadapterworkflow:SDNCRequestData>
504         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
505                 
506                         msoLogger.debug("sdncRequest:  " + sdncRequest)
507                         return sdncRequest
508         }
509                 
510         public void validateSDNCResponse(DelegateExecution execution, String response, String method){
511
512                 execution.setVariable("prefix",Prefix)
513                 msoLogger.trace("STARTED ValidateSDNCResponse Process")
514
515                 WorkflowException workflowException = execution.getVariable("WorkflowException")
516                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
517
518                 msoLogger.debug("workflowException: " + workflowException)
519
520                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
521                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
522
523                 msoLogger.debug("SDNCResponse: " + response)
524
525                 String sdncResponse = response
526                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
527                         msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse)                     
528                 }else{
529                         msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
530                         throw new BpmnError("MSOWorkflowException")
531                 }
532                 msoLogger.trace("COMPLETED ValidateSDNCResponse Process")
533         }
534         
535         
536         
537         
538         
539         
540         
541 }