X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fcontroller%2FAnrXappController.java;h=3d32415a56b0d0ab79266a14f16bbc542013e609;hb=036e63834ec23b08ceb2f9cece1eaa602d3082bd;hp=aa7b443fe189a719beadf7d1dbac41d519fed8da;hpb=21f98d01948dabb1d6a89b60f5694969e42c9e63;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AnrXappController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AnrXappController.java index aa7b443f..3d32415a 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AnrXappController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AnrXappController.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * Copyright (C) 2019 AT&T Intellectual Property * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import javax.servlet.http.HttpServletResponse; import org.oransc.ric.anrxapp.client.api.HealthApi; import org.oransc.ric.anrxapp.client.api.NcrtApi; -import org.oransc.ric.anrxapp.client.model.NeighborCellRelationDelTable; -import org.oransc.ric.anrxapp.client.model.NeighborCellRelationModTable; +import org.oransc.ric.anrxapp.client.model.GgNodeBTable; +import org.oransc.ric.anrxapp.client.model.NeighborCellRelationMod; import org.oransc.ric.anrxapp.client.model.NeighborCellRelationTable; import org.oransc.ric.portal.dashboard.DashboardApplication; import org.oransc.ric.portal.dashboard.DashboardConstants; @@ -36,55 +36,73 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; +import org.springframework.security.access.annotation.Secured; import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.ApiOperation; /** - * Provides methods to contact the ANR xApp which manages a Neighbor Cell - * Relation Table (NCRT). + * Proxies calls from the front end to the ANR xApp, which manages a Neighbor + * Cell Relation Table (NCRT). + * + * If a method throws RestClientResponseException, it is handled by + * {@link CustomResponseEntityExceptionHandler#handleProxyMethodException(Exception, org.springframework.web.context.request.WebRequest)} + * which returns status 502. All other exceptions are handled by Spring which + * returns status 500. */ @Configuration @RestController -@RequestMapping(value = DashboardConstants.ENDPOINT_PREFIX + "/xapp/anr", produces = MediaType.APPLICATION_JSON_VALUE) +@RequestMapping(value = AnrXappController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE) public class AnrXappController { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private static final String CELL_ID = "cellIdentifier"; - private static final String GGNBID = "ggnbId"; - private static final String START_INDEX = "startIndex"; - private static final String LIMIT = "limit"; - private static final String NRPCI = "neighborCellIdentifierNrpci"; - private static final String NRCGI = "neighborCellIdentifierNrcgi"; + // Publish paths in constants so tests are easy to write + public static final String CONTROLLER_PATH = DashboardConstants.ENDPOINT_PREFIX + "/xapp/anr"; + // Endpoints + public static final String HEALTH_ALIVE_METHOD = "/health/alive"; + public static final String HEALTH_READY_METHOD = "/health/ready"; + public static final String GNODEBS_METHOD = "/gnodebs"; + public static final String NCRT_METHOD = "/ncrt"; + public static final String VERSION_METHOD = DashboardConstants.VERSION_METHOD; + + // Path parameters + public static final String PP_SERVING = "servingcells"; + public static final String PP_NEIGHBOR = "neighborcells"; // Populated by the autowired constructor private final HealthApi healthApi; private final NcrtApi ncrtApi; @Autowired - public AnrXappController(final HealthApi healthApi, final NcrtApi ncrtApi) { - Assert.notNull(healthApi, "API must not be null"); - Assert.notNull(ncrtApi, "API must not be null"); - this.healthApi = healthApi; - this.ncrtApi = ncrtApi; + public AnrXappController(final HealthApi anrHealthApi, final NcrtApi anrNcrtApi) { + Assert.notNull(anrHealthApi, "API must not be null"); + Assert.notNull(anrNcrtApi, "API must not be null"); + this.healthApi = anrHealthApi; + this.ncrtApi = anrNcrtApi; + if (logger.isDebugEnabled()) + logger.debug("ctor: configured with client types {} and {}", anrHealthApi.getClass().getName(), + anrNcrtApi.getClass().getName()); } @ApiOperation(value = "Gets the ANR client library MANIFEST.MF property Implementation-Version.", response = SuccessTransport.class) - @RequestMapping(value = DashboardConstants.VERSION_PATH, method = RequestMethod.GET) - public SuccessTransport getVersion() { - logger.debug("getVersion enter"); + @GetMapping(VERSION_METHOD) + // No role required + public SuccessTransport getClientVersion() { return new SuccessTransport(200, DashboardApplication.getImplementationVersion(HealthApi.class)); } @ApiOperation(value = "Performs a liveness probe on the ANR xApp, result expressed as the response code.") - @RequestMapping(value = "/health/alive", method = RequestMethod.GET) + @GetMapping(HEALTH_ALIVE_METHOD) + // No role required public void getHealthAlive(HttpServletResponse response) { logger.debug("getHealthAlive"); healthApi.getHealthAlive(); @@ -92,56 +110,56 @@ public class AnrXappController { } @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.") - @RequestMapping(value = "/health/ready", method = RequestMethod.GET) + @GetMapping(HEALTH_READY_METHOD) + // No role required public void getHealthReady(HttpServletResponse response) { logger.debug("getHealthReady"); healthApi.getHealthReady(); response.setStatus(healthApi.getApiClient().getStatusCode().value()); } - @ApiOperation(value = "Query NCRT of all cells, all or one gNB(s)", response = NeighborCellRelationTable.class) - @RequestMapping(value = "/cell", method = RequestMethod.GET) - public NeighborCellRelationTable getNcrtInfo( // - @RequestParam(name = GGNBID, required = false) String ggnbId, // - @RequestParam(name = START_INDEX, required = false) String startIndex, // - @RequestParam(name = LIMIT, required = false) Integer limit) { - logger.debug("queryNcrtAllCells: ggnbid {}, startIndex {} limit {}", ggnbId, startIndex, limit); - return ncrtApi.getNcrtInfo(ggnbId, startIndex, limit); + @ApiOperation(value = "Returns list of gNodeB IDs based on NCRT in ANR", response = GgNodeBTable.class) + @GetMapping(GNODEBS_METHOD) + @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) + public GgNodeBTable getGnodebs() { + logger.debug("getGnodebs"); + return ncrtApi.getgNodeB(); } - @ApiOperation(value = "Query NCRT of a single serving cell", response = NeighborCellRelationTable.class) - @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.GET) - public NeighborCellRelationTable getCellNcrtInfo(@PathVariable(CELL_ID) String cellIdentifier, // - @RequestParam(name = START_INDEX, required = false) String startIndex, // - @RequestParam(name = LIMIT, required = false) Integer limit, - @RequestParam(name = NRPCI, required = false) String nrpci, - @RequestParam(name = NRCGI, required = false) String nrcgi) { - logger.debug("queryNcrtAllCells: cellIdentifier {}, startIndex {} limit {} nrpci {} nrcgi {}", cellIdentifier, - startIndex, limit, nrpci, nrcgi); - return ncrtApi.getCellNcrtInfo(cellIdentifier, startIndex, limit, nrpci, nrcgi); + @ApiOperation(value = "Returns neighbor cell relation table for all gNodeBs or based on query parameters", response = NeighborCellRelationTable.class) + @GetMapping(NCRT_METHOD) + @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) + public NeighborCellRelationTable getNcrt( // + @RequestParam(required = false) String ggnodeb, // + @RequestParam(required = false) String servingCellNrcgi, // + @RequestParam(required = false) String neighborCellNrpci) { + logger.debug("getNcrt: ggnbid {}, servingCellNrpci {}, neighborCellNrcgi {}", ggnodeb, servingCellNrcgi, + neighborCellNrpci); + return ncrtApi.getNcrt(ggnodeb, servingCellNrcgi, neighborCellNrpci); } - @ApiOperation(value = "Modify neighbor cell relation based on Source Cell NR CGI and Target Cell NR PCI / NR CGI") - @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.PUT) - public void modifyNcrt(@PathVariable(CELL_ID) String cellIdentifier, // - @RequestBody NeighborCellRelationModTable ncrtModTable, // - HttpServletResponse response) { - logger.debug("modifyNcrt: cellIdentifier {} modTable {}", cellIdentifier, ncrtModTable); - ncrtApi.modifyNcrt(cellIdentifier, ncrtModTable); - response.setStatus(healthApi.getApiClient().getStatusCode().value()); + // /ncrt/servingcells/{servCellNrcgi}/neighborcells/{neighCellNrpci} : + @ApiOperation(value = "Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI") + @PutMapping(NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + "}") + @Secured({ DashboardConstants.ROLE_ADMIN }) + public void modifyNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, // + @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, // + @RequestBody NeighborCellRelationMod ncrMod, HttpServletResponse response) { + logger.debug("modifyNcrt: servingCellNrcgi {}, neighborCellNrpci {}, ncrMod {}", servingCellNrcgi, + neighborCellNrpci, ncrMod); + ncrtApi.modifyNcrt(servingCellNrcgi, neighborCellNrpci, ncrMod); + response.setStatus(ncrtApi.getApiClient().getStatusCode().value()); } - /* - * TODO: DELETE should not have a body - the path should identify the resource to be deleted. - */ - @ApiOperation(value = "Delete neighbor cell relation based on Source Cell NR CGI and Target Cell NR PCI / NR CGI") - @RequestMapping(value = "/cell/" + CELL_ID + "/{" + CELL_ID + "}", method = RequestMethod.DELETE) - public void deleteNcrt(@PathVariable(CELL_ID) String cellIdentifier, // - @RequestBody NeighborCellRelationDelTable ncrtDelTable, // + @ApiOperation(value = "Delete neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI") + @DeleteMapping(NCRT_METHOD + "/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR + "}") + @Secured({ DashboardConstants.ROLE_ADMIN }) + public void deleteNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, // + @PathVariable(PP_NEIGHBOR) String neighborCellNrpci, // HttpServletResponse response) { - logger.debug("modifyNcrt: cellIdentifier {} delTable {}", cellIdentifier, ncrtDelTable); - ncrtApi.deleteNcrt(cellIdentifier, ncrtDelTable); - response.setStatus(healthApi.getApiClient().getStatusCode().value()); + logger.debug("deleteNcrt: servingCellNrcgi {}, neighborCellNrpci {}", servingCellNrcgi, neighborCellNrpci); + ncrtApi.deleteNcrt(servingCellNrcgi, neighborCellNrpci); + response.setStatus(ncrtApi.getApiClient().getStatusCode().value()); } }