b3c4698ab849377cb5d8fa813b7be0c29dadb872
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.scripts
24
25 import org.onap.so.logger.LoggingAnchor
26 import org.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
46
47 import javax.ws.rs.NotFoundException
48
49
50 public class DoCreateVfModuleRollback extends AbstractServiceTaskProcessor{
51     private static final Logger logger = LoggerFactory.getLogger( DoCreateVfModuleRollback.class);
52
53     def Prefix="DCVFMR_"
54     ExceptionUtil exceptionUtil = new ExceptionUtil()
55
56     public void initProcessVariables(DelegateExecution execution) {
57         execution.setVariable("prefix",Prefix)
58     }
59
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) {
63
64
65         initProcessVariables(execution)
66
67         try {
68
69             execution.setVariable("rolledBack", null)
70             execution.setVariable("rollbackError", null)
71
72             def rollbackData = execution.getVariable("rollbackData")
73             logger.debug("RollbackData:" + rollbackData)
74
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 = []
107                 int i = 0
108                 while (i < 100) {
109                     String fqdn = rollbackData.get("VFMODULE", "contrailNetworkPolicyFqdn" + i)
110                     if (fqdn == null) {
111                         break
112                     }
113                     createdNetworkPolicyFqdnList.add(fqdn)
114                     logger.debug("got fqdn # " + i + ": " + fqdn)
115                     i = i + 1
116
117                 }
118
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"))
134
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)
143             } else {
144                 execution.setVariable("skipRollback", true)
145             }
146
147             if (execution.getVariable("disableRollback").equals("true" )) {
148                 execution.setVariable("skipRollback", true)
149             }
150
151         } catch (BpmnError e) {
152             throw e;
153         } catch (Exception ex){
154             def msg = "Exception in DoCreateVfModuleRollback preProcessRequest " + ex.getMessage()
155             logger.debug(msg)
156             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
157         }
158     }
159
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) {
163
164         String srvInstId = execution.getVariable("DCVFMR_serviceInstanceId")
165
166         String uuid = execution.getVariable('testReqId') // for junits
167         if(uuid==null){
168             uuid = execution.getVariable("DCVFMR_requestId") + "-" +    System.currentTimeMillis()
169         }
170
171         def callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
172
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")
184
185         String serviceInstanceIdToSdnc = ""
186         if (srvInstId != null && !srvInstId.isEmpty()) {
187             serviceInstanceIdToSdnc = srvInstId
188         } else {
189             serviceInstanceIdToSdnc = vfModuleId
190         }
191
192         def doSDNCActivateRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestActivate")
193         def doSDNCAssignRollback = execution.getVariable("DCVFMR_rollbackSDNCRequestAssign")
194
195         def action = ""
196         def requestAction = ""
197
198         if (doSDNCActivateRollback.equals("true")) {
199             action = "delete"
200             requestAction = "DisconnectVNFRequest"
201         }
202         else if (doSDNCAssignRollback.equals("true")) {
203             action = "rollback"
204             requestAction = "VNFActivateRequest"
205         }
206         else
207             return
208
209
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>
225                                                             <notification-url/>
226                                                             <order-number/>
227                                                             <order-version/>
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>"""
247
248         logger.debug("sdncAdapterWorkflowRequest: " + request)
249         execution.setVariable("sdncAdapterWorkflowRequest", request)
250     }
251
252     public void preProcessSDNCDeactivateRequest(DelegateExecution execution){
253
254         execution.setVariable("prefix", Prefix)
255         logger.trace("STARTED preProcessSDNCDeactivateRequest")
256
257         def serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
258
259         try{
260             //Build SDNC Request
261
262             String deactivateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "deactivate")
263
264             deactivateSDNCRequest = utils.formatXml(deactivateSDNCRequest)
265             execution.setVariable("DCVFMR_deactivateSDNCRequest", deactivateSDNCRequest)
266             logger.debug("Outgoing DeactivateSDNCRequest is: \n" + deactivateSDNCRequest)
267
268         }catch(Exception e){
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())
273         }
274         logger.trace("COMPLETED preProcessSDNCDeactivateRequest")
275     }
276
277     public void preProcessSDNCUnassignRequest(DelegateExecution execution) {
278         def method = getClass().getSimpleName() + '.preProcessSDNCUnassignRequest(' +
279                 'execution=' + execution.getId() +
280                 ')'
281         def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
282         logger.trace('Entered ' + method)
283         execution.setVariable("prefix", Prefix)
284         logger.trace("STARTED preProcessSDNCUnassignRequest Process")
285         try{
286             String serviceInstanceId = execution.getVariable("DCVFMR_serviceInstanceId")
287
288             String unassignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "unassign")
289
290             execution.setVariable("DCVFMR_unassignSDNCRequest", unassignSDNCRequest)
291             logger.debug("Outgoing UnassignSDNCRequest is: \n" + unassignSDNCRequest)
292
293         }catch(Exception e){
294             logger.debug("Exception Occured Processing preProcessSDNCUnassignRequest. Exception is:\n" + e)
295             exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during  preProcessSDNCUnassignRequest Method:\n" + e.getMessage())
296         }
297         logger.trace("COMPLETED  preProcessSDNCUnassignRequest Process")
298     }
299
300     public String buildSDNCRequest(DelegateExecution execution, String svcInstId, String action){
301
302         String uuid = execution.getVariable('testReqId') // for junits
303         if(uuid==null){
304             uuid = execution.getVariable("DCVFMR_requestId") + "-" +    System.currentTimeMillis()
305         }
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")
313
314         def sdncVersion = execution.getVariable("sdncVersion")
315
316         String sdncRequest =
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>
333                         <notification-url/>
334                         <order-number/>
335                         <order-version/>
336                 </request-information>
337                 <service-information>
338                         <service-id/>
339                         <subscription-service-type/>
340                         <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
341                         <global-customer-id/>
342                 </service-information>
343                 <vnf-information>
344                         <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
345                         <vnf-type/>
346                 </vnf-information>
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>"""
353
354         logger.debug("sdncRequest:  " + sdncRequest)
355         return sdncRequest
356     }
357
358     // parse the incoming DELETE_VF_MODULE request
359     // and formulate the outgoing VnfAdapterDeleteV1 request
360     public void prepVNFAdapterRequest(DelegateExecution execution) {
361
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)
377         }
378
379         String request = """
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>
388                             <msoRequest>
389                                 <requestId>${MsoUtils.xmlEscape(origRequestId)}</requestId>
390                                 <serviceInstanceId>${MsoUtils.xmlEscape(srvInstId)}</serviceInstanceId>
391                             </msoRequest>
392                             <messageId>${MsoUtils.xmlEscape(messageId)}</messageId>
393                             <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl>
394                         </deleteVfModuleRequest>
395                         """ as String
396
397         execution.setVariable("vnfAdapterTaskRequest", request)
398     }
399
400     // parse the incoming DELETE_VF_MODULE request
401     // and formulate the outgoing UpdateAAIVfModuleRequest request
402     public void prepUpdateAAIVfModule(DelegateExecution execution) {
403
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)
415     }
416
417     // parse the incoming DELETE_VF_MODULE request
418     // and formulate the outgoing UpdateAAIVfModuleRequest request
419     public void prepUpdateAAIVfModuleToAssigned(DelegateExecution execution) {
420
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)
432     }
433
434     // parse the incoming DELETE_VF_MODULE request
435     // and formulate the outgoing DeleteAAIVfModuleRequest request
436     public void prepDeleteAAIVfModule(DelegateExecution execution) {
437
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)
447     }
448
449     // generates a WorkflowException if
450     //          -
451     public void handleDoDeleteVfModuleFailure(DelegateExecution execution) {
452
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")
458
459     }
460
461     public void sdncValidateResponse(DelegateExecution execution, String response){
462
463         execution.setVariable("prefix",Prefix)
464
465         WorkflowException workflowException = execution.getVariable("WorkflowException")
466         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
467
468         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
469         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
470
471         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
472             logger.debug("Successfully Validated SDNC Response")
473         }else{
474             throw new BpmnError("MSOWorkflowException")
475         }
476     }
477
478     public void deleteNetworkPoliciesFromAAI(DelegateExecution execution) {
479         def method = getClass().getSimpleName() + '.deleteNetworkPoliciesFromAAI(' +
480                 'execution=' + execution.getId() +
481                 ')'
482         def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
483         logger.trace('Entered ' + method)
484         execution.setVariable("prefix", Prefix)
485         logger.trace("STARTED deleteNetworkPoliciesFromAAI")
486
487         try {
488             // get variables
489             List fqdnList = execution.getVariable(Prefix + "createdNetworkPolicyFqdnList")
490             if (fqdnList == null) {
491                 logger.debug("No network policies to delete")
492                 return
493             }
494             int fqdnCount = fqdnList.size()
495
496             execution.setVariable(Prefix + "networkPolicyFqdnCount", fqdnCount)
497             logger.debug("networkPolicyFqdnCount - " + fqdnCount)
498
499             AaiUtil aaiUriUtil = new AaiUtil(this)
500
501             if (fqdnCount > 0) {
502                 // AII loop call over contrail network policy fqdn list
503                 for (i in 0..fqdnCount-1) {
504
505                     int counting = i+1
506                     String fqdn = fqdnList[i]
507
508                     try {
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)
513
514                         if (networkPolicies.isPresent() && !networkPolicies.get().getNetworkPolicy().isEmpty()) {
515                             execution.setVariable(Prefix + "aaiQueryNetworkPolicyByFqdnReturnCode", 200)
516                             NetworkPolicy networkPolicy = networkPolicies.get().getNetworkPolicy().get(0)
517
518                             try{
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)
531                             }catch(Exception e){
532                                 // aai all errors
533                                 String delErrorMessage = "Unable to delete network-policy to AAI deleteNetworkPoliciesFromAAI - " + e.getMessage()
534                                 logger.debug(delErrorMessage)
535                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, delErrorMessage)
536                             }
537                         } else {
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)
540                         }
541                     }catch (BpmnError e){
542                         throw e
543                     }
544                     catch (Exception e) {
545                         // aai all errors
546                         String dataErrorMessage = "Unexpected Response from deleteNetworkPoliciesFromAAI - " + e.getMessage()
547                         logger.debug(dataErrorMessage)
548                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
549                     }
550                 } // end loop
551
552
553             } else {
554                 logger.debug("No contrail network policies to query/create")
555
556             }
557
558         } catch (BpmnError e) {
559             throw e;
560
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)
565         }
566
567     }
568
569
570     /**
571      * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
572      *
573      * @param execution The flow's execution instance.
574      */
575     public void preProcessUpdateAAIGenericVnf(DelegateExecution execution) {
576         def method = getClass().getSimpleName() + '.preProcessUpdateAAIGenericVnf((' +
577                 'execution=' + execution.getId() +
578                 ')'
579         def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
580         logger.trace('Entered ' + method)
581
582         try {
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 = ''
588
589             if (oamManagementV4Address != null) {
590                 ipv4OamAddressElement = '<ipv4-oam-address>' + 'DELETE' + '</ipv4-oam-address>'
591             }
592
593             if (oamManagementV6Address != null) {
594                 managementV6AddressElement = '<management-v6-address>' + 'DELETE' + '</management-v6-address>'
595             }
596
597
598             String updateAAIGenericVnfRequest = """
599                                         <UpdateAAIGenericVnfRequest>
600                                                 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
601                                                 ${ipv4OamAddressElement}
602                                                 ${managementV6AddressElement}
603                                         </UpdateAAIGenericVnfRequest>
604                                 """
605             updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
606             execution.setVariable(Prefix + 'updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
607             logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
608
609
610             logger.trace('Exited ' + method)
611         } catch (BpmnError e) {
612             throw 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())
618         }
619     }
620
621     public void setSuccessfulRollbackStatus (DelegateExecution execution){
622
623         execution.setVariable("prefix", Prefix)
624         logger.trace("STARTED setSuccessfulRollbackStatus")
625
626         try{
627             // Set rolledBack to true, rollbackError to null
628             execution.setVariable("rolledBack", true)
629             execution.setVariable("rollbackError", null)
630
631         }catch(Exception e){
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())
636         }
637         logger.trace("COMPLETED setSuccessfulRollbackStatus")
638     }
639
640     public void setFailedRollbackStatus (DelegateExecution execution){
641
642         execution.setVariable("prefix", Prefix)
643         logger.trace("STARTED setFailedRollbackStatus")
644
645         try{
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)
650
651         }catch(Exception e){
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())
656         }
657         logger.trace("COMPLETED setFailedRollbackStatus")
658     }
659 }