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