2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.vcpe.scripts;
22 import static org.apache.commons.lang3.StringUtils.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.common.scripts.VidUtils
31 import org.onap.so.bpmn.core.WorkflowException
32 import org.onap.so.bpmn.core.domain.*
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.so.bpmn.core.UrnPropertiesReader
35 import org.onap.so.logger.MessageEnum
36 import org.onap.so.logger.MsoLogger
37 import org.springframework.web.util.UriUtils;
44 * This groovy class supports the <class>CreateVcpeResCustService.bpmn</class> process.
49 public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
50 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CreateVcpeResCustService.class);
52 private static final String DebugFlag = "isDebugLogEnabled"
54 String Prefix = "CVRCS_"
55 ExceptionUtil exceptionUtil = new ExceptionUtil()
56 JsonUtils jsonUtil = new JsonUtils()
57 VidUtils vidUtils = new VidUtils()
58 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
61 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
64 private InitializeProcessVariables(DelegateExecution execution) {
65 /* Initialize all the process variables in this block */
67 execution.setVariable("createVcpeServiceRequest", "")
68 execution.setVariable("globalSubscriberId", "")
69 execution.setVariable("serviceInstanceName", "")
70 execution.setVariable("msoRequestId", "")
71 execution.setVariable(Prefix + "VnfsCreatedCount", 0)
72 execution.setVariable("productFamilyId", "")
73 execution.setVariable("brgWanMacAddress", "")
74 execution.setVariable("customerLocation", "")
75 execution.setVariable("homingService", "")
76 execution.setVariable("cloudOwner", "")
77 execution.setVariable("cloudRegionId", "")
78 execution.setVariable("homingModelIds", "")
81 execution.setVariable("sdncVersion", "1707")
84 // **************************************************
85 // Pre or Prepare Request Section
86 // **************************************************
88 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
91 public void preProcessRequest(DelegateExecution execution) {
92 def isDebugEnabled = execution.getVariable(DebugFlag)
93 execution.setVariable("prefix", Prefix)
95 msoLogger.trace("Inside preProcessRequest CreateVcpeResCustService Request ")
98 // initialize flow variables
99 InitializeProcessVariables(execution)
102 String aaiDistDelay = UrnPropertiesReader.getVariable("aai.workflowAaiDistributionDelay")
103 if (isBlank(aaiDistDelay)) {
104 String msg = "workflowAaiDistributionDelay is null"
106 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108 execution.setVariable("aaiDistDelay", aaiDistDelay)
109 msoLogger.debug("AAI distribution delay: " + aaiDistDelay)
111 // check for incoming json message/input
112 String createVcpeServiceRequest = execution.getVariable("bpmnRequest")
113 msoLogger.debug(createVcpeServiceRequest)
114 execution.setVariable("createVcpeServiceRequest", createVcpeServiceRequest);
115 println 'createVcpeServiceRequest - ' + createVcpeServiceRequest
118 String requestId = execution.getVariable("mso-request-id")
119 execution.setVariable("msoRequestId", requestId)
121 String serviceInstanceId = execution.getVariable("serviceInstanceId")
123 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
124 serviceInstanceId = UUID.randomUUID().toString()
125 msoLogger.debug(" Generated new Service Instance: " + serviceInstanceId)
127 msoLogger.debug("Using provided Service Instance ID: " + serviceInstanceId)
130 serviceInstanceId = UriUtils.encode(serviceInstanceId, "UTF-8")
131 execution.setVariable("serviceInstanceId", serviceInstanceId)
132 utils.log("DEBUG", "Incoming serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)
134 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
135 execution.setVariable("serviceInstanceName", serviceInstanceName)
136 utils.log("DEBUG", "Incoming serviceInstanceName is: " + serviceInstanceName, isDebugEnabled)
138 String requestAction = execution.getVariable("requestAction")
139 execution.setVariable("requestAction", requestAction)
141 setBasicDBAuthHeader(execution, isDebugEnabled)
143 String source = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.source")
144 if ((source == null) || (source.isEmpty())) {
147 execution.setVariable("source", source)
149 // extract globalSubscriberId
150 String globalSubscriberId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
152 // verify element global-customer-id is sent from JSON input, throw exception if missing
153 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
154 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
155 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
158 execution.setVariable("globalSubscriberId", globalSubscriberId)
159 execution.setVariable("globalCustomerId", globalSubscriberId)
162 // extract subscriptionServiceType
163 String subscriptionServiceType = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
164 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
165 msoLogger.debug("Incoming subscriptionServiceType is: " + subscriptionServiceType)
167 String suppressRollback = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.suppressRollback")
168 execution.setVariable("disableRollback", suppressRollback)
169 msoLogger.debug("Incoming Suppress/Disable Rollback is: " + suppressRollback)
171 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
172 execution.setVariable("productFamilyId", productFamilyId)
173 msoLogger.debug("Incoming productFamilyId is: " + productFamilyId)
175 String subscriberInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo")
176 execution.setVariable("subscriberInfo", subscriberInfo)
177 msoLogger.debug("Incoming subscriberInfo is: " + subscriberInfo)
179 // extract cloud configuration, split vid_ID into cloudOwner and cloudRegionId
180 String vimId = jsonUtil.getJsonValue(createVcpeServiceRequest,
181 "requestDetails.cloudConfiguration.lcpCloudRegionId")
182 def cloudRegion = vimId.split("_")
183 def cloudOwner = cloudRegion[0].toString()
184 def cloudRegionId = cloudRegion[1].toString()
185 execution.setVariable("cloudOwner", cloudOwner)
186 utils.log("DEBUG","cloudOwner: " + cloudOwner, isDebugEnabled)
187 execution.setVariable("cloudRegionId", cloudRegionId)
188 utils.log("DEBUG","cloudRegionId: " + cloudRegionId, isDebugEnabled)
191 * Extracting User Parameters from incoming Request and converting into a Map
193 def jsonSlurper = new JsonSlurper()
195 Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest)
198 def userParams = reqMap.requestDetails?.requestParameters?.userParams
200 Map<String, String> inputMap = [:]
204 if ("Customer_Location".equals(userParam?.name)) {
205 Map<String, String> customerMap = [:]
206 userParam.value.each {
209 inputMap.put(param.key, param.value)
210 customerMap.put(param.key, param.value)
212 execution.setVariable("customerLocation", customerMap)
214 if ("Homing_Model_Ids".equals(userParam?.name)) {
215 utils.log("DEBUG", "Homing_Model_Ids: " + userParam.value.toString() + " ---- Type is:" +
216 userParam.value.getClass() , isDebugEnabled)
218 userParam.value.each {
223 valueMap.put(entry.key, entry.value)
225 modelIdLst.add(valueMap)
226 utils.log("DEBUG", "Param: " + param.toString() + " ---- Type is:" +
227 param.getClass() , isDebugEnabled)
229 execution.setVariable("homingModelIds", modelIdLst)
231 if ("BRG_WAN_MAC_Address".equals(userParam?.name)) {
232 execution.setVariable("brgWanMacAddress", userParam.value)
233 inputMap.put("BRG_WAN_MAC_Address", userParam.value)
235 if ("Homing_Solution".equals(userParam?.name)) {
236 execution.setVariable("homingService", userParam.value)
237 execution.setVariable("callHoming", true)
238 inputMap.put("Homing_Solution", userParam.value)
243 if (execution.getVariable("homingService") == "") {
244 // Set Default Homing to OOF if not set
245 execution.setVariable("homingService", "oof")
248 msoLogger.debug("User Input Parameters map: " + userParams.toString())
249 execution.setVariable("serviceInputParams", inputMap)
251 msoLogger.debug("Incoming brgWanMacAddress is: " + execution.getVariable('brgWanMacAddress'))
253 //For Completion Handler & Fallout Handler
255 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
256 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
257 <action>CREATE</action>
258 <source>${MsoUtils.xmlEscape(source)}</source>
261 execution.setVariable(Prefix + "requestInfo", requestInfo)
263 msoLogger.trace("Completed preProcessRequest CreateVcpeResCustService Request ")
265 } catch (BpmnError e) {
268 } catch (Exception ex) {
269 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
270 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
274 public void sendSyncResponse(DelegateExecution execution) {
276 msoLogger.trace("Inside sendSyncResponse of CreateVcpeResCustService ")
279 String serviceInstanceId = execution.getVariable("serviceInstanceId")
280 String requestId = execution.getVariable("mso-request-id")
282 // RESTResponse (for API Handler (APIH) Reply Task)
283 String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${
287 msoLogger.debug(" sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
288 sendWorkflowResponse(execution, 202, syncResponse)
290 } catch (Exception ex) {
291 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
292 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
296 // *******************************
298 // *******************************
299 public void prepareDecomposeService(DelegateExecution execution) {
302 msoLogger.trace("Inside prepareDecomposeService of CreateVcpeResCustService ")
304 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
306 //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB
307 String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.modelInfo")
308 execution.setVariable("serviceModelInfo", serviceModelInfo)
310 msoLogger.trace("Completed prepareDecomposeService of CreateVcpeResCustService ")
311 } catch (Exception ex) {
312 // try error in method block
313 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
314 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
318 // *******************************
320 // *******************************
321 public void prepareCreateServiceInstance(DelegateExecution execution) {
324 msoLogger.trace("Inside prepareCreateServiceInstance of CreateVcpeResCustService ")
327 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
328 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
329 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
332 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
333 // String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters")
334 // execution.setVariable("serviceInputParams", serviceInputParams)
337 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
338 execution.setVariable("serviceInstanceName", serviceInstanceName)
340 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
341 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonStringNoRootName())
343 msoLogger.trace("Completed prepareCreateServiceInstance of CreateVcpeResCustService ")
344 } catch (Exception ex) {
345 // try error in method block
346 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
347 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
351 public void postProcessServiceInstanceCreate(DelegateExecution execution) {
352 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' + 'execution=' + execution.getId() + ')'
353 msoLogger.trace('Entered ' + method)
355 String requestId = execution.getVariable("mso-request-id")
356 String serviceInstanceId = execution.getVariable("serviceInstanceId")
357 String serviceInstanceName = execution.getVariable("serviceInstanceName")
362 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
365 <req:updateInfraRequest>
366 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
367 <lastModifiedBy>BPEL</lastModifiedBy>
368 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
369 <serviceInstanceName>${MsoUtils.xmlEscape(serviceInstanceName)}</serviceInstanceName>
370 </req:updateInfraRequest>
374 execution.setVariable(Prefix + "setUpdateDbInstancePayload", payload)
375 msoLogger.debug(Prefix + "setUpdateDbInstancePayload: " + payload)
376 msoLogger.trace('Exited ' + method)
378 } catch (BpmnError e) {
380 } catch (Exception e) {
381 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
382 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
387 public void processDecomposition(DelegateExecution execution) {
389 msoLogger.trace("Inside processDecomposition() of CreateVcpeResCustService ")
393 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
396 List<VnfResource> vnfList = serviceDecomposition.getVnfResources()
398 serviceDecomposition.setVnfResources(vnfList)
400 execution.setVariable("vnfList", vnfList)
401 execution.setVariable("vnfListString", vnfList.toString())
403 String vnfModelInfoString = ""
404 if (vnfList != null && vnfList.size() > 0) {
405 execution.setVariable(Prefix + "VNFsCount", vnfList.size())
406 msoLogger.debug("vnfs to create: " + vnfList.size())
407 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
409 vnfModelInfoString = vnfModelInfo.toString()
410 String vnfModelInfoWithRoot = vnfModelInfo.toString()
411 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
413 execution.setVariable(Prefix + "VNFsCount", 0)
414 msoLogger.debug("no vnfs to create based upon serviceDecomposition content")
417 execution.setVariable("vnfModelInfo", vnfModelInfoString)
418 execution.setVariable("vnfModelInfoString", vnfModelInfoString)
419 msoLogger.debug(" vnfModelInfoString :" + vnfModelInfoString)
421 msoLogger.trace("Completed processDecomposition() of CreateVcpeResCustService ")
422 } catch (Exception ex) {
423 sendSyncError(execution)
424 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. processDecomposition() - " + ex.getMessage()
425 msoLogger.debug(exceptionMessage)
426 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
430 private void filterVnfs(List<VnfResource> vnfList) {
431 if (vnfList == null) {
435 // remove BRG & TXC from VNF list
437 Iterator<VnfResource> it = vnfList.iterator()
438 while (it.hasNext()) {
439 VnfResource vr = it.next()
441 String role = vr.getNfRole()
442 if (role == "BRG" || role == "TunnelXConn" || role == "Tunnel XConn") {
449 public void prepareCreateAllottedResourceTXC(DelegateExecution execution) {
452 msoLogger.trace("Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ")
455 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
456 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
457 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
460 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
462 //allottedResourceModelInfo
463 //allottedResourceRole
464 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
465 //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.
466 List<AllottedResource> allottedResources = serviceDecomposition.getAllottedResources()
467 if (allottedResources != null) {
468 Iterator iter = allottedResources.iterator();
469 while (iter.hasNext()) {
470 AllottedResource allottedResource = (AllottedResource) iter.next();
472 msoLogger.debug(" getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName())
473 msoLogger.debug(" allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType())
474 if ("TunnelXConn".equalsIgnoreCase(allottedResource.getAllottedResourceType()) || "Tunnel XConn".equalsIgnoreCase(allottedResource.getAllottedResourceType())) {
475 //set create flag to true
476 execution.setVariable("createTXCAR", true)
477 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
478 execution.setVariable("allottedResourceModelInfoTXC", allottedResourceModelInfo.toJsonStringNoRootName())
479 execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())
480 execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())
481 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the TXC,
482 //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).
483 execution.setVariable("parentServiceInstanceIdTXC", allottedResource.getHomingSolution().getServiceInstanceId())
489 String allottedResourceId = execution.getVariable("allottedResourceId")
490 execution.setVariable("allottedResourceIdTXC", allottedResourceId)
491 msoLogger.debug("setting allottedResourceId CreateVcpeResCustService " + allottedResourceId)
493 msoLogger.trace("Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ")
494 } catch (Exception ex) {
495 // try error in method block
496 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
497 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
501 public void prepareCreateAllottedResourceBRG(DelegateExecution execution) {
504 msoLogger.trace("Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ")
507 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
508 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
509 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
512 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
514 //allottedResourceModelInfo
515 //allottedResourceRole
516 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
517 //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.
518 List<AllottedResource> allottedResources = serviceDecomposition.getAllottedResources()
519 if (allottedResources != null) {
520 Iterator iter = allottedResources.iterator();
521 while (iter.hasNext()) {
522 AllottedResource allottedResource = (AllottedResource) iter.next();
524 msoLogger.debug(" getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName())
525 msoLogger.debug(" allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType())
526 if ("BRG".equalsIgnoreCase(allottedResource.getAllottedResourceType())) {
527 //set create flag to true
528 execution.setVariable("createBRGAR", true)
529 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
530 execution.setVariable("allottedResourceModelInfoBRG", allottedResourceModelInfo.toJsonStringNoRootName())
531 execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())
532 execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())
533 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the BRG,
534 //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).
535 execution.setVariable("parentServiceInstanceIdBRG", allottedResource.getHomingSolution().getServiceInstanceId())
541 String allottedResourceId = execution.getVariable("allottedResourceId")
542 execution.setVariable("allottedResourceIdBRG", allottedResourceId)
543 msoLogger.debug("setting allottedResourceId CreateVcpeResCustService " + allottedResourceId)
545 msoLogger.trace("Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ")
546 } catch (Exception ex) {
547 // try error in method block
548 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
549 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
553 // *******************************
554 // Generate Network request Section
555 // *******************************
556 public void prepareVnfAndModulesCreate(DelegateExecution execution) {
559 msoLogger.trace("Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ")
561 // String disableRollback = execution.getVariable("disableRollback")
562 // def backoutOnFailure = ""
563 // if(disableRollback != null){
564 // if ( disableRollback == true) {
565 // backoutOnFailure = "false"
566 // } else if ( disableRollback == false) {
567 // backoutOnFailure = "true"
570 //failIfExists - optional
572 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
573 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
574 execution.setVariable("productFamilyId", productFamilyId)
575 msoLogger.debug("productFamilyId: " + productFamilyId)
577 List<VnfResource> vnfList = execution.getVariable("vnfList")
579 Integer vnfsCreatedCount = execution.getVariable(Prefix + "VnfsCreatedCount")
580 String vnfModelInfoString = null;
582 if (vnfList != null && vnfList.size() > 0) {
583 msoLogger.debug("getting model info for vnf # " + vnfsCreatedCount)
584 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
585 msoLogger.debug("got 0 ")
586 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
587 vnfModelInfoString = vnfModelInfo.toString()
589 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored
590 vnfModelInfoString = execution.getVariable("vnfModelInfo")
593 msoLogger.debug(" vnfModelInfoString :" + vnfModelInfoString)
595 // extract cloud configuration
596 String vimId = jsonUtil.getJsonValue(createVcpeServiceRequest,
597 "requestDetails.cloudConfiguration.lcpCloudRegionId")
598 def cloudRegion = vimId.split("_")
599 execution.setVariable("cloudOwner", cloudRegion[0])
600 msoLogger.debug("cloudOwner: "+ cloudRegion[0])
601 execution.setVariable("cloudRegionId", cloudRegion[1])
602 msoLogger.debug("cloudRegionId: "+ cloudRegion[1])
603 execution.setVariable("lcpCloudRegionId", cloudRegion[1])
604 msoLogger.debug("lcpCloudRegionId: "+ cloudRegion[1])
605 String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest,
606 "requestDetails.cloudConfiguration.tenantId")
607 execution.setVariable("tenantId", tenantId)
608 msoLogger.debug("tenantId: " + tenantId)
610 String sdncVersion = execution.getVariable("sdncVersion")
611 msoLogger.debug("sdncVersion: " + sdncVersion)
613 msoLogger.trace("Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ")
614 } catch (Exception ex) {
615 // try error in method block
616 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
617 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
621 // *******************************
622 // Validate Vnf request Section -> increment count
623 // *******************************
624 public void validateVnfCreate(DelegateExecution execution) {
627 msoLogger.trace("Inside validateVnfCreate of CreateVcpeResCustService ")
629 Integer vnfsCreatedCount = execution.getVariable(Prefix + "VnfsCreatedCount")
632 execution.setVariable(Prefix + "VnfsCreatedCount", vnfsCreatedCount)
634 msoLogger.debug(" ***** Completed validateVnfCreate of CreateVcpeResCustService ***** " + " vnf # " + vnfsCreatedCount)
635 } catch (Exception ex) {
636 // try error in method block
637 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
638 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
642 // *****************************************
643 // Prepare Completion request Section
644 // *****************************************
645 public void postProcessResponse(DelegateExecution execution) {
647 msoLogger.trace("Inside postProcessResponse of CreateVcpeResCustService ")
650 String source = execution.getVariable("source")
651 String requestId = execution.getVariable("mso-request-id")
652 String serviceInstanceId = execution.getVariable("serviceInstanceId")
654 String msoCompletionRequest =
655 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
656 xmlns:ns="http://org.onap/so/request/types/v1">
657 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
658 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
659 <action>CREATE</action>
660 <source>${MsoUtils.xmlEscape(source)}</source>
662 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
663 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
664 <mso-bpel-name>BPMN macro create</mso-bpel-name>
665 </aetgt:MsoCompletionRequest>"""
668 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
670 msoLogger.debug(xmlMsoCompletionRequest)
671 execution.setVariable(Prefix + "Success", true)
672 execution.setVariable(Prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest)
673 msoLogger.debug(" SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
674 } catch (BpmnError e) {
676 } catch (Exception ex) {
677 // try error in method block
678 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
679 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
683 public void preProcessRollback(DelegateExecution execution) {
684 msoLogger.trace("preProcessRollback of CreateVcpeResCustService ")
687 Object workflowException = execution.getVariable("WorkflowException");
689 if (workflowException instanceof WorkflowException) {
690 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
691 execution.setVariable("prevWorkflowException", workflowException);
692 //execution.setVariable("WorkflowException", null);
694 } catch (BpmnError e) {
695 msoLogger.debug("BPMN Error during preProcessRollback")
696 } catch (Exception ex) {
697 String msg = "Exception in preProcessRollback. " + ex.getMessage()
700 msoLogger.trace("Exit preProcessRollback of CreateVcpeResCustService ")
703 public void postProcessRollback(DelegateExecution execution) {
704 msoLogger.trace("postProcessRollback of CreateVcpeResCustService ")
707 Object workflowException = execution.getVariable("prevWorkflowException");
708 if (workflowException instanceof WorkflowException) {
709 msoLogger.debug("Setting prevException to WorkflowException: ")
710 execution.setVariable("WorkflowException", workflowException);
712 } catch (BpmnError b) {
713 msoLogger.debug("BPMN Error during postProcessRollback")
715 } catch (Exception ex) {
716 msg = "Exception in postProcessRollback. " + ex.getMessage()
719 msoLogger.trace("Exit postProcessRollback of CreateVcpeResCustService ")
722 public void prepareFalloutRequest(DelegateExecution execution) {
724 msoLogger.trace("STARTED CreateVcpeResCustService prepareFalloutRequest Process ")
727 WorkflowException wfex = execution.getVariable("WorkflowException")
728 msoLogger.debug(" Incoming Workflow Exception: " + wfex.toString())
729 String requestInfo = execution.getVariable(Prefix + "requestInfo")
730 msoLogger.debug(" Incoming Request Info: " + requestInfo)
732 //TODO. hmmm. there is no way to UPDATE error message.
733 // String errorMessage = wfex.getErrorMessage()
734 // boolean successIndicator = execution.getVariable("DCRESI_rolledBack")
735 // if (successIndicator){
736 // errorMessage = errorMessage + ". Rollback successful."
738 // errorMessage = errorMessage + ". Rollback not completed."
741 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
743 execution.setVariable(Prefix + "falloutRequest", falloutRequest)
745 } catch (Exception ex) {
746 msoLogger.debug("Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage())
747 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")
749 msoLogger.trace("COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ")
753 public void sendSyncError(DelegateExecution execution) {
754 execution.setVariable("prefix", Prefix)
756 msoLogger.trace("Inside sendSyncError() of CreateVcpeResCustService ")
759 String errorMessage = ""
760 def wfe = execution.getVariable("WorkflowException")
761 if (wfe instanceof WorkflowException) {
762 errorMessage = wfe.getErrorMessage()
764 errorMessage = "Sending Sync Error."
767 String buildworkflowException =
768 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
769 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
770 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
771 </aetgt:WorkflowException>"""
773 msoLogger.debug(buildworkflowException)
774 sendWorkflowResponse(execution, 500, buildworkflowException)
775 } catch (Exception ex) {
776 msoLogger.debug(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
780 public void processJavaException(DelegateExecution execution) {
781 execution.setVariable("prefix", Prefix)
783 msoLogger.debug("Caught a Java Exception")
784 msoLogger.debug("Started processJavaException Method")
785 msoLogger.debug("Variables List: " + execution.getVariables())
786 execution.setVariable(Prefix + "unexpectedError", "Caught a Java Lang Exception")
787 // Adding this line temporarily until this flows error handling gets updated
788 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
789 } catch (BpmnError b) {
790 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Rethrowing MSOWorkflowException", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
792 } catch (Exception e) {
793 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
794 execution.setVariable(Prefix + "unexpectedError", "Exception in processJavaException method")
795 // Adding this line temporarily until this flows error handling gets updated
796 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
798 msoLogger.debug("Completed processJavaException Method")