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