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
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.scripts
24 import org.onap.so.logger.LoggingAnchor
25 import org.onap.logging.filter.base.ErrorCode
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.core.json.JsonUtils
30 import org.onap.appc.client.lcm.model.Action;
32 import org.onap.so.logger.MessageEnum
33 import org.slf4j.Logger
34 import org.slf4j.LoggerFactory
36 public class RollbackVnf extends VnfCmBase {
37 private static final Logger logger = LoggerFactory.getLogger( RollbackVnf.class);
39 ExceptionUtil exceptionUtil = new ExceptionUtil()
40 JsonUtils jsonUtils = new JsonUtils()
41 def prefix = "VnfIPU_"
44 * Initialize the flow's variables.
46 * @param execution The flow's execution instance.
48 public void initProcessVariables(DelegateExecution execution) {
49 execution.setVariable('prefix', 'RVnf_')
51 execution.setVariable('rollbackSuccessful', false)
52 execution.setVariable('currentActivity', 'RVnf')
53 execution.setVariable('workStep', null)
54 execution.setVariable('failedActivity', null)
55 execution.setVariable('errorCode', "0")
56 execution.setVariable('actionUnlock', Action.Unlock)
57 execution.setVariable('actionStart', Action.Start)
58 execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
63 * Check for missing elements in the received request.
65 * @param execution The flow's execution instance.
67 public void preProcessRequest(DelegateExecution execution) {
68 def method = getClass().getSimpleName() + '.preProcessRequest(' +
69 'execution=' + execution.getId() +
71 initProcessVariables(execution)
73 logger.trace('Entered ' + method)
75 initProcessVariables(execution)
79 execution.setVariable("rollbackErrorCode", "0")
81 if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
82 logger.debug("Will call setClosedLoopDisabledFlag")
86 logger.trace('Exited ' + method)
90 String restFaultMessage = e.getMessage()
91 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
92 "Exception Encountered - " + "\n" + restFaultMessage, "BPMN",
93 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
94 execution.setVariable("rollbackErrorCode", "1")
95 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
100 * Determine success of rollback execution.
102 * @param execution The flow's execution instance.
104 public void setRollbackResult(DelegateExecution execution) {
105 def method = getClass().getSimpleName() + '.setRollbackResult(' +
106 'execution=' + execution.getId() +
108 initProcessVariables(execution)
110 logger.trace('Entered ' + method)
112 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
113 if (rollbackErrorCode == "0") {
114 execution.setVariable('rollbackSuccessful', true)
115 logger.debug("rollback successful")
118 execution.setVariable('rollbackSuccessful', false)
119 logger.debug("rollback unsuccessful")
122 logger.trace('Exited ' + method)