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