Merge "version upgrades plus cleanup"
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateE2EServiceInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License")
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23 package org.onap.so.bpmn.infrastructure.scripts
24
25 import static org.apache.commons.lang3.StringUtils.*
26 import javax.ws.rs.NotFoundException
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.aai.domain.yang.Relationship
30 import org.onap.aai.domain.yang.ServiceInstance
31 import org.onap.aaiclient.client.aai.AAIObjectType
32 import org.onap.aaiclient.client.aai.AAIResourcesClient
33 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
34 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
35 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
36 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
37 import org.onap.logging.filter.base.ErrorCode
38 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
39 import org.onap.so.bpmn.common.scripts.ExceptionUtil
40 import org.onap.so.bpmn.common.scripts.MsoUtils
41 import org.onap.so.bpmn.core.RollbackData
42 import org.onap.so.bpmn.core.UrnPropertiesReader
43 import org.onap.so.bpmn.core.WorkflowException
44 import org.onap.so.bpmn.core.domain.Resource
45 import org.onap.so.bpmn.core.domain.ServiceDecomposition
46 import org.onap.so.bpmn.core.json.JsonUtils
47 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
48 import org.onap.so.logger.LoggingAnchor
49 import org.onap.so.logger.MessageEnum
50 import org.slf4j.Logger
51 import org.slf4j.LoggerFactory
52 import org.springframework.web.util.UriUtils
53 import com.fasterxml.jackson.databind.ObjectMapper
54 import com.fasterxml.jackson.databind.SerializationFeature
55
56 /**
57  * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
58  *
59  * Inputs:
60  * @param - msoRequestId
61  * @param - globalSubscriberId
62  * @param - subscriptionServiceType
63  * @param - serviceInstanceId
64  * @param - serviceInstanceName - O
65  * @param - serviceModelInfo
66  * @param - productFamilyId
67  * @param - disableRollback
68  * @param - failExists - TODO
69  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
70  * @param - sdncVersion ("1610")
71  * @param - serviceDecomposition - Decomposition for R1710
72  * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
73  *
74  * Outputs:
75  * @param - rollbackData (localRB->null)
76  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
77  * @param - WorkflowException
78  * @param - serviceInstanceName - (GET from AAI if null in input)
79  *
80  */
81 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
82     private static final Logger logger = LoggerFactory.getLogger( DoCreateE2EServiceInstance.class)
83
84
85         String Prefix="DCRESI_"
86         ExceptionUtil exceptionUtil = new ExceptionUtil()
87         JsonUtils jsonUtil = new JsonUtils()
88
89         public void preProcessRequest (DelegateExecution execution) {
90                 String msg = ""
91                 logger.trace("preProcessRequest ")
92
93                 try {
94                         execution.setVariable("prefix", Prefix)
95                         //Inputs
96                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
97                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
98                         logger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
99                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
100                         String serviceType = execution.getVariable("serviceType")
101                         logger.info(" ***** serviceType *****" + serviceType)
102                         //requestDetails.requestParameters. for SDNC assignTopology
103                         String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
104
105                         if (isBlank(globalSubscriberId)) {
106                                 msg = "Input globalSubscriberId is null"
107                                 logger.info(msg)
108                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
109                         }
110
111                         if (isBlank(serviceType)) {
112                                 msg = "Input serviceType is null"
113                                 logger.info(msg)
114                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
115                         }
116
117                         if (productFamilyId == null) {
118                                 execution.setVariable("productFamilyId", "")
119                         }
120
121                         String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback", execution)
122                         if (isBlank(sdncCallbackUrl)) {
123                                 msg = "URN_mso_workflow_sdncadapter_callback is null"
124                                 logger.info(msg)
125                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
126                         }
127                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
128                         logger.info("SDNC Callback URL: " + sdncCallbackUrl)
129
130                         //requestDetails.modelInfo.for AAI PUT servieInstanceData
131                         //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
132                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
133                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
134                         String uuiRequest = execution.getVariable("uuiRequest")
135                         String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
136                         String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
137                         String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
138                         execution.setVariable("serviceModelName", serviceModelName)
139                         //aai serviceType and Role can be setted as fixed value now.
140                         String aaiServiceType = "E2E Service"
141                         String aaiServiceRole = "E2E Service"
142
143                         execution.setVariable("modelInvariantUuid", modelInvariantUuid)
144                         execution.setVariable("modelUuid", modelUuid)
145
146                         //AAI PUT
147                         String oStatus = execution.getVariable("initialStatus") ?: ""
148                         if ("TRANSPORT".equalsIgnoreCase(serviceType))
149                         {
150                                 oStatus = "Created"
151                         }
152
153                         org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
154                         si.setServiceInstanceName(serviceInstanceName)
155                         si.setServiceType(aaiServiceType)
156                         si.setServiceRole(aaiServiceRole)
157                         si.setOrchestrationStatus(oStatus)
158                         si.setModelInvariantId(modelInvariantUuid)
159                         si.setModelVersionId(modelUuid)
160                         si.setInputParameters(uuiRequest)
161                         execution.setVariable("serviceInstanceData", si)
162
163                 } catch (BpmnError e) {
164                         throw e
165                 } catch (Exception ex){
166                         msg = "Exception in preProcessRequest " + ex.getMessage()
167                         logger.info(msg)
168                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
169                 }
170                 logger.trace("Exit preProcessRequest ")
171         }
172
173    public void prepareDecomposeService(DelegateExecution execution) {
174         try {
175             logger.trace("Inside prepareDecomposeService of create generic e2e service ")
176             String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
177             String modelUuid = execution.getVariable("modelUuid")
178             //here modelVersion is not set, we use modelUuid to decompose the service.
179             String serviceModelInfo = """{
180             "modelInvariantUuid":"${modelInvariantUuid}",
181             "modelUuid":"${modelUuid}",
182             "modelVersion":""
183              }"""
184             execution.setVariable("serviceModelInfo", serviceModelInfo)
185
186             logger.trace("Completed prepareDecomposeService of  create generic e2e service ")
187         } catch (Exception ex) {
188             // try error in method block
189             String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
190             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
191         }
192      }
193
194     public void processDecomposition(DelegateExecution execution) {
195         logger.trace("Inside processDecomposition() of  create generic e2e service flow ")
196         try {
197             ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
198         } catch (Exception ex) {
199             String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. processDecomposition() - " + ex.getMessage()
200             logger.debug(exceptionMessage)
201             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
202         }
203     }
204
205     public void doServicePreOperation(DelegateExecution execution){
206        //we need a service plugin platform here.
207         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
208         String uuiRequest = execution.getVariable("uuiRequest")
209         String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest)
210         execution.setVariable("uuiRequest", newUuiRequest)
211     }
212
213     public void doServiceHoming(DelegateExecution execution) {
214         //we need a service plugin platform here.
215         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
216         String uuiRequest = execution.getVariable("uuiRequest")
217         String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest)
218         execution.setVariable("uuiRequest", newUuiRequest)
219     }
220
221         public void postProcessAAIGET(DelegateExecution execution) {
222                 logger.trace("postProcessAAIGET ")
223                 String msg = ""
224
225                 try {
226                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
227                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
228                         if(!succInAAI){
229                                 logger.info("Error getting Service-instance from AAI", + serviceInstanceName)
230                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
231                                 logger.debug("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                                         logger.info(msg)
239                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
240                                 }
241                         }
242                         else
243                         {
244                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
245                                 if(foundInAAI){
246                                         logger.info("Found Service-instance in AAI")
247                                         msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
248                                         logger.info(msg)
249                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
250                                 }
251                         }
252                 } catch (BpmnError e) {
253                         throw e
254                 } catch (Exception ex) {
255                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
256                         logger.info(msg)
257                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
258                 }
259                 logger.trace("Exit postProcessAAIGET ")
260         }
261
262         //TODO use create if not exist
263         public void createServiceInstance(DelegateExecution execution) {
264                 logger.trace("createServiceInstance ")
265                 String msg = ""
266                 String serviceInstanceId = execution.getVariable("serviceInstanceId")
267                 try {
268                         org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
269
270                         AAIResourcesClient client = new AAIResourcesClient()
271                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("serviceType")).serviceInstance(serviceInstanceId))
272                         client.create(uri, si)
273
274                 } catch (BpmnError e) {
275                         throw e
276                 } catch (Exception ex) {
277                         //start rollback set up
278                         RollbackData rollbackData = new RollbackData()
279                         def disableRollback = execution.getVariable("disableRollback")
280                         rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
281                         rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
282                         rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
283                         rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
284                         rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
285                         execution.setVariable("rollbackData", rollbackData)
286
287                         msg = "Exception in DoCreateServiceInstance.createServiceInstance. " + ex.getMessage()
288                         logger.info(msg)
289                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
290                 }
291                 logger.trace("Exit createServiceInstance ")
292         }
293
294         public void createCustomRelationship(DelegateExecution execution) {
295                 logger.trace("createCustomRelationship ")
296                 String msg = ""
297                 try {
298                         String uuiRequest = execution.getVariable("uuiRequest")
299                         String  vpnName =  isNeedProcessCustomRelationship(uuiRequest)
300
301                         if(null != vpnName){
302                                 logger.debug("fetching resource-link information for the given sotnVpnName:"+vpnName)
303                                 // fetch the service instance to link the relationship
304                                 AAIResourcesClient client = new AAIResourcesClient()
305                                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.NODES_QUERY).queryParam("search-node-type","service-instance").queryParam("filter","service-instance-name:EQUALS:"+vpnName)
306                                 AAIResultWrapper aaiResult = client.get(uri,NotFoundException.class)
307                                 Map<String, Object> result = aaiResult.asMap()
308                                 List<Object> resources =
309                                                 (List<Object>) result.getOrDefault("result-data", Collections.emptyList())
310                                 if(resources.size()>0) {
311                                         String relationshipUrl = ((Map<String, Object>) resources.get(0)).get("resource-link")
312
313                                         final Relationship body = new Relationship()
314                                         body.setRelatedLink(relationshipUrl)
315
316                                         createRelationShipInAAI(execution, body)
317                                 } else {
318                                         logger.warn("No resource-link found for the given sotnVpnName:"+vpnName)
319                                 }
320
321                         } else {
322                                 logger.error("VPNName not found in request input")
323                         }
324
325
326
327                 } catch (BpmnError e) {
328                         throw e
329                 } catch (Exception ex) {
330
331                         msg = "Exception in DoCreateE2EServiceInstance.createCustomRelationship. " + ex.getMessage()
332                         logger.info(msg)
333                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
334                 }
335                 logger.trace("Exit createCustomRelationship ")
336         }
337
338         private void createRelationShipInAAI(DelegateExecution execution, final Relationship relationship){
339                 logger.trace("createRelationShipInAAI ")
340                 String msg = ""
341                 try {
342                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
343                         AAIResourcesClient client = new AAIResourcesClient()
344                         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("serviceType")).serviceInstance(serviceInstanceId)).relationshipAPI()
345                         client.create(uri, relationship)
346
347                 } catch (BpmnError e) {
348                         throw e
349                 } catch (Exception ex) {
350
351                         msg = "Exception in DoCreateE2EServiceInstance.createRelationShipInAAI. " + ex.getMessage()
352                         logger.info(msg)
353                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
354                 }
355                 logger.trace("Exit createRelationShipInAAI ")
356
357         }
358
359         private String isNeedProcessCustomRelationship(String uuiRequest) {
360                 String requestInput = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs")
361                 Map<String, String> requestInputObject = getJsonObject(requestInput, Map.class)
362                 if (requestInputObject == null) {
363                         return null
364                 }
365
366                 Optional<Map.Entry> firstKey =
367                 requestInputObject.entrySet()
368                                 .stream()
369                                 .filter({entry -> entry.getKey().toString().contains("_sotnVpnName")})
370                                 .findFirst()
371                 if (firstKey.isPresent()) {
372                         return firstKey.get().getValue()
373                 }
374
375                 return null
376         }
377
378         private static <T> T getJsonObject(String jsonstr, Class<T> type) {
379                 ObjectMapper mapper = new ObjectMapper()
380                 mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true)
381                 try {
382                         return mapper.readValue(jsonstr, type)
383                 } catch (IOException e) {
384                         logger.error("{} {} fail to unMarshal json", MessageEnum.RA_NS_EXC.toString(),
385                                         ErrorCode.BusinessProcessError.getValue(), e)
386                 }
387                 return null
388         }
389
390
391         /**
392          * Gets the service instance and its relationships from aai
393          */
394         public void getServiceInstance(DelegateExecution execution) {
395                 try {
396                         String serviceInstanceId = execution.getVariable('serviceInstanceId')
397                         String globalSubscriberId = execution.getVariable('globalSubscriberId')
398                         String serviceType = execution.getVariable('subscriptionServiceType')
399
400                         AAIResourcesClient resourceClient = new AAIResourcesClient()
401                         AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId))
402                         AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
403
404                         Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
405                         execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
406
407                 }catch(BpmnError e) {
408                         throw e
409                 }catch(Exception ex) {
410                         String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
411                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
412                 }
413         }
414
415         public void postProcessAAIGET2(DelegateExecution execution) {
416                 logger.trace("postProcessAAIGET2 ")
417                 String msg = ""
418
419                 try {
420                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
421                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
422                         if(!succInAAI){
423                                 logger.info("Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName)
424                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
425                                 logger.debug("workflowException: " + workflowException)
426                                 if(workflowException != null){
427                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
428                                 }
429                                 else
430                                 {
431                                         msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
432                                         logger.info(msg)
433                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
434                                 }
435                         }
436                         else
437                         {
438                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
439                                 if(foundInAAI){
440                                         String aaiService = execution.getVariable("GENGS_service")
441                                         if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
442                                                 execution.setVariable("serviceInstanceName",  utils.getNodeText(aaiService, "service-instance-name"))
443                                                 logger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
444                                         }
445                                 }
446                         }
447                 } catch (BpmnError e) {
448                         throw e
449                 } catch (Exception ex) {
450                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
451                         logger.info(msg)
452                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
453                 }
454                 logger.trace("Exit postProcessAAIGET2 ")
455         }
456
457         public void preProcessRollback (DelegateExecution execution) {
458                 logger.trace("preProcessRollback ")
459                 try {
460
461                         Object workflowException = execution.getVariable("WorkflowException")
462
463                         if (workflowException instanceof WorkflowException) {
464                                 logger.info("Prev workflowException: " + workflowException.getErrorMessage())
465                                 execution.setVariable("prevWorkflowException", workflowException)
466                                 //execution.setVariable("WorkflowException", null)
467                         }
468                 } catch (BpmnError e) {
469                         logger.info("BPMN Error during preProcessRollback")
470                 } catch(Exception ex) {
471                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
472                         logger.info(msg)
473                 }
474                 logger.trace("Exit preProcessRollback ")
475         }
476
477         public void postProcessRollback (DelegateExecution execution) {
478                 logger.trace("postProcessRollback ")
479                 String msg = ""
480                 try {
481                         Object workflowException = execution.getVariable("prevWorkflowException")
482                         if (workflowException instanceof WorkflowException) {
483                                 logger.info("Setting prevException to WorkflowException: ")
484                                 execution.setVariable("WorkflowException", workflowException)
485                         }
486                         execution.setVariable("rollbackData", null)
487                 } catch (BpmnError b) {
488                         logger.info("BPMN Error during postProcessRollback")
489                         throw b
490                 } catch(Exception ex) {
491                         msg = "Exception in postProcessRollback. " + ex.getMessage()
492                         logger.info(msg)
493                 }
494                 logger.trace("Exit postProcessRollback ")
495         }
496
497         public void preInitResourcesOperStatus(DelegateExecution execution){
498         logger.trace("STARTED preInitResourcesOperStatus Process ")
499         try{
500             String serviceId = execution.getVariable("serviceInstanceId")
501             String operationId = execution.getVariable("operationId")
502             String operationType = execution.getVariable("operationType")
503             String resourceTemplateUUIDs = ""
504             String result = "processing"
505             String progress = "0"
506             String reason = ""
507             String operationContent = "Prepare service creation"
508             logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
509             serviceId = UriUtils.encode(serviceId,"UTF-8")
510             execution.setVariable("serviceInstanceId", serviceId)
511             execution.setVariable("operationId", operationId)
512             execution.setVariable("operationType", operationType)
513             ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
514             List<Resource>  resourceList = serviceDecomposition.getServiceResources()
515
516             for(Resource resource : resourceList){
517                     resourceTemplateUUIDs  = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"
518             }
519
520             def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.db.endpoint")
521             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
522             logger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
523
524             String payload =
525                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
526                         xmlns:ns="http://org.onap.so/requestsdb">
527                         <soapenv:Header/>
528                         <soapenv:Body>
529                             <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
530                                                                 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
531                                                                 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
532                                                                 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
533                                                                 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
534                             </ns:initResourceOperationStatus>
535                         </soapenv:Body>
536                         </soapenv:Envelope>"""
537
538             payload = utils.formatXml(payload)
539             execution.setVariable("CVFMI_initResOperStatusRequest", payload)
540             logger.info("Outgoing initResourceOperationStatus: \n" + payload)
541             logger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
542
543         }catch(Exception e){
544             logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
545                                         "Exception Occured Processing preInitResourcesOperStatus.", "BPMN",
546                                         ErrorCode.UnknownError.getValue(), e)
547             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
548         }
549         logger.trace("COMPLETED preInitResourcesOperStatus Process ")
550         }
551
552         // if site location is in local Operator, create all resources in local ONAP
553         // if site location is in 3rd Operator, only process sp-partner to create all resources in 3rd ONAP
554         public void doProcessSiteLocation(DelegateExecution execution){
555                 logger.trace("======== Start doProcessSiteLocation Process ======== ")
556                 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
557                 String uuiRequest = execution.getVariable("uuiRequest")
558                 uuiRequest = ServicePluginFactory.getInstance().doProcessSiteLocation(serviceDecomposition, uuiRequest)
559                 execution.setVariable("uuiRequest", uuiRequest)
560                 execution.setVariable("serviceDecomposition", serviceDecomposition)
561
562                 logger.trace("======== COMPLETED doProcessSiteLocation Process ======== ")
563         }
564
565         // Allocate cross link TPs(terminal points) for sotn network only
566         public void doTPResourcesAllocation(DelegateExecution execution){
567                 logger.trace("======== Start doTPResourcesAllocation Process ======== ")
568                 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
569                 String uuiRequest = execution.getVariable("uuiRequest")
570                 uuiRequest = ServicePluginFactory.getInstance().doTPResourcesAllocation(execution, uuiRequest)
571                 execution.setVariable("uuiRequest", uuiRequest)
572                 logger.trace("======== COMPLETED doTPResourcesAllocation Process ======== ")
573         }
574
575         // prepare input param for using DoCreateResources.bpmn
576         public void preProcessForAddResource(DelegateExecution execution) {
577                 logger.trace("STARTED preProcessForAddResource Process ")
578
579                 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
580                 List<Resource> addResourceList = serviceDecomposition.getServiceResources()
581                 execution.setVariable("addResourceList", addResourceList)
582
583                 boolean isCreateResourceListValid = true
584                 if (addResourceList == null || addResourceList.isEmpty()) {
585                         isCreateResourceListValid = false
586                 }
587
588                 execution.setVariable("isCreateResourceListValid", isCreateResourceListValid)
589
590                 logger.trace("COMPLETED preProcessForAddResource Process ")
591         }
592
593         public void postProcessForAddResource(DelegateExecution execution) {
594                 // do nothing now
595
596         }
597
598 }