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.onap.so.logger.LoggingAnchor
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.AllottedResource
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.logger.ErrorCode
35 import org.onap.so.logger.MessageEnum
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
39 import static org.apache.commons.lang3.StringUtils.isBlank
42 * This groovy class supports the <class>CreateAllottedResourceBRGRollback.bpmn</class> process.
47 * @param - msoRequestId
48 * @param - isDebugLogEnabled
49 * @param - disableRollback - O
50 * @param - rollbackData
53 * @param - rollbackError
54 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
57 public class DoCreateAllottedResourceBRGRollback extends AbstractServiceTaskProcessor{
58 private static final Logger logger = LoggerFactory.getLogger(DoCreateAllottedResourceBRGRollback.class);
60 String Prefix="DCARBRGRB_"
61 ExceptionUtil exceptionUtil = new ExceptionUtil()
63 public void preProcessRequest (DelegateExecution execution) {
67 logger.trace("start preProcessRequest")
68 execution.setVariable("prefix", Prefix)
69 String rbType = "DCARBRG_"
72 def rollbackData = execution.getVariable("rollbackData")
73 logger.debug("RollbackData:" + rollbackData)
75 if (rollbackData != null) {
76 if (rollbackData.hasType(rbType)) {
78 execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
79 execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
80 execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
83 def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
84 if ("true".equals(rollbackAAI))
86 execution.setVariable("rollbackAAI",true)
87 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
90 def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
91 if ("true".equals(rollbackSDNC))
93 execution.setVariable("rollbackSDNC", true)
94 execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate"))
95 execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate"))
96 execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign"))
98 logger.debug("sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") )
99 logger.debug("sdncDelete:\n" + execution.getVariable("deleteSdnc"))
100 logger.debug("sdncUnassign:\n" + execution.getVariable("unassignSdnc"))
102 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
103 execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq"))
104 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
107 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
109 execution.setVariable("skipRollback", true)
113 execution.setVariable("skipRollback", true)
117 execution.setVariable("skipRollback", true)
119 if (execution.getVariable("disableRollback").equals("true" ))
121 execution.setVariable("skipRollback", true)
125 logger.debug("Rethrowing MSOWorkflowException")
127 } catch (Exception ex){
128 msg = "Exception in preProcessRequest " + ex.getMessage()
130 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
132 logger.trace("end preProcessRequest")
135 // aaiARPath set during query (existing AR)
136 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
139 logger.trace("start updateAaiAROrchStatus")
140 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
141 String aaiARPath = execution.getVariable("aaiARPath")
142 logger.debug(" aaiARPath:" + aaiARPath)
143 Optional<AllottedResource> ar = Optional.empty(); //need this for getting resourceVersion for delete
144 if (!isBlank(aaiARPath))
146 ar = arUtils.getARbyLink(execution, aaiARPath, "")
150 msg = "AR not found in AAI at:" + aaiARPath
152 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
154 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
155 logger.trace("end updateAaiAROrchStatus")
158 public void validateSDNCResp(DelegateExecution execution, String response, String method){
161 logger.trace("start ValidateSDNCResponse Process")
165 WorkflowException workflowException = execution.getVariable("WorkflowException")
166 logger.debug("workflowException: " + workflowException)
168 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
169 logger.debug("SDNCResponse: " + response)
171 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
172 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
174 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
175 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
179 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
180 throw new BpmnError("MSOWorkflowException")
182 } catch (BpmnError e) {
183 if ("404".contentEquals(e.getErrorCode()))
185 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
191 } catch(Exception ex) {
192 msg = "Exception in validateSDNCResp. " + ex.getMessage()
194 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
196 logger.trace("end ValidateSDNCResp Process")
199 public void deleteAaiAR(DelegateExecution execution){
202 logger.trace("start deleteAaiAR")
203 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
204 String arLink = execution.getVariable("aaiARPath")
205 arUtils.deleteAR(execution, arLink )
206 } catch (BpmnError e) {
208 }catch(Exception ex){
209 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
210 "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN",
211 ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
212 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
214 logger.trace("end deleteAaiAR")
217 public void postProcessRequest(DelegateExecution execution) {
219 logger.trace("start postProcessRequest")
222 execution.setVariable("rollbackData", null)
223 boolean skipRollback = execution.getVariable("skipRollback")
224 if (skipRollback != true)
226 execution.setVariable("rolledBack", true)
227 logger.debug("rolledBack")
229 logger.trace("end postProcessRequest")
231 } catch (BpmnError e) {
232 msg = "Bpmn Exception in postProcessRequest. "
234 } catch (Exception ex) {
235 msg = "Exception in postProcessRequest. " + ex.getMessage()
241 public void processRollbackException(DelegateExecution execution){
243 logger.trace("start processRollbackException")
245 logger.debug("Caught an Exception in DoCreateAllottedResourceRollback")
246 execution.setVariable("rollbackData", null)
247 execution.setVariable("rolledBack", false)
248 execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback")
249 execution.setVariable("WorkflowException", null)
252 logger.debug("BPMN Error during processRollbackExceptions Method: ")
254 logger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
257 logger.trace("end processRollbackException")
260 public void processRollbackJavaException(DelegateExecution execution){
262 logger.trace("start processRollbackJavaException")
264 execution.setVariable("rollbackData", null)
265 execution.setVariable("rolledBack", false)
266 execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback")
267 logger.debug("Caught Exception in processRollbackJavaException")
270 logger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
272 logger.trace("end processRollbackJavaException")