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