48eb1c85f961ce05ac6cd8f843d2256d3022749b
[so.git] /
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                         execution.setVariable("aaiARPath", arUtils.createARUrl(execution, siResourceLink, allottedResourceId))
209                         msoLogger.debug("GET AllottedResource AAI URL is:\n" + arUrl)
210
211                         String namespace = aaiUriUtil.getNamespaceFromUri(execution, arUrl)
212
213                         String arType = execution.getVariable("allottedResourceType")
214                         String arRole = execution.getVariable("allottedResourceRole")
215                         String CSI_resourceLink = execution.getVariable("CSI_resourceLink")
216                         String arModelInfo = execution.getVariable("allottedResourceModelInfo")
217                         msoLogger.debug("arModelInfo is:\n" + arModelInfo)
218                         String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid")
219                         String modelVersionId = jsonUtil.getJsonValue(arModelInfo, "modelUuid")
220                         String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid")
221
222                         if (modelInvariantId == null) {
223                                 modelInvariantId = ""
224                         }
225                         if (modelVersionId == null) {
226                                 modelVersionId = ""
227                         }
228                         if (modelCustomizationId == null) {
229                                 modelCustomizationId = ""
230                         }
231
232                         String payload =
233                         """<allotted-resource xmlns="${namespace}">
234                                 <id>${MsoUtils.xmlEscape(allottedResourceId)}</id>
235                                 <description></description>
236                                 <type>${MsoUtils.xmlEscape(arType)}</type>
237                                 <role>${MsoUtils.xmlEscape(arRole)}</role>
238                                 <selflink></selflink>
239                                 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-id>
240                                 <model-version-id>${MsoUtils.xmlEscape(modelVersionId)}</model-version-id>
241                                 <model-customization-id>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-id>
242                                 <orchestration-status>PendingCreate</orchestration-status>
243                                 <operation-status></operation-status>
244                                 <relationship-list>
245                                         <relationship>
246                                 <related-to>service-instance</related-to>
247                                 <related-link>${MsoUtils.xmlEscape(CSI_resourceLink)}</related-link>
248                                         </relationship>
249                                 </relationship-list>
250                         </allotted-resource>""".trim()
251
252                         execution.setVariable("AaiARPayload", payload)
253                         msoLogger.debug(" payload to create AllottedResource in AAI:" + "\n" + payload)
254
255                         APIResponse response = aaiUriUtil.executeAAIPutCall(execution, arUrl, payload)
256                         int responseCode = response.getStatusCode()
257                         msoLogger.debug("AllottedResource AAI PUT responseCode:" + responseCode)
258
259                         String aaiResponse = response.getResponseBodyAsString()
260                         msoLogger.debug("AllottedResource AAI PUT responseStr:" + aaiResponse)
261
262                         //200 OK 201 CREATED 202 ACCEPTED
263                         if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
264                         {
265                                 msoLogger.debug("AAI PUT AllottedResource received a Good Response")
266                         }
267                         else{
268                                 msoLogger.debug("AAI Put AllottedResouce received a Bad Response Code: " + responseCode)
269                                 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
270                                 throw new BpmnError("MSOWorkflowException")
271                         }
272                 }catch(BpmnError b){
273                         msoLogger.debug("Rethrowing MSOWorkflowException")
274                         throw b
275                 } catch (Exception ex) {
276                         msg = "Exception in createAaiAR " + ex.getMessage()
277                         msoLogger.debug(msg)
278                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
279                 }
280
281                 //start rollback set up
282                 RollbackData rollbackData = new RollbackData()
283                 def disableRollback = execution.getVariable("disableRollback")
284                 rollbackData.put(Prefix, "disableRollback", disableRollback.toString())
285                 rollbackData.put(Prefix, "rollbackAAI", "true")
286                 rollbackData.put(Prefix, "allottedResourceId", allottedResourceId)
287                 rollbackData.put(Prefix, "serviceInstanceId", execution.getVariable("serviceInstanceId"))
288                 rollbackData.put(Prefix, "parentServiceInstanceId", execution.getVariable("parentServiceInstanceId"))
289                 rollbackData.put(Prefix, "aaiARPath", arUrl)
290                 execution.setVariable("rollbackData", rollbackData)
291                 msoLogger.trace("end createAaiAR")
292         }
293
294         public String buildSDNCRequest(DelegateExecution execution, String action, String sdncRequestId) {
295
296
297                 String msg = ""
298                 msoLogger.trace("start buildSDNCRequest")
299                 String sdncReq = null
300
301                 try {
302
303                         String allottedResourceId = execution.getVariable("allottedResourceId")
304                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
305                         String globalCustomerId = execution.getVariable("globalCustomerId")
306                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
307                         String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
308                         String serviceChainServiceInstanceId = execution.getVariable("serviceChainServiceInstanceId")
309                         String callbackUrl = execution.getVariable("sdncCallbackUrl")
310                         String requestId = execution.getVariable("msoRequestId")
311
312                         String brgWanMacAddress = execution.getVariable("brgWanMacAddress")
313
314                         String arModelInfo = execution.getVariable("allottedResourceModelInfo")
315                         String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid")
316                         String modelVersion = jsonUtil.getJsonValue(arModelInfo, "modelVersion")
317                         String modelUUId = jsonUtil.getJsonValue(arModelInfo, "modelUuid")
318                         String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid")
319                         String modelName = jsonUtil.getJsonValue(arModelInfo, "modelName")
320
321                         if (modelInvariantId == null) {
322                                 modelInvariantId = ""
323                         }
324                         if (modelVersion == null) {
325                                 modelVersion = ""
326                         }
327                         if (modelUUId == null) {
328                                 modelUUId = ""
329                         }
330                         if (modelName == null) {
331                                 modelName = ""
332                         }
333                         if (modelCustomizationId == null) {
334                                 modelCustomizationId = ""
335                         }
336
337                         sdncReq =
338                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
339                                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
340                                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
341                                    <sdncadapter:RequestHeader>
342                                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
343                                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
344                                                         <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
345                                                         <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
346                                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
347                                         </sdncadapter:RequestHeader>
348                                 <sdncadapterworkflow:SDNCRequestData>
349                                         <request-information>
350                                                 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
351                                                 <request-action>CreateTunnelXConnInstance</request-action>
352                                                 <source>MSO</source>
353                                                 <notification-url/>
354                                                 <order-number/>
355                                                 <order-version/>
356                                         </request-information>
357                                         <service-information>
358                                                 <service-id></service-id>
359                                                 <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
360                                                 <onap-model-information></onap-model-information>
361                                                 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
362                                                 <subscriber-name/>
363                                                 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
364                                         </service-information>
365                                         <allotted-resource-information>
366                                                 <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id>    
367                                                 <allotted-resource-type>tunnelxconn</allotted-resource-type>
368                                                 <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id>   
369                                                 <onap-model-information>
370                                                         <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid>
371                                                         <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid>
372                                                         <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationId)}</model-customization-uuid>
373                                                         <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
374                                                         <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
375                                                 </onap-model-information>
376                                         </allotted-resource-information>
377                                         <tunnelxconn-request-input>
378                                                         <brg-wan-mac-address>${MsoUtils.xmlEscape(brgWanMacAddress)}</brg-wan-mac-address>
379                                         </tunnelxconn-request-input>
380                                 </sdncadapterworkflow:SDNCRequestData>
381                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
382
383                         msoLogger.debug("sdncRequest:\n" + sdncReq)
384                         sdncReq = utils.formatXml(sdncReq)
385
386                 } catch(Exception ex) {
387                         msg = "Exception in buildSDNCRequest. " + ex.getMessage()
388                         msoLogger.debug(msg)
389                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
390                 }
391                 msoLogger.trace("end buildSDNCRequest")
392                 return sdncReq
393         }
394
395         public void preProcessSDNCAssign(DelegateExecution execution) {
396
397
398                 String msg = ""
399                 msoLogger.trace("start preProcessSDNCAssign")
400
401                 try {
402                         String sdncRequestId = UUID.randomUUID().toString()
403                         String sdncAssignReq = buildSDNCRequest(execution, "assign", sdncRequestId)
404                         execution.setVariable("sdncAssignRequest", sdncAssignReq)
405                         msoLogger.debug("sdncAssignRequest:  " + sdncAssignReq)
406                         def sdncRequestId2 = UUID.randomUUID().toString()
407                         String sdncAssignRollbackReq = sdncAssignReq.replace(">assign<", ">unassign<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
408                         def rollbackData = execution.getVariable("rollbackData")
409                         rollbackData.put(Prefix, "sdncAssignRollbackReq", sdncAssignRollbackReq)
410                         execution.setVariable("rollbackData", rollbackData)
411
412                         msoLogger.debug("sdncAssignRollbackReq:\n" + sdncAssignRollbackReq)
413                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
414
415                 } catch (BpmnError e) {
416                         throw e;
417                 } catch(Exception ex) {
418                         msg = "Exception in preProcessSDNCAssign. " + ex.getMessage()
419                         msoLogger.debug(msg)
420                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
421                 }
422                 msoLogger.debug("end preProcessSDNCAssign")
423         }
424
425         public void preProcessSDNCCreate(DelegateExecution execution) {
426
427
428                 String msg = ""
429                 msoLogger.trace("start preProcessSDNCCreate")
430
431                 try {
432                         String sdncRequestId = UUID.randomUUID().toString()
433                         String sdncCreateReq = buildSDNCRequest(execution, "create", sdncRequestId)
434                         execution.setVariable("sdncCreateRequest", sdncCreateReq)
435                         msoLogger.debug("sdncCreateReq:  " + sdncCreateReq)
436                         def sdncRequestId2 = UUID.randomUUID().toString()
437                         String sdncCreateRollbackReq = sdncCreateReq.replace(">create<", ">delete<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
438                         def rollbackData = execution.getVariable("rollbackData")
439                         rollbackData.put(Prefix, "sdncCreateRollbackReq", sdncCreateRollbackReq)
440                         execution.setVariable("rollbackData", rollbackData)
441
442                         msoLogger.debug("sdncCreateRollbackReq:\n" + sdncCreateRollbackReq)
443                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
444
445                 } catch (BpmnError e) {
446                         throw e;
447                 } catch(Exception ex) {
448                         msg = "Exception in preProcessSDNCCreate. " + ex.getMessage()
449                         msoLogger.debug(msg)
450                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
451                 }
452                 msoLogger.trace("end preProcessSDNCCreate")
453         }
454
455         public void preProcessSDNCActivate(DelegateExecution execution) {
456
457
458                 String msg = ""
459                 msoLogger.trace("start preProcessSDNCActivate")
460
461                 try {
462                         String sdncRequestId = UUID.randomUUID().toString()
463                         String sdncActivateReq = buildSDNCRequest(execution, "activate", sdncRequestId)
464                         execution.setVariable("sdncActivateRequest", sdncActivateReq)
465                         msoLogger.debug("sdncActivateReq:  " + sdncActivateReq)
466                         def sdncRequestId2 = UUID.randomUUID().toString()
467                         String sdncActivateRollbackReq = sdncActivateReq.replace(">activate<", ">deactivate<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
468                         def rollbackData = execution.getVariable("rollbackData")
469                         rollbackData.put(Prefix, "sdncActivateRollbackReq", sdncActivateRollbackReq)
470                         execution.setVariable("rollbackData", rollbackData)
471
472                         msoLogger.debug("sdncActivateRollbackReq:\n" + sdncActivateRollbackReq)
473                         msoLogger.debug("rollbackData:\n" + rollbackData.toString())
474
475                 } catch (BpmnError e) {
476                         throw e;
477                 } catch(Exception ex) {
478                         msg = "Exception in preProcessSDNCActivate. " + ex.getMessage()
479                         msoLogger.debug(msg)
480                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
481                 }
482                 msoLogger.trace("end preProcessSDNCActivate")
483         }
484
485         public void validateSDNCResp(DelegateExecution execution, String response, String method){
486
487
488                 msoLogger.trace("start ValidateSDNCResponse Process")
489                 String msg = ""
490
491                 try {
492                         WorkflowException workflowException = execution.getVariable("WorkflowException")
493                         msoLogger.debug("workflowException: " + workflowException)
494
495                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
496                         msoLogger.debug("SDNCResponse: " + response)
497
498                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
499                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
500
501                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
502                                 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + response)
503
504                                 if (!"get".equals(method))
505                                 {
506                                         def rollbackData = execution.getVariable("rollbackData")
507                                         rollbackData.put(Prefix, "rollback" +  "SDNC" + method, "true")
508                                         execution.setVariable("rollbackData", rollbackData)
509                                 }
510
511                         }else{
512                                 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
513                                 throw new BpmnError("MSOWorkflowException")
514                         }
515                 } catch (BpmnError e) {
516                         throw e;
517                 } catch(Exception ex) {
518                         msg = "Exception in validateSDNCResp. " + ex.getMessage()
519                         msoLogger.debug(msg)
520                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
521                 }
522                 msoLogger.trace("end ValidateSDNCResp Process")
523         }
524
525         public void preProcessSDNCGet(DelegateExecution execution){
526
527                 msoLogger.trace("start preProcessSDNCGet")
528                 try{
529
530                         def callbackUrl = execution.getVariable("sdncCallbackUrl")
531                         // serviceOperation (URI for topology GET) will be retrieved from "selflink" from AAI if active AR exists in AAI
532                         // or from  "object-path" in SDNC response for assign when AR does not exist in AA
533
534                         String serviceOperation = ""
535
536                         if (execution.getVariable("foundActiveAR")) {
537                                 def aaiQueryResponse = execution.getVariable("aaiARGetResponse")
538                                 serviceOperation = utils.getNodeText(aaiQueryResponse, "selflink")
539                                 msoLogger.debug("AR service operation/aaiARSelfLink: " + serviceOperation)
540                         }
541                         else
542                         {
543                                 String response = execution.getVariable("sdncAssignResponse")
544                                 String data = utils.getNodeXml(response, "response-data")
545                                 msoLogger.debug("Assign responseData: " + data)
546                                 serviceOperation = utils.getNodeText(data, "object-path")
547                                 msoLogger.debug("AR service operation:" + serviceOperation)
548                         }
549
550                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
551                         String sdncRequestId = UUID.randomUUID().toString()
552                         
553                         //neeed the same url as used by vfmodules
554                         String SDNCGetRequest =
555                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
556                                                                                         xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
557                                                                                         xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
558                                         <sdncadapter:RequestHeader>
559                                         <sdncadapter:RequestId>${MsoUtils.xmlEscape(sdncRequestId)}</sdncadapter:RequestId>
560                                         <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
561                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
562                                         <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(serviceOperation)}</sdncadapter:SvcOperation>
563                                         <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
564                                         <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction>
565                                 </sdncadapter:RequestHeader>
566                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
567                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
568
569                         execution.setVariable("sdncGetRequest", SDNCGetRequest)
570
571                 }catch(Exception e){
572                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
573                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + e.getMessage())
574                 }
575                 msoLogger.trace("end preProcessSDNCGet")
576         }
577         
578         public void updateAaiAROrchStatus(DelegateExecution execution, String status){
579
580                 msoLogger.trace("start updateAaiAROrchStatus")
581                 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) or create
582                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
583                 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
584                 msoLogger.trace("end updateAaiAROrchStatus")
585         }
586         
587         public void generateOutputs(DelegateExecution execution)
588         {
589
590                 msoLogger.trace("start generateOutputs")
591                 try {
592                         String sdncGetResponse = execution.getVariable("enhancedCallbackRequestData") //unescaped
593                         msoLogger.debug("resp:" + sdncGetResponse)
594                         String arData = utils.getNodeXml(sdncGetResponse, "tunnelxconn-topology")
595                         arData = utils.removeXmlNamespaces(arData)
596                 
597                         String txca = utils.getNodeXml(arData, "tunnelxconn-assignments")
598                         execution.setVariable("vni", utils.getNodeText(txca, "vni"))
599                         execution.setVariable("vgmuxBearerIP", utils.getNodeText(txca, "vgmux-bearer-ip"))
600                         execution.setVariable("vgmuxLanIP", utils.getNodeText(txca, "vgmux-lan-ip"))
601                         
602                         String ari = utils.getNodeXml(arData, "allotted-resource-identifiers")
603                         execution.setVariable("allotedResourceName", utils.getNodeText(ari, "allotted-resource-name"))
604                 } catch (BpmnError e) {
605                         msoLogger.debug("BPMN Error in generateOutputs ")
606                 } catch(Exception ex) {
607                         String msg = "Exception in generateOutputs " + ex.getMessage()
608                         msoLogger.debug(msg)
609                 }
610                 msoLogger.trace("end generateOutputs")
611                 
612         }
613
614         public void preProcessRollback (DelegateExecution execution) {
615
616                 msoLogger.trace("start preProcessRollback")
617                 try {
618
619                         Object workflowException = execution.getVariable("WorkflowException");
620
621                         if (workflowException instanceof WorkflowException) {
622                                 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
623                                 execution.setVariable("prevWorkflowException", workflowException);
624                                 //execution.setVariable("WorkflowException", null);
625                         }
626                 } catch (BpmnError e) {
627                         msoLogger.debug("BPMN Error during preProcessRollback")
628                 } catch(Exception ex) {
629                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
630                         msoLogger.debug(msg)
631                 }
632                 msoLogger.trace("end preProcessRollback")
633         }
634
635         public void postProcessRollback (DelegateExecution execution) {
636
637                 msoLogger.trace("start postProcessRollback")
638                 String msg = ""
639                 try {
640                         Object workflowException = execution.getVariable("prevWorkflowException");
641                         if (workflowException instanceof WorkflowException) {
642                                 msoLogger.debug("Setting prevException to WorkflowException: ")
643                                 execution.setVariable("WorkflowException", workflowException);
644                         }
645                         execution.setVariable("rollbackData", null)
646                 } catch (BpmnError b) {
647                         msoLogger.debug("BPMN Error during postProcessRollback")
648                         throw b;
649                 } catch(Exception ex) {
650                         msg = "Exception in postProcessRollback. " + ex.getMessage()
651                         msoLogger.debug(msg)
652                 }
653                 msoLogger.trace("end postProcessRollback")
654         }
655
656 }