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.delegate.DelegateExecution
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 <class>CreateServiceInstance.bpmn</class> process.
65 public InitializeProcessVariables(DelegateExecution execution){
66 /* Initialize all the process variables in this block */
68 execution.setVariable("createVcpeServiceRequest", "")
69 execution.setVariable("globalSubscriberId", "")
70 execution.setVariable("serviceInstanceName", "")
71 execution.setVariable("msoRequestId", "")
72 execution.setVariable(Prefix+"VnfsCreatedCount", 0)
73 execution.setVariable("productFamilyId", "")
74 execution.setVariable("brgWanMacAddress", "")
77 execution.setVariable("sdncVersion", "1707")
80 // **************************************************
81 // Pre or Prepare Request Section
82 // **************************************************
84 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
87 public void preProcessRequest (DelegateExecution execution) {
88 def isDebugEnabled=execution.getVariable(DebugFlag)
89 execution.setVariable("prefix",Prefix)
91 utils.log("DEBUG", " ***** Inside preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
94 // initialize flow variables
95 InitializeProcessVariables(execution)
98 String aaiDistDelay = execution.getVariable('URN_mso_workflow_aai_distribution_delay')
99 if (isBlank(aaiDistDelay)) {
100 msg = "URN_mso_workflow_aai_distribution_delay is null"
101 utils.log("DEBUG", msg, isDebugEnabled)
102 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
104 execution.setVariable("aaiDistDelay", aaiDistDelay)
105 utils.log("DEBUG","AAI distribution delay: " + aaiDistDelay, isDebugEnabled)
107 // check for incoming json message/input
108 String createVcpeServiceRequest = execution.getVariable("bpmnRequest")
109 utils.logAudit(createVcpeServiceRequest)
110 execution.setVariable("createVcpeServiceRequest", createVcpeServiceRequest);
111 println 'createVcpeServiceRequest - ' + createVcpeServiceRequest
114 String requestId = execution.getVariable("mso-request-id")
115 execution.setVariable("msoRequestId", requestId)
117 String serviceInstanceId = execution.getVariable("serviceInstanceId")
119 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
120 serviceInstanceId = UUID.randomUUID().toString()
121 utils.log("DEBUG", " Generated new Service Instance: " + serviceInstanceId , isDebugEnabled)
123 utils.log("DEBUG", "Using provided Service Instance ID: " + serviceInstanceId , isDebugEnabled)
126 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
127 execution.setVariable("serviceInstanceId", serviceInstanceId)
129 String requestAction = execution.getVariable("requestAction")
130 execution.setVariable("requestAction", requestAction)
132 setBasicDBAuthHeader(execution, isDebugEnabled)
134 String source = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.source")
135 if ((source == null) || (source.isEmpty())) {
138 execution.setVariable("source", source)
140 // extract globalSubscriberId
141 String globalSubscriberId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
143 // verify element global-customer-id is sent from JSON input, throw exception if missing
144 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
145 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
146 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
149 execution.setVariable("globalSubscriberId", globalSubscriberId)
150 execution.setVariable("globalCustomerId", globalSubscriberId)
153 // extract subscriptionServiceType
154 String subscriptionServiceType = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
155 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
156 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
158 String suppressRollback = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.suppressRollback")
159 execution.setVariable("disableRollback", suppressRollback)
160 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
162 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
163 execution.setVariable("productFamilyId", productFamilyId)
164 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
166 String subscriberInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo")
167 execution.setVariable("subscriberInfo", subscriberInfo)
168 utils.log("DEBUG", "Incoming subscriberInfo is: " + subscriberInfo, isDebugEnabled)
171 * Extracting User Parameters from incoming Request and converting into a Map
173 def jsonSlurper = new JsonSlurper()
174 def jsonOutput = new JsonOutput()
176 Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest)
179 def userParams = reqMap.requestDetails?.requestParameters?.userParams
181 Map<String, String> inputMap = [:]
187 if("BRG_WAN_MAC_Address".equals(userParam?.name)) {
188 execution.setVariable("brgWanMacAddress", userParam.value)
189 inputMap.put("BRG_WAN_MAC_Address", userParam.value)
194 utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
195 execution.setVariable("serviceInputParams", inputMap)
197 utils.log("DEBUG", "Incoming brgWanMacAddress is: " + execution.getVariable('brgWanMacAddress'), isDebugEnabled)
199 //For Completion Handler & Fallout Handler
201 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
202 <request-id>${requestId}</request-id>
203 <action>CREATE</action>
204 <source>${source}</source>
207 execution.setVariable(Prefix+"requestInfo", requestInfo)
209 utils.log("DEBUG", " ***** Completed preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
211 } catch (BpmnError e) {
214 } catch (Exception ex){
215 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
216 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
220 public void sendSyncResponse(DelegateExecution execution) {
221 def isDebugEnabled=execution.getVariable(DebugFlag)
223 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
226 String serviceInstanceId = execution.getVariable("serviceInstanceId")
227 String requestId = execution.getVariable("mso-request-id")
229 // RESTResponse (for API Handler (APIH) Reply Task)
230 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
232 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
233 sendWorkflowResponse(execution, 202, syncResponse)
235 } catch (Exception ex) {
236 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
237 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
241 // *******************************
243 // *******************************
244 public void prepareDecomposeService(DelegateExecution execution) {
245 def isDebugEnabled=execution.getVariable(DebugFlag)
248 utils.log("DEBUG", " ***** Inside prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
250 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
252 //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB
253 String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.modelInfo")
254 execution.setVariable("serviceModelInfo", serviceModelInfo)
256 utils.log("DEBUG", " ***** Completed prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
257 } catch (Exception ex) {
258 // try error in method block
259 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
260 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
264 // *******************************
266 // *******************************
267 public void prepareCreateServiceInstance(DelegateExecution execution) {
268 def isDebugEnabled=execution.getVariable(DebugFlag)
271 utils.log("DEBUG", " ***** Inside prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
274 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
275 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
276 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
279 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
280 // String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters")
281 // execution.setVariable("serviceInputParams", serviceInputParams)
284 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
285 execution.setVariable("serviceInstanceName", serviceInstanceName)
287 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
288 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonStringNoRootName())
290 utils.log("DEBUG", " ***** Completed prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
291 } catch (Exception ex) {
292 // try error in method block
293 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
294 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
298 public void postProcessServiceInstanceCreate (DelegateExecution execution){
299 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +'execution=' + execution.getId() +')'
300 def isDebugLogEnabled = execution.getVariable(DebugFlag)
301 logDebug('Entered ' + method, isDebugLogEnabled)
303 String requestId = execution.getVariable("mso-request-id")
304 String serviceInstanceId = execution.getVariable("serviceInstanceId")
305 String serviceInstanceName = execution.getVariable("serviceInstanceName")
310 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
313 <req:updateInfraRequest>
314 <requestId>${requestId}</requestId>
315 <lastModifiedBy>BPEL</lastModifiedBy>
316 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
317 <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>
318 </req:updateInfraRequest>
322 execution.setVariable(Prefix+"setUpdateDbInstancePayload", payload)
323 utils.logAudit(Prefix+"setUpdateDbInstancePayload: " + payload)
324 logDebug('Exited ' + method, isDebugLogEnabled)
326 } catch (BpmnError e) {
328 } catch (Exception e) {
329 logError('Caught exception in ' + method, e)
330 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
335 public void processDecomposition (DelegateExecution execution) {
336 def isDebugEnabled=execution.getVariable(DebugFlag)
338 utils.log("DEBUG", " ***** Inside processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
342 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
345 List<VnfResource> vnfList = serviceDecomposition.getServiceVnfs()
347 serviceDecomposition.setServiceVnfs(vnfList)
349 execution.setVariable("vnfList", vnfList)
350 execution.setVariable("vnfListString", vnfList.toString())
352 String vnfModelInfoString = ""
353 if (vnfList != null && vnfList.size() > 0) {
354 execution.setVariable(Prefix+"VNFsCount", vnfList.size())
355 utils.log("DEBUG", "vnfs to create: "+ vnfList.size(), isDebugEnabled)
356 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
358 vnfModelInfoString = vnfModelInfo.toString()
359 String vnfModelInfoWithRoot = vnfModelInfo.toString()
360 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
362 execution.setVariable(Prefix+"VNFsCount", 0)
363 utils.log("DEBUG", "no vnfs to create based upon serviceDecomposition content", isDebugEnabled)
366 execution.setVariable("vnfModelInfo", vnfModelInfoString)
367 execution.setVariable("vnfModelInfoString", vnfModelInfoString)
368 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
370 utils.log("DEBUG", " ***** Completed processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
371 } catch (Exception ex) {
372 sendSyncError(execution)
373 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. processDecomposition() - " + ex.getMessage()
374 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
375 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
379 private void filterVnfs(List<VnfResource> vnfList) {
380 if(vnfList == null) {
384 // remove BRG & TXC from VNF list
386 Iterator<VnfResource> it = vnfList.iterator()
387 while(it.hasNext()) {
388 VnfResource vr = it.next()
390 String role = vr.getNfRole()
391 if(role == "BRG" || role == "TunnelXConn") {
398 public void prepareCreateAllottedResourceTXC(DelegateExecution execution) {
399 def isDebugEnabled=execution.getVariable(DebugFlag)
402 utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
405 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
406 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
407 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
410 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
411 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
413 //allottedResourceModelInfo
414 //allottedResourceRole
415 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
416 //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.
417 List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
418 if (allottedResources != null) {
419 Iterator iter = allottedResources.iterator();
420 while (iter.hasNext()){
421 AllottedResource allottedResource = (AllottedResource)iter.next();
423 utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName(), isDebugEnabled)
424 utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)
425 if("TunnelXConn".equalsIgnoreCase(allottedResource.getAllottedResourceType())){
426 //set create flag to true
427 execution.setVariable("createTXCAR", true)
428 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
429 execution.setVariable("allottedResourceModelInfoTXC", allottedResourceModelInfo.toJsonStringNoRootName())
430 execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())
431 execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())
432 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the TXC,
433 //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).
434 execution.setVariable("parentServiceInstanceIdTXC", allottedResource.getHomingSolution().getServiceInstanceId())
440 String allottedResourceId = execution.getVariable("allottedResourceId")
441 execution.setVariable("allottedResourceIdTXC", allottedResourceId)
442 utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)
444 utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
445 } catch (Exception ex) {
446 // try error in method block
447 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
448 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
451 public void prepareCreateAllottedResourceBRG(DelegateExecution execution) {
452 def isDebugEnabled=execution.getVariable(DebugFlag)
455 utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
458 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
459 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
460 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
463 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
464 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
466 //allottedResourceModelInfo
467 //allottedResourceRole
468 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
469 //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.
470 List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
471 if (allottedResources != null) {
472 Iterator iter = allottedResources.iterator();
473 while (iter.hasNext()){
474 AllottedResource allottedResource = (AllottedResource)iter.next();
476 utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName(), isDebugEnabled)
477 utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)
478 if("BRG".equalsIgnoreCase(allottedResource.getAllottedResourceType())){
479 //set create flag to true
480 execution.setVariable("createBRGAR", true)
481 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
482 execution.setVariable("allottedResourceModelInfoBRG", allottedResourceModelInfo.toJsonStringNoRootName())
483 execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())
484 execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())
485 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the BRG,
486 //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).
487 execution.setVariable("parentServiceInstanceIdBRG", allottedResource.getHomingSolution().getServiceInstanceId())
493 String allottedResourceId = execution.getVariable("allottedResourceId")
494 execution.setVariable("allottedResourceIdBRG", allottedResourceId)
495 utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)
497 utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
498 } catch (Exception ex) {
499 // try error in method block
500 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
501 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
507 // *******************************
508 // Generate Network request Section
509 // *******************************
510 public void prepareVnfAndModulesCreate (DelegateExecution execution) {
511 def isDebugEnabled=execution.getVariable(DebugFlag)
514 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
516 // String disableRollback = execution.getVariable("disableRollback")
517 // def backoutOnFailure = ""
518 // if(disableRollback != null){
519 // if ( disableRollback == true) {
520 // backoutOnFailure = "false"
521 // } else if ( disableRollback == false) {
522 // backoutOnFailure = "true"
525 //failIfExists - optional
527 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
528 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
529 execution.setVariable("productFamilyId", productFamilyId)
530 utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)
532 List<VnfResource> vnfList = execution.getVariable("vnfList")
534 Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")
535 String vnfModelInfoString = null;
537 if (vnfList != null && vnfList.size() > 0 ) {
538 utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)
539 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
540 utils.log("DEBUG", "got 0 ", isDebugEnabled)
541 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
542 vnfModelInfoString = vnfModelInfo.toString()
544 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored
545 vnfModelInfoString = execution.getVariable("vnfModelInfo")
548 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
550 // extract cloud configuration
551 String lcpCloudRegionId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
552 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
553 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
554 String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.tenantId")
555 execution.setVariable("tenantId", tenantId)
556 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
558 String sdncVersion = execution.getVariable("sdncVersion")
559 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
561 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
562 } catch (Exception ex) {
563 // try error in method block
564 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
565 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
569 // *******************************
570 // Validate Vnf request Section -> increment count
571 // *******************************
572 public void validateVnfCreate (DelegateExecution execution) {
573 def isDebugEnabled=execution.getVariable(DebugFlag)
576 utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
578 Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")
581 execution.setVariable(Prefix+"VnfsCreatedCount", vnfsCreatedCount)
583 utils.log("DEBUG", " ***** Completed validateVnfCreate of CreateVcpeResCustService ***** "+" vnf # "+vnfsCreatedCount, isDebugEnabled)
584 } catch (Exception ex) {
585 // try error in method block
586 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
587 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
591 // *****************************************
592 // Prepare Completion request Section
593 // *****************************************
594 public void postProcessResponse (DelegateExecution execution) {
595 def isDebugEnabled=execution.getVariable(DebugFlag)
597 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
600 String source = execution.getVariable("source")
601 String requestId = execution.getVariable("mso-request-id")
602 String serviceInstanceId = execution.getVariable("serviceInstanceId")
604 String msoCompletionRequest =
605 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
606 xmlns:ns="http://org.openecomp/mso/request/types/v1">
607 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
608 <request-id>${requestId}</request-id>
609 <action>CREATE</action>
610 <source>${source}</source>
612 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
613 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
614 <mso-bpel-name>BPMN macro create</mso-bpel-name>
615 </aetgt:MsoCompletionRequest>"""
618 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
620 utils.logAudit(xmlMsoCompletionRequest)
621 execution.setVariable(Prefix+"Success", true)
622 execution.setVariable(Prefix+"CompleteMsoProcessRequest", xmlMsoCompletionRequest)
623 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
624 } catch (BpmnError e) {
626 } catch (Exception ex) {
627 // try error in method block
628 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
629 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
633 public void preProcessRollback (DelegateExecution execution) {
634 def isDebugEnabled=execution.getVariable(DebugFlag)
635 utils.log("DEBUG"," ***** preProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
638 Object workflowException = execution.getVariable("WorkflowException");
640 if (workflowException instanceof WorkflowException) {
641 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
642 execution.setVariable("prevWorkflowException", workflowException);
643 //execution.setVariable("WorkflowException", null);
645 } catch (BpmnError e) {
646 utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
647 } catch(Exception ex) {
648 String msg = "Exception in preProcessRollback. " + ex.getMessage()
649 utils.log("DEBUG", msg, isDebugEnabled)
651 utils.log("DEBUG"," *** Exit preProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
654 public void postProcessRollback (DelegateExecution execution) {
655 def isDebugEnabled=execution.getVariable(DebugFlag)
656 utils.log("DEBUG"," ***** postProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
659 Object workflowException = execution.getVariable("prevWorkflowException");
660 if (workflowException instanceof WorkflowException) {
661 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
662 execution.setVariable("WorkflowException", workflowException);
664 } catch (BpmnError b) {
665 utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
667 } catch(Exception ex) {
668 msg = "Exception in postProcessRollback. " + ex.getMessage()
669 utils.log("DEBUG", msg, isDebugEnabled)
671 utils.log("DEBUG"," *** Exit postProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
674 public void prepareFalloutRequest(DelegateExecution execution){
675 def isDebugEnabled=execution.getVariable(DebugFlag)
677 utils.log("DEBUG", " *** STARTED CreateVcpeResCustService prepareFalloutRequest Process *** ", isDebugEnabled)
680 WorkflowException wfex = execution.getVariable("WorkflowException")
681 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
682 String requestInfo = execution.getVariable(Prefix+"requestInfo")
683 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
685 //TODO. hmmm. there is no way to UPDATE error message.
686 // String errorMessage = wfex.getErrorMessage()
687 // boolean successIndicator = execution.getVariable("DCRESI_rolledBack")
688 // if (successIndicator){
689 // errorMessage = errorMessage + ". Rollback successful."
691 // errorMessage = errorMessage + ". Rollback not completed."
694 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
696 execution.setVariable(Prefix+"falloutRequest", falloutRequest)
698 } catch (Exception ex) {
699 utils.log("DEBUG", "Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
700 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")
702 utils.log("DEBUG", "*** COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ***", isDebugEnabled)
706 public void sendSyncError (DelegateExecution execution) {
707 def isDebugEnabled=execution.getVariable(DebugFlag)
708 execution.setVariable("prefix", Prefix)
710 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateVcpeResCustService ***** ", isDebugEnabled)
713 String errorMessage = ""
714 def wfe = execution.getVariable("WorkflowException")
715 if (wfe instanceof WorkflowException) {
716 errorMessage = wfe.getErrorMessage()
718 errorMessage = "Sending Sync Error."
721 String buildworkflowException =
722 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
723 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
724 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
725 </aetgt:WorkflowException>"""
727 utils.logAudit(buildworkflowException)
728 sendWorkflowResponse(execution, 500, buildworkflowException)
729 } catch (Exception ex) {
730 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
734 public void processJavaException(DelegateExecution execution){
735 def isDebugEnabled=execution.getVariable(DebugFlag)
736 execution.setVariable("prefix",Prefix)
738 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
739 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
740 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
741 execution.setVariable(Prefix+"unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
742 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
744 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
747 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
748 execution.setVariable(Prefix+"unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
749 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
751 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)