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