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.ErrorCode
25 import org.onap.so.bpmn.common.scripts.ExceptionUtil
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.ExceptionUtil
28 import org.onap.so.bpmn.core.json.JsonUtils
29 import org.onap.appc.client.lcm.model.Action;
31 import org.onap.so.logger.MessageEnum
32 import org.slf4j.Logger
33 import org.slf4j.LoggerFactory
35 public class RollbackVnf extends VnfCmBase {
36 private static final Logger logger = LoggerFactory.getLogger( RollbackVnf.class);
38 ExceptionUtil exceptionUtil = new ExceptionUtil()
39 JsonUtils jsonUtils = new JsonUtils()
40 def prefix = "VnfIPU_"
43 * Initialize the flow's variables.
45 * @param execution The flow's execution instance.
47 public void initProcessVariables(DelegateExecution execution) {
48 execution.setVariable('prefix', 'RVnf_')
50 execution.setVariable('rollbackSuccessful', false)
51 execution.setVariable('currentActivity', 'RVnf')
52 execution.setVariable('workStep', null)
53 execution.setVariable('failedActivity', null)
54 execution.setVariable('errorCode', "0")
55 execution.setVariable('actionUnlock', Action.Unlock)
56 execution.setVariable('actionStart', Action.Start)
57 execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
62 * Check for missing elements in the received request.
64 * @param execution The flow's execution instance.
66 public void preProcessRequest(DelegateExecution execution) {
67 def method = getClass().getSimpleName() + '.preProcessRequest(' +
68 'execution=' + execution.getId() +
70 initProcessVariables(execution)
72 logger.trace('Entered ' + method)
74 initProcessVariables(execution)
78 execution.setVariable("rollbackErrorCode", "0")
80 if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
81 logger.debug("Will call setClosedLoopDisabledFlag")
85 logger.trace('Exited ' + method)
89 String restFaultMessage = e.getMessage()
90 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
91 "Exception Encountered - " + "\n" + restFaultMessage, "BPMN",
92 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
93 execution.setVariable("rollbackErrorCode", "1")
94 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
99 * Determine success of rollback execution.
101 * @param execution The flow's execution instance.
103 public void setRollbackResult(DelegateExecution execution) {
104 def method = getClass().getSimpleName() + '.setRollbackResult(' +
105 'execution=' + execution.getId() +
107 initProcessVariables(execution)
109 logger.trace('Entered ' + method)
111 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
112 if (rollbackErrorCode == "0") {
113 execution.setVariable('rollbackSuccessful', true)
114 logger.debug("rollback successful")
117 execution.setVariable('rollbackSuccessful', false)
118 logger.debug("rollback unsuccessful")
121 logger.trace('Exited ' + method)