2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.delegate.DelegateExecution
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>DoUpdateE2EServiceInstanceRollback.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 DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
66 String Prefix="DUPDSIRB_"
68 public void preProcessRequest(DelegateExecution 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("rollbackAdded",false)
75 execution.setVariable("rollbackDeleted",false)
77 List addResourceList = execution.getVariable("addResourceList")
78 List delResourceList = execution.getVariable("delResourceList")
79 execution.setVariable("addResourceList_o", addResourceList)
80 execution.setVariable("delResourceList_o", delResourceList)
81 //exchange add and delete resource list
82 execution.setVariable("addResourceList", delResourceList)
83 execution.setVariable("delResourceList", addResourceList)
86 def rollbackData = execution.getVariable("rollbackData")
87 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
89 if (rollbackData != null) {
90 if (rollbackData.hasType("SERVICEINSTANCE")) {
92 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
93 execution.setVariable("serviceInstanceId", serviceInstanceId)
95 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
96 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
98 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
99 execution.setVariable("globalSubscriberId", globalSubscriberId)
101 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
102 if ("true".equals(rollbackAAI))
104 execution.setVariable("rollbackAAI",true)
107 def rollbackAdded = rollbackData.get("SERVICEINSTANCE", "rollbackAdded")
108 if ("true".equals(rollbackAdded))
110 execution.setVariable("rollbackAdded", true)
113 def rollbackDeleted = rollbackData.get("SERVICEINSTANCE", "rollbackDeleted")
114 if ("true".equals(rollbackDeleted))
116 execution.setVariable("rollbackDeleted", true)
119 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true
120 && execution.getVariable("rollbackDeleted") != true)
122 execution.setVariable("skipRollback", true)
127 execution.setVariable("skipRollback", true)
131 execution.setVariable("skipRollback", true)
133 if (execution.getVariable("disableRollback").equals("true" ))
135 execution.setVariable("skipRollback", true)
138 } catch (BpmnError e) {
140 } catch (Exception ex){
141 msg = "Exception in Update ServiceInstance Rollback preProcessRequest " + ex.getMessage()
142 utils.log("DEBUG", msg, isDebugEnabled)
143 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
145 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
148 public void postProcessRequest(DelegateExecution execution) {
149 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
150 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
153 execution.setVariable("rollbackData", null)
154 String serviceInstanceId = execution.getVariable("serviceInstanceId")
155 boolean rollbackAAI = execution.getVariable("rollbackAAI")
156 boolean rollbackAdded = execution.getVariable("rollbackAdded")
157 boolean rollbackDeleted = execution.getVariable("rollbackDeleted")
159 List addResourceList = execution.getVariable("addResourceList_o")
160 List delResourceList = execution.getVariable("delResourceList_o")
161 execution.setVariable("addResourceList", addResourceList)
162 execution.setVariable("delResourceList", delResourceList)
164 if (rollbackAAI || rollbackAdded || rollbackDeleted)
166 execution.setVariable("rolledBack", true)
170 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
172 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
173 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
174 utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)
177 utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
179 } catch (BpmnError e) {
180 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
181 utils.log("DEBUG", msg, isDebugEnabled)
182 } catch (Exception ex) {
183 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
184 utils.log("DEBUG", msg, isDebugEnabled)
189 public void preProcessForAddResource(DelegateExecution execution) {
190 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
193 public void postProcessForAddResource(DelegateExecution execution) {
194 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
198 public void preProcessForDeleteResource(DelegateExecution execution) {
199 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
203 public void postProcessForDeleteResource(DelegateExecution execution) {
204 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
208 public void preProcessAAIGET(DelegateExecution execution) {
209 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
212 public void postProcessAAIGET(DelegateExecution execution) {
213 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
214 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
218 String serviceInstanceName = execution.getVariable("serviceInstanceName")
219 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
221 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled)
222 WorkflowException workflowException = execution.getVariable("WorkflowException")
223 utils.logAudit("workflowException: " + workflowException)
224 if(workflowException != null){
225 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
229 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
230 utils.log("INFO", msg, isDebugEnabled)
231 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
236 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
238 String aaiService = execution.getVariable("GENGS_service")
239 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {
240 execution.setVariable("serviceInstanceVersion_n", utils.getNodeText1(aaiService, "resource-version"))
241 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
245 } catch (BpmnError e) {
247 } catch (Exception ex) {
248 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET " + ex.getMessage()
249 utils.log("INFO", msg, isDebugEnabled)
250 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
252 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
255 public void preProcessAAIPUT(DelegateExecution execution) {
256 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
257 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
258 utils.log("INFO","Entered " + method, isDebugEnabled)
260 utils.log("INFO"," ***** preProcessAAIPUT *****", isDebugEnabled)
262 String modelUuid = execution.getVariable("model-version-id-original")
263 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n")
264 execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
266 String serviceInstanceData =
267 """<service-instance xmlns=\"${namespace}\">
268 <resource-version">${modelUuid}</resource-version>
269 </service-instance>""".trim()
271 execution.setVariable("serviceInstanceData", serviceInstanceData)
272 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)
273 utils.logAudit(serviceInstanceData)
274 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
275 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
277 utils.log("INFO", "Exited " + method, isDebugEnabled)
280 public void postProcessAAIPUT(DelegateExecution execution) {
281 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
282 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
285 String serviceInstanceId = execution.getVariable("serviceInstanceId")
286 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
288 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
289 WorkflowException workflowException = execution.getVariable("WorkflowException")
290 utils.logAudit("workflowException: " + workflowException)
291 if(workflowException != null){
292 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
300 } catch (BpmnError e) {
302 } catch (Exception ex) {
303 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
304 utils.log("INFO", msg, isDebugEnabled)
305 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
307 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
310 public void processRollbackException(DelegateExecution execution){
311 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
312 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
314 utils.log("DEBUG", "Caught an Exception in DoUpdateE2EServiceInstanceRollback", isDebugEnabled)
315 execution.setVariable("rollbackData", null)
316 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Update Rollback")
317 execution.setVariable("WorkflowException", null)
320 utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
322 utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
325 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
328 public void processRollbackJavaException(DelegateExecution execution){
329 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
330 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
332 execution.setVariable("rollbackData", null)
333 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Update Rollback")
334 utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
337 utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
339 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)