1 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
3 import javax.xml.parsers.DocumentBuilder
\r
4 import javax.xml.parsers.DocumentBuilderFactory
\r
6 import org.camunda.bpm.engine.delegate.BpmnError
\r
7 import org.camunda.bpm.engine.runtime.Execution
\r
8 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
\r
9 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
10 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
\r
11 import org.openecomp.mso.bpmn.common.scripts.VfModule
\r
12 import org.openecomp.mso.bpmn.common.scripts.VfModuleBase
\r
13 import org.openecomp.mso.bpmn.core.WorkflowException
\r
14 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
15 import org.openecomp.mso.rest.APIResponse
\r
16 import org.openecomp.mso.rest.RESTClient
\r
17 import org.openecomp.mso.rest.RESTConfig
\r
18 import org.springframework.web.util.UriUtils
\r
19 import org.w3c.dom.Document
\r
20 import org.w3c.dom.Element
\r
21 import org.xml.sax.InputSource
\r
22 import static org.apache.commons.lang3.StringUtils.*
\r
24 public class DoDeleteVfModuleFromVnf extends VfModuleBase {
\r
26 def Prefix="DDVFMV_"
\r
27 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
28 JsonUtils jsonUtil = new JsonUtils()
\r
30 public void initProcessVariables(Execution execution) {
\r
31 execution.setVariable("prefix",Prefix)
\r
32 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", null)
\r
35 // parse the incoming request
\r
36 public void preProcessRequest(Execution execution) {
\r
37 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
38 initProcessVariables(execution)
\r
42 // Building Block-type request
\r
44 // Set mso-request-id to request-id for VNF Adapter interface
\r
45 String requestId = execution.getVariable("msoRequestId")
\r
46 execution.setVariable("mso-request-id", requestId)
\r
47 execution.setVariable("requestId", requestId)
\r
48 utils.log("DEBUG", "msoRequestId: " + requestId, isDebugEnabled)
\r
49 String tenantId = execution.getVariable("tenantId")
\r
50 utils.log("DEBUG", "tenantId: " + tenantId, isDebugEnabled)
\r
51 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
\r
52 execution.setVariable("cloudSiteId", cloudSiteId)
\r
53 utils.log("DEBUG", "cloudSiteId: " + cloudSiteId, isDebugEnabled)
\r
54 // Source is HARDCODED
\r
55 String source = "VID"
\r
56 execution.setVariable("source", source)
\r
57 // isVidRequest is hardcoded to "true"
\r
58 execution.setVariable("isVidRequest", "true")
\r
59 // SrvInstId is hardcoded to empty
\r
60 execution.setVariable("srvInstId", "")
\r
61 // ServiceId is hardcoded to empty
\r
62 execution.setVariable("serviceId", "")
\r
63 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
64 utils.log("DEBUG", "serviceInstanceId: " + serviceInstanceId, isDebugEnabled)
\r
65 String vnfId = execution.getVariable("vnfId")
\r
66 utils.log("DEBUG", "vnfId: " + vnfId, isDebugEnabled)
\r
67 String vfModuleId = execution.getVariable("vfModuleId")
\r
68 utils.log("DEBUG", "vfModuleId: " + vfModuleId, isDebugEnabled)
\r
69 if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
\r
70 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", vfModuleId)
\r
73 execution.setVariable(Prefix + "serviceInstanceIdToSdnc", serviceInstanceId)
\r
76 String sdncVersion = execution.getVariable("sdncVersion")
\r
77 if (sdncVersion == null) {
\r
78 sdncVersion = "1707"
\r
80 execution.setVariable(Prefix + "sdncVersion", sdncVersion)
\r
81 utils.log("DEBUG", "Incoming Sdnc Version is: " + sdncVersion, isDebugEnabled)
\r
83 String sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
\r
84 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
\r
85 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
\r
87 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
\r
89 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
\r
90 utils.logAudit("SDNC Callback URL: " + sdncCallbackUrl)
\r
91 utils.log("DEBUG:", "SDNC Callback URL is: " + sdncCallbackUrl, isDebugEnabled)
\r
95 }catch(BpmnError b){
\r
97 }catch(Exception e){
\r
98 utils.log("DEBUG", "Exception is: " + e.getMessage(), isDebugEnabled)
\r
99 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error encountered in PreProcess method!")
\r
103 public void queryAAIForVfModule(Execution execution) {
\r
104 def method = getClass().getSimpleName() + '.queryAAIForVfModule(' +
\r
105 'execution=' + execution.getId() +
\r
107 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
108 logDebug('Entered ' + method, isDebugLogEnabled)
\r
111 def vnfId = execution.getVariable('vnfId')
\r
113 AaiUtil aaiUriUtil = new AaiUtil(this)
\r
114 def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
\r
115 logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
\r
117 String endPoint = execution.getVariable("URN_aai_endpoint") + "${aai_uri}/" + UriUtils.encode(vnfId, "UTF-8") + "?depth=1"
\r
119 utils.logAudit("DoDeleteVfModuleFromVnf: AAI endPoint : " + endPoint)
\r
122 utils.logAudit("DoDeleteVfModuleFromVnf: - invoking httpGet to AAI")
\r
123 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
\r
125 def responseData = response.getResponseBodyAsString()
\r
126 execution.setVariable('DDVMFV_getVnfResponseCode', response.getStatusCode())
\r
127 execution.setVariable('DDVMFV_getVnfResponse', responseData)
\r
129 utils.logAudit("DoDeleteVfModuleFromVnf: AAI Response : " + responseData)
\r
130 utils.logAudit("DoDeleteVfModuleFromVnf: AAI ResponseCode : " + response.getStatusCode())
\r
132 logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
\r
133 logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
\r
135 } catch (Exception ex) {
\r
136 ex.printStackTrace()
\r
137 logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(), isDebugLogEnabled)
\r
138 execution.setVariable('DDVMFV_getVnfResponseCode', 500)
\r
139 execution.setVariable('DDVFMV_getVnfResponse', 'AAI GET Failed:' + ex.getMessage())
\r
141 logDebug('Exited ' + method, isDebugLogEnabled)
\r
142 } catch (BpmnError e) {
\r
144 } catch (Exception e) {
\r
145 logError('Caught exception in ' + method, e)
\r
146 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVfModule(): ' + e.getMessage())
\r
151 * Validate the VF Module. That is, confirm that a VF Module with the input VF Module ID
\r
152 * exists in the retrieved Generic VNF. Then, check to make sure that if that VF Module
\r
153 * is the base VF Module and it's not the only VF Module for this Generic VNF, that we're not
\r
154 * attempting to delete it.
\r
156 * @param execution The flow's execution instance.
\r
158 public void validateVfModule(Execution execution) {
\r
159 def method = getClass().getSimpleName() + '.validateVfModule(' +
\r
160 'execution=' + execution.getId() +
\r
162 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
163 logDebug('Entered ' + method, isDebugLogEnabled)
\r
166 def genericVnf = execution.getVariable('DDVMFV_getVnfResponse')
\r
167 def vnfId = execution.getVariable('_vnfId')
\r
168 def vfModuleId = execution.getVariable('vfModuleId')
\r
169 def VfModule vfModule = findVfModule(genericVnf, vfModuleId)
\r
170 if (vfModule == null) {
\r
171 def String msg = 'VF Module \'' + vfModuleId + '\' does not exist in Generic VNF \'' + vnfId + '\''
\r
172 logDebug(msg, isDebugLogEnabled)
\r
173 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, msg)
\r
176 if (isDebugLogEnabled) {
\r
177 logDebug('VF Module \'' + vfModuleId + '\': isBaseVfModule=' + vfModule.isBaseVfModule() +
\r
178 ', isOnlyVfModule=' + vfModule.isOnlyVfModule(),
\r
181 if (vfModule.isBaseVfModule() && !vfModule.isOnlyVfModule()) {
\r
182 def String msg = 'Cannot delete VF Module \'' + vfModuleId +
\r
183 '\'since it is the base VF Module and it\'s not the only VF Module in Generic VNF \'' + vnfId + '\''
\r
184 logDebug("Received a BAD Response from VNF Adapter for CREATE_VF_MODULE Call.", isDebugLogEnabled)
\r
185 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
\r
188 def heatStackId = vfModule.getElementText('heat-stack-id')
\r
189 execution.setVariable('DDVMFV_heatStackId', heatStackId)
\r
190 logDebug('VF Module heatStackId retrieved from AAI: ' + heatStackId, isDebugLogEnabled)
\r
193 logDebug('Exited ' + method, isDebugLogEnabled)
\r
194 } catch (BpmnError e) {
\r
196 } catch (Exception e) {
\r
197 logError('Caught exception in ' + method, e)
\r
198 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in validateVfModule(): ' + e.getMessage())
\r
203 public void preProcessSDNCDeactivateRequest(Execution execution){
\r
204 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
205 execution.setVariable("prefix", Prefix)
\r
206 logDebug(" ======== STARTED preProcessSDNCDeactivateRequest ======== ", isDebugLogEnabled)
\r
208 def serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
211 //Build SDNC Request
\r
213 String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
\r
215 deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
\r
216 execution.setVariable("DDVMFV_deactivateSDNCRequest", deactivateSDNCRequest)
\r
217 logDebug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest, isDebugLogEnabled)
\r
218 utils.logAudit("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
\r
220 }catch(Exception e){
\r
221 utils.log("ERROR", "Exception Occured Processing preProcessSDNCDeactivateRequest. Exception is:\n" + e, isDebugLogEnabled)
\r
222 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
\r
224 logDebug("======== COMPLETED preProcessSDNCDeactivateRequest ======== ", isDebugLogEnabled)
\r
227 public void preProcessSDNCUnassignRequest(Execution execution) {
\r
228 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
\r
229 'execution=' + execution.getId() +
\r
231 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
232 logDebug('Entered ' + method, isDebugLogEnabled)
\r
233 execution.setVariable("prefix", Prefix)
\r
234 logDebug(" ======== STARTED preProcessSDNCUnassignRequest Process ======== ", isDebugLogEnabled)
\r
236 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
238 String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
\r
240 execution.setVariable("DDVMFV_unassignSDNCRequest", unassignSDNCRequest)
\r
241 logDebug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest, isDebugLogEnabled)
\r
242 utils.logAudit("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
\r
244 }catch(Exception e){
\r
245 log.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e, isDebugLogEnabled)
\r
246 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
\r
248 logDebug("======== COMPLETED preProcessSDNCUnassignRequest Process ======== ", isDebugLogEnabled)
\r
251 public String buildSDNCRequest(Execution execution, String svcInstId, String action){
\r
253 String uuid = execution.getVariable('testReqId') // for junits
\r
255 uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
\r
257 def callbackURL = execution.getVariable("sdncCallbackUrl")
\r
258 def requestId = execution.getVariable("msoRequestId")
\r
259 def serviceId = execution.getVariable("serviceId")
\r
260 def serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
261 def vfModuleId = execution.getVariable("vfModuleId")
\r
262 def source = execution.getVariable("source")
\r
263 def vnfId = execution.getVariable("vnfId")
\r
265 def sdncVersion = execution.getVariable(Prefix + "sdncVersion")
\r
267 String sdncRequest =
\r
268 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
\r
269 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
\r
270 xmlns:sdncadapter="http://org.openecomp.mso/workflow/sdnc/adapter/schema/v1">
\r
271 <sdncadapter:RequestHeader>
\r
272 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
\r
273 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
\r
274 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
\r
275 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
\r
276 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
\r
277 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
\r
278 </sdncadapter:RequestHeader>
\r
279 <sdncadapterworkflow:SDNCRequestData>
\r
280 <request-information>
\r
281 <request-id>${requestId}</request-id>
\r
282 <request-action>DeleteVfModuleInstance</request-action>
\r
283 <source>${source}</source>
\r
284 <notification-url/>
\r
287 </request-information>
\r
288 <service-information>
\r
290 <subscription-service-type/>
\r
291 <service-instance-id>${serviceInstanceId}</service-instance-id>
\r
292 <global-customer-id/>
\r
293 </service-information>
\r
295 <vnf-id>${vnfId}</vnf-id>
\r
298 <vf-module-information>
\r
299 <vf-module-id>${vfModuleId}</vf-module-id>
\r
300 </vf-module-information>
\r
301 <vf-module-request-input/>
\r
302 </sdncadapterworkflow:SDNCRequestData>
\r
303 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
\r
305 utils.logAudit("sdncRequest: " + sdncRequest)
\r
309 public void validateSDNCResponse(Execution execution, String response, String method){
\r
310 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
\r
311 execution.setVariable("prefix",Prefix)
\r
312 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
\r
314 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
315 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
\r
317 utils.logAudit("workflowException: " + workflowException)
\r
319 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
\r
320 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
\r
322 utils.logAudit("SDNCResponse: " + response)
\r
324 String sdncResponse = response
\r
325 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
\r
326 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
\r
328 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
\r
329 throw new BpmnError("MSOWorkflowException")
\r
331 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
\r
335 // parse the incoming DELETE_VF_MODULE request
\r
336 // and formulate the outgoing VnfAdapterDeleteV1 request
\r
337 public void prepVNFAdapterRequest(Execution execution) {
\r
338 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
339 def requestId = UUID.randomUUID().toString()
\r
340 def origRequestId = execution.getVariable('requestId')
\r
341 def srvInstId = execution.getVariable("serviceInstanceId")
\r
342 def aicCloudRegion = execution.getVariable("cloudSiteId")
\r
343 def vnfId = execution.getVariable("vnfId")
\r
344 def vfModuleId = execution.getVariable("vfModuleId")
\r
345 def vfModuleStackId = execution.getVariable('DDVMFV_heatStackId')
\r
346 def tenantId = execution.getVariable("tenantId")
\r
347 def messageId = execution.getVariable('requestId') + '-' +
\r
348 System.currentTimeMillis()
\r
349 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
\r
350 def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host")
\r
351 if ('true'.equals(useQualifiedHostName)) {
\r
352 notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
\r
355 String request = """
\r
356 <deleteVfModuleRequest>
\r
357 <cloudSiteId>${aicCloudRegion}</cloudSiteId>
\r
358 <tenantId>${tenantId}</tenantId>
\r
359 <vnfId>${vnfId}</vnfId>
\r
360 <vfModuleId>${vfModuleId}</vfModuleId>
\r
361 <vfModuleStackId>${vfModuleStackId}</vfModuleStackId>
\r
362 <skipAAI>true</skipAAI>
\r
364 <requestId>${origRequestId}</requestId>
\r
365 <serviceInstanceId>${srvInstId}</serviceInstanceId>
\r
367 <messageId>${messageId}</messageId>
\r
368 <notificationUrl>${notificationUrl}</notificationUrl>
\r
369 </deleteVfModuleRequest>
\r
372 utils.log("DEBUG", "vnfAdapterRestV1Request: " + request, isDebugEnabled)
\r
373 utils.logAudit("deleteVfModuleRequest: " + request)
\r
374 execution.setVariable("vnfAdapterRestV1Request", request)
\r
378 // generates a WorkflowException if
\r
380 public void handleDoDeleteVfModuleFailure(Execution execution) {
\r
381 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
382 utils.log("ERROR", "AAI error occurred deleting the Generic Vnf: "
\r
383 + execution.getVariable("DDVFMV_deleteGenericVnfResponse"), isDebugEnabled)
\r
384 String processKey = getProcessKey(execution);
\r
385 WorkflowException exception = new WorkflowException(processKey, 5000,
\r
386 execution.getVariable("DDVFMV_deleteGenericVnfResponse"))
\r
387 execution.setVariable("WorkflowException", exception)
\r
390 public void postProcessVNFAdapterRequest(Execution execution) {
\r
391 def method = getClass().getSimpleName() + '.postProcessVNFAdapterRequest(' +
\r
392 'execution=' + execution.getId() +
\r
394 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
395 logDebug('Entered ' + method, isDebugLogEnabled)
\r
396 execution.setVariable("prefix",Prefix)
\r
398 logDebug(" *** STARTED postProcessVNFAdapterRequest Process*** ", isDebugLogEnabled)
\r
400 String vnfResponse = execution.getVariable("DDVMFV_doDeleteVfModuleResponse")
\r
401 logDebug("VNF Adapter Response is: " + vnfResponse, isDebugLogEnabled)
\r
402 utils.logAudit("deleteVnfAResponse is: \n" + vnfResponse)
\r
404 if(vnfResponse != null){
\r
406 if(vnfResponse.contains("deleteVfModuleResponse")){
\r
407 logDebug("Received a Good Response from VNF Adapter for DELETE_VF_MODULE Call.", isDebugLogEnabled)
\r
408 execution.setVariable("DDVFMV_vnfVfModuleDeleteCompleted", true)
\r
410 // Parse vnfOutputs for contrail network polcy FQDNs
\r
411 def vfModuleOutputsXml = utils.getNodeXml(vnfResponse, "vfModuleOutputs")
\r
412 if(!isBlank(vfModuleOutputsXml)) {
\r
413 vfModuleOutputsXml = utils.removeXmlNamespaces(vfModuleOutputsXml)
\r
414 List contrailNetworkPolicyFqdnList = []
\r
415 for(Node node: utils.getMultNodeObjects(vfModuleOutputsXml, "entry")) {
\r
416 String key = utils.getChildNodeText(node, "key")
\r
419 } else if (key.endsWith("contrail_network_policy_fqdn")) {
\r
420 String contrailNetworkPolicyFqdn = utils.getChildNodeText(node, "value")
\r
421 logDebug("Obtained contrailNetworkPolicyFqdn: " + contrailNetworkPolicyFqdn, isDebugLogEnabled)
\r
422 contrailNetworkPolicyFqdnList.add(contrailNetworkPolicyFqdn)
\r
424 else if (key.equals("oam_management_v4_address")) {
\r
425 String oamManagementV4Address = utils.getChildNodeText(node, "value")
\r
426 logDebug("Obtained oamManagementV4Address: " + oamManagementV4Address, isDebugLogEnabled)
\r
427 execution.setVariable(Prefix + "oamManagementV4Address", oamManagementV4Address)
\r
429 else if (key.equals("oam_management_v6_address")) {
\r
430 String oamManagementV6Address = utils.getChildNodeText(node, "value")
\r
431 logDebug("Obtained oamManagementV6Address: " + oamManagementV6Address, isDebugLogEnabled)
\r
432 execution.setVariable(Prefix + "oamManagementV6Address", oamManagementV6Address)
\r
435 if (!contrailNetworkPolicyFqdnList.isEmpty()) {
\r
436 logDebug("Setting the fqdn list", isDebugLogEnabled)
\r
437 execution.setVariable("DDVFMV_contrailNetworkPolicyFqdnList", contrailNetworkPolicyFqdnList)
\r
441 logDebug("Received a BAD Response from VNF Adapter for DELETE_VF_MODULE Call.", isDebugLogEnabled)
\r
442 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "VNF Adapter Error")
\r
445 logDebug("Response from VNF Adapter is Null for DELETE_VF_MODULE Call.", isDebugLogEnabled)
\r
446 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Empty response from VNF Adapter")
\r
449 }catch(BpmnError b){
\r
451 }catch(Exception e){
\r
452 logDebug("Internal Error Occured in PostProcess Method", isDebugLogEnabled)
\r
453 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Internal Error Occured in PostProcess Method")
\r
455 logDebug(" *** COMPLETED postProcessVnfAdapterResponse Process*** ", isDebugLogEnabled)
\r
458 public void deleteNetworkPoliciesFromAAI(Execution execution) {
\r
459 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
\r
460 'execution=' + execution.getId() +
\r
462 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
463 logDebug('Entered ' + method, isDebugLogEnabled)
\r
464 execution.setVariable("prefix", Prefix)
\r
465 logDebug(" ======== STARTED deleteNetworkPoliciesFromAAI ======== ", isDebugLogEnabled)
\r
469 List fqdnList = execution.getVariable("DDVFMV_contrailNetworkPolicyFqdnList")
\r
470 if (fqdnList == null) {
\r
471 logDebug("No network policies to delete", isDebugLogEnabled)
\r
474 int fqdnCount = fqdnList.size()
\r
476 execution.setVariable("DDVFMV_networkPolicyFqdnCount", fqdnCount)
\r
477 logDebug("DDVFMV_networkPolicyFqdnCount - " + fqdnCount, isDebugLogEnabled)
\r
479 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
\r
480 AaiUtil aaiUriUtil = new AaiUtil(this)
\r
481 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
\r
483 if (fqdnCount > 0) {
\r
484 // AII loop call over contrail network policy fqdn list
\r
485 for (i in 0..fqdnCount-1) {
\r
488 String fqdn = fqdnList[i]
\r
490 // Query AAI for this network policy FQDN
\r
492 String queryNetworkPolicyByFqdnAAIRequest = "${aai_endpoint}${aai_uri}?network-policy-fqdn=" + UriUtils.encode(fqdn, "UTF-8")
\r
493 utils.logAudit("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest)
\r
494 logDebug("AAI request endpoint: " + queryNetworkPolicyByFqdnAAIRequest, isDebugLogEnabled)
\r
496 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyByFqdnAAIRequest)
\r
497 int returnCode = response.getStatusCode()
\r
498 execution.setVariable("DCVFM_aaiQueryNetworkPolicyByFqdnReturnCode", returnCode)
\r
499 logDebug(" ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugLogEnabled)
\r
501 String aaiResponseAsString = response.getResponseBodyAsString()
\r
503 if (isOneOf(returnCode, 200, 201)) {
\r
504 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
\r
505 // This network policy FQDN exists in AAI - need to delete it now
\r
506 utils.logAudit(aaiResponseAsString)
\r
507 execution.setVariable("DDVFMV_queryNetworkPolicyByFqdnAAIResponse", aaiResponseAsString)
\r
508 logDebug("QueryAAINetworkPolicyByFQDN Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugLogEnabled)
\r
509 // Retrieve the network policy id for this FQDN
\r
510 def networkPolicyId = utils.getNodeText1(aaiResponseAsString, "network-policy-id")
\r
511 logDebug("Deleting network-policy with network-policy-id " + networkPolicyId, isDebugLogEnabled)
\r
513 // Retrieve the resource version for this network policy
\r
514 def resourceVersion = utils.getNodeText1(aaiResponseAsString, "resource-version")
\r
515 logDebug("Deleting network-policy with resource-version " + resourceVersion, isDebugLogEnabled)
\r
517 String delNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(networkPolicyId, "UTF-8") +
\r
518 "?resource-version=" + UriUtils.encode(resourceVersion, "UTF-8")
\r
519 utils.logAudit("AAI request endpoint: " + delNetworkPolicyAAIRequest)
\r
520 logDebug("AAI request endpoint: " + delNetworkPolicyAAIRequest, isDebugLogEnabled)
\r
522 logDebug("invoking DELETE call to AAI", isDebugLogEnabled)
\r
523 utils.logAudit("Sending DELETE call to AAI with Endpoint /n" + delNetworkPolicyAAIRequest)
\r
524 APIResponse responseDel = aaiUriUtil.executeAAIDeleteCall(execution, delNetworkPolicyAAIRequest)
\r
525 int returnCodeDel = responseDel.getStatusCode()
\r
526 execution.setVariable("DDVFMV_aaiDeleteNetworkPolicyReturnCode", returnCodeDel)
\r
527 logDebug(" ***** AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + returnCodeDel, isDebugLogEnabled)
\r
529 if (isOneOf(returnCodeDel, 200, 201, 204)) {
\r
530 logDebug("The return code from deleting network policy is: " + returnCodeDel, isDebugLogEnabled)
\r
531 // This network policy was deleted from AAI successfully
\r
532 logDebug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ", isDebugLogEnabled)
\r
536 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + returnCodeDel
\r
537 logDebug(delErrorMessage, isDebugLogEnabled)
\r
538 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
\r
540 } else if (returnCode == 404) {
\r
541 // This network policy FQDN is not in AAI. No need to delete.
\r
542 logDebug("The return code is: " + returnCode, isDebugLogEnabled)
\r
543 logDebug("This network policy FQDN is not in AAI: " + fqdn, isDebugLogEnabled)
\r
544 utils.logAudit("Network policy FQDN is not in AAI")
\r
546 if (aaiResponseAsString.contains("RESTFault")) {
\r
547 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
548 execution.setVariable("WorkflowException", exceptionObject)
\r
549 throw new BpmnError("MSOWorkflowException")
\r
553 String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + returnCode
\r
554 logDebug(dataErrorMessage, isDebugLogEnabled)
\r
555 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
566 logDebug("No contrail network policies to query/create", isDebugLogEnabled)
\r
570 } catch (BpmnError e) {
\r
573 } catch (Exception ex) {
\r
574 String exceptionMessage = "Bpmn error encountered in DoDeletVfModule flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
\r
575 logDebug(exceptionMessage, isDebugLogEnabled)
\r
576 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
581 // and formulate the outgoing DeleteAAIVfModuleRequest request
\r
582 public void prepDeleteAAIVfModule(Execution execution) {
\r
583 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
585 def vnfId = execution.getVariable("vnfId")
\r
586 def vfModuleId = execution.getVariable("vfModuleId")
\r
587 // formulate the request for UpdateAAIVfModule
\r
588 String request = """<DeleteAAIVfModuleRequest>
\r
589 <vnf-id>${vnfId}</vnf-id>
\r
590 <vf-module-id>${vfModuleId}</vf-module-id>
\r
591 </DeleteAAIVfModuleRequest>""" as String
\r
592 utils.log("DEBUG", "DeleteAAIVfModuleRequest :" + request, isDebugEnabled)
\r
593 utils.logAudit("DeleteAAIVfModuleRequest: " + request)
\r
594 execution.setVariable("DeleteAAIVfModuleRequest", request)
\r