Add ANR xApp controller
[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.NeighborCellRelationDelTable;
29 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationModTable;
30 import org.oransc.ric.anrxapp.client.model.NeighborCellRelationTable;
31 import org.oransc.ric.portal.dashboard.DashboardConstants;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.annotation.Configuration;
36 import org.springframework.http.MediaType;
37 import org.springframework.util.Assert;
38 import org.springframework.web.bind.annotation.PathVariable;
39 import org.springframework.web.bind.annotation.RequestBody;
40 import org.springframework.web.bind.annotation.RequestMapping;
41 import org.springframework.web.bind.annotation.RequestMethod;
42 import org.springframework.web.bind.annotation.RequestParam;
43 import org.springframework.web.bind.annotation.RestController;
44
45 import io.swagger.annotations.ApiOperation;
46
47 /**
48  * Provides methods to contact the ANR xApp which manages a Neighbor Cell
49  * Relation Table (NCRT).
50  */
51 @Configuration
52 @RestController
53 @RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/ncrt", produces = MediaType.APPLICATION_JSON_VALUE)
54 public class AnrXappController {
55
56         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
57
58         private static final String CELL_ID = "cellIdentifier";
59         private static final String GGNBID = "ggnbId";
60         private static final String START_INDEX = "startIndex";
61         private static final String LIMIT = "limit";
62         private static final String NRPCI = "neighborCellIdentifierNrpci";
63         private static final String NRCGI = "neighborCellIdentifierNrcgi";
64
65         // Populated by the autowired constructor
66         private final HealthApi healthApi;
67         private final NcrtApi ncrtApi;
68
69         @Autowired
70         public AnrXappController(final HealthApi healthApi, final NcrtApi ncrtApi) {
71                 Assert.notNull(healthApi, "API must not be null");
72                 Assert.notNull(ncrtApi, "API must not be null");
73                 this.healthApi = healthApi;
74                 this.ncrtApi = ncrtApi;
75         }
76
77         @ApiOperation(value = "Performs a liveness probe on the ANR xApp, result expressed as the response code.")
78         @RequestMapping(value = "/health/alive", method = RequestMethod.GET)
79         public void getHealthAlive(HttpServletResponse response) {
80                 logger.debug("getHealthAlive");
81                 healthApi.getHealthAlive();
82                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
83         }
84
85         @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.")
86         @RequestMapping(value = "/health/ready", method = RequestMethod.GET)
87         public void getHealthReady(HttpServletResponse response) {
88                 logger.debug("getHealthReady");
89                 healthApi.getHealthReady();
90                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
91         }
92
93         @ApiOperation(value = "Query NCRT of all cells, all or one gNB(s)", response = NeighborCellRelationTable.class)
94         @RequestMapping(value = "/cell", method = RequestMethod.GET)
95         public NeighborCellRelationTable queryNcrtAllCells( //
96                         @RequestParam(name = GGNBID, required = false) String ggnbId, //
97                         @RequestParam(name = START_INDEX, required = false) String startIndex, //
98                         @RequestParam(name = LIMIT, required = false) Integer limit) {
99                 logger.debug("queryNcrtAllCells: ggnbid {}, startIndex {} limit {}", ggnbId, startIndex, limit);
100                 return ncrtApi.getNcrtInfo(ggnbId, startIndex, limit);
101         }
102
103         @ApiOperation(value = "Query NCRT of a single serving cell", response = NeighborCellRelationTable.class)
104         @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.GET)
105         public NeighborCellRelationTable queryNcrtServingCell(@PathVariable(CELL_ID) String cellIdentifier, //
106                         @RequestParam(name = START_INDEX, required = false) String startIndex, //
107                         @RequestParam(name = LIMIT, required = false) Integer limit,
108                         @RequestParam(name = NRPCI, required = false) String nrpci,
109                         @RequestParam(name = NRCGI, required = false) String nrcgi) {
110                 logger.debug("queryNcrtAllCells: cellIdentifier {}, startIndex {} limit {} nrpci {} nrcgi {}", cellIdentifier,
111                                 startIndex, limit, nrpci, nrcgi);
112                 return ncrtApi.getCellNcrtInfo(cellIdentifier, startIndex, limit, nrpci, nrcgi);
113         }
114
115         @ApiOperation(value = "Modify neighbor cell relation based on Source Cell NR CGI and Target Cell NR PCI / NR CGI")
116         @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.PUT)
117         public void modifyNcrt(@PathVariable(CELL_ID) String cellIdentifier, //
118                         @RequestBody NeighborCellRelationModTable ncrtModTable, //
119                         HttpServletResponse response) {
120                 logger.debug("modifyNcrt: cellIdentifier {} modTable {}", cellIdentifier, ncrtModTable);
121                 ncrtApi.modifyNCRT(cellIdentifier, ncrtModTable, null, null, null, null);
122                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
123         }
124
125         @ApiOperation(value = "Delete neighbor cell relation based on Source Cell NR CGI and Target Cell NR PCI / NR CGI")
126         @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.DELETE)
127         public void modifyNcrt(@PathVariable(CELL_ID) String cellIdentifier, //
128                         @RequestBody NeighborCellRelationDelTable ncrtDelTable, //
129                         HttpServletResponse response) {
130                 logger.debug("modifyNcrt: cellIdentifier {} delTable {}", cellIdentifier, ncrtDelTable);
131                 ncrtApi.deleteNcrt(cellIdentifier, ncrtDelTable, null, null, null, null);
132                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
133         }
134 }