2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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=========================================================
21 package org.onap.so.bpmn.vcpe.scripts;
23 import org.onap.so.bpmn.common.scripts.*;
24 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
25 import org.onap.so.bpmn.core.WorkflowException
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.common.scripts.MsoUtils
28 import org.onap.so.bpmn.common.scripts.AaiUtil
29 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
30 import org.onap.so.rest.APIResponse
32 import java.util.UUID;
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.camunda.bpm.engine.delegate.DelegateExecution
35 import org.apache.commons.lang3.*
36 import org.springframework.web.util.UriUtils;
37 import static org.apache.commons.lang3.StringUtils.*
39 import org.onap.so.logger.MessageEnum
40 import org.onap.so.logger.MsoLogger
43 * This groovy class supports the <class>CreateAllottedResourceBRGRollback.bpmn</class> process.
48 * @param - msoRequestId
49 * @param - isDebugLogEnabled
50 * @param - disableRollback - O
51 * @param - rollbackData
54 * @param - rollbackError
55 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
58 public class DoCreateAllottedResourceBRGRollback extends AbstractServiceTaskProcessor{
59 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateAllottedResourceBRGRollback.class);
61 String Prefix="DCARBRGRB_"
62 ExceptionUtil exceptionUtil = new ExceptionUtil()
64 public void preProcessRequest (DelegateExecution execution) {
68 msoLogger.trace("start preProcessRequest")
69 execution.setVariable("prefix", Prefix)
70 String rbType = "DCARBRG_"
73 def rollbackData = execution.getVariable("rollbackData")
74 msoLogger.debug("RollbackData:" + rollbackData)
76 if (rollbackData != null) {
77 if (rollbackData.hasType(rbType)) {
79 execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
80 execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
81 execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
84 def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
85 if ("true".equals(rollbackAAI))
87 execution.setVariable("rollbackAAI",true)
88 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
91 def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
92 if ("true".equals(rollbackSDNC))
94 execution.setVariable("rollbackSDNC", true)
95 execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate"))
96 execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate"))
97 execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign"))
99 msoLogger.debug("sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") )
100 msoLogger.debug("sdncDelete:\n" + execution.getVariable("deleteSdnc"))
101 msoLogger.debug("sdncUnassign:\n" + execution.getVariable("unassignSdnc"))
103 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
104 execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq"))
105 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
108 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
110 execution.setVariable("skipRollback", true)
114 execution.setVariable("skipRollback", true)
118 execution.setVariable("skipRollback", true)
120 if (execution.getVariable("disableRollback").equals("true" ))
122 execution.setVariable("skipRollback", true)
126 msoLogger.debug("Rethrowing MSOWorkflowException")
128 } catch (Exception ex){
129 msg = "Exception in preProcessRequest " + ex.getMessage()
131 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
133 msoLogger.trace("end preProcessRequest")
136 // aaiARPath set during query (existing AR)
137 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
140 msoLogger.trace("start updateAaiAROrchStatus")
141 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
142 String aaiARPath = execution.getVariable("aaiARPath")
143 msoLogger.debug(" aaiARPath:" + aaiARPath)
144 String ar = null; //need this for getting resourceVersion for delete
145 if (!isBlank(aaiARPath))
147 ar = arUtils.getARbyLink(execution, aaiARPath, "")
151 msg = "AR not found in AAI at:" + aaiARPath
153 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
155 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
156 msoLogger.trace("end updateAaiAROrchStatus")
159 public void validateSDNCResp(DelegateExecution execution, String response, String method){
162 msoLogger.trace("start ValidateSDNCResponse Process")
166 WorkflowException workflowException = execution.getVariable("WorkflowException")
167 msoLogger.debug("workflowException: " + workflowException)
169 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
170 msoLogger.debug("SDNCResponse: " + response)
172 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
173 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
175 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
176 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
180 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
181 throw new BpmnError("MSOWorkflowException")
183 } catch (BpmnError e) {
184 if ("404".contentEquals(e.getErrorCode()))
186 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
192 } catch(Exception ex) {
193 msg = "Exception in validateSDNCResp. " + ex.getMessage()
195 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
197 msoLogger.trace("end ValidateSDNCResp Process")
200 public void deleteAaiAR(DelegateExecution execution){
203 msoLogger.trace("start deleteAaiAR")
204 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
205 String ar = null //need to get resource-version
206 String arLink = execution.getVariable("aaiARPath")
207 if (!isBlank(arLink))
209 ar = arUtils.getARbyLink(execution, arLink, "")
211 arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
212 } catch (BpmnError e) {
214 }catch(Exception ex){
215 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + ex);
216 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
218 msoLogger.trace("end deleteAaiAR")
221 public void postProcessRequest(DelegateExecution execution) {
223 msoLogger.trace("start postProcessRequest")
226 execution.setVariable("rollbackData", null)
227 boolean skipRollback = execution.getVariable("skipRollback")
228 if (skipRollback != true)
230 execution.setVariable("rolledBack", true)
231 msoLogger.debug("rolledBack")
233 msoLogger.trace("end postProcessRequest")
235 } catch (BpmnError e) {
236 msg = "Bpmn Exception in postProcessRequest. "
238 } catch (Exception ex) {
239 msg = "Exception in postProcessRequest. " + ex.getMessage()
245 public void processRollbackException(DelegateExecution execution){
247 msoLogger.trace("start processRollbackException")
249 msoLogger.debug("Caught an Exception in DoCreateAllottedResourceRollback")
250 execution.setVariable("rollbackData", null)
251 execution.setVariable("rolledBack", false)
252 execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback")
253 execution.setVariable("WorkflowException", null)
256 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
258 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
261 msoLogger.trace("end processRollbackException")
264 public void processRollbackJavaException(DelegateExecution execution){
266 msoLogger.trace("start processRollbackJavaException")
268 execution.setVariable("rollbackData", null)
269 execution.setVariable("rolledBack", false)
270 execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback")
271 msoLogger.debug("Caught Exception in processRollbackJavaException")
274 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
276 msoLogger.trace("end processRollbackJavaException")