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.aai.domain.yang.AllottedResource;
26 import org.onap.so.bpmn.common.scripts.*;
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.core.WorkflowException
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.common.scripts.AaiUtil
32 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
35 import java.util.UUID;
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.delegate.DelegateExecution
38 import org.apache.commons.lang3.*
39 import org.springframework.web.util.UriUtils;
40 import static org.apache.commons.lang3.StringUtils.*
42 import org.onap.so.logger.MessageEnum
43 import org.onap.so.logger.MsoLogger
44 import org.slf4j.Logger
45 import org.slf4j.LoggerFactory
48 * This groovy class supports the <class>CreateAllottedResourceTXCRollback.bpmn</class> process.
53 * @param - msoRequestId
54 * @param - isDebugLogEnabled
55 * @param - disableRollback - O
56 * @param - rollbackData
59 * @param - rollbackError
60 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
63 public class DoCreateAllottedResourceTXCRollback extends AbstractServiceTaskProcessor{
64 private static final Logger logger = LoggerFactory.getLogger(DoCreateAllottedResourceTXCRollback.class);
66 String Prefix="DCARTXCRB_"
67 ExceptionUtil exceptionUtil = new ExceptionUtil()
69 public void preProcessRequest (DelegateExecution execution) {
73 logger.trace("start preProcessRequest")
74 execution.setVariable("prefix", Prefix)
75 String rbType = "DCARTXC_"
78 def rollbackData = execution.getVariable("rollbackData")
79 logger.debug("RollbackData:" + rollbackData)
81 if (rollbackData != null) {
82 if (rollbackData.hasType(rbType)) {
84 execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
85 execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
86 execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
89 def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
90 if ("true".equals(rollbackAAI))
92 execution.setVariable("rollbackAAI",true)
93 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
96 def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
97 if ("true".equals(rollbackSDNC))
99 execution.setVariable("rollbackSDNC", true)
100 execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate"))
101 execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate"))
102 execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign"))
104 logger.debug("sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") )
105 logger.debug("sdncDelete:\n" + execution.getVariable("deleteSdnc"))
106 logger.debug("sdncUnassign:\n" + execution.getVariable("unassignSdnc"))
108 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
109 execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq"))
110 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
113 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
115 execution.setVariable("skipRollback", true)
119 execution.setVariable("skipRollback", true)
123 execution.setVariable("skipRollback", true)
125 if (execution.getVariable("disableRollback").equals("true" ))
127 execution.setVariable("skipRollback", true)
131 logger.debug("Rethrowing MSOWorkflowException")
133 } catch (Exception ex){
134 msg = "Exception in preProcessRequest " + ex.getMessage()
136 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
138 logger.trace("end preProcessRequest")
141 // aaiARPath set during query (existing AR)
142 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
145 logger.trace("start updateAaiAROrchStatus")
146 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
147 String aaiARPath = execution.getVariable("aaiARPath")
148 logger.debug(" aaiARPath:" + aaiARPath)
149 Optional<AllottedResource> ar = Optional.empty(); //need this for getting resourceVersion for delete
150 if (!isBlank(aaiARPath))
152 ar = arUtils.getARbyLink(execution, aaiARPath, "")
156 msg = "AR not found in AAI at:" + aaiARPath
158 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
160 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
161 logger.trace("end updateAaiAROrchStatus")
164 public void validateSDNCResp(DelegateExecution execution, String response, String method){
167 logger.trace("start ValidateSDNCResponse Process")
171 WorkflowException workflowException = execution.getVariable("WorkflowException")
172 logger.debug("workflowException: " + workflowException)
174 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
175 logger.debug("SDNCResponse: " + response)
177 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
178 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
180 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
181 logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
185 logger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
186 throw new BpmnError("MSOWorkflowException")
188 } catch (BpmnError e) {
189 if ("404".contentEquals(e.getErrorCode()))
191 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
197 } catch(Exception ex) {
198 msg = "Exception in validateSDNCResp. " + ex.getMessage()
200 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
202 logger.trace("Exit ValidateSDNCResp Process")
205 public void deleteAaiAR(DelegateExecution execution){
208 logger.trace("start deleteAaiAR")
209 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
210 String arLink = execution.getVariable("aaiARPath")
211 arUtils.deleteAR(execution, arLink)
212 } catch (BpmnError e) {
214 }catch(Exception ex){
215 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
216 "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN",
217 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
218 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
220 logger.trace("end deleteAaiAR")
223 public void postProcessRequest(DelegateExecution execution) {
225 logger.trace("start postProcessRequest")
228 execution.setVariable("rollbackData", null)
229 boolean skipRollback = execution.getVariable("skipRollback")
230 if (skipRollback != true)
232 execution.setVariable("rolledBack", true)
233 logger.debug("rolledBack")
235 logger.trace("end postProcessRequest")
237 } catch (BpmnError e) {
239 } catch (Exception ex) {
240 msg = "Exception in postProcessRequest. " + ex.getMessage()
246 public void processRollbackException(DelegateExecution execution){
248 logger.trace("start processRollbackException")
250 logger.debug("Caught an Exception in DoCreateAllottedResourceRollback")
251 execution.setVariable("rollbackData", null)
252 execution.setVariable("rolledBack", false)
253 execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback")
254 execution.setVariable("WorkflowException", null)
257 logger.debug("BPMN Error during processRollbackExceptions Method: ")
259 logger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
262 logger.trace("end processRollbackException")
265 public void processRollbackJavaException(DelegateExecution execution){
267 logger.trace("start processRollbackJavaException")
269 execution.setVariable("rollbackData", null)
270 execution.setVariable("rolledBack", false)
271 execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback")
272 logger.debug("Caught Exception in processRollbackJavaException")
275 logger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
277 logger.trace("end processRollbackJavaException")