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