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