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.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.AllottedResource
26 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.onap.so.bpmn.common.scripts.AllottedResourceUtils
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
30 import org.onap.so.bpmn.core.WorkflowException
31 import org.onap.so.logger.MessageEnum
32 import org.onap.so.logger.MsoLogger
34 import static org.apache.commons.lang3.StringUtils.isBlank
37 * This groovy class supports the <class>CreateAllottedResourceBRGRollback.bpmn</class> process.
42 * @param - msoRequestId
43 * @param - isDebugLogEnabled
44 * @param - disableRollback - O
45 * @param - rollbackData
48 * @param - rollbackError
49 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
52 public class DoCreateAllottedResourceBRGRollback extends AbstractServiceTaskProcessor{
53 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateAllottedResourceBRGRollback.class);
55 String Prefix="DCARBRGRB_"
56 ExceptionUtil exceptionUtil = new ExceptionUtil()
58 public void preProcessRequest (DelegateExecution execution) {
62 msoLogger.trace("start preProcessRequest")
63 execution.setVariable("prefix", Prefix)
64 String rbType = "DCARBRG_"
67 def rollbackData = execution.getVariable("rollbackData")
68 msoLogger.debug("RollbackData:" + rollbackData)
70 if (rollbackData != null) {
71 if (rollbackData.hasType(rbType)) {
73 execution.setVariable("serviceInstanceId", rollbackData.get(rbType, "serviceInstanceId"))
74 execution.setVariable("parentServiceInstanceId", rollbackData.get(rbType, "parentServiceInstanceId"))
75 execution.setVariable("allottedResourceId", rollbackData.get("SERVICEINSTANCE", "allottedResourceId"))
78 def rollbackAAI = rollbackData.get(rbType, "rollbackAAI")
79 if ("true".equals(rollbackAAI))
81 execution.setVariable("rollbackAAI",true)
82 execution.setVariable("aaiARPath", rollbackData.get(rbType, "aaiARPath"))
85 def rollbackSDNC = rollbackData.get(rbType, "rollbackSDNCassign")
86 if ("true".equals(rollbackSDNC))
88 execution.setVariable("rollbackSDNC", true)
89 execution.setVariable("deactivateSdnc", rollbackData.get(rbType, "rollbackSDNCactivate"))
90 execution.setVariable("deleteSdnc", rollbackData.get(rbType, "rollbackSDNCcreate"))
91 execution.setVariable("unassignSdnc", rollbackData.get(rbType, "rollbackSDNCassign"))
93 msoLogger.debug("sdncDeactivate:\n" + execution.getVariable("deactivateSdnc") )
94 msoLogger.debug("sdncDelete:\n" + execution.getVariable("deleteSdnc"))
95 msoLogger.debug("sdncUnassign:\n" + execution.getVariable("unassignSdnc"))
97 execution.setVariable("sdncDeactivateRequest", rollbackData.get(rbType, "sdncActivateRollbackReq"))
98 execution.setVariable("sdncDeleteRequest", rollbackData.get(rbType, "sdncCreateRollbackReq"))
99 execution.setVariable("sdncUnassignRequest", rollbackData.get(rbType, "sdncAssignRollbackReq"))
102 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)
104 execution.setVariable("skipRollback", true)
108 execution.setVariable("skipRollback", true)
112 execution.setVariable("skipRollback", true)
114 if (execution.getVariable("disableRollback").equals("true" ))
116 execution.setVariable("skipRollback", true)
120 msoLogger.debug("Rethrowing MSOWorkflowException")
122 } catch (Exception ex){
123 msg = "Exception in preProcessRequest " + ex.getMessage()
125 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
127 msoLogger.trace("end preProcessRequest")
130 // aaiARPath set during query (existing AR)
131 public void updateAaiAROrchStatus(DelegateExecution execution, String status){
134 msoLogger.trace("start updateAaiAROrchStatus")
135 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
136 String aaiARPath = execution.getVariable("aaiARPath")
137 msoLogger.debug(" aaiARPath:" + aaiARPath)
138 Optional<AllottedResource> ar = Optional.empty(); //need this for getting resourceVersion for delete
139 if (!isBlank(aaiARPath))
141 ar = arUtils.getARbyLink(execution, aaiARPath, "")
145 msg = "AR not found in AAI at:" + aaiARPath
147 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
149 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
150 msoLogger.trace("end updateAaiAROrchStatus")
153 public void validateSDNCResp(DelegateExecution execution, String response, String method){
156 msoLogger.trace("start ValidateSDNCResponse Process")
160 WorkflowException workflowException = execution.getVariable("WorkflowException")
161 msoLogger.debug("workflowException: " + workflowException)
163 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
164 msoLogger.debug("SDNCResponse: " + response)
166 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
167 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
169 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
170 msoLogger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response)
174 msoLogger.debug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.")
175 throw new BpmnError("MSOWorkflowException")
177 } catch (BpmnError e) {
178 if ("404".contentEquals(e.getErrorCode()))
180 msg = "SDNC rollback " + method + " returned a 404. Proceding with rollback"
186 } catch(Exception ex) {
187 msg = "Exception in validateSDNCResp. " + ex.getMessage()
189 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
191 msoLogger.trace("end ValidateSDNCResp Process")
194 public void deleteAaiAR(DelegateExecution execution){
197 msoLogger.trace("start deleteAaiAR")
198 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
199 String arLink = execution.getVariable("aaiARPath")
200 arUtils.deleteAR(execution, arLink )
201 } catch (BpmnError e) {
203 }catch(Exception ex){
204 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occurred Processing preProcessSDNCGetRequest.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + ex);
205 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
207 msoLogger.trace("end deleteAaiAR")
210 public void postProcessRequest(DelegateExecution execution) {
212 msoLogger.trace("start postProcessRequest")
215 execution.setVariable("rollbackData", null)
216 boolean skipRollback = execution.getVariable("skipRollback")
217 if (skipRollback != true)
219 execution.setVariable("rolledBack", true)
220 msoLogger.debug("rolledBack")
222 msoLogger.trace("end postProcessRequest")
224 } catch (BpmnError e) {
225 msg = "Bpmn Exception in postProcessRequest. "
227 } catch (Exception ex) {
228 msg = "Exception in postProcessRequest. " + ex.getMessage()
234 public void processRollbackException(DelegateExecution execution){
236 msoLogger.trace("start processRollbackException")
238 msoLogger.debug("Caught an Exception in DoCreateAllottedResourceRollback")
239 execution.setVariable("rollbackData", null)
240 execution.setVariable("rolledBack", false)
241 execution.setVariable("rollbackError", "Caught exception in AllottedResource Create Rollback")
242 execution.setVariable("WorkflowException", null)
245 msoLogger.debug("BPMN Error during processRollbackExceptions Method: ")
247 msoLogger.debug("Caught Exception during processRollbackExceptions Method: " + e.getMessage())
250 msoLogger.trace("end processRollbackException")
253 public void processRollbackJavaException(DelegateExecution execution){
255 msoLogger.trace("start processRollbackJavaException")
257 execution.setVariable("rollbackData", null)
258 execution.setVariable("rolledBack", false)
259 execution.setVariable("rollbackError", "Caught Java exception in AllottedResource Create Rollback")
260 msoLogger.debug("Caught Exception in processRollbackJavaException")
263 msoLogger.debug("Caught Exception in processRollbackJavaException " + e.getMessage())
265 msoLogger.trace("end processRollbackJavaException")