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
25 import org.onap.so.bpmn.core.UrnPropertiesReader
26 import org.onap.so.bpmn.core.json.JsonUtils
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
35 import java.util.UUID;
37 import org.camunda.bpm.engine.delegate.BpmnError
38 import org.camunda.bpm.engine.delegate.DelegateExecution
39 import org.apache.commons.lang3.*
40 import org.apache.commons.codec.binary.Base64;
41 import org.springframework.web.util.UriUtils
43 import org.onap.so.logger.MessageEnum
44 import org.onap.so.logger.MsoLogger
47 * This groovy class supports the <class>DoCreateNetworkInstanceRollback.bpmn</class> process.
50 public class DoDeleteNetworkInstanceRollback extends AbstractServiceTaskProcessor {
51 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteNetworkInstanceRollback.class);
53 String Prefix="DELNWKIR_"
54 ExceptionUtil exceptionUtil = new ExceptionUtil()
55 JsonUtils jsonUtil = new JsonUtils()
56 VidUtils vidUtils = new VidUtils(this)
57 NetworkUtils networkUtils = new NetworkUtils()
58 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
60 def className = getClass().getSimpleName()
63 * This method is executed during the preProcessRequest task of the <class>DoDeleteNetworkInstanceRollback.bpmn</class> process.
66 public InitializeProcessVariables(DelegateExecution execution){
67 /* Initialize all the process variables in this block */
69 execution.setVariable(Prefix + "WorkflowException", null)
71 execution.setVariable(Prefix + "rollbackDeactivateSDNCRequest", null)
72 execution.setVariable(Prefix + "rollbackDeactivateSDNCResponse", "")
73 execution.setVariable(Prefix + "rollbackDeactivateSDNCReturnCode", "")
75 execution.setVariable(Prefix + "rollbackSDNCRequest", "")
76 execution.setVariable(Prefix + "rollbackSDNCResponse", "")
77 execution.setVariable(Prefix + "rollbackSDNCReturnCode", "")
79 execution.setVariable(Prefix + "rollbackNetworkRequest", null)
80 execution.setVariable(Prefix + "rollbackNetworkResponse", "")
81 execution.setVariable(Prefix + "rollbackNetworkReturnCode", "")
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>DoDeleteNetworkInstanceRollback.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 rollbackDeactivateSDNCRequest = null
107 String rollbackSDNCRequest = null
108 String rollbackNetworkRequest = null
110 Map<String, String> rollbackData = execution.getVariable("rollbackData")
111 if (rollbackData != null && rollbackData instanceof Map) {
113 if(rollbackData.containsKey("rollbackDeactivateSDNCRequest")) {
114 rollbackDeactivateSDNCRequest = rollbackData["rollbackDeactivateSDNCRequest"]
117 if(rollbackData.containsKey("rollbackSDNCRequest")) {
118 rollbackSDNCRequest = rollbackData["rollbackSDNCRequest"]
121 if(rollbackData.containsKey("rollbackNetworkRequest")) {
122 rollbackNetworkRequest = rollbackData["rollbackNetworkRequest"]
126 execution.setVariable(Prefix + "rollbackNetworkRequest", rollbackNetworkRequest)
127 execution.setVariable(Prefix + "rollbackSDNCRequest", rollbackSDNCRequest)
128 execution.setVariable(Prefix + "rollbackDeactivateSDNCRequest", rollbackDeactivateSDNCRequest)
129 msoLogger.debug("'rollbackData': " + '\n' + execution.getVariable("rollbackData"))
131 String sdncVersion = execution.getVariable("sdncVersion")
132 msoLogger.debug("sdncVersion? : " + sdncVersion)
134 // PO Authorization Info / headers Authorization=
135 String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution)
137 def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution))
138 execution.setVariable("BasicAuthHeaderValuePO",encodedString)
139 execution.setVariable("BasicAuthHeaderValueSDNC", encodedString)
141 } catch (IOException ex) {
142 String exceptionMessage = "Exception Encountered in DoCreateNetworkInstance, PreProcessRequest() - "
143 String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage()
144 msoLogger.debug(dataErrorMessage )
145 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
148 if (execution.getVariable("SavedWorkflowException1") != null) {
149 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1"))
151 execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException"))
153 msoLogger.debug("*** WorkflowException : " + execution.getVariable(Prefix + "WorkflowException"))
154 if(execution.getVariable(Prefix + "WorkflowException") != null) {
155 // called by: DoCreateNetworkInstance, partial rollback
156 execution.setVariable(Prefix + "fullRollback", false)
159 // called by: Macro - Full Rollback, WorkflowException = null
160 execution.setVariable(Prefix + "fullRollback", true)
164 msoLogger.debug("*** fullRollback? : " + execution.getVariable(Prefix + "fullRollback"))
166 } catch (BpmnError e) {
169 } catch (Exception ex) {
170 sendSyncError(execution)
172 String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage()
173 msoLogger.debug(exceptionMessage)
174 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
180 public void validateRollbackResponses (DelegateExecution execution) {
182 execution.setVariable("prefix",Prefix)
184 msoLogger.trace("Inside validateRollbackResponses() of DoDeleteNetworkInstanceRollback ")
188 // validate SDNC activate response
189 String rollbackDeactivateSDNCMessages = ""
190 String rollbackDeactivateSDNCReturnCode = "200"
191 if (execution.getVariable(Prefix + "rollbackDeactivateSDNCRequest") != null) {
192 rollbackDeactivateSDNCReturnCode = execution.getVariable(Prefix + "rollbackDeactivateSDNCReturnCode")
193 String rollbackDeactivateSDNCResponse = execution.getVariable(Prefix + "rollbackDeactivateSDNCResponse")
194 String rollbackDeactivateSDNCReturnInnerCode = ""
195 rollbackDeactivateSDNCResponse = rollbackDeactivateSDNCResponse.replace('$', '').replace('<?xml version="1.0" encoding="UTF-8"?>', "")
196 if (rollbackDeactivateSDNCReturnCode == "200") {
197 if (utils.nodeExists(rollbackDeactivateSDNCResponse, "response-code")) {
198 rollbackDeactivateSDNCReturnInnerCode = utils.getNodeText(rollbackDeactivateSDNCResponse, "response-code")
199 if (rollbackDeactivateSDNCReturnInnerCode == "200" || rollbackDeactivateSDNCReturnInnerCode == "" || rollbackDeactivateSDNCReturnInnerCode == "0") {
200 rollbackDeactivateSDNCMessages = " + SNDC deactivate rollback completed."
202 rollbackDeactivateSDNCMessages = " + SDNC deactivate rollback failed. "
205 rollbackDeactivateSDNCMessages = " + SNDC deactivate rollback completed."
208 rollbackDeactivateSDNCMessages = " + SDNC deactivate rollback failed. "
210 msoLogger.debug(" SDNC deactivate rollback Code - " + rollbackDeactivateSDNCReturnCode)
211 msoLogger.debug(" SDNC deactivate rollback Response - " + rollbackDeactivateSDNCResponse)
214 // validate SDNC rollback response
215 String rollbackSdncErrorMessages = ""
216 String rollbackSDNCReturnCode = "200"
217 if (execution.getVariable(Prefix + "rollbackSDNCRequest") != null) {
218 rollbackSDNCReturnCode = execution.getVariable(Prefix + "rollbackSDNCReturnCode")
219 String rollbackSDNCResponse = execution.getVariable(Prefix + "rollbackSDNCResponse")
220 String rollbackSDNCReturnInnerCode = ""
221 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
222 rollbackSDNCResponse = rollbackSDNCResponse.replace('$', '').replace('<?xml version="1.0" encoding="UTF-8"?>', "")
223 if (rollbackSDNCReturnCode == "200") {
224 if (utils.nodeExists(rollbackSDNCResponse, "response-code")) {
225 rollbackSDNCReturnInnerCode = utils.getNodeText(rollbackSDNCResponse, "response-code")
226 if (rollbackSDNCReturnInnerCode == "200" || rollbackSDNCReturnInnerCode == "" || rollbackSDNCReturnInnerCode == "0") {
227 rollbackSdncErrorMessages = " + SNDC unassign rollback completed."
229 rollbackSdncErrorMessages = " + SDNC unassign rollback failed. "
232 rollbackSdncErrorMessages = " + SNDC unassign rollback completed."
235 rollbackSdncErrorMessages = " + SDNC unassign rollback failed. "
237 msoLogger.debug(" SDNC assign rollback Code - " + rollbackSDNCReturnCode)
238 msoLogger.debug(" SDNC assign rollback Response - " + rollbackSDNCResponse)
241 // validate PO network rollback response
242 String rollbackNetworkErrorMessages = ""
243 String rollbackNetworkReturnCode = "200"
244 if (execution.getVariable(Prefix + "rollbackNetworkRequest") != null) {
245 rollbackNetworkReturnCode = execution.getVariable(Prefix + "rollbackNetworkReturnCode")
246 String rollbackNetworkResponse = execution.getVariable(Prefix + "rollbackNetworkResponse")
247 if (rollbackNetworkReturnCode != "200") {
248 rollbackNetworkErrorMessages = " + PO Network rollback failed. "
250 rollbackNetworkErrorMessages = " + PO Network rollback completed."
253 msoLogger.debug(" NetworkRollback Code - " + rollbackNetworkReturnCode)
254 msoLogger.debug(" NetworkRollback Response - " + rollbackNetworkResponse)
257 String statusMessage = ""
259 msoLogger.debug("*** fullRollback? : " + execution.getVariable(Prefix + "fullRollback"))
260 if (execution.getVariable(Prefix + "fullRollback") == false) {
261 WorkflowException wfe = execution.getVariable(Prefix + "WorkflowException") // original WorkflowException
263 statusMessage = wfe.getErrorMessage()
264 errorCode = wfe.getErrorCode()
266 statusMessage = "See Previous Camunda flows for cause of Error: Undetermined Exception."
270 // set if all rolledbacks are successful
271 if (rollbackDeactivateSDNCReturnCode == "200" && rollbackNetworkReturnCode == "200" && rollbackSDNCReturnCode == "200") {
272 execution.setVariable("rolledBack", true)
273 execution.setVariable("wasDeleted", true)
276 execution.setVariable("rolledBack", false)
277 execution.setVariable("wasDeleted", true)
280 statusMessage = statusMessage + rollbackDeactivateSDNCMessages + rollbackNetworkErrorMessages + rollbackSdncErrorMessages
281 msoLogger.debug("Final DoDeleteNetworkInstanceRollback status message: " + statusMessage)
282 String processKey = getProcessKey(execution);
283 WorkflowException exception = new WorkflowException(processKey, errorCode, statusMessage);
284 execution.setVariable("workflowException", exception);
287 // rollback due to failures in Main flow (Macro or a-ala-carte) - Full rollback
288 if (rollbackDeactivateSDNCReturnCode == "200" && rollbackNetworkReturnCode == "200" && rollbackSDNCReturnCode == "200") {
289 execution.setVariable("rollbackSuccessful", true)
290 execution.setVariable("rollbackError", false)
292 String exceptionMessage = "Network Delete Rollback was not Successful. "
293 msoLogger.debug(exceptionMessage)
294 execution.setVariable("rollbackSuccessful", false)
295 execution.setVariable("rollbackError", true)
296 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
297 throw new BpmnError("MSOWorkflowException")
301 } catch (Exception ex) {
302 String errorMessage = "See Previous Camunda flows for cause of Error: Undetermined Exception."
303 String exceptionMessage = " Bpmn error encountered in DoDeleteNetworkInstanceRollback flow. validateRollbackResponses() - " + errorMessage + ": " + ex.getMessage()
304 msoLogger.debug(exceptionMessage)
305 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
311 // *******************************
312 // Build Error Section
313 // *******************************
317 public void processJavaException(DelegateExecution execution){
319 execution.setVariable("prefix",Prefix)
322 msoLogger.debug("Caught a Java Exception in " + Prefix)
323 msoLogger.debug("Started processJavaException Method")
324 msoLogger.debug("Variables List: " + execution.getVariables())
325 execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
326 exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception")
329 msoLogger.debug("Caught Exception during processJavaException Method: " + e)
330 execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated
331 exceptionUtil.buildWorkflowException(execution, 500, "Exception in processJavaException method" + Prefix)
333 msoLogger.debug("Completed processJavaException Method in " + Prefix)