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