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.aaiclient.client.aai.AAIObjectType
36 import org.onap.aaiclient.client.aai.AAIResourcesClient
37 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
38 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
39 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
40 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
41 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
42 import org.slf4j.Logger
43 import org.slf4j.LoggerFactory
44 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
46 import org.onap.so.bpmn.common.scripts.AaiUtil;
49 * This groovy class supports the <class>DoUpdateE2EServiceInstanceRollback.bpmn</class> process.
52 * @param - msoRequestId
53 * @param - rollbackData with
55 * subscriptionServiceType
64 * @param - rollbackError
65 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
68 public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
69 private static final Logger logger = LoggerFactory.getLogger( DoUpdateE2EServiceInstanceRollback.class);
72 String Prefix="DUPDSIRB_"
73 ExceptionUtil exceptionUtil = new ExceptionUtil()
75 public void preProcessRequest(DelegateExecution execution) {
76 execution.setVariable("prefix",Prefix)
78 logger.trace("preProcessRequest ")
79 execution.setVariable("rollbackAAI",false)
80 execution.setVariable("rollbackAdded",false)
81 execution.setVariable("rollbackDeleted",false)
83 List addResourceList = execution.getVariable("addResourceList")
84 List delResourceList = execution.getVariable("delResourceList")
85 execution.setVariable("addResourceList_o", addResourceList)
86 execution.setVariable("delResourceList_o", delResourceList)
87 //exchange add and delete resource list
88 execution.setVariable("addResourceList", delResourceList)
89 execution.setVariable("delResourceList", addResourceList)
92 def rollbackData = execution.getVariable("rollbackData")
93 logger.debug("RollbackData:" + rollbackData)
95 if (rollbackData != null) {
96 if (rollbackData.hasType("SERVICEINSTANCE")) {
98 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
99 execution.setVariable("serviceInstanceId", serviceInstanceId)
101 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
102 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
104 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
105 execution.setVariable("globalSubscriberId", globalSubscriberId)
107 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
108 if ("true".equals(rollbackAAI))
110 execution.setVariable("rollbackAAI",true)
113 def rollbackAdded = rollbackData.get("SERVICEINSTANCE", "rollbackAdded")
114 if ("true".equals(rollbackAdded))
116 execution.setVariable("rollbackAdded", true)
119 def rollbackDeleted = rollbackData.get("SERVICEINSTANCE", "rollbackDeleted")
120 if ("true".equals(rollbackDeleted))
122 execution.setVariable("rollbackDeleted", true)
125 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true
126 && execution.getVariable("rollbackDeleted") != true)
128 execution.setVariable("skipRollback", true)
133 execution.setVariable("skipRollback", true)
137 execution.setVariable("skipRollback", true)
139 if (execution.getVariable("disableRollback").equals("true" ))
141 execution.setVariable("skipRollback", true)
144 } catch (BpmnError e) {
146 } catch (Exception ex){
147 msg = "Exception in Update ServiceInstance Rollback preProcessRequest " + ex.getMessage()
149 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
151 logger.trace("Exit preProcessRequest ")
154 public void postProcessRequest(DelegateExecution execution) {
155 logger.trace("postProcessRequest ")
158 execution.setVariable("rollbackData", null)
159 String serviceInstanceId = execution.getVariable("serviceInstanceId")
160 boolean rollbackAAI = execution.getVariable("rollbackAAI")
161 boolean rollbackAdded = execution.getVariable("rollbackAdded")
162 boolean rollbackDeleted = execution.getVariable("rollbackDeleted")
164 List addResourceList = execution.getVariable("addResourceList_o")
165 List delResourceList = execution.getVariable("delResourceList_o")
166 execution.setVariable("addResourceList", addResourceList)
167 execution.setVariable("delResourceList", delResourceList)
169 if (rollbackAAI || rollbackAdded || rollbackDeleted)
171 execution.setVariable("rolledBack", true)
175 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
177 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
178 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
179 logger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
182 logger.trace("Exit postProcessRequest ")
184 } catch (BpmnError e) {
185 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
187 } catch (Exception ex) {
188 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
194 public void preProcessForAddResource(DelegateExecution execution) {
197 public void postProcessForAddResource(DelegateExecution execution) {
200 public void preProcessForDeleteResource(DelegateExecution execution) {
203 public void postProcessForDeleteResource(DelegateExecution execution) {
206 public void preProcessAAIPUT(DelegateExecution execution) {
207 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
208 logger.info("Entered " + method)
210 logger.trace("preProcessAAIPUT ")
212 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n")
213 // execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
215 //requestDetails.modelInfo.for AAI PUT servieInstanceData
216 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
217 String serviceInstanceName = execution.getVariable("serviceInstanceName")
218 String serviceInstanceId = execution.getVariable("serviceInstanceId")
219 //aai serviceType and Role can be setted as fixed value now.
220 String aaiServiceType = "E2E Service"
221 String aaiServiceRole = "E2E Service"
222 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
223 String modelUuid = execution.getVariable("model-version-id-original")
225 org.onap.aai.domain.yang.ServiceInstance si = new org.onap.aai.domain.yang.ServiceInstance()
226 si.setServiceInstanceId(serviceInstanceId)
227 si.setServiceInstanceName(serviceInstanceName)
228 si.setServiceType(aaiServiceType)
229 si.setServiceRole(aaiServiceRole)
230 si.setModelInvariantId(modelInvariantUuid)
231 si.setModelVersionId(modelUuid)
233 execution.setVariable("serviceInstanceData", si)
235 logger.info("Exited " + method)
238 public void updateServiceInstance(DelegateExecution execution) {
239 logger.trace("updateServiceInstance ")
242 String serviceInstanceId = execution.getVariable("serviceInstanceId")
243 org.onap.aai.domain.yang.ServiceInstance si = execution.getVariable("serviceInstanceData")
245 AAIResourcesClient client = new AAIResourcesClient()
246 AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
247 client.update(uri, si)
249 } catch (BpmnError e) {
251 } catch (Exception ex) {
252 msg = "Exception in DoCreateServiceInstance.updateServiceInstance. " + ex.getMessage()
254 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
256 logger.trace("Exit updateServiceInstance ")
259 public void processRollbackException(DelegateExecution execution){
260 logger.trace("processRollbackException ")
262 logger.debug("Caught an Exception in DoUpdateE2EServiceInstanceRollback")
263 execution.setVariable("rollbackData", null)
264 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Update Rollback")
265 execution.setVariable("WorkflowException", null)
268 logger.debug("BPMN Error during processRollbackExceptions Method: ")
270 logger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
273 logger.debug(" Exit processRollbackException")
276 public void processRollbackJavaException(DelegateExecution execution){
277 logger.trace("processRollbackJavaException ")
279 execution.setVariable("rollbackData", null)
280 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Update Rollback")
281 logger.debug("Caught Exception in processRollbackJavaException")
284 logger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
286 logger.trace("Exit processRollbackJavaException ")