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 org.onap.so.logger.ErrorCode;
26 import static org.apache.commons.lang3.StringUtils.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.common.scripts.VidUtils
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.domain.*
36 import org.onap.so.bpmn.core.json.JsonUtils
37 import org.onap.so.bpmn.core.UrnPropertiesReader
38 import org.onap.so.logger.MessageEnum
39 import org.springframework.web.util.UriUtils
40 import org.slf4j.Logger
41 import org.slf4j.LoggerFactory
48 * This groovy class supports the <class>CreateVcpeResCustService.bpmn</class> process.
53 public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
54 private static final Logger logger = LoggerFactory.getLogger(CreateVcpeResCustService.class);
56 private static final String DebugFlag = "isDebugLogEnabled"
58 String Prefix = "CVRCS_"
59 ExceptionUtil exceptionUtil = new ExceptionUtil()
60 JsonUtils jsonUtil = new JsonUtils()
61 VidUtils vidUtils = new VidUtils()
64 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
67 private InitializeProcessVariables(DelegateExecution execution) {
68 /* Initialize all the process variables in this block */
70 execution.setVariable("createVcpeServiceRequest", "")
71 execution.setVariable("globalSubscriberId", "")
72 execution.setVariable("serviceInstanceName", "")
73 execution.setVariable("msoRequestId", "")
74 execution.setVariable(Prefix + "VnfsCreatedCount", 0)
75 execution.setVariable("productFamilyId", "")
76 execution.setVariable("brgWanMacAddress", "")
77 execution.setVariable("customerLocation", "")
78 execution.setVariable("homingService", "")
79 execution.setVariable("cloudOwner", "")
80 execution.setVariable("cloudRegionId", "")
81 execution.setVariable("homingModelIds", "")
84 execution.setVariable("sdncVersion", "1707")
87 // **************************************************
88 // Pre or Prepare Request Section
89 // **************************************************
91 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
94 public void preProcessRequest(DelegateExecution execution) {
95 def isDebugEnabled = execution.getVariable(DebugFlag)
96 execution.setVariable("prefix", Prefix)
98 logger.trace("Inside preProcessRequest CreateVcpeResCustService Request ")
101 // initialize flow variables
102 InitializeProcessVariables(execution)
105 String aaiDistDelay = UrnPropertiesReader.getVariable("aai.workflowAaiDistributionDelay", execution)
106 if (isBlank(aaiDistDelay)) {
107 String msg = "workflowAaiDistributionDelay is null"
109 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
111 execution.setVariable("aaiDistDelay", aaiDistDelay)
112 logger.debug("AAI distribution delay: " + aaiDistDelay)
114 // check for incoming json message/input
115 String createVcpeServiceRequest = execution.getVariable("bpmnRequest")
116 logger.debug(createVcpeServiceRequest)
117 execution.setVariable("createVcpeServiceRequest", createVcpeServiceRequest);
118 println 'createVcpeServiceRequest - ' + createVcpeServiceRequest
121 String requestId = execution.getVariable("mso-request-id")
122 execution.setVariable("msoRequestId", requestId)
124 String serviceInstanceId = execution.getVariable("serviceInstanceId")
126 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
127 serviceInstanceId = UUID.randomUUID().toString()
128 logger.debug(" Generated new Service Instance: " + serviceInstanceId)
130 logger.debug("Using provided Service Instance ID: " + serviceInstanceId)
133 serviceInstanceId = UriUtils.encode(serviceInstanceId, "UTF-8")
134 execution.setVariable("serviceInstanceId", serviceInstanceId)
135 logger.debug("Incoming serviceInstanceId is: " + serviceInstanceId)
137 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
138 execution.setVariable("serviceInstanceName", serviceInstanceName)
139 logger.debug("Incoming serviceInstanceName is: " + serviceInstanceName)
141 String requestAction = execution.getVariable("requestAction")
142 execution.setVariable("requestAction", requestAction)
144 setBasicDBAuthHeader(execution, isDebugEnabled)
146 String source = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.source")
147 if ((source == null) || (source.isEmpty())) {
150 execution.setVariable("source", source)
152 // extract globalSubscriberId
153 String globalSubscriberId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
155 // verify element global-customer-id is sent from JSON input, throw exception if missing
156 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
157 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
158 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
161 execution.setVariable("globalSubscriberId", globalSubscriberId)
162 execution.setVariable("globalCustomerId", globalSubscriberId)
165 // extract subscriptionServiceType
166 String subscriptionServiceType = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
167 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
168 logger.debug("Incoming subscriptionServiceType is: " + subscriptionServiceType)
170 String suppressRollback = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.suppressRollback")
171 execution.setVariable("disableRollback", suppressRollback)
172 logger.debug("Incoming Suppress/Disable Rollback is: " + suppressRollback)
174 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
175 execution.setVariable("productFamilyId", productFamilyId)
176 logger.debug("Incoming productFamilyId is: " + productFamilyId)
178 String subscriberInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo")
179 execution.setVariable("subscriberInfo", subscriberInfo)
180 logger.debug("Incoming subscriberInfo is: " + subscriberInfo)
182 // extract cloud configuration - if underscore "_" is present treat as vimId else it's a cloudRegion
183 String vimId = jsonUtil.getJsonValue(createVcpeServiceRequest,
184 "requestDetails.cloudConfiguration.lcpCloudRegionId")
185 if (vimId.contains("_") && vimId.split("_").length == 2 ) {
186 def cloudRegion = vimId.split("_")
187 def cloudOwner = cloudRegion[0]
188 def cloudRegionId = cloudRegion[1]
189 execution.setVariable("cloudOwner", cloudOwner)
190 logger.debug("cloudOwner: " + cloudOwner)
191 execution.setVariable("cloudRegionId", cloudRegionId)
192 logger.debug("cloudRegionId: " + cloudRegionId)
194 logger.debug("vimId is not present - setting cloudRegion/cloudOwner from request.")
195 String cloudOwner = jsonUtil.getJsonValue(createVcpeServiceRequest,
196 "requestDetails.cloudConfiguration.cloudOwner")
197 if (!cloudOwner?.empty && cloudOwner != "")
199 execution.setVariable("cloudOwner", cloudOwner)
200 logger.debug("cloudOwner: " + cloudOwner)
202 def cloudRegionId = vimId
203 execution.setVariable("cloudRegionId", cloudRegionId)
204 logger.debug("cloudRegionId: " + cloudRegionId)
207 * Extracting User Parameters from incoming Request and converting into a Map
209 def jsonSlurper = new JsonSlurper()
211 Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest)
214 def userParams = reqMap.requestDetails?.requestParameters?.userParams
216 Map<String, String> inputMap = [:]
220 if ("Customer_Location".equals(userParam?.name)) {
221 Map<String, String> customerMap = [:]
222 userParam.value.each {
224 inputMap.put(param.key, param.value)
225 customerMap.put(param.key, param.value)
227 execution.setVariable("customerLocation", customerMap)
229 if ("Homing_Model_Ids".equals(userParam?.name)) {
230 logger.debug("Homing_Model_Ids: " + userParam.value.toString() + " ---- Type is:" +
231 userParam.value.getClass())
233 userParam.value.each {
238 valueMap.put(entry.key, entry.value)
240 modelIdLst.add(valueMap)
241 logger.debug("Param: " + param.toString() + " ---- Type is:" +
244 execution.setVariable("homingModelIds", modelIdLst)
246 if ("BRG_WAN_MAC_Address".equals(userParam?.name)) {
247 execution.setVariable("brgWanMacAddress", userParam.value)
248 inputMap.put("BRG_WAN_MAC_Address", userParam.value)
250 if ("Homing_Solution".equals(userParam?.name)) {
251 execution.setVariable("homingService", userParam.value)
252 execution.setVariable("callHoming", true)
253 inputMap.put("Homing_Solution", userParam.value)
255 if ("Orchestrator".equalsIgnoreCase(userParam?.name)) {
256 execution.setVariable("orchestrator", userParam.value)
257 inputMap.put("orchestrator", userParam.value)
259 if ("VfModuleNames".equals(userParam?.name)) {
260 logger.debug("VfModuleNames: " + userParam.value.toString())
261 def vfModuleNames = [:]
262 userParam.value.each {
264 String vfModuleModelInvariantUuid = null;
265 String vfModuleName = null;
268 if ("VfModuleModelInvariantUuid".equals(param.key)) {
269 vfModuleModelInvariantUuid = param.value;
270 } else if ("VfModuleName".equals(param.key)) {
271 vfModuleName = param.value;
275 if (vfModuleModelInvariantUuid != null && !vfModuleModelInvariantUuid.isEmpty() && vfModuleName != null && !vfModuleName.isEmpty()) {
276 vfModuleNames.put(vfModuleModelInvariantUuid, vfModuleName)
277 logger.debug("VfModuleModelInvariantUuid: " + vfModuleModelInvariantUuid + " VfModuleName: " + vfModuleName)
280 execution.setVariable("vfModuleNames", vfModuleNames)
285 if (execution.getVariable("homingService") == "") {
286 // Set Default Homing to OOF if not set
287 execution.setVariable("homingService", "oof")
290 logger.debug("User Input Parameters map: " + userParams.toString())
291 execution.setVariable("serviceInputParams", inputMap) // DOES NOT SEEM TO BE USED
293 logger.debug("Incoming brgWanMacAddress is: " + execution.getVariable('brgWanMacAddress'))
295 //For Completion Handler & Fallout Handler
297 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
298 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
299 <action>CREATE</action>
300 <source>${MsoUtils.xmlEscape(source)}</source>
303 execution.setVariable(Prefix + "requestInfo", requestInfo)
305 logger.trace("Completed preProcessRequest CreateVcpeResCustService Request ")
307 } catch (BpmnError e) {
310 } catch (Exception ex) {
311 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
312 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
316 public void sendSyncResponse(DelegateExecution execution) {
318 logger.trace("Inside sendSyncResponse of CreateVcpeResCustService ")
321 String serviceInstanceId = execution.getVariable("serviceInstanceId")
322 String requestId = execution.getVariable("mso-request-id")
324 // RESTResponse (for API Handler (APIH) Reply Task)
325 String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${
329 logger.debug(" sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
330 sendWorkflowResponse(execution, 202, syncResponse)
332 } catch (Exception ex) {
333 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
334 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
338 // *******************************
340 // *******************************
341 public void prepareDecomposeService(DelegateExecution execution) {
344 logger.trace("Inside prepareDecomposeService of CreateVcpeResCustService ")
346 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
348 //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB
349 String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.modelInfo")
350 execution.setVariable("serviceModelInfo", serviceModelInfo)
352 logger.trace("Completed prepareDecomposeService of CreateVcpeResCustService ")
353 } catch (Exception ex) {
354 // try error in method block
355 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
356 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
360 // *******************************
362 // *******************************
363 public void prepareCreateServiceInstance(DelegateExecution execution) {
366 logger.trace("Inside prepareCreateServiceInstance of CreateVcpeResCustService ")
369 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
370 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
371 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
374 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
375 // String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters")
376 // execution.setVariable("serviceInputParams", serviceInputParams)
379 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
380 execution.setVariable("serviceInstanceName", serviceInstanceName)
382 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
383 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonStringNoRootName())
385 logger.trace("Completed prepareCreateServiceInstance of CreateVcpeResCustService ")
386 } catch (Exception ex) {
387 // try error in method block
388 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
389 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
393 public void postProcessServiceInstanceCreate(DelegateExecution execution) {
394 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' + 'execution=' + execution.getId() + ')'
395 logger.trace('Entered ' + method)
397 String requestId = execution.getVariable("mso-request-id")
398 String serviceInstanceId = execution.getVariable("serviceInstanceId")
399 String serviceInstanceName = execution.getVariable("serviceInstanceName")
404 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
407 <req:updateInfraRequest>
408 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
409 <lastModifiedBy>BPEL</lastModifiedBy>
410 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
411 <serviceInstanceName>${MsoUtils.xmlEscape(serviceInstanceName)}</serviceInstanceName>
412 </req:updateInfraRequest>
416 execution.setVariable(Prefix + "setUpdateDbInstancePayload", payload)
417 logger.debug(Prefix + "setUpdateDbInstancePayload: " + payload)
418 logger.trace('Exited ' + method)
420 } catch (BpmnError e) {
422 } catch (Exception e) {
423 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
424 'Caught exception in ' + method, "BPMN",
425 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
426 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
431 public void processDecomposition(DelegateExecution execution) {
433 logger.trace("Inside processDecomposition() of CreateVcpeResCustService ")
437 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
440 List<VnfResource> vnfList = serviceDecomposition.getVnfResources()
442 serviceDecomposition.setVnfResources(vnfList)
444 execution.setVariable("vnfList", vnfList)
445 execution.setVariable("vnfListString", vnfList.toString())
447 String vnfModelInfoString = ""
448 if (vnfList != null && vnfList.size() > 0) {
449 execution.setVariable(Prefix + "VNFsCount", vnfList.size())
450 logger.debug("vnfs to create: " + vnfList.size())
451 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
453 vnfModelInfoString = vnfModelInfo.toString()
454 String vnfModelInfoWithRoot = vnfModelInfo.toString()
455 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
457 execution.setVariable(Prefix + "VNFsCount", 0)
458 logger.debug("no vnfs to create based upon serviceDecomposition content")
461 execution.setVariable("vnfModelInfo", vnfModelInfoString)
462 execution.setVariable("vnfModelInfoString", vnfModelInfoString)
463 logger.debug(" vnfModelInfoString :" + vnfModelInfoString)
465 logger.trace("Completed processDecomposition() of CreateVcpeResCustService ")
466 } catch (Exception ex) {
467 sendSyncError(execution)
468 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. processDecomposition() - " + ex.getMessage()
469 logger.debug(exceptionMessage)
470 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
474 private void filterVnfs(List<VnfResource> vnfList) {
475 if (vnfList == null) {
479 // remove BRG & TXC from VNF list
481 Iterator<VnfResource> it = vnfList.iterator()
482 while (it.hasNext()) {
483 VnfResource vr = it.next()
485 String role = vr.getNfRole()
486 if (role == "BRG" || role == "TunnelXConn" || role == "Tunnel XConn") {
493 public void prepareCreateAllottedResourceTXC(DelegateExecution execution) {
496 logger.trace("Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ")
499 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
500 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
501 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
504 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
506 //allottedResourceModelInfo
507 //allottedResourceRole
508 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
509 //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.
510 List<AllottedResource> allottedResources = serviceDecomposition.getAllottedResources()
511 if (allottedResources != null) {
512 Iterator iter = allottedResources.iterator();
513 while (iter.hasNext()) {
514 AllottedResource allottedResource = (AllottedResource) iter.next();
516 logger.debug(" getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName())
517 logger.debug(" allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType())
518 if ("TunnelXConn".equalsIgnoreCase(allottedResource.getAllottedResourceType()) || "Tunnel XConn".equalsIgnoreCase(allottedResource.getAllottedResourceType())) {
519 //set create flag to true
520 execution.setVariable("createTXCAR", true)
521 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
522 execution.setVariable("allottedResourceModelInfoTXC", allottedResourceModelInfo.toJsonStringNoRootName())
523 execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())
524 execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())
525 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the TXC,
526 //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).
527 execution.setVariable("parentServiceInstanceIdTXC", allottedResource.getHomingSolution().getServiceInstanceId())
533 String allottedResourceId = execution.getVariable("allottedResourceId")
534 execution.setVariable("allottedResourceIdTXC", allottedResourceId)
535 logger.debug("setting allottedResourceId CreateVcpeResCustService " + allottedResourceId)
537 logger.trace("Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ")
538 } catch (Exception ex) {
539 // try error in method block
540 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
541 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
545 public void prepareCreateAllottedResourceBRG(DelegateExecution execution) {
548 logger.trace("Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ")
551 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
552 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
553 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
556 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
558 //allottedResourceModelInfo
559 //allottedResourceRole
560 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
561 //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.
562 List<AllottedResource> allottedResources = serviceDecomposition.getAllottedResources()
563 if (allottedResources != null) {
564 Iterator iter = allottedResources.iterator();
565 while (iter.hasNext()) {
566 AllottedResource allottedResource = (AllottedResource) iter.next();
568 logger.debug(" getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName())
569 logger.debug(" allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType())
570 if ("BRG".equalsIgnoreCase(allottedResource.getAllottedResourceType())) {
571 //set create flag to true
572 execution.setVariable("createBRGAR", true)
573 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
574 execution.setVariable("allottedResourceModelInfoBRG", allottedResourceModelInfo.toJsonStringNoRootName())
575 execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())
576 execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())
577 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the BRG,
578 //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).
579 execution.setVariable("parentServiceInstanceIdBRG", allottedResource.getHomingSolution().getServiceInstanceId())
585 String allottedResourceId = execution.getVariable("allottedResourceId")
586 execution.setVariable("allottedResourceIdBRG", allottedResourceId)
587 logger.debug("setting allottedResourceId CreateVcpeResCustService " + allottedResourceId)
589 logger.trace("Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ")
590 } catch (Exception ex) {
591 // try error in method block
592 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
593 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
597 // *******************************
598 // Generate Network request Section
599 // *******************************
600 public void prepareVnfAndModulesCreate(DelegateExecution execution) {
603 logger.trace("Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ")
605 // String disableRollback = execution.getVariable("disableRollback")
606 // def backoutOnFailure = ""
607 // if(disableRollback != null){
608 // if ( disableRollback == true) {
609 // backoutOnFailure = "false"
610 // } else if ( disableRollback == false) {
611 // backoutOnFailure = "true"
614 //failIfExists - optional
616 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
617 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
618 execution.setVariable("productFamilyId", productFamilyId)
619 logger.debug("productFamilyId: " + productFamilyId)
621 List<VnfResource> vnfList = execution.getVariable("vnfList")
623 Integer vnfsCreatedCount = execution.getVariable(Prefix + "VnfsCreatedCount")
624 String vnfModelInfoString = null;
626 if (vnfList != null && vnfList.size() > 0) {
627 logger.debug("getting model info for vnf # " + vnfsCreatedCount)
628 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
629 logger.debug("got 0 ")
630 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
631 vnfModelInfoString = vnfModelInfo.toString()
633 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored
634 vnfModelInfoString = execution.getVariable("vnfModelInfo")
637 logger.debug(" vnfModelInfoString :" + vnfModelInfoString)
639 // extract cloud configuration - if underscore "_" is present treat as vimId else it's a cloudRegion
640 String vimId = jsonUtil.getJsonValue(createVcpeServiceRequest,
641 "requestDetails.cloudConfiguration.lcpCloudRegionId")
642 if (vimId.contains("_") && vimId.split("_").length == 2 ) {
643 def cloudRegion = vimId.split("_")
644 execution.setVariable("cloudOwner", cloudRegion[0])
645 logger.debug("cloudOwner: " + cloudRegion[0])
646 execution.setVariable("cloudRegionId", cloudRegion[1])
647 logger.debug("cloudRegionId: " + cloudRegion[1])
648 execution.setVariable("lcpCloudRegionId", cloudRegion[1])
649 logger.debug("lcpCloudRegionId: " + cloudRegion[1])
651 logger.debug("vimId is not present - setting cloudRegion/cloudOwner from request.")
652 String cloudOwner = jsonUtil.getJsonValue(createVcpeServiceRequest,
653 "requestDetails.cloudConfiguration.cloudOwner")
654 if (!cloudOwner?.empty && cloudOwner != "")
656 execution.setVariable("cloudOwner", cloudOwner)
657 logger.debug("cloudOwner: " + cloudOwner)
659 execution.setVariable("cloudRegionId", vimId)
660 logger.debug("cloudRegionId: " + vimId)
661 execution.setVariable("lcpCloudRegionId", vimId)
662 logger.debug("lcpCloudRegionId: " + vimId)
665 String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest,
666 "requestDetails.cloudConfiguration.tenantId")
667 execution.setVariable("tenantId", tenantId)
668 logger.debug("tenantId: " + tenantId)
670 String sdncVersion = execution.getVariable("sdncVersion")
671 logger.debug("sdncVersion: " + sdncVersion)
673 logger.trace("Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ")
674 } catch (Exception ex) {
675 // try error in method block
676 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
677 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
681 // *******************************
682 // Validate Vnf request Section -> increment count
683 // *******************************
684 public void validateVnfCreate(DelegateExecution execution) {
687 logger.trace("Inside validateVnfCreate of CreateVcpeResCustService ")
689 Integer vnfsCreatedCount = execution.getVariable(Prefix + "VnfsCreatedCount")
692 execution.setVariable(Prefix + "VnfsCreatedCount", vnfsCreatedCount)
694 logger.debug(" ***** Completed validateVnfCreate of CreateVcpeResCustService ***** " + " vnf # " + vnfsCreatedCount)
695 } catch (Exception ex) {
696 // try error in method block
697 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
698 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
702 // *****************************************
703 // Prepare Completion request Section
704 // *****************************************
705 public void postProcessResponse(DelegateExecution execution) {
707 logger.trace("Inside postProcessResponse of CreateVcpeResCustService ")
710 String source = execution.getVariable("source")
711 String requestId = execution.getVariable("mso-request-id")
712 String serviceInstanceId = execution.getVariable("serviceInstanceId")
714 String msoCompletionRequest =
715 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
716 xmlns:ns="http://org.onap/so/request/types/v1">
717 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
718 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
719 <action>CREATE</action>
720 <source>${MsoUtils.xmlEscape(source)}</source>
722 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
723 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
724 <mso-bpel-name>BPMN macro create</mso-bpel-name>
725 </aetgt:MsoCompletionRequest>"""
728 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
730 logger.debug(xmlMsoCompletionRequest)
731 execution.setVariable(Prefix + "Success", true)
732 execution.setVariable(Prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest)
733 logger.debug(" SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
734 } catch (BpmnError e) {
736 } catch (Exception ex) {
737 // try error in method block
738 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
739 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
743 public void preProcessRollback(DelegateExecution execution) {
744 logger.trace("preProcessRollback of CreateVcpeResCustService ")
747 Object workflowException = execution.getVariable("WorkflowException");
749 if (workflowException instanceof WorkflowException) {
750 logger.debug("Prev workflowException: " + workflowException.getErrorMessage())
751 execution.setVariable("prevWorkflowException", workflowException);
752 //execution.setVariable("WorkflowException", null);
754 } catch (BpmnError e) {
755 logger.debug("BPMN Error during preProcessRollback")
756 } catch (Exception ex) {
757 String msg = "Exception in preProcessRollback. " + ex.getMessage()
760 logger.trace("Exit preProcessRollback of CreateVcpeResCustService ")
763 public void postProcessRollback(DelegateExecution execution) {
764 logger.trace("postProcessRollback of CreateVcpeResCustService ")
767 Object workflowException = execution.getVariable("prevWorkflowException");
768 if (workflowException instanceof WorkflowException) {
769 logger.debug("Setting prevException to WorkflowException: ")
770 execution.setVariable("WorkflowException", workflowException);
772 } catch (BpmnError b) {
773 logger.debug("BPMN Error during postProcessRollback")
775 } catch (Exception ex) {
776 msg = "Exception in postProcessRollback. " + ex.getMessage()
779 logger.trace("Exit postProcessRollback of CreateVcpeResCustService ")
782 public void prepareFalloutRequest(DelegateExecution execution) {
784 logger.trace("STARTED CreateVcpeResCustService prepareFalloutRequest Process ")
787 WorkflowException wfex = execution.getVariable("WorkflowException")
788 logger.debug(" Incoming Workflow Exception: " + wfex.toString())
789 String requestInfo = execution.getVariable(Prefix + "requestInfo")
790 logger.debug(" Incoming Request Info: " + requestInfo)
792 //TODO. hmmm. there is no way to UPDATE error message.
793 // String errorMessage = wfex.getErrorMessage()
794 // boolean successIndicator = execution.getVariable("DCRESI_rolledBack")
795 // if (successIndicator){
796 // errorMessage = errorMessage + ". Rollback successful."
798 // errorMessage = errorMessage + ". Rollback not completed."
801 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
803 execution.setVariable(Prefix + "falloutRequest", falloutRequest)
805 } catch (Exception ex) {
806 logger.debug("Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage())
807 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")
809 logger.trace("COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ")
813 public void sendSyncError(DelegateExecution execution) {
814 execution.setVariable("prefix", Prefix)
816 logger.trace("Inside sendSyncError() of CreateVcpeResCustService ")
819 String errorMessage = ""
820 def wfe = execution.getVariable("WorkflowException")
821 if (wfe instanceof WorkflowException) {
822 errorMessage = wfe.getErrorMessage()
824 errorMessage = "Sending Sync Error."
827 String buildworkflowException =
828 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
829 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
830 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
831 </aetgt:WorkflowException>"""
833 logger.debug(buildworkflowException)
834 sendWorkflowResponse(execution, 500, buildworkflowException)
835 } catch (Exception ex) {
836 logger.debug(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
840 public void processJavaException(DelegateExecution execution) {
841 execution.setVariable("prefix", Prefix)
843 logger.debug("Caught a Java Exception")
844 logger.debug("Started processJavaException Method")
845 logger.debug("Variables List: " + execution.getVariables())
846 execution.setVariable(Prefix + "unexpectedError", "Caught a Java Lang Exception")
847 // Adding this line temporarily until this flows error handling gets updated
848 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
849 } catch (BpmnError b) {
850 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
851 "Rethrowing MSOWorkflowException", "BPMN",
852 ErrorCode.UnknownError.getValue());
854 } catch (Exception e) {
855 logger.debug("Caught Exception during processJavaException Method: " + e)
856 execution.setVariable(Prefix + "unexpectedError", "Exception in processJavaException method")
857 // Adding this line temporarily until this flows error handling gets updated
858 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
860 logger.debug("Completed processJavaException Method")