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
24 import static org.apache.commons.lang3.StringUtils.*;
25 import groovy.xml.XmlUtil
28 import org.onap.so.bpmn.core.json.JsonUtils
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
31 import org.onap.so.bpmn.core.RollbackData
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.logger.MsoLogger
34 import org.onap.so.logger.MessageEnum
36 import java.util.UUID;
38 import org.camunda.bpm.engine.delegate.BpmnError
39 import org.camunda.bpm.engine.delegate.DelegateExecution
40 import org.json.JSONObject;
41 import org.apache.commons.lang3.*
42 import org.apache.commons.codec.binary.Base64;
43 import org.springframework.web.util.UriUtils;
45 * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
48 * @param - msoRequestId
49 * @param - rollbackData with
51 * subscriptionServiceType
60 * @param - rollbackError
61 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
64 public class DoCreateServiceInstanceRollback extends AbstractServiceTaskProcessor{
65 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateServiceInstanceRollback.class);
68 String Prefix="DCRESIRB_"
70 public void preProcessRequest(DelegateExecution execution) {
71 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
72 execution.setVariable("prefix",Prefix)
74 msoLogger.trace("preProcessRequest")
75 execution.setVariable("rollbackAAI",false)
76 execution.setVariable("rollbackSDNC",false)
79 def rollbackData = execution.getVariable("rollbackData")
80 msoLogger.debug("RollbackData:" + rollbackData)
82 if (rollbackData != null) {
83 if (rollbackData.hasType("SERVICEINSTANCE")) {
85 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
86 execution.setVariable("serviceInstanceId", serviceInstanceId)
88 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
89 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
91 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
92 execution.setVariable("globalSubscriberId", globalSubscriberId)
94 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
95 if ("true".equals(rollbackAAI))
97 execution.setVariable("rollbackAAI",true)
100 def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
101 if ("true".equals(rollbackSDNC))
103 execution.setVariable("rollbackSDNC", true)
106 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
108 execution.setVariable("skipRollback", true)
111 def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
112 execution.setVariable("sdncDelete", sdncDelete)
113 def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
114 execution.setVariable("sdncDeactivate", sdncDeactivate)
115 msoLogger.debug("sdncDeactivate:\n" + sdncDeactivate)
116 msoLogger.debug("sdncDelete:\n" + sdncDelete)
119 execution.setVariable("skipRollback", true)
123 execution.setVariable("skipRollback", true)
125 if (execution.getVariable("disableRollback").equals("true" ))
127 execution.setVariable("skipRollback", true)
130 } catch (BpmnError e) {
132 } catch (Exception ex){
133 msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
135 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
137 msoLogger.trace("Exit preProcessRequest")
140 public void validateSDNCResponse(DelegateExecution execution, String response, String method) {
142 msoLogger.trace("validateSDNCResponse")
145 WorkflowException workflowException = execution.getVariable("WorkflowException")
146 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
147 msoLogger.debug("SDNCResponse: " + response)
148 msoLogger.debug("workflowException: " + workflowException)
150 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
151 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
153 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
154 msg = "SDNC Adapter service-instance rollback successful for " + method
157 execution.setVariable("rolledBack", false)
158 msg = "Error Response from SDNC Adapter service-instance rollback for " + method
159 execution.setVariable("rollbackError", msg)
161 throw new BpmnError("MSOWorkflowException")
163 } catch (BpmnError e) {
165 } catch (Exception ex){
166 msg = "Exception in Create ServiceInstance rollback for " + method + " Exception:" + ex.getMessage()
168 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
170 msoLogger.trace("Exit validateSDNCResponse")
173 public void postProcessRequest(DelegateExecution execution) {
175 msoLogger.trace("postProcessRequest")
178 execution.setVariable("rollbackData", null)
179 String serviceInstanceId = execution.getVariable("serviceInstanceId")
180 boolean rollbackAAI = execution.getVariable("rollbackAAI")
181 boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
182 if (rollbackAAI || rollbackSDNC)
184 execution.setVariable("rolledBack", true)
188 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
190 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
191 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
192 msoLogger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
195 msoLogger.trace("Exit postProcessRequest")
197 } catch (BpmnError e) {
198 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
200 } catch (Exception ex) {
201 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
207 public void processRollbackException(DelegateExecution execution){
209 msoLogger.trace("processRollbackException")
211 msoLogger.debug("Caught an Exception in DoCreateServiceInstanceRollback")
212 execution.setVariable("rollbackData", null)
213 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
214 execution.setVariable("WorkflowException", null)
217 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
219 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
222 msoLogger.debug("Exit processRollbackException")
225 public void processRollbackJavaException(DelegateExecution execution){
227 msoLogger.trace("processRollbackJavaException")
229 execution.setVariable("rollbackData", null)
230 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
231 msoLogger.debug("Caught Exception in processRollbackJavaException")
234 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
236 msoLogger.trace("Exit processRollbackJavaException")