Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / 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  * 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 import org.onap.so.rest.APIResponse
36 import org.onap.so.rest.RESTClient
37 import org.onap.so.rest.RESTConfig
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
60 public class RollbackVnf extends VnfCmBase {
61         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, RollbackVnf.class);
62
63         ExceptionUtil exceptionUtil = new ExceptionUtil()
64         JsonUtils jsonUtils = new JsonUtils()   
65         def prefix = "VnfIPU_"
66
67         /**
68          * Initialize the flow's variables.
69          *
70          * @param execution The flow's execution instance.
71          */
72         public void initProcessVariables(DelegateExecution execution) {
73                 execution.setVariable('prefix', 'RVnf_')
74                 
75                 execution.setVariable('rollbackSuccessful', false)              
76                 execution.setVariable('currentActivity', 'RVnf')
77                 execution.setVariable('workStep', null)
78                 execution.setVariable('failedActivity', null)
79                 execution.setVariable('errorCode', "0")         
80                 execution.setVariable('actionUnlock', Action.Unlock)    
81                 execution.setVariable('actionStart', Action.Start)
82                 execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
83                 
84         }
85
86         /**
87          * Check for missing elements in the received request.
88          *
89          * @param execution The flow's execution instance.
90          */
91         public void preProcessRequest(DelegateExecution execution) {
92                 def method = getClass().getSimpleName() + '.preProcessRequest(' +
93                 'execution=' + execution.getId() +
94                 ')'
95                 initProcessVariables(execution)
96
97                 msoLogger.trace('Entered ' + method)
98
99                 initProcessVariables(execution)
100                 
101                 try {
102                 
103                         execution.setVariable("rollbackErrorCode", "0")
104                         
105                         if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
106                                 msoLogger.debug("Will call setClosedLoopDisabledFlag")
107                         }                       
108
109                 
110                         msoLogger.trace('Exited ' + method)
111
112                 }
113                 catch(Exception e) {
114                         String restFaultMessage = e.getMessage()
115                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, " Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
116                         execution.setVariable("rollbackErrorCode", "1")
117                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
118                 }       
119         }
120         
121         /**
122          * Determine success of rollback execution.
123          *
124          * @param execution The flow's execution instance.
125          */
126         public void setRollbackResult(DelegateExecution execution) {
127                 def method = getClass().getSimpleName() + '.setRollbackResult(' +
128                 'execution=' + execution.getId() +
129                 ')'
130                 initProcessVariables(execution)
131
132                 msoLogger.trace('Entered ' + method)
133                 
134                 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
135                 if (rollbackErrorCode == "0") {
136                         execution.setVariable('rollbackSuccessful', true)
137                         msoLogger.debug("rollback successful")
138                 }
139                 else {
140                         execution.setVariable('rollbackSuccessful', false)
141                         msoLogger.debug("rollback unsuccessful")
142                 }
143                 
144                 msoLogger.trace('Exited ' + method)     
145                 
146         }       
147         
148 }