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