2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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
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=========================================================
21 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
23 import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID;
24 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse;
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
27 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
28 import org.onap.so.client.exception.ExceptionBuilder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
33 import com.google.common.base.Optional;
37 * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
40 public class EtsiVnfDeleteTask {
42 private static final Logger LOGGER = LoggerFactory.getLogger(EtsiVnfDeleteTask.class);
43 private final ExtractPojosForBB extractPojosForBB;
44 private final ExceptionBuilder exceptionUtil;
45 private final VnfmAdapterServiceProvider vnfmAdapterServiceProvider;
48 public EtsiVnfDeleteTask(final ExceptionBuilder exceptionUtil, final ExtractPojosForBB extractPojosForBB,
49 final VnfmAdapterServiceProvider vnfmAdapterServiceProvider) {
50 this.exceptionUtil = exceptionUtil;
51 this.extractPojosForBB = extractPojosForBB;
52 this.vnfmAdapterServiceProvider = vnfmAdapterServiceProvider;
56 * Invoke VNFM adapter to delete the VNF
58 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
60 public void invokeVnfmAdapter(final BuildingBlockExecution execution) {
62 LOGGER.debug("Executing invokeVnfmAdapter ...");
63 final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
65 final Optional<DeleteVnfResponse> response = vnfmAdapterServiceProvider.invokeDeleteRequest(vnf.getVnfId());
67 if (!response.isPresent()) {
68 final String errorMessage = "Unexpected error while processing delete request";
69 LOGGER.error(errorMessage);
70 exceptionUtil.buildAndThrowWorkflowException(execution, 1211, errorMessage);
73 final DeleteVnfResponse vnfResponse = response.get();
75 LOGGER.debug("Vnf delete response: {}", vnfResponse);
76 execution.setVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME, vnfResponse);
78 LOGGER.debug("Finished executing invokeVnfmAdapter ...");
79 } catch (final Exception exception) {
80 LOGGER.error("Unable to invoke delete request", exception);
81 exceptionUtil.buildAndThrowWorkflowException(execution, 1212, exception);