diff options
author | a.sreekumar <ajith.sreekumar@bell.ca> | 2022-02-07 16:05:17 +0000 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@bell.ca> | 2022-02-10 10:31:15 +0000 |
commit | 873803eca00830dc3ecb61e610d90710f64a8242 (patch) | |
tree | 31531d76a87c300577da83bdf86563b78a015fce /main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java | |
parent | ed116b0d61f3195a1b0ed9d38f23e494260977fd (diff) |
Move PAP database provider to spring boot default
This review makes PAP talk to DB directly using the spring repositories
instead of going to policy-models-provider.
The models-provider methods that were just used by PAP (and not used
anymore) will be removed in a different review.
Also a bug identified with the usage of GeneratedValue in
PfGeneratedIdKey (which is just used by PAP in statistics & audit) will
also be fixed in a separate review as part of POLICY-3897.
CSIT changes: https://gerrit.onap.org/r/c/policy/docker/+/127033
WIP OOM review: https://gerrit.onap.org/r/c/oom/+/127035
Change-Id: Idb13ba7eb2767cc718672b582a6518fcfc95320f
Issue-ID: POLICY-3867
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java')
-rw-r--r-- | main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java index 641e2ba9..f1251cbd 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,8 @@ import java.util.List; import java.util.Map; import java.util.UUID; import lombok.RequiredArgsConstructor; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pdp.concepts.PdpStatistics; -import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters; +import org.onap.policy.pap.main.service.PdpStatisticsService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -56,7 +55,7 @@ import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor public class StatisticsRestControllerV1 extends PapRestControllerV1 { - private final StatisticsRestProvider provider; + private final PdpStatisticsService pdpStatisticsService; /** * get statistics of PAP. @@ -77,15 +76,13 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { required = false, value = REQUEST_ID_NAME) final UUID requestId) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(provider.fetchCurrentStatistics()); + .body(pdpStatisticsService.fetchCurrentStatistics()); } /** * get all statistics of PDP groups. * - * * @return a response - * @throws PfModelException the exception */ @GetMapping("pdps/statistics") @ApiOperation(value = "Fetch statistics for all PDP Groups and subgroups in the system", @@ -126,10 +123,9 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { value = "startTime") final Long startTime, @ApiParam(value = "End time in epoch timestamp") @RequestParam( required = false, - value = "endTime") final Long endTime) throws PfModelException { - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(provider.fetchDatabaseStatistics(PdpFilterParameters.builder().recordNum(recordCount) - .startTime(convertEpochtoInstant(startTime)).endTime(convertEpochtoInstant(endTime)).build())); + value = "endTime") final Long endTime) { + return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(pdpStatisticsService + .fetchDatabaseStatistics(recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); } /** @@ -137,7 +133,6 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { * * @param groupName name of the PDP group * @return a response - * @throws PfModelException the exception */ @GetMapping("pdps/statistics/{group}") @ApiOperation(value = "Fetch current statistics for given PDP Group", @@ -178,10 +173,10 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { value = "startTime") final Long startTime, @ApiParam(value = "End time in epoch timestamp") @RequestParam( required = false, - value = "endTime") final Long endTime) throws PfModelException { + value = "endTime") final Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(provider.fetchDatabaseStatistics(PdpFilterParameters.builder().group(groupName).recordNum(recordCount) - .startTime(convertEpochtoInstant(startTime)).endTime(convertEpochtoInstant(endTime)).build())); + .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, recordCount, convertEpochtoInstant(startTime), + convertEpochtoInstant(endTime))); } /** @@ -190,7 +185,6 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { * @param groupName name of the PDP group * @param subType type of the sub PDP group * @return a response - * @throws PfModelException the exception */ @GetMapping("pdps/statistics/{group}/{type}") @ApiOperation(value = "Fetch statistics for the specified subgroup", @@ -232,11 +226,10 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { value = "startTime") final Long startTime, @ApiParam(value = "End time in epoch timestamp") @RequestParam( required = false, - value = "endTime") final Long endTime) throws PfModelException { + value = "endTime") final Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(provider.fetchDatabaseStatistics( - PdpFilterParameters.builder().group(groupName).subGroup(subType).recordNum(recordCount) - .startTime(convertEpochtoInstant(startTime)).endTime(convertEpochtoInstant(endTime)).build())); + .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, recordCount, + convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); } /** @@ -247,7 +240,6 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { * @param pdpName the name of the PDP * @param recordCount the count of the query response, optional, default return all statistics stored * @return a response - * @throws PfModelException the exception */ @GetMapping("pdps/statistics/{group}/{type}/{pdp}") @ApiOperation(value = "Fetch statistics for the specified pdp", @@ -291,11 +283,10 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { value = "startTime") final Long startTime, @ApiParam(value = "End time in epoch timestamp") @RequestParam( required = false, - value = "endTime") final Long endTime) throws PfModelException { + value = "endTime") final Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(provider.fetchDatabaseStatistics( - PdpFilterParameters.builder().group(groupName).subGroup(subType).name(pdpName).recordNum(recordCount) - .startTime(convertEpochtoInstant(startTime)).endTime(convertEpochtoInstant(endTime)).build())); + .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, pdpName, recordCount, + convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); } private Instant convertEpochtoInstant(Long epochSecond) { |