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
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
23 import groovy.xml.XmlUtil
\r
24 import groovy.json.*
\r
26 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
28 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
\r
29 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
31 import org.openecomp.mso.bpmn.core.WorkflowException
\r
32 import org.openecomp.mso.rest.APIResponse;
\r
33 import org.openecomp.mso.rest.RESTClient
\r
34 import org.openecomp.mso.rest.RESTConfig
\r
36 import java.util.UUID;
\r
38 import org.camunda.bpm.engine.delegate.BpmnError
\r
39 import org.camunda.bpm.engine.runtime.Execution
\r
40 import org.json.JSONObject;
\r
41 import org.json.JSONArray;
\r
42 import org.apache.commons.lang3.*
\r
43 import org.apache.commons.codec.binary.Base64;
\r
44 import org.springframework.web.util.UriUtils;
\r
47 * This groovy class supports the <class>CreateGenericMacroServiceNetworkVnf.bpmn</class> process.
\r
50 public class CreateGenericMacroServiceNetworkVnf extends AbstractServiceTaskProcessor {
\r
52 String Prefix="CREVAS_"
\r
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
54 JsonUtils jsonUtil = new JsonUtils()
\r
55 VidUtils vidUtils = new VidUtils()
\r
56 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
\r
59 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
62 public InitializeProcessVariables(Execution execution){
\r
63 /* Initialize all the process variables in this block */
\r
65 execution.setVariable("createGenericMacroServiceNetworkVnfRequest", "")
\r
66 execution.setVariable("globalSubscriberId", "")
\r
67 execution.setVariable("serviceInstanceName", "")
\r
68 execution.setVariable("msoRequestId", "")
\r
69 execution.setVariable("CREVAS_NetworksCreatedCount", 0)
\r
70 execution.setVariable("CREVAS_VnfsCreatedCount", 0)
\r
71 execution.setVariable("productFamilyId", "")
\r
75 execution.setVariable("sdncVersion", "1702")
\r
78 // **************************************************
\r
79 // Pre or Prepare Request Section
\r
80 // **************************************************
\r
82 * This method is executed during the preProcessRequest task of the <class>CreateServiceInstance.bpmn</class> process.
\r
85 public void preProcessRequest (Execution execution) {
\r
86 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
87 execution.setVariable("prefix",Prefix)
\r
89 utils.log("DEBUG", " ***** Inside preProcessRequest CreateGenericMacroServiceNetworkVnf Request ***** ", isDebugEnabled)
\r
92 // initialize flow variables
\r
93 InitializeProcessVariables(execution)
\r
95 // check for incoming json message/input
\r
96 String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("bpmnRequest")
\r
97 utils.logAudit(createGenericMacroServiceNetworkVnfRequest)
\r
98 execution.setVariable("createGenericMacroServiceNetworkVnfRequest", createGenericMacroServiceNetworkVnfRequest);
\r
99 println 'createGenericMacroServiceNetworkVnfRequest - ' + createGenericMacroServiceNetworkVnfRequest
\r
101 // extract requestId
\r
102 String requestId = execution.getVariable("mso-request-id")
\r
103 execution.setVariable("msoRequestId", requestId)
\r
105 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
107 if ((serviceInstanceId == null) || (serviceInstanceId.isEmpty())) {
\r
108 serviceInstanceId = UUID.randomUUID().toString()
\r
109 utils.log("DEBUG", " Generated new Service Instance: " + serviceInstanceId , isDebugEnabled)
\r
111 utils.log("DEBUG", "Using provided Service Instance ID: " + serviceInstanceId , isDebugEnabled)
\r
114 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
\r
115 execution.setVariable("serviceInstanceId", serviceInstanceId)
\r
117 String requestAction = execution.getVariable("requestAction")
\r
118 execution.setVariable("requestAction", requestAction)
\r
120 String source = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.source")
\r
121 if ((source == null) || (source.isEmpty())) {
\r
122 execution.setVariable("source", "VID")
\r
124 execution.setVariable("source", source)
\r
127 // extract globalSubscriberId
\r
128 String globalSubscriberId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.subscriberInfo.globalSubscriberId")
\r
130 // verify element global-customer-id is sent from JSON input, throw exception if missing
\r
131 if ((globalSubscriberId == null) || (globalSubscriberId.isEmpty())) {
\r
132 String dataErrorMessage = " Element 'globalSubscriberId' is missing. "
\r
133 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
136 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
137 execution.setVariable("globalCustomerId", globalSubscriberId)
\r
140 // extract subscriptionServiceType
\r
141 String subscriptionServiceType = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestParameters.subscriptionServiceType")
\r
142 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
143 utils.log("DEBUG", "Incoming subscriptionServiceType is: " + subscriptionServiceType, isDebugEnabled)
\r
145 String suppressRollback = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.suppressRollback")
\r
146 execution.setVariable("disableRollback", suppressRollback)
\r
147 utils.log("DEBUG", "Incoming Suppress/Disable Rollback is: " + suppressRollback, isDebugEnabled)
\r
149 String productFamilyId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.productFamilyId")
\r
150 execution.setVariable("productFamilyId", productFamilyId)
\r
151 utils.log("DEBUG", "Incoming productFamilyId is: " + productFamilyId, isDebugEnabled)
\r
153 //For Completion Handler & Fallout Handler
\r
154 String requestInfo =
\r
155 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
156 <request-id>${requestId}</request-id>
\r
157 <action>CREATE</action>
\r
158 <source>${source}</source>
\r
161 execution.setVariable("CREVAS_requestInfo", requestInfo)
\r
163 utils.log("DEBUG", " ***** Completed preProcessRequest CreateGenericMacroServiceNetworkVnf Request ***** ", isDebugEnabled)
\r
165 } catch (BpmnError e) {
\r
168 } catch (Exception ex){
\r
169 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected from method preProcessRequest() - " + ex.getMessage()
\r
170 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
174 public void sendSyncResponse (Execution execution) {
\r
175 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
177 utils.log("DEBUG", " ***** Inside sendSyncResponse of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
180 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
181 String requestId = execution.getVariable("mso-request-id")
\r
183 // RESTResponse (for API Handler (APIH) Reply Task)
\r
184 String syncResponse ="""{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
186 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
187 sendWorkflowResponse(execution, 202, syncResponse)
\r
189 } catch (Exception ex) {
\r
190 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected from method sendSyncResponse() - " + ex.getMessage()
\r
191 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
195 // *******************************
\r
197 // *******************************
\r
198 public void prepareCreateServiceInstance(Execution execution) {
\r
199 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
202 utils.log("DEBUG", " ***** Inside prepareCreateServiceInstance of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
204 String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("createGenericMacroServiceNetworkVnfRequest")
\r
205 String serviceModelInfo = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.modelInfo")
\r
206 execution.setVariable("serviceModelInfo", serviceModelInfo)
\r
208 String serviceInputParams = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestParameters")
\r
209 execution.setVariable("serviceInputParams", serviceInputParams)
\r
211 String serviceInstanceName = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.instanceName")
\r
212 execution.setVariable("serviceInstanceName", serviceInstanceName)
\r
214 utils.log("DEBUG", " ***** Completed prepareCreateServiceInstance of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
215 } catch (Exception ex) {
\r
216 // try error in method block
\r
217 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareCreateService() - " + ex.getMessage()
\r
218 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
223 public void postProcessServiceInstanceCreate (Execution execution){
\r
224 def method = getClass().getSimpleName() + '.postProcessServiceInstanceCreate(' +'execution=' + execution.getId() +')'
\r
225 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
226 logDebug('Entered ' + method, isDebugLogEnabled)
\r
228 String source = execution.getVariable("source")
\r
229 String requestId = execution.getVariable("mso-request-id")
\r
230 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
231 String serviceInstanceName = execution.getVariable("serviceInstanceName")
\r
235 String payload = """
\r
236 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
239 <req:updateInfraRequest>
\r
240 <requestId>${requestId}</requestId>
\r
241 <lastModifiedBy>BPEL</lastModifiedBy>
\r
242 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
243 <serviceInstanceName>${serviceInstanceName}</serviceInstanceName>
\r
244 </req:updateInfraRequest>
\r
246 </soapenv:Envelope>
\r
248 execution.setVariable("CREVAS_setUpdateDbInstancePayload", payload)
\r
249 utils.logAudit("CREVAS_setUpdateDbInstancePayload: " + payload)
\r
250 logDebug('Exited ' + method, isDebugLogEnabled)
\r
251 //println("CMSO_updateDBStatusToSuccessPayload --> " + execution.getVariable("CMSO_updateDBStatusToSuccessPayload"))
\r
253 } catch (BpmnError e) {
\r
255 } catch (Exception e) {
\r
256 logError('Caught exception in ' + method, e)
\r
257 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
262 public void callDBCatalog (Execution execution) {
\r
263 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
265 utils.log("DEBUG", " ***** Inside callDBCatalog() of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
269 // get variable within incoming json
\r
270 String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("createGenericMacroServiceNetworkVnfRequest");
\r
272 String catalog_db_endpoint = execution.getVariable("URN_mso_catalog_db_endpoint")
\r
273 utils.log("DEBUG", "catalog_db_endpoint: "+catalog_db_endpoint, isDebugEnabled)
\r
275 String serviceModelInvariantId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.modelInfo.modelInvariantId")
\r
276 String serviceModelVersion = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.modelInfo.modelVersion")
\r
277 utils.log("DEBUG", "getting network list ", isDebugEnabled)
\r
279 JSONArray networkList = catalogDbUtils.getAllNetworksByServiceModelInvariantUuidAndServiceModelVersion(catalog_db_endpoint, serviceModelInvariantId, serviceModelVersion)
\r
281 //utils.log("DEBUG", "got network list: "+ networkList.toString(), isDebugEnabled)
\r
282 execution.setVariable("networkList", networkList)
\r
283 execution.setVariable("networkListString", networkList.toString())
\r
285 networkList = execution.getVariable("networkList");
\r
286 utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
\r
288 if (networkList != null && networkList.length() > 0) {
\r
290 execution.setVariable("CREVAS_NetworksCount", networkList.length())
\r
291 utils.log("DEBUG", "networks to create: "+ networkList.length(), isDebugEnabled)
\r
293 execution.setVariable("CREVAS_NetworksCount", 0)
\r
294 utils.log("DEBUG", "no networks to create based upon Catalog DB response", isDebugEnabled)
\r
298 JSONArray vnfList = catalogDbUtils.getAllVnfsByServiceModelInvariantUuidAndServiceModelVersion(catalog_db_endpoint, serviceModelInvariantId, serviceModelVersion)
\r
299 execution.setVariable("vnfList", vnfList)
\r
301 String vnfModelInfoString = ""
\r
302 if (vnfList != null && vnfList.length() > 0) {
\r
303 execution.setVariable("CREVAS_VNFsCount", vnfList.length())
\r
304 utils.log("DEBUG", "vnfs to create: "+ vnfList.length(), isDebugEnabled)
\r
305 JSONObject vnfModelInfo = vnfList.getJSONObject(0).getJSONObject("modelInfo")
\r
306 vnfModelInfoString = vnfModelInfo.toString()
\r
308 execution.setVariable("CREVAS_VNFsCount", 0)
\r
309 utils.log("DEBUG", "no vnfs to create based upon Catalog DB response", isDebugEnabled)
\r
312 execution.setVariable("vnfModelInfo", vnfModelInfoString)
\r
313 //utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
\r
315 utils.log("DEBUG", " ***** Completed callDBCatalog() of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
316 } catch (Exception ex) {
\r
317 sendSyncError(execution)
\r
318 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. callDBCatalog() - " + ex.getMessage()
\r
319 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
320 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
324 // *******************************
\r
325 // Generate Network request Section
\r
326 // *******************************
\r
327 public void prepareNetworkCreate (Execution execution) {
\r
328 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
331 utils.log("DEBUG", " ***** Inside preparenNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
333 // String disableRollback = execution.getVariable("disableRollback")
\r
334 // def backoutOnFailure = ""
\r
335 // if(disableRollback != null){
\r
336 // if ( disableRollback == true) {
\r
337 // backoutOnFailure = "false"
\r
338 // } else if ( disableRollback == false) {
\r
339 // backoutOnFailure = "true"
\r
342 //failIfExists - optional
\r
344 String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("createGenericMacroServiceNetworkVnfRequest")
\r
346 JSONArray networkList = execution.getVariable("networkList")
\r
347 utils.log("DEBUG", "array networkList: "+ networkList, isDebugEnabled)
\r
349 if (networkList == null || networkList.length() < 1){
\r
350 networkList = new JSONArray(execution.getVariable("networkListString"))
\r
351 utils.log("DEBUG", "array from string networkList: "+ networkList, isDebugEnabled)
\r
354 Integer networksCreatedCount = execution.getVariable("CREVAS_NetworksCreatedCount")
\r
355 String networkModelInfoString = ""
\r
357 if (networkList != null) {
\r
358 utils.log("DEBUG", " getting model info for network # :" + networksCreatedCount, isDebugEnabled)
\r
359 JSONObject networkModelInfo = networkList.getJSONObject(networksCreatedCount.intValue()).getJSONObject("modelInfo")
\r
360 networkModelInfoString = networkModelInfo.toString()
\r
362 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected number of networks to create - " + ex.getMessage()
\r
363 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
366 execution.setVariable("networkModelInfo", networkModelInfoString)
\r
367 utils.log("DEBUG", " networkModelInfoString :" + networkModelInfoString, isDebugEnabled)
\r
369 // String networkModelInfo = execution.getVariable("networkModelInfo")
\r
370 // extract cloud configuration
\r
371 String lcpCloudRegionId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
\r
372 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
\r
373 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
\r
374 String tenantId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.tenantId")
\r
375 execution.setVariable("tenantId", tenantId)
\r
376 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
\r
378 String sdncVersion = execution.getVariable("sdncVersion")
\r
379 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
\r
381 JSONArray vnfList = execution.getVariable("vnfList")
\r
382 utils.log("DEBUG", "vnfList: "+ vnfList, isDebugEnabled)
\r
384 String vnfModelInfo = execution.getVariable("vnfModelInfo")
\r
385 utils.log("DEBUG", "vnfModelInfo: "+ vnfModelInfo, isDebugEnabled)
\r
387 networkList = execution.getVariable("networkList")
\r
388 utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
\r
390 utils.log("DEBUG", " ***** Completed preparenNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
391 } catch (Exception ex) {
\r
392 // try error in method block
\r
393 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareNetworkCreate() - " + ex.getMessage()
\r
394 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
398 // *******************************
\r
399 // Validate Network request Section -> increment count
\r
400 // *******************************
\r
401 public void validateNetworkCreate (Execution execution) {
\r
402 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
405 utils.log("DEBUG", " ***** Inside validateNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
407 Integer networksCreatedCount = execution.getVariable("CREVAS_NetworksCreatedCount")
\r
408 networksCreatedCount++
\r
410 execution.setVariable("CREVAS_NetworksCreatedCount", networksCreatedCount)
\r
412 execution.setVariable("DCRENI_rollbackData"+networksCreatedCount, execution.getVariable("DCRENI_rollbackData"))
\r
414 utils.log("DEBUG", "networksCreatedCount: "+ networksCreatedCount, isDebugEnabled)
\r
415 utils.log("DEBUG", "DCRENI_rollbackData N : "+ execution.getVariable("DCRENI_rollbackData"+networksCreatedCount), isDebugEnabled)
\r
417 JSONArray vnfList = execution.getVariable("vnfList")
\r
418 utils.log("DEBUG", "vnfList: "+ vnfList, isDebugEnabled)
\r
420 String vnfModelInfo = execution.getVariable("vnfModelInfo")
\r
421 utils.log("DEBUG", "vnfModelInfo: "+ vnfModelInfo, isDebugEnabled)
\r
423 JSONArray networkList = execution.getVariable("networkList")
\r
424 utils.log("DEBUG", "networkList: "+ networkList, isDebugEnabled)
\r
426 utils.log("DEBUG", " ***** Completed validateNetworkCreate of CreateGenericMacroServiceNetworkVnf ***** "+" network # "+networksCreatedCount, isDebugEnabled)
\r
427 } catch (Exception ex) {
\r
428 // try error in method block
\r
429 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateNetworkCreate() - " + ex.getMessage()
\r
430 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
434 // *******************************
\r
435 // Generate Network request Section
\r
436 // *******************************
\r
437 public void prepareVnfAndModulesCreate (Execution execution) {
\r
438 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
441 utils.log("DEBUG", " ***** Inside prepareVnfAndModulesCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
443 // String disableRollback = execution.getVariable("disableRollback")
\r
444 // def backoutOnFailure = ""
\r
445 // if(disableRollback != null){
\r
446 // if ( disableRollback == true) {
\r
447 // backoutOnFailure = "false"
\r
448 // } else if ( disableRollback == false) {
\r
449 // backoutOnFailure = "true"
\r
452 //failIfExists - optional
\r
454 String createGenericMacroServiceNetworkVnfRequest = execution.getVariable("createGenericMacroServiceNetworkVnfRequest")
\r
455 String productFamilyId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.requestInfo.productFamilyId")
\r
456 execution.setVariable("productFamilyId", productFamilyId)
\r
457 utils.log("DEBUG","productFamilyId: "+ productFamilyId, isDebugEnabled)
\r
459 JSONArray vnfList = execution.getVariable("vnfList")
\r
461 Integer vnfsCreatedCount = execution.getVariable("CREVAS_VnfsCreatedCount")
\r
462 String vnfModelInfoString = null;
\r
464 if (vnfList != null && vnfList.length() > 0 ) {
\r
465 utils.log("DEBUG", "getting model info for vnf # " + vnfsCreatedCount, isDebugEnabled)
\r
466 JSONObject vnfModelInfo1 = vnfList.getJSONObject(0).getJSONObject("modelInfo")
\r
467 utils.log("DEBUG", "got 0 ", isDebugEnabled)
\r
468 JSONObject vnfModelInfo = vnfList.getJSONObject(vnfsCreatedCount.intValue()).getJSONObject("modelInfo")
\r
469 vnfModelInfoString = vnfModelInfo.toString()
\r
471 //TODO: vnfList does not contain data. Need to investigate why ... . Fro VIPR use model stored
\r
472 vnfModelInfoString = execution.getVariable("vnfModelInfo")
\r
475 utils.log("DEBUG", " vnfModelInfoString :" + vnfModelInfoString, isDebugEnabled)
\r
477 // extract cloud configuration
\r
478 String lcpCloudRegionId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
\r
479 execution.setVariable("lcpCloudRegionId", lcpCloudRegionId)
\r
480 utils.log("DEBUG","lcpCloudRegionId: "+ lcpCloudRegionId, isDebugEnabled)
\r
481 String tenantId = jsonUtil.getJsonValue(createGenericMacroServiceNetworkVnfRequest, "requestDetails.cloudConfiguration.tenantId")
\r
482 execution.setVariable("tenantId", tenantId)
\r
483 utils.log("DEBUG","tenantId: "+ tenantId, isDebugEnabled)
\r
485 String sdncVersion = execution.getVariable("sdncVersion")
\r
486 utils.log("DEBUG","sdncVersion: "+ sdncVersion, isDebugEnabled)
\r
488 utils.log("DEBUG", " ***** Completed prepareVnfAndModulesCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
489 } catch (Exception ex) {
\r
490 // try error in method block
\r
491 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareVnfAndModulesCreate() - " + ex.getMessage()
\r
492 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
496 // *******************************
\r
497 // Validate Vnf request Section -> increment count
\r
498 // *******************************
\r
499 public void validateVnfCreate (Execution execution) {
\r
500 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
503 utils.log("DEBUG", " ***** Inside validateVnfCreate of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
505 Integer vnfsCreatedCount = execution.getVariable("CREVAS_VnfsCreatedCount")
\r
508 execution.setVariable("CREVAS_VnfsCreatedCount", vnfsCreatedCount)
\r
510 utils.log("DEBUG", " ***** Completed validateVnfCreate of CreateGenericMacroServiceNetworkVnf ***** "+" vnf # "+vnfsCreatedCount, isDebugEnabled)
\r
511 } catch (Exception ex) {
\r
512 // try error in method block
\r
513 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateVnfCreate() - " + ex.getMessage()
\r
514 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
518 // *******************************
\r
519 // Validate Network request Section -> decrement count
\r
520 // *******************************
\r
521 public void validateNetworkRollback (Execution execution) {
\r
522 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
525 utils.log("DEBUG", " ***** Inside validateNetworkRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
527 Integer networksCreatedCount = execution.getVariable("CREVAS_NetworksCreatedCount")
\r
528 networksCreatedCount--
\r
530 execution.setVariable("CREVAS_NetworksCreatedCount", networksCreatedCount)
\r
532 execution.setVariable("DCRENI_rollbackData", execution.getVariable("DCRENI_rollbackData"+networksCreatedCount))
\r
534 utils.log("DEBUG", " ***** Completed validateNetworkRollback of CreateGenericMacroServiceNetworkVnf ***** "+" network # "+networksCreatedCount, isDebugEnabled)
\r
535 } catch (Exception ex) {
\r
536 // try error in method block
\r
537 String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method validateNetworkRollback() - " + ex.getMessage()
\r
538 //exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
539 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
540 execution.setVariable("CREVAS_NetworksCreatedCount", 0)
\r
541 utils.log("ERROR", exceptionMessage, true)
\r
544 // *******************************
\r
545 // Build DB request Section
\r
546 // *******************************
\r
547 // public void prepareDBRequest (Execution execution) {
\r
548 // def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
551 // utils.log("DEBUG", " ***** Inside prepareDBRequest of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
553 // String requestId = execution.getVariable("CREVAS_requestId")
\r
554 // String statusMessage = "vIPR ATM Service Instance successfully created."
\r
555 // String serviceInstanceId = execution.getVariable("CREVAS_serviceInstanceId")
\r
557 // //TODO - verify the format for Service Instance Create,
\r
558 // String dbRequest =
\r
559 // """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
560 // <soapenv:Header/>
\r
562 // <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
563 // <requestId>${requestId}</requestId>
\r
564 // <lastModifiedBy>BPMN</lastModifiedBy>
\r
565 // <statusMessage>${statusMessage}</statusMessage>
\r
566 // <responseBody></responseBody>
\r
567 // <requestStatus>COMPLETED</requestStatus>
\r
568 // <progress>100</progress>
\r
570 // <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
571 // </ns:updateInfraRequest>
\r
573 // </soapenv:Envelope>"""
\r
575 // String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
\r
576 // execution.setVariable("CREVAS_createDBRequest", buildDeleteDBRequestAsString)
\r
577 // utils.logAudit(buildDeleteDBRequestAsString)
\r
579 // utils.log("DEBUG", " ***** Completed prepareDBRequest of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
580 // } catch (Exception ex) {
\r
581 // // try error in method block
\r
582 // String exceptionMessage = "Bpmn error encountered in CreateGenericMacroServiceNetworkVnf flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
\r
583 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
590 // *****************************************
\r
591 // Prepare Completion request Section
\r
592 // *****************************************
\r
593 public void postProcessResponse (Execution execution) {
\r
594 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
596 utils.log("DEBUG", " ***** Inside postProcessResponse of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
599 String source = execution.getVariable("source")
\r
600 String requestId = execution.getVariable("mso-request-id")
\r
601 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
603 String msoCompletionRequest =
\r
604 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
605 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
606 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
607 <request-id>${requestId}</request-id>
\r
608 <action>CREATE</action>
\r
609 <source>${source}</source>
\r
611 <status-message>Service Instance has been created successfully via macro orchestration</status-message>
\r
612 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
613 <mso-bpel-name>BPMN macro create</mso-bpel-name>
\r
614 </aetgt:MsoCompletionRequest>"""
\r
617 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
619 utils.logAudit(xmlMsoCompletionRequest)
\r
620 execution.setVariable("CREVAS_Success", true)
\r
621 execution.setVariable("CREVAS_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
\r
622 utils.log("DEBUG", " SUCCESS flow, going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
623 } catch (BpmnError e) {
\r
625 } catch (Exception ex) {
\r
626 // try error in method block
\r
627 String exceptionMessage = "Bpmn error encountered in CreateServiceInstance flow. Unexpected Error from method postProcessResponse() - " + ex.getMessage()
\r
628 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
632 public void preProcessRollback (Execution execution) {
\r
633 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
634 utils.log("DEBUG"," ***** preProcessRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
637 Object workflowException = execution.getVariable("WorkflowException");
\r
639 if (workflowException instanceof WorkflowException) {
\r
640 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
\r
641 execution.setVariable("prevWorkflowException", workflowException);
\r
642 //execution.setVariable("WorkflowException", null);
\r
644 } catch (BpmnError e) {
\r
645 utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
\r
646 } catch(Exception ex) {
\r
647 String msg = "Exception in preProcessRollback. " + ex.getMessage()
\r
648 utils.log("DEBUG", msg, isDebugEnabled)
\r
650 utils.log("DEBUG"," *** Exit preProcessRollback of CreateGenericMacroServiceNetworkVnf *** ", isDebugEnabled)
\r
653 public void postProcessRollback (Execution execution) {
\r
654 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
655 utils.log("DEBUG"," ***** postProcessRollback of CreateGenericMacroServiceNetworkVnf ***** ", isDebugEnabled)
\r
658 Object workflowException = execution.getVariable("prevWorkflowException");
\r
659 if (workflowException instanceof WorkflowException) {
\r
660 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
\r
661 execution.setVariable("WorkflowException", workflowException);
\r
663 } catch (BpmnError b) {
\r
664 utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
\r
666 } catch(Exception ex) {
\r
667 msg = "Exception in postProcessRollback. " + ex.getMessage()
\r
668 utils.log("DEBUG", msg, isDebugEnabled)
\r
670 utils.log("DEBUG"," *** Exit postProcessRollback of CreateGenericMacroServiceNetworkVnf *** ", isDebugEnabled)
\r
673 public void prepareFalloutRequest(Execution execution){
\r
674 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
676 utils.log("DEBUG", " *** STARTED CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process *** ", isDebugEnabled)
\r
679 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
680 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
681 String requestInfo = execution.getVariable("CREVAS_requestInfo")
\r
682 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
\r
684 //TODO. hmmm. there is no way to UPDATE error message.
\r
685 // String errorMessage = wfex.getErrorMessage()
\r
686 // boolean successIndicator = execution.getVariable("DCRESI_rollbackSuccessful")
\r
687 // if (successIndicator){
\r
688 // errorMessage = errorMessage + ". Rollback successful."
\r
690 // errorMessage = errorMessage + ". Rollback not completed."
\r
693 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
695 execution.setVariable("CREVAS_falloutRequest", falloutRequest)
\r
697 } catch (Exception ex) {
\r
698 utils.log("DEBUG", "Error Occured in CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
\r
699 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process")
\r
701 utils.log("DEBUG", "*** COMPLETED CreateGenericMacroServiceNetworkVnf prepareFalloutRequest Process ***", isDebugEnabled)
\r
705 public void sendSyncError (Execution execution) {
\r
706 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
707 execution.setVariable("prefix", Prefix)
\r
709 utils.log("DEBUG", " ***** Inside sendSyncError() of CreateServiceInstanceInfra ***** ", isDebugEnabled)
\r
712 String errorMessage = ""
\r
713 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
714 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
715 errorMessage = wfe.getErrorMessage()
\r
717 errorMessage = "Sending Sync Error."
\r
720 String buildworkflowException =
\r
721 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
722 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
723 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
724 </aetgt:WorkflowException>"""
\r
726 utils.logAudit(buildworkflowException)
\r
727 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
728 } catch (Exception ex) {
\r
729 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
733 public void processJavaException(Execution execution){
\r
734 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
735 execution.setVariable("prefix",Prefix)
\r
737 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
\r
738 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
\r
739 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
\r
740 execution.setVariable("CRESI_unexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
\r
741 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Caught a Java Lang Exception")
\r
742 }catch(BpmnError b){
\r
743 utils.log("ERROR", "Rethrowing MSOWorkflowException", isDebugEnabled)
\r
745 }catch(Exception e){
\r
746 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
\r
747 execution.setVariable("CRESI_unexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
\r
748 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception in processJavaException method")
\r
750 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)
\r