diff options
author | 2022-02-07 16:05:17 +0000 | |
---|---|---|
committer | 2022-02-10 10:31:15 +0000 | |
commit | 873803eca00830dc3ecb61e610d90710f64a8242 (patch) | |
tree | 31531d76a87c300577da83bdf86563b78a015fce /main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.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/service/PdpStatisticsService.java')
-rw-r--r-- | main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java b/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java index 79112cd2..c9a831ee 100644 --- a/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java +++ b/main/src/main/java/org/onap/policy/pap/main/service/PdpStatisticsService.java @@ -26,17 +26,23 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; import javax.ws.rs.core.Response; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.base.PfGeneratedIdKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics; +import org.onap.policy.pap.main.PapConstants; import org.onap.policy.pap.main.repository.PdpStatisticsRepository; +import org.onap.policy.pap.main.rest.PapStatisticsManager; +import org.onap.policy.pap.main.rest.StatisticsReport; +import org.onap.policy.pap.main.startstop.PapActivator; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -52,9 +58,33 @@ public class PdpStatisticsService { private static final int DEFAULT_RECORD_COUNT = 10; private static final int MAX_RECORD_COUNT = 100; + private AtomicLong generatedId = new AtomicLong(); + private final PdpStatisticsRepository pdpStatisticsRepository; /** + * Returns the current statistics of pap component. + * + * @return Report containing statistics of pap component + */ + public StatisticsReport fetchCurrentStatistics() { + final var report = new StatisticsReport(); + report.setCode(Registry.get(PapConstants.REG_PAP_ACTIVATOR, PapActivator.class).isAlive() ? 200 : 500); + + PapStatisticsManager mgr = Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class); + report.setTotalPdpCount(mgr.getTotalPdpCount()); + report.setTotalPdpGroupCount(mgr.getTotalPdpGroupCount()); + report.setTotalPolicyDownloadCount(mgr.getTotalPolicyDownloadCount()); + report.setPolicyDownloadSuccessCount(mgr.getPolicyDownloadSuccessCount()); + report.setPolicyDownloadFailureCount(mgr.getPolicyDownloadFailureCount()); + report.setTotalPolicyDeployCount(mgr.getTotalPolicyDeployCount()); + report.setPolicyDeploySuccessCount(mgr.getPolicyDeploySuccessCount()); + report.setPolicyDeployFailureCount(mgr.getPolicyDeployFailureCount()); + + return report; + } + + /** * Creates PDP statistics. * * @param pdpStatisticsList a specification of the PDP statistics to create @@ -68,7 +98,9 @@ public class PdpStatisticsService { if (!validationResult.isValid()) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); } - pdpStatisticsRepository.save(jpaPdpStatistics); + //TODO: Fix this as part of POLICY-3897 + jpaPdpStatistics.getKey().setGeneratedId(generatedId.incrementAndGet()); + pdpStatisticsRepository.saveAndFlush(jpaPdpStatistics); pdpStatistics.setGeneratedId(jpaPdpStatistics.getKey().getGeneratedId()); } @@ -95,8 +127,8 @@ public class PdpStatisticsService { * @param endTime end time of the records to be returned * @return pdpStatistics grouped by pdpGroup */ - public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(String pdpGroup, String pdpSubGroup, - String pdp, int recordCount, Instant startTime, Instant endTime) { + public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(@NonNull String pdpGroup, + @NonNull String pdpSubGroup, @NonNull String pdp, int recordCount, Instant startTime, Instant endTime) { Pageable recordSize = getRecordSize(recordCount); if (startTime != null && endTime != null) { @@ -128,8 +160,8 @@ public class PdpStatisticsService { * @param endTime end time of the records to be returned * @return pdpStatistics grouped by pdpGroup */ - public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(String pdpGroup, String pdpSubGroup, - int recordCount, Instant startTime, Instant endTime) { + public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(@NonNull String pdpGroup, + @NonNull String pdpSubGroup, int recordCount, Instant startTime, Instant endTime) { Pageable recordSize = getRecordSize(recordCount); if (startTime != null && endTime != null) { @@ -159,8 +191,8 @@ public class PdpStatisticsService { * @param endTime end time of the records to be returned * @return pdpStatistics grouped by pdpGroup */ - public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(String pdpGroup, int recordCount, - Instant startTime, Instant endTime) { + public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(@NonNull String pdpGroup, + int recordCount, Instant startTime, Instant endTime) { Pageable recordSize = getRecordSize(recordCount); if (startTime != null && endTime != null) { |