22b44c9eaddc5f2f2b368b76c7e510f4b5a18765
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.so.bpmn.infrastructure.scripts
21
22 import groovy.json.JsonOutput
23
24 import groovy.json.JsonSlurper
25 import groovy.util.Node
26 import groovy.util.XmlParser;
27 import groovy.xml.QName
28
29 import java.io.Serializable;
30 import java.util.UUID;
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.camunda.bpm.engine.delegate.BpmnError
33 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd
34 import org.camunda.bpm.engine.delegate.DelegateExecution
35
36 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
37 import org.onap.so.bpmn.common.scripts.VidUtils;
38 import org.onap.so.bpmn.core.RollbackData
39 import org.onap.so.bpmn.core.WorkflowException
40 import org.onap.so.bpmn.common.scripts.ExceptionUtil
41 import org.onap.so.bpmn.core.json.JsonUtils
42 import org.onap.so.bpmn.core.domain.ModelInfo
43 import org.onap.so.bpmn.core.domain.ServiceDecomposition
44 import org.onap.so.bpmn.core.domain.VnfResource
45 import org.onap.so.client.aai.*
46
47 import org.onap.so.client.appc.ApplicationControllerClient;
48 import org.onap.so.client.appc.ApplicationControllerSupport;
49 import org.onap.so.client.aai.AAIResourcesClient
50 import org.onap.so.client.aai.entities.AAIResultWrapper
51 import org.onap.so.client.aai.entities.uri.AAIUri
52 import org.onap.so.client.aai.entities.uri.AAIUriFactory
53 import org.onap.appc.client.lcm.model.Action;
54
55 import org.onap.so.logger.MessageEnum
56 import org.onap.so.logger.MsoLogger
57
58 public class RollbackVnf extends VnfCmBase {
59         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, RollbackVnf.class);
60
61         ExceptionUtil exceptionUtil = new ExceptionUtil()
62         JsonUtils jsonUtils = new JsonUtils()
63         def prefix = "VnfIPU_"
64
65         /**
66          * Initialize the flow's variables.
67          *
68          * @param execution The flow's execution instance.
69          */
70         public void initProcessVariables(DelegateExecution execution) {
71                 execution.setVariable('prefix', 'RVnf_')
72
73                 execution.setVariable('rollbackSuccessful', false)
74                 execution.setVariable('currentActivity', 'RVnf')
75                 execution.setVariable('workStep', null)
76                 execution.setVariable('failedActivity', null)
77                 execution.setVariable('errorCode', "0")
78                 execution.setVariable('actionUnlock', Action.Unlock)
79                 execution.setVariable('actionStart', Action.Start)
80                 execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
81
82         }
83
84         /**
85          * Check for missing elements in the received request.
86          *
87          * @param execution The flow's execution instance.
88          */
89         public void preProcessRequest(DelegateExecution execution) {
90                 def method = getClass().getSimpleName() + '.preProcessRequest(' +
91                 'execution=' + execution.getId() +
92                 ')'
93                 initProcessVariables(execution)
94
95                 msoLogger.trace('Entered ' + method)
96
97                 initProcessVariables(execution)
98
99                 try {
100
101                         execution.setVariable("rollbackErrorCode", "0")
102
103                         if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
104                                 msoLogger.debug("Will call setClosedLoopDisabledFlag")
105                         }
106
107
108                         msoLogger.trace('Exited ' + method)
109
110                 }
111                 catch(Exception e) {
112                         String restFaultMessage = e.getMessage()
113                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, " Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
114                         execution.setVariable("rollbackErrorCode", "1")
115                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
116                 }
117         }
118
119         /**
120          * Determine success of rollback execution.
121          *
122          * @param execution The flow's execution instance.
123          */
124         public void setRollbackResult(DelegateExecution execution) {
125                 def method = getClass().getSimpleName() + '.setRollbackResult(' +
126                 'execution=' + execution.getId() +
127                 ')'
128                 initProcessVariables(execution)
129
130                 msoLogger.trace('Entered ' + method)
131
132                 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
133                 if (rollbackErrorCode == "0") {
134                         execution.setVariable('rollbackSuccessful', true)
135                         msoLogger.debug("rollback successful")
136                 }
137                 else {
138                         execution.setVariable('rollbackSuccessful', false)
139                         msoLogger.debug("rollback unsuccessful")
140                 }
141
142                 msoLogger.trace('Exited ' + method)
143
144         }
145
146 }