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