Non-functional changes to silence Sonar
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / controller / AnrXappController.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 package org.oransc.ric.portal.dashboard.controller;
21
22 import java.lang.invoke.MethodHandles;
23
24 import javax.servlet.http.HttpServletResponse;
25
26 import org.oransc.ric.anrxapp.client.api.HealthApi;
27 import org.oransc.ric.anrxapp.client.api.NcrtApi;
28 import org.oransc.ric.anrxapp.client.model.GgNodeBTable;
29 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationMod;
30 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationTable;
31 import org.oransc.ric.portal.dashboard.DashboardApplication;
32 import org.oransc.ric.portal.dashboard.DashboardConstants;
33 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.context.annotation.Configuration;
38 import org.springframework.http.MediaType;
39 import org.springframework.util.Assert;
40 import org.springframework.web.bind.annotation.DeleteMapping;
41 import org.springframework.web.bind.annotation.GetMapping;
42 import org.springframework.web.bind.annotation.PathVariable;
43 import org.springframework.web.bind.annotation.PutMapping;
44 import org.springframework.web.bind.annotation.RequestBody;
45 import org.springframework.web.bind.annotation.RequestMapping;
46 import org.springframework.web.bind.annotation.RequestParam;
47 import org.springframework.web.bind.annotation.RestController;
48
49 import io.swagger.annotations.ApiOperation;
50
51 /**
52  * Provides methods to contact the ANR xApp which manages a Neighbor Cell
53  * Relation Table (NCRT).
54  */
55 @Configuration
56 @RestController
57 @RequestMapping(value = AnrXappController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
58 public class AnrXappController {
59
60         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
61
62         // Publish paths in constants so tests are easy to write
63         public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/xapp/anr";
64         // Endpoints
65         public static final String HEALTH_ALIVE_METHOD = "/health/alive";
66         public static final String HEALTH_READY_METHOD = "/health/ready";
67         public static final String GNODEBS_METHOD = "/gnodebs";
68         public static final String NCRT_METHOD = "/ncrt";
69         public static final String VERSION_METHOD = DashboardConstants.VERSION_METHOD;
70
71         // Path parameters
72         public static final String PP_SERVING = "servingcells";
73         public static final String PP_NEIGHBOR = "neighborcells";
74         // Query parameters
75         public static final String QP_NODEB = "ggnodeb";
76         public static final String QP_SERVING = "servingCellNrcgi";
77         public static final String QP_NEIGHBOR = "neighborCellNrpci";
78
79         // Populated by the autowired constructor
80         private final HealthApi healthApi;
81         private final NcrtApi ncrtApi;
82
83         @Autowired
84         public AnrXappController(final HealthApi anrHealthApi, final NcrtApi anrNcrtApi) {
85                 Assert.notNull(anrHealthApi, "API must not be null");
86                 Assert.notNull(anrNcrtApi, "API must not be null");
87                 this.healthApi = anrHealthApi;
88                 this.ncrtApi = anrNcrtApi;
89                 if (logger.isDebugEnabled())
90                         logger.debug("ctor: configured with client types {} and {}", anrHealthApi.getClass().getName(),
91                                         anrNcrtApi.getClass().getName());
92         }
93
94         @ApiOperation(value = "Gets the ANR client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
95         @GetMapping(VERSION_METHOD)
96         public SuccessTransport getClientVersion() {
97                 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class));
98         }
99
100         @ApiOperation(value = "Performs a liveness probe on the ANR xApp, result expressed as the response code.")
101         @GetMapping(HEALTH_ALIVE_METHOD)
102         public void getHealthAlive(HttpServletResponse response) {
103                 logger.debug("getHealthAlive");
104                 healthApi.getHealthAlive();
105                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
106         }
107
108         @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.")
109         @GetMapping(HEALTH_READY_METHOD)
110         public void getHealthReady(HttpServletResponse response) {
111                 logger.debug("getHealthReady");
112                 healthApi.getHealthReady();
113                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
114         }
115
116         @ApiOperation(value = "Returns list of gNodeB IDs based on NCRT in ANR", response = GgNodeBTable.class)
117         @GetMapping(GNODEBS_METHOD)
118         public GgNodeBTable getGnodebs() {
119                 logger.debug("getGnodebs");
120                 return ncrtApi.getgNodeB();
121         }
122
123         @ApiOperation(value = "Returns neighbor cell relation table for all gNodeBs or based on query parameters", response = NeighborCellRelationTable.class)
124         @GetMapping(NCRT_METHOD)
125         public NeighborCellRelationTable getNcrt( //
126                         @RequestParam(name = QP_NODEB, required = false) String ggnbId, //
127                         @RequestParam(name = QP_SERVING, required = false) String servingCellNrcgi, //
128                         @RequestParam(name = QP_NEIGHBOR, required = false) String neighborCellNrpci) {
129                 logger.debug("getNcrt: ggnbid {}, servingCellNrpci {}, neighborCellNrcgi {}", ggnbId, servingCellNrcgi,
130                                 neighborCellNrpci);
131                 return ncrtApi.getNcrt(ggnbId, servingCellNrcgi, neighborCellNrpci);
132         }
133
134         // /ncrt/servingcells/{servCellNrcgi}/neighborcells/{neighCellNrpci} :
135         @ApiOperation(value = "Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
136         @PutMapping(NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + "}")
137         public void modifyNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
138                         @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
139                         @RequestBody NeighborCellRelationMod ncrMod, HttpServletResponse response) {
140                 logger.debug("modifyNcrt: servingCellNrcgi {}, neighborCellNrpci {}, ncrMod {}", servingCellNrcgi,
141                                 neighborCellNrpci, ncrMod);
142                 ncrtApi.modifyNcrt(servingCellNrcgi, neighborCellNrpci, ncrMod);
143                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
144         }
145
146         @ApiOperation(value = "Delete neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
147         @DeleteMapping(NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + "}")
148         public void deleteNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
149                         @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
150                         HttpServletResponse response) {
151                 logger.debug("deleteNcrt: servingCellNrcgi {}, neighborCellNrpci {}", servingCellNrcgi, neighborCellNrpci);
152                 ncrtApi.deleteNcrt(servingCellNrcgi, neighborCellNrpci);
153                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
154         }
155
156 }