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