2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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=========================================================
23 package org.onap.so.bpmn.vcpe.scripts
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.AllottedResource
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.logger.ErrorCode
34 import org.onap.so.logger.MessageEnum
35 import org.slf4j.Logger
36 import org.slf4j.LoggerFactory
38 import static org.apache.commons.lang3.StringUtils.isBlank
41 * This groovy class supports the <class>CreateAllottedResourceBRGRollback.bpmn</class> process.
46 * @param - msoRequestId
47 * @param - isDebugLogEnabled
48 * @param - disableRollback - O
49 * @param - rollbackData
52 * @param - rollbackError
53 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
56 public class DoCreateAllottedResourceBRGRollback extends AbstractServiceTaskProcessor{
57 private static final Logger logger = LoggerFactory.getLogger(DoCreateAllottedResourceBRGRollback.class);
59 String Prefix="DCARBRGRB_"
60 ExceptionUtil exceptionUtil = new ExceptionUtil()
62 public void preProcessRequest (DelegateExecution execution) {
66 logger.trace("start preProcessRequest")
67 execution.setVariable("prefix", Prefix)
68 String rbType = "DCARBRG_"
71 def rollbackData = execution.getVariable("rollbackData")
72 logger.debug("RollbackData:" + rollbackData)
74 if (rollbackData != null) {
75 if (rollbackData.hasType(rbType)) {
77 execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
78 execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
79 execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
82 def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
83 if ("true".equals(rollbackAAI))
85 execution.setVariable("rollbackAAI",true)
86 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
89 def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
90 if ("true".equals(rollbackSDNC))
92 execution.setVariable("rollbackSDNC", true)
93 execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate"))
94 execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate"))
95 execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign"))
97 logger.debug("sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") )
98 logger.debug("sdncDelete:\n" + execution.getVariable("deleteSdnc"))
99 logger.debug("sdncUnassign:\n" + execution.getVariable("unassignSdnc"))
101 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
102 execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq"))
103 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
106 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
108 execution.setVariable("skipRollback", true)
112 execution.setVariable("skipRollback", true)
116 execution.setVariable("skipRollback", true)
118 if (execution.getVariable("disableRollback").equals("true" ))
120 execution.setVariable("skipRollback", true)
124 logger.debug("Rethrowing MSOWorkflowException")
126 } catch (Exception ex){
127 msg = "Exception in preProcessRequest " + ex.getMessage()
129 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
131 logger.trace("end preProcessRequest")
134 // aaiARPath set during query (existing AR)
135 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
138 logger.trace("start updateAaiAROrchStatus")
139 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
140 String aaiARPath = execution.getVariable("aaiARPath")
141 logger.debug(" aaiARPath:" + aaiARPath)
142 Optional<AllottedResource> ar = Optional.empty(); //need this for getting resourceVersion for delete
143 if (!isBlank(aaiARPath))
145 ar = arUtils.getARbyLink(execution, aaiARPath, "")
149 msg = "AR not found in AAI at:" + aaiARPath
151 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
153 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
154 logger.trace("end updateAaiAROrchStatus")
157 public void validateSDNCResp(DelegateExecution execution, String response, String method){
160 logger.trace("start ValidateSDNCResponse Process")
164 WorkflowException workflowException = execution.getVariable("WorkflowException")
165 logger.debug("workflowException: " + workflowException)
167 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
168 logger.debug("SDNCResponse: " + response)
170 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
171 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
173 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
174 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
178 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
179 throw new BpmnError("MSOWorkflowException")
181 } catch (BpmnError e) {
182 if ("404".contentEquals(e.getErrorCode()))
184 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
190 } catch(Exception ex) {
191 msg = "Exception in validateSDNCResp. " + ex.getMessage()
193 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
195 logger.trace("end ValidateSDNCResp Process")
198 public void deleteAaiAR(DelegateExecution execution){
201 logger.trace("start deleteAaiAR")
202 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
203 String arLink = execution.getVariable("aaiARPath")
204 arUtils.deleteAR(execution, arLink )
205 } catch (BpmnError e) {
207 }catch(Exception ex){
208 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
209 "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN",
210 ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
211 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
213 logger.trace("end deleteAaiAR")
216 public void postProcessRequest(DelegateExecution execution) {
218 logger.trace("start postProcessRequest")
221 execution.setVariable("rollbackData", null)
222 boolean skipRollback = execution.getVariable("skipRollback")
223 if (skipRollback != true)
225 execution.setVariable("rolledBack", true)
226 logger.debug("rolledBack")
228 logger.trace("end postProcessRequest")
230 } catch (BpmnError e) {
231 msg = "Bpmn Exception in postProcessRequest. "
233 } catch (Exception ex) {
234 msg = "Exception in postProcessRequest. " + ex.getMessage()
240 public void processRollbackException(DelegateExecution execution){
242 logger.trace("start processRollbackException")
244 logger.debug("Caught an Exception in DoCreateAllottedResourceRollback")
245 execution.setVariable("rollbackData", null)
246 execution.setVariable("rolledBack", false)
247 execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback")
248 execution.setVariable("WorkflowException", null)
251 logger.debug("BPMN Error during processRollbackExceptions Method: ")
253 logger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
256 logger.trace("end processRollbackException")
259 public void processRollbackJavaException(DelegateExecution execution){
261 logger.trace("start processRollbackJavaException")
263 execution.setVariable("rollbackData", null)
264 execution.setVariable("rolledBack", false)
265 execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback")
266 logger.debug("Caught Exception in processRollbackJavaException")
269 logger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
271 logger.trace("end processRollbackJavaException")