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