6bbb391ca9eb1c937a61ec109a010c35e582a418
[so.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
21
22 import org.onap.logging.filter.base.ONAPComponents;
23 import org.onap.so.bpmn.common.BuildingBlockExecution;
24 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
25 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
26 import org.onap.so.client.exception.ExceptionBuilder;
27 import org.onap.so.serviceinstancebeans.RequestDetails;
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
33 import static java.util.Objects.isNull;
34
35
36 /**
37  * This class performs CNF Delete
38  *
39  * @author raviteja.karumuri@est.tech
40  */
41 @Component
42 public class CnfDeleteTask {
43
44     private static final String AS_INSTANCE_ID = "asInstanceid";
45     private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
46     private final ExceptionBuilder exceptionUtil;
47     private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
48
49     @Autowired
50     public CnfDeleteTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil) {
51         this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
52         this.exceptionUtil = exceptionUtil;
53     }
54
55     public void invokeCnfmToDeleteAsInstnace(final BuildingBlockExecution execution) {
56         try {
57             LOGGER.debug("Executing DelteAsInstance task  ...");
58             final ExecuteBuildingBlock executeBuildingBlock =
59                     (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
60
61             final GeneralBuildingBlock generalBuildingBlock = execution.getGeneralBuildingBlock();
62
63             final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails();
64             LOGGER.debug("RequestDetails of DeleteAsInstance: {}", requestDetails);
65
66             if (isNull(requestDetails) && isNull(requestDetails.getModelInfo())
67                     && isNull(requestDetails.getRequestInfo()) && isNull(requestDetails.getCloudConfiguration())
68                     && isNull(generalBuildingBlock)) {
69                 LOGGER.error("Missing Mandatory attribute from RequestDetails: {} or GeneralBuildingBlock: {}",
70                         requestDetails, generalBuildingBlock);
71                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000,
72                         "Missing Mandatory attribute from RequestDetails or GeneralBuildingBlock", ONAPComponents.SO);
73             }
74
75             LOGGER.debug("Finished executing DeleteAsInstance task ...");
76
77         } catch (final Exception exception) {
78             LOGGER.error("Unable to invoke DeleteAsInstance", exception);
79             exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception);
80         }
81     }
82 }