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