d85444497db7b62e5ae75ee150dde7f3e5d6aab8
[so.git] / so-etsi-nfvo / so-etsi-nfvo-ns-lcm / so-etsi-nfvo-ns-lcm-bpmn-flows / src / main / java / org / onap / so / etsi / nfvo / ns / lcm / bpmn / flows / tasks / MonitorSol003AdapterTerminateJobTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks;
21
22 import org.camunda.bpm.engine.delegate.DelegateExecution;
23 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse;
24 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum;
25 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterServiceProvider;
26 import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
31 import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME;
32 import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.DELETE_VNF_RESPONSE_PARAM_NAME;
33
34 /**
35  * @author Waqas Ikram (waqas.ikram@est.tech)
36  * @author Andrew Lamb (andrew.a.lamb@est.tech)
37  *
38  */
39 @Component
40 public class MonitorSol003AdapterTerminateJobTask extends MonitorSol003AdapterJobTask {
41
42     private static final Logger LOGGER = LoggerFactory.getLogger(MonitorSol003AdapterTerminateJobTask.class);
43
44     @Autowired
45     public MonitorSol003AdapterTerminateJobTask(final Sol003AdapterServiceProvider sol003AdapterServiceProvider,
46             final DatabaseServiceProvider databaseServiceProvider) {
47         super(sol003AdapterServiceProvider, databaseServiceProvider);
48     }
49
50     public void getCurrentOperationStatus(final DelegateExecution execution) {
51         try {
52             LOGGER.debug("Executing getCurrentOperationStatus  ...");
53             final DeleteVnfResponse deleteVnfResponse =
54                     (DeleteVnfResponse) execution.getVariable(DELETE_VNF_RESPONSE_PARAM_NAME);
55             execution.setVariable(OPERATION_STATUS_PARAM_NAME,
56                     getOperationStatus(execution, deleteVnfResponse.getJobId()));
57             LOGGER.debug("Finished executing getCurrentOperationStatus ...");
58         } catch (final Exception exception) {
59             final String message = "Unable to invoke get current Operation status";
60             LOGGER.error(message, exception);
61             abortOperation(execution, message);
62
63         }
64     }
65
66     /**
67      * Log and throw exception on timeout for job status
68      *
69      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
70      */
71     public void timeOutLogFailure(final DelegateExecution execution) {
72         final String message = "Termination operation time out";
73         LOGGER.error(message);
74         abortOperation(execution, message);
75     }
76
77     /**
78      * Check the final status of termination throw exception if not completed successfully
79      *
80      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
81      */
82     public void checkIfOperationWasSuccessful(final DelegateExecution execution) {
83         LOGGER.debug("Executing checkIfOperationWasSuccessful  ...");
84         final OperationStateEnum operationStatus =
85                 (OperationStateEnum) execution.getVariable(OPERATION_STATUS_PARAM_NAME);
86         final DeleteVnfResponse deleteVnfResponse =
87                 (DeleteVnfResponse) execution.getVariable(DELETE_VNF_RESPONSE_PARAM_NAME);
88
89         if (operationStatus == null) {
90             final String message =
91                     "Unable to terminate, jobId: " + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null")
92                             + "Unable to retrieve OperationStatus";
93             LOGGER.error(message);
94             abortOperation(execution, message);
95         }
96         if (operationStatus != OperationStateEnum.COMPLETED) {
97             final String message =
98                     "Unable to terminate, jobId: " + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null")
99                             + " OperationStatus: " + operationStatus;
100             LOGGER.error(message);
101             abortOperation(execution, message);
102         }
103
104         LOGGER.debug("Successfully completed termination of job {}", deleteVnfResponse);
105     }
106 }