2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
20 package org.oransc.ric.portal.dashboard.controller;
22 import java.lang.invoke.MethodHandles;
24 import javax.servlet.http.HttpServletResponse;
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;
47 import io.swagger.annotations.ApiOperation;
50 * Provides methods to contact the ANR xApp which manages a Neighbor Cell
51 * Relation Table (NCRT).
55 @RequestMapping(value = AnrXappController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
56 public class AnrXappController {
58 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
60 // Publish paths in constants so tests are easy to write
61 public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/xapp/anr";
63 public static final String HEALTH_ALIVE_METHOD = "/health/alive";
64 public static final String HEALTH_READY_METHOD = "/health/ready";
65 public static final String GNODEBS_METHOD = "/gnodebs";
66 public static final String NCRT_METHOD = "/ncrt";
68 public static final String PP_SERVING = "servingcells";
69 public static final String PP_NEIGHBOR = "neighborcells";
71 public static final String QP_NODEB = "ggnodeb";
72 public static final String QP_SERVING = "servingCellNrcgi";
73 public static final String QP_NEIGHBOR = "neighborCellNrpci";
75 // Populated by the autowired constructor
76 private final HealthApi healthApi;
77 private final NcrtApi ncrtApi;
80 public AnrXappController(final HealthApi anrHealthApi, final NcrtApi anrNcrtApi) {
81 Assert.notNull(anrHealthApi, "API must not be null");
82 Assert.notNull(anrNcrtApi, "API must not be null");
83 this.healthApi = anrHealthApi;
84 this.ncrtApi = anrNcrtApi;
85 if (logger.isDebugEnabled())
86 logger.debug("ctor: configured with client types {} and {}", anrHealthApi.getClass().getName(),
87 anrNcrtApi.getClass().getName());
90 @ApiOperation(value = "Gets the ANR client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
91 @RequestMapping(value = DashboardConstants.VERSION_METHOD, method = RequestMethod.GET)
92 public SuccessTransport getAnrXappClientVersion() {
93 return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class));
96 @ApiOperation(value = "Performs a liveness probe on the ANR xApp, result expressed as the response code.")
97 @RequestMapping(value = HEALTH_ALIVE_METHOD, method = RequestMethod.GET)
98 public void getHealthAlive(HttpServletResponse response) {
99 logger.debug("getHealthAlive");
100 healthApi.getHealthAlive();
101 response.setStatus(healthApi.getApiClient().getStatusCode().value());
104 @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.")
105 @RequestMapping(value = HEALTH_READY_METHOD, method = RequestMethod.GET)
106 public void getHealthReady(HttpServletResponse response) {
107 logger.debug("getHealthReady");
108 healthApi.getHealthReady();
109 response.setStatus(healthApi.getApiClient().getStatusCode().value());
112 @ApiOperation(value = "Returns list of gNodeB IDs based on NCRT in ANR", response = GgNodeBTable.class)
113 @RequestMapping(value = GNODEBS_METHOD, method = RequestMethod.GET)
114 public GgNodeBTable getGnodebs() {
115 logger.debug("getGnodebs");
116 return ncrtApi.getgNodeB();
119 @ApiOperation(value = "Returns neighbor cell relation table for all gNodeBs or based on query parameters", response = NeighborCellRelationTable.class)
120 @RequestMapping(value = NCRT_METHOD, method = RequestMethod.GET)
121 public NeighborCellRelationTable getNcrt( //
122 @RequestParam(name = QP_NODEB, required = false) String ggnbId, //
123 @RequestParam(name = QP_SERVING, required = false) String servingCellNrcgi, //
124 @RequestParam(name = QP_NEIGHBOR, required = false) String neighborCellNrpci) {
125 logger.debug("getNcrt: ggnbid {}, servingCellNrpci {}, neighborCellNrcgi {}", ggnbId, servingCellNrcgi,
127 return ncrtApi.getNcrt(ggnbId, servingCellNrcgi, neighborCellNrpci);
130 // /ncrt/servingcells/{servCellNrcgi}/neighborcells/{neighCellNrpci} :
131 @ApiOperation(value = "Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
132 @RequestMapping(value = NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR
133 + "}", method = RequestMethod.PUT)
134 public void modifyNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
135 @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
136 @RequestBody NeighborCellRelationMod ncrMod, HttpServletResponse response) {
137 logger.debug("modifyNcrt: servingCellNrcgi {}, neighborCellNrpci {}, ncrMod {}", servingCellNrcgi,
138 neighborCellNrpci, ncrMod);
139 ncrtApi.modifyNcrt(servingCellNrcgi, neighborCellNrpci, ncrMod);
140 response.setStatus(healthApi.getApiClient().getStatusCode().value());
143 @ApiOperation(value = "Delete neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI")
144 @RequestMapping(value = NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR
145 + "}", method = RequestMethod.DELETE)
146 public void deleteNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, //
147 @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, //
148 HttpServletResponse response) {
149 logger.debug("deleteNcrt: servingCellNrcgi {}, neighborCellNrpci {}", servingCellNrcgi, neighborCellNrpci);
150 ncrtApi.deleteNcrt(servingCellNrcgi, neighborCellNrpci);
151 response.setStatus(healthApi.getApiClient().getStatusCode().value());