Added CSIT for Macroflow with HEAT
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / sdnc-simulator / src / main / java / org / onap / so / sdncsimulator / controller / ConfigController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright 2021 Huawei Technologies Co., Ltd.
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  * ============LICENSE_END=========================================================
17  */
18 package org.onap.so.sdncsimulator.controller;
19
20 import static org.onap.so.sdncsimulator.utils.Constants.BASE_URL;
21 import java.util.Optional;
22 import javax.ws.rs.core.MediaType;
23 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology;
24 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology;
25
26 import org.onap.so.sdncsimulator.providers.ServiceOperationsCacheServiceProvider;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.http.HttpStatus;
31 import org.springframework.http.ResponseEntity;
32 import org.springframework.stereotype.Controller;
33 import org.springframework.web.bind.annotation.GetMapping;
34 import org.springframework.web.bind.annotation.PathVariable;
35 import org.springframework.web.bind.annotation.RequestMapping;
36
37 /**
38  * @author Md Irshad Sheikh (md.irshad.sheikh@huawei.com)
39  *
40  */
41 @Controller
42 @RequestMapping(path = BASE_URL)
43 public class ConfigController {
44     private static final String HTTP_STATUS_OK = HttpStatus.OK.value() + "";
45
46     private static final Logger LOGGER = LoggerFactory.getLogger(OperationsController.class);
47
48     private final ServiceOperationsCacheServiceProvider cacheServiceProvider;
49
50     @Autowired
51     public ConfigController(final ServiceOperationsCacheServiceProvider cacheServiceProvider) {
52         this.cacheServiceProvider = cacheServiceProvider;
53     }
54
55     @GetMapping(value = "/config/GENERIC-RESOURCE-API:services/service/{service-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/")
56     public ResponseEntity<?> getVNf(@PathVariable("service-id") String serviceId,
57                                     @PathVariable("vnf-id") String vnfId) {
58
59         LOGGER.info("Get vnf-topology with serviceId {} and vnfId {}",serviceId, vnfId);
60         final Optional<GenericResourceApiVnfTopology> optional =
61                 cacheServiceProvider.getGenericResourceApiVnfTopology(vnfId);
62         if (optional.isPresent()) {
63             final GenericResourceApiVnfTopology genericVnfTopology = optional.get();
64             LOGGER.info("found VnfTopology {} in cache", genericVnfTopology);
65             return ResponseEntity.ok(genericVnfTopology);
66         }
67
68         LOGGER.error(
69                 "Unable to find VnfTopology in cache ");
70
71         return ResponseEntity.badRequest().build();
72     }
73
74     @GetMapping(value = "/config/GENERIC-RESOURCE-API:services/service/{service-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/vf-module-data/vf-module-topology/", produces = {
75             MediaType.APPLICATION_JSON })
76     public ResponseEntity<?> getVFmodule(@PathVariable("service-id") String serviceId,
77                                          @PathVariable("vnf-id") String vnfId, @PathVariable("vf-module-id") String vfModuleId) {
78         LOGGER.info("Get vfModule-topology with serviceId {}, vnfId {} and vfModuleId {}",serviceId, vnfId,vfModuleId);
79
80         final Optional<GenericResourceApiVfModuleTopology> optional =
81                 cacheServiceProvider.getGenericResourceApiVfModuleTopology(vfModuleId);
82
83         if (optional.isPresent()) {
84             final GenericResourceApiVfModuleTopology vfModuleTopology = optional.get();
85             LOGGER.info("found vfModuleTopology {} in cache", vfModuleTopology);
86             return ResponseEntity.ok(vfModuleTopology);
87         }
88
89         LOGGER.error(
90                 "Unable to find VfModuleTopology in cache for ");
91
92         return ResponseEntity.badRequest().build();
93     }
94 }