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