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.onap.aai.domain.yang.AllottedResource;
27 import org.onap.so.bpmn.common.scripts.*;
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.core.WorkflowException
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
32 import org.onap.so.logger.ErrorCode
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.camunda.bpm.engine.delegate.DelegateExecution
36 import static org.apache.commons.lang3.StringUtils.*
38 import org.onap.so.logger.MessageEnum
39 import org.slf4j.Logger
40 import org.slf4j.LoggerFactory
43 * This groovy class supports the <class>CreateAllottedResourceTXCRollback.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 DoCreateAllottedResourceTXCRollback extends AbstractServiceTaskProcessor{
59 private static final Logger logger = LoggerFactory.getLogger(DoCreateAllottedResourceTXCRollback.class);
61 String Prefix="DCARTXCRB_"
62 ExceptionUtil exceptionUtil = new ExceptionUtil()
64 public void preProcessRequest (DelegateExecution execution) {
68 logger.trace("start preProcessRequest")
69 execution.setVariable("prefix", Prefix)
70 String rbType = "DCARTXC_"
73 def rollbackData = execution.getVariable("rollbackData")
74 logger.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 logger.debug("sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") )
100 logger.debug("sdncDelete:\n" + execution.getVariable("deleteSdnc"))
101 logger.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 logger.debug("Rethrowing MSOWorkflowException")
128 } catch (Exception ex){
129 msg = "Exception in preProcessRequest " + ex.getMessage()
131 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
133 logger.trace("end preProcessRequest")
136 // aaiARPath set during query (existing AR)
137 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
140 logger.trace("start updateAaiAROrchStatus")
141 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
142 String aaiARPath = execution.getVariable("aaiARPath")
143 logger.debug(" aaiARPath:" + aaiARPath)
144 Optional<AllottedResource> ar = Optional.empty(); //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 logger.trace("end updateAaiAROrchStatus")
159 public void validateSDNCResp(DelegateExecution execution, String response, String method){
162 logger.trace("start ValidateSDNCResponse Process")
166 WorkflowException workflowException = execution.getVariable("WorkflowException")
167 logger.debug("workflowException: " + workflowException)
169 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
170 logger.debug("SDNCResponse: " + response)
172 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
173 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
175 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
176 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
180 logger.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 logger.trace("Exit ValidateSDNCResp Process")
200 public void deleteAaiAR(DelegateExecution execution){
203 logger.trace("start deleteAaiAR")
204 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
205 String arLink = execution.getVariable("aaiARPath")
206 arUtils.deleteAR(execution, arLink)
207 } catch (BpmnError e) {
209 }catch(Exception ex){
210 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
211 "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN",
212 ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
213 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
215 logger.trace("end deleteAaiAR")
218 public void postProcessRequest(DelegateExecution execution) {
220 logger.trace("start postProcessRequest")
223 execution.setVariable("rollbackData", null)
224 boolean skipRollback = execution.getVariable("skipRollback")
225 if (skipRollback != true)
227 execution.setVariable("rolledBack", true)
228 logger.debug("rolledBack")
230 logger.trace("end postProcessRequest")
232 } catch (BpmnError e) {
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")