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