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