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=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts
23 import static org.apache.commons.lang3.StringUtils.*;
24 import groovy.xml.XmlUtil
27 import org.openecomp.mso.bpmn.core.json.JsonUtils
28 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
30 import org.openecomp.mso.bpmn.core.RollbackData
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.rest.APIResponse;
33 import org.openecomp.mso.rest.RESTClient
34 import org.openecomp.mso.rest.RESTConfig
36 import java.util.UUID;
38 import org.camunda.bpm.engine.delegate.BpmnError
39 import org.camunda.bpm.engine.runtime.Execution
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{
66 String Prefix="DCRESIRB_"
68 public void preProcessRequest(Execution execution) {
69 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
70 execution.setVariable("prefix",Prefix)
72 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
73 execution.setVariable("rollbackAAI",false)
74 execution.setVariable("rollbackSDNC",false)
77 def rollbackData = execution.getVariable("rollbackData")
78 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
80 if (rollbackData != null) {
81 if (rollbackData.hasType("SERVICEINSTANCE")) {
83 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
84 execution.setVariable("serviceInstanceId", serviceInstanceId)
86 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
87 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
89 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
90 execution.setVariable("globalSubscriberId", globalSubscriberId)
92 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
93 if ("true".equals(rollbackAAI))
95 execution.setVariable("rollbackAAI",true)
98 def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
99 if ("true".equals(rollbackSDNC))
101 execution.setVariable("rollbackSDNC", true)
104 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
106 execution.setVariable("skipRollback", true)
109 def sdncRollbackRequest = rollbackData.get("SERVICEINSTANCE", "sdncRollbackRequest")
110 execution.setVariable("sdncRollbackRequest", sdncRollbackRequest)
113 execution.setVariable("skipRollback", true)
117 execution.setVariable("skipRollback", true)
119 if (execution.getVariable("disableRollback").equals("true" ))
121 execution.setVariable("skipRollback", true)
124 } catch (BpmnError e) {
126 } catch (Exception ex){
127 msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
128 utils.log("DEBUG", msg, isDebugEnabled)
129 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
131 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
134 public void validateSDNCResponse(Execution execution) {
135 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
136 utils.log("DEBUG"," ***** validateSDNCResponse ***** ", isDebugEnabled)
139 WorkflowException workflowException = execution.getVariable("WorkflowException")
141 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
142 String response = execution.getVariable("sdncAdapterResponse")
144 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
145 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
147 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
148 utils.log("DEBUG", "SDNC Adapter for service-instance delete for rollback successful. response", isDebugEnabled)
150 execution.setVariable("rolledBack", false)
151 execution.setVariable("rollbackError", "Error Response from SDNC Adapter for service-instance delete for rollback")
152 utils.log("DEBUG","Error Response from SDNC Adapter for service-instance delete for rollback", isDebugEnabled)
153 throw new BpmnError("MSOWorkflowException")
155 } catch (BpmnError e) {
157 } catch (Exception ex){
158 msg = "Exception in Create ServiceInstance Rollback validateSDNCResponse " + ex.getMessage()
159 utils.log("DEBUG", msg, isDebugEnabled)
160 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
162 utils.log("DEBUG"," ***** Exit validateSDNCResponse ***** ", isDebugEnabled)
165 public void postProcessRequest(Execution execution) {
166 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
167 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
170 execution.setVariable("rollbackData", null)
171 String serviceInstanceId = execution.getVariable("serviceInstanceId")
172 boolean rollbackAAI = execution.getVariable("rollbackAAI")
173 boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
174 if (rollbackAAI == true || rollbackSDNC == true)
176 execution.setVariable("rolledBack", true)
178 if (rollbackAAI == true)
180 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
181 if(succInAAI != true){
182 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
183 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
184 utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)
187 utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
189 } catch (BpmnError e) {
190 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
191 utils.log("DEBUG", msg, isDebugEnabled)
192 } catch (Exception ex) {
193 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
194 utils.log("DEBUG", msg, isDebugEnabled)
199 public void processRollbackException(Execution execution){
200 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
201 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
203 utils.log("DEBUG", "Caught an Exception in DoCreateServiceInstanceRollback", isDebugEnabled)
204 execution.setVariable("rollbackData", null)
205 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
206 execution.setVariable("WorkflowException", null)
209 utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
211 utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
214 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
217 public void processRollbackJavaException(Execution execution){
218 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
219 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
221 execution.setVariable("rollbackData", null)
222 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
223 utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
226 utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
228 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)