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.onap.so.bpmn.infrastructure.scripts
23 import static org.apache.commons.lang3.StringUtils.*;
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.core.WorkflowException
31 import org.onap.so.logger.MsoLogger
37 * This groovy class supports the <class>DoUpdateE2EServiceInstanceRollback.bpmn</class> process.
40 * @param - msoRequestId
41 * @param - rollbackData with
43 * subscriptionServiceType
52 * @param - rollbackError
53 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
56 public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
57 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateE2EServiceInstanceRollback.class);
60 String Prefix="DUPDSIRB_"
61 ExceptionUtil exceptionUtil = new ExceptionUtil()
63 public void preProcessRequest(DelegateExecution execution) {
64 execution.setVariable("prefix",Prefix)
66 msoLogger.trace("preProcessRequest ")
67 execution.setVariable("rollbackAAI",false)
68 execution.setVariable("rollbackAdded",false)
69 execution.setVariable("rollbackDeleted",false)
71 List addResourceList = execution.getVariable("addResourceList")
72 List delResourceList = execution.getVariable("delResourceList")
73 execution.setVariable("addResourceList_o", addResourceList)
74 execution.setVariable("delResourceList_o", delResourceList)
75 //exchange add and delete resource list
76 execution.setVariable("addResourceList", delResourceList)
77 execution.setVariable("delResourceList", addResourceList)
80 def rollbackData = execution.getVariable("rollbackData")
81 msoLogger.debug("RollbackData:" + rollbackData)
83 if (rollbackData != null) {
84 if (rollbackData.hasType("SERVICEINSTANCE")) {
86 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
87 execution.setVariable("serviceInstanceId", serviceInstanceId)
89 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
90 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
92 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
93 execution.setVariable("globalSubscriberId", globalSubscriberId)
95 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
96 if ("true".equals(rollbackAAI))
98 execution.setVariable("rollbackAAI",true)
101 def rollbackAdded = rollbackData.get("SERVICEINSTANCE", "rollbackAdded")
102 if ("true".equals(rollbackAdded))
104 execution.setVariable("rollbackAdded", true)
107 def rollbackDeleted = rollbackData.get("SERVICEINSTANCE", "rollbackDeleted")
108 if ("true".equals(rollbackDeleted))
110 execution.setVariable("rollbackDeleted", true)
113 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true
114 && execution.getVariable("rollbackDeleted") != true)
116 execution.setVariable("skipRollback", true)
121 execution.setVariable("skipRollback", true)
125 execution.setVariable("skipRollback", true)
127 if (execution.getVariable("disableRollback").equals("true" ))
129 execution.setVariable("skipRollback", true)
132 } catch (BpmnError e) {
134 } catch (Exception ex){
135 msg = "Exception in Update ServiceInstance Rollback preProcessRequest " + ex.getMessage()
137 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
139 msoLogger.trace("Exit preProcessRequest ")
142 public void postProcessRequest(DelegateExecution execution) {
143 msoLogger.trace("postProcessRequest ")
146 execution.setVariable("rollbackData", null)
147 String serviceInstanceId = execution.getVariable("serviceInstanceId")
148 boolean rollbackAAI = execution.getVariable("rollbackAAI")
149 boolean rollbackAdded = execution.getVariable("rollbackAdded")
150 boolean rollbackDeleted = execution.getVariable("rollbackDeleted")
152 List addResourceList = execution.getVariable("addResourceList_o")
153 List delResourceList = execution.getVariable("delResourceList_o")
154 execution.setVariable("addResourceList", addResourceList)
155 execution.setVariable("delResourceList", delResourceList)
157 if (rollbackAAI || rollbackAdded || rollbackDeleted)
159 execution.setVariable("rolledBack", true)
163 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
165 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
166 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
167 msoLogger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
170 msoLogger.trace("Exit postProcessRequest ")
172 } catch (BpmnError e) {
173 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
175 } catch (Exception ex) {
176 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
182 public void preProcessForAddResource(DelegateExecution execution) {
185 public void postProcessForAddResource(DelegateExecution execution) {
188 public void preProcessForDeleteResource(DelegateExecution execution) {
191 public void postProcessForDeleteResource(DelegateExecution execution) {
194 public void preProcessAAIGET(DelegateExecution execution) {
197 public void postProcessAAIGET(DelegateExecution execution) {
198 msoLogger.trace("postProcessAAIGET ")
202 String serviceInstanceName = execution.getVariable("serviceInstanceName")
203 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
205 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName)
206 WorkflowException workflowException = execution.getVariable("WorkflowException")
207 msoLogger.debug("workflowException: " + workflowException)
208 if(workflowException != null){
209 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
213 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
215 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
220 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
222 String aaiService = execution.getVariable("GENGS_service")
223 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {
224 execution.setVariable("serviceInstanceVersion_n", utils.getNodeText(aaiService, "resource-version"))
225 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
229 } catch (BpmnError e) {
231 } catch (Exception ex) {
232 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET " + ex.getMessage()
234 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
236 msoLogger.trace("Exit postProcessAAIGET ")
239 public void preProcessAAIPUT(DelegateExecution execution) {
240 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
241 msoLogger.info("Entered " + method)
243 msoLogger.trace("preProcessAAIPUT ")
245 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n")
246 // execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
248 //requestDetails.modelInfo.for AAI PUT servieInstanceData
249 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
250 String serviceInstanceName = execution.getVariable("serviceInstanceName")
251 String serviceInstanceId = execution.getVariable("serviceInstanceId")
252 //aai serviceType and Role can be setted as fixed value now.
253 String aaiServiceType = "E2E Service"
254 String aaiServiceRole = "E2E Service"
255 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
256 String modelUuid = execution.getVariable("model-version-id-original")
259 AaiUtil aaiUriUtil = new AaiUtil(this)
260 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled)
261 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
262 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)
263 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
264 utils.log("INFO","namespace: " + namespace, isDebugEnabled)
266 String serviceInstanceData =
267 """<service-instance xmlns=\"${namespace}\">
268 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
269 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
270 <service-type>${MsoUtils.xmlEscape(aaiServiceType)}</service-type>
271 <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role>
272 <resource-version>${MsoUtils.xmlEscape(serviceInstanceVersion)}</resource-version>
273 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
274 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
275 </service-instance>""".trim()
277 execution.setVariable("serviceInstanceData", serviceInstanceData)
278 msoLogger.info("serviceInstanceData: " + serviceInstanceData)
279 msoLogger.debug(serviceInstanceData)
280 msoLogger.info(" aai_uri " + aai_uri + " namespace:" + namespace)
281 msoLogger.info(" 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData)
283 msoLogger.info("Exited " + method)
286 public void postProcessAAIPUT(DelegateExecution execution) {
287 msoLogger.trace("postProcessAAIPUT ")
290 String serviceInstanceId = execution.getVariable("serviceInstanceId")
291 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
293 msoLogger.info("Error putting Service-instance in AAI", + serviceInstanceId)
294 WorkflowException workflowException = execution.getVariable("WorkflowException")
295 msoLogger.debug("workflowException: " + workflowException)
296 if(workflowException != null){
297 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
305 } catch (BpmnError e) {
307 } catch (Exception ex) {
308 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
310 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
312 msoLogger.trace("Exit postProcessAAIPUT ")
315 public void processRollbackException(DelegateExecution execution){
316 msoLogger.trace("processRollbackException ")
318 msoLogger.debug("Caught an Exception in DoUpdateE2EServiceInstanceRollback")
319 execution.setVariable("rollbackData", null)
320 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Update Rollback")
321 execution.setVariable("WorkflowException", null)
324 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
326 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
329 msoLogger.debug(" Exit processRollbackException")
332 public void processRollbackJavaException(DelegateExecution execution){
333 msoLogger.trace("processRollbackJavaException ")
335 execution.setVariable("rollbackData", null)
336 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Update Rollback")
337 msoLogger.debug("Caught Exception in processRollbackJavaException")
340 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
342 msoLogger.trace("Exit processRollbackJavaException ")