Merge "version upgrades plus cleanup"
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / RollbackVnf.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
13  *
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=========================================================
20  */
21
22 package org.onap.so.bpmn.infrastructure.scripts
23
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;
31
32 import org.onap.so.logger.MessageEnum
33 import org.slf4j.Logger
34 import org.slf4j.LoggerFactory
35
36 public class RollbackVnf extends VnfCmBase {
37     private static final Logger logger = LoggerFactory.getLogger( RollbackVnf.class);
38
39         ExceptionUtil exceptionUtil = new ExceptionUtil()
40         JsonUtils jsonUtils = new JsonUtils()
41         def prefix = "VnfIPU_"
42
43         /**
44          * Initialize the flow's variables.
45          *
46          * @param execution The flow's execution instance.
47          */
48         public void initProcessVariables(DelegateExecution execution) {
49                 execution.setVariable('prefix', 'RVnf_')
50
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)
59
60         }
61
62         /**
63          * Check for missing elements in the received request.
64          *
65          * @param execution The flow's execution instance.
66          */
67         public void preProcessRequest(DelegateExecution execution) {
68                 def method = getClass().getSimpleName() + '.preProcessRequest(' +
69                 'execution=' + execution.getId() +
70                 ')'
71                 initProcessVariables(execution)
72
73                 logger.trace('Entered ' + method)
74
75                 initProcessVariables(execution)
76
77                 try {
78
79                         execution.setVariable("rollbackErrorCode", "0")
80
81                         if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
82                                 logger.debug("Will call setClosedLoopDisabledFlag")
83                         }
84
85
86                         logger.trace('Exited ' + method)
87
88                 }
89                 catch(Exception e) {
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)
96                 }
97         }
98
99         /**
100          * Determine success of rollback execution.
101          *
102          * @param execution The flow's execution instance.
103          */
104         public void setRollbackResult(DelegateExecution execution) {
105                 def method = getClass().getSimpleName() + '.setRollbackResult(' +
106                 'execution=' + execution.getId() +
107                 ')'
108                 initProcessVariables(execution)
109
110                 logger.trace('Entered ' + method)
111
112                 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
113                 if (rollbackErrorCode == "0") {
114                         execution.setVariable('rollbackSuccessful', true)
115                         logger.debug("rollback successful")
116                 }
117                 else {
118                         execution.setVariable('rollbackSuccessful', false)
119                         logger.debug("rollback unsuccessful")
120                 }
121
122                 logger.trace('Exited ' + method)
123
124         }
125
126 }