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.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.*
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
65 public class RollbackVnf extends VnfCmBase {
67 ExceptionUtil exceptionUtil = new ExceptionUtil()
68 JsonUtils jsonUtils = new JsonUtils()
69 def prefix = "VnfIPU_"
72 * Initialize the flow's variables.
74 * @param execution The flow's execution instance.
76 public void initProcessVariables(DelegateExecution execution) {
77 execution.setVariable('prefix', 'RVnf_')
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)
91 * Check for missing elements in the received request.
93 * @param execution The flow's execution instance.
95 public void preProcessRequest(DelegateExecution execution) {
96 def method = getClass().getSimpleName() + '.preProcessRequest(' +
97 'execution=' + execution.getId() +
99 initProcessVariables(execution)
100 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
101 logDebug('Entered ' + method, isDebugLogEnabled)
103 initProcessVariables(execution)
107 execution.setVariable("rollbackErrorCode", "0")
109 if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
110 logDebug("Will call setClosedLoopDisabledFlag", isDebugLogEnabled)
114 logDebug('Exited ' + method, isDebugLogEnabled)
118 String restFaultMessage = e.getMessage()
119 utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
120 execution.setVariable("rollbackErrorCode", "1")
125 * Determine success of rollback execution.
127 * @param execution The flow's execution instance.
129 public void setRollbackResult(DelegateExecution execution) {
130 def method = getClass().getSimpleName() + '.setRollbackResult(' +
131 'execution=' + execution.getId() +
133 initProcessVariables(execution)
134 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
135 logDebug('Entered ' + method, isDebugLogEnabled)
137 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
138 if (rollbackErrorCode == "0") {
139 execution.setVariable('rollbackSuccessful', true)
140 logDebug("rollback successful", isDebugLogEnabled)
143 execution.setVariable('rollbackSuccessful', false)
144 logDebug("rollback unsuccessful", isDebugLogEnabled)
147 logDebug('Exited ' + method, isDebugLogEnabled)