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=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
23 import groovy.xml.XmlUtil
26 import org.openecomp.mso.bpmn.core.json.JsonUtils
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
29 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.bpmn.core.decomposition.ModelInfo
33 import org.openecomp.mso.bpmn.core.decomposition.NetworkResource
34 import org.openecomp.mso.bpmn.core.decomposition.ServiceDecomposition
35 import org.openecomp.mso.bpmn.core.decomposition.VnfResource
36 import org.openecomp.mso.rest.APIResponse;
37 import org.openecomp.mso.rest.RESTClient
38 import org.openecomp.mso.rest.RESTConfig
40 import java.util.UUID;
42 import org.camunda.bpm.engine.delegate.BpmnError
43 import org.camunda.bpm.engine.runtime.Execution
44 import org.json.JSONObject;
45 import org.json.JSONArray;
46 import org.apache.commons.lang3.*
47 import org.apache.commons.codec.binary.Base64;
48 import org.springframework.web.util.UriUtils;
51 * This groovy class supports the <class>CreateGenericMacroServiceNetworkVnf.bpmn</class> process.
54 public class CreateGenericMacroServiceNetworkVnf extends AbstractServiceTaskProcessor {
56 String Prefix="CGMSNV_"
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
58 JsonUtils jsonUtil = new JsonUtils()
59 VidUtils vidUtils = new VidUtils()
60 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
63 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
66 public InitializeProcessVariables(Execution execution){
67 /* Initialize all the process variables in this block */
69 execution.setVariable("createViprServiceRequest", "")
70 execution.setVariable("globalSubscriberId", "")
71 execution.setVariable("serviceInstanceName", "")
72 execution.setVariable("msoRequestId", "")
73 execution.setVariable("CGMSNV_NetworksCreatedCount", 0)
74 execution.setVariable("CGMSNV_VnfsCreatedCount", 0)
75 execution.setVariable("productFamilyId", "")
78 execution.setVariable("sdncVersion", "1707")
81 // **************************************************
82 // Pre or Prepare Request Section
83 // **************************************************
85 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
88 public void preProcessRequest (Execution execution) {
89 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
90 execution.setVariable("prefix",Prefix)
92 utils.log("DEBUG", " ***** Inside preProcessRequest CreateGenericMacroServiceNetworkVnf Request ***** ", isDebugEnabled)
95 // initialize flow variables
96 InitializeProcessVariables(execution)
98 // check for incoming json message/input
99 String createViprServiceRequest = execution.getVariable("bpmnRequest")
100 utils.logAudit(createViprServiceRequest)
101 execution.setVariable("createViprServiceRequest", createViprServiceRequest);
102 println 'createViprServiceRequest - ' + createViprServiceRequest
105 String requestId = execution.getVariable("mso-request-id")
106 execution.setVariable("msoRequestId", requestId)
108 String serviceInstanceId = execution.getVariable("serviceInstanceId")
110 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
111 serviceInstanceId = UUID.randomUUID().toString()
112 utils.log("DEBUG", " Generated new Service Instance: " + serviceInstanceId , isDebugEnabled)
114 utils.log("DEBUG", "Using provided Service Instance ID: " + serviceInstanceId , isDebugEnabled)
117 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
118 execution.setVariable("serviceInstanceId", serviceInstanceId)
120 String requestAction = execution.getVariable("requestAction")
121 execution.setVariable("requestAction", requestAction)
123 String source = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.requestInfo.source")
124 if ((source == null) || (source.isEmpty())) {
125 execution.setVariable("source", "VID")
127 execution.setVariable("source", source)
130 // extract globalSubscriberId
131 String globalSubscriberId = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.subscriberInfo.globalSubscriberId")
133 // verify element global-customer-id is sent from JSON input, throw exception if missing
134 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
135 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
136 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
139 execution.setVariable("globalSubscriberId", globalSubscriberId)
140 execution.setVariable("globalCustomerId", globalSubscriberId)
143 // extract subscriptionServiceType
144 String subscriptionServiceType = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.requestParameters.subscriptionServiceType")
145 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
146 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
148 String suppressRollback = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.requestInfo.suppressRollback")
149 execution.setVariable("disableRollback", suppressRollback)
150 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
152 String productFamilyId = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.requestInfo.productFamilyId")
153 execution.setVariable("productFamilyId", productFamilyId)
154 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
156 //For Completion Handler & Fallout Handler
158 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
159 <request-id>${requestId}</request-id>
160 <action>CREATE</action>
161 <source>${source}</source>
164 execution.setVariable("CGMSNV_requestInfo", requestInfo)
166 utils.log("DEBUG", " ***** Completed preProcessRequest CreateGenericMacroServiceNetworkVnf Request ***** ", isDebugEnabled)
168 } catch (BpmnError e) {
171 } catch (Exception ex){
172 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
173 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
177 public void sendSyncResponse (Execution execution) {
178 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
180 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
183 String serviceInstanceId = execution.getVariable("serviceInstanceId")
184 String requestId = execution.getVariable("mso-request-id")
186 // RESTResponse (for API Handler (APIH) Reply Task)
187 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
189 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
190 sendWorkflowResponse(execution, 202, syncResponse)
192 } catch (Exception ex) {
193 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
194 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
198 // *******************************
200 // *******************************
201 public void prepareDecomposeService(Execution execution) {
202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
205 utils.log("DEBUG", " ***** Inside prepareDecomposeService of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
207 String createViprServiceRequest = execution.getVariable("createViprServiceRequest")
208 String serviceModelInfo = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.modelInfo")
209 execution.setVariable("serviceModelInfo", serviceModelInfo)
211 utils.log("DEBUG", " ***** Completed prepareDecomposeService of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
212 } catch (Exception ex) {
213 // try error in method block
214 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
215 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
219 // *******************************
221 // *******************************
222 public void prepareCreateServiceInstance(Execution execution) {
223 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
226 utils.log("DEBUG", " ***** Inside prepareCreateServiceInstance of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
229 * Service modelInfo is created in earlier step. This flow can use it as-is ... or, extract from DecompositionObject
230 * ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
231 * ModelInfo modelInfo = serviceDecomposition.getModelInfo()
234 String createViprServiceRequest = execution.getVariable("createViprServiceRequest")
235 String serviceInputParams = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.requestParameters")
236 execution.setVariable("serviceInputParams", serviceInputParams)
238 String serviceInstanceName = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.requestInfo.instanceName")
239 execution.setVariable("serviceInstanceName", serviceInstanceName)
241 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
242 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())
244 utils.log("DEBUG", " ***** Completed prepareCreateServiceInstance of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
245 } catch (Exception ex) {
246 // try error in method block
247 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareCreateServiceInstance() - " + ex.getMessage()
248 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
252 public void postProcessServiceInstanceCreate (Execution execution){
253 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +'execution=' + execution.getId() +')'
254 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
255 logDebug('Entered ' + method, isDebugLogEnabled)
257 String source = execution.getVariable("source")
258 String requestId = execution.getVariable("mso-request-id")
259 String serviceInstanceId = execution.getVariable("serviceInstanceId")
260 String serviceInstanceName = execution.getVariable("serviceInstanceName")
265 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
268 <req:updateInfraRequest>
269 <requestId>${requestId}</requestId>
270 <lastModifiedBy>BPEL</lastModifiedBy>
271 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
272 <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>
273 </req:updateInfraRequest>
277 execution.setVariable("CGMSNV_setUpdateDbInstancePayload", payload)
278 utils.logAudit("CGMSNV_setUpdateDbInstancePayload: " + payload)
279 logDebug('Exited ' + method, isDebugLogEnabled)
280 //println("CMSO_updateDBStatusToSuccessPayload --> " + execution.getVariable("CMSO_updateDBStatusToSuccessPayload"))
282 } catch (BpmnError e) {
284 } catch (Exception e) {
285 logError('Caught exception in ' + method, e)
286 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
291 public void getDataFromDecomposition (Execution execution) {
292 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
294 utils.log("DEBUG", " ***** Inside getDataFromDecomposition() of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
298 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
300 List<NetworkResource> networkList = serviceDecomposition.getServiceNetworks()
302 //utils.log("DEBUG", "got network list: "+ networkList.toString(), isDebugEnabled)
303 execution.setVariable("networkList", networkList)
304 execution.setVariable("networkListString", networkList.toString())
306 networkList = execution.getVariable("networkList");
307 utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
309 if (networkList != null && networkList.size() > 0) {
311 execution.setVariable("CGMSNV_NetworksCount", networkList.size())
312 utils.log("DEBUG", "networks to create: "+ networkList.size(), isDebugEnabled)
314 execution.setVariable("CGMSNV_NetworksCount", 0)
315 utils.log("DEBUG", "no networks to create based upon serviceDecomposition content", isDebugEnabled)
319 List<VnfResource> vnfList = serviceDecomposition.getServiceVnfs()
320 execution.setVariable("vnfList", vnfList)
322 String vnfModelInfoString = ""
323 if (vnfList != null && vnfList.size() > 0) {
324 execution.setVariable("CGMSNV_VNFsCount", vnfList.size())
325 utils.log("DEBUG", "vnfs to create: "+ vnfList.size(), isDebugEnabled)
326 ModelInfo vnfModelInfo = vnfList[0].getModelInfo()
327 String vnfModelInfoWithRoot = vnfModelInfo.toString()
328 vnfModelInfoString = jsonUtil.getJsonValue(vnfModelInfoWithRoot, "modelInfo")
330 execution.setVariable("CGMSNV_VNFsCount", 0)
331 utils.log("DEBUG", "no vnfs to create based upon Catalog DB response", isDebugEnabled)
334 execution.setVariable("vnfModelInfo", vnfModelInfoString)
335 //utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
337 utils.log("DEBUG", " ***** Completed getDataFromDecomposition() of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
338 } catch (Exception ex) {
339 sendSyncError(execution)
340 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. getDataFromDecomposition() - " + ex.getMessage()
341 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
342 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
346 // *******************************
347 // Generate Network request Section
348 // *******************************
349 public void prepareNetworkCreate (Execution execution) {
350 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
353 utils.log("DEBUG", " ***** Inside preparenNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
355 // String disableRollback = execution.getVariable("disableRollback")
356 // def backoutOnFailure = ""
357 // if(disableRollback != null){
358 // if ( disableRollback == true) {
359 // backoutOnFailure = "false"
360 // } else if ( disableRollback == false) {
361 // backoutOnFailure = "true"
364 //failIfExists - optional
366 String createViprServiceRequest = execution.getVariable("createViprServiceRequest")
368 JSONArray networkList = execution.getVariable("networkList")
369 utils.log("DEBUG", "array networkList: "+ networkList, isDebugEnabled)
371 if (networkList == null || networkList.size() < 1){
372 networkList = new JSONArray(execution.getVariable("networkListString"))
373 utils.log("DEBUG", "array from string networkList: "+ networkList, isDebugEnabled)
376 Integer networksCreatedCount = execution.getVariable("CGMSNV_NetworksCreatedCount")
377 String networkModelInfoString = ""
379 if (networkList != null) {
380 utils.log("DEBUG", " getting model info for network # :" + networksCreatedCount, isDebugEnabled)
381 ModelInfo networkModelInfo = networkList[networksCreatedCount.intValue()].getModelInfo()
382 networkModelInfoString = networkModelInfo.toString()
384 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected number of networks to create - " + ex.getMessage()
385 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
388 execution.setVariable("networkModelInfo", networkModelInfoString)
389 utils.log("DEBUG", " networkModelInfoString :" + networkModelInfoString, isDebugEnabled)
391 // String networkModelInfo = execution.getVariable("networkModelInfo")
392 // extract cloud configuration
393 String lcpCloudRegionId = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
394 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
395 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
396 String tenantId = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.cloudConfiguration.tenantId")
397 execution.setVariable("tenantId", tenantId)
398 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
400 String sdncVersion = execution.getVariable("sdncVersion")
401 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
403 List<VnfResource> vnfList = execution.getVariable("vnfList")
404 utils.log("DEBUG", "vnfList: "+ vnfList.toString(), isDebugEnabled)
406 String vnfModelInfo = execution.getVariable("vnfModelInfo")
407 utils.log("DEBUG", "vnfModelInfo: "+ vnfModelInfo, isDebugEnabled)
409 networkList = execution.getVariable("networkList")
410 utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
412 utils.log("DEBUG", " ***** Completed preparenNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
413 } catch (Exception ex) {
414 // try error in method block
415 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareNetworkCreate() - " + ex.getMessage()
416 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
420 // *******************************
421 // Validate Network request Section -> increment count
422 // *******************************
423 public void validateNetworkCreate (Execution execution) {
424 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
427 utils.log("DEBUG", " ***** Inside validateNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
429 Integer networksCreatedCount = execution.getVariable("CGMSNV_NetworksCreatedCount")
430 networksCreatedCount++
432 execution.setVariable("CGMSNV_NetworksCreatedCount", networksCreatedCount)
434 execution.setVariable("DCRENI_rollbackData"+networksCreatedCount, execution.getVariable("DCRENI_rollbackData"))
436 utils.log("DEBUG", "networksCreatedCount: "+ networksCreatedCount, isDebugEnabled)
437 utils.log("DEBUG", "DCRENI_rollbackData N : "+ execution.getVariable("DCRENI_rollbackData"+networksCreatedCount), isDebugEnabled)
439 JSONArray vnfList = execution.getVariable("vnfList")
440 utils.log("DEBUG", "vnfList: "+ vnfList, isDebugEnabled)
442 String vnfModelInfo = execution.getVariable("vnfModelInfo")
443 utils.log("DEBUG", "vnfModelInfo: "+ vnfModelInfo, isDebugEnabled)
445 JSONArray networkList = execution.getVariable("networkList")
446 utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
448 utils.log("DEBUG", " ***** Completed validateNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** "+" network # "+networksCreatedCount, isDebugEnabled)
449 } catch (Exception ex) {
450 // try error in method block
451 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateNetworkCreate() - " + ex.getMessage()
452 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
456 // *******************************
457 // Generate Network request Section
458 // *******************************
459 public void prepareVnfAndModulesCreate (Execution execution) {
460 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
463 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
465 // String disableRollback = execution.getVariable("disableRollback")
466 // def backoutOnFailure = ""
467 // if(disableRollback != null){
468 // if ( disableRollback == true) {
469 // backoutOnFailure = "false"
470 // } else if ( disableRollback == false) {
471 // backoutOnFailure = "true"
474 //failIfExists - optional
476 String createViprServiceRequest = execution.getVariable("createViprServiceRequest")
477 String productFamilyId = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.requestInfo.productFamilyId")
478 execution.setVariable("productFamilyId", productFamilyId)
479 utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)
481 List<VnfResource> vnfList = execution.getVariable("vnfList")
483 Integer vnfsCreatedCount = execution.getVariable("CGMSNV_VnfsCreatedCount")
484 String vnfModelInfoString = null;
486 if (vnfList != null && vnfList.size() > 0 ) {
487 utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)
488 ModelInfo vnfModelInfo1 = vnfList[0].getModelInfo()
489 utils.log("DEBUG", "got 0 ", isDebugEnabled)
490 ModelInfo vnfModelInfo = vnfList[vnfsCreatedCount.intValue()].getModelInfo()
491 vnfModelInfoString = vnfModelInfo.toString()
493 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VIPR use model stored
494 vnfModelInfoString = execution.getVariable("vnfModelInfo")
497 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
499 // extract cloud configuration
500 String lcpCloudRegionId = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
501 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
502 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
503 String tenantId = jsonUtil.getJsonValue(createViprServiceRequest, "requestDetails.cloudConfiguration.tenantId")
504 execution.setVariable("tenantId", tenantId)
505 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
507 String sdncVersion = execution.getVariable("sdncVersion")
508 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
510 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
511 } catch (Exception ex) {
512 // try error in method block
513 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
514 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
518 // *******************************
519 // Validate Vnf request Section -> increment count
520 // *******************************
521 public void validateVnfCreate (Execution execution) {
522 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
525 utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
527 Integer vnfsCreatedCount = execution.getVariable("CGMSNV_VnfsCreatedCount")
530 execution.setVariable("CGMSNV_VnfsCreatedCount", vnfsCreatedCount)
532 utils.log("DEBUG", " ***** Completed validateVnfCreate of CreateGenericMacroServiceNetworkVnf ***** "+" vnf # "+vnfsCreatedCount, isDebugEnabled)
533 } catch (Exception ex) {
534 // try error in method block
535 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
536 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
540 // *******************************
541 // Validate Network request Section -> decrement count
542 // *******************************
543 public void validateNetworkRollback (Execution execution) {
544 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
547 utils.log("DEBUG", " ***** Inside validateNetworkRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
549 Integer networksCreatedCount = execution.getVariable("CGMSNV_NetworksCreatedCount")
550 networksCreatedCount--
552 execution.setVariable("CGMSNV_NetworksCreatedCount", networksCreatedCount)
554 execution.setVariable("DCRENI_rollbackData", execution.getVariable("DCRENI_rollbackData"+networksCreatedCount))
556 utils.log("DEBUG", " ***** Completed validateNetworkRollback of CreateGenericMacroServiceNetworkVnf ***** "+" network # "+networksCreatedCount, isDebugEnabled)
557 } catch (Exception ex) {
558 // try error in method block
559 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateNetworkRollback() - " + ex.getMessage()
560 //exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
561 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
562 execution.setVariable("CGMSNV_NetworksCreatedCount", 0)
563 utils.log("ERROR", exceptionMessage, true)
567 // public void extractServiceModelInfo (Execution execution) {
568 // def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
570 // utils.log("DEBUG"," ***** extractServiceModelInfo of CreateGenericMacroServiceNetworkVnf *****", isDebugEnabled)
574 // // check for input
575 // String requestId = execution.getVariable("msoRequestId")
577 // ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
578 // ModelInfo modelInfo = serviceDecomposition.getModelInfo()
580 // utils.log("DEBUG", "modelInfo: "+ modelInfo.toJsonString(), isDebugEnabled)
581 // utils.log("DEBUG", "modelInfo: "+ modelInfo, isDebugEnabled)
582 // execution.setVariable("serviceDecomposition", modelInfo)
584 // utils.log("DEBUG"," ***** Exit extractServiceModelInfo of CreateGenericMacroServiceNetworkVnf *****", isDebugEnabled)
586 // } catch (BpmnError e) {
588 // } catch (Exception ex){
589 // msg = "Exception in extractServiceModelInfo " + ex.getMessage()
590 // utils.log("DEBUG", msg, isDebugEnabled)
591 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
593 // utils.log("DEBUG"," ***** Exit extractServiceModelInfo of DecomposeService *****", isDebugEnabled)
596 // *******************************
597 // Build DB request Section
598 // *******************************
599 // public void prepareDBRequest (Execution execution) {
600 // def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
603 // utils.log("DEBUG", " ***** Inside prepareDBRequest of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
605 // String requestId = execution.getVariable("CGMSNV_requestId")
606 // String statusMessage = "vIPR ATM Service Instance successfully created."
607 // String serviceInstanceId = execution.getVariable("CGMSNV_serviceInstanceId")
609 // //TODO - verify the format for Service Instance Create,
610 // String dbRequest =
611 // """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
614 // <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
615 // <requestId>${requestId}</requestId>
616 // <lastModifiedBy>BPMN</lastModifiedBy>
617 // <statusMessage>${statusMessage}</statusMessage>
618 // <responseBody></responseBody>
619 // <requestStatus>COMPLETED</requestStatus>
620 // <progress>100</progress>
622 // <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
623 // </ns:updateInfraRequest>
625 // </soapenv:Envelope>"""
627 // String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
628 // execution.setVariable("CGMSNV_createDBRequest", buildDeleteDBRequestAsString)
629 // utils.logAudit(buildDeleteDBRequestAsString)
631 // utils.log("DEBUG", " ***** Completed prepareDBRequest of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
632 // } catch (Exception ex) {
633 // // try error in method block
634 // String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
635 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
642 // *****************************************
643 // Prepare Completion request Section
644 // *****************************************
645 public void postProcessResponse (Execution execution) {
646 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
648 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
651 String source = execution.getVariable("source")
652 String requestId = execution.getVariable("mso-request-id")
653 String serviceInstanceId = execution.getVariable("serviceInstanceId")
655 String msoCompletionRequest =
656 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
657 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
658 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
659 <request-id>${requestId}</request-id>
660 <action>CREATE</action>
661 <source>${source}</source>
663 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
664 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
665 <mso-bpel-name>BPMN macro create</mso-bpel-name>
666 </aetgt:MsoCompletionRequest>"""
669 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
671 utils.logAudit(xmlMsoCompletionRequest)
672 execution.setVariable("CGMSNV_Success", true)
673 execution.setVariable("CGMSNV_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
674 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
675 } catch (BpmnError e) {
677 } catch (Exception ex) {
678 // try error in method block
679 String exceptionMessage = "Bpmn error encountered in CreateServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
680 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
684 public void preProcessRollback (Execution execution) {
685 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
686 utils.log("DEBUG"," ***** preProcessRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
689 Object workflowException = execution.getVariable("WorkflowException");
691 if (workflowException instanceof WorkflowException) {
692 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
693 execution.setVariable("prevWorkflowException", workflowException);
694 //execution.setVariable("WorkflowException", null);
696 } catch (BpmnError e) {
697 utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
698 } catch(Exception ex) {
699 String msg = "Exception in preProcessRollback. " + ex.getMessage()
700 utils.log("DEBUG", msg, isDebugEnabled)
702 utils.log("DEBUG"," *** Exit preProcessRollback of CreateGenericMacroServiceNetworkVnf *** ", isDebugEnabled)
705 public void postProcessRollback (Execution execution) {
706 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
707 utils.log("DEBUG"," ***** postProcessRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
710 Object workflowException = execution.getVariable("prevWorkflowException");
711 if (workflowException instanceof WorkflowException) {
712 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
713 execution.setVariable("WorkflowException", workflowException);
715 } catch (BpmnError b) {
716 utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
718 } catch(Exception ex) {
719 msg = "Exception in postProcessRollback. " + ex.getMessage()
720 utils.log("DEBUG", msg, isDebugEnabled)
722 utils.log("DEBUG"," *** Exit postProcessRollback of CreateGenericMacroServiceNetworkVnf *** ", isDebugEnabled)
725 public void prepareFalloutRequest(Execution execution){
726 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
728 utils.log("DEBUG", " *** STARTED CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process *** ", isDebugEnabled)
731 WorkflowException wfex = execution.getVariable("WorkflowException")
732 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
733 String requestInfo = execution.getVariable("CGMSNV_requestInfo")
734 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
736 //TODO. hmmm. there is no way to UPDATE error message.
737 // String errorMessage = wfex.getErrorMessage()
738 // boolean successIndicator = execution.getVariable("DCRESI_rollbackSuccessful")
739 // if (successIndicator){
740 // errorMessage = errorMessage + ". Rollback successful."
742 // errorMessage = errorMessage + ". Rollback not completed."
745 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
747 execution.setVariable("CGMSNV_falloutRequest", falloutRequest)
749 } catch (Exception ex) {
750 utils.log("DEBUG", "Error Occured in CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
751 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process")
753 utils.log("DEBUG", "*** COMPLETED CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process ***", isDebugEnabled)
757 public void sendSyncError (Execution execution) {
758 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
759 execution.setVariable("prefix", Prefix)
761 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateServiceInstanceInfra ***** ", isDebugEnabled)
764 String errorMessage = ""
765 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
766 WorkflowException wfe = execution.getVariable("WorkflowException")
767 errorMessage = wfe.getErrorMessage()
769 errorMessage = "Sending Sync Error."
772 String buildworkflowException =
773 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
774 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
775 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
776 </aetgt:WorkflowException>"""
778 utils.logAudit(buildworkflowException)
779 sendWorkflowResponse(execution, 500, buildworkflowException)
780 } catch (Exception ex) {
781 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
785 public void processJavaException(Execution execution){
786 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
787 execution.setVariable("prefix",Prefix)
789 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
790 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
791 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
792 execution.setVariable("CRESI_unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
793 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
795 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
798 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
799 execution.setVariable("CRESI_unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
800 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
802 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)