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
45 * This groovy class supports the <class>CreateVcpeResCustService.bpmn</class> process.
\r
50 public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
\r
52 private static final String DebugFlag = "isDebugLogEnabled"
\r
54 String Prefix="CVRCS_"
\r
55 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
56 JsonUtils jsonUtil = new JsonUtils()
\r
57 VidUtils vidUtils = new VidUtils()
\r
58 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
\r
61 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
64 public InitializeProcessVariables(Execution execution){
\r
65 /* Initialize all the process variables in this block */
\r
67 execution.setVariable("createVcpeServiceRequest", "")
\r
68 execution.setVariable("globalSubscriberId", "")
\r
69 execution.setVariable("serviceInstanceName", "")
\r
70 execution.setVariable("msoRequestId", "")
\r
71 execution.setVariable(Prefix+"VnfsCreatedCount", 0)
\r
72 execution.setVariable("productFamilyId", "")
\r
73 execution.setVariable("brgWanMacAddress", "")
\r
76 execution.setVariable("sdncVersion", "1707")
\r
79 // **************************************************
\r
80 // Pre or Prepare Request Section
\r
81 // **************************************************
\r
83 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
86 public void preProcessRequest (Execution execution) {
\r
87 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
88 execution.setVariable("prefix",Prefix)
\r
90 utils.log("DEBUG", " ***** Inside preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
\r
93 // initialize flow variables
\r
94 InitializeProcessVariables(execution)
\r
96 // check for incoming json message/input
\r
97 String createVcpeServiceRequest = execution.getVariable("bpmnRequest")
\r
98 utils.logAudit(createVcpeServiceRequest)
\r
99 execution.setVariable("createVcpeServiceRequest", createVcpeServiceRequest);
\r
100 println 'createVcpeServiceRequest - ' + createVcpeServiceRequest
\r
102 // extract requestId
\r
103 String requestId = execution.getVariable("mso-request-id")
\r
104 execution.setVariable("msoRequestId", requestId)
\r
106 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
108 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
\r
109 serviceInstanceId = UUID.randomUUID().toString()
\r
110 utils.log("DEBUG", " Generated new Service Instance: " + serviceInstanceId , isDebugEnabled)
\r
112 utils.log("DEBUG", "Using provided Service Instance ID: " + serviceInstanceId , isDebugEnabled)
\r
115 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
\r
116 execution.setVariable("serviceInstanceId", serviceInstanceId)
\r
118 String requestAction = execution.getVariable("requestAction")
\r
119 execution.setVariable("requestAction", requestAction)
\r
121 setBasicDBAuthHeader(execution, isDebugEnabled)
\r
123 String source = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.source")
\r
124 if ((source == null) || (source.isEmpty())) {
\r
127 execution.setVariable("source", source)
\r
129 // extract globalSubscriberId
\r
130 String globalSubscriberId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
\r
132 // verify element global-customer-id is sent from JSON input, throw exception if missing
\r
133 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
\r
134 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
\r
135 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
138 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
139 execution.setVariable("globalCustomerId", globalSubscriberId)
\r
142 // extract subscriptionServiceType
\r
143 String subscriptionServiceType = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
\r
144 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
145 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
\r
147 String suppressRollback = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.suppressRollback")
\r
148 execution.setVariable("disableRollback", suppressRollback)
\r
149 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
\r
151 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
\r
152 execution.setVariable("productFamilyId", productFamilyId)
\r
153 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
\r
155 String subscriberInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.subscriberInfo")
\r
156 execution.setVariable("subscriberInfo", subscriberInfo)
\r
157 utils.log("DEBUG", "Incoming subscriberInfo is: " + subscriberInfo, isDebugEnabled)
\r
160 * Extracting User Parameters from incoming Request and converting into a Map
\r
162 def jsonSlurper = new JsonSlurper()
\r
163 def jsonOutput = new JsonOutput()
\r
165 Map reqMap = jsonSlurper.parseText(createVcpeServiceRequest)
\r
168 def userParams = reqMap.requestDetails?.requestParameters?.userParams
\r
170 Map<String, String> inputMap = [:]
\r
176 if("BRG_WAN_MAC_Address".equals(userParam?.name)) {
\r
177 execution.setVariable("brgWanMacAddress", userParam.value)
\r
178 inputMap.put("BRG_WAN_MAC_Address", userParam.value)
\r
183 utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
\r
184 execution.setVariable("serviceInputParams", inputMap)
\r
186 utils.log("DEBUG", "Incoming brgWanMacAddress is: " + execution.getVariable('brgWanMacAddress'), isDebugEnabled)
\r
188 //For Completion Handler & Fallout Handler
\r
189 String requestInfo =
\r
190 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
191 <request-id>${requestId}</request-id>
\r
192 <action>CREATE</action>
\r
193 <source>${source}</source>
\r
196 execution.setVariable(Prefix+"requestInfo", requestInfo)
\r
198 utils.log("DEBUG", " ***** Completed preProcessRequest CreateVcpeResCustService Request ***** ", isDebugEnabled)
\r
200 } catch (BpmnError e) {
\r
203 } catch (Exception ex){
\r
204 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
\r
205 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
209 public void sendSyncResponse(Execution execution) {
\r
210 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
212 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
215 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
216 String requestId = execution.getVariable("mso-request-id")
\r
218 // RESTResponse (for API Handler (APIH) Reply Task)
\r
219 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
221 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
222 sendWorkflowResponse(execution, 202, syncResponse)
\r
224 } catch (Exception ex) {
\r
225 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
\r
226 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
230 // *******************************
\r
232 // *******************************
\r
233 public void prepareDecomposeService(Execution execution) {
\r
234 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
237 utils.log("DEBUG", " ***** Inside prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
239 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
241 //serviceModelInfo JSON string will be used as-is for DoCreateServiceInstance BB
\r
242 String serviceModelInfo = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.modelInfo")
\r
243 execution.setVariable("serviceModelInfo", serviceModelInfo)
\r
245 utils.log("DEBUG", " ***** Completed prepareDecomposeService of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
246 } catch (Exception ex) {
\r
247 // try error in method block
\r
248 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
\r
249 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
253 // *******************************
\r
255 // *******************************
\r
256 public void prepareCreateServiceInstance(Execution execution) {
\r
257 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
260 utils.log("DEBUG", " ***** Inside prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
263 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
\r
264 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
265 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
\r
268 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
269 // String serviceInputParams = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestParameters")
\r
270 // execution.setVariable("serviceInputParams", serviceInputParams)
\r
273 String serviceInstanceName = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.instanceName")
\r
274 execution.setVariable("serviceInstanceName", serviceInstanceName)
\r
276 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
277 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())
\r
279 utils.log("DEBUG", " ***** Completed prepareCreateServiceInstance of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
280 } catch (Exception ex) {
\r
281 // try error in method block
\r
282 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
\r
283 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
287 public void postProcessServiceInstanceCreate (Execution execution){
\r
288 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +'execution=' + execution.getId() +')'
\r
289 def isDebugLogEnabled = execution.getVariable(DebugFlag)
\r
290 logDebug('Entered ' + method, isDebugLogEnabled)
\r
292 String requestId = execution.getVariable("mso-request-id")
\r
293 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
294 String serviceInstanceName = execution.getVariable("serviceInstanceName")
\r
298 String payload = """
\r
299 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
302 <req:updateInfraRequest>
\r
303 <requestId>${requestId}</requestId>
\r
304 <lastModifiedBy>BPEL</lastModifiedBy>
\r
305 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
306 <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>
\r
307 </req:updateInfraRequest>
\r
309 </soapenv:Envelope>
\r
311 execution.setVariable(Prefix+"setUpdateDbInstancePayload", payload)
\r
312 utils.logAudit(Prefix+"setUpdateDbInstancePayload: " + payload)
\r
313 logDebug('Exited ' + method, isDebugLogEnabled)
\r
315 } catch (BpmnError e) {
\r
317 } catch (Exception e) {
\r
318 logError('Caught exception in ' + method, e)
\r
319 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
324 public void processDecomposition (Execution execution) {
\r
325 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
327 utils.log("DEBUG", " ***** Inside processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
331 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
334 List<VnfResource> vnfList = serviceDecomposition.getServiceVnfs()
\r
335 execution.setVariable("vnfList", vnfList)
\r
336 execution.setVariable("vnfListString", vnfList.toString())
\r
338 String vnfModelInfoString = ""
\r
339 if (vnfList != null && vnfList.size() > 0) {
\r
340 execution.setVariable(Prefix+"VNFsCount", vnfList.size())
\r
341 utils.log("DEBUG", "vnfs to create: "+ vnfList.size(), isDebugEnabled)
\r
342 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
\r
344 vnfModelInfoString = vnfModelInfo.toString()
\r
345 String vnfModelInfoWithRoot = vnfModelInfo.toString()
\r
346 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
\r
348 execution.setVariable(Prefix+"VNFsCount", 0)
\r
349 utils.log("DEBUG", "no vnfs to create based upon serviceDecomposition content", isDebugEnabled)
\r
352 execution.setVariable("vnfModelInfo", vnfModelInfoString)
\r
353 execution.setVariable("vnfModelInfoString", vnfModelInfoString)
\r
354 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
\r
356 utils.log("DEBUG", " ***** Completed processDecomposition() of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
357 } catch (Exception ex) {
\r
358 sendSyncError(execution)
\r
359 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. processDecomposition() - " + ex.getMessage()
\r
360 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
361 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
366 public void prepareCreateAllottedResourceTXC(Execution execution) {
\r
367 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
370 utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
373 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
\r
374 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
375 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
\r
378 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
379 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
381 //allottedResourceModelInfo
\r
382 //allottedResourceRole
\r
383 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
\r
384 //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
385 List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
\r
386 if (allottedResources != null) {
\r
387 Iterator iter = allottedResources.iterator();
\r
388 while (iter.hasNext()){
\r
389 AllottedResource allottedResource = (AllottedResource)iter.next();
\r
391 utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonString(), isDebugEnabled)
\r
392 utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)
\r
393 if("TunnelXConn".equalsIgnoreCase(allottedResource.getAllottedResourceType())){
\r
394 //set create flag to true
\r
395 execution.setVariable("createTXCAR", true)
\r
396 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
\r
397 execution.setVariable("allottedResourceModelInfoTXC", allottedResourceModelInfo.toJsonString())
\r
398 execution.setVariable("allottedResourceRoleTXC", allottedResource.getAllottedResourceRole())
\r
399 execution.setVariable("allottedResourceTypeTXC", allottedResource.getAllottedResourceType())
\r
400 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the TXC,
\r
401 //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
402 execution.setVariable("parentServiceInstanceIdTXC", allottedResource.getHomingSolution().getServiceInstanceId())
\r
408 String allottedResourceId = execution.getVariable("allottedResourceId")
\r
409 execution.setVariable("allottedResourceIdTXC", allottedResourceId)
\r
410 utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)
\r
412 utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceTXC of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
413 } catch (Exception ex) {
\r
414 // try error in method block
\r
415 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceTXC flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
\r
416 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
419 public void prepareCreateAllottedResourceBRG(Execution execution) {
\r
420 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
423 utils.log("DEBUG", " ***** Inside prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
426 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
\r
427 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
428 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
\r
431 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
432 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
434 //allottedResourceModelInfo
\r
435 //allottedResourceRole
\r
436 //The model Info parameters are a JSON structure as defined in the Service Instantiation API.
\r
437 //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
438 List<AllottedResource> allottedResources = serviceDecomposition.getServiceAllottedResources()
\r
439 if (allottedResources != null) {
\r
440 Iterator iter = allottedResources.iterator();
\r
441 while (iter.hasNext()){
\r
442 AllottedResource allottedResource = (AllottedResource)iter.next();
\r
444 utils.log("DEBUG", " getting model info for AllottedResource # :" + allottedResource.toJsonString(), isDebugEnabled)
\r
445 utils.log("DEBUG", " allottedResource.getAllottedResourceType() :" + allottedResource.getAllottedResourceType(), isDebugEnabled)
\r
446 if("BRG".equalsIgnoreCase(allottedResource.getAllottedResourceType())){
\r
447 //set create flag to true
\r
448 execution.setVariable("createBRGAR", true)
\r
449 ModelInfo allottedResourceModelInfo = allottedResource.getModelInfo()
\r
450 execution.setVariable("allottedResourceModelInfoBRG", allottedResourceModelInfo.toJsonString())
\r
451 execution.setVariable("allottedResourceRoleBRG", allottedResource.getAllottedResourceRole())
\r
452 execution.setVariable("allottedResourceTypeBRG", allottedResource.getAllottedResourceType())
\r
453 //After decomposition and homing BBs, there should be an allotted resource object in the decomposition that represents the BRG,
\r
454 //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
455 execution.setVariable("parentServiceInstanceIdBRG", allottedResource.getHomingSolution().getServiceInstanceId())
\r
461 String allottedResourceId = execution.getVariable("allottedResourceId")
\r
462 execution.setVariable("allottedResourceIdBRG", allottedResourceId)
\r
463 utils.log("DEBUG", "setting allottedResourceId CreateVcpeResCustService "+allottedResourceId, isDebugEnabled)
\r
465 utils.log("DEBUG", " ***** Completed prepareCreateAllottedResourceBRG of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
466 } catch (Exception ex) {
\r
467 // try error in method block
\r
468 String exceptionMessage = "Bpmn error encountered in prepareCreateAllottedResourceBRG flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
\r
469 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
475 // *******************************
\r
476 // Generate Network request Section
\r
477 // *******************************
\r
478 public void prepareVnfAndModulesCreate (Execution execution) {
\r
479 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
482 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
484 // String disableRollback = execution.getVariable("disableRollback")
\r
485 // def backoutOnFailure = ""
\r
486 // if(disableRollback != null){
\r
487 // if ( disableRollback == true) {
\r
488 // backoutOnFailure = "false"
\r
489 // } else if ( disableRollback == false) {
\r
490 // backoutOnFailure = "true"
\r
493 //failIfExists - optional
\r
495 String createVcpeServiceRequest = execution.getVariable("createVcpeServiceRequest")
\r
496 String productFamilyId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.requestInfo.productFamilyId")
\r
497 execution.setVariable("productFamilyId", productFamilyId)
\r
498 utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)
\r
500 List<VnfResource> vnfList = execution.getVariable("vnfList")
\r
502 Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")
\r
503 String vnfModelInfoString = null;
\r
505 if (vnfList != null && vnfList.size() > 0 ) {
\r
506 utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)
\r
507 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
\r
508 utils.log("DEBUG", "got 0 ", isDebugEnabled)
\r
509 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
\r
510 vnfModelInfoString = vnfModelInfo.toString()
\r
512 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VCPE use model stored
\r
513 vnfModelInfoString = execution.getVariable("vnfModelInfo")
\r
516 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
\r
518 // extract cloud configuration
\r
519 String lcpCloudRegionId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
\r
520 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
\r
521 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
\r
522 String tenantId = jsonUtil.getJsonValue(createVcpeServiceRequest, "requestDetails.cloudConfiguration.tenantId")
\r
523 execution.setVariable("tenantId", tenantId)
\r
524 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
\r
526 String sdncVersion = execution.getVariable("sdncVersion")
\r
527 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
\r
529 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
530 } catch (Exception ex) {
\r
531 // try error in method block
\r
532 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
\r
533 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
537 // *******************************
\r
538 // Validate Vnf request Section -> increment count
\r
539 // *******************************
\r
540 public void validateVnfCreate (Execution execution) {
\r
541 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
544 utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
546 Integer vnfsCreatedCount = execution.getVariable(Prefix+"VnfsCreatedCount")
\r
549 execution.setVariable(Prefix+"VnfsCreatedCount", vnfsCreatedCount)
\r
551 utils.log("DEBUG", " ***** Completed validateVnfCreate of CreateVcpeResCustService ***** "+" vnf # "+vnfsCreatedCount, isDebugEnabled)
\r
552 } catch (Exception ex) {
\r
553 // try error in method block
\r
554 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
\r
555 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
559 // *****************************************
\r
560 // Prepare Completion request Section
\r
561 // *****************************************
\r
562 public void postProcessResponse (Execution execution) {
\r
563 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
565 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
568 String source = execution.getVariable("source")
\r
569 String requestId = execution.getVariable("mso-request-id")
\r
570 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
572 String msoCompletionRequest =
\r
573 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
574 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
575 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
576 <request-id>${requestId}</request-id>
\r
577 <action>CREATE</action>
\r
578 <source>${source}</source>
\r
580 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
\r
581 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
582 <mso-bpel-name>BPMN macro create</mso-bpel-name>
\r
583 </aetgt:MsoCompletionRequest>"""
\r
586 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
588 utils.logAudit(xmlMsoCompletionRequest)
\r
589 execution.setVariable(Prefix+"Success", true)
\r
590 execution.setVariable(Prefix+"CompleteMsoProcessRequest", xmlMsoCompletionRequest)
\r
591 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
592 } catch (BpmnError e) {
\r
594 } catch (Exception ex) {
\r
595 // try error in method block
\r
596 String exceptionMessage = "Bpmn error encountered in CreateVcpeResCustService flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
\r
597 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
601 public void preProcessRollback (Execution execution) {
\r
602 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
603 utils.log("DEBUG"," ***** preProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
606 Object workflowException = execution.getVariable("WorkflowException");
\r
608 if (workflowException instanceof WorkflowException) {
\r
609 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
\r
610 execution.setVariable("prevWorkflowException", workflowException);
\r
611 //execution.setVariable("WorkflowException", null);
\r
613 } catch (BpmnError e) {
\r
614 utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
\r
615 } catch(Exception ex) {
\r
616 String msg = "Exception in preProcessRollback. " + ex.getMessage()
\r
617 utils.log("DEBUG", msg, isDebugEnabled)
\r
619 utils.log("DEBUG"," *** Exit preProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
\r
622 public void postProcessRollback (Execution execution) {
\r
623 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
624 utils.log("DEBUG"," ***** postProcessRollback of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
627 Object workflowException = execution.getVariable("prevWorkflowException");
\r
628 if (workflowException instanceof WorkflowException) {
\r
629 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
\r
630 execution.setVariable("WorkflowException", workflowException);
\r
632 } catch (BpmnError b) {
\r
633 utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
\r
635 } catch(Exception ex) {
\r
636 msg = "Exception in postProcessRollback. " + ex.getMessage()
\r
637 utils.log("DEBUG", msg, isDebugEnabled)
\r
639 utils.log("DEBUG"," *** Exit postProcessRollback of CreateVcpeResCustService *** ", isDebugEnabled)
\r
642 public void prepareFalloutRequest(Execution execution){
\r
643 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
645 utils.log("DEBUG", " *** STARTED CreateVcpeResCustService prepareFalloutRequest Process *** ", isDebugEnabled)
\r
648 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
649 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
650 String requestInfo = execution.getVariable(Prefix+"requestInfo")
\r
651 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
\r
653 //TODO. hmmm. there is no way to UPDATE error message.
\r
654 // String errorMessage = wfex.getErrorMessage()
\r
655 // boolean successIndicator = execution.getVariable("DCRESI_rolledBack")
\r
656 // if (successIndicator){
\r
657 // errorMessage = errorMessage + ". Rollback successful."
\r
659 // errorMessage = errorMessage + ". Rollback not completed."
\r
662 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
664 execution.setVariable(Prefix+"falloutRequest", falloutRequest)
\r
666 } catch (Exception ex) {
\r
667 utils.log("DEBUG", "Error Occured in CreateVcpeResCustService prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
\r
668 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVcpeResCustService prepareFalloutRequest Process")
\r
670 utils.log("DEBUG", "*** COMPLETED CreateVcpeResCustService prepareFalloutRequest Process ***", isDebugEnabled)
\r
674 public void sendSyncError (Execution execution) {
\r
675 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
676 execution.setVariable("prefix", Prefix)
\r
678 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateVcpeResCustService ***** ", isDebugEnabled)
\r
681 String errorMessage = ""
\r
682 def wfe = execution.getVariable("WorkflowException")
\r
683 if (wfe instanceof WorkflowException) {
\r
684 errorMessage = wfe.getErrorMessage()
\r
686 errorMessage = "Sending Sync Error."
\r
689 String buildworkflowException =
\r
690 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
691 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
692 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
693 </aetgt:WorkflowException>"""
\r
695 utils.logAudit(buildworkflowException)
\r
696 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
697 } catch (Exception ex) {
\r
698 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
702 public void processJavaException(Execution execution){
\r
703 def isDebugEnabled=execution.getVariable(DebugFlag)
\r
704 execution.setVariable("prefix",Prefix)
\r
706 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
\r
707 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
\r
708 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
\r
709 execution.setVariable(Prefix+"unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
\r
710 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
\r
711 }catch(BpmnError b){
\r
712 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
714 }catch(Exception e){
\r
715 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
\r
716 execution.setVariable(Prefix+"unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
\r
717 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
\r
719 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
\r