2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 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.cnfm.tasks;
22 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;
41 * This class performs CNF Delete
43 * @author raviteja.karumuri@est.tech
46 public class CnfDeleteTask {
47 private static final Logger LOGGER = LoggerFactory.getLogger(CnfDeleteTask.class);
48 private final ExceptionBuilder exceptionUtil;
49 private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
50 private final ExtractPojosForBB extractPojosForBB;
51 private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
52 private static final String TERMINATE_AS_REQUEST_OBJECT = "TerminateAsRequest";
53 private static final String MONITOR_JOB_NAME = "MonitorJobName";
56 public CnfDeleteTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil,
57 ExtractPojosForBB extractPojosForBB) {
58 this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
59 this.exceptionUtil = exceptionUtil;
60 this.extractPojosForBB = extractPojosForBB;
63 public void createTerminateAsRequest(final BuildingBlockExecution execution) {
65 LOGGER.debug("Executing createTerminateAsRequest task ...");
67 final TerminateAsRequest terminateAsRequest = new TerminateAsRequest();
68 terminateAsRequest.setTerminationType(TerminateAsRequest.TerminationTypeEnum.GRACEFUL);
69 terminateAsRequest.setGracefulTerminationTimeout(0);
70 terminateAsRequest.setAdditionalParams(new HashMap<>());
72 LOGGER.debug("Adding TerminateAsRequest to execution {}", terminateAsRequest);
74 execution.setVariable(TERMINATE_AS_REQUEST_OBJECT, terminateAsRequest);
75 LOGGER.debug("Finished executing terminateAsRequest task ...");
77 } catch (final Exception exception) {
78 LOGGER.error("Unable to create TerminateAsRequest", exception);
79 exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception);
83 public void invokeCnfmToTerminateAsInstance(final BuildingBlockExecution execution) {
85 LOGGER.debug("Executing TerminateAsInstance task ...");
87 final TerminateAsRequest terminateAsRequest = execution.getVariable(TERMINATE_AS_REQUEST_OBJECT);
88 final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
89 final String asInstanceId = vnf.getVnfId();
91 Optional<URI> terminateStatusCheck =
92 cnfmHttpServiceProvider.invokeTerminateAsRequest(asInstanceId, terminateAsRequest);
93 execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL,
94 terminateStatusCheck.orElseThrow(() -> new NoSuchElementException("Status check url Not found")));
95 execution.setVariable(MONITOR_JOB_NAME, "Terminate");
96 LOGGER.debug("Successfully invoked CNFM terminate AS request: {}", asInstanceId);
98 } catch (final Exception exception) {
99 LOGGER.error("Unable to invoke CNFM TerminateAsRequest", exception);
100 exceptionUtil.buildAndThrowWorkflowException(execution, 2004, exception);
104 public void invokeCnfmToDeleteAsInstance(final BuildingBlockExecution execution) {
106 LOGGER.debug("Executing DelteAsInstance task ...");
108 final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
109 final String asInstanceId = vnf.getVnfId();
111 Optional<Boolean> response = cnfmHttpServiceProvider.invokeDeleteAsRequest(asInstanceId);
112 if (Boolean.TRUE.equals(response
113 .orElseThrow(() -> new BpmnError("Unable to complete DeleteAsRequest of ID: " + asInstanceId)))) {
114 LOGGER.debug("Successfully invoked CNFM delete AS request with ID: {}", asInstanceId);
117 } catch (final Exception exception) {
118 LOGGER.error("Unable to invoke CNFM DeleteAsRequest", exception);
119 exceptionUtil.buildAndThrowWorkflowException(execution, 2004, exception);