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.onap.so.bpmn.infrastructure.scripts;
23 import groovy.xml.XmlUtil
26 import org.onap.so.bpmn.common.scripts.AaiUtil
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.NetworkUtils
30 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
31 import org.onap.so.bpmn.common.scripts.VidUtils
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.core.UrnPropertiesReader
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.so.rest.APIResponse
37 import java.util.UUID;
39 import org.camunda.bpm.engine.delegate.BpmnError
40 import org.camunda.bpm.engine.delegate.DelegateExecution
41 import org.apache.commons.lang3.*
42 import org.apache.commons.codec.binary.Base64;
43 import org.springframework.web.util.UriUtils
45 import org.onap.so.logger.MessageEnum
46 import org.onap.so.logger.MsoLogger
49 * This groovy class supports the <class>DoCreateNetworkInstance.bpmn</class> process.
52 public class DoUpdateNetworkInstanceRollback extends AbstractServiceTaskProcessor {
53 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateNetworkInstanceRollback.class);
55 String Prefix="UPDNETIR_"
56 ExceptionUtil exceptionUtil = new ExceptionUtil()
57 JsonUtils jsonUtil = new JsonUtils()
58 VidUtils vidUtils = new VidUtils(this)
59 NetworkUtils networkUtils = new NetworkUtils()
60 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
62 def className = getClass().getSimpleName()
65 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstanceRollback.bpmn</class> process.
68 public InitializeProcessVariables(DelegateExecution execution){
69 /* Initialize all the process variables in this block */
71 execution.setVariable(Prefix + "rollbackNetworkRequest", null)
72 execution.setVariable(Prefix + "rollbackSDNCRequest", null)
73 execution.setVariable(Prefix + "WorkflowException", null)
75 execution.setVariable(Prefix + "rollbackNetworkRequest", "")
76 execution.setVariable(Prefix + "rollbackNetworkResponse", "")
77 execution.setVariable(Prefix + "rollbackNetworkReturnCode", "")
79 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
80 execution.setVariable(Prefix + "rollbackSDNCResponse", "")
81 execution.setVariable(Prefix + "rollbackSDNCReturnCode", "")
83 execution.setVariable(Prefix + "Success", false)
84 execution.setVariable(Prefix + "fullRollback", false)
88 // **************************************************
89 // Pre or Prepare Request Section
90 // **************************************************
92 * This method is executed during the preProcessRequest task of the <class>DoUpdateNetworkInstanceRollback.bpmn</class> process.
95 public void preProcessRequest (DelegateExecution execution) {
97 execution.setVariable("prefix",Prefix)
99 msoLogger.trace("Inside preProcessRequest() of " + className + ".groovy ")
102 // initialize flow variables
103 InitializeProcessVariables(execution)
105 // GET Incoming request/variables
106 String rollbackNetworkRequest = null
107 String rollbackSDNCRequest = null
110 Map<String, String> rollbackData = execution.getVariable("rollbackData")
111 if (rollbackData != null && rollbackData instanceof Map) {
113 if(rollbackData.containsKey("rollbackNetworkRequest")) {
114 rollbackNetworkRequest = rollbackData["rollbackNetworkRequest"]
117 if(rollbackData.containsKey("rollbackSDNCRequest")) {
118 rollbackSDNCRequest = rollbackData["rollbackSDNCRequest"]
122 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkRequest)
123 execution.setVariable(Prefix + "rollbackSDNCRequest", rollbackSDNCRequest)
124 msoLogger.debug("'rollbackData': " + '\n' + execution.getVariable("rollbackData"))
126 String sdncVersion = execution.getVariable("sdncVersion")
127 msoLogger.debug("sdncVersion? : " + sdncVersion)
129 // PO Authorization Info / headers Authorization=
130 String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
133 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution))
134 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
135 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
137 } catch (IOException ex) {
138 String exceptionMessage = "Exception Encountered in DoCreateNetworkInstance, PreProcessRequest() - "
139 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
140 msoLogger.debug(dataErrorMessage )
141 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
144 if (execution.getVariable("SavedWorkflowException1") != null) {
145 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
147 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
149 msoLogger.debug("*** WorkflowException : " + execution.getVariable(Prefix + "WorkflowException"))
150 if(execution.getVariable(Prefix + "WorkflowException") != null) {
151 // called by: DoCreateNetworkInstance, partial rollback
152 execution.setVariable(Prefix + "fullRollback", false)
155 // called by: Macro - Full Rollback, WorkflowException = null
156 execution.setVariable(Prefix + "fullRollback", true)
159 msoLogger.debug("*** fullRollback? : " + execution.getVariable(Prefix + "fullRollback"))
162 } catch (BpmnError e) {
165 } catch (Exception ex) {
166 sendSyncError(execution)
168 String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage()
169 msoLogger.debug(exceptionMessage)
170 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
176 public void validateRollbackResponses (DelegateExecution execution) {
178 execution.setVariable("prefix",Prefix)
180 msoLogger.trace("Inside validateRollbackResponses() of DoUpdateNetworkInstanceRollback ")
183 // validate PO network rollback response
184 String rollbackNetworkErrorMessages = ""
185 String rollbackNetworkReturnCode = "200"
186 if (execution.getVariable(Prefix + "rollbackNetworkRequest") != null) {
187 rollbackNetworkReturnCode = execution.getVariable(Prefix + "rollbackNetworkReturnCode")
188 String rollbackNetworkResponse = execution.getVariable(Prefix + "rollbackNetworkResponse")
189 msoLogger.debug(" NetworkRollback Code - " + rollbackNetworkReturnCode)
190 msoLogger.debug(" NetworkRollback Response - " + rollbackNetworkResponse)
191 if (rollbackNetworkReturnCode != "200") {
192 rollbackNetworkErrorMessages = " + PO Network rollback failed. "
194 rollbackNetworkErrorMessages = " + PO Network rollback completed."
198 // validate SDNC rollback response
199 String rollbackSdncErrorMessages = ""
200 String rollbackSDNCReturnCode = "200"
201 if (execution.getVariable(Prefix + "rollbackSDNCRequest") != null) {
202 rollbackSDNCReturnCode = execution.getVariable(Prefix + "rollbackSDNCReturnCode")
203 String rollbackSDNCResponse = execution.getVariable(Prefix + "rollbackSDNCResponse")
204 String rollbackSDNCReturnInnerCode = ""
205 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
206 rollbackSDNCResponse = rollbackSDNCResponse.replace('$', '').replace('<?xml version="1.0" encoding="UTF-8"?>', "")
207 if (rollbackSDNCReturnCode == "200") {
208 if (utils.nodeExists(rollbackSDNCResponse, "response-code")) {
209 rollbackSDNCReturnInnerCode = utils.getNodeText(rollbackSDNCResponse, "response-code")
210 if (rollbackSDNCReturnInnerCode == "200" || rollbackSDNCReturnInnerCode == "" || rollbackSDNCReturnInnerCode == "0") {
211 rollbackSdncErrorMessages = " + SNDC changeassign rollback completed."
213 rollbackSdncErrorMessages = " + SDNC changeassign rollback failed. "
216 rollbackSdncErrorMessages = " + SNDC changeassign rollback completed."
219 rollbackSdncErrorMessages = " + SDNC changeassign rollback failed. "
221 msoLogger.debug(" SDNC changeassign rollback Code - " + rollbackSDNCReturnCode)
222 msoLogger.debug(" SDNC changeassign rollback Response - " + rollbackSDNCResponse)
225 String statusMessage = ""
227 msoLogger.debug("*** fullRollback? : " + execution.getVariable(Prefix + "fullRollback"))
228 if (execution.getVariable(Prefix + "fullRollback") == false) {
229 // original WorkflowException,
230 WorkflowException wfe = execution.getVariable(Prefix + "WorkflowException")
232 // rollback due to failure in DoCreate - Partial rollback
233 statusMessage = wfe.getErrorMessage()
234 errorCode = wfe.getErrorCode()
236 statusMessage = "See Previous Camunda flows for cause of Error: Undetermined Exception."
240 // set if all rolledbacks are successful
241 if (rollbackNetworkReturnCode == "200" && rollbackSDNCReturnCode == "200") {
242 execution.setVariable("rolledBack", true)
245 execution.setVariable("rolledBack", false)
249 statusMessage = statusMessage + rollbackNetworkErrorMessages + rollbackSdncErrorMessages
250 msoLogger.debug("Final DoUpdateNetworkInstanceRollback status message: " + statusMessage)
251 String processKey = getProcessKey(execution);
252 WorkflowException exception = new WorkflowException(processKey, errorCode, statusMessage);
253 execution.setVariable("workflowException", exception);
256 // rollback due to failures in Main flow (Macro) - Full rollback
257 // WorkflowException = null
258 if (rollbackNetworkReturnCode == "200" && rollbackSDNCReturnCode == "200") {
259 execution.setVariable("rollbackSuccessful", true)
260 execution.setVariable("rollbackError", false)
262 String exceptionMessage = "Network Update Rollback was not Successful. "
263 msoLogger.debug(exceptionMessage)
264 execution.setVariable("rollbackSuccessful", false)
265 execution.setVariable("rollbackError", true)
266 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
267 throw new BpmnError("MSOWorkflowException")
273 } catch (Exception ex) {
274 execution.setVariable("WorkflowException", null)
275 String errorMessage = "See Previous Camunda flows for cause of Error: Undetermined Exception."
276 String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstanceRollback flow. validateRollbackResponses() - " + errorMessage + ": " + ex.getMessage()
277 msoLogger.debug(exceptionMessage)
278 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
279 execution.setVariable("WorkflowException", execution.getVariable("WorkflowException"))
285 // *******************************
286 // Build Error Section
287 // *******************************
291 public void processJavaException(DelegateExecution execution){
293 execution.setVariable("prefix",Prefix)
296 msoLogger.debug("Caught a Java Exception in " + Prefix)
297 msoLogger.debug("Started processJavaException Method")
298 msoLogger.debug("Variables List: " + execution.getVariables())
299 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
300 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
303 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
304 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
305 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
307 msoLogger.trace("Completed processJavaException Method in " + Prefix)