2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
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.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.client.exception.ExceptionBuilder;
26 import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
27 import org.onap.vnfmadapter.v1.model.OperationStateEnum;
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;
37 * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
41 public class MonitorVnfmDeleteJobTask extends MonitorVnfmJobTask {
43 private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmDeleteJobTask.class);
46 public MonitorVnfmDeleteJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider,
47 final ExceptionBuilder exceptionUtil) {
48 super(vnfmAdapterServiceProvider, exceptionUtil);
52 * Get the current operation status of Delete job
54 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
56 public void getCurrentOperationStatus(final BuildingBlockExecution execution) {
57 LOGGER.debug("Executing getCurrentOperationStatus ...");
58 final DeleteVnfResponse deleteVnfResponse = execution.getVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME);
59 execution.setVariable(OPERATION_STATUS_PARAM_NAME, getOperationStatus(execution, deleteVnfResponse.getJobId()));
60 LOGGER.debug("Finished executing getCurrentOperationStatus ...");
64 * Log and throw exception on timeout for job status
66 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
68 public void timeOutLogFailue(final BuildingBlockExecution execution) {
69 final String message = "Delete operation time out";
70 LOGGER.error(message);
71 exceptionUtil.buildAndThrowWorkflowException(execution, 1213, message);
75 * Check the final status of delete throw exception if not completed successfully
77 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
79 public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) {
80 LOGGER.debug("Executing checkIfOperationWasSuccessful ...");
81 final Optional<OperationStateEnum> operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME);
82 final DeleteVnfResponse deleteVnfResponse = execution.getVariable(DELETE_VNF_RESPONSE_PARAM_NAME);
83 if (operationStatusOption == null || !operationStatusOption.isPresent()) {
84 final String message = "Unable to delete jobId: "
85 + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null") + "Unable to retrieve OperationStatus";
86 LOGGER.error(message);
87 exceptionUtil.buildAndThrowWorkflowException(execution, 1214, message);
89 if (operationStatusOption.isPresent()) {
90 final OperationStateEnum operationStatus = operationStatusOption.get();
91 if (operationStatus != OperationStateEnum.COMPLETED) {
92 final String message =
93 "Unable to Delete jobId: " + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null")
94 + " OperationStatus: " + operationStatus;
95 LOGGER.error(message);
96 exceptionUtil.buildAndThrowWorkflowException(execution, 1215, message);
98 LOGGER.debug("Successfully completed Deletion of job {}", deleteVnfResponse);