2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 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.cnfm.tasks;
23 import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID;
25 import java.util.HashMap;
26 import java.util.NoSuchElementException;
27 import java.util.Optional;
28 import org.camunda.bpm.engine.delegate.BpmnError;
29 import org.onap.so.bpmn.common.BuildingBlockExecution;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
31 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
40 * This class performs CNF Delete
42 * @author Raviteja Karumuri (raviteja.karumuri@est.tech)
45 public class CnfDeleteTask {
47 private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
48 private final ExceptionBuilder exceptionUtil;
49 private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
50 private final ExtractPojosForBB extractPojosForBB;
51 private static final String MONITOR_JOB_NAME = "MonitorJobName";
52 private static final String AS_INSTANCE_ID = "asInstanceid";
53 private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
54 private static final String TERMINATE_AS_REQUEST_OBJECT = "TerminateAsRequest";
57 public CnfDeleteTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil,
58 ExtractPojosForBB extractPojosForBB) {
59 this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
60 this.exceptionUtil = exceptionUtil;
61 this.extractPojosForBB = extractPojosForBB;
64 public void createTerminateAsRequest(final BuildingBlockExecution execution) {
66 LOGGER.debug("Executing createTerminateAsRequest task ...");
68 final TerminateAsRequest terminateAsRequest = new TerminateAsRequest();
69 terminateAsRequest.setTerminationType(TerminateAsRequest.TerminationTypeEnum.GRACEFUL);
70 terminateAsRequest.setGracefulTerminationTimeout(0);
71 terminateAsRequest.setAdditionalParams(new HashMap<>());
73 LOGGER.debug("Adding TerminateAsRequest to execution {}", terminateAsRequest);
75 execution.setVariable(TERMINATE_AS_REQUEST_OBJECT, terminateAsRequest);
76 LOGGER.debug("Finished executing terminateAsRequest task ...");
78 } catch (final Exception exception) {
79 LOGGER.error("Unable to create TerminateAsRequest", exception);
80 exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception);
84 public void invokeCnfmToTerminateAsInstance(final BuildingBlockExecution execution) {
86 LOGGER.debug("Executing TerminateAsInstance task ...");
88 final TerminateAsRequest terminateAsRequest = execution.getVariable(TERMINATE_AS_REQUEST_OBJECT);
89 final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
90 final String asInstanceId = vnf.getVnfId();
92 Optional<URI> terminateStatusCheck =
93 cnfmHttpServiceProvider.invokeTerminateAsRequest(asInstanceId, terminateAsRequest);
94 execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL,
95 terminateStatusCheck.orElseThrow(() -> new NoSuchElementException("Status check url Not found")));
96 execution.setVariable(MONITOR_JOB_NAME, "Terminate");
97 LOGGER.debug("Successfully invoked CNFM terminate AS request: {}", asInstanceId);
99 } catch (final Exception exception) {
100 LOGGER.error("Unable to invoke CNFM TerminateAsRequest", exception);
101 exceptionUtil.buildAndThrowWorkflowException(execution, 2002, exception);
105 public void invokeCnfmToDeleteAsInstance(final BuildingBlockExecution execution) {
107 LOGGER.debug("Executing DeleteAsInstance task ...");
109 final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
110 final String asInstanceId = vnf.getVnfId();
112 Optional<Boolean> response = cnfmHttpServiceProvider.invokeDeleteAsRequest(asInstanceId);
113 if (Boolean.TRUE.equals(response
114 .orElseThrow(() -> new BpmnError("Unable to complete DeleteAsRequest of ID: " + asInstanceId)))) {
115 LOGGER.debug("Successfully invoked CNFM delete AS request with ID: {}", asInstanceId);
118 } catch (final Exception exception) {
119 LOGGER.error("Unable to invoke CNFM DeleteAsRequest", exception);
120 exceptionUtil.buildAndThrowWorkflowException(execution, 2003, exception);