2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.scripts
25 import static org.apache.commons.lang3.StringUtils.*;
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.so.bpmn.common.scripts.AaiUtil
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.common.scripts.MsoUtils
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.client.aai.AAIObjectType
36 import org.onap.so.client.aai.AAIResourcesClient
37 import org.onap.so.client.aai.entities.AAIResultWrapper
38 import org.onap.so.client.aai.entities.uri.AAIResourceUri
39 import org.onap.so.client.aai.entities.uri.AAIUriFactory
40 import org.slf4j.Logger
41 import org.slf4j.LoggerFactory
42 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
44 import org.onap.so.bpmn.common.scripts.AaiUtil;
47 * This groovy class supports the <class>DoUpdateE2EServiceInstanceRollback.bpmn</class> process.
50 * @param - msoRequestId
51 * @param - rollbackData with
53 * subscriptionServiceType
62 * @param - rollbackError
63 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
66 public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
67 private static final Logger logger = LoggerFactory.getLogger( DoUpdateE2EServiceInstanceRollback.class);
70 String Prefix="DUPDSIRB_"
71 ExceptionUtil exceptionUtil = new ExceptionUtil()
73 public void preProcessRequest(DelegateExecution execution) {
74 execution.setVariable("prefix",Prefix)
76 logger.trace("preProcessRequest ")
77 execution.setVariable("rollbackAAI",false)
78 execution.setVariable("rollbackAdded",false)
79 execution.setVariable("rollbackDeleted",false)
81 List addResourceList = execution.getVariable("addResourceList")
82 List delResourceList = execution.getVariable("delResourceList")
83 execution.setVariable("addResourceList_o", addResourceList)
84 execution.setVariable("delResourceList_o", delResourceList)
85 //exchange add and delete resource list
86 execution.setVariable("addResourceList", delResourceList)
87 execution.setVariable("delResourceList", addResourceList)
90 def rollbackData = execution.getVariable("rollbackData")
91 logger.debug("RollbackData:" + rollbackData)
93 if (rollbackData != null) {
94 if (rollbackData.hasType("SERVICEINSTANCE")) {
96 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
97 execution.setVariable("serviceInstanceId", serviceInstanceId)
99 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
100 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
102 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
103 execution.setVariable("globalSubscriberId", globalSubscriberId)
105 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
106 if ("true".equals(rollbackAAI))
108 execution.setVariable("rollbackAAI",true)
111 def rollbackAdded = rollbackData.get("SERVICEINSTANCE", "rollbackAdded")
112 if ("true".equals(rollbackAdded))
114 execution.setVariable("rollbackAdded", true)
117 def rollbackDeleted = rollbackData.get("SERVICEINSTANCE", "rollbackDeleted")
118 if ("true".equals(rollbackDeleted))
120 execution.setVariable("rollbackDeleted", true)
123 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true
124 && execution.getVariable("rollbackDeleted") != true)
126 execution.setVariable("skipRollback", true)
131 execution.setVariable("skipRollback", true)
135 execution.setVariable("skipRollback", true)
137 if (execution.getVariable("disableRollback").equals("true" ))
139 execution.setVariable("skipRollback", true)
142 } catch (BpmnError e) {
144 } catch (Exception ex){
145 msg = "Exception in Update ServiceInstance Rollback preProcessRequest " + ex.getMessage()
147 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
149 logger.trace("Exit preProcessRequest ")
152 public void postProcessRequest(DelegateExecution execution) {
153 logger.trace("postProcessRequest ")
156 execution.setVariable("rollbackData", null)
157 String serviceInstanceId = execution.getVariable("serviceInstanceId")
158 boolean rollbackAAI = execution.getVariable("rollbackAAI")
159 boolean rollbackAdded = execution.getVariable("rollbackAdded")
160 boolean rollbackDeleted = execution.getVariable("rollbackDeleted")
162 List addResourceList = execution.getVariable("addResourceList_o")
163 List delResourceList = execution.getVariable("delResourceList_o")
164 execution.setVariable("addResourceList", addResourceList)
165 execution.setVariable("delResourceList", delResourceList)
167 if (rollbackAAI || rollbackAdded || rollbackDeleted)
169 execution.setVariable("rolledBack", true)
173 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
175 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
176 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
177 logger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
180 logger.trace("Exit postProcessRequest ")
182 } catch (BpmnError e) {
183 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
185 } catch (Exception ex) {
186 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
192 public void preProcessForAddResource(DelegateExecution execution) {
195 public void postProcessForAddResource(DelegateExecution execution) {
198 public void preProcessForDeleteResource(DelegateExecution execution) {
201 public void postProcessForDeleteResource(DelegateExecution execution) {
204 public void preProcessAAIPUT(DelegateExecution execution) {
205 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
206 logger.info("Entered " + method)
208 logger.trace("preProcessAAIPUT ")
210 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n")
211 // execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
213 //requestDetails.modelInfo.for AAI PUT servieInstanceData
214 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
215 String serviceInstanceName = execution.getVariable("serviceInstanceName")
216 String serviceInstanceId = execution.getVariable("serviceInstanceId")
217 //aai serviceType and Role can be setted as fixed value now.
218 String aaiServiceType = "E2E Service"
219 String aaiServiceRole = "E2E Service"
220 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
221 String modelUuid = execution.getVariable("model-version-id-original")
223 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
224 si.setServiceInstanceId(serviceInstanceId)
225 si.setServiceInstanceName(serviceInstanceName)
226 si.setServiceType(aaiServiceType)
227 si.setServiceRole(aaiServiceRole)
228 si.setModelInvariantId(modelInvariantUuid)
229 si.setModelVersionId(modelUuid)
231 execution.setVariable("serviceInstanceData", si)
233 logger.info("Exited " + method)
236 public void updateServiceInstance(DelegateExecution execution) {
237 logger.trace("updateServiceInstance ")
240 String serviceInstanceId = execution.getVariable("serviceInstanceId")
241 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
243 AAIResourcesClient client = new AAIResourcesClient()
244 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
245 client.update(uri, si)
247 } catch (BpmnError e) {
249 } catch (Exception ex) {
250 msg = "Exception in DoCreateServiceInstance.updateServiceInstance. " + ex.getMessage()
252 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
254 logger.trace("Exit updateServiceInstance ")
257 public void processRollbackException(DelegateExecution execution){
258 logger.trace("processRollbackException ")
260 logger.debug("Caught an Exception in DoUpdateE2EServiceInstanceRollback")
261 execution.setVariable("rollbackData", null)
262 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Update Rollback")
263 execution.setVariable("WorkflowException", null)
266 logger.debug("BPMN Error during processRollbackExceptions Method: ")
268 logger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
271 logger.debug(" Exit processRollbackException")
274 public void processRollbackJavaException(DelegateExecution execution){
275 logger.trace("processRollbackJavaException ")
277 execution.setVariable("rollbackData", null)
278 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Update Rollback")
279 logger.debug("Caught Exception in processRollbackJavaException")
282 logger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
284 logger.trace("Exit processRollbackJavaException ")