Upgrade ANR API to version 0.0.7
[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 getVersion() {
83                 logger.debug("getVersion enter");
84                 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class));
85         }
86
87         @ApiOperation(value = "Performs a liveness probe on the ANR xApp, result expressed as the response code.")
88         @RequestMapping(value = "/health/alive", method = RequestMethod.GET)
89         public void getHealthAlive(HttpServletResponse response) {
90                 logger.debug("getHealthAlive");
91                 healthApi.getHealthAlive();
92                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
93         }
94
95         @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.")
96         @RequestMapping(value = "/health/ready", method = RequestMethod.GET)
97         public void getHealthReady(HttpServletResponse response) {
98                 logger.debug("getHealthReady");
99                 healthApi.getHealthReady();
100                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
101         }
102
103         @ApiOperation(value = "Returns list of gNodeB IDs based on NCRT in ANR", response = GgNodeBTable.class)
104         @RequestMapping(value = "/gnodebs", method = RequestMethod.GET)
105         public GgNodeBTable getGnodebs() {
106                 return ncrtApi.getgNodeB();
107         }
108
109         @ApiOperation(value = "Returns neighbor cell relation table for all gNodeBs or based on query parameters", response = NeighborCellRelationTable.class)
110         @RequestMapping(value = "/ncrt", method = RequestMethod.GET)
111         public NeighborCellRelationTable getNcrtInfo( //
112                         @RequestParam(name = QP_NODEB, required = false) String ggnbId, //
113                         @RequestParam(name = QP_SERVING, required = false) String servingCellNrcgi, //
114                         @RequestParam(name = QP_NEIGHBOR, required = false) String neighborCellNrpci) {
115                 logger.debug("getNcrtInfo: ggnbid {}, servingCellNrpci {} neighborCellNrcgi {}", ggnbId, servingCellNrcgi,
116                                 neighborCellNrpci);
117                 return ncrtApi.getNcrt(ggnbId, servingCellNrcgi, neighborCellNrpci);
118         }
119
120         // /ncrt/servingcells/{servCellNrcgi}/neighborcells/{neighCellNrpci} :
121         @ApiOperation(value = "Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
122         @RequestMapping(value = "/ncrt/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR
123                         + "}", method = RequestMethod.PUT)
124         public void modifyNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
125                         @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
126                         @RequestBody NeighborCellRelationMod ncrMod, HttpServletResponse response) {
127                 logger.debug("modifyNcrt: servingCellNrcgi {}, neighborCellNrpci {}, ncrMod {}", servingCellNrcgi,
128                                 neighborCellNrpci, ncrMod);
129                 ncrtApi.modifyNcrt(servingCellNrcgi, neighborCellNrpci, ncrMod);
130                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
131         }
132
133         @ApiOperation(value = "Delete neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
134         @RequestMapping(value = "/ncrt/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR
135                         + "}", method = RequestMethod.DELETE)
136         public void deleteNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
137                         @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
138                         HttpServletResponse response) {
139                 logger.debug("deleteNcrt: servingCellNrcgi {}, neighborCellNrpci {}", servingCellNrcgi, neighborCellNrpci);
140                 ncrtApi.deleteNcrt(servingCellNrcgi, neighborCellNrpci);
141                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
142         }
143
144 }