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.AaiUtil
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.MsoUtils
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.client.aai.AAIObjectType
34 import org.onap.so.client.aai.AAIResourcesClient
35 import org.onap.so.client.aai.entities.AAIResultWrapper
36 import org.onap.so.client.aai.entities.uri.AAIResourceUri
37 import org.onap.so.client.aai.entities.uri.AAIUriFactory
38 import org.onap.so.logger.MsoLogger
39 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
41 import org.onap.so.bpmn.common.scripts.AaiUtil;
44 * This groovy class supports the <class>DoUpdateE2EServiceInstanceRollback.bpmn</class> process.
47 * @param - msoRequestId
48 * @param - rollbackData with
50 * subscriptionServiceType
59 * @param - rollbackError
60 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
63 public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
64 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateE2EServiceInstanceRollback.class);
67 String Prefix="DUPDSIRB_"
68 ExceptionUtil exceptionUtil = new ExceptionUtil()
70 public void preProcessRequest(DelegateExecution execution) {
71 execution.setVariable("prefix",Prefix)
73 msoLogger.trace("preProcessRequest ")
74 execution.setVariable("rollbackAAI",false)
75 execution.setVariable("rollbackAdded",false)
76 execution.setVariable("rollbackDeleted",false)
78 List addResourceList = execution.getVariable("addResourceList")
79 List delResourceList = execution.getVariable("delResourceList")
80 execution.setVariable("addResourceList_o", addResourceList)
81 execution.setVariable("delResourceList_o", delResourceList)
82 //exchange add and delete resource list
83 execution.setVariable("addResourceList", delResourceList)
84 execution.setVariable("delResourceList", addResourceList)
87 def rollbackData = execution.getVariable("rollbackData")
88 msoLogger.debug("RollbackData:" + rollbackData)
90 if (rollbackData != null) {
91 if (rollbackData.hasType("SERVICEINSTANCE")) {
93 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
94 execution.setVariable("serviceInstanceId", serviceInstanceId)
96 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
97 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
99 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
100 execution.setVariable("globalSubscriberId", globalSubscriberId)
102 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
103 if ("true".equals(rollbackAAI))
105 execution.setVariable("rollbackAAI",true)
108 def rollbackAdded = rollbackData.get("SERVICEINSTANCE", "rollbackAdded")
109 if ("true".equals(rollbackAdded))
111 execution.setVariable("rollbackAdded", true)
114 def rollbackDeleted = rollbackData.get("SERVICEINSTANCE", "rollbackDeleted")
115 if ("true".equals(rollbackDeleted))
117 execution.setVariable("rollbackDeleted", true)
120 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true
121 && execution.getVariable("rollbackDeleted") != true)
123 execution.setVariable("skipRollback", true)
128 execution.setVariable("skipRollback", true)
132 execution.setVariable("skipRollback", true)
134 if (execution.getVariable("disableRollback").equals("true" ))
136 execution.setVariable("skipRollback", true)
139 } catch (BpmnError e) {
141 } catch (Exception ex){
142 msg = "Exception in Update ServiceInstance Rollback preProcessRequest " + ex.getMessage()
144 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
146 msoLogger.trace("Exit preProcessRequest ")
149 public void postProcessRequest(DelegateExecution execution) {
150 msoLogger.trace("postProcessRequest ")
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 msoLogger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
177 msoLogger.trace("Exit postProcessRequest ")
179 } catch (BpmnError e) {
180 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
182 } catch (Exception ex) {
183 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
189 public void preProcessForAddResource(DelegateExecution execution) {
192 public void postProcessForAddResource(DelegateExecution execution) {
195 public void preProcessForDeleteResource(DelegateExecution execution) {
198 public void postProcessForDeleteResource(DelegateExecution execution) {
201 public void preProcessAAIPUT(DelegateExecution execution) {
202 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
203 msoLogger.info("Entered " + method)
205 msoLogger.trace("preProcessAAIPUT ")
207 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n")
208 // execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
210 //requestDetails.modelInfo.for AAI PUT servieInstanceData
211 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
212 String serviceInstanceName = execution.getVariable("serviceInstanceName")
213 String serviceInstanceId = execution.getVariable("serviceInstanceId")
214 //aai serviceType and Role can be setted as fixed value now.
215 String aaiServiceType = "E2E Service"
216 String aaiServiceRole = "E2E Service"
217 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
218 String modelUuid = execution.getVariable("model-version-id-original")
220 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
221 si.setServiceInstanceId(serviceInstanceId)
222 si.setServiceInstanceName(serviceInstanceName)
223 si.setServiceType(aaiServiceType)
224 si.setServiceRole(aaiServiceRole)
225 si.setModelInvariantId(modelInvariantUuid)
226 si.setModelVersionId(modelUuid)
228 execution.setVariable("serviceInstanceData", si)
230 msoLogger.info("Exited " + method)
233 public void updateServiceInstance(DelegateExecution execution) {
234 msoLogger.trace("updateServiceInstance ")
237 String serviceInstanceId = execution.getVariable("serviceInstanceId")
238 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
240 AAIResourcesClient client = new AAIResourcesClient()
241 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
242 client.update(uri, si)
244 } catch (BpmnError e) {
246 } catch (Exception ex) {
247 msg = "Exception in DoCreateServiceInstance.updateServiceInstance. " + ex.getMessage()
249 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
251 msoLogger.trace("Exit updateServiceInstance ")
254 public void processRollbackException(DelegateExecution execution){
255 msoLogger.trace("processRollbackException ")
257 msoLogger.debug("Caught an Exception in DoUpdateE2EServiceInstanceRollback")
258 execution.setVariable("rollbackData", null)
259 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Update Rollback")
260 execution.setVariable("WorkflowException", null)
263 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
265 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
268 msoLogger.debug(" Exit processRollbackException")
271 public void processRollbackJavaException(DelegateExecution execution){
272 msoLogger.trace("processRollbackJavaException ")
274 execution.setVariable("rollbackData", null)
275 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Update Rollback")
276 msoLogger.debug("Caught Exception in processRollbackJavaException")
279 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
281 msoLogger.trace("Exit processRollbackJavaException ")