2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
24 import static org.apache.commons.lang3.StringUtils.*;
\r
25 import groovy.xml.XmlUtil
\r
26 import groovy.json.*
\r
28 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
29 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
30 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
\r
31 import org.openecomp.mso.bpmn.core.RollbackData
\r
32 import org.openecomp.mso.bpmn.core.WorkflowException
\r
33 import org.openecomp.mso.rest.APIResponse;
\r
34 import org.openecomp.mso.rest.RESTClient
\r
35 import org.openecomp.mso.rest.RESTConfig
\r
37 import java.util.UUID;
\r
39 import org.camunda.bpm.engine.delegate.BpmnError
\r
40 import org.camunda.bpm.engine.runtime.Execution
\r
41 import org.json.JSONObject;
\r
42 import org.apache.commons.lang3.*
\r
43 import org.apache.commons.codec.binary.Base64;
\r
44 import org.springframework.web.util.UriUtils;
\r
46 * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
\r
49 * @param - msoRequestId
\r
50 * @param - rollbackData with
\r
52 * subscriptionServiceType
\r
57 * sdncRollbackRequest
\r
61 * @param - rollbackError
\r
62 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
\r
65 public class DoCreateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
\r
67 String Prefix="DCRESIRB_"
\r
69 public void preProcessRequest(Execution execution) {
\r
70 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
71 execution.setVariable("prefix",Prefix)
\r
73 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
\r
74 execution.setVariable("rollbackAAI",false)
\r
75 execution.setVariable("rollbackSDNC",false)
\r
78 def rollbackData = execution.getVariable("rollbackData")
\r
79 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
\r
81 if (rollbackData != null) {
\r
82 if (rollbackData.hasType("SERVICEINSTANCE")) {
\r
84 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
\r
85 execution.setVariable("serviceInstanceId", serviceInstanceId)
\r
87 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
\r
88 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
90 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
\r
91 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
93 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
\r
94 if ("true".equals(rollbackAAI))
\r
96 execution.setVariable("rollbackAAI",true)
\r
99 def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
\r
100 if ("true".equals(rollbackSDNC))
\r
102 execution.setVariable("rollbackSDNC", true)
\r
105 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
\r
107 execution.setVariable("skipRollback", true)
\r
110 def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
\r
111 execution.setVariable("sdncDelete", sdncDelete)
\r
112 def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
\r
113 execution.setVariable("sdncDeactivate", sdncDeactivate)
\r
114 utils.log("DEBUG","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)
\r
115 utils.log("DEBUG","sdncDelete:\n" + sdncDelete, isDebugEnabled)
\r
118 execution.setVariable("skipRollback", true)
\r
122 execution.setVariable("skipRollback", true)
\r
124 if (execution.getVariable("disableRollback").equals("true" ))
\r
126 execution.setVariable("skipRollback", true)
\r
129 } catch (BpmnError e) {
\r
131 } catch (Exception ex){
\r
132 msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
\r
133 utils.log("DEBUG", msg, isDebugEnabled)
\r
134 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
136 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
139 public void validateSDNCResponse(Execution execution, String response, String method) {
\r
140 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
141 utils.log("DEBUG"," ***** validateSDNCResponse ***** ", isDebugEnabled)
\r
144 WorkflowException workflowException = execution.getVariable("WorkflowException")
\r
145 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
\r
146 utils.log("DEBUG", "SDNCResponse: " + response, isDebugEnabled)
\r
147 utils.log("DEBUG", "workflowException: " + workflowException, isDebugEnabled)
\r
149 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
\r
150 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
\r
152 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
\r
153 msg = "SDNC Adapter service-instance rollback successful for " + method
\r
154 utils.log("DEBUG", msg, isDebugEnabled)
\r
156 execution.setVariable("rolledBack", false)
\r
157 msg = "Error Response from SDNC Adapter service-instance rollback for " + method
\r
158 execution.setVariable("rollbackError", msg)
\r
159 utils.log("DEBUG", msg, isDebugEnabled)
\r
160 throw new BpmnError("MSOWorkflowException")
\r
162 } catch (BpmnError e) {
\r
164 } catch (Exception ex){
\r
165 msg = "Exception in Create ServiceInstance rollback for " + method + " Exception:" + ex.getMessage()
\r
166 utils.log("DEBUG", msg, isDebugEnabled)
\r
167 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
169 utils.log("DEBUG"," ***** Exit validateSDNCResponse ***** ", isDebugEnabled)
\r
172 public void postProcessRequest(Execution execution) {
\r
173 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
174 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
\r
177 execution.setVariable("rollbackData", null)
\r
178 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
179 boolean rollbackAAI = execution.getVariable("rollbackAAI")
\r
180 boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
\r
181 if (rollbackAAI || rollbackSDNC)
\r
183 execution.setVariable("rolledBack", true)
\r
187 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
\r
189 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
\r
190 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
\r
191 utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)
\r
194 utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
\r
196 } catch (BpmnError e) {
\r
197 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
\r
198 utils.log("DEBUG", msg, isDebugEnabled)
\r
199 } catch (Exception ex) {
\r
200 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
\r
201 utils.log("DEBUG", msg, isDebugEnabled)
\r
206 public void processRollbackException(Execution execution){
\r
207 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
208 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
\r
210 utils.log("DEBUG", "Caught an Exception in DoCreateServiceInstanceRollback", isDebugEnabled)
\r
211 execution.setVariable("rollbackData", null)
\r
212 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
\r
213 execution.setVariable("WorkflowException", null)
\r
215 }catch(BpmnError b){
\r
216 utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
\r
217 }catch(Exception e){
\r
218 utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
\r
221 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
\r
224 public void processRollbackJavaException(Execution execution){
\r
225 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
226 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
\r
228 execution.setVariable("rollbackData", null)
\r
229 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
\r
230 utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
\r
232 }catch(Exception e){
\r
233 utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
\r
235 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)
\r