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