2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.so.bpmn.vcpe.scripts;
24 import static org.apache.commons.lang3.StringUtils.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.common.scripts.VidUtils
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.core.domain.*
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.logger.MessageEnum
37 import org.onap.so.logger.MsoLogger
38 import org.springframework.web.util.UriUtils
39 import org.slf4j.Logger
40 import org.slf4j.LoggerFactory
47 * This groovy class supports the <class>CreateVcpeResCustService.bpmn</class> process.
52 public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
53 private static final Logger logger = LoggerFactory.getLogger(CreateVcpeResCustService.class);
55 private static final String DebugFlag = "isDebugLogEnabled"
57 String Prefix = "CVRCS_"
58 ExceptionUtil exceptionUtil = new ExceptionUtil()
59 JsonUtils jsonUtil = new JsonUtils()
60 VidUtils vidUtils = new VidUtils()
63 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
66 private InitializeProcessVariables(DelegateExecution execution) {
67 /* Initialize all the process variables in this block */
69 execution.setVariable("createVcpeServiceRequest", "")
70 execution.setVariable("globalSubscriberId", "")
71 execution.setVariable("serviceInstanceName", "")
72 execution.setVariable("msoRequestId", "")
73 execution.setVariable(Prefix + "VnfsCreatedCount", 0)
74 execution.setVariable("productFamilyId", "")
75 execution.setVariable("brgWanMacAddress", "")
76 execution.setVariable("customerLocation", "")
77 execution.setVariable("homingService", "")
78 execution.setVariable("cloudOwner", "")
79 execution.setVariable("cloudRegionId", "")
80 execution.setVariable("homingModelIds", "")
83 execution.setVariable("sdncVersion", "1707")
86 // **************************************************
87 // Pre or Prepare Request Section
88 // **************************************************
90 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
93 public void preProcessRequest(DelegateExecution execution) {
94 def isDebugEnabled = execution.getVariable(DebugFlag)
95 execution.setVariable("prefix", Prefix)
97 logger.trace("Inside preProcessRequest CreateVcpeResCustService Request ")
100 // initialize flow variables
101 InitializeProcessVariables(execution)
104 String aaiDistDelay = UrnPropertiesReader.getVariable("aai.workflowAaiDistributionDelay", execution)
105 if (isBlank(aaiDistDelay)) {
106 String msg = "workflowAaiDistributionDelay is null"
108 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
110 execution.setVariable("aaiDistDelay", aaiDistDelay)
111 logger.debug("AAI distribution delay: " + aaiDistDelay)
113 // check for incoming json message/input
114 String createVcpeServiceRequest = execution.getVariable("bpmnRequest")
115 logger.debug(createVcpeServiceRequest)
116 execution.setVariable("createVcpeServiceRequest", createVcpeServiceRequest);
117 println 'createVcpeServiceRequest - ' + createVcpeServiceRequest
120 String requestId = execution.getVariable("mso-request-id")
121 execution.setVariable("msoRequestId", requestId)
123 String serviceInstanceId = execution.getVariable("serviceInstanceId")
125 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
126 serviceInstanceId = UUID.randomUUID().toString()
127 logger.debug(" Generated new Service Instance: " + serviceInstanceId)
129 logger.debug("Using provided Service Instance ID: " + serviceInstanceId)
132 serviceInstanceId = UriUtils.encode(serviceInstanceId, "UTF-8")
133 execution.setVariable("serviceInstanceId", serviceInstanceId)
134 logger.debug("Incoming serviceInstanceId is: " + serviceInstanceId)
136 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
137 execution.setVariable("serviceInstanceName", serviceInstanceName)
138 logger.debug("Incoming serviceInstanceName is: " + serviceInstanceName)
140 String requestAction = execution.getVariable("requestAction")
141 execution.setVariable("requestAction", requestAction)
143 setBasicDBAuthHeader(execution, isDebugEnabled)
145 String source = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.source")
146 if ((source == null) || (source.isEmpty())) {
149 execution.setVariable("source", source)
151 // extract globalSubscriberId
152 String globalSubscriberId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
154 // verify element global-customer-id is sent from JSON input, throw exception if missing
155 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
156 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
157 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
160 execution.setVariable("globalSubscriberId", globalSubscriberId)
161 execution.setVariable("globalCustomerId", globalSubscriberId)
164 // extract subscriptionServiceType
165 String subscriptionServiceType = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
166 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
167 logger.debug("Incoming subscriptionServiceType is: " + subscriptionServiceType)
169 String suppressRollback = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.suppressRollback")
170 execution.setVariable("disableRollback", suppressRollback)
171 logger.debug("Incoming Suppress/Disable Rollback is: " + suppressRollback)
173 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
174 execution.setVariable("productFamilyId", productFamilyId)
175 logger.debug("Incoming productFamilyId is: " + productFamilyId)
177 String subscriberInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo")
178 execution.setVariable("subscriberInfo", subscriberInfo)
179 logger.debug("Incoming subscriberInfo is: " + subscriberInfo)
181 // extract cloud configuration - if underscore "_" is present treat as vimId else it's a cloudRegion
182 String vimId = jsonUtil.getJsonValue(createVcpeServiceRequest,
183 "requestDetails.cloudConfiguration.lcpCloudRegionId")
184 if (vimId.contains("_") && vimId.split("_").length == 2 ) {
185 def cloudRegion = vimId.split("_")
186 def cloudOwner = cloudRegion[0]
187 def cloudRegionId = cloudRegion[1]
188 execution.setVariable("cloudOwner", cloudOwner)
189 logger.debug("cloudOwner: " + cloudOwner)
190 execution.setVariable("cloudRegionId", cloudRegionId)
191 logger.debug("cloudRegionId: " + cloudRegionId)
193 logger.debug("vimId is not present - setting cloudRegion/cloudOwner from request.")
194 String cloudOwner = jsonUtil.getJsonValue(createVcpeServiceRequest,
195 "requestDetails.cloudConfiguration.cloudOwner")
196 if (!cloudOwner?.empty && cloudOwner != "")
198 execution.setVariable("cloudOwner", cloudOwner)
199 logger.debug("cloudOwner: " + cloudOwner)
201 def cloudRegionId = vimId
202 execution.setVariable("cloudRegionId", cloudRegionId)
203 logger.debug("cloudRegionId: " + cloudRegionId)
206 * Extracting User Parameters from incoming Request and converting into a Map
208 def jsonSlurper = new JsonSlurper()
210 Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest)
213 def userParams = reqMap.requestDetails?.requestParameters?.userParams
215 Map<String, String> inputMap = [:]
219 if ("Customer_Location".equals(userParam?.name)) {
220 Map<String, String> customerMap = [:]
221 userParam.value.each {
223 inputMap.put(param.key, param.value)
224 customerMap.put(param.key, param.value)
226 execution.setVariable("customerLocation", customerMap)
228 if ("Homing_Model_Ids".equals(userParam?.name)) {
229 logger.debug("Homing_Model_Ids: " + userParam.value.toString() + " ---- Type is:" +
230 userParam.value.getClass())
232 userParam.value.each {
237 valueMap.put(entry.key, entry.value)
239 modelIdLst.add(valueMap)
240 logger.debug("Param: " + param.toString() + " ---- Type is:" +
243 execution.setVariable("homingModelIds", modelIdLst)
245 if ("BRG_WAN_MAC_Address".equals(userParam?.name)) {
246 execution.setVariable("brgWanMacAddress", userParam.value)
247 inputMap.put("BRG_WAN_MAC_Address", userParam.value)
249 if ("Homing_Solution".equals(userParam?.name)) {
250 execution.setVariable("homingService", userParam.value)
251 execution.setVariable("callHoming", true)
252 inputMap.put("Homing_Solution", userParam.value)
254 if ("Orchestrator".equalsIgnoreCase(userParam?.name)) {
255 execution.setVariable("orchestrator", userParam.value)
256 inputMap.put("orchestrator", userParam.value)
258 if ("VfModuleNames".equals(userParam?.name)) {
259 logger.debug("VfModuleNames: " + userParam.value.toString())
260 def vfModuleNames = [:]
261 userParam.value.each {
263 String vfModuleModelInvariantUuid = null;
264 String vfModuleName = null;
267 if ("VfModuleModelInvariantUuid".equals(param.key)) {
268 vfModuleModelInvariantUuid = param.value;
269 } else if ("VfModuleName".equals(param.key)) {
270 vfModuleName = param.value;
274 if (vfModuleModelInvariantUuid != null && !vfModuleModelInvariantUuid.isEmpty() && vfModuleName != null && !vfModuleName.isEmpty()) {
275 vfModuleNames.put(vfModuleModelInvariantUuid, vfModuleName)
276 logger.debug("VfModuleModelInvariantUuid: " + vfModuleModelInvariantUuid + " VfModuleName: " + vfModuleName)
279 execution.setVariable("vfModuleNames", vfModuleNames)
284 if (execution.getVariable("homingService") == "") {
285 // Set Default Homing to OOF if not set
286 execution.setVariable("homingService", "oof")
289 logger.debug("User Input Parameters map: " + userParams.toString())
290 execution.setVariable("serviceInputParams", inputMap) // DOES NOT SEEM TO BE USED
292 logger.debug("Incoming brgWanMacAddress is: " + execution.getVariable('brgWanMacAddress'))
294 //For Completion Handler & Fallout Handler
296 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
297 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
298 <action>CREATE</action>
299 <source>${MsoUtils.xmlEscape(source)}</source>
302 execution.setVariable(Prefix + "requestInfo", requestInfo)
304 logger.trace("Completed preProcessRequest CreateVcpeResCustService Request ")
306 } catch (BpmnError e) {
309 } catch (Exception ex) {
310 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
311 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
315 public void sendSyncResponse(DelegateExecution execution) {
317 logger.trace("Inside sendSyncResponse of CreateVcpeResCustService ")
320 String serviceInstanceId = execution.getVariable("serviceInstanceId")
321 String requestId = execution.getVariable("mso-request-id")
323 // RESTResponse (for API Handler (APIH) Reply Task)
324 String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${
328 logger.debug(" sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
329 sendWorkflowResponse(execution, 202, syncResponse)
331 } catch (Exception ex) {
332 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
333 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
337 // *******************************
339 // *******************************
340 public void prepareDecomposeService(DelegateExecution execution) {
343 logger.trace("Inside prepareDecomposeService of CreateVcpeResCustService ")
345 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
347 //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB
348 String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.modelInfo")
349 execution.setVariable("serviceModelInfo", serviceModelInfo)
351 logger.trace("Completed prepareDecomposeService of CreateVcpeResCustService ")
352 } catch (Exception ex) {
353 // try error in method block
354 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
355 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
359 // *******************************
361 // *******************************
362 public void prepareCreateServiceInstance(DelegateExecution execution) {
365 logger.trace("Inside prepareCreateServiceInstance of CreateVcpeResCustService ")
368 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
369 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
370 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
373 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
374 // String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters")
375 // execution.setVariable("serviceInputParams", serviceInputParams)
378 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
379 execution.setVariable("serviceInstanceName", serviceInstanceName)
381 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
382 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonStringNoRootName())
384 logger.trace("Completed prepareCreateServiceInstance of CreateVcpeResCustService ")
385 } catch (Exception ex) {
386 // try error in method block
387 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
388 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
392 public void postProcessServiceInstanceCreate(DelegateExecution execution) {
393 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' + 'execution=' + execution.getId() + ')'
394 logger.trace('Entered ' + method)
396 String requestId = execution.getVariable("mso-request-id")
397 String serviceInstanceId = execution.getVariable("serviceInstanceId")
398 String serviceInstanceName = execution.getVariable("serviceInstanceName")
403 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
406 <req:updateInfraRequest>
407 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
408 <lastModifiedBy>BPEL</lastModifiedBy>
409 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
410 <serviceInstanceName>${MsoUtils.xmlEscape(serviceInstanceName)}</serviceInstanceName>
411 </req:updateInfraRequest>
415 execution.setVariable(Prefix + "setUpdateDbInstancePayload", payload)
416 logger.debug(Prefix + "setUpdateDbInstancePayload: " + payload)
417 logger.trace('Exited ' + method)
419 } catch (BpmnError e) {
421 } catch (Exception e) {
422 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
423 'Caught exception in ' + method, "BPMN",
424 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
425 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
430 public void processDecomposition(DelegateExecution execution) {
432 logger.trace("Inside processDecomposition() of CreateVcpeResCustService ")
436 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
439 List<VnfResource> vnfList = serviceDecomposition.getVnfResources()
441 serviceDecomposition.setVnfResources(vnfList)
443 execution.setVariable("vnfList", vnfList)
444 execution.setVariable("vnfListString", vnfList.toString())
446 String vnfModelInfoString = ""
447 if (vnfList != null && vnfList.size() > 0) {
448 execution.setVariable(Prefix + "VNFsCount", vnfList.size())
449 logger.debug("vnfs to create: " + vnfList.size())
450 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
452 vnfModelInfoString = vnfModelInfo.toString()
453 String vnfModelInfoWithRoot = vnfModelInfo.toString()
454 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
456 execution.setVariable(Prefix + "VNFsCount", 0)
457 logger.debug("no vnfs to create based upon serviceDecomposition content")
460 execution.setVariable("vnfModelInfo", vnfModelInfoString)
461 execution.setVariable("vnfModelInfoString", vnfModelInfoString)
462 logger.debug(" vnfModelInfoString :" + vnfModelInfoString)
464 logger.trace("Completed processDecomposition() of CreateVcpeResCustService ")
465 } catch (Exception ex) {
466 sendSyncError(execution)
467 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. processDecomposition() - " + ex.getMessage()
468 logger.debug(exceptionMessage)
469 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
473 private void filterVnfs(List<VnfResource> vnfList) {
474 if (vnfList == null) {
478 // remove BRG & TXC from VNF list
480 Iterator<VnfResource> it = vnfList.iterator()
481 while (it.hasNext()) {
482 VnfResource vr = it.next()
484 String role = vr.getNfRole()
485 if (role == "BRG" || role == "TunnelXConn" || role == "Tunnel XConn") {
492 public void prepareCreateAllottedResourceTXC(DelegateExecution execution) {
495 logger.trace("Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ")
498 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
499 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
500 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
503 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
505 //allottedResourceModelInfo
506 //allottedResourceRole
507 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
508 //It would be sufficient to only include the service model UUID (i.e. the modelVersionId), since this BB will query the full model from the Catalog DB.
509 List<AllottedResource> allottedResources = serviceDecomposition.getAllottedResources()
510 if (allottedResources != null) {
511 Iterator iter = allottedResources.iterator();
512 while (iter.hasNext()) {
513 AllottedResource allottedResource = (AllottedResource) iter.next();
515 logger.debug(" getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName())
516 logger.debug(" allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType())
517 if ("TunnelXConn".equalsIgnoreCase(allottedResource.getAllottedResourceType()) || "Tunnel XConn".equalsIgnoreCase(allottedResource.getAllottedResourceType())) {
518 //set create flag to true
519 execution.setVariable("createTXCAR", true)
520 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
521 execution.setVariable("allottedResourceModelInfoTXC", allottedResourceModelInfo.toJsonStringNoRootName())
522 execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())
523 execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())
524 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the TXC,
525 //and in its homingSolution section should be found the infraServiceInstanceId (i.e. infraServiceInstanceId in TXC Allotted Resource structure) (which the Homing BB would have populated).
526 execution.setVariable("parentServiceInstanceIdTXC", allottedResource.getHomingSolution().getServiceInstanceId())
532 String allottedResourceId = execution.getVariable("allottedResourceId")
533 execution.setVariable("allottedResourceIdTXC", allottedResourceId)
534 logger.debug("setting allottedResourceId CreateVcpeResCustService " + allottedResourceId)
536 logger.trace("Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ")
537 } catch (Exception ex) {
538 // try error in method block
539 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
540 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
544 public void prepareCreateAllottedResourceBRG(DelegateExecution execution) {
547 logger.trace("Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ")
550 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
551 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
552 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
555 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
557 //allottedResourceModelInfo
558 //allottedResourceRole
559 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
560 //It would be sufficient to only include the service model UUID (i.e. the modelVersionId), since this BB will query the full model from the Catalog DB.
561 List<AllottedResource> allottedResources = serviceDecomposition.getAllottedResources()
562 if (allottedResources != null) {
563 Iterator iter = allottedResources.iterator();
564 while (iter.hasNext()) {
565 AllottedResource allottedResource = (AllottedResource) iter.next();
567 logger.debug(" getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName())
568 logger.debug(" allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType())
569 if ("BRG".equalsIgnoreCase(allottedResource.getAllottedResourceType())) {
570 //set create flag to true
571 execution.setVariable("createBRGAR", true)
572 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
573 execution.setVariable("allottedResourceModelInfoBRG", allottedResourceModelInfo.toJsonStringNoRootName())
574 execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())
575 execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())
576 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the BRG,
577 //and in its homingSolution section should be found the infraServiceInstanceId (i.e. infraServiceInstanceId in BRG Allotted Resource structure) (which the Homing BB would have populated).
578 execution.setVariable("parentServiceInstanceIdBRG", allottedResource.getHomingSolution().getServiceInstanceId())
584 String allottedResourceId = execution.getVariable("allottedResourceId")
585 execution.setVariable("allottedResourceIdBRG", allottedResourceId)
586 logger.debug("setting allottedResourceId CreateVcpeResCustService " + allottedResourceId)
588 logger.trace("Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ")
589 } catch (Exception ex) {
590 // try error in method block
591 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
592 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
596 // *******************************
597 // Generate Network request Section
598 // *******************************
599 public void prepareVnfAndModulesCreate(DelegateExecution execution) {
602 logger.trace("Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ")
604 // String disableRollback = execution.getVariable("disableRollback")
605 // def backoutOnFailure = ""
606 // if(disableRollback != null){
607 // if ( disableRollback == true) {
608 // backoutOnFailure = "false"
609 // } else if ( disableRollback == false) {
610 // backoutOnFailure = "true"
613 //failIfExists - optional
615 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
616 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
617 execution.setVariable("productFamilyId", productFamilyId)
618 logger.debug("productFamilyId: " + productFamilyId)
620 List<VnfResource> vnfList = execution.getVariable("vnfList")
622 Integer vnfsCreatedCount = execution.getVariable(Prefix + "VnfsCreatedCount")
623 String vnfModelInfoString = null;
625 if (vnfList != null && vnfList.size() > 0) {
626 logger.debug("getting model info for vnf # " + vnfsCreatedCount)
627 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
628 logger.debug("got 0 ")
629 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
630 vnfModelInfoString = vnfModelInfo.toString()
632 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored
633 vnfModelInfoString = execution.getVariable("vnfModelInfo")
636 logger.debug(" vnfModelInfoString :" + vnfModelInfoString)
638 // extract cloud configuration - if underscore "_" is present treat as vimId else it's a cloudRegion
639 String vimId = jsonUtil.getJsonValue(createVcpeServiceRequest,
640 "requestDetails.cloudConfiguration.lcpCloudRegionId")
641 if (vimId.contains("_") && vimId.split("_").length == 2 ) {
642 def cloudRegion = vimId.split("_")
643 execution.setVariable("cloudOwner", cloudRegion[0])
644 logger.debug("cloudOwner: " + cloudRegion[0])
645 execution.setVariable("cloudRegionId", cloudRegion[1])
646 logger.debug("cloudRegionId: " + cloudRegion[1])
647 execution.setVariable("lcpCloudRegionId", cloudRegion[1])
648 logger.debug("lcpCloudRegionId: " + cloudRegion[1])
650 logger.debug("vimId is not present - setting cloudRegion/cloudOwner from request.")
651 String cloudOwner = jsonUtil.getJsonValue(createVcpeServiceRequest,
652 "requestDetails.cloudConfiguration.cloudOwner")
653 if (!cloudOwner?.empty && cloudOwner != "")
655 execution.setVariable("cloudOwner", cloudOwner)
656 logger.debug("cloudOwner: " + cloudOwner)
658 execution.setVariable("cloudRegionId", vimId)
659 logger.debug("cloudRegionId: " + vimId)
660 execution.setVariable("lcpCloudRegionId", vimId)
661 logger.debug("lcpCloudRegionId: " + vimId)
664 String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest,
665 "requestDetails.cloudConfiguration.tenantId")
666 execution.setVariable("tenantId", tenantId)
667 logger.debug("tenantId: " + tenantId)
669 String sdncVersion = execution.getVariable("sdncVersion")
670 logger.debug("sdncVersion: " + sdncVersion)
672 logger.trace("Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ")
673 } catch (Exception ex) {
674 // try error in method block
675 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
676 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
680 // *******************************
681 // Validate Vnf request Section -> increment count
682 // *******************************
683 public void validateVnfCreate(DelegateExecution execution) {
686 logger.trace("Inside validateVnfCreate of CreateVcpeResCustService ")
688 Integer vnfsCreatedCount = execution.getVariable(Prefix + "VnfsCreatedCount")
691 execution.setVariable(Prefix + "VnfsCreatedCount", vnfsCreatedCount)
693 logger.debug(" ***** Completed validateVnfCreate of CreateVcpeResCustService ***** " + " vnf # " + vnfsCreatedCount)
694 } catch (Exception ex) {
695 // try error in method block
696 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
697 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
701 // *****************************************
702 // Prepare Completion request Section
703 // *****************************************
704 public void postProcessResponse(DelegateExecution execution) {
706 logger.trace("Inside postProcessResponse of CreateVcpeResCustService ")
709 String source = execution.getVariable("source")
710 String requestId = execution.getVariable("mso-request-id")
711 String serviceInstanceId = execution.getVariable("serviceInstanceId")
713 String msoCompletionRequest =
714 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
715 xmlns:ns="http://org.onap/so/request/types/v1">
716 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
717 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
718 <action>CREATE</action>
719 <source>${MsoUtils.xmlEscape(source)}</source>
721 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
722 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
723 <mso-bpel-name>BPMN macro create</mso-bpel-name>
724 </aetgt:MsoCompletionRequest>"""
727 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
729 logger.debug(xmlMsoCompletionRequest)
730 execution.setVariable(Prefix + "Success", true)
731 execution.setVariable(Prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest)
732 logger.debug(" SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
733 } catch (BpmnError e) {
735 } catch (Exception ex) {
736 // try error in method block
737 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
738 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
742 public void preProcessRollback(DelegateExecution execution) {
743 logger.trace("preProcessRollback of CreateVcpeResCustService ")
746 Object workflowException = execution.getVariable("WorkflowException");
748 if (workflowException instanceof WorkflowException) {
749 logger.debug("Prev workflowException: " + workflowException.getErrorMessage())
750 execution.setVariable("prevWorkflowException", workflowException);
751 //execution.setVariable("WorkflowException", null);
753 } catch (BpmnError e) {
754 logger.debug("BPMN Error during preProcessRollback")
755 } catch (Exception ex) {
756 String msg = "Exception in preProcessRollback. " + ex.getMessage()
759 logger.trace("Exit preProcessRollback of CreateVcpeResCustService ")
762 public void postProcessRollback(DelegateExecution execution) {
763 logger.trace("postProcessRollback of CreateVcpeResCustService ")
766 Object workflowException = execution.getVariable("prevWorkflowException");
767 if (workflowException instanceof WorkflowException) {
768 logger.debug("Setting prevException to WorkflowException: ")
769 execution.setVariable("WorkflowException", workflowException);
771 } catch (BpmnError b) {
772 logger.debug("BPMN Error during postProcessRollback")
774 } catch (Exception ex) {
775 msg = "Exception in postProcessRollback. " + ex.getMessage()
778 logger.trace("Exit postProcessRollback of CreateVcpeResCustService ")
781 public void prepareFalloutRequest(DelegateExecution execution) {
783 logger.trace("STARTED CreateVcpeResCustService prepareFalloutRequest Process ")
786 WorkflowException wfex = execution.getVariable("WorkflowException")
787 logger.debug(" Incoming Workflow Exception: " + wfex.toString())
788 String requestInfo = execution.getVariable(Prefix + "requestInfo")
789 logger.debug(" Incoming Request Info: " + requestInfo)
791 //TODO. hmmm. there is no way to UPDATE error message.
792 // String errorMessage = wfex.getErrorMessage()
793 // boolean successIndicator = execution.getVariable("DCRESI_rolledBack")
794 // if (successIndicator){
795 // errorMessage = errorMessage + ". Rollback successful."
797 // errorMessage = errorMessage + ". Rollback not completed."
800 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
802 execution.setVariable(Prefix + "falloutRequest", falloutRequest)
804 } catch (Exception ex) {
805 logger.debug("Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage())
806 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")
808 logger.trace("COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ")
812 public void sendSyncError(DelegateExecution execution) {
813 execution.setVariable("prefix", Prefix)
815 logger.trace("Inside sendSyncError() of CreateVcpeResCustService ")
818 String errorMessage = ""
819 def wfe = execution.getVariable("WorkflowException")
820 if (wfe instanceof WorkflowException) {
821 errorMessage = wfe.getErrorMessage()
823 errorMessage = "Sending Sync Error."
826 String buildworkflowException =
827 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
828 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
829 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
830 </aetgt:WorkflowException>"""
832 logger.debug(buildworkflowException)
833 sendWorkflowResponse(execution, 500, buildworkflowException)
834 } catch (Exception ex) {
835 logger.debug(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
839 public void processJavaException(DelegateExecution execution) {
840 execution.setVariable("prefix", Prefix)
842 logger.debug("Caught a Java Exception")
843 logger.debug("Started processJavaException Method")
844 logger.debug("Variables List: " + execution.getVariables())
845 execution.setVariable(Prefix + "unexpectedError", "Caught a Java Lang Exception")
846 // Adding this line temporarily until this flows error handling gets updated
847 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
848 } catch (BpmnError b) {
849 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
850 "Rethrowing MSOWorkflowException", "BPMN",
851 MsoLogger.ErrorCode.UnknownError.getValue());
853 } catch (Exception e) {
854 logger.debug("Caught Exception during processJavaException Method: " + e)
855 execution.setVariable(Prefix + "unexpectedError", "Exception in processJavaException method")
856 // Adding this line temporarily until this flows error handling gets updated
857 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
859 logger.debug("Completed processJavaException Method")