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.common.scripts.AaiUtil;
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
29 import org.openecomp.mso.bpmn.common.scripts.NetworkUtils;
30 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils;
31 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
32 import org.openecomp.mso.bpmn.core.WorkflowException
33 import org.openecomp.mso.bpmn.core.json.JsonUtils;
34 import org.openecomp.mso.rest.APIResponse
36 import java.util.UUID;
38 import org.camunda.bpm.engine.delegate.BpmnError
39 import org.camunda.bpm.engine.runtime.Execution
40 import org.apache.commons.lang3.*
41 import org.apache.commons.codec.binary.Base64;
42 import org.springframework.web.util.UriUtils
45 * This groovy class supports the <class>UpdateNetworkInstanceInfra.bpmn</class> process.
47 public class UpdateNetworkInstanceInfra extends AbstractServiceTaskProcessor {
48 String Prefix="UPDNETI_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
51 VidUtils vidUtils = new VidUtils(this)
52 NetworkUtils networkUtils = new NetworkUtils()
53 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
56 * This method is executed during the preProcessRequest task of the <class>UpdateNetworkInstanceInfra.bpmn</class> process.
59 public InitializeProcessVariables(Execution execution){
60 /* Initialize all the process variables in this block */
62 execution.setVariable("UPDNETI_messageId", "")
63 execution.setVariable("BasicAuthHeaderValuePO", "")
64 execution.setVariable("BasicAuthHeaderValueSDNC", "")
65 execution.setVariable("UPDNETI_UpdateNetworkInstanceInfraJsonRequest", "")
66 execution.setVariable("UPDNETI_networkRequest", "")
67 execution.setVariable("UPDNETI_networkInputs", "")
68 execution.setVariable("UPDNETI_networkOutputs", "")
69 execution.setVariable("UPDNETI_requestId", "")
70 execution.setVariable("UPDNETI_source", "")
71 execution.setVariable("UPDNETI_networkId", "")
73 execution.setVariable("UPDNETI_CompleteMsoProcessRequest", "")
74 execution.setVariable("UPDNETI_FalloutHandlerRequest", "")
75 execution.setVariable("UPDNETI_isSilentSuccess", false)
76 execution.setVariable("UPDNETI_isPONR", false) // Point-of-no-return, means, rollback is not needed
78 // AAI query Cloud Region
79 execution.setVariable("UPDNETI_queryCloudRegionRequest","")
80 execution.setVariable("UPDNETI_queryCloudRegionReturnCode","")
81 execution.setVariable("UPDNETI_queryCloudRegionResponse","")
82 execution.setVariable("UPDNETI_cloudRegionPo","")
83 execution.setVariable("UPDNETI_cloudRegionSdnc","")
84 execution.setVariable("UPDNETI_isCloudRegionGood", false)
87 execution.setVariable("UPDNETI_queryIdAAIRequest","")
88 execution.setVariable("UPDNETI_queryIdAAIResponse", "")
89 execution.setVariable("UPDNETI_aaiIdReturnCode", "")
91 // AAI query vpn binding
92 execution.setVariable("UPDNETI_queryVpnBindingAAIRequest","")
93 execution.setVariable("UPDNETI_queryVpnBindingAAIResponse", "")
94 execution.setVariable("UPDNETI_aaiQqueryVpnBindingReturnCode", "")
95 execution.setVariable("UPDNETI_vpnBindings", null)
96 execution.setVariable("UPDNETI_vpnCount", 0)
97 execution.setVariable("UPDNETI_routeCollection", "")
99 // AAI query network policy
100 execution.setVariable("UPDNETI_queryNetworkPolicyAAIRequest","")
101 execution.setVariable("UPDNETI_queryNetworkPolicyAAIResponse", "")
102 execution.setVariable("UPDNETI_aaiQqueryNetworkPolicyReturnCode", "")
103 execution.setVariable("UPDNETI_networkPolicyUriList", null)
104 execution.setVariable("UPDNETI_networkPolicyCount", 0)
105 execution.setVariable("UPDNETI_networkCollection", "")
107 // AAI query route table reference
108 execution.setVariable("UPDNETI_queryNetworkTableRefAAIRequest","")
109 execution.setVariable("UPDNETI_queryNetworkTableRefAAIResponse", "")
110 execution.setVariable("UPDNETI_aaiQqueryNetworkTableRefReturnCode", "")
111 execution.setVariable("UPDNETI_networkTableRefUriList", null)
112 execution.setVariable("UPDNETI_networkTableRefCount", 0)
113 execution.setVariable("UPDNETI_tableRefCollection", "")
116 execution.setVariable("UPDNETI_requeryIdAAIRequest","")
117 execution.setVariable("UPDNETI_requeryIdAAIResponse", "")
118 execution.setVariable("UPDNETI_aaiRequeryIdReturnCode", "")
120 // AAI update contrail
121 execution.setVariable("UPDNETI_updateContrailAAIUrlRequest","")
122 execution.setVariable("UPDNETI_updateContrailAAIPayloadRequest","")
123 execution.setVariable("UPDNETI_updateContrailAAIResponse", "")
124 execution.setVariable("UPDNETI_aaiUpdateContrailReturnCode", "")
126 execution.setVariable("UPDNETI_updateNetworkRequest", "")
127 execution.setVariable("UPDNETI_updateNetworkResponse", "")
128 execution.setVariable("UPDNETI_rollbackNetworkRequest", "")
129 execution.setVariable("UPDNETI_rollbackNetworkResponse", "")
130 execution.setVariable("UPDNETI_networkReturnCode", "")
131 execution.setVariable("UPDNETI_rollbackNetworkReturnCode", "")
132 execution.setVariable("UPDNETI_isNetworkRollbackNeeded", false)
134 execution.setVariable("UPDNETI_changeAssignSDNCRequest", "")
135 execution.setVariable("UPDNETI_changeAssignSDNCResponse", "")
136 execution.setVariable("UPDNETI_rollbackSDNCRequest", "")
137 execution.setVariable("UPDNETI_rollbackSDNCResponse", "")
138 execution.setVariable("UPDNETI_sdncReturnCode", "")
139 execution.setVariable("UPDNETI_rollbackSDNCReturnCode", "")
140 execution.setVariable("UPDNETI_isSdncRollbackNeeded", false)
141 execution.setVariable("UPDNETI_sdncResponseSuccess", false)
143 execution.setVariable("UPDNETI_updateDBRequest", "")
144 execution.setVariable("UPDNETI_updateDBResponse", "")
145 execution.setVariable("UPDNETI_dbReturnCode", "")
147 execution.setVariable("UPDNETI_isVnfBindingPresent", false)
148 execution.setVariable("UPDNETI_Success", false)
149 execution.setVariable("UPDNETI_serviceInstanceId", "")
150 execution.setVariable("GENGS_type", "service-instance") // Setting for Generic Sub Flow use
154 // **************************************************
155 // Pre or Prepare Request Section
156 // **************************************************
158 * This method is executed during the preProcessRequest task of the <class>UpdateNetworkInstanceInfra.bpmn</class> process.
161 public void preProcessRequest (Execution execution) {
162 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
163 execution.setVariable("prefix",Prefix)
165 utils.log("DEBUG", " ***** Inside preProcessRequest UpdateNetworkInstanceInfra Request ***** ", isDebugEnabled)
167 // initialize flow variables
168 InitializeProcessVariables(execution)
170 // get Incoming request & validate json format
171 String updateNetworkJsonIncoming = execution.getVariable("bpmnRequest")
172 utils.logAudit(updateNetworkJsonIncoming)
174 def prettyJson = JsonOutput.prettyPrint(updateNetworkJsonIncoming.toString())
175 utils.log("DEBUG", " Incoming message formatted . . . : " + '\n' + prettyJson, isDebugEnabled)
177 } catch (Exception ex) {
178 String dataErrorMessage = " Invalid json format Request - " + ex.getMessage()
179 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
180 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
183 // PO Authorization Info / headers Authorization=
184 String basicAuthValuePO = execution.getVariable("URN_mso_adapters_po_auth")
185 utils.log("DEBUG", " Obtained BasicAuth userid password for PO/SDNC adapter: " + basicAuthValuePO, isDebugEnabled)
187 def encodedString = utils.getBasicAuth(basicAuthValuePO, execution.getVariable("URN_mso_msoKey"))
188 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
189 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
191 } catch (IOException ex) {
192 String dataErrorMessage = " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
193 utils.log("DEBUG", dataErrorMessage, , isDebugEnabled)
194 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
198 // Catalog DB headers Authorization
199 String basicAuthValueDB = execution.getVariable("URN_mso_adapters_db_auth")
200 utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugEnabled)
202 def encodedString = utils.getBasicAuth(basicAuthValueDB, execution.getVariable("URN_mso_msoKey"))
203 execution.setVariable("BasicAuthHeaderValueDB",encodedString)
204 } catch (IOException ex) {
205 String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
206 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
207 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
212 execution.setVariable("UPDNETI_UpdateNetworkInstanceInfraJsonRequest", updateNetworkJsonIncoming)
214 // recreate the xml network-request
215 String networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, updateNetworkJsonIncoming)
216 execution.setVariable("UPDNETI_networkRequest", networkRequest)
217 utils.log("DEBUG", " network-request - " + '\n' + networkRequest, isDebugEnabled)
219 String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","")
220 execution.setVariable("UPDNETI_networkInputs", networkInputs)
221 utils.log("DEBUG", " networkInputs - " + '\n' + networkInputs, isDebugEnabled)
223 String netId = utils.getNodeText1(networkRequest, "network-id")
224 String netName = utils.getNodeText1(networkRequest, "network-name")
225 String networkOutputs =
227 <network-id>${netId}</network-id>
228 <network-name>${netName}</network-name>
229 </network-outputs>"""
230 execution.setVariable("UPDNETI_networkOutputs", networkOutputs)
231 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
233 String requestId = execution.getVariable("mso-request-id")
234 if (requestId == null || requestId == "") {
235 requestId = execution.getVariable("requestId")
237 execution.setVariable("UPDNETI_requestId", requestId)
238 execution.setVariable("UPDNETI_source", utils.getNodeText1(networkRequest, "source"))
241 String messageId = execution.getVariable("UPDNETI_messageId") // for testing
242 if (messageId == null || messageId == "") {
243 messageId = UUID.randomUUID()
244 utils.log("DEBUG", " UPDNETI_messageId, random generated: " + messageId, isDebugEnabled)
246 utils.log("DEBUG", " UPDNETI_messageId, pre-assigned: " + messageId, isDebugEnabled)
248 execution.setVariable("UPDNETI_messageId", messageId)
250 // validate 'backout-on-failure' to override 'URN_mso_rollback'
251 boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest)
252 execution.setVariable("UPDNETI_rollbackEnabled", rollbackEnabled)
254 String networkId = ""
255 if (utils.nodeExists(networkRequest, "network-id")) {
256 networkId = utils.getNodeText1(networkRequest, "network-id")
257 if (networkId == 'null' || networkId == "") {
258 sendSyncError(execution)
259 // missing value of networkId
260 String dataErrorMessage = "Variable 'network-id' value/element is missing."
261 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
262 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
267 String lcpCloudRegion = ""
268 if (utils.nodeExists(networkRequest, "aic-cloud-region")) {
269 lcpCloudRegion = utils.getNodeText1(networkRequest, "aic-cloud-region")
270 if ((lcpCloudRegion == 'null') || (lcpCloudRegion == "")) {
271 sendSyncError(execution)
272 String dataErrorMessage = "requestDetails has missing 'aic-cloud-region' value/element."
273 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
274 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
278 String serviceInstanceId = ""
279 if (utils.nodeExists(networkRequest, "service-instance-id")) {
280 serviceInstanceId = utils.getNodeText1(networkRequest, "service-instance-id")
281 if ((serviceInstanceId == 'null') || (lcpCloudRegion == "")) {
282 sendSyncError(execution)
283 String dataErrorMessage = "Variable 'serviceInstanceId' value/element is missing."
284 utils.log("DEBUG", " Invalid Request - " + dataErrorMessage, isDebugEnabled)
285 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
289 execution.setVariable("UPDNETI_serviceInstanceId", serviceInstanceId)
291 } catch (BpmnError e) {
294 } catch (Exception ex){
295 sendSyncError(execution)
297 String exceptionMessage = "Exception Encountered in UpdateNetworkInstanceInfra, PreProcessRequest() - " + ex.getMessage()
298 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
299 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
304 public void sendSyncResponse (Execution execution) {
305 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
306 execution.setVariable("prefix",Prefix)
308 utils.log("DEBUG", " ***** Inside sendSyncResponse of UpdateNetworkInstanceInfra ***** ", isDebugEnabled)
311 String serviceInstanceId = execution.getVariable("UPDNETI_serviceInstanceId")
312 String requestId = execution.getVariable("mso-request-id")
314 // RESTResponse (for API Handler (APIH) Reply Task)
315 String updateNetworkRestRequest = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
317 utils.log("DEBUG", " sendSyncResponse to APIH - " + "\n" + updateNetworkRestRequest, isDebugEnabled)
318 sendWorkflowResponse(execution, 202, updateNetworkRestRequest)
320 } catch (Exception ex) {
321 String exceptionMessage = "Bpmn error encountered in UpdateNetworkInstanceInfra flow. sendSyncResponse() - " + ex.getMessage()
322 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
323 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
328 public void callRESTQueryAAICloudRegion (Execution execution) {
329 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
330 execution.setVariable("prefix", Prefix)
332 utils.log("DEBUG", " ***** Inside callRESTQueryAAICloudRegion of UpdateNetworkInstanceInfra ***** " , isDebugEnabled)
335 String networkInputs = execution.getVariable("UPDNETI_networkInputs")
336 String cloudRegion = utils.getNodeText1(networkInputs, "aic-cloud-region")
337 cloudRegion = UriUtils.encode(cloudRegion,"UTF-8")
340 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
341 AaiUtil aaiUtil = new AaiUtil(this)
342 String aai_uri = aaiUtil.getCloudInfrastructureCloudRegionUri(execution)
343 String queryCloudRegionRequest = "${aai_endpoint}${aai_uri}/" + cloudRegion
344 utils.logAudit(queryCloudRegionRequest)
345 execution.setVariable("UPDNETI_queryCloudRegionRequest", queryCloudRegionRequest)
346 utils.log("DEBUG", " UPDNETI_queryCloudRegionRequest - " + "\n" + queryCloudRegionRequest, isDebugEnabled)
348 String cloudRegionPo = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion)
349 String cloudRegionSdnc = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "SDNC", cloudRegion)
351 if ((cloudRegionPo != "ERROR") && (cloudRegionSdnc != "ERROR")) {
352 execution.setVariable("UPDNETI_cloudRegionPo", cloudRegionPo)
353 execution.setVariable("UPDNETI_cloudRegionSdnc", cloudRegionSdnc)
354 execution.setVariable("UPDNETI_isCloudRegionGood", true)
357 String dataErrorMessage = "QueryAAICloudRegion Unsuccessful. Return Code: " + execution.getVariable("UPDNETI_queryCloudRegionReturnCode")
358 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
359 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
363 utils.log("DEBUG", " is Cloud Region Good: " + execution.getVariable("UPDNETI_isCloudRegionGood"), isDebugEnabled)
365 } catch (BpmnError e) {
368 } catch (Exception ex) {
370 String exceptionMessage = "Bpmn error encountered in UpdateNetworkInstanceInfra flow - callRESTQueryAAICloudRegion() - " + ex.getMessage()
371 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
372 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
378 public void callRESTQueryAAINetworkId(Execution execution) {
379 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
380 execution.setVariable("prefix", Prefix)
382 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkId of UpdateNetworkInstanceInfra ***** " , isDebugEnabled)
386 String networkRequest = execution.getVariable("UPDNETI_networkRequest")
387 String networkId = utils.getNodeText1(networkRequest, "network-id")
388 networkId = UriUtils.encode(networkId,"UTF-8")
389 execution.setVariable("UPDNETI_networkId", networkId)
390 String messageId = execution.getVariable("UPDNETI_messageId")
393 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
394 AaiUtil aaiUriUtil = new AaiUtil(this)
395 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
396 String queryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId
397 utils.logAudit(queryIdAAIRequest)
398 execution.setVariable("UPDNETI_queryIdAAIRequest", queryIdAAIRequest)
399 utils.log("DEBUG", " UPDNETI_queryIdAAIRequest - " + "\n" + queryIdAAIRequest, isDebugEnabled)
401 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryIdAAIRequest)
402 String returnCode = response.getStatusCode()
403 execution.setVariable("UPDNETI_aaiIdReturnCode", returnCode)
405 utils.log("DEBUG", " ***** AAI Response Code : " + returnCode, isDebugEnabled)
407 String aaiResponseAsString = response.getResponseBodyAsString()
409 if (returnCode=='200') {
410 utils.logAudit(aaiResponseAsString)
411 execution.setVariable("UPDNETI_queryIdAAIResponse", aaiResponseAsString)
412 utils.log("DEBUG", " QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
415 if (returnCode=='404') {
416 String dataErrorMessage = "Response Error from QueryAAINetworkId is 404 (Not Found)."
417 utils.log("DEBUG", " AAI Query Failed. " + dataErrorMessage, isDebugEnabled)
418 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
421 if (aaiResponseAsString.contains("RESTFault")) {
422 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
423 execution.setVariable("WorkflowException", exceptionObject)
424 throw new BpmnError("MSOWorkflowException")
428 String dataErrorMessage = "Unexpected Response from QueryAAINetworkId - " + returnCode
429 utils.log("DEBUG", "Unexpected Response from QueryAAINetworkId - " + dataErrorMessage, isDebugEnabled)
430 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
436 } catch (BpmnError e) {
439 } catch (Exception ex) {
440 String exceptionMessage = "Bpmn error encountered in UpdateNetworkInstanceInfra flow. callRESTQueryAAINetworkId() - " + ex.getMessage()
441 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
442 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
448 public void callRESTReQueryAAINetworkId(Execution execution) {
449 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
450 execution.setVariable("prefix", Prefix)
452 utils.log("DEBUG", " ***** Inside callRESTReQueryAAINetworkId of UpdateNetworkInstanceInfra ***** " , isDebugEnabled)
456 String networkId = utils.getNodeText1(execution.getVariable("UPDNETI_changeAssignSDNCResponse"), "network-id")
457 networkId = UriUtils.encode(networkId,"UTF-8")
458 String messageId = execution.getVariable("UPDNETI_messageId")
461 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
462 AaiUtil aaiUriUtil = new AaiUtil(this)
463 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
464 String requeryIdAAIRequest = "${aai_endpoint}${aai_uri}/" + networkId
465 utils.logAudit(requeryIdAAIRequest)
466 execution.setVariable("UPDNETI_requeryIdAAIRequest", requeryIdAAIRequest)
467 utils.log("DEBUG", " UPDNETI_requeryIdAAIRequest - " + "\n" + requeryIdAAIRequest, isDebugEnabled)
469 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, requeryIdAAIRequest)
470 String returnCode = response.getStatusCode()
471 execution.setVariable("UPDNETI_aaiRequeryIdReturnCode", returnCode)
472 utils.log("DEBUG", " ***** AAI ReQuery Response Code : " + returnCode, isDebugEnabled)
474 String aaiResponseAsString = response.getResponseBodyAsString()
476 if (returnCode=='200') {
477 utils.logAudit(aaiResponseAsString)
478 execution.setVariable("UPDNETI_requeryIdAAIResponse", aaiResponseAsString)
479 utils.log("DEBUG", " ReQueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString, isDebugEnabled)
481 String netId = utils.getNodeText1(aaiResponseAsString, "network-id")
482 String netName = utils.getNodeText1(aaiResponseAsString, "network-name")
483 String networkOutputs =
485 <network-id>${netId}</network-id>
486 <network-name>${netName}</network-name>
487 </network-outputs>"""
488 execution.setVariable("UPDNETI_networkOutputs", networkOutputs)
489 utils.log("DEBUG", " networkOutputs - " + '\n' + networkOutputs, isDebugEnabled)
492 if (returnCode=='404') {
493 String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)."
494 utils.log("DEBUG", " AAI ReQuery Failed. - " + dataErrorMessage, isDebugEnabled)
495 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
498 if (aaiResponseAsString.contains("RESTFault")) {
499 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
500 execution.setVariable("WorkflowException", exceptionObject)
501 throw new BpmnError("MSOWorkflowException")
505 String dataErrorMessage = "Unexpected Response from ReQueryAAINetworkId - " + returnCode
506 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
507 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
513 } catch (BpmnError e) {
516 } catch (Exception ex) {
517 String exceptionMessage = "Bpmn error encountered in UpdateNetworkInstanceInfra flow. callRESTReQueryAAINetworkId() - " + ex.getMessage()
518 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
519 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
525 public void callRESTQueryAAINetworkVpnBinding(Execution execution) {
526 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
527 execution.setVariable("prefix", Prefix)
529 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkVpnBinding of UpdateNetworkInstanceInfra ***** " , isDebugEnabled)
534 String messageId = execution.getVariable("UPDNETI_messageId")
535 String queryIdAAIResponse = execution.getVariable("UPDNETI_requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
536 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
537 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
539 // Check if Vnf Binding is present, then build a List of vnfBinding
540 List vpnBindingUri = networkUtils.getVnfBindingObject(relationship)
541 int vpnCount = vpnBindingUri.size()
542 execution.setVariable("UPDNETI_vpnCount", vpnCount)
543 utils.log("DEBUG", " UPDNETI_vpnCount - " + vpnCount, isDebugEnabled)
545 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
546 AaiUtil aaiUriUtil = new AaiUtil(this)
549 execution.setVariable("UPDNETI_vpnBindings", vpnBindingUri)
550 utils.log("DEBUG", " vpnBindingUri List - " + vpnBindingUri, isDebugEnabled)
552 String routeTargets = ""
553 // AII loop call using list vpnBindings
554 for (i in 0..vpnBindingUri.size()-1) {
558 // prepare url using vpnBinding
559 String queryVpnBindingAAIRequest = ""
560 String aai_uri = aaiUriUtil.getNetworkVpnBindingUri(execution)
562 // Note: By default, the vpnBinding url is found in 'related-link' of the response,
563 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
564 if (aai_uri == null || aai_uri == "") {
565 // using value of 'related-link' from response
566 if (vpnBindingUri[i].charAt(vpnBindingUri[i].length()-1) == '/') {
567 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i].substring(0, vpnBindingUri[i].length()-1)
569 queryVpnBindingAAIRequest = "${aai_endpoint}" + vpnBindingUri[i]
573 // using uri value in URN mapping
574 String vpnBindingId = vpnBindingUri[i].substring(vpnBindingUri[i].indexOf("/vpn-binding/")+13, vpnBindingUri[i].length())
575 if (vpnBindingId.charAt(vpnBindingId.length()-1) == '/') {
576 vpnBindingId = vpnBindingId.substring(0, vpnBindingId.length()-1)
578 queryVpnBindingAAIRequest = "${aai_endpoint}${aai_uri}/" + vpnBindingId
581 utils.logAudit(queryVpnBindingAAIRequest)
582 execution.setVariable("UPDNETI_queryVpnBindingAAIRequest", queryVpnBindingAAIRequest)
583 utils.log("DEBUG", " UPDNETI_queryVpnBindingAAIRequest, , vpnBinding #" + counting + " : " + "\n" + queryVpnBindingAAIRequest, isDebugEnabled)
585 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryVpnBindingAAIRequest)
586 String returnCode = response.getStatusCode()
587 execution.setVariable("UPDNETI_aaiQqueryVpnBindingReturnCode", returnCode)
588 utils.log("DEBUG", " ***** AAI query vpn binding Response Code, vpnBinding #" + counting + " : " + returnCode, isDebugEnabled)
590 String aaiResponseAsString = response.getResponseBodyAsString()
592 if (returnCode=='200') {
593 utils.logAudit(aaiResponseAsString)
594 execution.setVariable("UPDNETI_queryVpnBindingAAIResponse", aaiResponseAsString)
595 utils.log("DEBUG", " AAI Query Vpn Binding Success REST Response, , vpnBinding #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
597 String routeTarget = ""
598 if (utils.nodeExists(aaiResponseAsString, "global-route-target")) {
599 routeTarget = utils.getNodeText1(aaiResponseAsString, "global-route-target")
600 routeTargets += "<routeTargets>" + routeTarget + "</routeTargets>" + '\n'
604 if (returnCode=='404') {
605 String dataErrorMessage = "Response Error from AAINetworkVpnBinding is 404 (Not Found)."
606 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
607 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
610 if (aaiResponseAsString.contains("RESTFault")) {
611 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
612 execution.setVariable("WorkflowException", exceptionObject)
613 throw new BpmnError("MSOWorkflowException")
617 String dataErrorMessage = " Unexpected Response from AAINetworkVpnBinding - " + returnCode
618 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
619 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
627 execution.setVariable("UPDNETI_routeCollection", routeTargets)
628 utils.log("DEBUG", " UPDNETI_routeCollection - " + '\n' + routeTargets, isDebugEnabled)
631 // reset return code to success
632 execution.setVariable("UPDNETI_aaiQqueryVpnBindingReturnCode", "200")
633 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
634 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
635 String aaiStubResponse =
636 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
637 <vpn-binding xmlns="${schemaVersion}">
638 <global-route-target/>
641 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
642 execution.setVariable("UPDNETI_queryVpnBindingAAIResponse", aaiStubResponseAsXml)
643 execution.setVariable("UPDNETI_routeCollection", "<routeTargets/>")
644 utils.log("DEBUG", " No vpnBinding, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
648 } catch (BpmnError e) {
651 } catch (Exception ex) {
652 String exceptionMessage = "Bpmn error encountered in UpdateNetworkInstanceInfra flow. callRESTQueryAAINetworkVpnBinding() - " + ex.getMessage()
653 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
654 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
660 public void callRESTQueryAAINetworkPolicy(Execution execution) {
661 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
662 execution.setVariable("prefix", Prefix)
664 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkPolicy of UpdateNetworkInstanceInfra ***** " , isDebugEnabled)
668 String messageId = execution.getVariable("UPDNETI_messageId")
669 String queryIdAAIResponse = execution.getVariable("UPDNETI_requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
670 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
671 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
673 // Check if Network Policy is present, then build a List of network policy
674 List networkPolicyUriList = networkUtils.getNetworkPolicyObject(relationship)
675 int networkPolicyCount = networkPolicyUriList.size()
676 execution.setVariable("UPDNETI_networkPolicyCount", networkPolicyCount)
677 utils.log("DEBUG", " UPDNETI_networkPolicyCount - " + networkPolicyCount, isDebugEnabled)
679 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
680 AaiUtil aaiUriUtil = new AaiUtil(this)
682 if (networkPolicyCount > 0) {
683 execution.setVariable("UPDNETI_networkPolicyUriList", networkPolicyUriList)
684 utils.log("DEBUG", " networkPolicyUri List - " + networkPolicyUriList, isDebugEnabled)
686 String networkPolicies = ""
687 // AII loop call using list vpnBindings
688 for (i in 0..networkPolicyUriList.size()-1) {
692 // prepare url using vpnBinding
693 String queryNetworkPolicyAAIRequest = ""
695 String aai_uri = aaiUriUtil.getNetworkPolicyUri(execution)
697 // Note: By default, the network policy url is found in 'related-link' of the response,
698 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
699 if (aai_uri == null || aai_uri == "") {
700 // using value of 'related-link' from response
701 if (networkPolicyUriList[i].charAt(networkPolicyUriList[i].length()-1) == '/') {
702 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i].substring(0, networkPolicyUriList[i].length()-1)
704 queryNetworkPolicyAAIRequest = "${aai_endpoint}" + networkPolicyUriList[i]
707 // using uri value in URN mapping
708 String networkPolicyId = networkPolicyUriList[i].substring(networkPolicyUriList[i].indexOf("/network-policy/")+16, networkPolicyUriList[i].length())
709 println " networkPolicyId - " + networkPolicyId
710 if (networkPolicyId.charAt(networkPolicyId.length()-1) == '/') {
711 networkPolicyId = networkPolicyId.substring(0, networkPolicyId.length()-1)
713 queryNetworkPolicyAAIRequest = "${aai_endpoint}${aai_uri}/" + networkPolicyId
718 utils.logAudit(queryNetworkPolicyAAIRequest)
719 execution.setVariable("UPDNETI_queryNetworkPolicyAAIRequest", queryNetworkPolicyAAIRequest)
720 utils.log("DEBUG", " UPDNETI_queryNetworkPolicyAAIRequest, , NetworkPolicy #" + counting + " : " + "\n" + queryNetworkPolicyAAIRequest, isDebugEnabled)
722 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkPolicyAAIRequest)
723 String returnCode = response.getStatusCode()
724 execution.setVariable("UPDNETI_aaiQqueryNetworkPolicyReturnCode", returnCode)
725 utils.log("DEBUG", " ***** AAI query network policy Response Code, NetworkPolicy #" + counting + " : " + returnCode, isDebugEnabled)
727 String aaiResponseAsString = response.getResponseBodyAsString()
729 if (returnCode=='200') {
730 utils.logAudit(aaiResponseAsString)
731 execution.setVariable("UPDNETI_queryNetworkPolicyAAIResponse", aaiResponseAsString)
732 utils.log("DEBUG", " QueryAAINetworkPolicy Success REST Response, , NetworkPolicy #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
734 String networkPolicy = ""
735 if (utils.nodeExists(aaiResponseAsString, "network-policy-fqdn")) {
736 networkPolicy = utils.getNodeText1(aaiResponseAsString, "network-policy-fqdn")
737 networkPolicies += "<policyFqdns>" + networkPolicy + "</policyFqdns>" + '\n'
741 if (returnCode=='404') {
742 String dataErrorMessage = "Response Error from QueryAAINetworkPolicy is 404 (Not Found)."
743 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
744 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
747 if (aaiResponseAsString.contains("RESTFault")) {
748 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
749 execution.setVariable("WorkflowException", exceptionObject)
750 throw new BpmnError("MSOWorkflowException")
754 String dataErrorMessage = "Unexpected Response from QueryAAINetworkPolicy - " + returnCode
755 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
756 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
764 execution.setVariable("UPDNETI_networkCollection", networkPolicies)
765 utils.log("DEBUG", " UPDNETI_networkCollection - " + '\n' + networkPolicies, isDebugEnabled)
768 // reset return code to success
769 execution.setVariable("UPDNETI_aaiQqueryNetworkPolicyReturnCode", "200")
770 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
771 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
772 String aaiStubResponse =
773 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
774 <network-policy xmlns="${schemaVersion}">
775 <network-policy-fqdn/>
778 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
779 execution.setVariable("UPDNETI_queryNetworkPolicyAAIResponse", aaiStubResponseAsXml)
780 execution.setVariable("UPDNETI_networkCollection", "<policyFqdns/>")
781 utils.log("DEBUG", " No net policies, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
785 } catch (BpmnError e) {
788 } catch (Exception ex) {
789 String exceptionMessage = "Bpmn error encountered in UpdateNetworkInstanceInfra flow. callRESTQueryAAINetworkPolicy() - " + ex.getMessage()
790 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
791 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
797 public void callRESTQueryAAINetworkTableRef(Execution execution) {
798 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
799 execution.setVariable("prefix", Prefix)
801 utils.log("DEBUG", " ***** Inside callRESTQueryAAINetworkTableRef of UpdateNetworkInstanceInfra ***** " , isDebugEnabled)
805 String messageId = execution.getVariable("UPDNETI_messageId")
806 String queryIdAAIResponse = execution.getVariable("UPDNETI_requeryIdAAIResponse").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
807 String relationship = networkUtils.getFirstNodeXml(queryIdAAIResponse, "relationship-list").trim().replace("tag0:","").replace(":tag0","")
808 utils.log("DEBUG", " relationship - " + relationship, isDebugEnabled)
810 // Check if Network TableREf is present, then build a List of network policy
811 List networkTableRefUriList = networkUtils.getNetworkTableRefObject(relationship)
812 int networkTableRefCount = networkTableRefUriList.size()
813 execution.setVariable("UPDNETI_networkTableRefCount", networkTableRefCount)
814 utils.log("DEBUG", " UPDNETI_networkTableRefCount - " + networkTableRefCount, isDebugEnabled)
816 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
817 AaiUtil aaiUriUtil = new AaiUtil(this)
819 if (networkTableRefCount > 0) {
820 execution.setVariable("UPDNETI_networkTableRefUriList", networkTableRefUriList)
821 utils.log("DEBUG", " networkTableRefUri List - " + networkTableRefUriList, isDebugEnabled)
823 // AII loop call using list vpnBindings
824 String networkTableRefs = ""
825 for (i in 0..networkTableRefUriList.size()-1) {
829 // prepare url using tableRef
830 String queryNetworkTableRefAAIRequest = ""
832 String aai_uri = aaiUriUtil.getNetworkTableReferencesUri(execution)
834 // Note: By default, the network policy url is found in 'related-link' of the response,
835 // so, the default in URN mappings for this is set to "" (ie, space), unless forced to use the URN mapping.
836 if (aai_uri == null || aai_uri == "") {
837 // using value of 'related-link' from response
838 if (networkTableRefUriList[i].charAt(networkTableRefUriList[i].length()-1) == '/') {
839 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i].substring(0, networkTableRefUriList[i].length()-1)
841 queryNetworkTableRefAAIRequest = "${aai_endpoint}" + networkTableRefUriList[i]
844 // using uri value in URN mapping
845 String networkTableRefId = networkTableRefUriList[i].substring(networkTableRefUriList[i].indexOf("/route-table-reference/")+23, networkTableRefUriList[i].length())
847 if (networkTableRefId.charAt(networkTableRefId.length()-1) == '/') {
848 networkTableRefId = networkTableRefId.substring(0, networkTableRefId.length()-1)
850 queryNetworkTableRefAAIRequest = "${aai_endpoint}${aai_uri}/" + networkTableRefId
855 utils.logAudit(queryNetworkTableRefAAIRequest)
856 execution.setVariable("UPDNETI_queryNetworkTableRefAAIRequest", queryNetworkTableRefAAIRequest)
857 utils.log("DEBUG", " UPDNETI_queryNetworkTableRefAAIRequest, , NetworkTableRef #" + counting + " : " + "\n" + queryNetworkTableRefAAIRequest, isDebugEnabled)
859 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, queryNetworkTableRefAAIRequest)
860 String returnCode = response.getStatusCode()
861 execution.setVariable("UPDNETI_aaiQqueryNetworkTableRefReturnCode", returnCode)
862 utils.log("DEBUG", " ***** AAI query network Table Reference Response Code, NetworkTableRef #" + counting + " : " + returnCode, isDebugEnabled)
864 String aaiResponseAsString = response.getResponseBodyAsString()
866 if (returnCode=='200') {
867 utils.logAudit(aaiResponseAsString)
868 execution.setVariable("UPDNETI_queryNetworkTableRefAAIResponse", aaiResponseAsString)
869 utils.log("DEBUG", " QueryAAINetworkTableRef Success REST Response, , NetworkTableRef #" + counting + " : " + "\n" + aaiResponseAsString, isDebugEnabled)
871 String networkTableRef = ""
872 if (utils.nodeExists(aaiResponseAsString, "route-table-reference-fqdn")) {
873 networkTableRef = utils.getNodeText1(aaiResponseAsString, "route-table-reference-fqdn")
874 networkTableRefs += "<routeTableFqdns>" + networkTableRef + "</routeTableFqdns>" + '\n'
878 if (returnCode=='404') {
879 String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)."
880 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
881 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
884 if (aaiResponseAsString.contains("RESTFault")) {
885 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
886 execution.setVariable("WorkflowException", exceptionObject)
887 throw new BpmnError("MSOWorkflowException")
891 String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode
892 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
893 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
901 execution.setVariable("UPDNETI_tableRefCollection", networkTableRefs)
902 utils.log("DEBUG", " UPDNETI_tableRefCollection - " + '\n' + networkTableRefs, isDebugEnabled)
905 // reset return code to success
906 execution.setVariable("UPDNETI_aaiQqueryNetworkTableRefReturnCode", "200")
907 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
908 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
909 String aaiStubResponse =
910 """ <rest:payload contentType="text/xml" xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd">
911 <route-table-references xmlns="${schemaVersion}">
912 <route-table-reference-fqdn/>
913 </route-table-references>
915 String aaiStubResponseAsXml = utils.formatXml(aaiStubResponse)
916 execution.setVariable("UPDNETI_queryNetworkTableRefAAIResponse", aaiStubResponseAsXml)
917 execution.setVariable("UPDNETI_tableRefCollection", "<routeTableFqdns/>")
918 utils.log("DEBUG", " No net table references, using this stub as response - " + '\n' + aaiStubResponseAsXml, isDebugEnabled)
922 } catch (BpmnError e) {
925 } catch (Exception ex) {
926 String exceptionMessage = "Bpmn error encountered in UpdateNetworkInstanceInfra flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage()
927 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
928 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
934 public void callRESTUpdateContrailAAINetwork(Execution execution) {
935 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
936 execution.setVariable("prefix", Prefix)
938 utils.log("DEBUG", " ***** Inside callRESTUpdateContrailAAINetwork of UpdateNetworkInstanceInfra ***** " , isDebugEnabled)
942 String networkId = utils.getNodeText1(execution.getVariable("UPDNETI_changeAssignSDNCResponse"), "network-id")
943 networkId = UriUtils.encode(networkId,"UTF-8")
944 String requeryIdAAIResponse = execution.getVariable("UPDNETI_requeryIdAAIResponse")
945 String updateNetworkResponse = execution.getVariable("UPDNETI_updateNetworkResponse")
946 String messageId = execution.getVariable("UPDNETI_messageId")
949 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
950 AaiUtil aaiUriUtil = new AaiUtil(this)
951 String aai_uri = aaiUriUtil.getNetworkL3NetworkUri(execution)
952 String updateContrailAAIUrlRequest = "${aai_endpoint}${aai_uri}/" + networkId
954 utils.logAudit(updateContrailAAIUrlRequest)
955 execution.setVariable("UPDNETI_updateContrailAAIUrlRequest", updateContrailAAIUrlRequest)
956 utils.log("DEBUG", " UPDNETI_updateContrailAAIUrlRequest - " + "\n" + updateContrailAAIUrlRequest, isDebugEnabled)
958 //Prepare payload (PUT)
959 String schemaVersion = aaiUriUtil.getNamespaceFromUri(aai_uri)
960 String payload = networkUtils.ContrailNetworkCreatedUpdate(requeryIdAAIResponse, updateNetworkResponse, schemaVersion)
961 String payloadXml = utils.formatXml(payload)
962 utils.logAudit(payloadXml)
963 execution.setVariable("UPDNETI_updateContrailAAIPayloadRequest", payloadXml)
964 utils.log("DEBUG", " 'payload' to Update Contrail - " + "\n" + payloadXml, isDebugEnabled)
966 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload)
967 String returnCode = response.getStatusCode()
968 execution.setVariable("UPDNETI_aaiUpdateContrailReturnCode", returnCode)
970 utils.log("DEBUG", " ***** AAI Update Contrail Response Code : " + returnCode, isDebugEnabled)
972 String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString()
974 if (returnCode=='200') {
975 utils.logAudit(aaiUpdateContrailResponseAsString)
976 execution.setVariable("UPDNETI_updateContrailAAIResponse", aaiUpdateContrailResponseAsString)
977 utils.log("DEBUG", " AAI Update Contrail Success REST Response - " + "\n" + aaiUpdateContrailResponseAsString, isDebugEnabled)
978 // Point-of-no-return is set to false, rollback not needed.
979 execution.setVariable("UPDNETI_isPONR", true)
982 if (returnCode=='404') {
983 String dataErrorMessage = " Response Error from UpdateContrailAAINetwork is 404 (Not Found)."
984 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
985 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
988 if (aaiUpdateContrailResponseAsString.contains("RESTFault")) {
989 WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiUpdateContrailResponseAsString, execution)
990 execution.setVariable("WorkflowException", exceptionObject)
991 throw new BpmnError("MSOWorkflowException")
995 String errorMessage = "Unexpected Response from UpdateContrailAAINetwork - " + returnCode
996 utils.log("DEBUG", errorMessage, isDebugEnabled)
997 exceptionUtil.buildAndThrowWorkflowException(execution, "2500", errorMessage)
1002 } catch (BpmnError e) {
1005 } catch (Exception ex) {
1006 String exceptionMessage = "Bpmn error encountered in UpdateNetworkInstanceInfra flow. callRESTUpdateContrailAAINetwork() - " + ex.getMessage()
1007 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1008 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1014 public void prepareUpdateNetworkRequest (Execution execution) {
1015 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1016 execution.setVariable("prefix", Prefix)
1018 utils.log("DEBUG", " ***** Inside prepareUpdateNetworkRequest of UpdateNetworkInstanceInfra ***** ", isDebugEnabled)
1023 String requestId = execution.getVariable("UPDNETI_requestId")
1024 String messageId = execution.getVariable("UPDNETI_messageId")
1025 String source = execution.getVariable("UPDNETI_source")
1027 String requestInput = execution.getVariable("UPDNETI_networkRequest")
1028 String queryIdResponse = execution.getVariable("UPDNETI_requeryIdAAIResponse")
1029 String cloudRegionId = execution.getVariable("UPDNETI_cloudRegionPo")
1030 String backoutOnFailure = execution.getVariable("UPDNETI_rollbackEnabled")
1032 // Prepare Network request
1033 String routeCollection = execution.getVariable("UPDNETI_routeCollection")
1034 String policyCollection = execution.getVariable("UPDNETI_networkCollection")
1035 String tableCollection = execution.getVariable("UPDNETI_tableRefCollection")
1036 String updateNetworkRequest = networkUtils.UpdateNetworkRequestV2(execution, requestId, messageId, requestInput, queryIdResponse, routeCollection, policyCollection, tableCollection, cloudRegionId, backoutOnFailure, source )
1038 String buildUpdateNetworkRequestAsString = utils.formatXml(updateNetworkRequest)
1039 buildUpdateNetworkRequestAsString = buildUpdateNetworkRequestAsString.replace(":w1aac13n0", "").replace("w1aac13n0:", "")
1040 utils.logAudit(buildUpdateNetworkRequestAsString)
1042 execution.setVariable("UPDNETI_updateNetworkRequest", buildUpdateNetworkRequestAsString)
1043 utils.log("DEBUG", " UPDNETI_updateNetworkRequest - " + "\n" + buildUpdateNetworkRequestAsString, isDebugEnabled)
1045 } catch (Exception ex) {
1046 String exceptionMessage = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. prepareUpdateNetworkRequest() - " + ex.getMessage()
1047 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1048 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1054 public void prepareSDNCRequest (Execution execution) {
1055 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1056 execution.setVariable("prefix", Prefix)
1058 utils.log("DEBUG", " ***** Inside prepareSDNCRequest of UpdateNetworkInstanceInfra ***** ", isDebugEnabled)
1062 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1063 String updateNetworkInput = execution.getVariable("UPDNETI_networkRequest")
1064 String cloudRegionId = execution.getVariable("UPDNETI_cloudRegionSdnc")
1066 String networkId = ""
1067 if (utils.nodeExists(updateNetworkInput, "network-id")) {
1068 networkId = utils.getNodeText1(updateNetworkInput, "network-id")
1070 if (networkId == null) {networkId = ""}
1072 String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1074 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
1075 String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "changeassign", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1077 String sndcTopologyUpdateRequesAsString = utils.formatXml(sndcTopologyCreateRequest)
1078 utils.logAudit(sndcTopologyUpdateRequesAsString)
1079 execution.setVariable("UPDNETI_changeAssignSDNCRequest", sndcTopologyUpdateRequesAsString)
1080 utils.log("DEBUG", " UPDNETI_changeAssignSDNCRequest - " + "\n" + sndcTopologyUpdateRequesAsString, isDebugEnabled)
1083 } catch (Exception ex) {
1084 String exceptionMessage = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. prepareSDNCRequest() - " + ex.getMessage()
1085 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1086 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1092 public void prepareDBRequest (Execution execution) {
1093 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1094 execution.setVariable("prefix", Prefix)
1097 utils.log("DEBUG", " ***** Inside prepareDBRequest of UpdateNetworkInstanceInfra ***** ", isDebugEnabled)
1099 String networkOutputs = execution.getVariable("UPDNETI_networkOutputs")
1100 String networkName = ""
1102 networkName = utils.getNodeText1(networkOutputs, "network-name")
1103 if (networkName == null) {networkName = ""}
1104 } catch (Exception ex) {
1106 utils.log("DEBUG", " No 'network-name' found in '<network-outputs>' ! ", isDebugEnabled)
1108 String networkId = ""
1110 networkId = utils.getNodeText1(networkOutputs, "network-id")
1111 if (networkId == null) {networkId = ""}
1112 } catch (Exception) {
1114 utils.log("DEBUG", " No 'network-id' found in '<network-outputs>' ! ", isDebugEnabled)
1116 String requestId = execution.getVariable("UPDNETI_requestId")
1118 String statusMessage = "Network successfully updated."
1121 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
1124 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
1125 <requestId>${requestId}</requestId>
1126 <lastModifiedBy>BPMN</lastModifiedBy>
1127 <statusMessage>${statusMessage}</statusMessage>
1128 <responseBody></responseBody>
1129 <requestStatus>COMPLETED</requestStatus>
1130 <progress>100</progress>
1131 <vnfOutputs><network-id>${networkId}</network-id><network-name>${networkName}</network-names></vnfOutputs>
1132 <networkId>${networkId}</networkId>
1133 </ns:updateInfraRequest>
1135 </soapenv:Envelope>"""
1137 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
1138 execution.setVariable("UPDNETI_updateDBRequest", buildDeleteDBRequestAsString)
1139 utils.log("DEBUG", " DB Adapter Request - " + "\n" + buildDeleteDBRequestAsString, isDebugEnabled)
1140 utils.logAudit(buildDeleteDBRequestAsString)
1142 } catch (Exception ex) {
1143 String exceptionMessage = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. prepareDBRequest() - " + ex.getMessage()
1144 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1145 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1151 public void prepareDBRequestError (Execution execution) {
1152 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1153 execution.setVariable("prefix", Prefix)
1156 utils.log("DEBUG", " ***** Inside prepareDBRequestError of UpdateNetworkInstanceInfra ***** ", isDebugEnabled)
1158 String statusMessage = ""
1159 WorkflowException wfe = null
1160 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
1161 wfe = execution.getVariable("WorkflowException")
1162 statusMessage = wfe.getErrorMessage()
1164 String workflowException = execution.getVariable("WorkflowException")
1166 statusMessage = utils.getNodeText1(workflowException, "ErrorMessage")
1167 } catch (Exception ex) {
1168 statusMessage = "Encountered Error during DB Update. " + ex.getMessage()
1171 String networkOutputs = execution.getVariable("UPDNETI_networkOutputs")
1172 String requestId = execution.getVariable("UPDNETI_requestId")
1173 String networkId = ""
1175 networkId = utils.getNodeText1(networkOutputs, "network-id")
1176 if (networkId == null) {networkId = ""}
1177 } catch (Exception) {
1179 utils.log("DEBUG", " No 'network-id' found in '<network-outputs>' ! ", isDebugEnabled)
1181 String networkName = ""
1183 networkName = utils.getNodeText1(networkOutputs, "network-name")
1184 if (networkName == null) {networkName = ""}
1185 } catch (Exception ex) {
1187 utils.log("DEBUG", " No 'network-name' found in '<network-outputs>' ! ", isDebugEnabled)
1190 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
1193 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
1194 <requestId>${requestId}</requestId>
1195 <lastModifiedBy>BPMN</lastModifiedBy>
1196 <statusMessage>${statusMessage}</statusMessage>
1197 <responseBody></responseBody>
1198 <requestStatus>FAILED</requestStatus>
1199 <vnfOutputs><network-id>${networkId}</network-id><network-name>${networkName}</network-names></vnfOutputs>
1200 </ns:updateInfraRequest>
1202 </soapenv:Envelope>"""
1204 execution.setVariable("UPDNETI_updateDBRequest", dbRequest)
1205 utils.log("DEBUG", " DB Adapter Request - " + "\n" + dbRequest, isDebugEnabled)
1206 utils.logAudit(dbRequest)
1208 } catch (Exception ex) {
1209 String exceptionMessage = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. prepareDBRequestError() - " + ex.getMessage()
1210 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1211 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1218 // **************************************************
1219 // Post or Validate Response Section
1220 // **************************************************
1222 public void validateUpdateNetworkResponse (Execution execution) {
1223 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1224 execution.setVariable("prefix", Prefix)
1226 utils.log("DEBUG", " ***** Inside validateUpdateNetworkResponse of UpdateNetworkInstanceInfra *****", isDebugEnabled)
1229 String returnCode = execution.getVariable("UPDNETI_networkReturnCode")
1230 String networkResponse = execution.getVariable("UPDNETI_updateNetworkResponse")
1231 if (networkResponse==null) {
1232 networkResponse="" // reset
1235 utils.log("DEBUG", " Network Adapter update responseCode: " + returnCode, isDebugEnabled)
1237 String errorMessage = ""
1238 if (returnCode == "200") {
1239 execution.setVariable("UPDNETI_isNetworkRollbackNeeded", true)
1240 utils.logAudit(networkResponse)
1241 execution.setVariable("UPDNETI_updateNetworkResponse", networkResponse)
1242 utils.log("DEBUG", " Network Adapter update Success Response - " + "\n" + networkResponse, isDebugEnabled)
1244 // prepare rollback data
1245 String rollbackData = utils.getNodeXml(networkResponse, "rollback", false).replace("tag0:","").replace(":tag0","")
1246 String rollbackNetwork =
1247 """<NetworkAdapter:rollbackNetwork xmlns:NetworkAdapter="http://org.openecomp.mso/network">
1249 </NetworkAdapter:rollbackNetwork>"""
1250 String rollbackNetworkXml = utils.formatXml(rollbackNetwork)
1251 execution.setVariable("UPDNETI_rollbackNetworkRequest", rollbackNetworkXml)
1252 utils.log("DEBUG", " Network Adapter rollback data - " + "\n" + rollbackNetworkXml, isDebugEnabled)
1254 } else { // network error
1255 if (returnCode.toInteger() > 399 && returnCode.toInteger() < 600) { //4xx, 5xx
1256 if (networkResponse.contains("updateNetworkError")) {
1257 networkResponse = networkResponse.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
1258 errorMessage = utils.getNodeText1(networkResponse, "message")
1259 errorMessage = "Received error from Network Adapter: " + errorMessage
1260 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1262 } else { // CatchAll exception
1263 if (returnCode == "500") {
1264 errorMessage = "JBWEB000065: HTTP Status 500."
1266 errorMessage = "Return code is " + returnCode
1268 errorMessage = "Received error from Network Adapter: " + errorMessage
1269 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1273 } else { // CatchAll exception
1274 String dataErrorMessage = "Received error from Network Adapter. Return code is: " + returnCode
1275 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
1281 } catch (BpmnError e) {
1284 } catch (Exception ex) {
1285 String exceptionMessage = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. validateUpdateNetworkResponse() - " + ex.getMessage()
1286 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1287 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1294 public void validateSDNCResponse (Execution execution) {
1295 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1296 execution.setVariable("prefix", Prefix)
1298 utils.log("DEBUG", " ***** Inside validateSDNCResponse of UpdateNetworkInstanceInfra ***** ", isDebugEnabled)
1300 String response = execution.getVariable("UPDNETI_changeAssignSDNCResponse")
1301 WorkflowException workflowException = null
1303 workflowException = execution.getVariable("UPDNETI_WorkflowException")
1304 //execution.setVariable("WorkflowException", workflowException)
1305 } catch (Exception ex) {
1306 utils.log("DEBUG", " Sdnc 'WorkflowException' object is empty or null. ", isDebugEnabled)
1309 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
1311 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1312 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
1314 String changeAssignSDNCResponseDecodeXml = sdncAdapterUtils.decodeXML(execution.getVariable("UPDNETI_changeAssignSDNCResponse"))
1315 changeAssignSDNCResponseDecodeXml = changeAssignSDNCResponseDecodeXml.replace("&", "&").replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1316 execution.setVariable("UPDNETI_changeAssignSDNCResponse", changeAssignSDNCResponseDecodeXml)
1318 if (execution.getVariable("UPDNETI_sdncResponseSuccess") == true) { // from sdnc util, prefix+'sdncResponseSuccess'
1319 execution.setVariable("UPDNETI_isSdncRollbackNeeded", true)
1320 utils.log("DEBUG", "Successfully Validated SDNC Response", isDebugEnabled)
1323 utils.log("DEBUG", "Did NOT Successfully Validated SDNC Response", isDebugEnabled)
1324 throw new BpmnError("MSOWorkflowException")
1330 public void postProcessResponse (Execution execution) {
1331 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1332 execution.setVariable("prefix", Prefix)
1334 utils.log("DEBUG", " ***** Inside postProcessResponse of UpdateNetworkInstanceInfra ***** ", isDebugEnabled)
1337 // Display DB response: UPDNETI_updateDBResponse / UPDNETI_dbReturnCode
1338 String dbReturnCode = execution.getVariable("UPDNETI_dbReturnCode")
1339 utils.log("DEBUG", " ***** DB Update Response Code : " + dbReturnCode, isDebugEnabled)
1340 String updateDBResponse = execution.getVariable("UPDNETI_updateDBResponse")
1341 utils.log("DEBUG", " ***** DB Update Response String: " + '\n' + updateDBResponse, isDebugEnabled)
1342 utils.logAudit(updateDBResponse)
1344 String source = execution.getVariable("UPDNETI_source")
1345 String requestId = execution.getVariable("UPDNETI_requestId")
1347 String msoCompletionRequest =
1348 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
1349 xmlns:ns="http://org.openecomp/mso/request/types/v1">
1350 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
1351 <request-id>${requestId}</request-id>
1352 <action>UPDATE</action>
1353 <source>${source}</source>
1355 <aetgt:mso-bpel-name>BPMN Network action: UPDATE</aetgt:mso-bpel-name>
1356 </aetgt:MsoCompletionRequest>"""
1359 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
1361 if (dbReturnCode == "200") {
1362 utils.logAudit(updateDBResponse)
1363 utils.logAudit(xmlMsoCompletionRequest)
1364 execution.setVariable("UPDNETI_Success", true)
1365 execution.setVariable("UPDNETI_CompleteMsoProcessRequest", xmlMsoCompletionRequest)
1366 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
1369 String errorMessage = " DB Update failed, code: " + dbReturnCode
1370 utils.log("DEBUG", errorMessage, isDebugEnabled)
1371 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, errorMessage)
1376 } catch (BpmnError e) {
1379 } catch (Exception ex) {
1380 String exceptionMessage = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. postProcessResponse() - " + ex.getMessage()
1381 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1382 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
1389 public void prepareSDNCRollbackRequest (Execution execution) {
1390 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1391 execution.setVariable("prefix", Prefix)
1393 utils.log("DEBUG", " ***** Inside prepareSDNCRollbackRequest of UpdateNetworkInstanceInfra ***** ", isDebugEnabled)
1396 // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException.
1397 execution.setVariable("UPDNETI_WorkflowException", execution.getVariable("WorkflowException"))
1399 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
1400 String updateNetworkInput = execution.getVariable("UPDNETI_networkRequest")
1401 String cloudRegionId = execution.getVariable("UPDNETI_cloudRegionSdnc")
1402 String changeAssignSDNCResponse = execution.getVariable("UPDNETI_changeAssignSDNCResponse")
1403 String networkId = utils.getNodeText1(changeAssignSDNCResponse, "network-id")
1405 String serviceInstanceId = utils.getNodeText1(updateNetworkInput, "service-instance-id")
1407 // 2. prepare rollback topology via SDNC Adapter SUBFLOW call
1408 String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, updateNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null)
1409 String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest)
1410 execution.setVariable("UPDNETI_rollbackSDNCRequest", sndcTopologyRollbackRequestAsString)
1411 utils.log("DEBUG", " Preparing request for SDNC Topology assign's rollback/compensation . . . - " + "\n" + sndcTopologyRollbackRequestAsString, isDebugEnabled)
1414 } catch (Exception ex) {
1415 String exceptionMessage = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. prepareSDNCRollbackRequest() - " + ex.getMessage()
1416 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1417 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1423 public void validateRollbackResponses (Execution execution) {
1424 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1425 execution.setVariable("prefix", Prefix)
1428 // Note: Updates do not support rollback. To restore a previous state, another Update would be needed to revert to the original settings.
1429 // This would need to be managed by the client.
1430 String rollbackNetworkErrorMessages = ""
1431 Boolean isNetworkRollbackNeeded = execution.getVariable("UPDNETI_isNetworkRollbackNeeded")
1432 if (isNetworkRollbackNeeded == true) {
1433 rollbackNetworkErrorMessages = " + PO Network rollback is not supported for Update. Submit another Update to restore/rollback."
1436 // validate SDNC rollback response
1437 String rollbackSdncErrorMessages = ""
1438 Boolean isSdncRollbackNeeded = execution.getVariable("UPDNETI_isSdncRollbackNeeded")
1439 if (isSdncRollbackNeeded == true) {
1440 String rollbackSDNCReturnCode = execution.getVariable("UPDNETI_rollbackSDNCReturnCode")
1441 String rollbackSDNCReturnInnerCode = ""
1442 String rollbackSDNCResponse = execution.getVariable("UPDNETI_rollbackSDNCResponse")
1443 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
1444 rollbackSDNCResponse = sdncAdapterUtils.decodeXML(rollbackSDNCResponse)
1445 rollbackSDNCResponse = rollbackSDNCResponse.replace("&", "&").replace('$', '').replace('<?xml version="1.0" encoding="UTF-8"?>', "")
1447 if (rollbackSDNCReturnCode == "200") {
1448 if (utils.nodeExists(rollbackSDNCResponse, "response-code")) {
1449 rollbackSDNCReturnInnerCode = utils.getNodeText1(rollbackSDNCResponse, "response-code")
1450 if (rollbackSDNCReturnInnerCode == "200" || rollbackSDNCReturnInnerCode == "" || rollbackSDNCReturnInnerCode == "0") {
1451 rollbackSdncErrorMessages = " + SNDC rollback completed."
1453 rollbackSdncErrorMessages = " + SDNC rollback failed. "
1456 rollbackSdncErrorMessages = " + SNDC rollback completed."
1459 rollbackSdncErrorMessages = " + SDNC rollback failed. "
1462 utils.log("DEBUG", " SDNC rollback Code - " + rollbackSDNCReturnCode, isDebugEnabled)
1463 utils.log("DEBUG", " SDNC rollback Response - " + rollbackSDNCResponse, isDebugEnabled)
1467 //WorkflowException wfe = execution.getVariable("WorkflowException")
1468 //String statusMessage = wfe.getErrorMessage()
1469 //int errorCode = wfe.getErrorCode()
1471 String statusMessage = ""
1473 WorkflowException wfe = execution.getVariable("WorkflowException")
1474 if (wfe instanceof WorkflowException) {
1475 statusMessage = wfe.getErrorMessage()
1476 errorCode = wfe.getErrorCode()
1478 if (execution.getVariable("UPDNETI_WorkflowException") instanceof WorkflowException) {
1479 // get saved WorkflowException
1480 WorkflowException swfe = execution.getVariable("UPDNETI_WorkflowException")
1481 statusMessage = swfe.getErrorMessage()
1482 errorCode = swfe.getErrorCode()
1484 statusMessage = "Encountered Error, please see previous tasks/activities/steps for error messages."
1489 // recreate WorkflowException to include the rollback Message
1490 statusMessage = statusMessage + rollbackNetworkErrorMessages + rollbackSdncErrorMessages
1491 exceptionUtil.buildWorkflowException(execution, errorCode, statusMessage)
1493 } catch (Exception ex) {
1494 execution.setVariable("WorkflowException", null)
1495 String exceptionMessage = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. validateRollbackResponses() - " + ex.getMessage()
1496 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
1497 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
1505 // *******************************
1506 // Build Error Section
1507 // *******************************
1509 // Prepare for FalloutHandler
1510 public void buildErrorResponse (Execution execution) {
1511 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1512 execution.setVariable("prefix", Prefix)
1514 utils.log("DEBUG", " ***** Prepare for FalloutHandler. FAILURE - prepare request for sub-process FalloutHandler. *****", isDebugEnabled)
1516 String dbReturnCode = execution.getVariable("UPDNETI_dbReturnCode")
1517 utils.log("DEBUG", " ***** DB Update Response Code : " + dbReturnCode, isDebugEnabled)
1518 String updateDBResponse = execution.getVariable("UPDNETI_updateDBResponse")
1519 utils.log("DEBUG", " ***** DB Update Response String: " + '\n' + updateDBResponse, isDebugEnabled)
1520 utils.logAudit(updateDBResponse)
1522 String falloutHandlerRequest = ""
1523 String requestId = execution.getVariable("UPDNETI_requestId")
1524 String source = execution.getVariable("UPDNETI_source")
1526 execution.setVariable("UPDNETI_Success", false)
1527 WorkflowException wfe = execution.getVariable("WorkflowException")
1528 String errorCode = String.valueOf(wfe.getErrorCode())
1529 String errorMessage = wfe.getErrorMessage()
1530 falloutHandlerRequest =
1531 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
1532 xmlns:ns="http://org.openecomp/mso/request/types/v1"
1533 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
1534 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
1535 <request-id>${requestId}</request-id>
1536 <action>UPDATE</action>
1537 <source>${source}</source>
1539 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
1540 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
1541 <aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>
1542 </aetgt:WorkflowException>
1543 </aetgt:FalloutHandlerRequest>"""
1545 utils.logAudit(falloutHandlerRequest)
1546 execution.setVariable("UPDNETI_FalloutHandlerRequest", falloutHandlerRequest)
1547 utils.log("DEBUG", " Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
1549 } catch (Exception ex) {
1550 String errorException = " Bpmn error encountered in UpdateNetworkInstanceInfra flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
1551 utils.log("DEBUG", errorException, isDebugEnabled)
1552 falloutHandlerRequest =
1553 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
1554 xmlns:ns="http://org.openecomp/mso/request/types/v1"
1555 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
1556 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
1557 <request-id>${requestId}</request-id>
1558 <action>UPDATE</action>
1559 <source>${source}</source>
1561 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
1562 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
1563 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
1564 </aetgt:WorkflowException>
1565 </aetgt:FalloutHandlerRequest>"""
1567 execution.setVariable("UPDNETI_FalloutHandlerRequest", falloutHandlerRequest)
1568 utils.log("DEBUG", " Overall Error Response going to FalloutHandler: " + "\n" + falloutHandlerRequest, isDebugEnabled)
1575 public void sendSyncError (Execution execution) {
1576 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1577 execution.setVariable("prefix", Prefix)
1581 String requestId = execution.getVariable("mso-request-id")
1583 // REST Error (for API Handler (APIH) Reply Task)
1584 String syncError = """{"requestReferences":{"instanceId":"","requestId":"${requestId}"}}""".trim()
1586 sendWorkflowResponse(execution, 500, syncError)
1588 } catch (Exception ex) {
1589 utils.log("DEBUG", " Bpmn error encountered in UpdateNetworkInstanceInfra flow. sendSyncError() - " + ex.getMessage(), isDebugEnabled)
1595 public void processJavaException(Execution execution){
1596 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
1597 execution.setVariable("prefix",Prefix)
1599 utils.log("DEBUG", "Caught a Java Exception", isDebugEnabled)
1600 utils.log("DEBUG", "Started processJavaException Method", isDebugEnabled)
1601 utils.log("DEBUG", "Variables List: " + execution.getVariables(), isDebugEnabled)
1602 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception") // Adding this line temporarily until this flows error handling gets updated
1603 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
1605 }catch(Exception e){
1606 utils.log("DEBUG", "Caught Exception during processJavaException Method: " + e, isDebugEnabled)
1607 execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated
1608 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method")
1610 utils.log("DEBUG", "Completed processJavaException Method", isDebugEnabled)