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.aai.domain.yang.AllottedResource;
24 import org.onap.so.bpmn.common.scripts.*;
25 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.onap.so.bpmn.core.WorkflowException
27 import org.onap.so.bpmn.common.scripts.ExceptionUtil
28 import org.onap.so.bpmn.common.scripts.MsoUtils
29 import org.onap.so.bpmn.common.scripts.AaiUtil
30 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
31 import org.onap.so.rest.APIResponse
33 import java.util.UUID;
34 import org.camunda.bpm.engine.delegate.BpmnError
35 import org.camunda.bpm.engine.delegate.DelegateExecution
36 import org.apache.commons.lang3.*
37 import org.springframework.web.util.UriUtils;
38 import static org.apache.commons.lang3.StringUtils.*
40 import org.onap.so.logger.MessageEnum
41 import org.onap.so.logger.MsoLogger
44 * This groovy class supports the <class>CreateAllottedResourceTXCRollback.bpmn</class> process.
49 * @param - msoRequestId
50 * @param - isDebugLogEnabled
51 * @param - disableRollback - O
52 * @param - rollbackData
55 * @param - rollbackError
56 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
59 public class DoCreateAllottedResourceTXCRollback extends AbstractServiceTaskProcessor{
60 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateAllottedResourceTXCRollback.class);
62 String Prefix="DCARTXCRB_"
63 ExceptionUtil exceptionUtil = new ExceptionUtil()
65 public void preProcessRequest (DelegateExecution execution) {
69 msoLogger.trace("start preProcessRequest")
70 execution.setVariable("prefix", Prefix)
71 String rbType = "DCARTXC_"
74 def rollbackData = execution.getVariable("rollbackData")
75 msoLogger.debug("RollbackData:" + rollbackData)
77 if (rollbackData != null) {
78 if (rollbackData.hasType(rbType)) {
80 execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
81 execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
82 execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
85 def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
86 if ("true".equals(rollbackAAI))
88 execution.setVariable("rollbackAAI",true)
89 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
92 def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
93 if ("true".equals(rollbackSDNC))
95 execution.setVariable("rollbackSDNC", true)
96 execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate"))
97 execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate"))
98 execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign"))
100 msoLogger.debug("sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") )
101 msoLogger.debug("sdncDelete:\n" + execution.getVariable("deleteSdnc"))
102 msoLogger.debug("sdncUnassign:\n" + execution.getVariable("unassignSdnc"))
104 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
105 execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq"))
106 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
109 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
111 execution.setVariable("skipRollback", true)
115 execution.setVariable("skipRollback", true)
119 execution.setVariable("skipRollback", true)
121 if (execution.getVariable("disableRollback").equals("true" ))
123 execution.setVariable("skipRollback", true)
127 msoLogger.debug("Rethrowing MSOWorkflowException")
129 } catch (Exception ex){
130 msg = "Exception in preProcessRequest " + ex.getMessage()
132 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
134 msoLogger.trace("end preProcessRequest")
137 // aaiARPath set during query (existing AR)
138 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
141 msoLogger.trace("start updateAaiAROrchStatus")
142 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
143 String aaiARPath = execution.getVariable("aaiARPath")
144 msoLogger.debug(" aaiARPath:" + aaiARPath)
145 Optional<AllottedResource> ar = Optional.empty(); //need this for getting resourceVersion for delete
146 if (!isBlank(aaiARPath))
148 ar = arUtils.getARbyLink(execution, aaiARPath, "")
152 msg = "AR not found in AAI at:" + aaiARPath
154 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
156 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
157 msoLogger.trace("end updateAaiAROrchStatus")
160 public void validateSDNCResp(DelegateExecution execution, String response, String method){
163 msoLogger.trace("start ValidateSDNCResponse Process")
167 WorkflowException workflowException = execution.getVariable("WorkflowException")
168 msoLogger.debug("workflowException: " + workflowException)
170 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
171 msoLogger.debug("SDNCResponse: " + response)
173 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
174 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
176 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
177 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
181 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
182 throw new BpmnError("MSOWorkflowException")
184 } catch (BpmnError e) {
185 if ("404".contentEquals(e.getErrorCode()))
187 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
193 } catch(Exception ex) {
194 msg = "Exception in validateSDNCResp. " + ex.getMessage()
196 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
198 msoLogger.trace("Exit ValidateSDNCResp Process")
201 public void deleteAaiAR(DelegateExecution execution){
204 msoLogger.trace("start deleteAaiAR")
205 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
206 String arLink = execution.getVariable("aaiARPath")
207 arUtils.deleteAR(execution, arLink)
208 } catch (BpmnError e) {
210 }catch(Exception ex){
211 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + ex);
212 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
214 msoLogger.trace("end deleteAaiAR")
217 public void postProcessRequest(DelegateExecution execution) {
219 msoLogger.trace("start postProcessRequest")
222 execution.setVariable("rollbackData", null)
223 boolean skipRollback = execution.getVariable("skipRollback")
224 if (skipRollback != true)
226 execution.setVariable("rolledBack", true)
227 msoLogger.debug("rolledBack")
229 msoLogger.trace("end postProcessRequest")
231 } catch (BpmnError e) {
233 } catch (Exception ex) {
234 msg = "Exception in postProcessRequest. " + ex.getMessage()
240 public void processRollbackException(DelegateExecution execution){
242 msoLogger.trace("start processRollbackException")
244 msoLogger.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 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
253 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
256 msoLogger.trace("end processRollbackException")
259 public void processRollbackJavaException(DelegateExecution execution){
261 msoLogger.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 msoLogger.debug("Caught Exception in processRollbackJavaException")
269 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
271 msoLogger.trace("end processRollbackJavaException")