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