5b0b92415d74b3912ab848906183dc295dbe05d5
[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 groovy.json.JsonOutput
25
26 import groovy.json.JsonSlurper
27 import groovy.util.Node
28 import groovy.util.XmlParser;
29 import groovy.xml.QName
30
31 import java.io.Serializable;
32 import java.util.UUID;
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.camunda.bpm.engine.delegate.BpmnError
35 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd
36 import org.camunda.bpm.engine.delegate.DelegateExecution
37
38 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
39 import org.onap.so.bpmn.common.scripts.VidUtils;
40 import org.onap.so.bpmn.core.RollbackData
41 import org.onap.so.bpmn.core.WorkflowException
42 import org.onap.so.bpmn.common.scripts.ExceptionUtil
43 import org.onap.so.bpmn.core.json.JsonUtils
44 import org.onap.so.bpmn.core.domain.ModelInfo
45 import org.onap.so.bpmn.core.domain.ServiceDecomposition
46 import org.onap.so.bpmn.core.domain.VnfResource
47 import org.onap.so.client.aai.*
48
49 import org.onap.so.client.appc.ApplicationControllerClient;
50 import org.onap.so.client.appc.ApplicationControllerSupport;
51 import org.onap.so.client.aai.AAIResourcesClient
52 import org.onap.so.client.aai.entities.AAIResultWrapper
53 import org.onap.so.client.aai.entities.uri.AAIUri
54 import org.onap.so.client.aai.entities.uri.AAIUriFactory
55 import org.onap.appc.client.lcm.model.Action;
56
57 import org.onap.so.logger.MessageEnum
58 import org.onap.so.logger.MsoLogger
59 import org.slf4j.Logger
60 import org.slf4j.LoggerFactory
61
62 public class RollbackVnf extends VnfCmBase {
63     private static final Logger logger = LoggerFactory.getLogger( RollbackVnf.class);
64
65         ExceptionUtil exceptionUtil = new ExceptionUtil()
66         JsonUtils jsonUtils = new JsonUtils()
67         def prefix = "VnfIPU_"
68
69         /**
70          * Initialize the flow's variables.
71          *
72          * @param execution The flow's execution instance.
73          */
74         public void initProcessVariables(DelegateExecution execution) {
75                 execution.setVariable('prefix', 'RVnf_')
76
77                 execution.setVariable('rollbackSuccessful', false)
78                 execution.setVariable('currentActivity', 'RVnf')
79                 execution.setVariable('workStep', null)
80                 execution.setVariable('failedActivity', null)
81                 execution.setVariable('errorCode', "0")
82                 execution.setVariable('actionUnlock', Action.Unlock)
83                 execution.setVariable('actionStart', Action.Start)
84                 execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
85
86         }
87
88         /**
89          * Check for missing elements in the received request.
90          *
91          * @param execution The flow's execution instance.
92          */
93         public void preProcessRequest(DelegateExecution execution) {
94                 def method = getClass().getSimpleName() + '.preProcessRequest(' +
95                 'execution=' + execution.getId() +
96                 ')'
97                 initProcessVariables(execution)
98
99                 logger.trace('Entered ' + method)
100
101                 initProcessVariables(execution)
102
103                 try {
104
105                         execution.setVariable("rollbackErrorCode", "0")
106
107                         if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
108                                 logger.debug("Will call setClosedLoopDisabledFlag")
109                         }
110
111
112                         logger.trace('Exited ' + method)
113
114                 }
115                 catch(Exception e) {
116                         String restFaultMessage = e.getMessage()
117                         logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
118                                         "Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(),
119                                         MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
120                         execution.setVariable("rollbackErrorCode", "1")
121                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
122                 }
123         }
124
125         /**
126          * Determine success of rollback execution.
127          *
128          * @param execution The flow's execution instance.
129          */
130         public void setRollbackResult(DelegateExecution execution) {
131                 def method = getClass().getSimpleName() + '.setRollbackResult(' +
132                 'execution=' + execution.getId() +
133                 ')'
134                 initProcessVariables(execution)
135
136                 logger.trace('Entered ' + method)
137
138                 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
139                 if (rollbackErrorCode == "0") {
140                         execution.setVariable('rollbackSuccessful', true)
141                         logger.debug("rollback successful")
142                 }
143                 else {
144                         execution.setVariable('rollbackSuccessful', false)
145                         logger.debug("rollback unsuccessful")
146                 }
147
148                 logger.trace('Exited ' + method)
149
150         }
151
152 }