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