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