2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.vcpe.scripts;
\r
22 import groovy.xml.XmlUtil
\r
23 import groovy.json.*
\r
25 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
27 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
\r
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
29 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
30 import org.openecomp.mso.bpmn.core.RollbackData
\r
31 import org.openecomp.mso.bpmn.core.WorkflowException
\r
32 import org.openecomp.mso.bpmn.core.domain.*
\r
34 import java.util.UUID;
\r
36 import org.camunda.bpm.engine.delegate.BpmnError
\r
37 import org.camunda.bpm.engine.runtime.Execution
\r
38 import org.json.JSONObject;
\r
39 import org.json.JSONArray;
\r
40 import org.apache.commons.lang3.*
\r
41 import org.apache.commons.codec.binary.Base64;
\r
42 import org.springframework.web.util.UriUtils;
\r
43 import static org.apache.commons.lang3.StringUtils.*
\r
46 * This groovy class supports the <class>CreateVcpeResCustService.bpmn</class> process.
\r
51 public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
\r
53 private static final String DebugFlag = "isDebugLogEnabled"
\r
55 String Prefix="CVRCS_"
\r
56 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
57 JsonUtils jsonUtil = new JsonUtils()
\r
58 VidUtils vidUtils = new VidUtils()
\r
59 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
\r
62 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
65 public InitializeProcessVariables(Execution execution){
\r
66 /* Initialize all the process variables in this block */
\r
68 execution.setVariable("createVcpeServiceRequest", "")
\r
69 execution.setVariable("globalSubscriberId", "")
\r
70 execution.setVariable("serviceInstanceName", "")
\r
71 execution.setVariable("msoRequestId", "")
\r
72 execution.setVariable(Prefix+"VnfsCreatedCount", 0)
\r
73 execution.setVariable("productFamilyId", "")
\r
74 execution.setVariable("brgWanMacAddress", "")
\r
77 execution.setVariable("sdncVersion", "1707")
\r
80 // **************************************************
\r
81 // Pre or Prepare Request Section
\r
82 // **************************************************
\r
84 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
87 public void preProcessRequest (Execution execution) {
\r
88 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
89 execution.setVariable("prefix",Prefix)
\r
91 utils.log("DEBUG", " ***** Inside preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
\r
94 // initialize flow variables
\r
95 InitializeProcessVariables(execution)
\r
98 String aaiDistDelay = execution.getVariable('URN_mso_workflow_aai_distribution_delay')
\r
99 if (isBlank(aaiDistDelay)) {
\r
100 msg = "URN_mso_workflow_aai_distribution_delay is null"
\r
101 utils.log("DEBUG", msg, isDebugEnabled)
\r
102 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
104 execution.setVariable("aaiDistDelay", aaiDistDelay)
\r
105 utils.log("DEBUG","AAI distribution delay: " + aaiDistDelay, isDebugEnabled)
\r
107 // check for incoming json message/input
\r
108 String createVcpeServiceRequest = execution.getVariable("bpmnRequest")
\r
109 utils.logAudit(createVcpeServiceRequest)
\r
110 execution.setVariable("createVcpeServiceRequest", createVcpeServiceRequest);
\r
111 println 'createVcpeServiceRequest - ' + createVcpeServiceRequest
\r
113 // extract requestId
\r
114 String requestId = execution.getVariable("mso-request-id")
\r
115 execution.setVariable("msoRequestId", requestId)
\r
117 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
119 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
\r
120 serviceInstanceId = UUID.randomUUID().toString()
\r
121 utils.log("DEBUG", " Generated new Service Instance: " + serviceInstanceId , isDebugEnabled)
\r
123 utils.log("DEBUG", "Using provided Service Instance ID: " + serviceInstanceId , isDebugEnabled)
\r
126 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
\r
127 execution.setVariable("serviceInstanceId", serviceInstanceId)
\r
129 String requestAction = execution.getVariable("requestAction")
\r
130 execution.setVariable("requestAction", requestAction)
\r
132 setBasicDBAuthHeader(execution, isDebugEnabled)
\r
134 String source = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.source")
\r
135 if ((source == null) || (source.isEmpty())) {
\r
138 execution.setVariable("source", source)
\r
140 // extract globalSubscriberId
\r
141 String globalSubscriberId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
\r
143 // verify element global-customer-id is sent from JSON input, throw exception if missing
\r
144 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
\r
145 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
\r
146 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
149 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
150 execution.setVariable("globalCustomerId", globalSubscriberId)
\r
153 // extract subscriptionServiceType
\r
154 String subscriptionServiceType = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
\r
155 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
156 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
\r
158 String suppressRollback = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.suppressRollback")
\r
159 execution.setVariable("disableRollback", suppressRollback)
\r
160 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
\r
162 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
\r
163 execution.setVariable("productFamilyId", productFamilyId)
\r
164 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
\r
166 String subscriberInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo")
\r
167 execution.setVariable("subscriberInfo", subscriberInfo)
\r
168 utils.log("DEBUG", "Incoming subscriberInfo is: " + subscriberInfo, isDebugEnabled)
\r
171 * Extracting User Parameters from incoming Request and converting into a Map
\r
173 def jsonSlurper = new JsonSlurper()
\r
174 def jsonOutput = new JsonOutput()
\r
176 Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest)
\r
179 def userParams = reqMap.requestDetails?.requestParameters?.userParams
\r
181 Map<String, String> inputMap = [:]
\r
187 if("BRG_WAN_MAC_Address".equals(userParam?.name)) {
\r
188 execution.setVariable("brgWanMacAddress", userParam.value)
\r
189 inputMap.put("BRG_WAN_MAC_Address", userParam.value)
\r
194 utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
\r
195 execution.setVariable("serviceInputParams", inputMap)
\r
197 utils.log("DEBUG", "Incoming brgWanMacAddress is: " + execution.getVariable('brgWanMacAddress'), isDebugEnabled)
\r
199 //For Completion Handler & Fallout Handler
\r
200 String requestInfo =
\r
201 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
202 <request-id>${requestId}</request-id>
\r
203 <action>CREATE</action>
\r
204 <source>${source}</source>
\r
207 execution.setVariable(Prefix+"requestInfo", requestInfo)
\r
209 utils.log("DEBUG", " ***** Completed preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
\r
211 } catch (BpmnError e) {
\r
214 } catch (Exception ex){
\r
215 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
\r
216 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
220 public void sendSyncResponse(Execution execution) {
\r
221 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
223 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
226 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
227 String requestId = execution.getVariable("mso-request-id")
\r
229 // RESTResponse (for API Handler (APIH) Reply Task)
\r
230 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
232 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
233 sendWorkflowResponse(execution, 202, syncResponse)
\r
235 } catch (Exception ex) {
\r
236 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
\r
237 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
241 // *******************************
\r
243 // *******************************
\r
244 public void prepareDecomposeService(Execution execution) {
\r
245 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
248 utils.log("DEBUG", " ***** Inside prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
250 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
252 //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB
\r
253 String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.modelInfo")
\r
254 execution.setVariable("serviceModelInfo", serviceModelInfo)
\r
256 utils.log("DEBUG", " ***** Completed prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
257 } catch (Exception ex) {
\r
258 // try error in method block
\r
259 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
\r
260 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
264 // *******************************
\r
266 // *******************************
\r
267 public void prepareCreateServiceInstance(Execution execution) {
\r
268 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
271 utils.log("DEBUG", " ***** Inside prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
274 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
\r
275 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
276 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
\r
279 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
280 // String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters")
\r
281 // execution.setVariable("serviceInputParams", serviceInputParams)
\r
284 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
\r
285 execution.setVariable("serviceInstanceName", serviceInstanceName)
\r
287 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
288 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonStringNoRootName())
\r
290 utils.log("DEBUG", " ***** Completed prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
291 } catch (Exception ex) {
\r
292 // try error in method block
\r
293 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
\r
294 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
298 public void postProcessServiceInstanceCreate (Execution execution){
\r
299 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +'execution=' + execution.getId() +')'
\r
300 def isDebugLogEnabled = execution.getVariable(DebugFlag)
\r
301 logDebug('Entered ' + method, isDebugLogEnabled)
\r
303 String requestId = execution.getVariable("mso-request-id")
\r
304 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
305 String serviceInstanceName = execution.getVariable("serviceInstanceName")
\r
309 String payload = """
\r
310 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
313 <req:updateInfraRequest>
\r
314 <requestId>${requestId}</requestId>
\r
315 <lastModifiedBy>BPEL</lastModifiedBy>
\r
316 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
317 <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>
\r
318 </req:updateInfraRequest>
\r
320 </soapenv:Envelope>
\r
322 execution.setVariable(Prefix+"setUpdateDbInstancePayload", payload)
\r
323 utils.logAudit(Prefix+"setUpdateDbInstancePayload: " + payload)
\r
324 logDebug('Exited ' + method, isDebugLogEnabled)
\r
326 } catch (BpmnError e) {
\r
328 } catch (Exception e) {
\r
329 logError('Caught exception in ' + method, e)
\r
330 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
335 public void processDecomposition (Execution execution) {
\r
336 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
338 utils.log("DEBUG", " ***** Inside processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
342 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
345 List<VnfResource> vnfList = serviceDecomposition.getServiceVnfs()
\r
346 execution.setVariable("vnfList", vnfList)
\r
347 execution.setVariable("vnfListString", vnfList.toString())
\r
349 String vnfModelInfoString = ""
\r
350 if (vnfList != null && vnfList.size() > 0) {
\r
351 execution.setVariable(Prefix+"VNFsCount", vnfList.size())
\r
352 utils.log("DEBUG", "vnfs to create: "+ vnfList.size(), isDebugEnabled)
\r
353 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
\r
355 vnfModelInfoString = vnfModelInfo.toString()
\r
356 String vnfModelInfoWithRoot = vnfModelInfo.toString()
\r
357 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
\r
359 execution.setVariable(Prefix+"VNFsCount", 0)
\r
360 utils.log("DEBUG", "no vnfs to create based upon serviceDecomposition content", isDebugEnabled)
\r
363 execution.setVariable("vnfModelInfo", vnfModelInfoString)
\r
364 execution.setVariable("vnfModelInfoString", vnfModelInfoString)
\r
365 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
\r
367 utils.log("DEBUG", " ***** Completed processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
368 } catch (Exception ex) {
\r
369 sendSyncError(execution)
\r
370 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. processDecomposition() - " + ex.getMessage()
\r
371 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
372 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
377 public void prepareCreateAllottedResourceTXC(Execution execution) {
\r
378 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
381 utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
384 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
\r
385 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
386 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
\r
389 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
390 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
392 //allottedResourceModelInfo
\r
393 //allottedResourceRole
\r
394 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
\r
395 //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.
\r
396 List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
\r
397 if (allottedResources != null) {
\r
398 Iterator iter = allottedResources.iterator();
\r
399 while (iter.hasNext()){
\r
400 AllottedResource allottedResource = (AllottedResource)iter.next();
\r
402 utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName(), isDebugEnabled)
\r
403 utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)
\r
404 if("TunnelXConn".equalsIgnoreCase(allottedResource.getAllottedResourceType())){
\r
405 //set create flag to true
\r
406 execution.setVariable("createTXCAR", true)
\r
407 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
\r
408 execution.setVariable("allottedResourceModelInfoTXC", allottedResourceModelInfo.toJsonStringNoRootName())
\r
409 execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())
\r
410 execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())
\r
411 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the TXC,
\r
412 //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).
\r
413 execution.setVariable("parentServiceInstanceIdTXC", allottedResource.getHomingSolution().getServiceInstanceId())
\r
419 String allottedResourceId = execution.getVariable("allottedResourceId")
\r
420 execution.setVariable("allottedResourceIdTXC", allottedResourceId)
\r
421 utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)
\r
423 utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
424 } catch (Exception ex) {
\r
425 // try error in method block
\r
426 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
\r
427 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
430 public void prepareCreateAllottedResourceBRG(Execution execution) {
\r
431 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
434 utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
437 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
\r
438 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
439 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
\r
442 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
443 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
445 //allottedResourceModelInfo
\r
446 //allottedResourceRole
\r
447 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
\r
448 //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.
\r
449 List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
\r
450 if (allottedResources != null) {
\r
451 Iterator iter = allottedResources.iterator();
\r
452 while (iter.hasNext()){
\r
453 AllottedResource allottedResource = (AllottedResource)iter.next();
\r
455 utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonStringNoRootName(), isDebugEnabled)
\r
456 utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)
\r
457 if("BRG".equalsIgnoreCase(allottedResource.getAllottedResourceType())){
\r
458 //set create flag to true
\r
459 execution.setVariable("createBRGAR", true)
\r
460 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
\r
461 execution.setVariable("allottedResourceModelInfoBRG", allottedResourceModelInfo.toJsonStringNoRootName())
\r
462 execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())
\r
463 execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())
\r
464 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the BRG,
\r
465 //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).
\r
466 execution.setVariable("parentServiceInstanceIdBRG", allottedResource.getHomingSolution().getServiceInstanceId())
\r
472 String allottedResourceId = execution.getVariable("allottedResourceId")
\r
473 execution.setVariable("allottedResourceIdBRG", allottedResourceId)
\r
474 utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)
\r
476 utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
477 } catch (Exception ex) {
\r
478 // try error in method block
\r
479 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
\r
480 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
486 // *******************************
\r
487 // Generate Network request Section
\r
488 // *******************************
\r
489 public void prepareVnfAndModulesCreate (Execution execution) {
\r
490 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
493 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
495 // String disableRollback = execution.getVariable("disableRollback")
\r
496 // def backoutOnFailure = ""
\r
497 // if(disableRollback != null){
\r
498 // if ( disableRollback == true) {
\r
499 // backoutOnFailure = "false"
\r
500 // } else if ( disableRollback == false) {
\r
501 // backoutOnFailure = "true"
\r
504 //failIfExists - optional
\r
506 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
507 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
\r
508 execution.setVariable("productFamilyId", productFamilyId)
\r
509 utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)
\r
511 List<VnfResource> vnfList = execution.getVariable("vnfList")
\r
513 Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")
\r
514 String vnfModelInfoString = null;
\r
516 if (vnfList != null && vnfList.size() > 0 ) {
\r
517 utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)
\r
518 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
\r
519 utils.log("DEBUG", "got 0 ", isDebugEnabled)
\r
520 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
\r
521 vnfModelInfoString = vnfModelInfo.toString()
\r
523 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored
\r
524 vnfModelInfoString = execution.getVariable("vnfModelInfo")
\r
527 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
\r
529 // extract cloud configuration
\r
530 String lcpCloudRegionId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
\r
531 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
\r
532 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
\r
533 String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.tenantId")
\r
534 execution.setVariable("tenantId", tenantId)
\r
535 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
\r
537 String sdncVersion = execution.getVariable("sdncVersion")
\r
538 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
\r
540 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
541 } catch (Exception ex) {
\r
542 // try error in method block
\r
543 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
\r
544 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
548 // *******************************
\r
549 // Validate Vnf request Section -> increment count
\r
550 // *******************************
\r
551 public void validateVnfCreate (Execution execution) {
\r
552 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
555 utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
557 Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")
\r
560 execution.setVariable(Prefix+"VnfsCreatedCount", vnfsCreatedCount)
\r
562 utils.log("DEBUG", " ***** Completed validateVnfCreate of CreateVcpeResCustService ***** "+" vnf # "+vnfsCreatedCount, isDebugEnabled)
\r
563 } catch (Exception ex) {
\r
564 // try error in method block
\r
565 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
\r
566 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
570 // *****************************************
\r
571 // Prepare Completion request Section
\r
572 // *****************************************
\r
573 public void postProcessResponse (Execution execution) {
\r
574 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
576 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
579 String source = execution.getVariable("source")
\r
580 String requestId = execution.getVariable("mso-request-id")
\r
581 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
583 String msoCompletionRequest =
\r
584 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
585 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
586 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
587 <request-id>${requestId}</request-id>
\r
588 <action>CREATE</action>
\r
589 <source>${source}</source>
\r
591 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
\r
592 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
593 <mso-bpel-name>BPMN macro create</mso-bpel-name>
\r
594 </aetgt:MsoCompletionRequest>"""
\r
597 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
599 utils.logAudit(xmlMsoCompletionRequest)
\r
600 execution.setVariable(Prefix+"Success", true)
\r
601 execution.setVariable(Prefix+"CompleteMsoProcessRequest", xmlMsoCompletionRequest)
\r
602 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
603 } catch (BpmnError e) {
\r
605 } catch (Exception ex) {
\r
606 // try error in method block
\r
607 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
\r
608 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
612 public void preProcessRollback (Execution execution) {
\r
613 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
614 utils.log("DEBUG"," ***** preProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
617 Object workflowException = execution.getVariable("WorkflowException");
\r
619 if (workflowException instanceof WorkflowException) {
\r
620 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
\r
621 execution.setVariable("prevWorkflowException", workflowException);
\r
622 //execution.setVariable("WorkflowException", null);
\r
624 } catch (BpmnError e) {
\r
625 utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
\r
626 } catch(Exception ex) {
\r
627 String msg = "Exception in preProcessRollback. " + ex.getMessage()
\r
628 utils.log("DEBUG", msg, isDebugEnabled)
\r
630 utils.log("DEBUG"," *** Exit preProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
\r
633 public void postProcessRollback (Execution execution) {
\r
634 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
635 utils.log("DEBUG"," ***** postProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
638 Object workflowException = execution.getVariable("prevWorkflowException");
\r
639 if (workflowException instanceof WorkflowException) {
\r
640 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
\r
641 execution.setVariable("WorkflowException", workflowException);
\r
643 } catch (BpmnError b) {
\r
644 utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
\r
646 } catch(Exception ex) {
\r
647 msg = "Exception in postProcessRollback. " + ex.getMessage()
\r
648 utils.log("DEBUG", msg, isDebugEnabled)
\r
650 utils.log("DEBUG"," *** Exit postProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
\r
653 public void prepareFalloutRequest(Execution execution){
\r
654 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
656 utils.log("DEBUG", " *** STARTED CreateVcpeResCustService prepareFalloutRequest Process *** ", isDebugEnabled)
\r
659 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
660 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
661 String requestInfo = execution.getVariable(Prefix+"requestInfo")
\r
662 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
\r
664 //TODO. hmmm. there is no way to UPDATE error message.
\r
665 // String errorMessage = wfex.getErrorMessage()
\r
666 // boolean successIndicator = execution.getVariable("DCRESI_rolledBack")
\r
667 // if (successIndicator){
\r
668 // errorMessage = errorMessage + ". Rollback successful."
\r
670 // errorMessage = errorMessage + ". Rollback not completed."
\r
673 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
675 execution.setVariable(Prefix+"falloutRequest", falloutRequest)
\r
677 } catch (Exception ex) {
\r
678 utils.log("DEBUG", "Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
\r
679 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")
\r
681 utils.log("DEBUG", "*** COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ***", isDebugEnabled)
\r
685 public void sendSyncError (Execution execution) {
\r
686 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
687 execution.setVariable("prefix", Prefix)
\r
689 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
692 String errorMessage = ""
\r
693 def wfe = execution.getVariable("WorkflowException")
\r
694 if (wfe instanceof WorkflowException) {
\r
695 errorMessage = wfe.getErrorMessage()
\r
697 errorMessage = "Sending Sync Error."
\r
700 String buildworkflowException =
\r
701 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
702 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
703 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
704 </aetgt:WorkflowException>"""
\r
706 utils.logAudit(buildworkflowException)
\r
707 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
708 } catch (Exception ex) {
\r
709 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
713 public void processJavaException(Execution execution){
\r
714 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
715 execution.setVariable("prefix",Prefix)
\r
717 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
\r
718 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
\r
719 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
\r
720 execution.setVariable(Prefix+"unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
\r
721 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
\r
722 }catch(BpmnError b){
\r
723 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
725 }catch(Exception e){
\r
726 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
\r
727 execution.setVariable(Prefix+"unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
\r
728 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
\r
730 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
\r