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