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