2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts;
25 import groovy.xml.XmlUtil
28 import org.onap.so.bpmn.common.scripts.AaiUtil
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.NetworkUtils
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
33 import org.onap.so.bpmn.common.scripts.VidUtils
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.bpmn.core.json.JsonUtils
39 import java.util.UUID;
41 import org.camunda.bpm.engine.delegate.BpmnError
42 import org.camunda.bpm.engine.delegate.DelegateExecution
43 import org.apache.commons.lang3.*
44 import org.apache.commons.codec.binary.Base64;
45 import org.springframework.web.util.UriUtils
47 import org.slf4j.Logger
48 import org.slf4j.LoggerFactory
51 * This groovy class supports the <class>DoCreateNetworkInstance.bpmn</class> process.
54 public class DoUpdateNetworkInstanceRollback extends AbstractServiceTaskProcessor {
55 private static final Logger logger = LoggerFactory.getLogger( DoUpdateNetworkInstanceRollback.class);
57 String Prefix="UPDNETIR_"
58 ExceptionUtil exceptionUtil = new ExceptionUtil()
59 JsonUtils jsonUtil = new JsonUtils()
60 VidUtils vidUtils = new VidUtils(this)
61 NetworkUtils networkUtils = new NetworkUtils()
62 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
64 def className = getClass().getSimpleName()
67 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstanceRollback.bpmn</class> process.
70 public InitializeProcessVariables(DelegateExecution execution){
71 /* Initialize all the process variables in this block */
73 execution.setVariable(Prefix + "rollbackNetworkRequest", null)
74 execution.setVariable(Prefix + "rollbackSDNCRequest", null)
75 execution.setVariable(Prefix + "WorkflowException", null)
77 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
78 execution.setVariable(Prefix + "rollbackNetworkResponse", "")
79 execution.setVariable(Prefix + "rollbackNetworkReturnCode", "")
81 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
82 execution.setVariable(Prefix + "rollbackSDNCResponse", "")
83 execution.setVariable(Prefix + "rollbackSDNCReturnCode", "")
85 execution.setVariable(Prefix + "Success", false)
86 execution.setVariable(Prefix + "fullRollback", false)
90 // **************************************************
91 // Pre or Prepare Request Section
92 // **************************************************
94 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstanceRollback.bpmn</class> process.
97 public void preProcessRequest (DelegateExecution execution) {
99 execution.setVariable("prefix",Prefix)
101 logger.trace("Inside preProcessRequest() of " + className + ".groovy ")
104 // initialize flow variables
105 InitializeProcessVariables(execution)
107 // GET Incoming request/variables
108 String rollbackNetworkRequest = null
109 String rollbackSDNCRequest = null
112 Map<String, String> rollbackData = execution.getVariable("rollbackData")
113 if (rollbackData != null && rollbackData instanceof Map) {
115 if(rollbackData.containsKey("rollbackNetworkRequest")) {
116 rollbackNetworkRequest = rollbackData["rollbackNetworkRequest"]
119 if(rollbackData.containsKey("rollbackSDNCRequest")) {
120 rollbackSDNCRequest = rollbackData["rollbackSDNCRequest"]
124 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkRequest)
125 execution.setVariable(Prefix + "rollbackSDNCRequest", rollbackSDNCRequest)
126 logger.debug("'rollbackData': " + '\n' + execution.getVariable("rollbackData"))
128 String sdncVersion = execution.getVariable("sdncVersion")
129 logger.debug("sdncVersion? : " + sdncVersion)
131 // PO Authorization Info / headers Authorization=
132 String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
135 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution))
136 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
137 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
139 } catch (IOException ex) {
140 String exceptionMessage = "Exception Encountered in DoCreateNetworkInstance, PreProcessRequest() - "
141 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
142 logger.debug(dataErrorMessage )
143 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
146 if (execution.getVariable("SavedWorkflowException1") != null) {
147 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
149 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
151 logger.debug("*** WorkflowException : " + execution.getVariable(Prefix + "WorkflowException"))
152 if(execution.getVariable(Prefix + "WorkflowException") != null) {
153 // called by: DoCreateNetworkInstance, partial rollback
154 execution.setVariable(Prefix + "fullRollback", false)
157 // called by: Macro - Full Rollback, WorkflowException = null
158 execution.setVariable(Prefix + "fullRollback", true)
161 logger.debug("*** fullRollback? : " + execution.getVariable(Prefix + "fullRollback"))
164 } catch (BpmnError e) {
167 } catch (Exception ex) {
168 sendSyncError(execution)
170 String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage()
171 logger.debug(exceptionMessage)
172 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
178 public void validateRollbackResponses (DelegateExecution execution) {
180 execution.setVariable("prefix",Prefix)
182 logger.trace("Inside validateRollbackResponses() of DoUpdateNetworkInstanceRollback ")
185 // validate PO network rollback response
186 String rollbackNetworkErrorMessages = ""
187 String rollbackNetworkReturnCode = "200"
188 if (execution.getVariable(Prefix + "rollbackNetworkRequest") != null) {
189 rollbackNetworkReturnCode = execution.getVariable(Prefix + "rollbackNetworkReturnCode")
190 String rollbackNetworkResponse = execution.getVariable(Prefix + "rollbackNetworkResponse")
191 logger.debug(" NetworkRollback Code - " + rollbackNetworkReturnCode)
192 logger.debug(" NetworkRollback Response - " + rollbackNetworkResponse)
193 if (rollbackNetworkReturnCode != "200") {
194 rollbackNetworkErrorMessages = " + PO Network rollback failed. "
196 rollbackNetworkErrorMessages = " + PO Network rollback completed."
200 // validate SDNC rollback response
201 String rollbackSdncErrorMessages = ""
202 String rollbackSDNCReturnCode = "200"
203 if (execution.getVariable(Prefix + "rollbackSDNCRequest") != null) {
204 rollbackSDNCReturnCode = execution.getVariable(Prefix + "rollbackSDNCReturnCode")
205 String rollbackSDNCResponse = execution.getVariable(Prefix + "rollbackSDNCResponse")
206 String rollbackSDNCReturnInnerCode = ""
207 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
208 rollbackSDNCResponse = rollbackSDNCResponse.replace('$', '').replace('<?xml version="1.0" encoding="UTF-8"?>', "")
209 if (rollbackSDNCReturnCode == "200") {
210 if (utils.nodeExists(rollbackSDNCResponse, "response-code")) {
211 rollbackSDNCReturnInnerCode = utils.getNodeText(rollbackSDNCResponse, "response-code")
212 if (rollbackSDNCReturnInnerCode == "200" || rollbackSDNCReturnInnerCode == "" || rollbackSDNCReturnInnerCode == "0") {
213 rollbackSdncErrorMessages = " + SNDC changeassign rollback completed."
215 rollbackSdncErrorMessages = " + SDNC changeassign rollback failed. "
218 rollbackSdncErrorMessages = " + SNDC changeassign rollback completed."
221 rollbackSdncErrorMessages = " + SDNC changeassign rollback failed. "
223 logger.debug(" SDNC changeassign rollback Code - " + rollbackSDNCReturnCode)
224 logger.debug(" SDNC changeassign rollback Response - " + rollbackSDNCResponse)
227 String statusMessage = ""
229 logger.debug("*** fullRollback? : " + execution.getVariable(Prefix + "fullRollback"))
230 if (execution.getVariable(Prefix + "fullRollback") == false) {
231 // original WorkflowException,
232 WorkflowException wfe = execution.getVariable(Prefix + "WorkflowException")
234 // rollback due to failure in DoCreate - Partial rollback
235 statusMessage = wfe.getErrorMessage()
236 errorCode = wfe.getErrorCode()
238 statusMessage = "See Previous Camunda flows for cause of Error: Undetermined Exception."
242 // set if all rolledbacks are successful
243 if (rollbackNetworkReturnCode == "200" && rollbackSDNCReturnCode == "200") {
244 execution.setVariable("rolledBack", true)
247 execution.setVariable("rolledBack", false)
251 statusMessage = statusMessage + rollbackNetworkErrorMessages + rollbackSdncErrorMessages
252 logger.debug("Final DoUpdateNetworkInstanceRollback status message: " + statusMessage)
253 String processKey = getProcessKey(execution);
254 WorkflowException exception = new WorkflowException(processKey, errorCode, statusMessage);
255 execution.setVariable("workflowException", exception);
258 // rollback due to failures in Main flow (Macro) - Full rollback
259 // WorkflowException = null
260 if (rollbackNetworkReturnCode == "200" && rollbackSDNCReturnCode == "200") {
261 execution.setVariable("rollbackSuccessful", true)
262 execution.setVariable("rollbackError", false)
264 String exceptionMessage = "Network Update Rollback was not Successful. "
265 logger.debug(exceptionMessage)
266 execution.setVariable("rollbackSuccessful", false)
267 execution.setVariable("rollbackError", true)
268 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
269 throw new BpmnError("MSOWorkflowException")
275 } catch (Exception ex) {
276 execution.setVariable("WorkflowException", null)
277 String errorMessage = "See Previous Camunda flows for cause of Error: Undetermined Exception."
278 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstanceRollback flow. validateRollbackResponses() - " + errorMessage + ": " + ex.getMessage()
279 logger.debug(exceptionMessage)
280 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
281 execution.setVariable("WorkflowException", execution.getVariable("WorkflowException"))
287 // *******************************
288 // Build Error Section
289 // *******************************
293 public void processJavaException(DelegateExecution execution){
295 execution.setVariable("prefix",Prefix)
298 logger.debug("Caught a Java Exception in " + Prefix)
299 logger.debug("Started processJavaException Method")
300 logger.debug("Variables List: " + execution.getVariables())
301 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
302 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
305 logger.debug("Caught Exception during processJavaException Method: " + e)
306 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
307 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
309 logger.trace("Completed processJavaException Method in " + Prefix)