2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.scripts
24 import groovy.json.JsonOutput
26 import groovy.json.JsonSlurper
27 import groovy.util.Node
28 import groovy.util.XmlParser;
29 import groovy.xml.QName
31 import java.io.Serializable;
32 import java.util.UUID;
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.camunda.bpm.engine.delegate.BpmnError
35 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd
36 import org.camunda.bpm.engine.delegate.DelegateExecution
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
59 import org.slf4j.Logger
60 import org.slf4j.LoggerFactory
62 public class RollbackVnf extends VnfCmBase {
63 private static final Logger logger = LoggerFactory.getLogger( RollbackVnf.class);
65 ExceptionUtil exceptionUtil = new ExceptionUtil()
66 JsonUtils jsonUtils = new JsonUtils()
67 def prefix = "VnfIPU_"
70 * Initialize the flow's variables.
72 * @param execution The flow's execution instance.
74 public void initProcessVariables(DelegateExecution execution) {
75 execution.setVariable('prefix', 'RVnf_')
77 execution.setVariable('rollbackSuccessful', false)
78 execution.setVariable('currentActivity', 'RVnf')
79 execution.setVariable('workStep', null)
80 execution.setVariable('failedActivity', null)
81 execution.setVariable('errorCode', "0")
82 execution.setVariable('actionUnlock', Action.Unlock)
83 execution.setVariable('actionStart', Action.Start)
84 execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
89 * Check for missing elements in the received request.
91 * @param execution The flow's execution instance.
93 public void preProcessRequest(DelegateExecution execution) {
94 def method = getClass().getSimpleName() + '.preProcessRequest(' +
95 'execution=' + execution.getId() +
97 initProcessVariables(execution)
99 logger.trace('Entered ' + method)
101 initProcessVariables(execution)
105 execution.setVariable("rollbackErrorCode", "0")
107 if (execution.getVariable("rollbackSetClosedLoopDisabledFlag") == true) {
108 logger.debug("Will call setClosedLoopDisabledFlag")
112 logger.trace('Exited ' + method)
116 String restFaultMessage = e.getMessage()
117 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
118 "Exception Encountered - " + "\n" + restFaultMessage, "BPMN",
119 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
120 execution.setVariable("rollbackErrorCode", "1")
121 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
126 * Determine success of rollback execution.
128 * @param execution The flow's execution instance.
130 public void setRollbackResult(DelegateExecution execution) {
131 def method = getClass().getSimpleName() + '.setRollbackResult(' +
132 'execution=' + execution.getId() +
134 initProcessVariables(execution)
136 logger.trace('Entered ' + method)
138 def rollbackErrorCode = execution.getVariable('rollbackErrorCode')
139 if (rollbackErrorCode == "0") {
140 execution.setVariable('rollbackSuccessful', true)
141 logger.debug("rollback successful")
144 execution.setVariable('rollbackSuccessful', false)
145 logger.debug("rollback unsuccessful")
148 logger.trace('Exited ' + method)