summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/PapConstants.java6
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java4
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java3
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckControllerV1.java88
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java174
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java56
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java221
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestProvider.java125
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java4
-rw-r--r--main/src/main/resources/META-INF/persistence.xml6
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java2
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java38
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java7
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java88
-rw-r--r--main/src/test/resources/e2e/PapConfigParameters.json20
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json20
-rw-r--r--main/src/test/resources/parameters/PapConfigParameters.json20
-rw-r--r--main/src/test/resources/parameters/PapConfigParametersStd.json20
18 files changed, 828 insertions, 74 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/PapConstants.java b/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
index b8b199e6..2acf3e72 100644
--- a/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
+++ b/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
@@ -38,6 +38,12 @@ public class PapConstants {
public static final String TOPIC_POLICY_PDP_PAP = "POLICY-PDP-PAP";
public static final String TOPIC_POLICY_NOTIFICATION = "POLICY-NOTIFICATION";
+ // policy components names
+ public static final String POLICY_API = "api";
+ public static final String POLICY_DISTRIBUTION = "distribution";
+ public static final String POLICY_PAP = "pap";
+ public static final String POLICY_PDPS = "pdps";
+
private PapConstants() {
super();
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
index ed1b4adc..9a50cf0f 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterGroup.java
@@ -21,7 +21,9 @@
package org.onap.policy.pap.main.parameters;
+import java.util.List;
import lombok.Getter;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.ParameterGroupImpl;
@@ -42,6 +44,8 @@ public class PapParameterGroup extends ParameterGroupImpl {
private PdpParameters pdpParameters;
private PolicyModelsProviderParameters databaseProviderParameters;
private TopicParameterGroup topicParameterGroup;
+ // API, Distribution Health Check restClient parameters.
+ private List<BusTopicParams> healthCheckRestClientParameters;
/**
* Create the pap parameter group.
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java
index b585b9d2..9d3ad816 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java
@@ -22,6 +22,7 @@
package org.onap.policy.pap.main.rest;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
+import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.startstop.PapActivator;
@@ -35,7 +36,7 @@ public class HealthCheckProvider {
private static final String NOT_ALIVE = "not alive";
private static final String ALIVE = "alive";
- private static final String URL = "self";
+ private static final String URL = NetworkUtil.getHostname();
private static final String NAME = "Policy PAP";
/**
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckControllerV1.java
new file mode 100644
index 00000000..8abc09cd
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckControllerV1.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.Authorization;
+import io.swagger.annotations.Extension;
+import io.swagger.annotations.ExtensionProperty;
+import io.swagger.annotations.ResponseHeader;
+import java.util.Map;
+import java.util.UUID;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ * Class to provide REST end point for PAP component to fetch all policy components, including PAP,
+ * API, Distribution, and PDPs
+ *
+ * @author Yehui Wang (yehui.wang@est.tech)
+ */
+public class PolicyComponentsHealthCheckControllerV1 extends PapRestControllerV1 {
+
+ /**
+ * Returns health status of all Policy components, including PAP, API, Distribution, and PDPs.
+ * Note: a new provider {@link PolicyComponentsHealthCheckProvider} must be created for each
+ * request.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @return a response
+ */
+ // @formatter:off
+ @GET
+ @Path("components/healthcheck")
+ @ApiOperation(value = "Returns health status of all policy components, including PAP, API, Distribution, and PDPs",
+ notes = "Queries health status of all policy components, returning all policy components health status",
+ response = Map.class,
+ tags = {"Policy Administration (PAP) API"},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {@Extension(name = EXTENSION_NAME,
+ properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
+ @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
+ // @formatter:on
+
+ public Response policyComponentsHealthCheck(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+ final Pair<Status, Map<String, Object>> pair =
+ new PolicyComponentsHealthCheckProvider().fetchPolicyComponentsHealthStatus();
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
+ .entity(pair.getRight()).build();
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java
new file mode 100644
index 00000000..ddcab778
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import java.net.HttpURLConnection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.endpoints.report.HealthCheckReport;
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.utils.services.Registry;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.pdp.concepts.Pdp;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.pdp.enums.PdpHealthStatus;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.pap.main.PapConstants;
+import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
+import org.onap.policy.pap.main.parameters.PapParameterGroup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provider for PAP to fetch health status of all Policy components, including PAP, API,
+ * Distribution, and PDPs. Note: a new provider {@link PolicyComponentsHealthCheckProvider} must be
+ * created for each request.
+ *
+ * @author Yehui Wang (yehui.wang@est.tech)
+ */
+public class PolicyComponentsHealthCheckProvider {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PolicyComponentsHealthCheckProvider.class);
+ private static final String PAP_GROUP_PARAMS_NAME = "PapGroup";
+ private static final String HEALTH_STATUS = "healthy";
+ private static final Pattern IP_REPLACEMENT_PATTERN = Pattern.compile("//(\\S+):");
+ private static final String POLICY_PAP_HEALTHCHECK_URI = "/policy/pap/v1/healthcheck";
+ private PapParameterGroup papParameterGroup = ParameterService.get(PAP_GROUP_PARAMS_NAME);
+ private boolean isHealthy = true;
+ private Map<String, Object> result = new HashMap<>();
+
+ /**
+ * Returns health status of all Policy components.
+ *
+ * @return a pair containing the status and the response
+ * @throws PfModelException in case of errors
+ */
+ public Pair<Status, Map<String, Object>> fetchPolicyComponentsHealthStatus() {
+ getHttpClients(papParameterGroup.getHealthCheckRestClientParameters()).parallelStream()
+ .forEach(this::fetchPolicyComponentHealthStatus);
+ HealthCheckReport papReport = new HealthCheckProvider().performHealthCheck();
+ RestServerParameters restServerParameters = papParameterGroup.getRestServerParameters();
+ papReport.setUrl((restServerParameters.isHttps() ? "https://" : "http://") + papReport.getUrl() + ":"
+ + restServerParameters.getPort() + POLICY_PAP_HEALTHCHECK_URI);
+ result.put(PapConstants.POLICY_PAP, papReport);
+ try {
+ Map<String, List<Pdp>> pdpListWithType = fetchPdpsHealthStatus();
+ if (isHealthy && (pdpListWithType.isEmpty() || pdpListWithType.values().stream().flatMap(List::stream)
+ .anyMatch(pdp -> !PdpHealthStatus.HEALTHY.equals(pdp.getHealthy())))) {
+ isHealthy = false;
+ }
+ result.put(PapConstants.POLICY_PDPS, pdpListWithType);
+ } catch (final PfModelException exp) {
+ result.put(PapConstants.POLICY_PDPS, exp.getErrorResponse());
+ isHealthy = false;
+ }
+ result.put(HEALTH_STATUS, isHealthy);
+ LOGGER.debug("Policy Components HealthCheck Response - {}", result);
+ return Pair.of(Response.Status.OK, result);
+ }
+
+ private Map<String, List<Pdp>> fetchPdpsHealthStatus() throws PfModelException {
+ Map<String, List<Pdp>> pdpListWithType = new HashMap<>();
+ final PolicyModelsProviderFactoryWrapper modelProviderWrapper =
+ Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
+ try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
+ final List<PdpGroup> groups = databaseProvider.getPdpGroups(null);
+ for (final PdpGroup group : groups) {
+ for (final PdpSubGroup subGroup : group.getPdpSubgroups()) {
+ List<Pdp> pdpList = new ArrayList<>(subGroup.getPdpInstances());
+ pdpListWithType.computeIfAbsent(subGroup.getPdpType(), k -> new ArrayList<>()).addAll(pdpList);
+ }
+ }
+ }
+ return pdpListWithType;
+ }
+
+ private List<HttpClient> getHttpClients(List<BusTopicParams> restClientParameters) {
+ HttpClientFactory clientFactory = HttpClientFactoryInstance.getClientFactory();
+ for (BusTopicParams params : restClientParameters) {
+ try {
+ params.setManaged(true);
+ clientFactory.build(params);
+ } catch (HttpClientConfigException e) {
+ LOGGER.warn("{} httpClient creation error", params.getClientName());
+ String url = (params.isUseHttps() ? "https://" : "http://") + params.getHostname() + ":"
+ + params.getPort() + "/" + params.getBasePath();
+ storeUnHealthCheckReport(params.getClientName(), url, HttpURLConnection.HTTP_BAD_REQUEST,
+ e.getMessage());
+ }
+ }
+ return clientFactory.inventory();
+ }
+
+ private void fetchPolicyComponentHealthStatus(HttpClient httpClient) {
+ try {
+ Response resp = httpClient.get();
+ if (resp.getStatus() != HttpURLConnection.HTTP_OK) {
+ isHealthy = false;
+ result.put(httpClient.getName(),
+ replaceIpWithHostname(resp.readEntity(HealthCheckReport.class), httpClient.getBaseUrl()));
+ } else {
+ result.put(httpClient.getName(),
+ replaceIpWithHostname(resp.readEntity(HealthCheckReport.class), httpClient.getBaseUrl()));
+ }
+ } catch (RuntimeException e) {
+ LOGGER.warn("{} connection error", httpClient.getName());
+ storeUnHealthCheckReport(httpClient.getName(), httpClient.getBaseUrl(),
+ HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage());
+ }
+ }
+
+
+ private void storeUnHealthCheckReport(String name, String url, int code, String message) {
+ HealthCheckReport report = new HealthCheckReport();
+ report.setName(name);
+ report.setUrl(url);
+ report.setHealthy(false);
+ isHealthy = false;
+ report.setCode(code);
+ report.setMessage(message);
+ result.put(name, report);
+ }
+
+ private HealthCheckReport replaceIpWithHostname(HealthCheckReport report, String baseUrl) {
+ Matcher matcher = IP_REPLACEMENT_PATTERN.matcher(baseUrl);
+ String ip = "";
+ if (matcher.find()) {
+ ip = matcher.group(1);
+ report.setUrl(baseUrl.replace(ip, report.getUrl()));
+ }
+ return report;
+ }
+}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java
deleted file mode 100644
index 8e6410a8..00000000
--- a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pap.main.rest;
-
-import org.onap.policy.common.utils.services.Registry;
-import org.onap.policy.pap.main.PapConstants;
-import org.onap.policy.pap.main.startstop.PapActivator;
-
-/**
- * Class to fetch statistics of pap component.
- *
- * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
- */
-public class StatisticsProvider {
-
- /**
- * Returns the current statistics of pap component.
- *
- * @return Report containing statistics of pap component
- */
- public StatisticsReport fetchCurrentStatistics() {
- final StatisticsReport 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;
- }
-}
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 e8645869..5b36330a 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,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,12 +22,25 @@
package org.onap.policy.pap.main.rest;
import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
+import io.swagger.annotations.Extension;
+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;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
+import org.onap.policy.models.base.PfModelException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Class to provide REST endpoints for PAP component statistics.
@@ -36,15 +49,209 @@ import javax.ws.rs.core.Response;
*/
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.
+ *
+ *
+ * @return a response
+ */
@GET
@Path("statistics")
@ApiOperation(value = "Fetch current statistics",
- notes = "Returns current statistics of the Policy Administration component",
- response = StatisticsReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE))
+ notes = "Returns current statistics of the Policy Administration component",
+ response = StatisticsReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE))
+ @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
+ public Response statistics(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(new StatisticsRestProvider().fetchCurrentStatistics())
+ .build();
+ }
+
+ /**
+ * get all statistics of PDP groups.
+ *
+ *
+ * @return a response
+ */
+ @GET
+ @Path("pdps/statistics")
+ @ApiOperation(value = "Fetch statistics for all PDP Groups and subgroups in the system",
+ notes = "Returns for all PDP Groups and subgroups statistics of the Policy Administration component",
+ response = Map.class, tags = {"Policy Administration (PAP) API"},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {@Extension(name = EXTENSION_NAME,
+ properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
+
+ @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
+ public Response pdpStatistics(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+ try {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(new StatisticsRestProvider().fetchDatabaseStatistics(null, null, null, NO_COUNT_LIMIT))
+ .build();
+ } catch (final PfModelException exp) {
+ LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
+ return addLoggingHeaders(
+ addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
+ .build();
+ }
+ }
+
+ /**
+ * get all statistics of a PDP group.
+ *
+ * @param groupName name of the PDP group
+ * @return a response
+ */
+ @GET
+ @Path("pdps/statistics/{group}")
+ @ApiOperation(value = "Fetch current statistics for given PDP Group",
+ notes = "Returns statistics for given PDP Group of the Policy Administration component",
+ response = Map.class, tags = {"Policy Administration (PAP) API"},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {@Extension(name = EXTENSION_NAME,
+ properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
@ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
- @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
- @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
- public Response statistics() {
- return Response.status(Response.Status.OK).entity(new StatisticsProvider().fetchCurrentStatistics()).build();
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
+ 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) {
+ try {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, null, null, NO_COUNT_LIMIT))
+ .build();
+ } catch (final PfModelException exp) {
+ LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
+ return addLoggingHeaders(
+ addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
+ .build();
+ }
+ }
+
+ /**
+ * get all statistics of sub PDP group.
+ *
+ * @param groupName name of the PDP group
+ * @param subType type of the sub PDP group
+ * @return a response
+ */
+ @GET
+ @Path("pdps/statistics/{group}/{type}")
+ @ApiOperation(value = "Fetch statistics for the specified subgroup",
+ notes = "Returns statistics for the specified subgroup of the Policy Administration component",
+ response = Map.class, tags = {"Policy Administration (PAP) API"},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {@Extension(name = EXTENSION_NAME,
+ properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
+ @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
+ 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) {
+ try {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, null,
+ NO_COUNT_LIMIT))
+ .build();
+ } catch (final PfModelException exp) {
+ LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
+ return addLoggingHeaders(
+ addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
+ .build();
+ }
+ }
+
+ /**
+ * get all statistics of one PDP.
+ *
+ * @param groupName name of the PDP group
+ * @param subType type of the sub PDP group
+ * @param pdpName the name of the PDP
+ * @param recordCount the count of the query response, optional, default return all statistics stored
+ * @return a response
+ */
+ @GET
+ @Path("pdps/statistics/{group}/{type}/{pdp}")
+ @ApiOperation(value = "Fetch statistics for the specified pdp",
+ notes = "Returns statistics for the specified pdp of the Policy Administration component",
+ response = Map.class,
+ tags = {"Policy Administration (PAP) API"},
+ authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+ responseHeaders = {
+ @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+ response = String.class),
+ @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+ response = UUID.class)},
+ extensions = {@Extension(name = EXTENSION_NAME,
+ properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+ @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
+ @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+ @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+ @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
+
+ public Response pdpInstanceStatistics(
+ @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 Instance name", required = true) @PathParam("pdp") final String pdpName,
+ @ApiParam(value = "Record Count",
+ required = false) @DefaultValue("0") @QueryParam("recordCount") final int recordCount) {
+ try {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, pdpName,
+ recordCount))
+ .build();
+ } catch (final PfModelException exp) {
+ LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
+ return addLoggingHeaders(
+ addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
+ .build();
+ }
}
}
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
new file mode 100644
index 00000000..9a283391
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestProvider.java
@@ -0,0 +1,125 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.Response;
+import org.onap.policy.common.utils.services.Registry;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.pap.main.PapConstants;
+import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
+import org.onap.policy.pap.main.startstop.PapActivator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class to fetch statistics of pap component.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+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 DESC_ORDER = "DESC";
+
+ /**
+ * Returns the current statistics of pap component.
+ *
+ * @return Report containing statistics of pap component
+ */
+ public StatisticsReport fetchCurrentStatistics() {
+ final StatisticsReport 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;
+ }
+
+ /**
+ * Returns statistics of pdp component from database.
+ *
+ * @param groupName name of the PDP group
+ * @param subType type of the sub PDP group
+ * @param pdpName the name of the PDP
+ * @param recordCount the count to query from database
+ * @return Report containing statistics of pdp component
+ * @throws PfModelException when database can not found
+ */
+ public Map<String, Map<String, List<PdpStatistics>>> fetchDatabaseStatistics(String groupName, String subType,
+ 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()) {
+ Date startTime = null;
+ Date endTime = null;
+
+ if (groupName == null) {
+ pdpStatisticsMap = generatePdpStatistics(databaseProvider.getPdpStatistics(pdpName, startTime));
+ } else {
+ pdpStatisticsMap = generatePdpStatistics(databaseProvider.getFilteredPdpStatistics(pdpName, groupName,
+ subType, startTime, endTime, DESC_ORDER, recordCount));
+ }
+ } 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;
+ }
+
+ /**
+ * generate the statistics of pap component by group/subgroup.
+ *
+ */
+ private Map<String, Map<String, List<PdpStatistics>>> generatePdpStatistics(List<PdpStatistics> pdpStatisticsList) {
+ Map<String, Map<String, List<PdpStatistics>>> groupMap = new HashMap<>();
+ if (pdpStatisticsList != null) {
+ pdpStatisticsList.stream().forEach(s -> {
+ String curGroup = s.getPdpGroupName();
+ String curSubGroup = s.getPdpSubGroupName();
+ groupMap.computeIfAbsent(curGroup, curGroupMap -> new HashMap<>())
+ .computeIfAbsent(curSubGroup, curSubGroupList -> new ArrayList<>()).add(s);
+ });
+ }
+ return groupMap;
+ }
+}
+
+
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
index 1721cb0d..83b9151c 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
@@ -56,6 +56,7 @@ import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1;
import org.onap.policy.pap.main.rest.PdpGroupHealthCheckControllerV1;
import org.onap.policy.pap.main.rest.PdpGroupQueryControllerV1;
import org.onap.policy.pap.main.rest.PdpGroupStateChangeControllerV1;
+import org.onap.policy.pap.main.rest.PolicyComponentsHealthCheckControllerV1;
import org.onap.policy.pap.main.rest.PolicyStatusControllerV1;
import org.onap.policy.pap.main.rest.PolicyUndeployerImpl;
import org.onap.policy.pap.main.rest.StatisticsRestControllerV1;
@@ -246,7 +247,8 @@ public class PapActivator extends ServiceManagerContainer {
PdpGroupStateChangeControllerV1.class,
PdpGroupQueryControllerV1.class,
PdpGroupHealthCheckControllerV1.class,
- PolicyStatusControllerV1.class);
+ PolicyStatusControllerV1.class,
+ PolicyComponentsHealthCheckControllerV1.class);
restServer.set(server);
restServer.get().start();
},
diff --git a/main/src/main/resources/META-INF/persistence.xml b/main/src/main/resources/META-INF/persistence.xml
index b1358362..4a678b01 100644
--- a/main/src/main/resources/META-INF/persistence.xml
+++ b/main/src/main/resources/META-INF/persistence.xml
@@ -6,15 +6,15 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-
+
SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
-->
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
index 8660d005..3823365b 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
@@ -72,7 +72,7 @@ public class CommonPapRestServer {
public static final String NOT_ALIVE = "not alive";
public static final String ALIVE = "alive";
- public static final String SELF = "self";
+ public static final String SELF = NetworkUtil.getHostname();
public static final String NAME = "Policy PAP";
public static final String ENDPOINT_PREFIX = "policy/pap/v1/";
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java
new file mode 100644
index 00000000..f73178b7
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test of {@link PolicyComponentsHealthCheckControllerV1}.
+ *
+ * @author Yehui Wang (yehui.wang@est.tech)
+ */
+public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer {
+
+ private static final String ENDPOINT = "components/healthcheck";
+
+ @Test
+ public void testSwagger() throws Exception {
+ super.testSwagger(ENDPOINT);
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java
index 1894fd7b..70deedc1 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,10 +36,15 @@ import org.onap.policy.pap.main.PapConstants;
public class TestStatisticsRestControllerV1 extends CommonPapRestServer {
private static final String STATISTICS_ENDPOINT = "statistics";
+ private static final String STATISTICS_DB_ENDPOINT = "pdps/statistics";
@Test
public void testSwagger() throws Exception {
super.testSwagger(STATISTICS_ENDPOINT);
+ super.testSwagger(STATISTICS_DB_ENDPOINT);
+ super.testSwagger(STATISTICS_DB_ENDPOINT + "/{group}");
+ super.testSwagger(STATISTICS_DB_ENDPOINT + "/{group}" + "/{type}");
+ super.testSwagger(STATISTICS_DB_ENDPOINT + "/{group}" + "/{type}" + "/{pdp}");
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java
index 13492cf9..aa2c59ea 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,15 +24,27 @@ package org.onap.policy.pap.main.rest.e2e;
import static org.junit.Assert.assertEquals;
import java.net.HttpURLConnection;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
import org.junit.Test;
import org.onap.policy.common.utils.services.Registry;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.pap.main.PapConstants;
+import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
import org.onap.policy.pap.main.rest.PapStatisticsManager;
import org.onap.policy.pap.main.rest.StatisticsReport;
public class StatisticsTest extends End2EndBase {
private static final String STATISTICS_ENDPOINT = "statistics";
+ private List<PdpStatistics> recordList = new ArrayList<>();
@Test
@@ -56,6 +69,47 @@ public class StatisticsTest extends End2EndBase {
assertEquals(report.getPolicyDeployFailureCount() + 1, report2.getPolicyDeployFailureCount());
}
+ @Test
+ public void testDb() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+ }
+
+ @Test
+ public void testDbWithGroup() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics/defaultGroup");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+
+ }
+
+ @Test
+ public void testDbWithSubGroup() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics/defaultGroup/apex");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+ }
+
+ @Test
+ public void testDbWithPdp() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics/defaultGroup/apex/pdp1");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+ }
+
+ @Test
+ public void testDbWithPdpLatest() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics/defaultGroup/apex/pdp1?recordCount=5");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+ }
+
private void updateDistributionStatistics() {
PapStatisticsManager mgr = Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class);
@@ -68,4 +122,38 @@ public class StatisticsTest extends End2EndBase {
mgr.updatePolicyDownloadSuccessCount();
mgr.updatePolicyDownloadFailureCount();
}
+
+ private void setupEnv() {
+ PolicyModelsProviderFactoryWrapper modelProviderWrapper =
+ Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
+
+ try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
+ PdpStatistics pdpStatisticsRecord = new PdpStatistics();
+ pdpStatisticsRecord.setPdpGroupName("defaultGroup");
+ pdpStatisticsRecord.setPdpSubGroupName("apex");
+ pdpStatisticsRecord.setPdpInstanceId("pdp1");
+ pdpStatisticsRecord.setTimeStamp(new Date());
+ pdpStatisticsRecord.setPolicyDeployCount(1);
+ pdpStatisticsRecord.setPolicyDeployFailCount(0);
+ pdpStatisticsRecord.setPolicyDeploySuccessCount(1);
+ pdpStatisticsRecord.setPolicyExecutedCount(1);
+ pdpStatisticsRecord.setPolicyExecutedFailCount(0);
+ pdpStatisticsRecord.setPolicyExecutedSuccessCount(1);
+ recordList.add(pdpStatisticsRecord);
+ databaseProvider.createPdpStatistics(recordList);
+ } catch (final PfModelException exp) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, exp.getMessage());
+ }
+ }
+
+ private void verifyResponse(Response testResponse) {
+ assertEquals(Response.Status.OK.getStatusCode(), testResponse.getStatus());
+ Map<String, Map<String, List<PdpStatistics>>> map =
+ testResponse.readEntity(new GenericType<Map<String, Map<String, List<PdpStatistics>>>>() {});
+ Map<String, List<PdpStatistics>> subMap = map.get("defaultGroup");
+ List<PdpStatistics> resRecord = subMap.get("apex");
+ assertEquals("pdp1", resRecord.get(0).getPdpInstanceId());
+ assertEquals("apex", resRecord.get(0).getPdpSubGroupName());
+ assertEquals("defaultGroup", resRecord.get(0).getPdpGroupName());
+ }
}
diff --git a/main/src/test/resources/e2e/PapConfigParameters.json b/main/src/test/resources/e2e/PapConfigParameters.json
index 17507bdb..610ded8c 100644
--- a/main/src/test/resources/e2e/PapConfigParameters.json
+++ b/main/src/test/resources/e2e/PapConfigParameters.json
@@ -42,5 +42,23 @@
"servers" : [ "message-router" ],
"topicCommInfrastructure" : "noop"
}]
- }
+ },
+ "healthCheckRestClientParameters":[{
+ "clientName": "api",
+ "hostname": "policy-api",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "policy/api/v1/healthcheck"
+ },
+ {
+ "clientName": "distribution",
+ "hostname": "policy-distribution",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "healthcheck"
+ }]
}
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index 6b21b4dc..69492e9b 100644
--- a/main/src/test/resources/parameters/MinimumParameters.json
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -37,5 +37,23 @@
"servers" : [ "message-router" ],
"topicCommInfrastructure" : "dmaap"
}]
- }
+ },
+ "healthCheckRestClientParameters":[{
+ "clientName": "api",
+ "hostname": "policy-api",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "policy/api/v1/healthcheck"
+ },
+ {
+ "clientName": "distribution",
+ "hostname": "policy-distribution",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "healthcheck"
+ }]
}
diff --git a/main/src/test/resources/parameters/PapConfigParameters.json b/main/src/test/resources/parameters/PapConfigParameters.json
index 11315029..111a6352 100644
--- a/main/src/test/resources/parameters/PapConfigParameters.json
+++ b/main/src/test/resources/parameters/PapConfigParameters.json
@@ -42,5 +42,23 @@
"servers" : [ "message-router" ],
"topicCommInfrastructure" : "noop"
}]
- }
+ },
+ "healthCheckRestClientParameters":[{
+ "clientName": "api",
+ "hostname": "policy-api",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "policy/api/v1/healthcheck"
+ },
+ {
+ "clientName": "distribution",
+ "hostname": "policy-distribution",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "healthcheck"
+ }]
}
diff --git a/main/src/test/resources/parameters/PapConfigParametersStd.json b/main/src/test/resources/parameters/PapConfigParametersStd.json
index 828c1a44..47925dff 100644
--- a/main/src/test/resources/parameters/PapConfigParametersStd.json
+++ b/main/src/test/resources/parameters/PapConfigParametersStd.json
@@ -42,5 +42,23 @@
"servers" : [ "message-router" ],
"topicCommInfrastructure" : "noop"
}]
- }
+ },
+ "healthCheckRestClientParameters":[{
+ "clientName": "api",
+ "hostname": "policy-api",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "policy/api/v1/healthcheck"
+ },
+ {
+ "clientName": "distribution",
+ "hostname": "policy-distribution",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "healthcheck"
+ }]
}