arUrl variable is null on vCPE PUT to AAI
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / vcpe / scripts / DoCreateAllottedResourceTXC.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.vcpe.scripts;
22
23 import static org.apache.commons.lang3.StringUtils.*
24
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.*;
29 import org.onap.so.bpmn.core.RollbackData
30 import org.onap.so.bpmn.core.UrnPropertiesReader
31 import org.onap.so.bpmn.core.WorkflowException
32 import org.onap.so.bpmn.core.json.JsonUtils
33 import org.onap.so.client.aai.AAIObjectType
34 import org.onap.so.client.aai.entities.uri.AAIResourceUri
35 import org.onap.so.client.aai.entities.uri.AAIUriFactory
36 import org.onap.so.logger.MessageEnum
37 import org.onap.so.logger.MsoLogger
38 import org.onap.so.rest.APIResponse
39
40 /**
41  * This groovy class supports the <class>DoCreateAllottedResourceTXC.bpmn</class> process.
42  *
43  * @author
44  * 
45  * Inputs:
46  * @param - msoRequestId
47  * @param - isDEbugLogEnabled
48  * @param - disableRollback
49  * @param - failExists  - O
50  * @param - serviceInstanceId
51  * @param - globalCustomerId - O
52  * @param - subscriptionServiceType - O
53  * @param - parentServiceInstanceId
54  * @param - allottedReourceId - O
55  * @param - allottedResourceModelInfo
56  * @param - allottedResourceRole
57  * @param - allottedResourceType
58  * @param - brgWanMacAddress
59  *
60  * Outputs:
61  * @param - rollbackData (localRB->null)
62  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
63  * @param - WorkflowException - O
64  * @param - allottedResourceId
65  * @param - allottedResourceName 
66  * @param - vni 
67  * @param - vgmuxBearerIP 
68  * @param - vgmuxLanIP 
69  *
70  */
71 public class DoCreateAllottedResourceTXC extends AbstractServiceTaskProcessor{
72         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateAllottedResourceTXC.class);
73
74         String Prefix="DCARTXC_"
75         ExceptionUtil exceptionUtil = new ExceptionUtil()
76         JsonUtils jsonUtil = new JsonUtils()
77
78         public void preProcessRequest (DelegateExecution execution) {
79
80
81                 String msg = ""
82                 msoLogger.trace("start preProcessRequest")
83
84                 try {
85                         String msoRequestId      = execution.getVariable("msoRequestId")
86                         msoLogger.debug(" msoRequestId  = " + msoRequestId)
87                         
88                         execution.setVariable("prefix", Prefix)
89
90                         //Config Inputs
91                         String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
92                         if (isBlank(sdncCallbackUrl)) {
93                                 msg = "mso.workflow.sdncadapter.callback is null"
94                                 msoLogger.debug(msg)
95                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
96                         }
97                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
98                         msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
99
100                         String sdncReplDelay = UrnPropertiesReader.getVariable("mso.workflow.sdnc.replication.delay",execution)
101                         if (isBlank(sdncReplDelay)) {
102                                 msg = "mso.workflow.sdnc.replication.delay is null"
103                                 msoLogger.debug(msg)
104                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
105                         }
106                         execution.setVariable("sdncReplDelay", sdncReplDelay)
107                         msoLogger.debug("SDNC replication delay: " + sdncReplDelay)
108
109                         //Request Inputs
110                         if (isBlank(execution.getVariable("serviceInstanceId"))){
111                                 msg = "Input serviceInstanceId is null"
112                                 msoLogger.debug(msg)
113                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
114                         }
115                         if (isBlank(execution.getVariable("parentServiceInstanceId"))) {
116                                 msg = "Input parentServiceInstanceId is null"
117                                 msoLogger.debug(msg)
118                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
119                         }
120                         if (isBlank(execution.getVariable("allottedResourceModelInfo"))) {
121                                 msg = "Input allottedResourceModelInfo is null"
122                                 msoLogger.debug(msg)
123                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
124                         }
125                         if (isBlank(execution.getVariable("brgWanMacAddress"))) {
126                                 msg = "Input brgWanMacAddress is null"
127                                 msoLogger.debug(msg)
128                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
129                         }
130                         if (isBlank(execution.getVariable("allottedResourceRole"))) {
131                                 msg = "Input allottedResourceRole is null"
132                                 msoLogger.debug(msg)
133                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
134                         }
135                         if (isBlank(execution.getVariable("allottedResourceType"))) {
136                                 msg = "Input allottedResourceType is null"
137                                 msoLogger.debug(msg)
138                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
139                         }
140                 }catch(BpmnError b){
141                         msoLogger.debug("Rethrowing MSOWorkflowException")
142                         throw b
143                 } catch (Exception ex){
144                         msg = "Exception in preProcessRequest " + ex.getMessage()
145                         msoLogger.debug(msg)
146                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
147                 }
148                 msoLogger.trace("end preProcessRequest")
149         }
150
151         public void getAaiAR (DelegateExecution execution) {
152
153
154                 msoLogger.trace("start getAaiAR")
155
156                 String arType = execution.getVariable("allottedResourceType")
157                 String arRole = execution.getVariable("allottedResourceRole")
158
159                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
160                 String orchStatus = arUtils.getAROrchStatus(execution)
161
162                 String errorMsg = ""
163
164                 if (orchStatus != null) // AR was found
165                 {
166                         if ("true".equals(execution.getVariable("failExists")))
167                         {
168                                 errorMsg = "Allotted resource " + arType + " with Role " + arRole + " already exists"
169                         }
170                         else
171                         {
172                                 if ("Active".equals(orchStatus))
173                                 {
174                                         execution.setVariable("foundActiveAR", true)
175                                 }
176                                 else // blanks included
177                                 {
178                                         errorMsg = "Allotted Resource " + arType + " with Role " + arRole + " already exists in an incomplete state -"  +  orchStatus
179                                 }
180                         }
181                 }
182                 if (!isBlank(errorMsg)) {
183                         msoLogger.debug(errorMsg)
184                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
185                 }
186                 msoLogger.trace("end getAaiAR")
187         }
188
189         public void createAaiAR(DelegateExecution execution) {
190
191
192                 msoLogger.trace("start createAaiAR")
193                 String msg = ""
194
195                 String allottedResourceId = execution.getVariable("allottedResourceId")
196                 if (isBlank(allottedResourceId))
197                 {
198                         allottedResourceId = UUID.randomUUID().toString()
199                         execution.setVariable("allottedResourceId", allottedResourceId)
200                 }
201                 String arUrl = ""
202                 try {
203
204                         //AAI PUT
205                         AaiUtil aaiUriUtil = new AaiUtil(this)
206                         AAIResourceUri siResourceLink= execution.getVariable("PSI_resourceLink")
207                         AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
208                         arUrl = arUtils.createARUrl(execution, siResourceLink, allottedResourceId)
209                         execution.setVariable("aaiARPath", arUrl)
210                         msoLogger.debug("PUT AllottedResource AAI URL is:\n" + arUrl)
211
212                         String namespace = aaiUriUtil.getNamespaceFromUri(execution, arUrl)
213
214                         String arType = execution.getVariable("allottedResourceType")
215                         String arRole = execution.getVariable("allottedResourceRole")
216                         String CSI_resourceLink = execution.getVariable("CSI_resourceLink")
217                         String arModelInfo = execution.getVariable("allottedResourceModelInfo")
218                         msoLogger.debug("arModelInfo is:\n" + arModelInfo)
219                         String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid")
220                         String modelVersionId = jsonUtil.getJsonValue(arModelInfo, "modelUuid")
221                         String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid")
222
223                         if (modelInvariantId == null) {
224                                 modelInvariantId = ""
225                         }
226                         if (modelVersionId == null) {
227                                 modelVersionId = ""
228                         }
229                         if (modelCustomizationId == null) {
230                                 modelCustomizationId = ""
231                         }
232
233                         String payload =
234                         """<allotted-resource xmlns="${namespace}">
235                                 <id>${MsoUtils.xmlEscape(allottedResourceId)}</id>
236                                 <description></description>
237                                 <type>${MsoUtils.xmlEscape(arType)}</type>
238                                 <role>${MsoUtils.xmlEscape(arRole)}</role>
239                                 <selflink></selflink>
240                                 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-id>
241                                 <model-version-id>${MsoUtils.xmlEscape(modelVersionId)}</model-version-id>
242                                 <model-customization-id>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-id>
243                                 <orchestration-status>PendingCreate</orchestration-status>
244                                 <operation-status></operation-status>
245                                 <relationship-list>
246                                         <relationship>
247                                 <related-to>service-instance</related-to>
248                                 <related-link>${MsoUtils.xmlEscape(CSI_resourceLink)}</related-link>
249                                         </relationship>
250                                 </relationship-list>
251                         </allotted-resource>""".trim()
252
253                         execution.setVariable("AaiARPayload", payload)
254                         msoLogger.debug(" payload to create AllottedResource in AAI:" + "\n" + payload)
255
256                         APIResponse response = aaiUriUtil.executeAAIPutCall(execution, arUrl, payload)
257                         int responseCode = response.getStatusCode()
258                         msoLogger.debug("AllottedResource AAI PUT responseCode:" + responseCode)
259
260                         String aaiResponse = response.getResponseBodyAsString()
261                         msoLogger.debug("AllottedResource AAI PUT responseStr:" + aaiResponse)
262
263                         //200 OK 201 CREATED 202 ACCEPTED
264                         if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
265                         {
266                                 msoLogger.debug("AAI PUT AllottedResource received a Good Response")
267                         }
268                         else{
269                                 msoLogger.debug("AAI Put AllottedResouce received a Bad Response Code: " + responseCode)
270                                 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
271                                 throw new BpmnError("MSOWorkflowException")
272                         }
273                 }catch(BpmnError b){
274                         msoLogger.debug("Rethrowing MSOWorkflowException")
275                         throw b
276                 } catch (Exception ex) {
277                         msg = "Exception in createAaiAR " + ex.getMessage()
278                         msoLogger.debug(msg)
279                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
280                 }
281
282                 //start rollback set up
283                 RollbackData rollbackData = new RollbackData()
284                 def disableRollback = execution.getVariable("disableRollback")
285                 rollbackData.put(Prefix, "disableRollback", disableRollback.toString())
286                 rollbackData.put(Prefix, "rollbackAAI", "true")
287                 rollbackData.put(Prefix, "allottedResourceId", allottedResourceId)
288                 rollbackData.put(Prefix, "serviceInstanceId", execution.getVariable("serviceInstanceId"))
289                 rollbackData.put(Prefix, "parentServiceInstanceId", execution.getVariable("parentServiceInstanceId"))
290                 rollbackData.put(Prefix, "aaiARPath", arUrl)
291                 execution.setVariable("rollbackData", rollbackData)
292                 msoLogger.trace("end createAaiAR")
293         }
294
295         public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
296
297
298                 String msg = ""
299                 msoLogger.trace("start buildSDNCRequest")
300                 String sdncReq = null
301
302                 try {
303
304                         String allottedResourceId = execution.getVariable("allottedResourceId")
305                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
306                         String globalCustomerId = execution.getVariable("globalCustomerId")
307                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
308                         String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
309                         String serviceChainServiceInstanceId = execution.getVariable("serviceChainServiceInstanceId")
310                         String callbackUrl = execution.getVariable("sdncCallbackUrl")
311                         String requestId = execution.getVariable("msoRequestId")
312
313                         String brgWanMacAddress = execution.getVariable("brgWanMacAddress")
314
315                         String arModelInfo = execution.getVariable("allottedResourceModelInfo")
316                         String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid")
317                         String modelVersion = jsonUtil.getJsonValue(arModelInfo, "modelVersion")
318                         String modelUUId = jsonUtil.getJsonValue(arModelInfo, "modelUuid")
319                         String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid")
320                         String modelName = jsonUtil.getJsonValue(arModelInfo, "modelName")
321
322                         if (modelInvariantId == null) {
323                                 modelInvariantId = ""
324                         }
325                         if (modelVersion == null) {
326                                 modelVersion = ""
327                         }
328                         if (modelUUId == null) {
329                                 modelUUId = ""
330                         }
331                         if (modelName == null) {
332                                 modelName = ""
333                         }
334                         if (modelCustomizationId == null) {
335                                 modelCustomizationId = ""
336                         }
337
338                         sdncReq =
339                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
340                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
341                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
342                                    <sdncadapter:RequestHeader>
343                                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
344                                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
345                                                         <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
346                                                         <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
347                                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
348                                         </sdncadapter:RequestHeader>
349                                 <sdncadapterworkflow:SDNCRequestData>
350                                         <request-information>
351                                                 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
352                                                 <request-action>CreateTunnelXConnInstance</request-action>
353                                                 <source>MSO</source>
354                                                 <notification-url/>
355                                                 <order-number/>
356                                                 <order-version/>
357                                         </request-information>
358                                         <service-information>
359                                                 <service-id></service-id>
360                                                 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
361                                                 <onap-model-information></onap-model-information>
362                                                 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
363                                                 <subscriber-name/>
364                                                 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
365                                         </service-information>
366                                         <allotted-resource-information>
367                                                 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>    
368                                                 <allotted-resource-type>tunnelxconn</allotted-resource-type>
369                                                 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>   
370                                                 <onap-model-information>
371                                                         <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
372                                                         <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
373                                                         <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
374                                                         <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
375                                                         <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
376                                                 </onap-model-information>
377                                         </allotted-resource-information>
378                                         <tunnelxconn-request-input>
379                                                         <brg-wan-mac-address>${MsoUtils.xmlEscape(brgWanMacAddress)}</brg-wan-mac-address>
380                                         </tunnelxconn-request-input>
381                                 </sdncadapterworkflow:SDNCRequestData>
382                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
383
384                         msoLogger.debug("sdncRequest:\n" + sdncReq)
385                         sdncReq = utils.formatXml(sdncReq)
386
387                 } catch(Exception ex) {
388                         msg = "Exception in buildSDNCRequest. " + ex.getMessage()
389                         msoLogger.debug(msg)
390                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
391                 }
392                 msoLogger.trace("end buildSDNCRequest")
393                 return sdncReq
394         }
395
396         public void preProcessSDNCAssign(DelegateExecution execution) {
397
398
399                 String msg = ""
400                 msoLogger.trace("start preProcessSDNCAssign")
401
402                 try {
403                         String sdncRequestId = UUID.randomUUID().toString()
404                         String sdncAssignReq = buildSDNCRequest(execution, "assign", sdncRequestId)
405                         execution.setVariable("sdncAssignRequest", sdncAssignReq)
406                         msoLogger.debug("sdncAssignRequest:  " + sdncAssignReq)
407                         def sdncRequestId2 = UUID.randomUUID().toString()
408                         String sdncAssignRollbackReq = sdncAssignReq.replace(">assign<", ">unassign<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
409                         def rollbackData = execution.getVariable("rollbackData")
410                         rollbackData.put(Prefix, "sdncAssignRollbackReq", sdncAssignRollbackReq)
411                         execution.setVariable("rollbackData", rollbackData)
412
413                         msoLogger.debug("sdncAssignRollbackReq:\n" + sdncAssignRollbackReq)
414                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
415
416                 } catch (BpmnError e) {
417                         throw e;
418                 } catch(Exception ex) {
419                         msg = "Exception in preProcessSDNCAssign. " + ex.getMessage()
420                         msoLogger.debug(msg)
421                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
422                 }
423                 msoLogger.debug("end preProcessSDNCAssign")
424         }
425
426         public void preProcessSDNCCreate(DelegateExecution execution) {
427
428
429                 String msg = ""
430                 msoLogger.trace("start preProcessSDNCCreate")
431
432                 try {
433                         String sdncRequestId = UUID.randomUUID().toString()
434                         String sdncCreateReq = buildSDNCRequest(execution, "create", sdncRequestId)
435                         execution.setVariable("sdncCreateRequest", sdncCreateReq)
436                         msoLogger.debug("sdncCreateReq:  " + sdncCreateReq)
437                         def sdncRequestId2 = UUID.randomUUID().toString()
438                         String sdncCreateRollbackReq = sdncCreateReq.replace(">create<", ">delete<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
439                         def rollbackData = execution.getVariable("rollbackData")
440                         rollbackData.put(Prefix, "sdncCreateRollbackReq", sdncCreateRollbackReq)
441                         execution.setVariable("rollbackData", rollbackData)
442
443                         msoLogger.debug("sdncCreateRollbackReq:\n" + sdncCreateRollbackReq)
444                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
445
446                 } catch (BpmnError e) {
447                         throw e;
448                 } catch(Exception ex) {
449                         msg = "Exception in preProcessSDNCCreate. " + ex.getMessage()
450                         msoLogger.debug(msg)
451                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
452                 }
453                 msoLogger.trace("end preProcessSDNCCreate")
454         }
455
456         public void preProcessSDNCActivate(DelegateExecution execution) {
457
458
459                 String msg = ""
460                 msoLogger.trace("start preProcessSDNCActivate")
461
462                 try {
463                         String sdncRequestId = UUID.randomUUID().toString()
464                         String sdncActivateReq = buildSDNCRequest(execution, "activate", sdncRequestId)
465                         execution.setVariable("sdncActivateRequest", sdncActivateReq)
466                         msoLogger.debug("sdncActivateReq:  " + sdncActivateReq)
467                         def sdncRequestId2 = UUID.randomUUID().toString()
468                         String sdncActivateRollbackReq = sdncActivateReq.replace(">activate<", ">deactivate<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
469                         def rollbackData = execution.getVariable("rollbackData")
470                         rollbackData.put(Prefix, "sdncActivateRollbackReq", sdncActivateRollbackReq)
471                         execution.setVariable("rollbackData", rollbackData)
472
473                         msoLogger.debug("sdncActivateRollbackReq:\n" + sdncActivateRollbackReq)
474                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
475
476                 } catch (BpmnError e) {
477                         throw e;
478                 } catch(Exception ex) {
479                         msg = "Exception in preProcessSDNCActivate. " + ex.getMessage()
480                         msoLogger.debug(msg)
481                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
482                 }
483                 msoLogger.trace("end preProcessSDNCActivate")
484         }
485
486         public void validateSDNCResp(DelegateExecution execution, String response, String method){
487
488
489                 msoLogger.trace("start ValidateSDNCResponse Process")
490                 String msg = ""
491
492                 try {
493                         WorkflowException workflowException = execution.getVariable("WorkflowException")
494                         msoLogger.debug("workflowException: " + workflowException)
495
496                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
497                         msoLogger.debug("SDNCResponse: " + response)
498
499                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
500                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
501
502                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
503                                 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + response)
504
505                                 if (!"get".equals(method))
506                                 {
507                                         def rollbackData = execution.getVariable("rollbackData")
508                                         rollbackData.put(Prefix, "rollback" +  "SDNC" + method, "true")
509                                         execution.setVariable("rollbackData", rollbackData)
510                                 }
511
512                         }else{
513                                 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
514                                 throw new BpmnError("MSOWorkflowException")
515                         }
516                 } catch (BpmnError e) {
517                         throw e;
518                 } catch(Exception ex) {
519                         msg = "Exception in validateSDNCResp. " + ex.getMessage()
520                         msoLogger.debug(msg)
521                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
522                 }
523                 msoLogger.trace("end ValidateSDNCResp Process")
524         }
525
526         public void preProcessSDNCGet(DelegateExecution execution){
527
528                 msoLogger.trace("start preProcessSDNCGet")
529                 try{
530
531                         def callbackUrl = execution.getVariable("sdncCallbackUrl")
532                         // serviceOperation (URI for topology GET) will be retrieved from "selflink" from AAI if active AR exists in AAI
533                         // or from  "object-path" in SDNC response for assign when AR does not exist in AA
534
535                         String serviceOperation = ""
536
537                         if (execution.getVariable("foundActiveAR")) {
538                                 def aaiQueryResponse = execution.getVariable("aaiARGetResponse")
539                                 serviceOperation = utils.getNodeText(aaiQueryResponse, "selflink")
540                                 msoLogger.debug("AR service operation/aaiARSelfLink: " + serviceOperation)
541                         }
542                         else
543                         {
544                                 String response = execution.getVariable("sdncAssignResponse")
545                                 String data = utils.getNodeXml(response, "response-data")
546                                 msoLogger.debug("Assign responseData: " + data)
547                                 serviceOperation = utils.getNodeText(data, "object-path")
548                                 msoLogger.debug("AR service operation:" + serviceOperation)
549                         }
550
551                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
552                         String sdncRequestId = UUID.randomUUID().toString()
553                         
554                         //neeed the same url as used by vfmodules
555                         String SDNCGetRequest =
556                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
557                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
558                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
559                                         <sdncadapter:RequestHeader>
560                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
561                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
562                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
563                                         <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(serviceOperation)}</sdncadapter:SvcOperation>
564                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
565                                         <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction>
566                                 </sdncadapter:RequestHeader>
567                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
568                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
569
570                         execution.setVariable("sdncGetRequest", SDNCGetRequest)
571
572                 }catch(Exception e){
573                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
574                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + e.getMessage())
575                 }
576                 msoLogger.trace("end preProcessSDNCGet")
577         }
578         
579         public void updateAaiAROrchStatus(DelegateExecution execution, String status){
580
581                 msoLogger.trace("start updateAaiAROrchStatus")
582                 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) or create
583                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
584                 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
585                 msoLogger.trace("end updateAaiAROrchStatus")
586         }
587         
588         public void generateOutputs(DelegateExecution execution)
589         {
590
591                 msoLogger.trace("start generateOutputs")
592                 try {
593                         String sdncGetResponse = execution.getVariable("enhancedCallbackRequestData") //unescaped
594                         msoLogger.debug("resp:" + sdncGetResponse)
595                         String arData = utils.getNodeXml(sdncGetResponse, "tunnelxconn-topology")
596                         arData = utils.removeXmlNamespaces(arData)
597                 
598                         String txca = utils.getNodeXml(arData, "tunnelxconn-assignments")
599                         execution.setVariable("vni", utils.getNodeText(txca, "vni"))
600                         execution.setVariable("vgmuxBearerIP", utils.getNodeText(txca, "vgmux-bearer-ip"))
601                         execution.setVariable("vgmuxLanIP", utils.getNodeText(txca, "vgmux-lan-ip"))
602                         
603                         String ari = utils.getNodeXml(arData, "allotted-resource-identifiers")
604                         execution.setVariable("allotedResourceName", utils.getNodeText(ari, "allotted-resource-name"))
605                 } catch (BpmnError e) {
606                         msoLogger.debug("BPMN Error in generateOutputs ")
607                 } catch(Exception ex) {
608                         String msg = "Exception in generateOutputs " + ex.getMessage()
609                         msoLogger.debug(msg)
610                 }
611                 msoLogger.trace("end generateOutputs")
612                 
613         }
614
615         public void preProcessRollback (DelegateExecution execution) {
616
617                 msoLogger.trace("start preProcessRollback")
618                 try {
619
620                         Object workflowException = execution.getVariable("WorkflowException");
621
622                         if (workflowException instanceof WorkflowException) {
623                                 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
624                                 execution.setVariable("prevWorkflowException", workflowException);
625                                 //execution.setVariable("WorkflowException", null);
626                         }
627                 } catch (BpmnError e) {
628                         msoLogger.debug("BPMN Error during preProcessRollback")
629                 } catch(Exception ex) {
630                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
631                         msoLogger.debug(msg)
632                 }
633                 msoLogger.trace("end preProcessRollback")
634         }
635
636         public void postProcessRollback (DelegateExecution execution) {
637
638                 msoLogger.trace("start postProcessRollback")
639                 String msg = ""
640                 try {
641                         Object workflowException = execution.getVariable("prevWorkflowException");
642                         if (workflowException instanceof WorkflowException) {
643                                 msoLogger.debug("Setting prevException to WorkflowException: ")
644                                 execution.setVariable("WorkflowException", workflowException);
645                         }
646                         execution.setVariable("rollbackData", null)
647                 } catch (BpmnError b) {
648                         msoLogger.debug("BPMN Error during postProcessRollback")
649                         throw b;
650                 } catch(Exception ex) {
651                         msg = "Exception in postProcessRollback. " + ex.getMessage()
652                         msoLogger.debug(msg)
653                 }
654                 msoLogger.trace("end postProcessRollback")
655         }
656
657 }