Added Groovy for E2E svc
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateE2EServiceInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. 
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
22
23 import static org.apache.commons.lang3.StringUtils.*;
24 import groovy.xml.XmlUtil
25 import groovy.json.*
26
27 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
28 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
29 import org.openecomp.mso.bpmn.core.domain.ModelInfo
30 import org.openecomp.mso.bpmn.core.json.JsonUtils
31 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
32 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
34 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
35 import org.openecomp.mso.bpmn.core.RollbackData
36 import org.openecomp.mso.bpmn.core.WorkflowException
37 import org.openecomp.mso.rest.APIResponse;
38 import org.openecomp.mso.rest.RESTClient
39 import org.openecomp.mso.rest.RESTConfig
40
41 import java.util.UUID;
42
43 import org.camunda.bpm.engine.delegate.BpmnError
44 import org.camunda.bpm.engine.runtime.Execution
45 import org.json.JSONObject;
46 import org.apache.commons.lang3.*
47 import org.apache.commons.codec.binary.Base64;
48 import org.springframework.web.util.UriUtils;
49
50 /**
51  * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
52  *
53  * Inputs:
54  * @param - msoRequestId
55  * @param - globalSubscriberId
56  * @param - subscriptionServiceType
57  * @param - serviceInstanceId
58  * @param - serviceInstanceName - O
59  * @param - serviceModelInfo
60  * @param - productFamilyId
61  * @param - disableRollback
62  * @param - failExists - TODO
63  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
64  * @param - sdncVersion ("1610")
65  * @param - serviceDecomposition - Decomposition for R1710 
66  * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
67  *
68  * Outputs:
69  * @param - rollbackData (localRB->null)
70  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
71  * @param - WorkflowException
72  * @param - serviceInstanceName - (GET from AAI if null in input)
73  *
74  */
75 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
76
77         String Prefix="DCRESI_"
78         ExceptionUtil exceptionUtil = new ExceptionUtil()
79         JsonUtils jsonUtil = new JsonUtils()
80
81         public void preProcessRequest (Execution execution) {
82                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
83                 String msg = ""
84                 utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
85
86                 try {
87                         String requestId = execution.getVariable("msoRequestId")
88                         execution.setVariable("prefix", Prefix)
89                         
90                         //Inputs
91                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
92                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
93
94                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
95                         String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
96
97                         //requestDetails.requestParameters. for SDNC assignTopology
98                         String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
99
100                         if (isBlank(globalSubscriberId)) {
101                                 msg = "Input globalSubscriberId is null"
102                                 utils.log("DEBUG", msg, isDebugEnabled)
103                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
104                         }
105                         
106                         if (isBlank(subscriptionServiceType)) {
107                                 msg = "Input subscriptionServiceType is null"
108                                 utils.log("DEBUG", msg, isDebugEnabled)
109                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
110                         }
111                         
112                         if (productFamilyId == null) {
113                                 execution.setVariable("productFamilyId", "")
114                         }
115                         
116                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
117                         if (isBlank(sdncCallbackUrl)) {
118                                 msg = "URN_mso_workflow_sdncadapter_callback is null"
119                                 utils.log("DEBUG", msg, isDebugEnabled)
120                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
121                         }
122                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
123                         utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
124
125                         //requestDetails.modelInfo.for AAI PUT servieInstanceData & SDNC assignTopology
126                         String modelInvariantUuid = ""
127                         String modelVersion = ""
128                         String modelUuid = ""
129                         String modelName = ""
130                         String serviceInstanceName = "" 
131                         //Generated in parent.for AAI PUT
132                         String serviceInstanceId = ""
133                         String serviceType = ""
134                         String serviceRole = ""
135                         
136                         //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology
137                         serviceInstanceName = execution.getVariable("serviceInstanceName")
138                         serviceInstanceId = execution.getVariable("serviceInstanceId")
139                         
140                         String serviceModelInfo = execution.getVariable("serviceModelInfo")
141                         if (isBlank(serviceModelInfo)) {
142                                 msg = "Input serviceModelInfo is null"
143                                 utils.log("DEBUG", msg, isDebugEnabled)
144                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
145                         }
146                         modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
147                         modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
148                         modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
149                         modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
150                         //modelCustomizationUuid NA for SI
151         
152                         execution.setVariable("serviceType", serviceType)
153                         execution.setVariable("serviceRole", serviceRole)
154                         
155                         if (serviceInstanceName == null) {
156                                 execution.setVariable("serviceInstanceName", "")
157                                 serviceInstanceName = ""
158                         }
159                         if (isBlank(serviceInstanceId)){
160                                 msg = "Input serviceInstanceId is null"
161                                 utils.log("DEBUG", msg, isDebugEnabled)
162                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
163                         }
164                         
165                         if (modelInvariantUuid == null) {
166                                 modelInvariantUuid = ""
167                         }
168                         if (modelUuid == null) {
169                                 modelUuid = ""
170                         }
171                         if (modelVersion == null) {
172                                 modelVersion = ""
173                         }
174                         if (modelName == null) {
175                                 modelName = ""
176                         }
177                         
178                         execution.setVariable("modelInvariantUuid", modelInvariantUuid)
179                         execution.setVariable("modelVersion", modelVersion)
180                         execution.setVariable("modelUuid", modelUuid)
181                         execution.setVariable("modelName", modelName)
182                         
183                         StringBuilder sbParams = new StringBuilder()
184                         Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
185                         if (paramsMap != null)
186                         {
187                                 sbParams.append("<service-input-parameters>")
188                                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
189                                         String paramsXml
190                                         String paramName = entry.getKey()
191                                         String paramValue = entry.getValue()
192                                         paramsXml =
193                                                         """     <param>
194                                                         <name>${paramName}</name>
195                                                         <value>${paramValue}</value>
196                                                         </param>
197                                                         """
198                                         sbParams.append(paramsXml)
199                                 }
200                                 sbParams.append("</service-input-parameters>")
201                         }
202                         String siParamsXml = sbParams.toString()
203                         if (siParamsXml == null)
204                                 siParamsXml = ""
205                         execution.setVariable("siParamsXml", siParamsXml)
206
207                         //AAI PUT
208                         String oStatus = execution.getVariable("initialStatus") ?: ""
209                         if ("TRANSPORT".equalsIgnoreCase(serviceType))
210                         {
211                                 oStatus = "Created"
212                         }
213
214                         String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${oStatus}</orchestration-status>"
215                                 
216                         AaiUtil aaiUriUtil = new AaiUtil(this)
217                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
218                         String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
219                         String serviceInstanceData =
220                                         """<service-instance xmlns=\"${namespace}\">
221                                         <service-instance-name>${serviceInstanceName}</service-instance-name>
222                                         <service-type>${serviceType}</service-type>
223                                         <service-role>${serviceRole}</service-role>
224                                         ${statusLine}
225                                     <model-invariant-id>${modelInvariantUuid}</model-invariant-id>
226                                     <model-version-id>${modelUuid}</model-version-id>
227                                         </service-instance>""".trim()
228
229                         execution.setVariable("serviceInstanceData", serviceInstanceData)
230                         utils.logAudit(serviceInstanceData)
231                         utils.log("DEBUG", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
232
233                 } catch (BpmnError e) {
234                         throw e;
235                 } catch (Exception ex){
236                         msg = "Exception in preProcessRequest " + ex.getMessage()
237                         utils.log("DEBUG", msg, isDebugEnabled)
238                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
239                 }
240                 utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
241         }
242
243         //TODO: Will be able to replace with call to CustomE2EGetService as per the GenericGetService
244         public void getAAICustomerById (Execution execution) {
245                 // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId}
246                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
247                 String msg = ""
248                 try {
249
250                         String globalCustomerId = execution.getVariable("globalSubscriberId") //UUI to AAI name map
251                         utils.log("DEBUG"," ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId, isDebugEnabled)
252
253                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
254                         AaiUtil aaiUriUtil = new AaiUtil(this)
255                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
256                         if (isBlank(aai_endpoint) || isBlank(aai_uri))
257                         {
258                                 msg = "AAI URL is invalid. Endpoint:" + aai_endpoint + aai_uri
259                                 utils.log("DEBUG", msg, isDebugEnabled)
260                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
261                         }
262                         String getAAICustomerUrl = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8")
263
264                         utils.logAudit(getAAICustomerUrl)
265                         utils.log("DEBUG", "getAAICustomerById Url:" + getAAICustomerUrl, isDebugEnabled)
266                         APIResponse response = aaiUriUtil.executeAAIGetCall(execution, getAAICustomerUrl)
267                         String returnCode = response.getStatusCode()
268                         String aaiResponseAsString = response.getResponseBodyAsString()
269
270                         msg = "getAAICustomerById ResponseCode:" + returnCode + " ResponseString:" + aaiResponseAsString
271                         utils.log("DEBUG",msg, isDebugEnabled)
272                         utils.logAudit(msg)
273
274                         if (returnCode=='200') {
275                                 // Customer found by ID. FLow to proceed.
276                                 utils.log("DEBUG",msg, isDebugEnabled)
277
278                                 //TODO Deferred
279                                 //we might verify that service-subscription with matching name exists
280                                 //and throw error if not. If not checked, we will get exception in subsequent step on Create call
281                                 //in 1610 we assume both customer & service subscription were pre-created
282
283                         } else {
284                                 if (returnCode=='404') {
285                                         msg = "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI"
286                                         utils.log("DEBUG", msg, isDebugEnabled)
287                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
288
289                                 } else {
290                                         if (aaiResponseAsString.contains("RESTFault")) {
291                                                 utils.log("ERROR", aaiResponseAsString)
292                                                 WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
293                                                 execution.setVariable("WorkflowException", workflowException)
294                                                 throw new BpmnError("MSOWorkflowException")
295
296                                         } else {
297                                                 // aai all errors
298                                                 msg = "Error in getAAICustomerById ResponseCode:" + returnCode
299                                                 utils.log("DEBUG", msg, isDebugEnabled)
300                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
301                                         }
302                                 }
303                         }
304
305                 } catch (BpmnError e) {
306                         throw e;
307                 } catch (Exception ex) {
308                         msg = "Exception in getAAICustomerById. " + ex.getMessage()
309                         utils.log("DEBUG", msg, isDebugEnabled)
310                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
311                 }
312                 utils.log("DEBUG"," *****Exit getAAICustomerById *****", isDebugEnabled)
313
314         }
315
316         public void postProcessAAIGET(Execution execution) {
317                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
318                 utils.log("DEBUG"," ***** postProcessAAIGET ***** ", isDebugEnabled)
319                 String msg = ""
320
321                 try {
322                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
323                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
324                         if(succInAAI != true){
325                                 utils.log("DEBUG","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)
326                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
327                                 utils.logAudit("workflowException: " + workflowException)
328                                 if(workflowException != null){
329                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
330                                 }
331                                 else
332                                 {
333                                         msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
334                                         utils.log("DEBUG", msg, isDebugEnabled)
335                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
336                                 }
337                         }
338                         else
339                         {
340                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
341                                 if(foundInAAI == true){
342                                         utils.log("DEBUG","Found Service-instance in AAI", isDebugEnabled)
343                                         msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
344                                         utils.log("DEBUG", msg, isDebugEnabled)
345                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
346                                 }
347                         }
348                 } catch (BpmnError e) {
349                         throw e;
350                 } catch (Exception ex) {
351                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
352                         utils.log("DEBUG", msg, isDebugEnabled)
353                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
354                 }
355                 utils.log("DEBUG"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
356         }
357
358         public void postProcessAAIPUT(Execution execution) {
359                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
360                 utils.log("DEBUG"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
361                 String msg = ""
362                 try {
363                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
364                         boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
365                         if(succInAAI != true){
366                                 utils.log("DEBUG","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
367                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
368                                 utils.logAudit("workflowException: " + workflowException)
369                                 if(workflowException != null){
370                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
371                                 }
372                         }
373                         else
374                         {
375                                 //start rollback set up
376                                 RollbackData rollbackData = new RollbackData()
377                                 def disableRollback = execution.getVariable("disableRollback")
378                                 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
379                                 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
380                                 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
381                                 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
382                                 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
383                                 execution.setVariable("rollbackData", rollbackData)
384                         }
385
386                 } catch (BpmnError e) {
387                         throw e;
388                 } catch (Exception ex) {
389                         msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
390                         utils.log("DEBUG", msg, isDebugEnabled)
391                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
392                 }
393                 utils.log("DEBUG"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
394         }
395
396         public void preProcessSDNCAssignRequest(Execution execution) {
397                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
398                 String msg = ""
399                 utils.log("DEBUG"," ***** preProcessSDNCAssignRequest *****", isDebugEnabled)
400
401                 try {
402                         def serviceInstanceId = execution.getVariable("serviceInstanceId")
403                         def serviceInstanceName = execution.getVariable("serviceInstanceName")
404                         def callbackURL = execution.getVariable("sdncCallbackUrl")
405                         def requestId = execution.getVariable("msoRequestId")
406                         def serviceId = execution.getVariable("productFamilyId")
407                         def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
408                         def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
409                         def serviceType = execution.getVariable("serviceType")
410
411                         def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
412                         def modelVersion = execution.getVariable("modelVersion")
413                         def modelUuid = execution.getVariable("modelUuid")
414                         def modelName = execution.getVariable("modelName")
415                         
416                         def sdncRequestId = UUID.randomUUID().toString()
417                         
418                         def siParamsXml = execution.getVariable("siParamsXml")
419                         
420                         String sdncAssignRequest =
421                                         """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
422                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
423                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
424                                    <sdncadapter:RequestHeader>
425                                                         <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
426                                                         <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
427                                                         <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
428                                                         <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
429                                                         <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
430                                                         <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>
431                                         </sdncadapter:RequestHeader>
432                                 <sdncadapterworkflow:SDNCRequestData>
433                                         <request-information>
434                                                 <request-id>${requestId}</request-id>
435                                                 <source>MSO</source>
436                                                 <notification-url/>
437                                                 <order-number/>
438                                                 <order-version/>
439                                                 <request-action>CreateServiceInstance</request-action>
440                                         </request-information>
441                                         <service-information>
442                                                 <service-id>${serviceId}</service-id>
443                                                 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
444                                                 <ecomp-model-information>
445                                                  <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
446                                                  <model-uuid>${modelUuid}</model-uuid>
447                                                  <model-version>${modelVersion}</model-version>
448                                                  <model-name>${modelName}</model-name>
449                                             </ecomp-model-information>
450                                                 <service-instance-id>${serviceInstanceId}</service-instance-id>
451                                                 <subscriber-name/>
452                                                 <global-customer-id>${globalSubscriberId}</global-customer-id>
453                                         </service-information>
454                                         <service-request-input>
455                                                 <service-instance-name>${serviceInstanceName}</service-instance-name>
456                                                 ${siParamsXml}
457                                         </service-request-input>
458                                 </sdncadapterworkflow:SDNCRequestData>
459                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
460
461                         utils.log("DEBUG","sdncAssignRequest:\n" + sdncAssignRequest, isDebugEnabled)
462                         sdncAssignRequest = utils.formatXml(sdncAssignRequest)
463                         execution.setVariable("sdncAssignRequest", sdncAssignRequest)
464                         utils.logAudit("sdncAssignRequest:  " + sdncAssignRequest)
465
466                         def sdncRequestId2 = UUID.randomUUID().toString()
467                         String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
468                         def sdncRequestId3 = UUID.randomUUID().toString()
469                         String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
470                         def rollbackData = execution.getVariable("rollbackData")
471                         rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
472                         rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
473                         execution.setVariable("rollbackData", rollbackData)
474                         
475                         utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled)
476
477                 } catch (BpmnError e) {
478                         throw e;
479                 } catch(Exception ex) {
480                         msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
481                         utils.log("DEBUG", msg, isDebugEnabled)
482                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
483                 }
484                 utils.log("DEBUG"," *****Exit preProcessSDNCAssignRequest *****", isDebugEnabled)
485         }
486         
487         public void postProcessSDNCAssign (Execution execution) {
488                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
489                 utils.log("DEBUG"," ***** postProcessSDNCAssign ***** ", isDebugEnabled)
490                 try {
491                         WorkflowException workflowException = execution.getVariable("WorkflowException")
492                         utils.logAudit("workflowException: " + workflowException)
493
494                         boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
495
496                         String response = execution.getVariable("sdncAdapterResponse")
497                         utils.logAudit("SDNCResponse: " + response)
498
499                         SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
500                         sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
501
502                         if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
503                                 utils.log("DEBUG","Good response from SDNC Adapter for service-instance  topology assign: \n" + response, isDebugEnabled)
504
505                                 def rollbackData = execution.getVariable("rollbackData")
506                                 rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
507                                 execution.setVariable("rollbackData", rollbackData)
508
509                         }else{
510                                 utils.log("DEBUG","Bad Response from SDNC Adapter for service-instance assign", isDebugEnabled)
511                                 throw new BpmnError("MSOWorkflowException")
512                         }
513
514                 } catch (BpmnError e) {
515                         throw e;
516                 } catch(Exception ex) {
517                         msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
518                         utils.log("DEBUG", msg, isDebugEnabled)
519                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
520                 }
521                 utils.log("DEBUG"," *** Exit postProcessSDNCAssign *** ", isDebugEnabled)
522         }
523         
524         public void postProcessAAIGET2(Execution execution) {
525                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
526                 utils.log("DEBUG"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
527                 String msg = ""
528
529                 try {
530                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
531                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
532                         if(succInAAI != true){
533                                 utils.log("DEBUG","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)
534                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
535                                 utils.logAudit("workflowException: " + workflowException)
536                                 if(workflowException != null){
537                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
538                                 }
539                                 else
540                                 {
541                                         msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
542                                         utils.log("DEBUG", msg, isDebugEnabled)
543                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
544                                 }
545                         }
546                         else
547                         {
548                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
549                                 if(foundInAAI == true){
550                                         String aaiService = execution.getVariable("GENGS_service")
551                                         if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
552                                                 execution.setVariable("serviceInstanceName",  utils.getNodeText1(aaiService, "service-instance-name"))
553                                                 utils.log("DEBUG","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
554                                         }
555                                 }
556                         }
557                 } catch (BpmnError e) {
558                         throw e;
559                 } catch (Exception ex) {
560                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
561                         utils.log("DEBUG", msg, isDebugEnabled)
562                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
563                 }
564                 utils.log("DEBUG"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)
565         }
566
567         public void preProcessRollback (Execution execution) {
568                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
569                 utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled)
570                 try {
571                         
572                         Object workflowException = execution.getVariable("WorkflowException");
573
574                         if (workflowException instanceof WorkflowException) {
575                                 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
576                                 execution.setVariable("prevWorkflowException", workflowException);
577                                 //execution.setVariable("WorkflowException", null);
578                         }
579                 } catch (BpmnError e) {
580                         utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
581                 } catch(Exception ex) {
582                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
583                         utils.log("DEBUG", msg, isDebugEnabled)
584                 }
585                 utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled)
586         }
587
588         public void postProcessRollback (Execution execution) {
589                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
590                 utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled)
591                 String msg = ""
592                 try {
593                         Object workflowException = execution.getVariable("prevWorkflowException");
594                         if (workflowException instanceof WorkflowException) {
595                                 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
596                                 execution.setVariable("WorkflowException", workflowException);
597                         }
598                         execution.setVariable("rollbackData", null)
599                 } catch (BpmnError b) {
600                         utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
601                         throw b;
602                 } catch(Exception ex) {
603                         msg = "Exception in postProcessRollback. " + ex.getMessage()
604                         utils.log("DEBUG", msg, isDebugEnabled)
605                 }
606                 utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled)
607         }
608
609 }