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
35 import org.onap.so.rest.APIResponse
36 import org.onap.so.rest.RESTClient
37 import org.onap.so.rest.RESTConfig
38 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
39 import org.onap.so.bpmn.common.scripts.VidUtils;
40 import org.onap.so.bpmn.core.RollbackData
41 import org.onap.so.bpmn.core.WorkflowException
42 import org.onap.so.bpmn.common.scripts.ExceptionUtil
43 import org.onap.so.bpmn.core.json.JsonUtils
44 import org.onap.so.bpmn.core.domain.ModelInfo
45 import org.onap.so.bpmn.core.domain.ServiceDecomposition
46 import org.onap.so.bpmn.core.domain.VnfResource
47 import org.onap.so.client.aai.*
49 import org.onap.so.client.appc.ApplicationControllerClient;
50 import org.onap.so.client.appc.ApplicationControllerSupport;
51 import org.onap.so.client.aai.AAIResourcesClient
52 import org.onap.so.client.aai.entities.AAIResultWrapper
53 import org.onap.so.client.aai.entities.uri.AAIUri
54 import org.onap.so.client.aai.entities.uri.AAIUriFactory
55 import org.onap.appc.client.lcm.model.Action;
57 import org.onap.so.logger.MessageEnum
58 import org.onap.so.logger.MsoLogger
60 public class RollbackVnf extends VnfCmBase {
61 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, RollbackVnf.class);
63 ExceptionUtil exceptionUtil = new ExceptionUtil()
64 JsonUtils jsonUtils = new JsonUtils()
65 def prefix = "VnfIPU_"
68 * Initialize the flow's variables.
70 * @param execution The flow's execution instance.
72 public void initProcessVariables(DelegateExecution execution) {
73 execution.setVariable('prefix', 'RVnf_')
75 execution.setVariable('rollbackSuccessful', false)
76 execution.setVariable('currentActivity', 'RVnf')
77 execution.setVariable('workStep', null)
78 execution.setVariable('failedActivity', null)
79 execution.setVariable('errorCode', "0")
80 execution.setVariable('actionUnlock', Action.Unlock)
81 execution.setVariable('actionStart', Action.Start)
82 execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
87 * Check for missing elements in the received request.
89 * @param execution The flow's execution instance.
91 public void preProcessRequest(DelegateExecution execution) {
92 def method = getClass().getSimpleName() + '.preProcessRequest(' +
93 'execution=' + execution.getId() +
95 initProcessVariables(execution)
97 msoLogger.trace('Entered ' + method)
99 initProcessVariables(execution)
103 execution.setVariable("rollbackErrorCode", "0")
105 if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
106 msoLogger.debug("Will call setClosedLoopDisabledFlag")
110 msoLogger.trace('Exited ' + method)
114 String restFaultMessage = e.getMessage()
115 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, " Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
116 execution.setVariable("rollbackErrorCode", "1")
117 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
122 * Determine success of rollback execution.
124 * @param execution The flow's execution instance.
126 public void setRollbackResult(DelegateExecution execution) {
127 def method = getClass().getSimpleName() + '.setRollbackResult(' +
128 'execution=' + execution.getId() +
130 initProcessVariables(execution)
132 msoLogger.trace('Entered ' + method)
134 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
135 if (rollbackErrorCode == "0") {
136 execution.setVariable('rollbackSuccessful', true)
137 msoLogger.debug("rollback successful")
140 execution.setVariable('rollbackSuccessful', false)
141 msoLogger.debug("rollback unsuccessful")
144 msoLogger.trace('Exited ' + method)