X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fcontroller%2FAnrXappController.java;h=55b42124dc9fc35f344816ab44bfbe41fea369a5;hb=refs%2Fchanges%2F37%2F537%2F12;hp=9faeff72ce6721f96b81a3a4853d84af02841bf1;hpb=81c5a43871449332f9a9560c7cf25d07cf714d8e;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 9faeff72..55b42124 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 @@ -36,15 +36,16 @@ 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.http.ResponseEntity; +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 org.springframework.web.client.HttpStatusCodeException; import io.swagger.annotations.ApiOperation; @@ -54,18 +55,27 @@ import io.swagger.annotations.ApiOperation; */ @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()); - // Query parameters - private static final String QP_NODEB = "ggnodeb"; - private static final String QP_SERVING = "servingCellNrcgi"; - private static final String QP_NEIGHBOR = "neighborCellNrpci"; + // 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 - private static final String PP_SERVING = "servingcells"; - private static final String PP_NEIGHBOR = "neighborcells"; + public static final String PP_SERVING = "servingcells"; + public static final String PP_NEIGHBOR = "neighborcells"; + // Query parameters + public static final String QP_NODEB = "ggnodeb"; + public static final String QP_SERVING = "servingCellNrcgi"; + public static final String QP_NEIGHBOR = "neighborCellNrpci"; // Populated by the autowired constructor private final HealthApi healthApi; @@ -83,101 +93,72 @@ public class AnrXappController { } @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 getAnrXappClientVersion() { + @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) - public Object getHealthAlive(HttpServletResponse response) { + @GetMapping(HEALTH_ALIVE_METHOD) + // No role required + public void getHealthAlive(HttpServletResponse response) { logger.debug("getHealthAlive"); - try { - healthApi.getHealthAlive(); - response.setStatus(healthApi.getApiClient().getStatusCode().value()); - return null; - } catch (HttpStatusCodeException ex) { - logger.warn("getHealthAlive failed: {}", ex.toString()); - return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); - } + healthApi.getHealthAlive(); + response.setStatus(healthApi.getApiClient().getStatusCode().value()); } @ApiOperation(value = "Performs a readiness probe on the ANR xApp, result expressed as the response code.") - @RequestMapping(value = "/health/ready", method = RequestMethod.GET) - public Object getHealthReady(HttpServletResponse response) { + @GetMapping(HEALTH_READY_METHOD) + // No role required + public void getHealthReady(HttpServletResponse response) { logger.debug("getHealthReady"); - try { - healthApi.getHealthReady(); - response.setStatus(healthApi.getApiClient().getStatusCode().value()); - return null; - } catch (HttpStatusCodeException ex) { - logger.warn("getHealthAlive failed: {}", ex.toString()); - return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); - } + healthApi.getHealthReady(); + response.setStatus(healthApi.getApiClient().getStatusCode().value()); } @ApiOperation(value = "Returns list of gNodeB IDs based on NCRT in ANR", response = GgNodeBTable.class) - @RequestMapping(value = "/gnodebs", method = RequestMethod.GET) - public Object getGnodebs() { + @GetMapping(GNODEBS_METHOD) + @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) + public GgNodeBTable getGnodebs() { logger.debug("getGnodebs"); - try { - return ncrtApi.getgNodeB(); - } catch (HttpStatusCodeException ex) { - logger.warn("getGnodebs failed: {}", ex.toString()); - return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); - } + return ncrtApi.getgNodeB(); } @ApiOperation(value = "Returns neighbor cell relation table for all gNodeBs or based on query parameters", response = NeighborCellRelationTable.class) - @RequestMapping(value = "/ncrt", method = RequestMethod.GET) - public Object getNcrt( // + @GetMapping(NCRT_METHOD) + @Secured({ DashboardConstants.ROLE_ADMIN, DashboardConstants.ROLE_STANDARD }) + public NeighborCellRelationTable getNcrt( // @RequestParam(name = QP_NODEB, required = false) String ggnbId, // @RequestParam(name = QP_SERVING, required = false) String servingCellNrcgi, // @RequestParam(name = QP_NEIGHBOR, required = false) String neighborCellNrpci) { logger.debug("getNcrt: ggnbid {}, servingCellNrpci {}, neighborCellNrcgi {}", ggnbId, servingCellNrcgi, neighborCellNrpci); - try { - return ncrtApi.getNcrt(ggnbId, servingCellNrcgi, neighborCellNrpci); - } catch (HttpStatusCodeException ex) { - logger.warn("getNcrt failed: {}", ex.toString()); - return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); - } + return ncrtApi.getNcrt(ggnbId, servingCellNrcgi, neighborCellNrpci); } // /ncrt/servingcells/{servCellNrcgi}/neighborcells/{neighCellNrpci} : @ApiOperation(value = "Modify neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI") - @RequestMapping(value = "/ncrt/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR - + "}", method = RequestMethod.PUT) - public Object modifyNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, // + @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); - try { - ncrtApi.modifyNcrt(servingCellNrcgi, neighborCellNrpci, ncrMod); - response.setStatus(healthApi.getApiClient().getStatusCode().value()); - return null; - } catch (HttpStatusCodeException ex) { - logger.warn("modifyNcrt failed: {}", ex.toString()); - return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); - } + ncrtApi.modifyNcrt(servingCellNrcgi, neighborCellNrpci, ncrMod); + response.setStatus(healthApi.getApiClient().getStatusCode().value()); } @ApiOperation(value = "Delete neighbor cell relation based on Serving Cell NRCGI and Neighbor Cell NRPCI") - @RequestMapping(value = "/ncrt/" + PP_SERVING + "/{" + PP_SERVING + "}/" + PP_NEIGHBOR + "/{" + PP_NEIGHBOR - + "}", method = RequestMethod.DELETE) - public Object deleteNcrt(@PathVariable(PP_SERVING) String servingCellNrcgi, // + @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("deleteNcrt: servingCellNrcgi {}, neighborCellNrpci {}", servingCellNrcgi, neighborCellNrpci); - try { - ncrtApi.deleteNcrt(servingCellNrcgi, neighborCellNrpci); - response.setStatus(healthApi.getApiClient().getStatusCode().value()); - return null; - } catch (HttpStatusCodeException ex) { - logger.warn("modifyNcrt failed: {}", ex.toString()); - return ResponseEntity.status(HttpServletResponse.SC_BAD_GATEWAY).body(ex.getResponseBodyAsString()); - } + ncrtApi.deleteNcrt(servingCellNrcgi, neighborCellNrpci); + response.setStatus(healthApi.getApiClient().getStatusCode().value()); } }