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
26 import static org.apache.commons.lang3.StringUtils.*;
27 import groovy.xml.XmlUtil
30 import org.onap.so.bpmn.core.json.JsonUtils
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
33 import org.onap.so.bpmn.core.RollbackData
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.slf4j.Logger
36 import org.slf4j.LoggerFactory
38 import java.util.UUID;
40 import org.camunda.bpm.engine.delegate.BpmnError
41 import org.camunda.bpm.engine.delegate.DelegateExecution
42 import org.json.JSONObject;
43 import org.apache.commons.lang3.*
44 import org.apache.commons.codec.binary.Base64;
45 import org.springframework.web.util.UriUtils;
47 * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
50 * @param - msoRequestId
51 * @param - rollbackData with
53 * subscriptionServiceType
62 * @param - rollbackError
63 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
66 public class DoCreateServiceInstanceRollback extends AbstractServiceTaskProcessor{
67 private static final Logger logger = LoggerFactory.getLogger( DoCreateServiceInstanceRollback.class);
70 String Prefix="DCRESIRB_"
72 public void preProcessRequest(DelegateExecution execution) {
73 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
74 execution.setVariable("prefix",Prefix)
76 logger.trace("preProcessRequest")
77 execution.setVariable("rollbackAAI",false)
78 execution.setVariable("rollbackSDNC",false)
81 def rollbackData = execution.getVariable("rollbackData")
82 logger.debug("RollbackData:" + rollbackData)
84 if (rollbackData != null) {
85 if (rollbackData.hasType("SERVICEINSTANCE")) {
87 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
88 execution.setVariable("serviceInstanceId", serviceInstanceId)
90 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
91 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
93 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
94 execution.setVariable("globalSubscriberId", globalSubscriberId)
96 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
97 if ("true".equals(rollbackAAI))
99 execution.setVariable("rollbackAAI",true)
102 def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
103 if ("true".equals(rollbackSDNC))
105 execution.setVariable("rollbackSDNC", true)
108 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
110 execution.setVariable("skipRollback", true)
113 def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
114 execution.setVariable("sdncDelete", sdncDelete)
115 def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
116 execution.setVariable("sdncDeactivate", sdncDeactivate)
117 logger.debug("sdncDeactivate:\n" + sdncDeactivate)
118 logger.debug("sdncDelete:\n" + sdncDelete)
121 execution.setVariable("skipRollback", true)
125 execution.setVariable("skipRollback", true)
127 if (execution.getVariable("disableRollback").equals("true" ))
129 execution.setVariable("skipRollback", true)
132 } catch (BpmnError e) {
134 } catch (Exception ex){
135 msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
137 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
139 logger.trace("Exit preProcessRequest")
142 public void validateSDNCResponse(DelegateExecution execution, String response, String method) {
144 logger.trace("validateSDNCResponse")
147 WorkflowException workflowException = execution.getVariable("WorkflowException")
148 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
149 logger.debug("SDNCResponse: " + response)
150 logger.debug("workflowException: " + workflowException)
152 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
153 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
155 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
156 msg = "SDNC Adapter service-instance rollback successful for " + method
159 execution.setVariable("rolledBack", false)
160 msg = "Error Response from SDNC Adapter service-instance rollback for " + method
161 execution.setVariable("rollbackError", msg)
163 throw new BpmnError("MSOWorkflowException")
165 } catch (BpmnError e) {
167 } catch (Exception ex){
168 msg = "Exception in Create ServiceInstance rollback for " + method + " Exception:" + ex.getMessage()
170 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
172 logger.trace("Exit validateSDNCResponse")
175 public void postProcessRequest(DelegateExecution execution) {
177 logger.trace("postProcessRequest")
180 execution.setVariable("rollbackData", null)
181 String serviceInstanceId = execution.getVariable("serviceInstanceId")
182 boolean rollbackAAI = execution.getVariable("rollbackAAI")
183 boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
184 if (rollbackAAI || rollbackSDNC)
186 execution.setVariable("rolledBack", true)
190 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
192 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
193 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
194 logger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
197 logger.trace("Exit postProcessRequest")
199 } catch (BpmnError e) {
200 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
202 } catch (Exception ex) {
203 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
209 public void processRollbackException(DelegateExecution execution){
211 logger.trace("processRollbackException")
213 logger.debug("Caught an Exception in DoCreateServiceInstanceRollback")
214 execution.setVariable("rollbackData", null)
215 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
216 execution.setVariable("WorkflowException", null)
219 logger.debug("BPMN Error during processRollbackExceptions Method: ")
221 logger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
224 logger.debug("Exit processRollbackException")
227 public void processRollbackJavaException(DelegateExecution execution){
229 logger.trace("processRollbackJavaException")
231 execution.setVariable("rollbackData", null)
232 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
233 logger.debug("Caught Exception in processRollbackJavaException")
236 logger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
238 logger.trace("Exit processRollbackJavaException")