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
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
34 import org.onap.so.bpmn.common.scripts.AaiUtil;
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 preProcessAAIPUT(DelegateExecution execution) {
195 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
196 msoLogger.info("Entered " + method)
198 msoLogger.trace("preProcessAAIPUT ")
200 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n")
201 // execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
203 //requestDetails.modelInfo.for AAI PUT servieInstanceData
204 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
205 String serviceInstanceName = execution.getVariable("serviceInstanceName")
206 String serviceInstanceId = execution.getVariable("serviceInstanceId")
207 //aai serviceType and Role can be setted as fixed value now.
208 String aaiServiceType = "E2E Service"
209 String aaiServiceRole = "E2E Service"
210 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
211 String modelUuid = execution.getVariable("model-version-id-original")
214 AaiUtil aaiUriUtil = new AaiUtil(this)
215 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled)
216 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
217 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)
218 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
219 utils.log("INFO","namespace: " + namespace, isDebugEnabled)
221 String serviceInstanceData =
222 """<service-instance xmlns=\"${namespace}\">
223 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
224 <service-instance-name>${MsoUtils.xmlEscape(serviceInstanceName)}</service-instance-name>
225 <service-type>${MsoUtils.xmlEscape(aaiServiceType)}</service-type>
226 <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role>
227 <resource-version>${MsoUtils.xmlEscape(serviceInstanceVersion)}</resource-version>
228 <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id>
229 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
230 </service-instance>""".trim()
232 execution.setVariable("serviceInstanceData", serviceInstanceData)
233 msoLogger.info("serviceInstanceData: " + serviceInstanceData)
234 msoLogger.debug(serviceInstanceData)
235 msoLogger.info(" aai_uri " + aai_uri + " namespace:" + namespace)
236 msoLogger.info(" 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData)
238 msoLogger.info("Exited " + method)
241 public void postProcessAAIPUT(DelegateExecution execution) {
242 msoLogger.trace("postProcessAAIPUT ")
245 String serviceInstanceId = execution.getVariable("serviceInstanceId")
246 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
248 msoLogger.info("Error putting Service-instance in AAI", + serviceInstanceId)
249 WorkflowException workflowException = execution.getVariable("WorkflowException")
250 msoLogger.debug("workflowException: " + workflowException)
251 if(workflowException != null){
252 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
260 } catch (BpmnError e) {
262 } catch (Exception ex) {
263 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
265 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
267 msoLogger.trace("Exit postProcessAAIPUT ")
270 public void processRollbackException(DelegateExecution execution){
271 msoLogger.trace("processRollbackException ")
273 msoLogger.debug("Caught an Exception in DoUpdateE2EServiceInstanceRollback")
274 execution.setVariable("rollbackData", null)
275 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Update Rollback")
276 execution.setVariable("WorkflowException", null)
279 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
281 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
284 msoLogger.debug(" Exit processRollbackException")
287 public void processRollbackJavaException(DelegateExecution execution){
288 msoLogger.trace("processRollbackJavaException ")
290 execution.setVariable("rollbackData", null)
291 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Update Rollback")
292 msoLogger.debug("Caught Exception in processRollbackJavaException")
295 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
297 msoLogger.trace("Exit processRollbackJavaException ")