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