Removed MsoLogger class
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateVfModuleRollback.groovy
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 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.aai.domain.yang.NetworkPolicies
27 import org.onap.aai.domain.yang.NetworkPolicy
28 import org.onap.so.bpmn.common.scripts.AaiUtil
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.MsoUtils
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
33 import org.onap.so.bpmn.core.UrnPropertiesReader
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.client.aai.AAIObjectPlurals
36 import org.onap.so.client.aai.AAIObjectType
37 import org.onap.so.client.aai.entities.uri.AAIResourceUri
38 import org.onap.so.client.aai.entities.uri.AAIUriFactory
39 import org.onap.so.logger.ErrorCode
40 import org.onap.so.logger.MessageEnum
41 import org.slf4j.Logger
42 import org.slf4j.LoggerFactory
43
44 import javax.ws.rs.NotFoundException
45
46
47 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
48     private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleRollback.class);
49
50         def Prefix="DCVFMR_"
51         ExceptionUtil exceptionUtil = new ExceptionUtil()
52
53         public void initProcessVariables(DelegateExecution execution) {
54                 execution.setVariable("prefix",Prefix)
55         }
56
57         // parse the incoming DELETE_VF_MODULE request for the Generic Vnf and Vf Module Ids
58         // and formulate the outgoing request for PrepareUpdateAAIVfModuleRequest
59         public void preProcessRequest(DelegateExecution execution) {
60
61
62                 initProcessVariables(execution)
63
64                 try {
65
66                         execution.setVariable("rolledBack", null)
67                         execution.setVariable("rollbackError", null)
68
69                         def rollbackData = execution.getVariable("rollbackData")
70                         logger.debug("RollbackData:" + rollbackData)
71
72                         if (rollbackData != null) {
73                         String vnfId = rollbackData.get("VFMODULE", "vnfid")
74                         execution.setVariable("DCVFMR_vnfId", vnfId)
75                         String vfModuleId = rollbackData.get("VFMODULE", "vfmoduleid")
76                         execution.setVariable("DCVFMR_vfModuleId", vfModuleId)
77                         String source = rollbackData.get("VFMODULE", "source")
78                         execution.setVariable("DCVFMR_source", source)
79                         String serviceInstanceId = rollbackData.get("VFMODULE", "serviceInstanceId")
80                         execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
81                         String serviceId = rollbackData.get("VFMODULE", "service-id")
82                         execution.setVariable("DCVFMR_serviceId", serviceId)
83                         String vnfType = rollbackData.get("VFMODULE", "vnftype")
84                         execution.setVariable("DCVFMR_vnfType", vnfType)
85                         String vnfName = rollbackData.get("VFMODULE", "vnfname")
86                         execution.setVariable("DCVFMR_vnfName", vnfName)
87                         String tenantId = rollbackData.get("VFMODULE", "tenantid")
88                         execution.setVariable("DCVFMR_tenantId", tenantId)
89                         String vfModuleName = rollbackData.get("VFMODULE", "vfmodulename")
90                         execution.setVariable("DCVFMR_vfModuleName", vfModuleName)
91                         String vfModuleModelName = rollbackData.get("VFMODULE", "vfmodulemodelname")
92                         execution.setVariable("DCVFMR_vfModuleModelName", vfModuleModelName)
93                         String cloudSiteId = rollbackData.get("VFMODULE", "aiccloudregion")
94                         execution.setVariable("DCVFMR_cloudSiteId", cloudSiteId)
95                         String heatStackId = rollbackData.get("VFMODULE", "heatstackid")
96                         execution.setVariable("DCVFMR_heatStackId", heatStackId)
97                         String requestId = rollbackData.get("VFMODULE", "msorequestid")
98                         execution.setVariable("DCVFMR_requestId", requestId)
99                         // Set mso-request-id to request-id for VNF Adapter interface
100                         execution.setVariable("mso-request-id", requestId)
101                         List createdNetworkPolicyFqdnList = []
102                         int i = 0
103                         while (i < 100) {
104                                 String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
105                                 if (fqdn == null) {
106                                         break
107                                 }
108                                 createdNetworkPolicyFqdnList.add(fqdn)
109                                 logger.debug("got fqdn # " + i + ": " + fqdn)
110                                 i = i + 1
111
112                         }
113
114                         execution.setVariable("DCVFMR_createdNetworkPolicyFqdnList", createdNetworkPolicyFqdnList)
115                         String oamManagementV4Address = rollbackData.get("VFMODULE", "oamManagementV4Address")
116                         execution.setVariable("DCVFMR_oamManagementV4Address", oamManagementV4Address)
117                         String oamManagementV6Address = rollbackData.get("VFMODULE", "oamManagementV6Address")
118                         execution.setVariable("DCVFMR_oamManagementV6Address", oamManagementV6Address)
119                         //String serviceInstanceId = rollbackData.get("VFMODULE", "msoserviceinstanceid")
120                         //execution.setVariable("DCVFMR_serviceInstanceId", serviceInstanceId)
121                         execution.setVariable("DCVFMR_rollbackPrepareUpdateVfModule", rollbackData.get("VFMODULE", "rollbackPrepareUpdateVfModule"))
122                         execution.setVariable("DCVFMR_rollbackUpdateAAIVfModule", rollbackData.get("VFMODULE", "rollbackUpdateAAIVfModule"))
123                         execution.setVariable("DCVFMR_rollbackVnfAdapterCreate", rollbackData.get("VFMODULE", "rollbackVnfAdapterCreate"))
124                         execution.setVariable("DCVFMR_rollbackSDNCRequestAssign", rollbackData.get("VFMODULE", "rollbackSDNCRequestAssign"))
125                         execution.setVariable("DCVFMR_rollbackSDNCRequestActivate", rollbackData.get("VFMODULE", "rollbackSDNCRequestActivate"))
126                         execution.setVariable("DCVFMR_rollbackCreateAAIVfModule", rollbackData.get("VFMODULE", "rollbackCreateAAIVfModule"))
127                         execution.setVariable("DCVFMR_rollbackCreateNetworkPoliciesAAI", rollbackData.get("VFMODULE", "rollbackCreateNetworkPoliciesAAI"))
128                         execution.setVariable("DCVFMR_rollbackUpdateVnfAAI", rollbackData.get("VFMODULE", "rollbackUpdateVnfAAI"))
129
130                         // formulate the request for PrepareUpdateAAIVfModule
131                         String request = """<PrepareUpdateAAIVfModuleRequest>
132                                                                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
133                                                                         <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
134                                                                         <orchestration-status>pending-delete</orchestration-status>
135                                                                 </PrepareUpdateAAIVfModuleRequest>""" as String
136                         logger.debug("PrepareUpdateAAIVfModuleRequest :" + request)
137                         execution.setVariable("PrepareUpdateAAIVfModuleRequest", request)
138                 } else {
139                         execution.setVariable("skipRollback", true)
140                 }
141
142                 if (execution.getVariable("disableRollback").equals("true" )) {
143                         execution.setVariable("skipRollback", true)
144                 }
145
146                 } catch (BpmnError e) {
147                         throw e;
148                 } catch (Exception ex){
149                         def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
150                         logger.debug(msg)
151                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
152                 }
153         }
154
155         // build a SDNC vnf-topology-operation request for the specified action
156         // (note: the action passed is expected to be 'changedelete' or 'delete')
157         public void prepSDNCAdapterRequest(DelegateExecution execution) {
158
159                 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
160
161                 String uuid = execution.getVariable('testReqId') // for junits
162                 if(uuid==null){
163                         uuid = execution.getVariable("DCVFMR_requestId") + "-" +        System.currentTimeMillis()
164                 }
165
166                 def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
167
168                 String source = execution.getVariable("DCVFMR_source")
169                 String serviceId = execution.getVariable("DCVFMR_serviceId")
170                 String vnfId = execution.getVariable("DCVFMR_vnfId")
171                 String vnfType = execution.getVariable("DCVFMR_vnfType")
172                 String vnfName = execution.getVariable("DCVFMR_vnfName")
173                 String tenantId = execution.getVariable("DCVFMR_tenantId")
174                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
175                 String vfModuleName = execution.getVariable("DCVFMR_vfModuleName")
176                 String vfModuleModelName = execution.getVariable("DCVFMR_vfModuleModelName")
177                 String cloudSiteId = execution.getVariable("DCVFMR_cloudSiteId")
178                 String requestId = execution.getVariable("DCVFMR_requestId")
179
180                 String serviceInstanceIdToSdnc = ""
181                 if (srvInstId != null && !srvInstId.isEmpty()) {
182                         serviceInstanceIdToSdnc = srvInstId
183                 } else {
184                     serviceInstanceIdToSdnc = vfModuleId
185                 }
186
187                 def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
188                 def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
189
190                 def action = ""
191                 def requestAction = ""
192
193                 if (doSDNCActivateRollback.equals("true")) {
194                         action = "delete"
195                         requestAction = "DisconnectVNFRequest"
196                 }
197                 else if (doSDNCAssignRollback.equals("true")) {
198                         action = "rollback"
199                         requestAction = "VNFActivateRequest"
200                 }
201                 else
202                         return
203
204
205                 String request = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
206                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
207                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
208                                                       <sdncadapter:RequestHeader>
209                                                          <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
210                                                          <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(vfModuleId)}</sdncadapter:SvcInstanceId>
211                                                          <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
212                                                          <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
213                                                          <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
214                                                       </sdncadapter:RequestHeader>
215                                                       <sdncadapterworkflow:SDNCRequestData>
216                                                          <request-information>
217                                                             <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
218                                                             <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
219                                                             <source>${MsoUtils.xmlEscape(source)}</source>
220                                                             <notification-url/>
221                                                             <order-number/>
222                                                             <order-version/>
223                                                          </request-information>
224                                                          <service-information>
225                                                             <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
226                                                                         <service-type>${MsoUtils.xmlEscape(serviceId)}</service-type>
227                                                             <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceIdToSdnc)}</service-instance-id>
228                                                             <subscriber-name>notsurewecare</subscriber-name>
229                                                          </service-information>
230                                                          <vnf-request-information>
231                                                                 <vnf-id>${MsoUtils.xmlEscape(vfModuleId)}</vnf-id>
232                                                                         <vnf-type>${MsoUtils.xmlEscape(vfModuleModelName)}</vnf-type>
233                                     <vnf-name>${MsoUtils.xmlEscape(vfModuleName)}</vnf-name>
234                                                                         <generic-vnf-id>${MsoUtils.xmlEscape(vnfId)}</generic-vnf-id>
235                                     <generic-vnf-name>${MsoUtils.xmlEscape(vnfName)}</generic-vnf-name>
236                                                                         <generic-vnf-type>${MsoUtils.xmlEscape(vnfType)}</generic-vnf-type>
237                                                                         <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
238                                                                         <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
239                                                          </vnf-request-information>
240                                                       </sdncadapterworkflow:SDNCRequestData>
241                                                    </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
242
243                 logger.debug("sdncAdapterWorkflowRequest: " + request)
244                 execution.setVariable("sdncAdapterWorkflowRequest", request)
245         }
246
247         public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
248
249                 execution.setVariable("prefix", Prefix)
250                 logger.trace("STARTED preProcessSDNCDeactivateRequest")
251
252                 def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
253
254                 try{
255                         //Build SDNC Request
256
257                         String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
258
259                         deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
260                         execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
261                         logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
262
263                 }catch(Exception e){
264                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
265                                         "Exception Occured Processing preProcessSDNCDeactivateRequest.", "BPMN",
266                                         ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
267                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCDeactivateRequest Method:\n" + e.getMessage())
268                 }
269                 logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
270         }
271
272         public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
273                 def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
274                         'execution=' + execution.getId() +
275                         ')'
276                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
277                 logger.trace('Entered ' + method)
278                 execution.setVariable("prefix", Prefix)
279                 logger.trace("STARTED preProcessSDNCUnassignRequest Process")
280                 try{
281                         String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
282
283                         String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
284
285                         execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
286                         logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
287
288                 }catch(Exception e){
289                         logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
290                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
291                 }
292                 logger.trace("COMPLETED  preProcessSDNCUnassignRequest Process")
293         }
294
295         public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
296
297                         String uuid = execution.getVariable('testReqId') // for junits
298                         if(uuid==null){
299                                 uuid = execution.getVariable("DCVFMR_requestId") + "-" +        System.currentTimeMillis()
300                         }
301                         def callbackURL = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
302                         def requestId = execution.getVariable("DCVFMR_requestId")
303                         def serviceId = execution.getVariable("DCVFMR_serviceId")
304                         def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
305                         def vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
306                         def source = execution.getVariable("DCVFMR_source")
307                         def vnfId = execution.getVariable("DCVFMR_vnfId")
308
309                         def sdncVersion = execution.getVariable("sdncVersion")
310
311                         String sdncRequest =
312                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
313                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
314                                                                                                         xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1">
315            <sdncadapter:RequestHeader>
316                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
317                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
318                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
319                                 <sdncadapter:SvcOperation>vf-module-topology-operation</sdncadapter:SvcOperation>
320                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
321                                 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
322                 </sdncadapter:RequestHeader>
323         <sdncadapterworkflow:SDNCRequestData>
324                 <request-information>
325                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
326                         <request-action>DeleteVfModuleInstance</request-action>
327                         <source>${MsoUtils.xmlEscape(source)}</source>
328                         <notification-url/>
329                         <order-number/>
330                         <order-version/>
331                 </request-information>
332                 <service-information>
333                         <service-id/>
334                         <subscription-service-type/>
335                         <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
336                         <global-customer-id/>
337                 </service-information>
338                 <vnf-information>
339                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
340                         <vnf-type/>
341                 </vnf-information>
342                 <vf-module-information>
343                         <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
344                 </vf-module-information>
345                 <vf-module-request-input/>
346         </sdncadapterworkflow:SDNCRequestData>
347         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
348
349                 logger.debug("sdncRequest:  " + sdncRequest)
350                 return sdncRequest
351         }
352
353         // parse the incoming DELETE_VF_MODULE request
354         // and formulate the outgoing VnfAdapterDeleteV1 request
355         public void prepVNFAdapterRequest(DelegateExecution execution) {
356
357                 String requestId = UUID.randomUUID().toString()
358                 String origRequestId = execution.getVariable("DCVFMR_requestId")
359                 String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
360                 String aicCloudRegion = execution.getVariable("DCVFMR_cloudSiteId")
361                 String vnfId = execution.getVariable("DCVFMR_vnfId")
362                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
363                 String vfModuleStackId = execution.getVariable("DCVFMR_heatStackId")
364                 String tenantId = execution.getVariable("DCVFMR_tenantId")
365                 def messageId = execution.getVariable('mso-request-id') + '-' +
366                         System.currentTimeMillis()
367                 def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId)
368                 def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution)
369                 if ('true'.equals(useQualifiedHostName)) {
370                         notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl)
371                 }
372
373                 String request = """
374                         <deleteVfModuleRequest>
375                             <cloudSiteId>${MsoUtils.xmlEscape(aicCloudRegion)}</cloudSiteId>
376                             <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
377                             <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
378                             <vfModuleId>${MsoUtils.xmlEscape(vfModuleId)}</vfModuleId>
379                             <vfModuleStackId>${MsoUtils.xmlEscape(vfModuleStackId)}</vfModuleStackId>
380                             <skipAAI>true</skipAAI>
381                             <msoRequest>
382                                 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
383                                 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
384                             </msoRequest>
385                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
386                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
387                         </deleteVfModuleRequest>
388                         """ as String
389
390                 logger.debug("vnfAdapterRestV1Request: " + request)
391                 execution.setVariable("vnfAdapterRestV1Request", request)
392         }
393
394         // parse the incoming DELETE_VF_MODULE request
395         // and formulate the outgoing UpdateAAIVfModuleRequest request
396         public void prepUpdateAAIVfModule(DelegateExecution execution) {
397
398                 String vnfId = execution.getVariable("DCVFMR_vnfId")
399                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
400                 // formulate the request for UpdateAAIVfModule
401                 String request = """<UpdateAAIVfModuleRequest>
402                                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
403                                                                 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
404                                                                 <heat-stack-id>DELETE</heat-stack-id>
405                                                                 <orchestration-status>deleted</orchestration-status>
406                                                         </UpdateAAIVfModuleRequest>""" as String
407                 logger.debug("UpdateAAIVfModuleRequest :" + request)
408                 execution.setVariable("UpdateAAIVfModuleRequest", request)
409         }
410
411         // parse the incoming DELETE_VF_MODULE request
412         // and formulate the outgoing UpdateAAIVfModuleRequest request
413         public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
414
415                 String vnfId = execution.getVariable("DCVFMR_vnfId")
416                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
417                 // formulate the request for UpdateAAIVfModule
418                 String request = """<UpdateAAIVfModuleRequest>
419                                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
420                                                                 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
421                                                                 <heat-stack-id></heat-stack-id>
422                                                                 <orchestration-status>Assigned</orchestration-status>
423                                                         </UpdateAAIVfModuleRequest>""" as String
424                 logger.debug("UpdateAAIVfModuleRequest :" + request)
425                 execution.setVariable("UpdateAAIVfModuleRequest", request)
426         }
427
428         // parse the incoming DELETE_VF_MODULE request
429         // and formulate the outgoing DeleteAAIVfModuleRequest request
430         public void prepDeleteAAIVfModule(DelegateExecution execution) {
431
432                 String vnfId = execution.getVariable("DCVFMR_vnfId")
433                 String vfModuleId = execution.getVariable("DCVFMR_vfModuleId")
434                 // formulate the request for UpdateAAIVfModule
435                 String request = """<DeleteAAIVfModuleRequest>
436                                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
437                                                                 <vf-module-id>${MsoUtils.xmlEscape(vfModuleId)}</vf-module-id>
438                                                         </DeleteAAIVfModuleRequest>""" as String
439                 logger.debug("DeleteAAIVfModuleRequest :" + request)
440                 execution.setVariable("DeleteAAIVfModuleRequest", request)
441         }
442
443         // generates a WorkflowException if
444         //              -
445         public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
446
447                 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
448                                 "AAI error occurred deleting the Generic Vnf" + execution.getVariable("DoDVfMod_deleteGenericVnfResponse"),
449                                 "BPMN", ErrorCode.UnknownError.getValue());
450                 String processKey = getProcessKey(execution);
451                 exceptionUtil.buildWorkflowException(execution, 5000, "Failure in DoDeleteVfModule")
452
453         }
454
455         public void sdncValidateResponse(DelegateExecution execution, String response){
456
457                 execution.setVariable("prefix",Prefix)
458
459                 WorkflowException workflowException = execution.getVariable("WorkflowException")
460                 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
461
462                 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
463                 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
464
465                 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
466                         logger.debug("Successfully Validated SDNC Response")
467                 }else{
468                         throw new BpmnError("MSOWorkflowException")
469                 }
470         }
471
472         public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
473                 def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
474                 'execution=' + execution.getId() +
475                 ')'
476                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
477                 logger.trace('Entered ' + method)
478                 execution.setVariable("prefix", Prefix)
479                 logger.trace("STARTED deleteNetworkPoliciesFromAAI")
480
481                 try {
482                         // get variables
483                         List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
484                         if (fqdnList == null) {
485                                 logger.debug("No network policies to delete")
486                                 return
487                         }
488                         int fqdnCount = fqdnList.size()
489
490                         execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
491                         logger.debug("networkPolicyFqdnCount - " + fqdnCount)
492
493                         AaiUtil aaiUriUtil = new AaiUtil(this)
494
495                         if (fqdnCount > 0) {
496                                 // AII loop call over contrail network policy fqdn list
497                                 for (i in 0..fqdnCount-1) {
498
499                                         int counting = i+1
500                                         String fqdn = fqdnList[i]
501
502                     try {
503                         // Query AAI for this network policy FQDN
504                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_POLICY)
505                         uri.queryParam("network-policy-fqdn", fqdn)
506                         Optional<NetworkPolicies> networkPolicies = getAAIClient().get(NetworkPolicies.class, uri)
507
508                         if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
509                             execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", 200)
510                             NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
511
512                             try{
513                             AAIResourceUri delUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, networkPolicy.getNetworkPolicyId())
514                             getAAIClient().delete(delUri)
515                             execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 200)
516                             logger.debug("AAI delete network policy Response Code, NetworkPolicy #" + counting + " : " + 200)
517                                 logger.debug("The return code from deleting network policy is: " + 200)
518                                 // This network policy was deleted from AAI successfully
519                                 logger.debug(" DelAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : ")
520                             }catch(NotFoundException ne){
521                                 // This network policy FQDN is not in AAI. No need to delete.
522                                 execution.setVariable(Prefix + "aaiDeleteNetworkPolicyReturnCode", 404)
523                                 logger.debug("The return code is: " + 404)
524                                 logger.debug("This network policy FQDN is not in AAI: " + fqdn)
525                             }catch(Exception e){
526                                 // aai all errors
527                                 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
528                                 logger.debug(delErrorMessage)
529                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
530                             }
531                         } else {
532                             // This network policy FQDN is not in AAI. No need to delete.
533                             logger.debug("This network policy FQDN is not in AAI: " + fqdn)
534                         }
535                     }catch (BpmnError e){
536                         throw e
537                     }
538                     catch (Exception e) {
539                         // aai all errors
540                         String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
541                         logger.debug(dataErrorMessage)
542                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
543                     }
544                                 } // end loop
545
546
547                         } else {
548                                    logger.debug("No contrail network policies to query/create")
549
550                         }
551
552                 } catch (BpmnError e) {
553                         throw e;
554
555                 } catch (Exception ex) {
556                         String exceptionMessage = "Bpmn error encountered in DoCreateVfModuleRollback flow. deleteNetworkPoliciesFromAAI() - " + ex.getMessage()
557                         logger.debug(exceptionMessage)
558                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
559                 }
560
561         }
562
563
564         /**
565          * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
566          *
567          * @param execution The flow's execution instance.
568          */
569         public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
570                 def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
571                         'execution=' + execution.getId() +
572                         ')'
573                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
574                 logger.trace('Entered ' + method)
575
576                 try {
577                         def vnfId = execution.getVariable('DCVFMR_vnfId')
578                         def oamManagementV4Address = execution.getVariable(Prefix + 'oamManagementV4Address')
579                         def oamManagementV6Address = execution.getVariable(Prefix + 'oamManagementV6Address')
580                         def ipv4OamAddressElement = ''
581                         def managementV6AddressElement = ''
582
583                         if (oamManagementV4Address != null) {
584                                 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
585                         }
586
587                         if (oamManagementV6Address != null) {
588                                 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
589                         }
590
591
592                         String updateAAIGenericVnfRequest = """
593                                         <UpdateAAIGenericVnfRequest>
594                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
595                                                 ${ipv4OamAddressElement}
596                                                 ${managementV6AddressElement}
597                                         </UpdateAAIGenericVnfRequest>
598                                 """
599                                 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
600                                 execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
601                                 logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
602
603
604                         logger.trace('Exited ' + method)
605                 } catch (BpmnError e) {
606                         throw e;
607                 } catch (Exception e) {
608                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
609                                         'Caught exception in ' + method, "BPMN",
610                                         ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
611                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in preProcessUpdateAAIGenericVnf((): ' + e.getMessage())
612                 }
613         }
614
615         public void setSuccessfulRollbackStatus (DelegateExecution execution){
616
617                 execution.setVariable("prefix", Prefix)
618                 logger.trace("STARTED setSuccessfulRollbackStatus")
619
620                 try{
621                         // Set rolledBack to true, rollbackError to null
622                         execution.setVariable("rolledBack", true)
623                         execution.setVariable("rollbackError", null)
624
625                 }catch(Exception e){
626                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
627                                         "Exception Occured Processing setSuccessfulRollbackStatus.", "BPMN",
628                                         ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
629                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setSuccessfulRollbackStatus Method:\n" + e.getMessage())
630                 }
631                 logger.trace("COMPLETED setSuccessfulRollbackStatus")
632         }
633
634         public void setFailedRollbackStatus (DelegateExecution execution){
635
636                 execution.setVariable("prefix", Prefix)
637                 logger.trace("STARTED setFailedRollbackStatus")
638
639                 try{
640                         // Set rolledBack to false, rollbackError to actual value, rollbackData to null
641                         execution.setVariable("rolledBack", false)
642                         execution.setVariable("rollbackError", 'Caught exception in DoCreateVfModuleRollback')
643                         execution.setVariable("rollbackData", null)
644
645                 }catch(Exception e){
646                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
647                                         "Exception Occured Processing setFailedRollbackStatus.", "BPMN",
648                                         ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
649                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during setFailedRollbackStatus Method:\n" + e.getMessage())
650                 }
651                 logger.trace("COMPLETED setFailedRollbackStatus")
652         }
653 }