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