From c1a8b8036204ad38407375ac2c8ba5ce037f6a57 Mon Sep 17 00:00:00 2001 From: "k.kedron" Date: Mon, 20 Sep 2021 11:36:48 +0200 Subject: RanCellController enhancements Improve reports endpoint - new cell state checking Issue-ID: INT-1945 Signed-off-by: Krystian Kedron Change-Id: I0c491cce5494c277bb5740494b6c53c53b97d336 --- .../controller/RanCellController.java | 54 +++++++++++++--------- .../service/cell/RanCellStateService.java | 15 ++++-- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/onap/a1pesimulator/controller/RanCellController.java b/src/main/java/org/onap/a1pesimulator/controller/RanCellController.java index 0074058..6b49d96 100644 --- a/src/main/java/org/onap/a1pesimulator/controller/RanCellController.java +++ b/src/main/java/org/onap/a1pesimulator/controller/RanCellController.java @@ -25,6 +25,7 @@ import org.onap.a1pesimulator.service.cell.RanCellStateService; import org.onap.a1pesimulator.service.report.RanReportsBrokerService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -46,6 +47,8 @@ public class RanCellController { private final RanCellStateService ranCellStateService; private final RanReportsBrokerService ranReportsBrokerService; + public static final String CONFLICT_ERROR_MESSAGE = "The changing of the cell state is not allowed in current state"; + public RanCellController(RanCellService ranCellService, RanCellStateService ranCellStateService, RanReportsBrokerService ranReportsBrokerService) { this.ranCellService = ranCellService; @@ -68,27 +71,34 @@ public class RanCellController { public ResponseEntity startSendingFailureReports(@ApiParam(value = "Cell Id") final @PathVariable String identifier, @ApiParam(value = "Reporting Method", defaultValue = "FILE_READY", required = true) final @RequestParam() ReportingMethodEnum reportingMethod) { checkIfCellExistOrThrowException(identifier); - ranCellService.failure(identifier); - ranReportsBrokerService.startSendingFailureReports(identifier, reportingMethod); - ranCellStateService.failingState(identifier); + if (ranCellStateService.failingState(identifier)) { + ranCellService.failure(identifier); + ranReportsBrokerService.startSendingFailureReports(identifier, reportingMethod); + + return ResponseEntity.accepted().body("Failure VES Event sending started"); + } - return ResponseEntity.accepted().body("Failure VES Event sending started"); + return ResponseEntity.status(HttpStatus.CONFLICT).body(CONFLICT_ERROR_MESSAGE); } @ApiOperation("Stop sending failure VES events for specific cell") @PostMapping(value = "/{identifier}/stopFailure") public ResponseEntity stopSendingFailureReports(@ApiParam(value = "Cell Id") final @PathVariable String identifier) { checkIfCellExistOrThrowException(identifier); - ranCellService.recoverFromFailure(identifier); - Optional vesEvent = ranReportsBrokerService.stopSendingReports(identifier); + if (ranCellStateService.stopState(identifier)) { + ranCellService.recoverFromFailure(identifier); - if (!vesEvent.isPresent()) { - return ResponseEntity.notFound().build(); + Optional vesEvent = ranReportsBrokerService.stopSendingReports(identifier); + + if (!vesEvent.isPresent()) { + return ResponseEntity.notFound().build(); + } + + return ResponseEntity.accepted().build(); } - ranCellStateService.stopState(identifier); - return ResponseEntity.accepted().build(); + return ResponseEntity.status(HttpStatus.CONFLICT).build(); } @ApiOperation("Start sending normal VES events for specific cell and in specific granularity period") @@ -101,15 +111,12 @@ public class RanCellController { checkIfCellExistOrThrowException(identifier); log.info("Start sending ves events every {} seconds for {} ", getInterval(interval), identifier); VesEvent vesEvent = vesEventOpt.orElse(ranReportsBrokerService.getGlobalPmVesStructure()); - - ResponseEntity responseEntity = - ranReportsBrokerService.startSendingReports(identifier, vesEvent, getInterval(interval), reportingMethod); - if (!responseEntity.getStatusCode().is2xxSuccessful()) { - return responseEntity; + if (ranCellStateService.activateState(identifier)) { + return ranReportsBrokerService + .startSendingReports(identifier, vesEvent, getInterval(interval), reportingMethod); } - ranCellStateService.activateState(identifier); - return responseEntity; + return ResponseEntity.status(HttpStatus.CONFLICT).body(CONFLICT_ERROR_MESSAGE); } @ApiOperation("Stop sending normal VES events for specific cell") @@ -117,13 +124,16 @@ public class RanCellController { public ResponseEntity stopSendingReports(@ApiParam(value = "Cell Id") final @PathVariable String identifier) { checkIfCellExistOrThrowException(identifier); log.info("Stop sending custom ves events for {}", identifier); - Optional vesEvent = ranReportsBrokerService.stopSendingReports(identifier); - if (!vesEvent.isPresent()) { - return ResponseEntity.notFound().build(); + if (ranCellStateService.stopState(identifier)) { + Optional vesEvent = ranReportsBrokerService.stopSendingReports(identifier); + if (!vesEvent.isPresent()) { + return ResponseEntity.notFound().build(); + } + + return ResponseEntity.accepted().build(); } - ranCellStateService.stopState(identifier); - return ResponseEntity.accepted().build(); + return ResponseEntity.status(HttpStatus.CONFLICT).build(); } @GetMapping(value = "/{identifier}/pmConfig") diff --git a/src/main/java/org/onap/a1pesimulator/service/cell/RanCellStateService.java b/src/main/java/org/onap/a1pesimulator/service/cell/RanCellStateService.java index 274c6d1..175eb30 100644 --- a/src/main/java/org/onap/a1pesimulator/service/cell/RanCellStateService.java +++ b/src/main/java/org/onap/a1pesimulator/service/cell/RanCellStateService.java @@ -36,34 +36,43 @@ public class RanCellStateService { this.messagingTemplate = messagingTemplate; } - public void activateState(String identifier) { + public boolean activateState(String identifier) { Optional cellDetails = getCell(identifier); if (cellExist(cellDetails, identifier, "Activate")) { boolean changed = nextStateIfPossible(cellDetails.get(), CellStateEnum.INACTIVE); if (changed) { sendCellNotification(cellDetails.get()); + return true; } } + + return false; } - public void failingState(String identifier) { + public boolean failingState(String identifier) { Optional cellDetails = getCell(identifier); if (cellExist(cellDetails, identifier, "Failing")) { boolean changed = nextStateIfPossible(cellDetails.get(), CellStateEnum.ACTIVE); if (changed) { sendCellNotification(cellDetails.get()); + return true; } } + + return false; } - public void stopState(String identifier) { + public boolean stopState(String identifier) { Optional cellDetails = getCell(identifier); if (cellExist(cellDetails, identifier, "Stop")) { boolean changed = previousStateIfPossible(cellDetails.get()); if (changed) { sendCellNotification(cellDetails.get()); + return true; } } + + return false; } private boolean cellExist(Optional cellDetails, String identifier, String actionName) { -- cgit 1.2.3-korg