5692c5e4f5e813126d56ef64d00586d682d1f0db
[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.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         private static final String CELL_ID = "cellIdentifier";
61         private static final String GGNBID = "ggnbId";
62         private static final String START_INDEX = "startIndex";
63         private static final String LIMIT = "limit";
64         private static final String NRPCI = "neighborCellIdentifierNrpci";
65         private static final String NRCGI = "neighborCellIdentifierNrcgi";
66
67         // Populated by the autowired constructor
68         private final HealthApi healthApi;
69         private final NcrtApi ncrtApi;
70
71         @Autowired
72         public AnrXappController(final HealthApi healthApi, final NcrtApi ncrtApi) {
73                 Assert.notNull(healthApi, "API must not be null");
74                 Assert.notNull(ncrtApi, "API must not be null");
75                 this.healthApi = healthApi;
76                 this.ncrtApi = ncrtApi;
77         }
78
79         @ApiOperation(value = "Gets the ANR client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class)
80         @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET)
81         public SuccessTransport getVersion() {
82                 logger.debug("getVersion enter");
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 getHealthAlive(HttpServletResponse response) {
89                 logger.debug("getHealthAlive");
90                 healthApi.getHealthAlive();
91                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
92         }
93
94         @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.")
95         @RequestMapping(value = "/health/ready", method = RequestMethod.GET)
96         public void getHealthReady(HttpServletResponse response) {
97                 logger.debug("getHealthReady");
98                 healthApi.getHealthReady();
99                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
100         }
101
102         @ApiOperation(value = "Query NCRT of all cells, all or one gNB(s)", response = NeighborCellRelationTable.class)
103         @RequestMapping(value = "/cell", method = RequestMethod.GET)
104         public NeighborCellRelationTable queryNcrtAllCells( //
105                         @RequestParam(name = GGNBID, required = false) String ggnbId, //
106                         @RequestParam(name = START_INDEX, required = false) String startIndex, //
107                         @RequestParam(name = LIMIT, required = false) Integer limit) {
108                 logger.debug("queryNcrtAllCells: ggnbid {}, startIndex {} limit {}", ggnbId, startIndex, limit);
109                 return ncrtApi.getNcrtInfo(ggnbId, startIndex, limit);
110         }
111
112         @ApiOperation(value = "Query NCRT of a single serving cell", response = NeighborCellRelationTable.class)
113         @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.GET)
114         public NeighborCellRelationTable queryNcrtServingCell(@PathVariable(CELL_ID) String cellIdentifier, //
115                         @RequestParam(name = START_INDEX, required = false) String startIndex, //
116                         @RequestParam(name = LIMIT, required = false) Integer limit,
117                         @RequestParam(name = NRPCI, required = false) String nrpci,
118                         @RequestParam(name = NRCGI, required = false) String nrcgi) {
119                 logger.debug("queryNcrtAllCells: cellIdentifier {}, startIndex {} limit {} nrpci {} nrcgi {}", cellIdentifier,
120                                 startIndex, limit, nrpci, nrcgi);
121                 return ncrtApi.getCellNcrtInfo(cellIdentifier,  nrpci, nrcgi, startIndex, limit);
122         }
123
124         @ApiOperation(value = "Modify neighbor cell relation based on Source Cell NR CGI and Target Cell NR PCI / NR CGI")
125         @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.PUT)
126         public void modifyNcrt(@PathVariable(CELL_ID) String cellIdentifier, //
127                         @RequestBody NeighborCellRelationModTable ncrtModTable, //
128                         HttpServletResponse response) {
129                 logger.debug("modifyNcrt: cellIdentifier {} modTable {}", cellIdentifier, ncrtModTable);
130                 ncrtApi.modifyNcrt(cellIdentifier, ncrtModTable, null, null);
131                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
132         }
133
134         @ApiOperation(value = "Delete neighbor cell relation based on Source Cell NR CGI and Target Cell NR PCI / NR CGI")
135         @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.DELETE)
136         public void modifyNcrt(@PathVariable(CELL_ID) String cellIdentifier, //
137                         @RequestBody NeighborCellRelationDelTable ncrtDelTable, //
138                         HttpServletResponse response) {
139                 logger.debug("modifyNcrt: cellIdentifier {} delTable {}", cellIdentifier, ncrtDelTable);
140                 ncrtApi.deleteNcrt(cellIdentifier, ncrtDelTable, null, null);
141                 response.setStatus(healthApi.getApiClient().getStatusCode().value());
142         }
143 }