c721ae833be85b8efa6999ce9c7c137bef638cac
[so.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.bpmn.vcpe.scripts;
21
22 import org.openecomp.mso.bpmn.common.scripts.*;
23 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
24 import org.openecomp.mso.bpmn.core.RollbackData
25 import org.openecomp.mso.bpmn.core.WorkflowException
26 import org.openecomp.mso.bpmn.core.json.JsonUtils
27 import org.openecomp.mso.rest.APIResponse
28
29 import java.util.UUID;
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.runtime.Execution
32 import org.apache.commons.lang3.*
33 import org.springframework.web.util.UriUtils;
34 import static org.apache.commons.lang3.StringUtils.*
35
36
37 /**
38  * This groovy class supports the <class>DoCreateAllottedResourceTXC.bpmn</class> process.
39  *
40  * @author
41  * 
42  * Inputs:
43  * @param - msoRequestId
44  * @param - isDEbugLogEnabled
45  * @param - disableRollback
46  * @param - failExists  - O
47  * @param - serviceInstanceId
48  * @param - parentServiceInstanceId
49  * @param - allottedReourceId - O
50  * @param - allottedResourceModelInfo
51  * @param - allottedResourceRole
52  * @param - allottedResourceType
53  * @param - brgWanMacAddress
54  *
55  * Outputs:
56  * @param - rollbackData (localRB->null)
57  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
58  * @param - WorkflowException - O
59  * @param - allottedResourceId
60  * @param - allottedResourceName 
61  * @param - vni 
62  * @param - vgmuxBearerIP 
63  * @param - vgmuxLanIP 
64  *
65  */
66 public class DoCreateAllottedResourceTXC extends AbstractServiceTaskProcessor{
67
68         private static final String DebugFlag = "isDebugLogEnabled"
69
70         String Prefix="DCARTXC_"
71         ExceptionUtil exceptionUtil = new ExceptionUtil()
72         JsonUtils jsonUtil = new JsonUtils()
73
74         public void preProcessRequest (Execution execution) {
75
76                 def isDebugEnabled = execution.getVariable(DebugFlag)
77                 String msg = ""
78                 utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
79
80                 try {
81                         String msoRequestId      = execution.getVariable("msoRequestId")
82                         utils.log("DEBUG", " msoRequestId  = " + msoRequestId,  isDebugEnabled)
83
84                         if ((msoRequestId == null) || ("testRequestId".equals(msoRequestId)) || ("testRequestId123".equals(msoRequestId)))
85                         {
86                                 utils.log("DEBUG"," ***** NOT sleeping 30 seconds for Junit *****",  isDebugEnabled)
87                         }
88                         else
89                         {
90                                 utils.log("DEBUG"," ***** sleeping 30 seconds for AAI replication *****",  isDebugEnabled)
91                                 sleep(30000);
92                                 utils.log("DEBUG"," ***** sleep over *****",  isDebugEnabled)
93                         }
94
95                         execution.setVariable("prefix", Prefix)
96
97                         //Config Inputs
98                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
99                         if (isBlank(sdncCallbackUrl)) {
100                                 msg = "URN_mso_workflow_sdncadapter_callback is null"
101                                 utils.log("DEBUG", msg, isDebugEnabled)
102                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
103                         }
104                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
105                         utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, 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 (Execution 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(Execution 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(Execution 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 parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
322                         String serviceChainServiceInstanceId = execution.getVariable("serviceChainServiceInstanceId")
323                         String callbackUrl = execution.getVariable("sdncCallbackUrl")
324                         String requestId = execution.getVariable("msoRequestId")
325
326                         String brgWanMacAddress = execution.getVariable("brgWanMacAddress")
327
328                         String arModelInfo = execution.getVariable("allottedResourceModelInfo")
329                         String modelInvariantId = jsonUtil.getJsonValue(arModelInfo, "modelInvariantUuid")
330                         String modelVersion = jsonUtil.getJsonValue(arModelInfo, "modelVersion")
331                         String modelUUId = jsonUtil.getJsonValue(arModelInfo, "modelUuid")
332                         String modelCustomizationId = jsonUtil.getJsonValue(arModelInfo, "modelCustomizationUuid")
333                         String modelName = jsonUtil.getJsonValue(arModelInfo, "modelName")
334
335                         if (modelInvariantId == null) {
336                                 modelInvariantId = ""
337                         }
338                         if (modelVersion == null) {
339                                 modelVersion = ""
340                         }
341                         if (modelUUId == null) {
342                                 modelUUId = ""
343                         }
344                         if (modelName == null) {
345                                 modelName = ""
346                         }
347                         if (modelCustomizationId == null) {
348                                 modelCustomizationId = ""
349                         }
350
351                         sdncReq =
352                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
353                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
354                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
355                                    <sdncadapter:RequestHeader>
356                                                         <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
357                                                         <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
358                                                         <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
359                                                         <sdncadapter:SvcOperation>tunnelxconn-topology-operation</sdncadapter:SvcOperation>
360                                                         <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
361                                         </sdncadapter:RequestHeader>
362                                 <sdncadapterworkflow:SDNCRequestData>
363                                         <request-information>
364                                                 <request-id>${requestId}</request-id>
365                                                 <request-action>CreateTunnelXConnInstance</request-action>
366                                                 <source>MSO</source>
367                                                 <notification-url/>
368                                                 <order-number/>
369                                                 <order-version/>
370                                         </request-information>
371                                         <service-information>
372                                                 <service-id></service-id>
373                                                 <subscription-service-type></subscription-service-type>
374                                                 <onap-model-information></onap-model-information>
375                                                 <service-instance-id>${parentServiceInstanceId}</service-instance-id>
376                                                 <subscriber-name/>
377                                                 <global-customer-id></global-customer-id>
378                                         </service-information>
379                                         <allotted-resource-information>
380                                                 <allotted-resource-id>${allottedResourceId}</allotted-resource-id>    
381                                                 <allotted-resource-type>tunnelxconn</allotted-resource-type>
382                                                 <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id>   
383                                                 <onap-model-information>
384                                                         <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid>
385                                                         <model-uuid>${modelUUId}</model-uuid>
386                                                         <model-customization-uuid>${modelCustomizationId}</model-customization-uuid>
387                                                         <model-version>${modelVersion}</model-version>
388                                                         <model-name>${modelName}</model-name>
389                                                 </onap-model-information>
390                                         </allotted-resource-information>
391                                         <tunnelxconn-request-input>
392                                                         <brg-wan-mac-address>${brgWanMacAddress}</brg-wan-mac-address>
393                                         </tunnelxconn-request-input>
394                                 </sdncadapterworkflow:SDNCRequestData>
395                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
396
397                         utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled)
398                         sdncReq = utils.formatXml(sdncReq)
399
400                 } catch(Exception ex) {
401                         msg = "Exception in buildSDNCRequest. " + ex.getMessage()
402                         utils.log("DEBUG", msg, isDebugEnabled)
403                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
404                 }
405                 utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled)
406                 return sdncReq
407         }
408
409         public void preProcessSDNCAssign(Execution execution) {
410
411                 def isDebugEnabled = execution.getVariable(DebugFlag)
412                 String msg = ""
413                 utils.log("DEBUG"," ***** preProcessSDNCAssign *****", isDebugEnabled)
414
415                 try {
416                         String sdncRequestId = UUID.randomUUID().toString()
417                         String sdncAssignReq = buildSDNCRequest(execution, "assign", sdncRequestId)
418                         execution.setVariable("sdncAssignRequest", sdncAssignReq)
419                         utils.logAudit("sdncAssignRequest:  " + sdncAssignReq)
420                         def sdncRequestId2 = UUID.randomUUID().toString()
421                         String sdncAssignRollbackReq = sdncAssignReq.replace(">assign<", ">unassign<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
422                         def rollbackData = execution.getVariable("rollbackData")
423                         rollbackData.put(Prefix, "sdncAssignRollbackReq", sdncAssignRollbackReq)
424                         execution.setVariable("rollbackData", rollbackData)
425
426                         utils.log("DEBUG","sdncAssignRollbackReq:\n" + sdncAssignRollbackReq, isDebugEnabled)
427                         utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled)
428
429                 } catch (BpmnError e) {
430                         throw e;
431                 } catch(Exception ex) {
432                         msg = "Exception in preProcessSDNCAssign. " + ex.getMessage()
433                         utils.log("DEBUG", msg, isDebugEnabled)
434                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
435                 }
436                 utils.log("DEBUG"," *****Exit preProcessSDNCAssign *****", isDebugEnabled)
437         }
438
439         public void preProcessSDNCCreate(Execution execution) {
440
441                 def isDebugEnabled = execution.getVariable(DebugFlag)
442                 String msg = ""
443                 utils.log("DEBUG"," ***** preProcessSDNCCreate *****", isDebugEnabled)
444
445                 try {
446                         String sdncRequestId = UUID.randomUUID().toString()
447                         String sdncCreateReq = buildSDNCRequest(execution, "create", sdncRequestId)
448                         execution.setVariable("sdncCreateRequest", sdncCreateReq)
449                         utils.logAudit("sdncCreateReq:  " + sdncCreateReq)
450                         def sdncRequestId2 = UUID.randomUUID().toString()
451                         String sdncCreateRollbackReq = sdncCreateReq.replace(">create<", ">delete<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
452                         def rollbackData = execution.getVariable("rollbackData")
453                         rollbackData.put(Prefix, "sdncCreateRollbackReq", sdncCreateRollbackReq)
454                         execution.setVariable("rollbackData", rollbackData)
455
456                         utils.log("DEBUG","sdncCreateRollbackReq:\n" + sdncCreateRollbackReq, isDebugEnabled)
457                         utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled)
458
459                 } catch (BpmnError e) {
460                         throw e;
461                 } catch(Exception ex) {
462                         msg = "Exception in preProcessSDNCCreate. " + ex.getMessage()
463                         utils.log("DEBUG", msg, isDebugEnabled)
464                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
465                 }
466                 utils.log("DEBUG"," *****Exit preProcessSDNCCreate *****", isDebugEnabled)
467         }
468
469         public void preProcessSDNCActivate(Execution execution) {
470
471                 def isDebugEnabled = execution.getVariable(DebugFlag)
472                 String msg = ""
473                 utils.log("DEBUG"," ***** preProcessSDNCActivate *****", isDebugEnabled)
474
475                 try {
476                         String sdncRequestId = UUID.randomUUID().toString()
477                         String sdncActivateReq = buildSDNCRequest(execution, "activate", sdncRequestId)
478                         execution.setVariable("sdncActivateRequest", sdncActivateReq)
479                         utils.logAudit("sdncActivateReq:  " + sdncActivateReq)
480                         def sdncRequestId2 = UUID.randomUUID().toString()
481                         String sdncActivateRollbackReq = sdncActivateReq.replace(">activate<", ">deactivate<").replace(">CreateTunnelXConnInstance<", ">DeleteTunnelXConnInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
482                         def rollbackData = execution.getVariable("rollbackData")
483                         rollbackData.put(Prefix, "sdncActivateRollbackReq", sdncActivateRollbackReq)
484                         execution.setVariable("rollbackData", rollbackData)
485
486                         utils.log("DEBUG","sdncActivateRollbackReq:\n" + sdncActivateRollbackReq, isDebugEnabled)
487                         utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled)
488
489                 } catch (BpmnError e) {
490                         throw e;
491                 } catch(Exception ex) {
492                         msg = "Exception in preProcessSDNCActivate. " + ex.getMessage()
493                         utils.log("DEBUG", msg, isDebugEnabled)
494                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
495                 }
496                 utils.log("DEBUG"," *****Exit preProcessSDNCActivate *****", isDebugEnabled)
497         }
498
499         public void validateSDNCResp(Execution execution, String response, String method){
500
501                 def isDebugLogEnabled=execution.getVariable(DebugFlag)
502                 utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled)
503                 String msg = ""
504
505                 try {
506                         WorkflowException workflowException = execution.getVariable("WorkflowException")
507                         utils.logAudit("workflowException: " + workflowException)
508
509                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
510                         utils.logAudit("SDNCResponse: " + response)
511
512                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
513                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
514
515                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
516                                 utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call.  Response is: \n" + response, isDebugLogEnabled)
517
518                                 if (!"get".equals(method))
519                                 {
520                                         def rollbackData = execution.getVariable("rollbackData")
521                                         rollbackData.put(Prefix, "rollback" +  "SDNC" + method, "true")
522                                         execution.setVariable("rollbackData", rollbackData)
523                                 }
524
525                         }else{
526                                 utils.log("DEBUG", "Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
527                                 throw new BpmnError("MSOWorkflowException")
528                         }
529                 } catch (BpmnError e) {
530                         throw e;
531                 } catch(Exception ex) {
532                         msg = "Exception in validateSDNCResp. " + ex.getMessage()
533                         utils.log("DEBUG", msg, isDebugLogEnabled)
534                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
535                 }
536                 logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled)
537         }
538
539         public void preProcessSDNCGet(Execution execution){
540                 def isDebugLogEnabled = execution.getVariable(DebugFlag)
541                 utils.log("DEBUG", "*** preProcessSDNCGet *** ", isDebugLogEnabled)
542                 try{
543
544                         def callbackUrl = execution.getVariable("sdncCallbackUrl")
545                         // serviceOperation (URI for topology GET) will be retrieved from "selflink" from AAI if active AR exists in AAI
546                         // or from  "object-path" in SDNC response for assign when AR does not exist in AA
547
548                         String serviceOperation = ""
549
550                         if (execution.getVariable("foundActiveAR")) {
551                                 def aaiQueryResponse = execution.getVariable("aaiARGetResponse")
552                                 serviceOperation = utils.getNodeText1(aaiQueryResponse, "selflink")
553                                 utils.log("DEBUG", "AR service operation/aaiARSelfLink: " + serviceOperation, isDebugLogEnabled)
554                         }
555                         else
556                         {
557                                 String response = execution.getVariable("sdncAssignResponse")
558                                 String data = utils.getNodeXml(response, "response-data")
559                                 data = data.replaceAll("&lt;", "<")
560                                 data = data.replaceAll("&gt;", ">")
561                                 utils.log("DEBUG", "Assign responseData: " + data, isDebugLogEnabled)
562                                 serviceOperation = utils.getNodeText1(data, "object-path")
563                                 utils.log("DEBUG", "AR service operation:" + serviceOperation, isDebugLogEnabled)
564                         }
565
566                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
567                         String sdncRequestId = UUID.randomUUID().toString()
568                         
569                         String tsleep = execution.getVariable("junitSleepMs")
570                         
571                         //workaround for sdnc replication issue
572                         sleep(tsleep == null ? 5000 : tsleep as Long)
573
574                         //neeed the same url as used by vfmodules
575                         String SDNCGetRequest =
576                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
577                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
578                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
579                                         <sdncadapter:RequestHeader>
580                                         <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
581                                         <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
582                                         <sdncadapter:SvcAction>query</sdncadapter:SvcAction>
583                                         <sdncadapter:SvcOperation>${serviceOperation}</sdncadapter:SvcOperation>
584                                         <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
585                                         <sdncadapter:MsoAction>vfmodule</sdncadapter:MsoAction>
586                                 </sdncadapter:RequestHeader>
587                                         <sdncadapterworkflow:SDNCRequestData></sdncadapterworkflow:SDNCRequestData>
588                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
589
590                         execution.setVariable("sdncGetRequest", SDNCGetRequest)
591
592                 }catch(Exception e){
593                         utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + e, isDebugLogEnabled)
594                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + e.getMessage())
595                 }
596                 utils.log("DEBUG", "*** Exit preProcessSDNCGet *** ", isDebugLogEnabled)
597         }
598         
599         public void updateAaiAROrchStatus(Execution execution, String status){
600                 def isDebugEnabled = execution.getVariable(DebugFlag)
601                 utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled)
602                 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR) or create
603                 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
604                 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
605                 utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled)
606         }
607         
608         public void generateOutputs(Execution execution)
609         {
610                 def isDebugEnabled=execution.getVariable(DebugFlag)
611                 utils.log("DEBUG"," ***** generateOutputs ***** ", isDebugEnabled)
612                 try {
613                         String sdncGetResponse = execution.getVariable("enhancedCallbackRequestData") //unescaped
614                         utils.log("DEBUG", "resp:" + sdncGetResponse, isDebugEnabled)
615                         String arData = utils.getNodeXml(sdncGetResponse, "tunnelxconn-topology")
616                         arData = utils.removeXmlNamespaces(arData)
617                 
618                         String txca = utils.getNodeXml(arData, "tunnelxconn-assignments")
619                         execution.setVariable("vni", utils.getNodeText1(txca, "vni"))
620                         execution.setVariable("vgmuxBearerIP", utils.getNodeText1(txca, "vgmux_bearer_ip"))
621                         execution.setVariable("vgmuxLanIP", utils.getNodeText1(txca, "vgmux_lan_ip"))
622                         
623                         String ari = utils.getNodeXml(arData, "allotted-resource-identifiers")
624                         execution.setVariable("allotedResourceName", utils.getNodeText1(ari, "allotted-resource-name"))
625                 } catch (BpmnError e) {
626                         utils.log("DEBUG", "BPMN Error in generateOutputs ", isDebugEnabled)
627                 } catch(Exception ex) {
628                         String msg = "Exception in generateOutputs " + ex.getMessage()
629                         utils.log("DEBUG", msg, isDebugEnabled)
630                 }
631                 utils.log("DEBUG"," *** Exit generateOutputs *** ", isDebugEnabled)
632                 
633         }
634
635         public void preProcessRollback (Execution execution) {
636                 def isDebugEnabled=execution.getVariable(DebugFlag)
637                 utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled)
638                 try {
639
640                         Object workflowException = execution.getVariable("WorkflowException");
641
642                         if (workflowException instanceof WorkflowException) {
643                                 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
644                                 execution.setVariable("prevWorkflowException", workflowException);
645                                 //execution.setVariable("WorkflowException", null);
646                         }
647                 } catch (BpmnError e) {
648                         utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
649                 } catch(Exception ex) {
650                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
651                         utils.log("DEBUG", msg, isDebugEnabled)
652                 }
653                 utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled)
654         }
655
656         public void postProcessRollback (Execution execution) {
657                 def isDebugEnabled=execution.getVariable(DebugFlag)
658                 utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled)
659                 String msg = ""
660                 try {
661                         Object workflowException = execution.getVariable("prevWorkflowException");
662                         if (workflowException instanceof WorkflowException) {
663                                 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
664                                 execution.setVariable("WorkflowException", workflowException);
665                         }
666                         execution.setVariable("rollbackData", null)
667                 } catch (BpmnError b) {
668                         utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
669                         throw b;
670                 } catch(Exception ex) {
671                         msg = "Exception in postProcessRollback. " + ex.getMessage()
672                         utils.log("DEBUG", msg, isDebugEnabled)
673                 }
674                 utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled)
675         }
676
677 }