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.rest.APIResponse;
34 import org.onap.so.rest.RESTClient
35 import org.onap.so.rest.RESTConfig
36 import org.onap.so.logger.MsoLogger
37 import org.onap.so.logger.MessageEnum
39 import java.util.UUID;
41 import org.camunda.bpm.engine.delegate.BpmnError
42 import org.camunda.bpm.engine.delegate.DelegateExecution
43 import org.json.JSONObject;
44 import org.apache.commons.lang3.*
45 import org.apache.commons.codec.binary.Base64;
46 import org.springframework.web.util.UriUtils;
48 * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
51 * @param - msoRequestId
52 * @param - rollbackData with
54 * subscriptionServiceType
63 * @param - rollbackError
64 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
67 public class DoCreateServiceInstanceRollback extends AbstractServiceTaskProcessor{
68 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateServiceInstanceRollback.class);
71 String Prefix="DCRESIRB_"
73 public void preProcessRequest(DelegateExecution execution) {
74 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
75 execution.setVariable("prefix",Prefix)
77 msoLogger.trace("preProcessRequest")
78 execution.setVariable("rollbackAAI",false)
79 execution.setVariable("rollbackSDNC",false)
82 def rollbackData = execution.getVariable("rollbackData")
83 msoLogger.debug("RollbackData:" + rollbackData)
85 if (rollbackData != null) {
86 if (rollbackData.hasType("SERVICEINSTANCE")) {
88 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
89 execution.setVariable("serviceInstanceId", serviceInstanceId)
91 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
92 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
94 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
95 execution.setVariable("globalSubscriberId", globalSubscriberId)
97 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
98 if ("true".equals(rollbackAAI))
100 execution.setVariable("rollbackAAI",true)
103 def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
104 if ("true".equals(rollbackSDNC))
106 execution.setVariable("rollbackSDNC", true)
109 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
111 execution.setVariable("skipRollback", true)
114 def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
115 execution.setVariable("sdncDelete", sdncDelete)
116 def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
117 execution.setVariable("sdncDeactivate", sdncDeactivate)
118 msoLogger.debug("sdncDeactivate:\n" + sdncDeactivate)
119 msoLogger.debug("sdncDelete:\n" + sdncDelete)
122 execution.setVariable("skipRollback", true)
126 execution.setVariable("skipRollback", true)
128 if (execution.getVariable("disableRollback").equals("true" ))
130 execution.setVariable("skipRollback", true)
133 } catch (BpmnError e) {
135 } catch (Exception ex){
136 msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
138 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140 msoLogger.trace("Exit preProcessRequest")
143 public void validateSDNCResponse(DelegateExecution execution, String response, String method) {
145 msoLogger.trace("validateSDNCResponse")
148 WorkflowException workflowException = execution.getVariable("WorkflowException")
149 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
150 msoLogger.debug("SDNCResponse: " + response)
151 msoLogger.debug("workflowException: " + workflowException)
153 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
154 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
156 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
157 msg = "SDNC Adapter service-instance rollback successful for " + method
160 execution.setVariable("rolledBack", false)
161 msg = "Error Response from SDNC Adapter service-instance rollback for " + method
162 execution.setVariable("rollbackError", msg)
164 throw new BpmnError("MSOWorkflowException")
166 } catch (BpmnError e) {
168 } catch (Exception ex){
169 msg = "Exception in Create ServiceInstance rollback for " + method + " Exception:" + ex.getMessage()
171 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
173 msoLogger.trace("Exit validateSDNCResponse")
176 public void postProcessRequest(DelegateExecution execution) {
178 msoLogger.trace("postProcessRequest")
181 execution.setVariable("rollbackData", null)
182 String serviceInstanceId = execution.getVariable("serviceInstanceId")
183 boolean rollbackAAI = execution.getVariable("rollbackAAI")
184 boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
185 if (rollbackAAI || rollbackSDNC)
187 execution.setVariable("rolledBack", true)
191 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
193 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
194 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
195 msoLogger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
198 msoLogger.trace("Exit postProcessRequest")
200 } catch (BpmnError e) {
201 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
203 } catch (Exception ex) {
204 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
210 public void processRollbackException(DelegateExecution execution){
212 msoLogger.trace("processRollbackException")
214 msoLogger.debug("Caught an Exception in DoCreateServiceInstanceRollback")
215 execution.setVariable("rollbackData", null)
216 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
217 execution.setVariable("WorkflowException", null)
220 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
222 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
225 msoLogger.debug("Exit processRollbackException")
228 public void processRollbackJavaException(DelegateExecution execution){
230 msoLogger.trace("processRollbackJavaException")
232 execution.setVariable("rollbackData", null)
233 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
234 msoLogger.debug("Caught Exception in processRollbackJavaException")
237 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
239 msoLogger.trace("Exit processRollbackJavaException")