summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-07-13 14:02:30 -0400
committerJim Hahn <jrh3@att.com>2021-07-15 10:30:38 -0400
commit708e3bf02095bc7185b44cc30e91e293eebb4fd2 (patch)
tree2e5a07a5a80be958c6feb48f665d386d77169d75 /main
parent2d1e09960eefa671711c5b1830c5994037f9cab5 (diff)
Limit statistics record count
Modified PAP, for Honolulu only, to limit the number of statistics records retrieved from the DB. Also added the recordCount parameter to the REST APIs, because otherwise it would only return one record. Per review comments: - removed default value annotation; relying on the Provider code to change "0" to a reasonable default Issue-ID: POLICY-3485 Change-Id: Ib0820cfda95672f1bc6f879dfd2ac172e7b42f0d (cherry picked from commit 190b75c59bcc6f250446b627a96e4a12de52278f) Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java22
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestProvider.java26
2 files changed, 27 insertions, 21 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 d673ea88..b19e91a9 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019, 2021 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.
@@ -31,7 +31,6 @@ import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
import java.util.Map;
import java.util.UUID;
-import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
@@ -51,7 +50,6 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsRestControllerV1.class);
private static final String GET_STATISTICS_ERR_MSG = "get pdpStatistics failed";
- private static final int NO_COUNT_LIMIT = 0;
/**
* get statistics of PAP.
@@ -110,10 +108,11 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
@ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
})
public Response pdpStatistics(
- @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
+ @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
try {
return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
- .entity(new StatisticsRestProvider().fetchDatabaseStatistics(null, null, null, NO_COUNT_LIMIT))
+ .entity(new StatisticsRestProvider().fetchDatabaseStatistics(null, null, null, recordCount))
.build();
} catch (final PfModelException exp) {
LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
@@ -158,10 +157,11 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
})
public Response pdpGroupStatistics(
@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
- @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName) {
+ @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
+ @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
try {
return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
- .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, null, null, NO_COUNT_LIMIT))
+ .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, null, null, recordCount))
.build();
} catch (final PfModelException exp) {
LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
@@ -208,11 +208,12 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
public Response pdpSubGroupStatistics(
@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
@ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
- @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType) {
+ @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
+ @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
try {
return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, null,
- NO_COUNT_LIMIT))
+ recordCount))
.build();
} catch (final PfModelException exp) {
LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
@@ -264,8 +265,7 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 {
@ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
@ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
@ApiParam(value = "PDP Instance name", required = true) @PathParam("pdp") final String pdpName,
- @ApiParam(value = "Record Count",
- required = false) @DefaultValue("0") @QueryParam("recordCount") final int recordCount) {
+ @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
try {
return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, pdpName,
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestProvider.java
index 93632659..3859401e 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestProvider.java
@@ -47,6 +47,9 @@ import org.slf4j.LoggerFactory;
public class StatisticsRestProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsRestProvider.class);
private static final String GET_STATISTICS_ERR_MSG = "fetch database failed";
+ private static final String DEFAULT_GROUP = "defaultGroup";
+ private static final int MIN_RECORD_COUNT = 1;
+ private static final int MAX_RECORD_COUNT = 100;
/**
* Returns the current statistics of pap component.
@@ -84,26 +87,29 @@ public class StatisticsRestProvider {
String pdpName, int recordCount) throws PfModelException {
final PolicyModelsProviderFactoryWrapper modelProviderWrapper =
Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
- Map<String, Map<String, List<PdpStatistics>>> pdpStatisticsMap;
try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
Instant startTime = null;
Instant endTime = null;
- if (groupName == null) {
- pdpStatisticsMap = generatePdpStatistics(databaseProvider.getPdpStatistics(pdpName, startTime));
- } else {
- pdpStatisticsMap = generatePdpStatistics(databaseProvider.getFilteredPdpStatistics(
- PdpFilterParameters.builder().name(pdpName).group(groupName)
- .subGroup(subType).startTime(startTime).endTime(endTime)
- .recordNum(recordCount).build()));
- }
+ /*
+ * getFilteredPdpStatistics() will throw an NPE if a group name is not specified, so we
+ * provide a default value
+ */
+ String grpnm = (groupName != null ? groupName : DEFAULT_GROUP);
+
+ int nrecords = Math.min(MAX_RECORD_COUNT, Math.max(MIN_RECORD_COUNT, recordCount));
+
+ return generatePdpStatistics(databaseProvider.getFilteredPdpStatistics(
+ PdpFilterParameters.builder().name(pdpName).group(grpnm)
+ .subGroup(subType).startTime(startTime).endTime(endTime)
+ .recordNum(nrecords).build()));
+
} catch (final PfModelException exp) {
String errorMessage = GET_STATISTICS_ERR_MSG + "groupName:" + groupName + "subType:" + subType + "pdpName:"
+ pdpName + exp.getMessage();
LOGGER.debug(errorMessage, exp);
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
- return pdpStatisticsMap;
}
/**