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.openecomp.mso.bpmn.vcpe.scripts;
22 import groovy.xml.XmlUtil
25 import org.openecomp.mso.bpmn.core.json.JsonUtils
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
29 import org.openecomp.mso.bpmn.common.scripts.VidUtils
30 import org.openecomp.mso.bpmn.core.RollbackData
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.bpmn.core.domain.*
34 import java.util.UUID;
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.runtime.Execution
38 import org.json.JSONObject;
39 import org.json.JSONArray;
40 import org.apache.commons.lang3.*
41 import org.apache.commons.codec.binary.Base64;
42 import org.springframework.web.util.UriUtils;
43 import static org.apache.commons.lang3.StringUtils.*
46 * This groovy class supports the <class>CreateVcpeResCustService.bpmn</class> process.
51 public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
53 private static final String DebugFlag = "isDebugLogEnabled"
55 String Prefix="CVRCS_"
56 ExceptionUtil exceptionUtil = new ExceptionUtil()
57 JsonUtils jsonUtil = new JsonUtils()
58 VidUtils vidUtils = new VidUtils()
59 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
62 * This method is executed during the preProcessRequest task of the
63 * <class>CreateServiceInstance.bpmn</class> process.
66 public InitializeProcessVariables(Execution 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", "")
79 execution.setVariable("sdncVersion", "1707")
82 // **************************************************
83 // Pre or Prepare Request Section
84 // **************************************************
86 * This method is executed during the preProcessRequest task of the
87 * <class>CreateServiceInstance.bpmn</class> process.
90 public void preProcessRequest (Execution execution) {
91 def isDebugEnabled=execution.getVariable(DebugFlag)
92 execution.setVariable("prefix",Prefix)
94 utils.log("DEBUG", " ***** Inside preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
97 // initialize flow variables
98 InitializeProcessVariables(execution)
101 String aaiDistDelay = execution.getVariable('URN_mso_workflow_aai_distribution_delay')
102 if (isBlank(aaiDistDelay)) {
103 msg = "URN_mso_workflow_aai_distribution_delay is null"
104 utils.log("DEBUG", msg, isDebugEnabled)
105 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 execution.setVariable("aaiDistDelay", aaiDistDelay)
108 utils.log("DEBUG","AAI distribution delay: " + aaiDistDelay, isDebugEnabled)
110 // check for incoming json message/input
111 String createVcpeServiceRequest = execution.getVariable("bpmnRequest")
112 utils.logAudit(createVcpeServiceRequest)
113 execution.setVariable("createVcpeServiceRequest", createVcpeServiceRequest);
114 println 'createVcpeServiceRequest - ' + createVcpeServiceRequest
117 String requestId = execution.getVariable("mso-request-id")
118 execution.setVariable("msoRequestId", requestId)
120 String serviceInstanceId = execution.getVariable("serviceInstanceId")
122 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
123 serviceInstanceId = UUID.randomUUID().toString()
124 utils.log("DEBUG", " Generated new Service Instance: " + serviceInstanceId , isDebugEnabled)
126 utils.log("DEBUG", "Using provided Service Instance ID: " + serviceInstanceId , isDebugEnabled)
129 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
130 execution.setVariable("serviceInstanceId", serviceInstanceId)
132 String requestAction = execution.getVariable("requestAction")
133 execution.setVariable("requestAction", requestAction)
135 setBasicDBAuthHeader(execution, isDebugEnabled)
137 String source = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.source")
138 if ((source == null) || (source.isEmpty())) {
141 execution.setVariable("source", source)
143 // extract globalSubscriberId
144 String globalSubscriberId = jsonUtil.getJsonValue(createVcpeServiceRequest,
145 "requestDetails.subscriberInfo.globalSubscriberId")
147 // verify element global-customer-id is sent from JSON input, throw exception if missing
148 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
149 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
150 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
153 execution.setVariable("globalSubscriberId", globalSubscriberId)
154 execution.setVariable("globalCustomerId", globalSubscriberId)
157 // extract subscriptionServiceType
158 String subscriptionServiceType = jsonUtil.getJsonValue(createVcpeServiceRequest,
159 "requestDetails.requestParameters.subscriptionServiceType")
160 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
161 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
163 String suppressRollback = jsonUtil.getJsonValue(createVcpeServiceRequest,
164 "requestDetails.requestInfo.suppressRollback")
165 execution.setVariable("disableRollback", suppressRollback)
166 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
168 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest,
169 "requestDetails.requestInfo.productFamilyId")
170 execution.setVariable("productFamilyId", productFamilyId)
171 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
173 String subscriberInfo = jsonUtil.getJsonValue(createVcpeServiceRequest,
174 "requestDetails.subscriberInfo")
175 execution.setVariable("subscriberInfo", subscriberInfo)
176 utils.log("DEBUG", "Incoming subscriberInfo is: " + subscriberInfo, isDebugEnabled)
179 * Extracting User Parameters from incoming Request and converting into a Map
181 def jsonSlurper = new JsonSlurper()
182 def jsonOutput = new JsonOutput()
184 Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest)
188 def userParams = reqMap.requestDetails?.requestParameters?.userParams
190 Map<String, String> inputMap = [:]
196 if("BRG_WAN_MAC_Address".equals(userParam?.name)) {
197 execution.setVariable("brgWanMacAddress", userParam.value)
198 inputMap.put("BRG_WAN_MAC_Address", userParam.value)
200 if("Customer_Location".equals(userParam?.name)) {
201 execution.setVariable("customerLocation", userParam.value)
202 userParam.value.each {
204 inputMap.put(customerLocParam.key, customerLocParam.value)
210 utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
211 execution.setVariable("serviceInputParams", inputMap)
213 utils.log("DEBUG", "Incoming brgWanMacAddress is: " +
214 execution.getVariable('brgWanMacAddress'), isDebugEnabled)
215 utils.log("DEBUG", "Incoming customerLocation is: " +
216 execution.getVariable('customerLocation'), isDebugEnabled)
218 //For Completion Handler & Fallout Handler
220 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
221 <request-id>${requestId}</request-id>
222 <action>CREATE</action>
223 <source>${source}</source>
226 execution.setVariable(Prefix+"requestInfo", requestInfo)
229 " ***** Completed preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
231 } catch (BpmnError e) {
234 } catch (Exception ex){
235 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow." +
236 " Unexpected from method preProcessRequest() - " + ex.getMessage()
237 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
241 public void sendSyncResponse(Execution execution) {
242 def isDebugEnabled=execution.getVariable(DebugFlag)
244 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
247 String serviceInstanceId = execution.getVariable("serviceInstanceId")
248 String requestId = execution.getVariable("mso-request-id")
250 // RESTResponse (for API Handler (APIH) Reply Task)
251 String syncResponse ="""{"requestReferences":{
252 "instanceId":"${serviceInstanceId}",
253 "requestId":"${requestId}"
256 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
257 sendWorkflowResponse(execution, 202, syncResponse)
259 } catch (Exception ex) {
260 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. " +
261 "Unexpected from method sendSyncResponse() - " + ex.getMessage()
262 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
266 // *******************************
268 // *******************************
269 public void prepareDecomposeService(Execution execution) {
270 def isDebugEnabled=execution.getVariable(DebugFlag)
274 " ***** Inside prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
276 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
278 //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB
279 String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest,
280 "requestDetails.modelInfo")
281 execution.setVariable("serviceModelInfo", serviceModelInfo)
284 " ***** Completed prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
285 } catch (Exception ex) {
286 // try error in method block
287 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. " +
288 "Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
289 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
293 // *******************************
295 // *******************************
296 public void prepareCreateServiceInstance(Execution execution) {
297 def isDebugEnabled=execution.getVariable(DebugFlag)
301 " ***** Inside prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
304 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from
305 * DecompositionObject
306 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
307 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
310 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
311 // String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest,
312 // "requestDetails.requestParameters")
313 // execution.setVariable("serviceInputParams", serviceInputParams)
316 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest,
317 "requestDetails.requestInfo.instanceName")
318 execution.setVariable("serviceInstanceName", serviceInstanceName)
320 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
321 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonStringNoRootName())
324 " ***** Completed prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
325 } catch (Exception ex) {
326 // try error in method block
327 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. " +
328 "Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
329 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
333 public void postProcessServiceInstanceCreate (Execution execution){
334 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +
335 'execution=' + execution.getId() +')'
336 def isDebugLogEnabled = execution.getVariable(DebugFlag)
337 logDebug('Entered ' + method, isDebugLogEnabled)
339 String requestId = execution.getVariable("mso-request-id")
340 String serviceInstanceId = execution.getVariable("serviceInstanceId")
341 String serviceInstanceName = execution.getVariable("serviceInstanceName")
346 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
347 xmlns:req="http://org.openecomp.mso/requestsdb">
350 <req:updateInfraRequest>
351 <requestId>${requestId}</requestId>
352 <lastModifiedBy>BPEL</lastModifiedBy>
353 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
354 <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>
355 </req:updateInfraRequest>
359 execution.setVariable(Prefix+"setUpdateDbInstancePayload", payload)
360 utils.logAudit(Prefix+"setUpdateDbInstancePayload: " + payload)
361 logDebug('Exited ' + method, isDebugLogEnabled)
363 } catch (BpmnError e) {
365 } catch (Exception e) {
366 logError('Caught exception in ' + method, e)
367 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
372 public void processDecomposition (Execution execution) {
373 def isDebugEnabled=execution.getVariable(DebugFlag)
375 utils.log("DEBUG", " ***** Inside processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
379 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
382 List<VnfResource> vnfList = serviceDecomposition.getServiceVnfs()
384 serviceDecomposition.setServiceVnfs(vnfList)
386 execution.setVariable("vnfList", vnfList)
387 execution.setVariable("vnfListString", vnfList.toString())
389 String vnfModelInfoString = ""
390 if (vnfList != null && vnfList.size() > 0) {
391 execution.setVariable(Prefix+"VNFsCount", vnfList.size())
392 utils.log("DEBUG", "vnfs to create: "+ vnfList.size(), isDebugEnabled)
393 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
395 vnfModelInfoString = vnfModelInfo.toString()
396 String vnfModelInfoWithRoot = vnfModelInfo.toString()
397 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
399 execution.setVariable(Prefix+"VNFsCount", 0)
400 utils.log("DEBUG", "no vnfs to create based upon serviceDecomposition content", isDebugEnabled)
403 execution.setVariable("vnfModelInfo", vnfModelInfoString)
404 execution.setVariable("vnfModelInfoString", vnfModelInfoString)
405 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
408 " ***** Completed processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
409 } catch (Exception ex) {
410 sendSyncError(execution)
411 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. " +
412 "processDecomposition() - " + ex.getMessage()
413 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
414 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
418 private void filterVnfs(List<VnfResource> vnfList) {
419 if(vnfList == null) {
423 // remove BRG & TXC from VNF list
425 Iterator<VnfResource> it = vnfList.iterator()
426 while(it.hasNext()) {
427 VnfResource vr = it.next()
429 String role = vr.getNfRole()
430 if(role == "BRG" || role == "TunnelXConn") {
437 public void prepareCreateAllottedResourceTXC(Execution execution) {
438 def isDebugEnabled=execution.getVariable(DebugFlag)
442 " ***** Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
445 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from
446 * DecompositionObject
447 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
448 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
451 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
452 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
454 //allottedResourceModelInfo
455 //allottedResourceRole
456 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
457 //It would be sufficient to only include the service model UUID (i.e. the modelVersionId), since this
458 //BB will query the full model from the Catalog DB.
459 List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
460 if (allottedResources != null) {
461 Iterator iter = allottedResources.iterator();
462 while (iter.hasNext()){
463 AllottedResource allottedResource = (AllottedResource)iter.next();
465 utils.log("DEBUG", " getting model info for AllottedResource # :" +
466 allottedResource.toJsonStringNoRootName(), isDebugEnabled)
467 utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" +
468 allottedResource.getAllottedResourceType(), isDebugEnabled)
469 if("TunnelXConn".equalsIgnoreCase(allottedResource.getAllottedResourceType())){
470 //set create flag to true
471 execution.setVariable("createTXCAR", true)
472 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
473 execution.setVariable("allottedResourceModelInfoTXC",
474 allottedResourceModelInfo.toJsonStringNoRootName())
475 execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())
476 execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())
477 //After decomposition and homing BBs, there should be an allotted resource object in the
478 // decomposition that represents the TXC,
479 //and in its homingSolution section should be found the infraServiceInstanceId
480 // (i.e. infraServiceInstanceId in TXC Allotted Resource structure) (which the Homing
481 // BB would have populated).
482 execution.setVariable("parentServiceInstanceIdTXC",
483 allottedResource.getHomingSolution().getServiceInstanceId())
489 String allottedResourceId = execution.getVariable("allottedResourceId")
490 execution.setVariable("allottedResourceIdTXC", allottedResourceId)
492 "setting allottedResourceId CreateVcpeResCustService "+ allottedResourceId, isDebugEnabled)
495 " ***** Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ",
497 } catch (Exception ex) {
498 // try error in method block
499 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. " +
500 "Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
501 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
504 public void prepareCreateAllottedResourceBRG(Execution execution) {
505 def isDebugEnabled=execution.getVariable(DebugFlag)
509 " ***** Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
512 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from
513 * DecompositionObject
514 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
515 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
518 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
519 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
521 //allottedResourceModelInfo
522 //allottedResourceRole
523 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
524 //It would be sufficient to only include the service model UUID (i.e. the modelVersionId), since this
525 // BB will query the full model from the Catalog DB.
526 List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
527 if (allottedResources != null) {
528 Iterator iter = allottedResources.iterator();
529 while (iter.hasNext()){
530 AllottedResource allottedResource = (AllottedResource)iter.next();
532 utils.log("DEBUG", " getting model info for AllottedResource # :" +
533 allottedResource.toJsonStringNoRootName(), isDebugEnabled)
534 utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" +
535 allottedResource.getAllottedResourceType(), isDebugEnabled)
536 if("BRG".equalsIgnoreCase(allottedResource.getAllottedResourceType())){
537 //set create flag to true
538 execution.setVariable("createBRGAR", true)
539 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
540 execution.setVariable("allottedResourceModelInfoBRG",
541 allottedResourceModelInfo.toJsonStringNoRootName())
542 execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())
543 execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())
544 //After decomposition and homing BBs, there should be an allotted resource object in the
545 // decomposition that represents the BRG,
546 //and in its homingSolution section should be found the infraServiceInstanceId
547 // (i.e. infraServiceInstanceId in BRG Allotted Resource structure) (which the Homing
548 // BB would have populated).
549 execution.setVariable("parentServiceInstanceIdBRG",
550 allottedResource.getHomingSolution().getServiceInstanceId())
556 String allottedResourceId = execution.getVariable("allottedResourceId")
557 execution.setVariable("allottedResourceIdBRG", allottedResourceId)
559 "setting allottedResourceId CreateVcpeResCustService " + allottedResourceId, isDebugEnabled)
562 " ***** Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ",
564 } catch (Exception ex) {
565 // try error in method block
566 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. " +
567 "Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
568 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
574 // *******************************
575 // Generate Network request Section
576 // *******************************
577 public void prepareVnfAndModulesCreate (Execution execution) {
578 def isDebugEnabled=execution.getVariable(DebugFlag)
582 " ***** Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
584 // String disableRollback = execution.getVariable("disableRollback")
585 // def backoutOnFailure = ""
586 // if(disableRollback != null){
587 // if ( disableRollback == true) {
588 // backoutOnFailure = "false"
589 // } else if ( disableRollback == false) {
590 // backoutOnFailure = "true"
593 //failIfExists - optional
595 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
596 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest,
597 "requestDetails.requestInfo.productFamilyId")
598 execution.setVariable("productFamilyId", productFamilyId)
599 utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)
601 List<VnfResource> vnfList = execution.getVariable("vnfList")
603 Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")
604 String vnfModelInfoString = null;
606 if (vnfList != null && vnfList.size() > 0 ) {
607 utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)
608 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
609 utils.log("DEBUG", "got 0 ", isDebugEnabled)
610 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
611 vnfModelInfoString = vnfModelInfo.toString()
613 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored
614 vnfModelInfoString = execution.getVariable("vnfModelInfo")
617 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
619 // extract cloud configuration
620 String lcpCloudRegionId = jsonUtil.getJsonValue(createVcpeServiceRequest,
621 "requestDetails.cloudConfiguration.lcpCloudRegionId")
622 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
623 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
624 String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest,
625 "requestDetails.cloudConfiguration.tenantId")
626 execution.setVariable("tenantId", tenantId)
627 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
629 String sdncVersion = execution.getVariable("sdncVersion")
630 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
633 " ***** Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
634 } catch (Exception ex) {
635 // try error in method block
636 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. " +
637 "Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
638 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
642 // *******************************
643 // Validate Vnf request Section -> increment count
644 // *******************************
645 public void validateVnfCreate (Execution execution) {
646 def isDebugEnabled=execution.getVariable(DebugFlag)
649 utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
651 Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")
654 execution.setVariable(Prefix+"VnfsCreatedCount", vnfsCreatedCount)
657 " ***** Completed validateVnfCreate of CreateVcpeResCustService ***** "+" vnf # "+vnfsCreatedCount, isDebugEnabled)
658 } catch (Exception ex) {
659 // try error in method block
660 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. " +
661 "Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
662 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
666 // *****************************************
667 // Prepare Completion request Section
668 // *****************************************
669 public void postProcessResponse (Execution execution) {
670 def isDebugEnabled=execution.getVariable(DebugFlag)
672 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
675 String source = execution.getVariable("source")
676 String requestId = execution.getVariable("mso-request-id")
677 String serviceInstanceId = execution.getVariable("serviceInstanceId")
679 String msoCompletionRequest =
680 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
681 xmlns:ns="http://org.openecomp/mso/request/types/v1">
682 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
683 <request-id>${requestId}</request-id>
684 <action>CREATE</action>
685 <source>${source}</source>
687 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
688 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
689 <mso-bpel-name>BPMN macro create</mso-bpel-name>
690 </aetgt:MsoCompletionRequest>"""
693 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
695 utils.logAudit(xmlMsoCompletionRequest)
696 execution.setVariable(Prefix+"Success", true)
697 execution.setVariable(Prefix+"CompleteMsoProcessRequest", xmlMsoCompletionRequest)
698 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
699 } catch (BpmnError e) {
701 } catch (Exception ex) {
702 // try error in method block
703 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. " +
704 "Unexpected Error from method postProcessResponse() - " + ex.getMessage()
705 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
709 public void preProcessRollback (Execution execution) {
710 def isDebugEnabled=execution.getVariable(DebugFlag)
711 utils.log("DEBUG"," ***** preProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
714 Object workflowException = execution.getVariable("WorkflowException");
716 if (workflowException instanceof WorkflowException) {
717 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
718 execution.setVariable("prevWorkflowException", workflowException);
719 //execution.setVariable("WorkflowException", null);
721 } catch (BpmnError e) {
722 utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
723 } catch(Exception ex) {
724 String msg = "Exception in preProcessRollback. " + ex.getMessage()
725 utils.log("DEBUG", msg, isDebugEnabled)
727 utils.log("DEBUG"," *** Exit preProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
730 public void postProcessRollback (Execution execution) {
731 def isDebugEnabled=execution.getVariable(DebugFlag)
732 utils.log("DEBUG"," ***** postProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
735 Object workflowException = execution.getVariable("prevWorkflowException");
736 if (workflowException instanceof WorkflowException) {
737 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
738 execution.setVariable("WorkflowException", workflowException);
740 } catch (BpmnError b) {
741 utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
743 } catch(Exception ex) {
744 msg = "Exception in postProcessRollback. " + ex.getMessage()
745 utils.log("DEBUG", msg, isDebugEnabled)
747 utils.log("DEBUG"," *** Exit postProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
750 public void prepareFalloutRequest(Execution execution){
751 def isDebugEnabled=execution.getVariable(DebugFlag)
753 utils.log("DEBUG", " *** STARTED CreateVcpeResCustService prepareFalloutRequest Process *** ", isDebugEnabled)
756 WorkflowException wfex = execution.getVariable("WorkflowException")
757 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
758 String requestInfo = execution.getVariable(Prefix+"requestInfo")
759 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
761 //TODO. hmmm. there is no way to UPDATE error message.
762 // String errorMessage = wfex.getErrorMessage()
763 // boolean successIndicator = execution.getVariable("DCRESI_rolledBack")
764 // if (successIndicator){
765 // errorMessage = errorMessage + ". Rollback successful."
767 // errorMessage = errorMessage + ". Rollback not completed."
770 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
772 execution.setVariable(Prefix+"falloutRequest", falloutRequest)
774 } catch (Exception ex) {
776 "Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage(),
778 exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
779 "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")
782 "*** COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ***", isDebugEnabled)
786 public void sendSyncError (Execution execution) {
787 def isDebugEnabled=execution.getVariable(DebugFlag)
788 execution.setVariable("prefix", Prefix)
790 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateVcpeResCustService ***** ", isDebugEnabled)
793 String errorMessage = ""
794 def wfe = execution.getVariable("WorkflowException")
795 if (wfe instanceof WorkflowException) {
796 errorMessage = wfe.getErrorMessage()
798 errorMessage = "Sending Sync Error."
801 String buildworkflowException =
802 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
803 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
804 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
805 </aetgt:WorkflowException>"""
807 utils.logAudit(buildworkflowException)
808 sendWorkflowResponse(execution, 500, buildworkflowException)
809 } catch (Exception ex) {
810 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
814 public void processJavaException(Execution execution){
815 def isDebugEnabled=execution.getVariable(DebugFlag)
816 execution.setVariable("prefix",Prefix)
818 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
819 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
820 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
821 // Adding below line temporarily until this flows error handling gets updated
822 execution.setVariable(Prefix+"unexpectedError", "Caught a Java Lang Exception")
823 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
825 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
828 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
829 // Adding below line temporarily until this flows error handling gets updated
830 execution.setVariable(Prefix+"unexpectedError", "Exception in processJavaException method")
831 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
833 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)