2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.scripts
25 import static org.apache.commons.lang3.StringUtils.*;
27 import groovy.xml.XmlUtil
30 import org.onap.so.bpmn.core.json.JsonUtils
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
33 import org.onap.so.bpmn.core.RollbackData
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.logger.MsoLogger
36 import org.onap.so.logger.MessageEnum
37 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
38 import org.onap.so.client.aai.entities.uri.AAIResourceUri
39 import org.onap.so.client.aai.entities.uri.AAIUriFactory
40 import org.onap.so.client.aai.AAIObjectType
41 import org.onap.so.client.aai.AAIResourcesClient
43 import java.util.UUID;
45 import org.camunda.bpm.engine.delegate.BpmnError
46 import org.camunda.bpm.engine.delegate.DelegateExecution
47 import org.json.JSONObject;
48 import org.apache.commons.lang3.*
49 import org.apache.commons.codec.binary.Base64;
50 import org.springframework.web.util.UriUtils;
52 * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
55 * @param - msoRequestId
56 * @param - rollbackData with
58 * subscriptionServiceType
67 * @param - rollbackError
68 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
71 public class DoCreateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
73 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateE2EServiceInstanceRollback.class);
74 String Prefix="DCRESIRB_"
76 public void preProcessRequest(DelegateExecution execution) {
77 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
78 execution.setVariable("prefix",Prefix)
80 msoLogger.trace("Start preProcessRequest")
81 execution.setVariable("rollbackAAI",false)
82 execution.setVariable("rollbackSDNC",false)
85 def rollbackData = execution.getVariable("rollbackData")
86 msoLogger.debug("RollbackData:" + rollbackData)
88 if (rollbackData != null) {
89 if (rollbackData.hasType("SERVICEINSTANCE")) {
91 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
92 execution.setVariable("serviceInstanceId", serviceInstanceId)
94 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
95 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
97 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
98 execution.setVariable("globalSubscriberId", globalSubscriberId)
100 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
101 if ("true".equals(rollbackAAI))
103 execution.setVariable("rollbackAAI",true)
106 def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
107 if ("true".equals(rollbackSDNC))
109 execution.setVariable("rollbackSDNC", true)
112 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
114 execution.setVariable("skipRollback", true)
117 def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
118 execution.setVariable("sdncDelete", sdncDelete)
119 def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
120 execution.setVariable("sdncDeactivate", sdncDeactivate)
121 msoLogger.debug("sdncDeactivate:\n" + sdncDeactivate)
122 msoLogger.debug("sdncDelete:\n" + sdncDelete)
125 execution.setVariable("skipRollback", true)
129 execution.setVariable("skipRollback", true)
131 if (execution.getVariable("disableRollback").equals("true" ))
133 execution.setVariable("skipRollback", true)
136 } catch (BpmnError e) {
138 } catch (Exception ex){
139 msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
141 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) //TODO how does this even compile without exceptionUtil being declared
143 msoLogger.trace("Exit preProcessRequest ")
146 public void validateSDNCResponse(DelegateExecution execution, String response, String method) {
148 msoLogger.trace("validateSDNCResponse")
151 WorkflowException workflowException = execution.getVariable("WorkflowException")
152 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
153 msoLogger.debug("SDNCResponse: " + response)
154 msoLogger.debug("workflowException: " + workflowException)
156 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
157 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
159 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
160 msg = "SDNC Adapter service-instance rollback successful for " + method
163 execution.setVariable("rolledBack", false)
164 msg = "Error Response from SDNC Adapter service-instance rollback for " + method
165 execution.setVariable("rollbackError", msg)
167 throw new BpmnError("MSOWorkflowException")
169 } catch (BpmnError e) {
171 } catch (Exception ex){
172 msg = "Exception in Create ServiceInstance rollback for " + method + " Exception:" + ex.getMessage()
174 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
176 msoLogger.trace("Exit validateSDNCResponse ")
180 * Deletes the service instance in aai
182 public void deleteServiceInstance(DelegateExecution execution) {
183 msoLogger.trace("Started Delete Service Instance")
185 String globalCustId = execution.getVariable("globalSubscriberId")
186 String serviceType = execution.getVariable("subscriptionServiceType")
187 String serviceInstanceId = execution.getVariable("serviceInstanceId")
189 AAIResourcesClient resourceClient = new AAIResourcesClient();
190 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustId, serviceType, serviceInstanceId)
191 resourceClient.delete(serviceInstanceUri)
193 msoLogger.trace("Completed Delete Service Instance")
195 msoLogger.debug("Error occured within deleteServiceInstance method: " + e)
199 public void postProcessRequest(DelegateExecution execution) {
201 msoLogger.trace("postProcessRequest")
204 execution.setVariable("rollbackData", null)
205 String serviceInstanceId = execution.getVariable("serviceInstanceId")
206 boolean rollbackAAI = execution.getVariable("rollbackAAI")
207 boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
208 if (rollbackAAI || rollbackSDNC)
210 execution.setVariable("rolledBack", true)
214 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
216 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
217 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
218 msoLogger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
221 msoLogger.trace("Exit postProcessRequest ")
223 } catch (BpmnError e) {
224 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
226 } catch (Exception ex) {
227 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
233 public void processRollbackException(DelegateExecution execution){
235 msoLogger.trace("processRollbackException")
237 msoLogger.debug("Caught an Exception in DoCreateServiceInstanceRollback")
238 execution.setVariable("rollbackData", null)
239 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
240 execution.setVariable("WorkflowException", null)
243 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
245 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
248 msoLogger.trace(" Exit processRollbackException")
251 public void processRollbackJavaException(DelegateExecution execution){
253 msoLogger.trace("processRollbackJavaException")
255 execution.setVariable("rollbackData", null)
256 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
257 msoLogger.debug("Caught Exception in processRollbackJavaException")
260 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
262 msoLogger.trace("Exit processRollbackJavaException")