Add 'not found in AAI' for updateE2E syncresponse
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / UpdateCustomE2EServiceInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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
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 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
28
29 import org.openecomp.mso.bpmn.core.WorkflowException
30 import org.openecomp.mso.bpmn.core.json.JsonUtils
31 import org.openecomp.mso.bpmn.core.domain.Resource
32 import org.openecomp.mso.rest.APIResponse
33
34 import java.util.List;
35 import java.util.UUID;
36
37 import org.camunda.bpm.engine.delegate.BpmnError
38 import org.camunda.bpm.engine.delegate.DelegateExecution
39 import org.json.JSONObject
40 import org.json.JSONArray
41 import org.apache.commons.lang3.*
42 import org.apache.commons.codec.binary.Base64;
43 import org.springframework.web.util.UriUtils
44
45 /**
46  * This groovy class supports the <class>UpdateCustomE2EServiceInstance.bpmn</class> process.
47  * AlaCarte flow for 1702 ServiceInstance Update
48  *
49  */
50 public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
51         String Prefix="UPDSI_"
52         ExceptionUtil exceptionUtil = new ExceptionUtil()
53         JsonUtils jsonUtil = new JsonUtils()
54
55
56         public void preProcessRequest (DelegateExecution execution) {
57                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
58                 execution.setVariable("prefix",Prefix)
59                 String msg = ""
60                 utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)
61
62                 try {
63
64                         String siRequest = execution.getVariable("bpmnRequest")
65                         utils.logAudit(siRequest)
66
67                         String requestId = execution.getVariable("mso-request-id")
68                         execution.setVariable("msoRequestId", requestId)
69                         utils.log("INFO", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
70
71                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
72                         if (isBlank(serviceInstanceId)) {
73                                 msg = "Input serviceInstanceId' is null"
74                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
75                         }
76                                                 
77                         //subscriberInfo for aai
78                         String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
79                         if (isBlank(globalSubscriberId)) {
80                                 msg = "Input globalSubscriberId' is null"
81                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
82                         } else {
83                                 execution.setVariable("globalSubscriberId", globalSubscriberId)
84                         }
85
86                         //requestDetails
87                         execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
88                         execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
89                         execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
90                         String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
91                         if (isBlank(productFamilyId))
92                         {
93                                 msg = "Input productFamilyId is null"
94                                 utils.log("INFO", msg, isDebugEnabled)                          
95                         } else {
96                                 execution.setVariable("productFamilyId", productFamilyId)
97                         }
98                         
99                          //user params
100                  String userParams = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams")      
101              utils.log("INFO", "userParams:" + userParams, isDebugEnabled)
102                  List<String> paramList = jsonUtil.StringArrayToList(execution, userParams)
103                  String uuiRequest = jsonUtil.getJsonValue(paramList.get(0), "UUIRequest")                      
104                         if (isBlank(uuiRequest)) {
105                                 msg = "Input uuiRequest is null"
106                                 utils.log("INFO", msg, isDebugEnabled)
107                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108                         } else
109                         {
110                                 execution.setVariable("uuiRequest", uuiRequest)
111                         }
112
113                         utils.log("INFO", "uuiRequest:\n" + uuiRequest,  isDebugEnabled)
114
115                         //serviceType for aai
116                         String serviceType = jsonUtil.getJsonValue(uuiRequest, "service.serviceType")
117                         if (isBlank(serviceType)) {
118                                 msg = "Input serviceType is null"
119                                 utils.log("INFO", msg, isDebugEnabled)
120                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
121                         } else {
122                                 execution.setVariable("serviceType", serviceType)
123                         }
124                         
125                         // target model info
126                         String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
127                         utils.log("INFO","modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)
128                         execution.setVariable("modelInvariantUuid", modelInvariantUuid)
129                         execution.setVariable("model-invariant-id-target", modelInvariantUuid)
130                         
131                         String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
132                         utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)
133                         execution.setVariable("modelUuid", modelUuid)
134                         execution.setVariable("model-version-id-target", modelUuid)
135                         
136                         String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
137                         utils.log("INFO","serviceModelName: " + serviceModelName, isDebugEnabled)
138                         if(serviceModelName == null) {
139                                 serviceModelName = ""
140                         }
141                         execution.setVariable("serviceModelName", serviceModelName)                     
142                         
143                         //operationId
144                         String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
145                         if (isBlank(operationId)) {
146                                 operationId = UUID.randomUUID().toString()
147                          }   
148                         execution.setVariable("operationId", operationId) 
149                         execution.setVariable("operationType", "update")
150                         execution.setVariable("hasResourcetoUpdate", false)
151                         
152                         execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
153
154                 } catch (BpmnError e) {
155                         throw e;
156                 } catch (Exception ex){
157                         msg = "Exception in preProcessRequest " + ex.getMessage()
158                         utils.log("INFO", msg, isDebugEnabled)
159                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
160                 }
161                 utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)
162         }
163         
164         
165         public void postProcessAAIGET(DelegateExecution execution) {
166                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
167                 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
168                 String msg = ""
169
170                 try {
171                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
172                         boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
173                         String serviceType = ""
174
175                         if(foundInAAI){
176                                 utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)
177
178                                 String siData = execution.getVariable("GENGS_service")
179                                 utils.log("INFO", "SI Data", isDebugEnabled)
180                                 if (isBlank(siData))
181                                 {
182                                         msg = "Could not retrive ServiceInstance data from AAI, Id:" + serviceInstanceId
183                                         utils.log("INFO", msg, isDebugEnabled)
184                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
185                                 }
186
187                                 utils.log("INFO", "SI Data" + siData, isDebugEnabled)
188                                 
189                                 // serviceInstanceName
190                                 String serviceInstanceName = execution.getVariable("serviceInstanceName")
191                                 if(isBlank(serviceInstanceName) && utils.nodeExists(siData, "service-instance-name")) {
192                                         serviceInstanceName =  utils.getNodeText1(siData, "service-instance-name")
193                                         execution.setVariable("serviceInstanceName", serviceInstanceName)
194                                 }
195
196                                 // Get Template uuid and version
197                                 if (utils.nodeExists(siData, "model-invariant-id") && utils.nodeExists(siData, "model-version-id") ) {
198                                         utils.log("INFO", "SI Data model-invariant-id and model-version-id exist:", isDebugEnabled)
199
200                                         def modelInvariantId  = utils.getNodeText1(siData, "model-invariant-id")
201                                         def modelVersionId  = utils.getNodeText1(siData, "model-version-id")
202
203                                         // Set Original Template info
204                                         execution.setVariable("model-invariant-id-original", modelInvariantId)
205                                         execution.setVariable("model-version-id-original", modelVersionId)
206                                 }
207                                 
208                                 //get related service instances (vnf/network or volume) for delete
209                                 if (utils.nodeExists(siData, "relationship-list")) {
210                                         utils.log("INFO", "SI Data relationship-list exists:", isDebugEnabled)
211
212                                         JSONArray jArray = new JSONArray()
213
214                                         XmlParser xmlParser = new XmlParser()
215                                         Node root = xmlParser.parseText(siData)
216                                         def relation_list = utils.getChildNode(root, 'relationship-list')
217                                         def relationships = utils.getIdenticalChildren(relation_list, 'relationship')
218
219                                         for (def relation: relationships) {
220                                                 def jObj = getRelationShipData(relation, isDebugEnabled)
221                                                 jArray.put(jObj)
222                                         }
223
224                                         execution.setVariable("serviceRelationShip", jArray.toString())
225                                 }
226                         }else{
227                                 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
228                                 if(!succInAAI){
229                                         utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled)
230                                         WorkflowException workflowException = execution.getVariable("WorkflowException")
231                                         utils.logAudit("workflowException: " + workflowException)
232                                         if(workflowException != null){
233                                                 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
234                                         }
235                                         else
236                                         {
237                                                 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
238                                                 utils.log("INFO", msg, isDebugEnabled)
239                                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
240                                         }
241                                 }
242
243                                 utils.log("INFO","Service-instance NOT found in AAI. Silent Success", isDebugEnabled)
244                         }
245                 }catch (BpmnError e) {
246                         throw e;
247                 } catch (Exception ex) {
248                         msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()
249                         utils.log("INFO", msg, isDebugEnabled)
250                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
251                 }
252                 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
253         }
254         
255         private JSONObject getRelationShipData(node, isDebugEnabled){
256                 JSONObject jObj = new JSONObject()
257                 
258                 def relation  = utils.nodeToString(node)
259                 def rt  = utils.getNodeText1(relation, "related-to")
260                 
261                 def rl  = utils.getNodeText1(relation, "related-link")
262                 utils.log("INFO", "ServiceInstance Related NS/Configuration :" + rl, isDebugEnabled)
263                 
264                 def rl_datas = utils.getIdenticalChildren(node, "relationship-data")
265                 for(def rl_data : rl_datas) {
266                         def eKey =  utils.getChildNodeText(rl_data, "relationship-key")
267                         def eValue = utils.getChildNodeText(rl_data, "relationship-value")
268
269                         if ((rt == "service-instance" && eKey.equals("service-instance.service-instance-id"))
270                         //for overlay/underlay
271                         || (rt == "configuration" && eKey.equals("configuration.configuration-id"))){
272                                 jObj.put("resourceInstanceId", eValue)
273                         }
274                 }
275
276                 def rl_props = utils.getIdenticalChildren(node, "related-to-property")
277                 for(def rl_prop : rl_props) {
278                         def eKey =  utils.getChildNodeText(rl_prop, "property-key")
279                         def eValue = utils.getChildNodeText(rl_prop, "property-value")
280                         if((rt == "service-instance" && eKey.equals("service-instance.service-instance-name"))
281                         //for overlay/underlay
282                         || (rt == "configuration" && eKey.equals("configuration.configuration-type"))){
283                                 jObj.put("resourceType", eValue)
284                         }
285                 }
286
287                 utils.log("INFO", "Relationship related to Resource:" + jObj.toString(), isDebugEnabled)
288
289                 return jObj
290         }
291         
292         
293         public void preCompareModelVersions(DelegateExecution execution) {
294                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
295         }
296
297         public void postCompareModelVersions(DelegateExecution execution) {             
298                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
299                 utils.log("DEBUG", " ======== STARTED postCompareModelVersions Process ======== ", isDebugEnabled)
300                 
301                 def hasResourcetoUpdate = false
302                 def hasResourcetoAdd = false
303                 def hasResourcetoDelete = false
304                 List<Resource> addResourceList =  execution.getVariable("addResourceList")
305                 List<Resource> delResourceList =  execution.getVariable("delResourceList")
306                 
307                 if(addResourceList != null && !addResourceList.isEmpty()) {
308                         hasResourcetoAdd = true
309                 }
310                                 
311                 if(delResourceList != null && !delResourceList.isEmpty()) {
312                         hasResourcetoDelete = true
313                 }
314                 
315                 hasResourcetoUpdate = hasResourcetoAdd || hasResourcetoDelete
316                 execution.setVariable("hasResourcetoUpdate", hasResourcetoUpdate)
317                 
318                 utils.log("DEBUG", "======== COMPLETED postCompareModelVersions Process ======== ", isDebugEnabled)             
319         }
320         
321         /**
322          * Init the service Operation Status
323          */
324         public void prepareInitServiceOperationStatus(DelegateExecution execution){
325                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
326                 utils.log("DEBUG", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
327                 try{
328                         String serviceId = execution.getVariable("serviceInstanceId")
329                         String operationId = execution.getVariable("operationId")
330                         String operationType = execution.getVariable("operationType")
331                         String userId = ""
332                         String result = "processing"
333                         String progress = "0"
334                         String reason = ""
335                         String operationContent = "Prepare service updating"
336                         utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
337                         serviceId = UriUtils.encode(serviceId,"UTF-8")
338                         execution.setVariable("serviceInstanceId", serviceId)
339                         execution.setVariable("operationId", operationId)
340                         execution.setVariable("operationType", operationType)
341
342                         def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
343                         execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
344                         utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
345
346                         String payload =
347                                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
348                         xmlns:ns="http://org.openecomp.mso/requestsdb">
349                         <soapenv:Header/>
350                         <soapenv:Body>
351                             <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
352                             <serviceId>${serviceId}</serviceId>
353                             <operationId>${operationId}</operationId>
354                             <operationType>${operationType}</operationType>
355                             <userId>${userId}</userId>
356                             <result>${result}</result>
357                             <operationContent>${operationContent}</operationContent>
358                             <progress>${progress}</progress>
359                             <reason>${reason}</reason>
360                         </ns:updateServiceOperationStatus>
361                     </soapenv:Body>
362                 </soapenv:Envelope>"""
363
364                         payload = utils.formatXml(payload)
365                         execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
366                         utils.log("DEBUG", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
367                         utils.logAudit("CreateVfModuleInfra Outgoing updateServiceOperStatusRequest Request: " + payload)
368
369                 }catch(Exception e){
370                         utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
371                         execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
372                 }
373                 utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
374         }
375         
376         /**
377          * Update the service Operation Status
378          */
379         public void preUpdateServiceOperationStatus(DelegateExecution execution){               
380                 def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'
381                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
382                 utils.log("INFO","Entered " + method, isDebugEnabled)
383                 
384                 try{
385                         String serviceId = execution.getVariable("serviceInstanceId")
386                         String operationId = execution.getVariable("operationId")
387                         String operationType = execution.getVariable("operationType")
388                         String serviceName = execution.getVariable("serviceInstanceName")
389                         String result = execution.getVariable("operationResult")                                                
390                         String progress = execution.getVariable("progress")
391                         String reason = execution.getVariable("operationReason")
392                         String userId = ""
393                         utils.log("INFO", "progress: " + progress , isDebugEnabled)
394
395                         String operationContent = "Prepare service : " + execution.getVariable("operationStatus")
396                         
397                         utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
398                         serviceId = UriUtils.encode(serviceId,"UTF-8")
399                         execution.setVariable("serviceInstanceId", serviceId)
400                         execution.setVariable("operationId", operationId)
401                         execution.setVariable("operationType", operationType)
402
403                         def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
404                         execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
405                         utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
406
407                         execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
408                         String payload =
409                                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
410                         xmlns:ns="http://org.openecomp.mso/requestsdb">
411                         <soapenv:Header/>
412                         <soapenv:Body>
413                             <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
414                             <serviceId>${serviceId}</serviceId>
415                             <operationId>${operationId}</operationId>
416                             <serviceName>${serviceName}</serviceName>
417                             <operationType>${operationType}</operationType>
418                             <userId>${userId}</userId>
419                             <result>${result}</result>
420                             <operationContent>${operationContent}</operationContent>
421                             <progress>${progress}</progress>
422                             <reason>${reason}</reason>
423                         </ns:updateServiceOperationStatus>
424                     </soapenv:Body>
425                 </soapenv:Envelope>"""
426
427                         payload = utils.formatXml(payload)
428                         execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
429                         utils.log("INFO", "Outgoing preUpdateServiceOperationStatus: \n" + payload, isDebugEnabled)
430                    
431
432                 }catch(Exception e){
433                         utils.log("ERROR", "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
434                         execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())
435                 }
436                 utils.log("INFO", "======== COMPLETED preUpdateServiceOperationStatus Process ======== ", isDebugEnabled)
437                 utils.log("INFO", "Exited " + method, isDebugEnabled)
438         }               
439
440         public void sendSyncResponse (DelegateExecution execution) {
441                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
442                 utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
443
444                 try {
445                         String operationId = execution.getVariable("operationId")
446                         def hasResourcetoUpdate = execution.getVariable("hasResourcetoUpdate")
447                         
448                         String updateServiceResp = ""
449                         if(hasResourcetoUpdate) {
450                                 // RESTResponse for API Handler (APIH) Reply Task
451                                 updateServiceResp = """{"operationId":"${operationId}"}""".trim()
452                         }
453                         else {
454                                 updateServiceResp =  """{"OperationResult":"No Resource to Add or Delete or Service Instance not found in AAI."}"""
455                         }
456                         
457                         utils.log("INFO", " sendSyncResponse to APIH:" + "\n" + updateServiceResp, isDebugEnabled)
458                         sendWorkflowResponse(execution, 202, updateServiceResp)
459                         execution.setVariable("sentSyncResponse", true)
460
461                 } catch (Exception ex) {
462                         String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
463                         utils.log("INFO", msg, isDebugEnabled)
464                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
465                 }
466                 utils.log("INFO"," ***** Exit sendSyncResopnse *****",  isDebugEnabled)
467         }
468
469         public void sendSyncError (DelegateExecution execution) {
470                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
471                 utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
472
473                 try {
474                         String errorMessage = ""
475                         int errorCode = 7000
476                         if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
477                                 WorkflowException wfe = execution.getVariable("WorkflowException")
478                                 errorMessage = wfe.getErrorMessage()
479                                 errorCode = wfe.getErrorCode()
480                         } else {
481                                 errorMessage = "Sending Sync Error."
482                         }
483
484                         String buildworkflowException =
485                                         """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
486                                         <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
487                                         <aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>
488                                    </aetgt:WorkflowException>"""
489
490                         utils.logAudit(buildworkflowException)
491                         sendWorkflowResponse(execution, 500, buildworkflowException)
492
493                 } catch (Exception ex) {
494                         utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
495                 }
496
497         }
498
499         public void prepareCompletionRequest (DelegateExecution execution) {
500                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
501                 utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
502
503                 try {
504                         String requestId = execution.getVariable("msoRequestId")
505                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
506                         String source = execution.getVariable("source")
507                         
508                         String msoCompletionRequest =
509                                         """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
510                                                                 xmlns:ns="http://org.openecomp/mso/request/types/v1">\r
511                                                 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
512                                                         <request-id>${requestId}</request-id>
513                                                         <action>UPDATE</action>
514                                                         <source>${source}</source>
515                                                 </request-info>
516                                                 <status-message>Service Instance was updated successfully.</status-message>
517                                                 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
518                                                 <mso-bpel-name>UpdateCustomE2EServiceInstance</mso-bpel-name>
519                                         </aetgt:MsoCompletionRequest>"""
520
521                         // Format Response
522                         String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
523
524                         execution.setVariable("completionRequest", xmlMsoCompletionRequest)
525                         utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
526
527                 } catch (Exception ex) {
528                         String msg = " Exception in prepareCompletion:" + ex.getMessage()
529                         utils.log("INFO", msg, isDebugEnabled)
530                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
531                 }
532                 utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
533         }
534
535         public void prepareFalloutRequest(DelegateExecution execution){
536                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
537                 utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
538
539                 try {
540                         WorkflowException wfex = execution.getVariable("WorkflowException")
541                         utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
542                         String requestId = execution.getVariable("msoRequestId")
543                         String source = execution.getVariable("source")
544                         String requestInfo =
545                                         """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
546                                         <request-id>${requestId}</request-id>
547                                         <action>UPDATE</action>
548                                         <source>${source}</source>
549                                    </request-info>"""
550
551                         String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
552                         execution.setVariable("falloutRequest", falloutRequest)
553                 } catch (Exception ex) {
554                         utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
555                         String errorException = "  Bpmn error encountered in UpdateCustomE2EServiceInstance flow. FalloutHandlerRequest,  buildErrorResponse() - " + ex.getMessage()
556                         String requestId = execution.getVariable("msoRequestId")
557                         String falloutRequest =
558                                         """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
559                                                                      xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
560                                                                      xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">\r
561                                            <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
562                                               <request-id>${requestId}</request-id>
563                                               <action>UPDATE</action>
564                                               <source>UUI</source>
565                                            </request-info>
566                                                 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
567                                                         <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
568                                                         <aetgt:ErrorCode>7000</aetgt:ErrorCode>
569                                                 </aetgt:WorkflowException>
570                                         </aetgt:FalloutHandlerRequest>"""
571
572                         execution.setVariable("falloutRequest", falloutRequest)
573                 }
574                 utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
575         }       
576 }