Add column sorting on ANR page
[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.PathVariable;
41 import org.springframework.web.bind.annotation.RequestBody;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RequestMethod;
44 import org.springframework.web.bind.annotation.RequestParam;
45 import org.springframework.web.bind.annotation.RestController;
46
47 import io.swagger.annotations.ApiOperation;
48
49 /**
50  * Provides methods to contact the ANR xApp which manages a Neighbor Cell
51  * Relation Table (NCRT).
52  */
53 @Configuration
54 @RestController
55 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xapp/anr", produces = MediaType.APPLICATION_JSON_VALUE)
56 public class AnrXappController {
57
58         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
59
60         // Query parameters
61         private static final String QP_NODEB = "ggnodeb";
62         private static final String QP_SERVING = "servingCellNrcgi";
63         private static final String QP_NEIGHBOR = "neighborCellNrpci";
64         // Path parameters
65         private static final String PP_SERVING = "servingcells";
66         private static final String PP_NEIGHBOR = "neighborcells";
67
68         // Populated by the autowired constructor
69         private final HealthApi healthApi;
70         private final NcrtApi ncrtApi;
71
72         @Autowired
73         public AnrXappController(final HealthApi healthApi, final NcrtApi ncrtApi) {
74                 Assert.notNull(healthApi, "API must not be null");
75                 Assert.notNull(ncrtApi, "API must not be null");
76                 this.healthApi = healthApi;
77                 this.ncrtApi = ncrtApi;
78         }
79
80         @ApiOperation(value = "Gets the ANR client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
81         @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET)
82         public SuccessTransport getAnrXappClientVersion() {
83                 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class));
84         }
85
86         @ApiOperation(value = "Performs a liveness probe on the ANR xApp, result expressed as the response code.")
87         @RequestMapping(value = "/health/alive", method = RequestMethod.GET)
88         public void getAnrXappHealthAlive(HttpServletResponse response) {
89                 healthApi.getHealthAlive();
90                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
91         }
92
93         @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.")
94         @RequestMapping(value = "/health/ready", method = RequestMethod.GET)
95         public void getAnrXappHealthReady(HttpServletResponse response) {
96                 healthApi.getHealthReady();
97                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
98         }
99
100         @ApiOperation(value = "Returns list of gNodeB IDs based on NCRT in ANR", response = GgNodeBTable.class)
101         @RequestMapping(value = "/gnodebs", method = RequestMethod.GET)
102         public GgNodeBTable getGnodebs() {
103                 return ncrtApi.getgNodeB();
104         }
105
106         @ApiOperation(value = "Returns neighbor cell relation table for all gNodeBs or based on query parameters", response = NeighborCellRelationTable.class)
107         @RequestMapping(value = "/ncrt", method = RequestMethod.GET)
108         public NeighborCellRelationTable getNcrtInfo( //
109                         @RequestParam(name = QP_NODEB, required = false) String ggnbId, //
110                         @RequestParam(name = QP_SERVING, required = false) String servingCellNrcgi, //
111                         @RequestParam(name = QP_NEIGHBOR, required = false) String neighborCellNrpci) {
112                 logger.debug("getNcrtInfo: ggnbid {}, servingCellNrpci {}, neighborCellNrcgi {}", ggnbId, servingCellNrcgi,
113                                 neighborCellNrpci);
114                 return ncrtApi.getNcrt(ggnbId, servingCellNrcgi, neighborCellNrpci);
115         }
116
117         // /ncrt/servingcells/{servCellNrcgi}/neighborcells/{neighCellNrpci} :
118         @ApiOperation(value = "Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
119         @RequestMapping(value = "/ncrt/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR
120                         + "}", method = RequestMethod.PUT)
121         public void modifyNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
122                         @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
123                         @RequestBody NeighborCellRelationMod ncrMod, HttpServletResponse response) {
124                 logger.debug("modifyNcrt: servingCellNrcgi {}, neighborCellNrpci {}, ncrMod {}", servingCellNrcgi,
125                                 neighborCellNrpci, ncrMod);
126                 ncrtApi.modifyNcrt(servingCellNrcgi, neighborCellNrpci, ncrMod);
127                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
128         }
129
130         @ApiOperation(value = "Delete neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
131         @RequestMapping(value = "/ncrt/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR
132                         + "}", method = RequestMethod.DELETE)
133         public void deleteNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
134                         @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
135                         HttpServletResponse response) {
136                 logger.debug("deleteNcrt: servingCellNrcgi {}, neighborCellNrpci {}", servingCellNrcgi, neighborCellNrpci);
137                 ncrtApi.deleteNcrt(servingCellNrcgi, neighborCellNrpci);
138                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
139         }
140
141 }