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("addResourceList", delResourceList)
81 execution.setVariable("delResourceList_o", delResourceList)
82 execution.setVariable("delResourceList", addResourceList)
85 def rollbackData = execution.getVariable("rollbackData")
86 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
88 if (rollbackData != null) {
89 if (rollbackData.hasType("SERVICEINSTANCE")) {
91 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
92 execution.setVariable("serviceInstanceId", serviceInstanceId)
94 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
95 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
97 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
98 execution.setVariable("globalSubscriberId", globalSubscriberId)
100 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
101 if ("true".equals(rollbackAAI))
103 execution.setVariable("rollbackAAI",true)
106 def rollbackAdded = rollbackData.get("SERVICEINSTANCE", "rollbackAdded")
107 if ("true".equals(rollbackAdded))
109 execution.setVariable("rollbackAdded", true)
112 def rollbackDeleted = rollbackData.get("SERVICEINSTANCE", "rollbackDeleted")
113 if ("true".equals(rollbackDeleted))
115 execution.setVariable("rollbackDeleted", true)
118 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true
119 && execution.getVariable("rollbackDeleted") != true)
121 execution.setVariable("skipRollback", true)
126 execution.setVariable("skipRollback", true)
130 execution.setVariable("skipRollback", true)
132 if (execution.getVariable("disableRollback").equals("true" ))
134 execution.setVariable("skipRollback", true)
137 } catch (BpmnError e) {
139 } catch (Exception ex){
140 msg = "Exception in Update ServiceInstance Rollback preProcessRequest " + ex.getMessage()
141 utils.log("DEBUG", msg, isDebugEnabled)
142 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
144 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
147 public void postProcessRequest(DelegateExecution execution) {
148 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
149 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
152 execution.setVariable("rollbackData", null)
153 String serviceInstanceId = execution.getVariable("serviceInstanceId")
154 boolean rollbackAAI = execution.getVariable("rollbackAAI")
155 boolean rollbackAdded = execution.getVariable("rollbackAdded")
156 boolean rollbackDeleted = execution.getVariable("rollbackDeleted")
158 List addResourceList = execution.getVariable("addResourceList_o")
159 List delResourceList = execution.getVariable("delResourceList_o")
160 execution.setVariable("addResourceList", addResourceList)
161 execution.setVariable("delResourceList", delResourceList)
163 if (rollbackAAI || rollbackAdded || rollbackDeleted)
165 execution.setVariable("rolledBack", true)
169 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
171 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
172 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
173 utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)
176 utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
178 } catch (BpmnError e) {
179 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
180 utils.log("DEBUG", msg, isDebugEnabled)
181 } catch (Exception ex) {
182 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
183 utils.log("DEBUG", msg, isDebugEnabled)
188 public void preProcessForAddResource(DelegateExecution execution) {
189 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
192 public void postProcessForAddResource(DelegateExecution execution) {
193 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
197 public void preProcessForDeleteResource(DelegateExecution execution) {
198 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
202 public void postProcessForDeleteResource(DelegateExecution execution) {
203 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
207 public void preProcessAAIGET2(DelegateExecution execution) {
208 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
211 public void postProcessAAIGET(DelegateExecution execution) {
212 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
213 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
217 String serviceInstanceName = execution.getVariable("serviceInstanceName")
218 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
220 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled)
221 WorkflowException workflowException = execution.getVariable("WorkflowException")
222 utils.logAudit("workflowException: " + workflowException)
223 if(workflowException != null){
224 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
228 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
229 utils.log("INFO", msg, isDebugEnabled)
230 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
235 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
237 String aaiService = execution.getVariable("GENGS_service")
238 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {
239 execution.setVariable("serviceInstanceVersion_n", utils.getNodeText1(aaiService, "resource-version"))
240 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
244 } catch (BpmnError e) {
246 } catch (Exception ex) {
247 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET " + ex.getMessage()
248 utils.log("INFO", msg, isDebugEnabled)
249 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
251 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
254 public void preProcessAAIPUT(DelegateExecution execution) {
255 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
256 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
257 utils.log("INFO","Entered " + method, isDebugEnabled)
259 utils.log("INFO"," ***** preProcessAAIPUT *****", isDebugEnabled)
261 String modelUuid = execution.getVariable("model-version-id-original")
262 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n")
263 execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
265 String serviceInstanceData =
266 """<service-instance xmlns=\"${namespace}\">
267 <resource-version">${serviceInstanceVersion}</resource-version>
268 </service-instance>""".trim()
270 execution.setVariable("serviceInstanceData", serviceInstanceData)
271 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)
272 utils.logAudit(serviceInstanceData)
273 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
274 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
276 utils.log("INFO", "Exited " + method, isDebugEnabled)
279 public void postProcessAAIPUT(DelegateExecution execution) {
280 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
281 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
284 String serviceInstanceId = execution.getVariable("serviceInstanceId")
285 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
287 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
288 WorkflowException workflowException = execution.getVariable("WorkflowException")
289 utils.logAudit("workflowException: " + workflowException)
290 if(workflowException != null){
291 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
299 } catch (BpmnError e) {
301 } catch (Exception ex) {
302 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
303 utils.log("INFO", msg, isDebugEnabled)
304 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
306 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
309 public void processRollbackException(DelegateExecution execution){
310 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
311 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
313 utils.log("DEBUG", "Caught an Exception in DoCreateServiceInstanceRollback", isDebugEnabled)
314 execution.setVariable("rollbackData", null)
315 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Update Rollback")
316 execution.setVariable("WorkflowException", null)
319 utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
321 utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
324 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
327 public void processRollbackJavaException(DelegateExecution execution){
328 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
329 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
331 execution.setVariable("rollbackData", null)
332 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Update Rollback")
333 utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
336 utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
338 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)