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