2  * ============LICENSE_START=======================================================
 
   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
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  23 package org.onap.so.bpmn.infrastructure.scripts
 
  25 import org.onap.so.logger.LoggingAnchor
 
  26 import org.camunda.bpm.engine.delegate.BpmnError
 
  27 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  28 import org.onap.aai.domain.yang.NetworkPolicies
 
  29 import org.onap.aai.domain.yang.NetworkPolicy
 
  30 import org.onap.so.bpmn.common.scripts.AaiUtil
 
  31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  33 import org.onap.so.bpmn.common.scripts.MsoUtils
 
  34 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
 
  35 import org.onap.so.bpmn.core.UrnPropertiesReader
 
  36 import org.onap.so.bpmn.core.WorkflowException
 
  37 import org.onap.aaiclient.client.aai.AAIObjectPlurals
 
  38 import org.onap.aaiclient.client.aai.AAIObjectType
 
  39 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
 
  40 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
 
  41 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
 
  42 import org.onap.logging.filter.base.ErrorCode
 
  43 import org.onap.so.logger.MessageEnum
 
  44 import org.slf4j.Logger
 
  45 import org.slf4j.LoggerFactory
 
  47 import javax.ws.rs.NotFoundException
 
  50 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
 
  51     private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleRollback.class);
 
  54     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  56     public void initProcessVariables(DelegateExecution execution) {
 
  57         execution.setVariable("prefix",Prefix)
 
  60     // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
 
  61     // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
 
  62     public void preProcessRequest(DelegateExecution execution) {
 
  65         initProcessVariables(execution)
 
  69             execution.setVariable("rolledBack", null)
 
  70             execution.setVariable("rollbackError", null)
 
  72             def rollbackData = execution.getVariable("rollbackData")
 
  73             logger.debug("RollbackData:" + rollbackData)
 
  75             if (rollbackData != null) {
 
  76                 String vnfId = rollbackData.get("VFMODULE", "vnfid")
 
  77                 execution.setVariable("DCVFMR_vnfId", vnfId)
 
  78                 String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
 
  79                 execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
 
  80                 String source = rollbackData.get("VFMODULE", "source")
 
  81                 execution.setVariable("DCVFMR_source", source)
 
  82                 String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
 
  83                 execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
 
  84                 String serviceId = rollbackData.get("VFMODULE", "service-id")
 
  85                 execution.setVariable("DCVFMR_serviceId", serviceId)
 
  86                 String vnfType = rollbackData.get("VFMODULE", "vnftype")
 
  87                 execution.setVariable("DCVFMR_vnfType", vnfType)
 
  88                 String vnfName = rollbackData.get("VFMODULE", "vnfname")
 
  89                 execution.setVariable("DCVFMR_vnfName", vnfName)
 
  90                 String tenantId = rollbackData.get("VFMODULE", "tenantid")
 
  91                 execution.setVariable("DCVFMR_tenantId", tenantId)
 
  92                 String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
 
  93                 execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
 
  94                 String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
 
  95                 execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
 
  96                 String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
 
  97                 execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
 
  98                 String cloudOwner = rollbackData.get("VFMODULE", "cloudowner")
 
  99                 execution.setVariable("DCVFMR_cloudOwner", cloudOwner)
 
 100                 String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
 
 101                 execution.setVariable("DCVFMR_heatStackId", heatStackId)
 
 102                 String requestId = rollbackData.get("VFMODULE", "msorequestid")
 
 103                 execution.setVariable("DCVFMR_requestId", requestId)
 
 104                 // Set mso-request-id to request-id for VNF Adapter interface
 
 105                 execution.setVariable("mso-request-id", requestId)
 
 106                 List createdNetworkPolicyFqdnList = []
 
 109                     String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
 
 113                     createdNetworkPolicyFqdnList.add(fqdn)
 
 114                     logger.debug("got fqdn # " + i + ": " + fqdn)
 
 119                 execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
 
 120                 String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
 
 121                 execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
 
 122                 String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
 
 123                 execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
 
 124                 //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
 
 125                 //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
 
 126                 execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
 
 127                 execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
 
 128                 execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
 
 129                 execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
 
 130                 execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
 
 131                 execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
 
 132                 execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
 
 133                 execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
 
 135                 // formulate the request for PrepareUpdateAAIVfModule
 
 136                 String request = """<PrepareUpdateAAIVfModuleRequest>
 
 137                                                                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
 
 138                                                                         <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
 
 139                                                                         <orchestration-status>pending-delete</orchestration-status>
 
 140                                                                 </PrepareUpdateAAIVfModuleRequest>""" as String
 
 141                 logger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
 
 142                 execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
 
 144                 execution.setVariable("skipRollback", true)
 
 147             if (execution.getVariable("disableRollback").equals("true" )) {
 
 148                 execution.setVariable("skipRollback", true)
 
 151         } catch (BpmnError e) {
 
 153         } catch (Exception ex){
 
 154             def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
 
 156             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 160     // build a SDNC vnf-topology-operation request for the specified action
 
 161     // (note: the action passed is expected to be 'changedelete' or 'delete')
 
 162     public void prepSDNCAdapterRequest(DelegateExecution execution) {
 
 164         String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
 
 166         String uuid = execution.getVariable('testReqId') // for junits
 
 168             uuid = execution.getVariable("DCVFMR_requestId") + "-" +    System.currentTimeMillis()
 
 171         def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
 
 173         String source = execution.getVariable("DCVFMR_source")
 
 174         String serviceId = execution.getVariable("DCVFMR_serviceId")
 
 175         String vnfId = execution.getVariable("DCVFMR_vnfId")
 
 176         String vnfType = execution.getVariable("DCVFMR_vnfType")
 
 177         String vnfName = execution.getVariable("DCVFMR_vnfName")
 
 178         String tenantId = execution.getVariable("DCVFMR_tenantId")
 
 179         String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
 
 180         String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
 
 181         String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
 
 182         String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
 
 183         String requestId = execution.getVariable("DCVFMR_requestId")
 
 185         String serviceInstanceIdToSdnc = ""
 
 186         if (srvInstId != null && !srvInstId.isEmpty()) {
 
 187             serviceInstanceIdToSdnc = srvInstId
 
 189             serviceInstanceIdToSdnc = vfModuleId
 
 192         def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
 
 193         def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
 
 196         def requestAction = ""
 
 198         if (doSDNCActivateRollback.equals("true")) {
 
 200             requestAction = "DisconnectVNFRequest"
 
 202         else if (doSDNCAssignRollback.equals("true")) {
 
 204             requestAction = "VNFActivateRequest"
 
 210         String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
 
 211                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
 
 212                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
 
 213                                                       <sdncadapter:RequestHeader>
 
 214                                                          <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
 
 215                                                          <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
 
 216                                                          <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
 
 217                                                          <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
 
 218                                                          <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
 
 219                                                       </sdncadapter:RequestHeader>
 
 220                                                       <sdncadapterworkflow:SDNCRequestData>
 
 221                                                          <request-information>
 
 222                                                             <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
 
 223                                                             <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
 
 224                                                             <source>${MsoUtils.xmlEscape(source)}</source>
 
 228                                                          </request-information>
 
 229                                                          <service-information>
 
 230                                                             <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
 
 231                                                                         <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
 
 232                                                             <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
 
 233                                                             <subscriber-name>notsurewecare</subscriber-name>
 
 234                                                          </service-information>
 
 235                                                          <vnf-request-information>
 
 236                                                                 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
 
 237                                                                         <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
 
 238                                     <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
 
 239                                                                         <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
 
 240                                     <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
 
 241                                                                         <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
 
 242                                                                         <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
 
 243                                                                         <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
 
 244                                                          </vnf-request-information>
 
 245                                                       </sdncadapterworkflow:SDNCRequestData>
 
 246                                                    </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
 
 248         logger.debug("sdncAdapterWorkflowRequest: " + request)
 
 249         execution.setVariable("sdncAdapterWorkflowRequest", request)
 
 252     public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
 
 254         execution.setVariable("prefix", Prefix)
 
 255         logger.trace("STARTED preProcessSDNCDeactivateRequest")
 
 257         def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
 
 262             String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
 
 264             deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
 
 265             execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
 
 266             logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
 
 269             logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
 
 270                     "Exception Occured Processing preProcessSDNCDeactivateRequest.", "BPMN",
 
 271                     ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
 
 272             exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
 
 274         logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
 
 277     public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
 
 278         def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
 
 279                 'execution=' + execution.getId() +
 
 281         def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
 
 282         logger.trace('Entered ' + method)
 
 283         execution.setVariable("prefix", Prefix)
 
 284         logger.trace("STARTED preProcessSDNCUnassignRequest Process")
 
 286             String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
 
 288             String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
 
 290             execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
 
 291             logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
 
 294             logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
 
 295             exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
 
 297         logger.trace("COMPLETED  preProcessSDNCUnassignRequest Process")
 
 300     public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
 
 302         String uuid = execution.getVariable('testReqId') // for junits
 
 304             uuid = execution.getVariable("DCVFMR_requestId") + "-" +    System.currentTimeMillis()
 
 306         def callbackURL = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
 
 307         def requestId = execution.getVariable("DCVFMR_requestId")
 
 308         def serviceId = execution.getVariable("DCVFMR_serviceId")
 
 309         def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
 
 310         def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
 
 311         def source = execution.getVariable("DCVFMR_source")
 
 312         def vnfId = execution.getVariable("DCVFMR_vnfId")
 
 314         def sdncVersion = execution.getVariable("sdncVersion")
 
 317                 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
 
 318                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
 
 319                                                                                                         xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
 
 320            <sdncadapter:RequestHeader>
 
 321                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
 
 322                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
 
 323                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
 
 324                                 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
 
 325                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
 
 326                                 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
 
 327                 </sdncadapter:RequestHeader>
 
 328         <sdncadapterworkflow:SDNCRequestData>
 
 329                 <request-information>
 
 330                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
 
 331                         <request-action>DeleteVfModuleInstance</request-action>
 
 332                         <source>${MsoUtils.xmlEscape(source)}</source>
 
 336                 </request-information>
 
 337                 <service-information>
 
 339                         <subscription-service-type/>
 
 340                         <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
 
 341                         <global-customer-id/>
 
 342                 </service-information>
 
 344                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
 
 347                 <vf-module-information>
 
 348                         <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
 
 349                 </vf-module-information>
 
 350                 <vf-module-request-input/>
 
 351         </sdncadapterworkflow:SDNCRequestData>
 
 352         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
 
 354         logger.debug("sdncRequest:  " + sdncRequest)
 
 358     // parse the incoming DELETE_VF_MODULE request
 
 359     // and formulate the outgoing VnfAdapterDeleteV1 request
 
 360     public void prepVNFAdapterRequest(DelegateExecution execution) {
 
 362         String requestId = UUID.randomUUID().toString()
 
 363         String origRequestId = execution.getVariable("DCVFMR_requestId")
 
 364         String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
 
 365         String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
 
 366         String cloudOwner = execution.getVariable("DCVFMR_cloudOwner")
 
 367         String vnfId = execution.getVariable("DCVFMR_vnfId")
 
 368         String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
 
 369         String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
 
 370         String tenantId = execution.getVariable("DCVFMR_tenantId")
 
 371         def messageId = execution.getVariable('mso-request-id') + '-' +
 
 372                 System.currentTimeMillis()
 
 373         def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
 
 374         def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
 
 375         if ('true'.equals(useQualifiedHostName)) {
 
 376             notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
 
 380                         <deleteVfModuleRequest>
 
 381                             <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
 
 382                             <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
 
 383                             <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
 
 384                             <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
 
 385                             <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
 
 386                             <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
 
 387                             <skipAAI>true</skipAAI>
 
 389                                 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
 
 390                                 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
 
 392                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
 
 393                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
 
 394                         </deleteVfModuleRequest>
 
 397         execution.setVariable("vnfAdapterTaskRequest", request)
 
 400     // parse the incoming DELETE_VF_MODULE request
 
 401     // and formulate the outgoing UpdateAAIVfModuleRequest request
 
 402     public void prepUpdateAAIVfModule(DelegateExecution execution) {
 
 404         String vnfId = execution.getVariable("DCVFMR_vnfId")
 
 405         String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
 
 406         // formulate the request for UpdateAAIVfModule
 
 407         String request = """<UpdateAAIVfModuleRequest>
 
 408                                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
 
 409                                                                 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
 
 410                                                                 <heat-stack-id>DELETE</heat-stack-id>
 
 411                                                                 <orchestration-status>deleted</orchestration-status>
 
 412                                                         </UpdateAAIVfModuleRequest>""" as String
 
 413         logger.debug("UpdateAAIVfModuleRequest :" + request)
 
 414         execution.setVariable("UpdateAAIVfModuleRequest", request)
 
 417     // parse the incoming DELETE_VF_MODULE request
 
 418     // and formulate the outgoing UpdateAAIVfModuleRequest request
 
 419     public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
 
 421         String vnfId = execution.getVariable("DCVFMR_vnfId")
 
 422         String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
 
 423         // formulate the request for UpdateAAIVfModule
 
 424         String request = """<UpdateAAIVfModuleRequest>
 
 425                                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
 
 426                                                                 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
 
 427                                                                 <heat-stack-id></heat-stack-id>
 
 428                                                                 <orchestration-status>Assigned</orchestration-status>
 
 429                                                         </UpdateAAIVfModuleRequest>""" as String
 
 430         logger.debug("UpdateAAIVfModuleRequest :" + request)
 
 431         execution.setVariable("UpdateAAIVfModuleRequest", request)
 
 434     // parse the incoming DELETE_VF_MODULE request
 
 435     // and formulate the outgoing DeleteAAIVfModuleRequest request
 
 436     public void prepDeleteAAIVfModule(DelegateExecution execution) {
 
 438         String vnfId = execution.getVariable("DCVFMR_vnfId")
 
 439         String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
 
 440         // formulate the request for UpdateAAIVfModule
 
 441         String request = """<DeleteAAIVfModuleRequest>
 
 442                                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
 
 443                                                                 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
 
 444                                                         </DeleteAAIVfModuleRequest>""" as String
 
 445         logger.debug("DeleteAAIVfModuleRequest :" + request)
 
 446         execution.setVariable("DeleteAAIVfModuleRequest", request)
 
 449     // generates a WorkflowException if
 
 451     public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
 
 453         logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
 
 454                 "AAI error occurred deleting the Generic Vnf" + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"),
 
 455                 "BPMN", ErrorCode.UnknownError.getValue());
 
 456         String processKey = getProcessKey(execution);
 
 457         exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
 
 461     public void sdncValidateResponse(DelegateExecution execution, String response){
 
 463         execution.setVariable("prefix",Prefix)
 
 465         WorkflowException workflowException = execution.getVariable("WorkflowException")
 
 466         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
 
 468         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
 
 469         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
 
 471         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
 
 472             logger.debug("Successfully Validated SDNC Response")
 
 474             throw new BpmnError("MSOWorkflowException")
 
 478     public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
 
 479         def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
 
 480                 'execution=' + execution.getId() +
 
 482         def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
 
 483         logger.trace('Entered ' + method)
 
 484         execution.setVariable("prefix", Prefix)
 
 485         logger.trace("STARTED deleteNetworkPoliciesFromAAI")
 
 489             List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
 
 490             if (fqdnList == null) {
 
 491                 logger.debug("No network policies to delete")
 
 494             int fqdnCount = fqdnList.size()
 
 496             execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
 
 497             logger.debug("networkPolicyFqdnCount - " + fqdnCount)
 
 499             AaiUtil aaiUriUtil = new AaiUtil(this)
 
 502                 // AII loop call over contrail network policy fqdn list
 
 503                 for (i in 0..fqdnCount-1) {
 
 506                     String fqdn = fqdnList[i]
 
 509                         // Query AAI for this network policy FQDN
 
 510                         AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
 
 511                         uri.queryParam("network-policy-fqdn", fqdn)
 
 512                         Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
 
 514                         if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
 
 515                             execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", 200)
 
 516                             NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
 
 519                                 AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicy.getNetworkPolicyId())
 
 520                                 getAAIClient().delete(delUri)
 
 521                                 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 200)
 
 522                                 logger.debug("AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
 
 523                                 logger.debug("The return code from deleting network policy is: " + 200)
 
 524                                 // This network policy was deleted from AAI successfully
 
 525                                 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
 
 526                             }catch(NotFoundException ne){
 
 527                                 // This network policy FQDN is not in AAI. No need to delete.
 
 528                                 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 404)
 
 529                                 logger.debug("The return code is: " + 404)
 
 530                                 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
 
 533                                 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
 
 534                                 logger.debug(delErrorMessage)
 
 535                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
 
 538                             // This network policy FQDN is not in AAI. No need to delete.
 
 539                             logger.debug("This network policy FQDN is not in AAI: " + fqdn)
 
 541                     }catch (BpmnError e){
 
 544                     catch (Exception e) {
 
 546                         String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
 
 547                         logger.debug(dataErrorMessage)
 
 548                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
 
 554                 logger.debug("No contrail network policies to query/create")
 
 558         } catch (BpmnError e) {
 
 561         } catch (Exception ex) {
 
 562             String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
 
 563             logger.debug(exceptionMessage)
 
 564             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
 
 571      * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
 
 573      * @param execution The flow's execution instance.
 
 575     public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
 
 576         def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
 
 577                 'execution=' + execution.getId() +
 
 579         def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
 
 580         logger.trace('Entered ' + method)
 
 583             def vnfId = execution.getVariable('DCVFMR_vnfId')
 
 584             def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
 
 585             def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
 
 586             def ipv4OamAddressElement = ''
 
 587             def managementV6AddressElement = ''
 
 589             if (oamManagementV4Address != null) {
 
 590                 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
 
 593             if (oamManagementV6Address != null) {
 
 594                 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
 
 598             String updateAAIGenericVnfRequest = """
 
 599                                         <UpdateAAIGenericVnfRequest>
 
 600                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
 
 601                                                 ${ipv4OamAddressElement}
 
 602                                                 ${managementV6AddressElement}
 
 603                                         </UpdateAAIGenericVnfRequest>
 
 605             updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
 
 606             execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
 
 607             logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
 
 610             logger.trace('Exited ' + method)
 
 611         } catch (BpmnError e) {
 
 613         } catch (Exception e) {
 
 614             logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
 
 615                     'Caught exception in ' + method, "BPMN",
 
 616                     ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
 
 617             exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
 
 621     public void setSuccessfulRollbackStatus (DelegateExecution execution){
 
 623         execution.setVariable("prefix", Prefix)
 
 624         logger.trace("STARTED setSuccessfulRollbackStatus")
 
 627             // Set rolledBack to true, rollbackError to null
 
 628             execution.setVariable("rolledBack", true)
 
 629             execution.setVariable("rollbackError", null)
 
 632             logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
 
 633                     "Exception Occured Processing setSuccessfulRollbackStatus.", "BPMN",
 
 634                     ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
 
 635             exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
 
 637         logger.trace("COMPLETED setSuccessfulRollbackStatus")
 
 640     public void setFailedRollbackStatus (DelegateExecution execution){
 
 642         execution.setVariable("prefix", Prefix)
 
 643         logger.trace("STARTED setFailedRollbackStatus")
 
 646             // Set rolledBack to false, rollbackError to actual value, rollbackData to null
 
 647             execution.setVariable("rolledBack", false)
 
 648             execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
 
 649             execution.setVariable("rollbackData", null)
 
 652             logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
 
 653                     "Exception Occured Processing setFailedRollbackStatus.", "BPMN",
 
 654                     ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
 
 655             exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
 
 657         logger.trace("COMPLETED setFailedRollbackStatus")