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.rest.APIResponse;
36 import org.onap.so.rest.RESTClient
37 import org.onap.so.rest.RESTConfig
38 import org.onap.so.logger.MsoLogger
39 import org.onap.so.logger.MessageEnum
41 import org.onap.so.client.aai.entities.uri.AAIResourceUri
42 import org.onap.so.client.aai.entities.uri.AAIUriFactory
43 import org.onap.so.client.aai.AAIObjectType
44 import org.onap.so.client.aai.AAIResourcesClient
46 import java.util.UUID;
48 import org.camunda.bpm.engine.delegate.BpmnError
49 import org.camunda.bpm.engine.delegate.DelegateExecution
50 import org.json.JSONObject;
51 import org.apache.commons.lang3.*
52 import org.apache.commons.codec.binary.Base64;
53 import org.springframework.web.util.UriUtils;
55 * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.
58 * @param - msoRequestId
59 * @param - rollbackData with
61 * subscriptionServiceType
70 * @param - rollbackError
71 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
74 public class DoCreateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
76 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateE2EServiceInstanceRollback.class);
77 String Prefix="DCRESIRB_"
79 public void preProcessRequest(DelegateExecution execution) {
80 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
81 execution.setVariable("prefix",Prefix)
83 msoLogger.trace("Start preProcessRequest")
84 execution.setVariable("rollbackAAI",false)
85 execution.setVariable("rollbackSDNC",false)
88 def rollbackData = execution.getVariable("rollbackData")
89 msoLogger.debug("RollbackData:" + rollbackData)
91 if (rollbackData != null) {
92 if (rollbackData.hasType("SERVICEINSTANCE")) {
94 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
95 execution.setVariable("serviceInstanceId", serviceInstanceId)
97 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
98 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
100 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
101 execution.setVariable("globalSubscriberId", globalSubscriberId)
103 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
104 if ("true".equals(rollbackAAI))
106 execution.setVariable("rollbackAAI",true)
109 def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")
110 if ("true".equals(rollbackSDNC))
112 execution.setVariable("rollbackSDNC", true)
115 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
117 execution.setVariable("skipRollback", true)
120 def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")
121 execution.setVariable("sdncDelete", sdncDelete)
122 def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")
123 execution.setVariable("sdncDeactivate", sdncDeactivate)
124 msoLogger.debug("sdncDeactivate:\n" + sdncDeactivate)
125 msoLogger.debug("sdncDelete:\n" + sdncDelete)
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 Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()
144 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) //TODO how does this even compile without exceptionUtil being declared
146 msoLogger.trace("Exit preProcessRequest ")
149 public void validateSDNCResponse(DelegateExecution execution, String response, String method) {
151 msoLogger.trace("validateSDNCResponse")
154 WorkflowException workflowException = execution.getVariable("WorkflowException")
155 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
156 msoLogger.debug("SDNCResponse: " + response)
157 msoLogger.debug("workflowException: " + workflowException)
159 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
160 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
162 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
163 msg = "SDNC Adapter service-instance rollback successful for " + method
166 execution.setVariable("rolledBack", false)
167 msg = "Error Response from SDNC Adapter service-instance rollback for " + method
168 execution.setVariable("rollbackError", msg)
170 throw new BpmnError("MSOWorkflowException")
172 } catch (BpmnError e) {
174 } catch (Exception ex){
175 msg = "Exception in Create ServiceInstance rollback for " + method + " Exception:" + ex.getMessage()
177 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
179 msoLogger.trace("Exit validateSDNCResponse ")
183 * Deletes the service instance in aai
185 public void deleteServiceInstance(DelegateExecution execution) {
186 msoLogger.trace("Started Delete Service Instance")
188 String globalCustId = execution.getVariable("globalSubscriberId")
189 String serviceType = execution.getVariable("subscriptionServiceType")
190 String serviceInstanceId = execution.getVariable("serviceInstanceId")
192 AAIResourcesClient resourceClient = new AAIResourcesClient();
193 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustId, serviceType, serviceInstanceId)
194 resourceClient.delete(serviceInstanceUri)
196 msoLogger.trace("Completed Delete Service Instance")
198 msoLogger.debug("Error occured within deleteServiceInstance method: " + e)
202 public void postProcessRequest(DelegateExecution execution) {
204 msoLogger.trace("postProcessRequest")
207 execution.setVariable("rollbackData", null)
208 String serviceInstanceId = execution.getVariable("serviceInstanceId")
209 boolean rollbackAAI = execution.getVariable("rollbackAAI")
210 boolean rollbackSDNC = execution.getVariable("rollbackSDNC")
211 if (rollbackAAI || rollbackSDNC)
213 execution.setVariable("rolledBack", true)
217 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
219 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
220 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
221 msoLogger.debug("Error deleting service-instance in AAI for rollback", + serviceInstanceId)
224 msoLogger.trace("Exit postProcessRequest ")
226 } catch (BpmnError e) {
227 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
229 } catch (Exception ex) {
230 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
236 public void processRollbackException(DelegateExecution execution){
238 msoLogger.trace("processRollbackException")
240 msoLogger.debug("Caught an Exception in DoCreateServiceInstanceRollback")
241 execution.setVariable("rollbackData", null)
242 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")
243 execution.setVariable("WorkflowException", null)
246 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
248 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
251 msoLogger.trace(" Exit processRollbackException")
254 public void processRollbackJavaException(DelegateExecution execution){
256 msoLogger.trace("processRollbackJavaException")
258 execution.setVariable("rollbackData", null)
259 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")
260 msoLogger.debug("Caught Exception in processRollbackJavaException")
263 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
265 msoLogger.trace("Exit processRollbackJavaException")