2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
4 * ================================================================================
5 * Modifications 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
24 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.DELETE_VNF_RESPONSE_PARAM_NAME;
25 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.client.exception.ExceptionBuilder;
28 import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
29 import org.onap.vnfmadapter.v1.model.OperationStateEnum;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Component;
34 import com.google.common.base.Optional;
39 * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
43 public class MonitorVnfmDeleteJobTask extends MonitorVnfmJobTask {
45 private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmDeleteJobTask.class);
48 public MonitorVnfmDeleteJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider,
49 final ExceptionBuilder exceptionUtil) {
50 super(vnfmAdapterServiceProvider, exceptionUtil);
54 * Get the current operation status of Delete job
56 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
58 public void getCurrentOperationStatus(final BuildingBlockExecution execution) {
60 LOGGER.debug("Executing getCurrentOperationStatus ...");
61 final DeleteVnfResponse deleteVnfResponse = execution.getVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME);
62 execution.setVariable(OPERATION_STATUS_PARAM_NAME,
63 getOperationStatus(execution, deleteVnfResponse.getJobId()));
64 LOGGER.debug("Finished executing getCurrentOperationStatus ...");
65 } catch (final Exception exception) {
66 final String message = "Unable to invoke get current Operation status";
67 LOGGER.error(message);
68 exceptionUtil.buildAndThrowWorkflowException(execution, 1216, message);
74 * Log and throw exception on timeout for job status
76 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
78 public void timeOutLogFailue(final BuildingBlockExecution execution) {
79 final String message = "Delete operation time out";
80 LOGGER.error(message);
81 exceptionUtil.buildAndThrowWorkflowException(execution, 1213, message);
85 * Check the final status of delete throw exception if not completed successfully
87 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
89 public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) {
90 LOGGER.debug("Executing checkIfOperationWasSuccessful ...");
91 final Optional<OperationStateEnum> operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME);
92 final DeleteVnfResponse deleteVnfResponse = execution.getVariable(DELETE_VNF_RESPONSE_PARAM_NAME);
93 if (operationStatusOption == null || !operationStatusOption.isPresent()) {
94 final String message =
95 "Unable to delete jobId: " + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null")
96 + "Unable to retrieve OperationStatus";
97 LOGGER.error(message);
98 exceptionUtil.buildAndThrowWorkflowException(execution, 1214, message);
99 } else if (operationStatusOption != null && operationStatusOption.isPresent()) {
100 final OperationStateEnum operationStatus = operationStatusOption.get();
101 if (operationStatus != OperationStateEnum.COMPLETED) {
102 final String message =
103 "Unable to Delete jobId: " + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null")
104 + " OperationStatus: " + operationStatus;
105 LOGGER.error(message);
106 exceptionUtil.buildAndThrowWorkflowException(execution, 1215, message);
108 LOGGER.debug("Successfully completed Deletion of job {}", deleteVnfResponse);