2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
23 import static org.apache.commons.lang3.StringUtils.*;
\r
24 import groovy.xml.XmlUtil
\r
25 import groovy.json.*
\r
27 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
28 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
\r
30 import org.openecomp.mso.bpmn.core.RollbackData
\r
31 import org.openecomp.mso.bpmn.core.WorkflowException
\r
32 import org.openecomp.mso.rest.APIResponse;
\r
33 import org.openecomp.mso.rest.RESTClient
\r
34 import org.openecomp.mso.rest.RESTConfig
\r
36 import java.util.UUID;
\r
38 import org.camunda.bpm.engine.delegate.BpmnError
\r
39 import org.camunda.bpm.engine.runtime.Execution
\r
40 import org.json.JSONObject;
\r
41 import org.apache.commons.lang3.*
\r
42 import org.apache.commons.codec.binary.Base64;
\r
43 import org.springframework.web.util.UriUtils;
\r
45 * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
\r
48 * @param - msoRequestId
\r
49 * @param - rollbackData with
\r
51 * subscriptionServiceType
\r
56 * sdncRollbackRequest
\r
60 * @param - rollbackError
\r
61 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
\r
64 public class DoCreateServiceInstanceRollback extends AbstractServiceTaskProcessor{
\r
66 String Prefix="DCRESIRB_"
\r
68 public void preProcessRequest(Execution execution) {
\r
69 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
70 execution.setVariable("prefix",Prefix)
\r
72 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
\r
73 execution.setVariable("rollbackAAI",false)
\r
74 execution.setVariable("rollbackSDNC",false)
\r
77 def rollbackData = execution.getVariable("rollbackData")
\r
78 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
\r
80 if (rollbackData != null) {
\r
81 if (rollbackData.hasType("SERVICEINSTANCE")) {
\r
83 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
\r
84 execution.setVariable("serviceInstanceId", serviceInstanceId)
\r
86 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
\r
87 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
89 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
\r
90 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
92 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
\r
93 if ("true".equals(rollbackAAI))
\r
95 execution.setVariable("rollbackAAI",true)
\r
98 def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
\r
99 if ("true".equals(rollbackSDNC))
\r
101 execution.setVariable("rollbackSDNC", true)
\r
104 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
\r
106 execution.setVariable("skipRollback", true)
\r
109 def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
\r
110 execution.setVariable("sdncDelete", sdncDelete)
\r
111 def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
\r
112 execution.setVariable("sdncDeactivate", sdncDeactivate)
\r
113 utils.log("DEBUG","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)
\r
114 utils.log("DEBUG","sdncDelete:\n" + sdncDelete, isDebugEnabled)
\r
117 execution.setVariable("skipRollback", true)
\r
121 execution.setVariable("skipRollback", true)
\r
123 if (execution.getVariable("disableRollback").equals("true" ))
\r
125 execution.setVariable("skipRollback", true)
\r
128 } catch (BpmnError e) {
\r
130 } catch (Exception ex){
\r
131 msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
\r
132 utils.log("DEBUG", msg, isDebugEnabled)
\r
133 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
135 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
138 public void validateSDNCResponse(Execution execution, String response, String method) {
\r
139 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
140 utils.log("DEBUG"," ***** validateSDNCResponse ***** ", isDebugEnabled)
\r
143 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
144 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
\r
145 utils.log("DEBUG", "SDNCResponse: " + response, isDebugEnabled)
\r
146 utils.log("DEBUG", "workflowException: " + workflowException, isDebugEnabled)
\r
148 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
\r
149 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
\r
151 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
\r
152 msg = "SDNC Adapter service-instance rollback successful for " + method
\r
153 utils.log("DEBUG", msg, isDebugEnabled)
\r
155 execution.setVariable("rolledBack", false)
\r
156 msg = "Error Response from SDNC Adapter service-instance rollback for " + method
\r
157 execution.setVariable("rollbackError", msg)
\r
158 utils.log("DEBUG", msg, isDebugEnabled)
\r
159 throw new BpmnError("MSOWorkflowException")
\r
161 } catch (BpmnError e) {
\r
163 } catch (Exception ex){
\r
164 msg = "Exception in Create ServiceInstance rollback for " + method + " Exception:" + ex.getMessage()
\r
165 utils.log("DEBUG", msg, isDebugEnabled)
\r
166 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
168 utils.log("DEBUG"," ***** Exit validateSDNCResponse ***** ", isDebugEnabled)
\r
171 public void postProcessRequest(Execution execution) {
\r
172 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
173 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
\r
176 execution.setVariable("rollbackData", null)
\r
177 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
178 boolean rollbackAAI = execution.getVariable("rollbackAAI")
\r
179 boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
\r
180 if (rollbackAAI == true || rollbackSDNC == true)
\r
182 execution.setVariable("rolledBack", true)
\r
184 if (rollbackAAI == true)
\r
186 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
\r
187 if(succInAAI != true){
\r
188 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
\r
189 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
\r
190 utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)
\r
193 utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
\r
195 } catch (BpmnError e) {
\r
196 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
\r
197 utils.log("DEBUG", msg, isDebugEnabled)
\r
198 } catch (Exception ex) {
\r
199 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
\r
200 utils.log("DEBUG", msg, isDebugEnabled)
\r
205 public void processRollbackException(Execution execution){
\r
206 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
207 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
\r
209 utils.log("DEBUG", "Caught an Exception in DoCreateServiceInstanceRollback", isDebugEnabled)
\r
210 execution.setVariable("rollbackData", null)
\r
211 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
\r
212 execution.setVariable("WorkflowException", null)
\r
214 }catch(BpmnError b){
\r
215 utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
\r
216 }catch(Exception e){
\r
217 utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
\r
220 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
\r
223 public void processRollbackJavaException(Execution execution){
\r
224 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
225 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
\r
227 execution.setVariable("rollbackData", null)
\r
228 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
\r
229 utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
\r
231 }catch(Exception e){
\r
232 utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
\r
234 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)
\r