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.onap.so.bpmn.infrastructure.scripts
22 import groovy.json.JsonOutput
24 import groovy.json.JsonSlurper
25 import groovy.util.Node
26 import groovy.util.XmlParser;
27 import groovy.xml.QName
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
36 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
37 import org.onap.so.bpmn.common.scripts.VidUtils;
38 import org.onap.so.bpmn.core.RollbackData
39 import org.onap.so.bpmn.core.WorkflowException
40 import org.onap.so.bpmn.common.scripts.ExceptionUtil
41 import org.onap.so.bpmn.core.json.JsonUtils
42 import org.onap.so.bpmn.core.domain.ModelInfo
43 import org.onap.so.bpmn.core.domain.ServiceDecomposition
44 import org.onap.so.bpmn.core.domain.VnfResource
45 import org.onap.so.client.aai.*
47 import org.onap.so.client.appc.ApplicationControllerClient;
48 import org.onap.so.client.appc.ApplicationControllerSupport;
49 import org.onap.so.client.aai.AAIResourcesClient
50 import org.onap.so.client.aai.entities.AAIResultWrapper
51 import org.onap.so.client.aai.entities.uri.AAIUri
52 import org.onap.so.client.aai.entities.uri.AAIUriFactory
53 import org.onap.appc.client.lcm.model.Action;
55 import org.onap.so.logger.MessageEnum
56 import org.onap.so.logger.MsoLogger
58 public class RollbackVnf extends VnfCmBase {
59 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, RollbackVnf.class);
61 ExceptionUtil exceptionUtil = new ExceptionUtil()
62 JsonUtils jsonUtils = new JsonUtils()
63 def prefix = "VnfIPU_"
66 * Initialize the flow's variables.
68 * @param execution The flow's execution instance.
70 public void initProcessVariables(DelegateExecution execution) {
71 execution.setVariable('prefix', 'RVnf_')
73 execution.setVariable('rollbackSuccessful', false)
74 execution.setVariable('currentActivity', 'RVnf')
75 execution.setVariable('workStep', null)
76 execution.setVariable('failedActivity', null)
77 execution.setVariable('errorCode', "0")
78 execution.setVariable('actionUnlock', Action.Unlock)
79 execution.setVariable('actionStart', Action.Start)
80 execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
85 * Check for missing elements in the received request.
87 * @param execution The flow's execution instance.
89 public void preProcessRequest(DelegateExecution execution) {
90 def method = getClass().getSimpleName() + '.preProcessRequest(' +
91 'execution=' + execution.getId() +
93 initProcessVariables(execution)
95 msoLogger.trace('Entered ' + method)
97 initProcessVariables(execution)
101 execution.setVariable("rollbackErrorCode", "0")
103 if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
104 msoLogger.debug("Will call setClosedLoopDisabledFlag")
108 msoLogger.trace('Exited ' + method)
112 String restFaultMessage = e.getMessage()
113 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, " Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
114 execution.setVariable("rollbackErrorCode", "1")
115 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
120 * Determine success of rollback execution.
122 * @param execution The flow's execution instance.
124 public void setRollbackResult(DelegateExecution execution) {
125 def method = getClass().getSimpleName() + '.setRollbackResult(' +
126 'execution=' + execution.getId() +
128 initProcessVariables(execution)
130 msoLogger.trace('Entered ' + method)
132 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
133 if (rollbackErrorCode == "0") {
134 execution.setVariable('rollbackSuccessful', true)
135 msoLogger.debug("rollback successful")
138 execution.setVariable('rollbackSuccessful', false)
139 msoLogger.debug("rollback unsuccessful")
142 msoLogger.trace('Exited ' + method)