2 * ============LICENSE_START=======================================================
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
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=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts
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
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.*
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
67 public class RollbackVnf extends VnfCmBase {
69 ExceptionUtil exceptionUtil = new ExceptionUtil()
70 JsonUtils jsonUtils = new JsonUtils()
71 def prefix = "VnfIPU_"
74 * Initialize the flow's variables.
76 * @param execution The flow's execution instance.
78 public void initProcessVariables(DelegateExecution execution) {
79 execution.setVariable('prefix', 'RVnf_')
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)
93 * Check for missing elements in the received request.
95 * @param execution The flow's execution instance.
97 public void preProcessRequest(DelegateExecution execution) {
98 def method = getClass().getSimpleName() + '.preProcessRequest(' +
99 'execution=' + execution.getId() +
101 initProcessVariables(execution)
102 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
103 logDebug('Entered ' + method, isDebugLogEnabled)
105 initProcessVariables(execution)
109 execution.setVariable("rollbackErrorCode", "0")
111 if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
112 logDebug("Will call setClosedLoopDisabledFlag", isDebugLogEnabled)
116 logDebug('Exited ' + method, isDebugLogEnabled)
120 String restFaultMessage = e.getMessage()
121 utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
122 execution.setVariable("rollbackErrorCode", "1")
127 * Determine success of rollback execution.
129 * @param execution The flow's execution instance.
131 public void setRollbackResult(DelegateExecution execution) {
132 def method = getClass().getSimpleName() + '.setRollbackResult(' +
133 'execution=' + execution.getId() +
135 initProcessVariables(execution)
136 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
137 logDebug('Entered ' + method, isDebugLogEnabled)
139 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
140 if (rollbackErrorCode == "0") {
141 execution.setVariable('rollbackSuccessful', true)
142 logDebug("rollback successful", isDebugLogEnabled)
145 execution.setVariable('rollbackSuccessful', false)
146 logDebug("rollback unsuccessful", isDebugLogEnabled)
149 logDebug('Exited ' + method, isDebugLogEnabled)