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