Updating etsi-sol003-lcm-api module
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / adapter / vnfm / tasks / MonitorVnfmDeleteJobTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 Ericsson. All rights reserved.
4  * ================================================================================
5  * Copyright (C) 2019 Samsung
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  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
21
22 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.DELETE_VNF_RESPONSE_PARAM_NAME;
23 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME;
24 import org.onap.etsi.sol003.adapter.lcm.v1.model.DeleteVnfResponse;
25 import org.onap.etsi.sol003.adapter.lcm.v1.model.OperationStateEnum;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.client.exception.ExceptionBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component;
32 import com.google.common.base.Optional;
33
34
35 /**
36  * 
37  * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
38  *
39  */
40 @Component
41 public class MonitorVnfmDeleteJobTask extends MonitorVnfmJobTask {
42
43     private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmDeleteJobTask.class);
44
45     @Autowired
46     public MonitorVnfmDeleteJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider,
47             final ExceptionBuilder exceptionUtil) {
48         super(vnfmAdapterServiceProvider, exceptionUtil);
49     }
50
51     /**
52      * Get the current operation status of Delete job
53      * 
54      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
55      */
56     public void getCurrentOperationStatus(final BuildingBlockExecution execution) {
57         try {
58             LOGGER.debug("Executing getCurrentOperationStatus  ...");
59             final DeleteVnfResponse deleteVnfResponse = execution.getVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME);
60             execution.setVariable(OPERATION_STATUS_PARAM_NAME,
61                     getOperationStatus(execution, deleteVnfResponse.getJobId()));
62             LOGGER.debug("Finished executing getCurrentOperationStatus ...");
63         } catch (final Exception exception) {
64             final String message = "Unable to invoke get current Operation status";
65             LOGGER.error(message);
66             exceptionUtil.buildAndThrowWorkflowException(execution, 1216, message);
67
68         }
69     }
70
71     /**
72      * Log and throw exception on timeout for job status
73      * 
74      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
75      */
76     public void timeOutLogFailue(final BuildingBlockExecution execution) {
77         final String message = "Delete operation time out";
78         LOGGER.error(message);
79         exceptionUtil.buildAndThrowWorkflowException(execution, 1213, message);
80     }
81
82     /**
83      * Check the final status of delete throw exception if not completed successfully
84      * 
85      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
86      */
87     public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) {
88         LOGGER.debug("Executing checkIfOperationWasSuccessful  ...");
89         final Optional<OperationStateEnum> operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME);
90         final DeleteVnfResponse deleteVnfResponse = execution.getVariable(DELETE_VNF_RESPONSE_PARAM_NAME);
91         if (operationStatusOption == null || !operationStatusOption.isPresent()) {
92             final String message =
93                     "Unable to delete jobId: " + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null")
94                             + "Unable to retrieve OperationStatus";
95             LOGGER.error(message);
96             exceptionUtil.buildAndThrowWorkflowException(execution, 1214, message);
97         } else if (operationStatusOption != null && operationStatusOption.isPresent()) {
98             final OperationStateEnum operationStatus = operationStatusOption.get();
99             if (operationStatus != OperationStateEnum.COMPLETED) {
100                 final String message =
101                         "Unable to Delete jobId: " + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null")
102                                 + " OperationStatus: " + operationStatus;
103                 LOGGER.error(message);
104                 exceptionUtil.buildAndThrowWorkflowException(execution, 1215, message);
105             }
106             LOGGER.debug("Successfully completed Deletion of job {}", deleteVnfResponse);
107         }
108     }
109 }