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