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