47aec462771832047fc32bb6d88755c9a9527e1b
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.scripts
24
25 import org.onap.aai.domain.yang.GenericVnf
26 import org.onap.aai.domain.yang.NetworkPolicies
27 import org.onap.aai.domain.yang.NetworkPolicy
28 import org.onap.aai.domain.yang.VfModule
29 import org.onap.so.logger.ErrorCode
30
31 import static org.apache.commons.lang3.StringUtils.*
32 import org.camunda.bpm.engine.delegate.BpmnError
33 import org.camunda.bpm.engine.delegate.DelegateExecution
34 import org.onap.so.bpmn.common.scripts.AaiUtil
35 import org.onap.so.bpmn.common.scripts.ExceptionUtil
36 import org.onap.so.bpmn.common.scripts.MsoUtils
37 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
38 import org.onap.so.bpmn.common.scripts.VfModuleBase
39 import org.onap.so.bpmn.core.UrnPropertiesReader
40 import org.onap.so.bpmn.core.WorkflowException
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.AAIObjectPlurals
44 import org.onap.so.client.aai.AAIObjectType
45 import org.onap.so.client.aai.entities.uri.AAIResourceUri
46 import org.onap.so.client.aai.entities.uri.AAIUriFactory
47 import org.onap.so.logger.MessageEnum
48 import org.slf4j.Logger
49 import org.slf4j.LoggerFactory
50
51 public class DoDeleteVfModuleFromVnf extends VfModuleBase {
52     private static final Logger logger = LoggerFactory.getLogger( DoDeleteVfModuleFromVnf.class);
53         
54         def Prefix="DDVFMV_"
55         ExceptionUtil exceptionUtil = new ExceptionUtil()
56         JsonUtils jsonUtil = new JsonUtils()
57
58         public void initProcessVariables(DelegateExecution execution) {
59                 execution.setVariable("prefix",Prefix)
60                 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", null)
61         }
62
63         // parse the incoming request
64         public void preProcessRequest(DelegateExecution execution) {
65
66                 initProcessVariables(execution)
67
68                 try {
69                         
70                                 // Building Block-type request
71
72                                 // Set mso-request-id to request-id for VNF Adapter interface
73                                 String requestId = execution.getVariable("msoRequestId")
74                                 execution.setVariable("mso-request-id", requestId)
75                                 execution.setVariable("requestId", requestId)
76                                 logger.debug("msoRequestId: " + requestId)
77                                 String tenantId = execution.getVariable("tenantId")
78                                 logger.debug("tenantId: " + tenantId)                           
79                                 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
80                                 execution.setVariable("cloudSiteId", cloudSiteId)
81                                 logger.debug("cloudSiteId: " + cloudSiteId)
82                                 String cloudOwner = execution.getVariable("cloudOwner")
83                                 execution.setVariable("cloudOwner", cloudOwner)
84                                 logger.debug("cloudOwner: " + cloudOwner)
85                                 // Source is HARDCODED
86                                 String source = "VID"
87                                 execution.setVariable("source", source)
88                                 // isVidRequest is hardcoded to "true"
89                                 execution.setVariable("isVidRequest", "true")
90                                 // SrvInstId is hardcoded to empty
91                                 execution.setVariable("srvInstId", "")
92                                 // ServiceId is hardcoded to empty
93                                 execution.setVariable("serviceId", "")
94                                 String serviceInstanceId = execution.getVariable("serviceInstanceId")
95                                 logger.debug("serviceInstanceId: " + serviceInstanceId)
96                                 String vnfId = execution.getVariable("vnfId")
97                                 logger.debug("vnfId: " + vnfId)
98                                 String vfModuleId = execution.getVariable("vfModuleId")
99                                 logger.debug("vfModuleId: " + vfModuleId)
100                                 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
101                                         execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
102                                 }
103                                 else {
104                                         execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
105                                 }                               
106                                 
107                                 String sdncVersion = execution.getVariable("sdncVersion")
108                                 if (sdncVersion == null) {
109                                         sdncVersion = "1707"
110                                 }
111                                 execution.setVariable(Prefix + "sdncVersion", sdncVersion)
112                                 logger.debug("Incoming Sdnc Version is: " + sdncVersion)                                
113                                 
114                                 String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
115                                 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
116                                         def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
117                                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
118                                                         ErrorCode.UnknownError.getValue(), "Exception");
119                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
120                                 }
121                                 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
122                                 logger.debug("SDNC Callback URL: " + sdncCallbackUrl)
123                                 logger.debug("SDNC Callback URL is: " + sdncCallbackUrl)
124
125                         
126                         
127                 }catch(BpmnError b){
128                         throw b
129                 }catch(Exception e){
130                         logger.debug("Exception is: " + e.getMessage())
131                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
132                 }
133         }
134         
135         public void queryAAIForVfModule(DelegateExecution execution) {
136                 def method = getClass().getSimpleName() + '.queryAAIForVfModule(' +
137                         'execution=' + execution.getId() +
138                         ')'
139
140                 logger.trace('Entered ' + method)
141
142                 try {
143                         def vnfId = execution.getVariable('vnfId')
144
145                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
146                         try {
147                                 Optional<GenericVnf> genericVnf = getAAIClient().get(GenericVnf.class,uri)
148
149                                 if(genericVnf.isPresent()){
150                                         execution.setVariable('DDVMFV_getVnfResponseCode', 200)
151                                         execution.setVariable('DDVMFV_getVnfResponse', genericVnf.get())
152                                 }else{
153                                         execution.setVariable('DDVMFV_getVnfResponseCode', 404)
154                                         execution.setVariable('DDVMFV_getVnfResponse', "Generic Vnf not found!")
155                                 }
156                         } catch (Exception ex) {
157                                 ex.printStackTrace()
158                                 logger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
159                                 execution.setVariable('DDVMFV_getVnfResponseCode', 500)
160                                 execution.setVariable('DDVFMV_getVnfResponse', 'AAI GET Failed:' + ex.getMessage())
161                         }
162                         logger.trace('Exited ' + method)
163                 } catch (BpmnError e) {
164                         throw e;
165                 } catch (Exception e) {
166                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
167                                         'Caught exception in ' + method, "BPMN",
168                                         ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
169                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVfModule(): ' + e.getMessage())
170                 }
171         }
172         
173         /**
174          * Validate the VF Module.  That is, confirm that a VF Module with the input VF Module ID
175          * exists in the retrieved Generic VNF.  Then, check to make sure that if that VF Module
176          * is the base VF Module and it's not the only VF Module for this Generic VNF, that we're not
177          * attempting to delete it.
178          *
179          * @param execution The flow's execution instance.
180          */
181         public void validateVfModule(DelegateExecution execution) {
182                 def method = getClass().getSimpleName() + '.validateVfModule(' +
183                         'execution=' + execution.getId() +
184                         ')'
185                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
186                 logger.trace('Entered ' + method)
187
188                 try {
189                         GenericVnf genericVnf = execution.getVariable('DDVMFV_getVnfResponse')
190                         def vnfId = execution.getVariable('_vnfId')
191                         def vfModuleId = execution.getVariable('vfModuleId')
192             Optional<VfModule> vfModule = Optional.empty()
193             if(genericVnf.getVfModules()!=null && ! genericVnf.getVfModules().getVfModule().isEmpty()) {
194                 vfModule = genericVnf.getVfModules().getVfModule().stream().filter { v -> v.getVfModuleId().equals(vfModuleId) }.findFirst()
195             }
196                         if (!vfModule.isPresent()) {
197                                 String msg = 'VF Module \'' + vfModuleId + '\' does not exist in Generic VNF \'' + vnfId + '\''
198                                 logger.debug(msg)
199                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, msg)
200                         } else {
201                 Boolean isOnlyVfModule = (genericVnf.getVfModules().getVfModule().size() == 1)
202                                 if (isDebugLogEnabled) {
203                                         logger.debug('VF Module \'' + vfModuleId + '\': isBaseVfModule=' + vfModule.get().isIsBaseVfModule() + ', isOnlyVfModule=' + isOnlyVfModule)
204                                 }
205                                 if (vfModule.get().isIsBaseVfModule() && !isOnlyVfModule) {
206                     String msg = 'Cannot delete VF Module \'' + vfModuleId +
207                             '\'since it is the base VF Module and it\'s not the only VF Module in Generic VNF \'' + vnfId + '\''
208                     logger.debug(msg)
209                     exceptionUtil.buildAndThrowWorkflowException(execution, 1002,msg)
210                                 }
211                                 def heatStackId = vfModule.get().getHeatStackId()
212                                 execution.setVariable('DDVMFV_heatStackId', heatStackId)
213                                 logger.debug('VF Module heatStackId retrieved from AAI: ' + heatStackId)
214                         }
215                         logger.trace('Exited ' + method)
216                 } catch (BpmnError e) {
217                         throw e;
218                 } catch (Exception e) {
219                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
220                                         'Caught exception in ' + method, "BPMN",
221                                         ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
222                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in validateVfModule(): ' + e.getMessage())
223                 }
224         }
225
226
227         public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
228
229                 execution.setVariable("prefix", Prefix)
230                 logger.trace("STARTED preProcessSDNCDeactivateRequest ")
231                 
232                 def serviceInstanceId = execution.getVariable("serviceInstanceId")
233         
234                 try{
235                         //Build SDNC Request
236                         
237                         String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
238         
239                         deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
240                         execution.setVariable("DDVMFV_deactivateSDNCRequest", deactivateSDNCRequest)
241                         logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
242                         
243         
244                 }catch(Exception e){
245                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
246                                         "Exception Occured Processing preProcessSDNCDeactivateRequest. Exception is:\n" + e, "BPMN",
247                                         ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
248                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
249                 }
250                 logger.trace("COMPLETED preProcessSDNCDeactivateRequest ")
251         }
252
253         public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
254                 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
255                         'execution=' + execution.getId() +
256                         ')'
257
258                 logger.trace('Entered ' + method)
259                 execution.setVariable("prefix", Prefix)
260                 logger.trace("STARTED preProcessSDNCUnassignRequest Process ")
261                 try{                    
262                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
263         
264                         String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
265         
266                         execution.setVariable("DDVMFV_unassignSDNCRequest", unassignSDNCRequest)
267                         logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
268                         
269         
270                 }catch(Exception e){
271                         logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
272                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
273                 }
274                 logger.trace("COMPLETED  preProcessSDNCUnassignRequest Process ")
275         }
276
277         public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
278         
279                         String uuid = execution.getVariable('testReqId') // for junits
280                         if(uuid==null){
281                                 uuid = execution.getVariable("msoRequestId") + "-" +    System.currentTimeMillis()
282                         }
283                         def callbackURL = execution.getVariable("sdncCallbackUrl")      
284                         def requestId = execution.getVariable("msoRequestId")
285                         def serviceId = execution.getVariable("serviceId")
286                         def serviceInstanceId = execution.getVariable("serviceInstanceId")
287                         def vfModuleId = execution.getVariable("vfModuleId")
288                         def source = execution.getVariable("source")
289                         def vnfId = execution.getVariable("vnfId")
290                                 
291                         def sdncVersion = execution.getVariable(Prefix + "sdncVersion")
292                         
293                         String sdncRequest =
294                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
295                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
296                                                                                                         xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
297            <sdncadapter:RequestHeader>
298                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
299                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
300                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
301                                 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
302                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
303                                 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
304                 </sdncadapter:RequestHeader>
305         <sdncadapterworkflow:SDNCRequestData>
306                 <request-information>
307                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
308                         <request-action>DeleteVfModuleInstance</request-action>
309                         <source>${MsoUtils.xmlEscape(source)}</source>
310                         <notification-url/>
311                         <order-number/>
312                         <order-version/>
313                 </request-information>
314                 <service-information>
315                         <service-id/>
316                         <subscription-service-type/>                    
317                         <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
318                         <global-customer-id/>
319                 </service-information>
320                 <vnf-information>
321                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
322                         <vnf-type/>                     
323                 </vnf-information>
324                 <vf-module-information>
325                         <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
326                 </vf-module-information>
327                 <vf-module-request-input/>              
328         </sdncadapterworkflow:SDNCRequestData>
329         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
330         
331                 logger.debug("sdncRequest:  " + sdncRequest)
332                 return sdncRequest
333         }
334         
335         public void validateSDNCResponse(DelegateExecution execution, String response, String method){
336
337                 execution.setVariable("prefix",Prefix)
338                 logger.trace("STARTED ValidateSDNCResponse Process")
339         
340                 WorkflowException workflowException = execution.getVariable("WorkflowException")
341                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
342         
343                 logger.debug("workflowException: " + workflowException)
344         
345                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
346                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
347         
348                 logger.debug("SDNCResponse: " + response)
349         
350                 String sdncResponse = response
351                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
352                         logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + sdncResponse)
353                 }else{
354                         logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
355                         throw new BpmnError("MSOWorkflowException")
356                 }
357                 logger.trace("COMPLETED ValidateSDNCResponse Process")
358         }
359
360
361         // parse the incoming DELETE_VF_MODULE request
362         // and formulate the outgoing VnfAdapterDeleteV1 request
363         public void prepVNFAdapterRequest(DelegateExecution execution) {
364
365                 def requestId = UUID.randomUUID().toString()
366                 def origRequestId = execution.getVariable('requestId')
367                 def srvInstId = execution.getVariable("serviceInstanceId")
368                 def aicCloudRegion = execution.getVariable("cloudSiteId")
369                 def cloudOwner = execution.getVariable("cloudOwner")
370                 def vnfId = execution.getVariable("vnfId")
371                 def vfModuleId = execution.getVariable("vfModuleId")
372                 def vfModuleStackId = execution.getVariable('DDVMFV_heatStackId')
373                 def tenantId = execution.getVariable("tenantId")
374                 def messageId = execution.getVariable('requestId') + '-' +
375                         System.currentTimeMillis()
376                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
377                 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
378                 if ('true'.equals(useQualifiedHostName)) {
379                         notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
380                 }
381
382                 String request = """
383                         <deleteVfModuleRequest>
384                             <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
385                             <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
386                             <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
387                             <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
388                             <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
389                             <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
390                             <skipAAI>true</skipAAI>
391                             <msoRequest>
392                                 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
393                                 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
394                             </msoRequest>
395                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
396                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
397                         </deleteVfModuleRequest>
398                         """ as String
399
400                 logger.debug("vnfAdapterRestV1Request: " + request)
401                 logger.debug("deleteVfModuleRequest: " + request)
402                 execution.setVariable("vnfAdapterRestV1Request", request)
403         }
404
405         
406         // generates a WorkflowException if
407         //              -
408         public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
409                 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
410                                 "AAI error occurred deleting the Generic Vnf: " + execution.getVariable("DDVFMV_deleteGenericVnfResponse"),
411                                 "BPMN", ErrorCode.UnknownError.getValue(), "Exception");
412                 String processKey = getProcessKey(execution);
413                 WorkflowException exception = new WorkflowException(processKey, 5000,
414                         execution.getVariable("DDVFMV_deleteGenericVnfResponse"))
415                 execution.setVariable("WorkflowException", exception)
416         }
417         
418         public void postProcessVNFAdapterRequest(DelegateExecution execution) {
419                 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
420                         'execution=' + execution.getId() +
421                         ')'
422
423                 logger.trace('Entered ' + method)
424                 execution.setVariable("prefix",Prefix)
425                 try{
426                 logger.trace("STARTED postProcessVNFAdapterRequest Process")
427                 
428                 String vnfResponse = execution.getVariable("DDVMFV_doDeleteVfModuleResponse")
429                 logger.debug("VNF Adapter Response is: " + vnfResponse)
430                 logger.debug("deleteVnfAResponse is: \n"  + vnfResponse)
431
432                 if(vnfResponse != null){
433
434                         if(vnfResponse.contains("deleteVfModuleResponse")){
435                                 logger.debug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.")
436                                 execution.setVariable("DDVFMV_vnfVfModuleDeleteCompleted", true)
437
438                                 // Parse vnfOutputs for contrail network polcy FQDNs
439                                 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
440                                 if(!isBlank(vfModuleOutputsXml)) {
441                                         vfModuleOutputsXml = utils.removeXmlNamespaces(vfModuleOutputsXml)
442                                         List contrailNetworkPolicyFqdnList = []
443                                         for(Node node: utils.getMultNodeObjects(vfModuleOutputsXml, "entry")) {
444                                                 String key = utils.getChildNodeText(node, "key")
445                                                 if(key == null) {
446                                                         
447                                                 } else if (key.endsWith("contrail_network_policy_fqdn")) {
448                                                         String contrailNetworkPolicyFqdn = utils.getChildNodeText(node, "value")
449                                                         logger.debug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn)
450                                                         contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
451                                                 }
452                                                 else if (key.equals("oam_management_v4_address")) {
453                                                         String oamManagementV4Address = utils.getChildNodeText(node, "value")
454                                                         logger.debug("Obtained oamManagementV4Address: " + oamManagementV4Address)
455                                                         execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
456                                                 }
457                                                 else if (key.equals("oam_management_v6_address")) {
458                                                         String oamManagementV6Address = utils.getChildNodeText(node, "value")
459                                                         logger.debug("Obtained oamManagementV6Address: " + oamManagementV6Address)
460                                                         execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
461                                                 }
462                                         }
463                                         if (!contrailNetworkPolicyFqdnList.isEmpty()) {
464                                                 logger.debug("Setting the fqdn list")
465                                                 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
466                                         }
467                                 }
468                         }else{
469                                 logger.debug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.")
470                                 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
471                         }
472                 }else{
473                         logger.debug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.")
474                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
475                 }
476
477                 }catch(BpmnError b){
478                         throw b
479                 }catch(Exception e){
480                         logger.debug("Internal Error Occured in PostProcess Method")
481                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
482                 }
483                 logger.trace("COMPLETED postProcessVnfAdapterResponse Process")
484         }
485
486         public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
487                 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
488                 'execution=' + execution.getId() +
489                 ')'
490
491                 logger.trace('Entered ' + method)
492                 execution.setVariable("prefix", Prefix)
493                 logger.trace("STARTED deleteNetworkPoliciesFromAAI ")
494
495                 try {
496                         // get variables
497                         List fqdnList = execution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")
498                         if (fqdnList == null) {
499                                 logger.debug("No network policies to delete")
500                                 return
501                         }
502                         int fqdnCount = fqdnList.size()
503
504                         execution.setVariable("DDVFMV_networkPolicyFqdnCount", fqdnCount)
505                         logger.debug("DDVFMV_networkPolicyFqdnCount - " + fqdnCount)
506
507                         AaiUtil aaiUriUtil = new AaiUtil(this)
508
509                         if (fqdnCount > 0) {
510                                 // AII loop call over contrail network policy fqdn list
511                                 for (i in 0..fqdnCount-1) {
512
513                                         int counting = i+1
514                                         String fqdn = fqdnList[i]
515
516                                         // Query AAI for this network policy FQDN
517
518                                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
519                                         uri.queryParam("network-policy-fqdn", fqdn)
520
521                     try {
522                         Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
523
524                         if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
525                             NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
526                             execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 200)
527                             // This network policy FQDN exists in AAI - need to delete it now
528                             // Retrieve the network policy id for this FQDN
529                             def networkPolicyId = networkPolicy.getNetworkPolicyId()
530                             logger.debug("Deleting network-policy with network-policy-id " + networkPolicyId)
531
532                             // Retrieve the resource version for this network policy
533                             try {
534                                 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicyId)
535                                 getAAIClient().delete(delUri)
536                                 execution.setVariable("DDVFMV_aaiDeleteNetworkPolicyReturnCode", 200)
537                                 logger.debug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
538                                 // This network policy was deleted from AAI successfully
539                                 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
540                             } catch (Exception e) {
541                                 // aai all errors
542                                 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
543                                 logger.debug(delErrorMessage)
544                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
545                             }
546                         } else {
547                             execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", 404)
548                             // This network policy FQDN is not in AAI. No need to delete.
549                             logger.debug("This network policy FQDN is not in AAI: " + fqdn)
550                             logger.debug("Network policy FQDN is not in AAI")
551                         }
552                     } catch (Exception e) {
553                         // aai all errors
554                         String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
555                         logger.debug(dataErrorMessage)
556                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
557                     }
558                 } // end loop
559                         } else {
560                                    logger.debug("No contrail network policies to query/create")
561
562                         }
563
564                 } catch (BpmnError e) {
565                         throw e;
566
567                 } catch (Exception ex) {
568                         String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
569                         logger.debug(exceptionMessage)
570                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
571                 }
572
573         }       
574         
575         // and formulate the outgoing DeleteAAIVfModuleRequest request
576         public void prepDeleteAAIVfModule(DelegateExecution execution) {
577
578
579                 def vnfId = execution.getVariable("vnfId")
580                 def vfModuleId = execution.getVariable("vfModuleId")
581                 // formulate the request for UpdateAAIVfModule
582                 String request = """<DeleteAAIVfModuleRequest>
583                                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
584                                                                 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
585                                                         </DeleteAAIVfModuleRequest>""" as String
586                 logger.debug("DeleteAAIVfModuleRequest :" + request)
587                 
588                 execution.setVariable("DeleteAAIVfModuleRequest", request)
589         }
590 }