New GroupLevel DeleteE2EServiceInstance flow
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoDeleteE2EServiceInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22 package org.onap.so.bpmn.infrastructure.scripts
23
24
25 import groovy.json.JsonOutput
26 import groovy.json.JsonSlurper
27 import org.apache.commons.lang3.StringUtils
28 import org.apache.commons.lang3.tuple.ImmutablePair
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.json.JSONArray
32 import org.json.JSONObject
33 import org.onap.aai.domain.yang.RelatedToProperty
34 import org.onap.aai.domain.yang.Relationship
35 import org.onap.aai.domain.yang.RelationshipData
36 import org.onap.aai.domain.yang.ServiceInstance
37 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
38 import org.onap.so.bpmn.common.scripts.ExceptionUtil
39 import org.onap.so.bpmn.common.scripts.MsoUtils
40 import org.onap.so.bpmn.core.UrnPropertiesReader
41 import org.onap.so.bpmn.core.domain.GroupResource
42 import org.onap.so.bpmn.core.domain.Resource
43 import org.onap.so.bpmn.core.domain.ResourceType
44 import org.onap.so.bpmn.core.domain.ServiceDecomposition
45 import org.onap.so.bpmn.core.domain.VnfResource
46 import org.onap.so.bpmn.core.domain.VnfcResource
47 import org.onap.so.bpmn.core.json.JsonUtils
48 import org.onap.so.client.HttpClient
49 import org.onap.so.client.HttpClientFactory
50 import org.onap.so.client.aai.AAIObjectType
51 import org.onap.so.client.aai.AAIResourcesClient
52 import org.onap.so.client.aai.entities.AAIResultWrapper
53 import org.onap.so.client.aai.entities.uri.AAIResourceUri
54 import org.onap.so.client.aai.entities.uri.AAIUriFactory
55 import org.slf4j.Logger
56 import org.slf4j.LoggerFactory
57 import org.onap.so.utils.TargetEntity
58 import org.springframework.web.util.UriUtils
59
60 import javax.ws.rs.NotFoundException
61 import javax.ws.rs.core.Response
62
63
64 import static org.apache.commons.lang3.StringUtils.isBlank
65
66 /**
67  * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
68  *
69  * Inputs:
70  * @param - msoRequestId
71  * @param - globalSubscriberId - O
72  * @param - subscriptionServiceType - O
73  * @param - serviceInstanceId
74  * @param - serviceInstanceName - O
75  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
76  * @param - sdncVersion
77  * @param - failNotFound - TODO
78  * @param - serviceInputParams - TODO
79  *
80  * @param - delResourceList
81  * @param - serviceRelationShip
82  *
83  * Outputs:
84  * @param - WorkflowException
85  *
86  * Rollback - Deferred
87  */
88 public class DoDeleteE2EServiceInstance extends AbstractServiceTaskProcessor {
89
90         String Prefix="DDEESI_"
91     ExceptionUtil exceptionUtil = new ExceptionUtil()
92     JsonUtils jsonUtil = new JsonUtils()
93     private static final Logger logger = LoggerFactory.getLogger( DoDeleteE2EServiceInstance.class);
94
95
96     public void preProcessRequest (DelegateExecution execution) {
97         logger.debug(" ***** preProcessRequest *****")
98         String msg = ""
99
100         try {
101             String requestId = execution.getVariable("msoRequestId")
102             execution.setVariable("prefix",Prefix)
103
104             //Inputs
105             //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
106             String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
107             if (globalSubscriberId == null)
108             {
109                 execution.setVariable("globalSubscriberId", "")
110             }
111
112             //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
113             String serviceType = execution.getVariable("serviceType")
114             if (serviceType == null)
115             {
116                 execution.setVariable("serviceType", "")
117             }
118
119             //Generated in parent for AAI PUT
120             String serviceInstanceId = execution.getVariable("serviceInstanceId")
121             if (isBlank(serviceInstanceId)){
122                 msg = "Input serviceInstanceId is null"
123                 logger.info(msg)
124                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
125             }
126
127             String sdncCallbackUrl = UrnPropertiesReader.getVariable('mso.workflow.sdncadapter.callback', execution)
128             if (isBlank(sdncCallbackUrl)) {
129                 msg = "URN_mso_workflow_sdncadapter_callback is null"
130                 logger.info(msg)
131                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
132             }
133             execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
134             logger.info("SDNC Callback URL: " + sdncCallbackUrl)
135
136             StringBuilder sbParams = new StringBuilder()
137             Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
138
139             if (paramsMap != null) {
140                 sbParams.append("<service-input-parameters>")
141                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
142                     String paramsXml
143                     String paramName = entry.getKey()
144                     String paramValue = entry.getValue()
145                     paramsXml =
146                             """ <param>
147                                                         <name>${MsoUtils.xmlEscape(paramName)}</name>
148                                                         <value>${MsoUtils.xmlEscape(paramValue)}</value>
149                                                         </param>
150                                                         """
151                     sbParams.append(paramsXml)
152                 }
153                 sbParams.append("</service-input-parameters>")
154             }
155             String siParamsXml = sbParams.toString()
156             if (siParamsXml == null)
157                 siParamsXml = ""
158             execution.setVariable("siParamsXml", siParamsXml)
159
160         } catch (BpmnError e) {
161             throw e;
162         } catch (Exception ex){
163             msg = "Exception in preProcessRequest " + ex.getMessage()
164             logger.error(msg)
165             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
166         }
167         logger.debug("***** Exit preProcessRequest *****")
168     }
169
170     public void postProcessAAIGET(DelegateExecution execution) {
171         logger.debug(" ***** postProcessAAIGET ***** ")
172         String msg = ""
173
174         try {
175             String serviceInstanceId = execution.getVariable('serviceInstanceId')
176             String globalSubscriberId = execution.getVariable('globalSubscriberId')
177             String serviceType = execution.getVariable('serviceType')
178             AAIResourcesClient resourceClient = new AAIResourcesClient()
179             AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
180             if (!resourceClient.exists(serviceInstanceUri)) {
181                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
182             }
183             AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
184             Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
185             // found in AAI
186             if (si.isPresent() && StringUtils.isNotEmpty(si.get().getServiceInstanceName())) {
187                 logger.debug("Found Service-instance in AAI")
188                 execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
189                 // get model invariant id
190                 // Get Template uuid and version
191                 if ((null != si.get().getModelInvariantId()) && (null != si.get().getModelVersionId())) {
192                     logger.debug("SI Data model-invariant-id and model-version-id exist")
193                     // Set Original Template info
194                     execution.setVariable("model-invariant-id-original", si.get().getModelInvariantId())
195                     execution.setVariable("model-version-id-original", si.get().getModelVersionId())
196                 }
197                 if ((null != si.get().getRelationshipList()) && (null != si.get().getRelationshipList().getRelationship())) {
198                     logger.debug("SI Data relationship-list exists")
199                     List<Relationship> relationshipList = si.get().getRelationshipList().getRelationship()
200                     JSONArray jArray = new JSONArray()
201                     for (Relationship relationship : relationshipList) {
202                         def jObj = getRelationShipData(relationship)
203                         jArray.put(jObj)
204                     }
205                     execution.setVariable("serviceRelationShip", jArray.toString())
206                 }
207             } else {
208                 msg = "Service-instance: " + serviceInstanceId + " NOT found in AAI."
209                 logger.error(msg)
210                 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
211             }
212         } catch (BpmnError e) {
213             throw e
214         } catch (NotFoundException e) {
215             logger.debug("Service Instance does not exist AAI")
216             exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Service Instance was not found in aai")
217         } catch (Exception ex) {
218             msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()
219             logger.debug(msg)
220             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
221         }
222         logger.debug(" *** Exit postProcessAAIGET *** ")
223     }
224
225     private JSONObject getRelationShipData(Relationship relationship) {
226         JSONObject jObj = new JSONObject()
227         def rt = relationship.getRelatedTo()
228         def rl = relationship.getRelatedLink()
229         logger.debug("ServiceInstance Related NS/Configuration :" + rl)
230         List<RelationshipData> rl_datas = relationship.getRelationshipData()
231         for (RelationshipData rl_data : rl_datas) {
232             def eKey = rl_data.getRelationshipKey()
233             def eValue = rl_data.getRelationshipValue()
234             if ((rt.equals("service-instance") && eKey.equals("service-instance.service-instance-id"))
235                     //for overlay/underlay
236                     || (rt.equals("configuration") && eKey.equals("configuration.configuration-id")
237             )) {
238                 jObj.put("resourceInstanceId", eValue)
239             }
240             // for sp-partner and others
241             else if (eKey.endsWith("-id")) {
242                 jObj.put("resourceInstanceId", eValue)
243                 String resourceName = rt + eValue;
244                 jObj.put("resourceType", resourceName)
245             }
246             jObj.put("resourceLinkUrl", rl)
247         }
248         List<RelatedToProperty> rl_props = relationship.getRelatedToProperty()
249         for (RelatedToProperty rl_prop : rl_props) {
250             def eKey = rl_prop.getPropertyKey()
251             def eValue = rl_prop.getPropertyValue()
252             if ((rt.equals("service-instance") && eKey.equals("service-instance.service-instance-name"))
253                     //for overlay/underlay
254                     || (rt.equals("configuration") && eKey.equals("configuration.configuration-type"))) {
255                 jObj.put("resourceType", eValue)
256             }
257         }
258         logger.debug("Relationship related to Resource:" + jObj.toString())
259         return jObj
260     }
261
262     private Relationship getRelationShipFromNode(groovy.util.slurpersupport.Node relationshipNode) {
263         Relationship relationship = new Relationship()
264         def rtn = relationshipNode.childNodes()
265         List<RelationshipData> relationshipDatas = new ArrayList<>()
266         List<RelatedToProperty> relationshipProperties = new ArrayList<>()
267         while (rtn.hasNext()) {
268             groovy.util.slurpersupport.Node node = rtn.next()
269             def key = node.name()
270
271             if(key.equals("related-to")){
272                 def rt = node.text()
273                 relationship.setRelatedTo(rt)
274             } else if (key.equals("related-link")){
275                 def rl = node.text()
276                 relationship.setRelatedLink(rl)
277             } else if (key.equals("relationship-label")){
278                 def label = node.text()
279                 relationship.setRelationshipLabel(label)
280             } else if (key.equals("relationship-data")){
281                 def rData = node.childNodes()
282                 RelationshipData relationshipData = new RelationshipData()
283                 while(rData.hasNext()){
284                     groovy.util.slurpersupport.Node datanode = rData.next()
285                     def dataKey = datanode.name()
286                     if(dataKey.equals("relationship-key")) {
287                         relationshipData.setRelationshipKey(datanode.text())
288                     } else if(dataKey.equals("relationship-value")) {
289                         relationshipData.setRelationshipValue(datanode.text())
290                     }
291                 }
292                 relationshipDatas.add(relationshipData)
293             } else if (key.equals("related-to-property")){
294                 def rProperty = node.childNodes()
295                 RelatedToProperty relationshipProperty = new RelatedToProperty()
296                 while(rProperty.hasNext()){
297                     groovy.util.slurpersupport.Node propnode = rProperty.next()
298
299                     def dataKey = propnode.name()
300                     if(dataKey.equals("property-key")) {
301                         relationshipProperty.setPropertyKey(propnode.text())
302                     } else if(dataKey.equals("property-value")) {
303                         relationshipProperty.setPropertyValue(propnode.text())
304                     }
305
306                 }
307                 relationshipProperties.add(relationshipProperty)
308             }
309
310         }
311         relationship.getRelationshipData().addAll(relationshipDatas)
312         relationship.getRelatedToProperty().addAll(relationshipProperties)
313
314         logger.debug("Relationship related to Resource:" + relationship.toString())
315         return relationship
316     }
317
318    public void getCurrentNS(DelegateExecution execution){
319        logger.info( "======== Start getCurrentNS Process ======== ")
320
321        def currentIndex = execution.getVariable("currentNSIndex")
322        List<String> nsSequence = execution.getVariable("nsSequence")
323        String nsResourceType =  nsSequence.get(currentIndex)
324
325        // GET AAI by Name, not ID, for process convenient
326        execution.setVariable("GENGS_type", "service-instance")
327        execution.setVariable("GENGS_serviceInstanceId", "")
328        execution.setVariable("GENGS_serviceInstanceName", nsResourceType)
329
330        logger.debug("======== COMPLETED getCurrentNS Process ======== ")
331    }
332
333     public void prepareDecomposeService(DelegateExecution execution) {
334         try {
335             logger.debug(" ***** Inside prepareDecomposeService of create generic e2e service ***** ")
336             String modelInvariantUuid = execution.getVariable("model-invariant-id-original")
337             String modelVersionId = execution.getVariable("model-version-id-original")
338
339             String serviceModelInfo = """{
340             "modelInvariantUuid":"${modelInvariantUuid}",
341             "modelUuid":"${modelVersionId}",
342             "modelVersion":""
343              }"""
344             execution.setVariable("serviceModelInfo", serviceModelInfo)
345
346             logger.debug(" ***** Completed prepareDecomposeService of  create generic e2e service ***** ")
347         } catch (Exception ex) {
348             // try error in method block
349             String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
350             logger.error(exceptionMessage)
351             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
352         }
353     }
354
355         private void generateRelatedResourceInfo(String response, JSONObject jObj, boolean processRelationship){
356
357                 def xml = new XmlSlurper().parseText(response)
358                 def rtn = xml.childNodes()
359                 while (rtn.hasNext()) {
360                         groovy.util.slurpersupport.Node node = rtn.next()
361                         def key = node.name()
362             if (key.equals("relationship-list") && processRelationship) {
363                 def relns = node.childNodes()
364                 JSONArray jArray = new JSONArray()
365                 while (relns.hasNext()) {
366                     groovy.util.slurpersupport.Node relNode = relns.next()
367                     Relationship relationship = getRelationShipFromNode(relNode)
368                     def relationObj = getRelationShipData(relationship)
369                     jArray.put(relationObj)
370                 }
371                 jObj.put(key, jArray)
372             } else {
373                 def value = node.text()
374                 jObj.put(key, value)
375             }
376                 }
377         }
378
379         private JSONObject getRelatedResourceInAAI (DelegateExecution execution, JSONObject jObj, boolean processRelationship)
380         {
381                 logger.debug(" ***** Started getRelatedResourceInAAI *****")
382
383         String aai_endpoint = UrnPropertiesReader.getVariable("aai.endpoint", execution)
384                 String urlLink = jObj.get("resourceLinkUrl")
385                 String serviceAaiPath = "${aai_endpoint}${urlLink}"
386
387                 URL url = new URL(serviceAaiPath)
388                 HttpClient client = new HttpClientFactory().newXmlClient(url, TargetEntity.AAI)
389
390
391                 Response response = client.get()
392                 int responseCode = response.getStatus()
393                 execution.setVariable(Prefix + "GeRelatedResourceResponseCode", responseCode)
394                 logger.debug("  Get RelatedResource code is: " + responseCode)
395
396                 String aaiResponse = response.readEntity(String.class)
397                 execution.setVariable(Prefix + "GetRelatedResourceResponse", aaiResponse)
398
399                 //Process Response
400                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
401                         //200 OK 201 CREATED 202 ACCEPTED
402                 {
403                         logger.debug("GET RelatedResource Received a Good Response")
404                         execution.setVariable(Prefix + "SuccessIndicator", true)
405                         execution.setVariable(Prefix + "FoundIndicator", true)
406
407                         generateRelatedResourceInfo(aaiResponse, jObj, processRelationship)
408
409                         //get model-invariant-uuid and model-uuid
410                         String modelInvariantId = ""
411                         String modelUuid = ""
412                         String modelCustomizationId = ""
413                         if(jObj.has("model-invariant-id")) {
414                                 modelInvariantId = jObj.get("model-invariant-id")
415                                 modelUuid = jObj.get("model-version-id")
416                                 modelCustomizationId = jObj.get("model-customization-id")
417                         }
418
419                         jObj.put("modelInvariantId", modelInvariantId)
420                         jObj.put("modelVersionId", modelUuid)
421                         jObj.put("modelCustomizationId", modelCustomizationId)
422                 }
423                 else {
424             String exceptionMessage = "Get RelatedResource Received a Bad Response Code. Response Code is: " + responseCode
425                         logger.error(exceptionMessage)
426             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
427         }
428
429                 logger.debug(" ***** Exit getRelatedResourceInAAI *****")
430                 return jObj
431         }
432
433     public void postDecomposeService(DelegateExecution execution) {
434         logger.debug(" ***** Inside postDecomposeService() of  delete generic e2e service flow ***** ")
435         try {
436             ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
437
438             // service model info
439             execution.setVariable("serviceModelInfo", serviceDecomposition.getModelInfo())
440
441             List<Resource> deleteResourceList = serviceDecomposition.getServiceResources()
442             String serviceRelationShip = execution.getVariable("serviceRelationShip")
443             def jsonSlurper = new JsonSlurper()
444             def jsonOutput = new JsonOutput()
445
446             List relationShipList = null
447             if (serviceRelationShip != null) {
448                 relationShipList = jsonSlurper.parseText(serviceRelationShip)
449             }
450
451             List<ImmutablePair<Resource, List<Resource>>> deleteRealResourceList = new ArrayList<ImmutablePair<Resource, List<Resource>>>()
452
453             //Set the real resource instance id to the decomosed resource list
454             //reset the resource instance id , because in the decompose flow ,its a random one.
455             //match the resource-instance-name and the model name
456             if (relationShipList != null) {
457                 relationShipList.each {
458
459                     JSONObject obj = getRelatedResourceInAAI(execution, (JSONObject)it, true)
460
461                     for (Resource resource : deleteResourceList) {
462
463                         boolean matches = processMatchingResource(resource, obj)
464                         if((matches) && resource.getResourceType().equals(ResourceType.VNF))  {
465                             List<Resource> delGroupList = new ArrayList<Resource>()
466                             JSONArray vfRelationship = obj.getJSONArray("relationship-list")
467                             for (int idx = 0; idx < vfRelationship.length(); idx++) {
468                                 JSONObject vfItem = vfRelationship.getJSONObject(idx)
469                                 JSONObject groupObject = getRelatedResourceInAAI(execution, vfItem, false)
470                                 List<GroupResource> groups = ((VnfResource)resource).getGroups()
471                                 for (GroupResource group : groups){
472                                     if(processMatchingResource(group, groupObject)){
473                                         delGroupList.add(group)
474                                     }
475                                 }
476                             }
477                             def delMap = new ImmutablePair(resource, delGroupList)
478
479                             deleteRealResourceList.add(delMap)
480                         }
481                     }
482                 }
483             }
484
485             // only delete real existing resources
486             execution.setVariable("deleteResourceList", deleteRealResourceList)
487             
488             boolean isDeleteResourceListValid = false
489             if(deleteRealResourceList.size() > 0) {
490                 isDeleteResourceListValid = true
491             }
492             execution.setVariable("isDeleteResourceListValid", isDeleteResourceListValid)
493
494             logger.debug("delete resource list : " + deleteRealResourceList)
495         } catch (Exception ex) {
496             String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. processDecomposition() - " + ex.getMessage()
497             logger.error(exceptionMessage)
498             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
499         }
500         logger.debug(" ***** exit postDecomposeService() of  delete generic e2e service flow ***** ")
501     }
502
503     private boolean processMatchingResource(Resource resource, JSONObject obj) {
504         boolean matches = false
505         String modelName = resource.getModelInfo().getModelName()
506
507         String modelCustomizationUuid = resource.getModelInfo().getModelCustomizationUuid()
508         if (StringUtils.containsIgnoreCase(obj.get("resourceType"), modelName)) {
509             resource.setResourceId(obj.get("resourceInstanceId"))
510             //deleteRealResourceList.add(resource)
511             matches = true;
512         } else if (modelCustomizationUuid.equals(obj.get("modelCustomizationId"))) {
513             resource.setResourceId(obj.get("resourceInstanceId"))
514             resource.setResourceInstanceName(obj.get("resourceType"))
515             //deleteRealResourceList.add(resource)
516             matches = true;
517         }
518         return matches
519     }
520
521     public void preInitResourcesOperStatus(DelegateExecution execution){
522         logger.debug(" ======== STARTED preInitResourcesOperStatus Process ======== ")
523         try{
524             String serviceId = execution.getVariable("serviceInstanceId")
525             String operationId = execution.getVariable("operationId")
526             String operationType = execution.getVariable("operationType")
527             String resourceTemplateUUIDs = ""
528             String result = "processing"
529             String progress = "0"
530             String reason = ""
531             String operationContent = "Prepare service creation"
532             logger.debug("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
533             serviceId = UriUtils.encode(serviceId,"UTF-8")
534             execution.setVariable("serviceInstanceId", serviceId)
535             execution.setVariable("operationId", operationId)
536             execution.setVariable("operationType", operationType)
537             List<ImmutablePair<Resource, List<Resource>>> deleteResourceList = execution.getVariable("deleteResourceList")
538
539             String serviceRelationShip = execution.getVariable("serviceRelationShip")
540             for (ImmutablePair rc : deleteResourceList) {
541                 Resource resource = rc.getKey()
542                 resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
543             }
544
545             def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
546             execution.setVariable("URN_mso_adapters_openecomp_db_endpoint", dbAdapterEndpoint)
547
548             String payload =
549                     """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
550                         xmlns:ns="http://org.onap.so/requestsdb">
551                         <soapenv:Header/>
552                         <soapenv:Body>
553                             <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
554                             <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
555                             <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
556                             <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
557                             <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
558                         </ns:initResourceOperationStatus>
559                     </soapenv:Body>
560                 </soapenv:Envelope>"""
561
562             payload = utils.formatXml(payload)
563             execution.setVariable("CVFMI_initResOperStatusRequest", payload)
564             logger.debug("Outgoing initResourceOperationStatus: \n" + payload)
565             logger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
566
567         }catch(Exception e){
568             logger.debug("Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e)
569             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
570         }
571         logger.debug("======== COMPLETED preInitResourcesOperStatus Process ======== ")
572     }
573     
574     public void prepareUpdateServiceOperationStatus(DelegateExecution execution){
575         logger.debug(" ======== STARTED prepareUpdateServiceOperationStatus Process ======== ")
576         try{
577             String serviceId = execution.getVariable("serviceInstanceId")
578             String operationId = execution.getVariable("operationId")
579             String userId = ""
580             String result = execution.getVariable("result")
581             String progress = execution.getVariable("progress")
582             String reason = ""
583             String operationContent = execution.getVariable("operationContent")
584             
585             serviceId = UriUtils.encode(serviceId,"UTF-8")
586
587             def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
588             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
589             logger.debug("DB Adapter Endpoint is: " + dbAdapterEndpoint)
590
591             String payload =
592                     """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
593                         xmlns:ns="http://org.onap.so/requestsdb">
594                         <soapenv:Header/>
595                         <soapenv:Body>
596                             <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
597                             <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
598                             <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
599                             <operationType>DELETE</operationType>
600                             <userId>${MsoUtils.xmlEscape(userId)}</userId>
601                             <result>${MsoUtils.xmlEscape(result)}</result>
602                             <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
603                             <progress>${MsoUtils.xmlEscape(progress)}</progress>
604                             <reason>${MsoUtils.xmlEscape(reason)}</reason>
605                         </ns:updateServiceOperationStatus>
606                     </soapenv:Body>
607                 </soapenv:Envelope>"""
608
609             payload = utils.formatXml(payload)
610             execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
611             logger.debug("Outgoing updateServiceOperStatusRequest: \n" + payload)
612
613         }catch(Exception e){
614             logger.error("Exception Occured Processing prepareUpdateServiceOperationStatus. Exception is:\n" + e)
615             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareUpdateServiceOperationStatus Method:\n" + e.getMessage())
616         }
617         logger.debug("======== COMPLETED prepareUpdateServiceOperationStatus Process ======== ")
618     }
619
620      /**
621       * post config request.
622       */
623      public void postConfigRequest(execution){
624          //to do
625      }
626
627 }