aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java29
1 files changed, 9 insertions, 20 deletions
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
index 7a490166..d2a730eb 100644
--- 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020-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.
@@ -40,6 +40,7 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
@@ -47,20 +48,16 @@ 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.RestClientParameters;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
-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.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.onap.policy.pap.main.service.PdpGroupService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@@ -71,6 +68,7 @@ import org.springframework.stereotype.Service;
* @author Yehui Wang (yehui.wang@est.tech)
*/
@Service
+@RequiredArgsConstructor
public class PolicyComponentsHealthCheckProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(PolicyComponentsHealthCheckProvider.class);
@@ -80,8 +78,9 @@ public class PolicyComponentsHealthCheckProvider {
private static List<HttpClient> clients = new ArrayList<>();
private ExecutorService clientHealthCheckExecutorService;
- @Autowired
- private PapParameterGroup papParameterGroup;
+ private final PapParameterGroup papParameterGroup;
+
+ private final PdpGroupService pdpGroupService;
@Value("${server.ssl.enabled:false}")
private boolean isHttps;
@@ -157,14 +156,14 @@ public class PolicyComponentsHealthCheckProvider {
// Check PDPs, read status from DB
try {
- List<PdpGroup> groups = fetchPdpGroups();
+ List<PdpGroup> groups = pdpGroupService.getPdpGroups();
Map<String, List<Pdp>> pdpListWithType = fetchPdpsHealthStatus(groups);
if (isHealthy && (!verifyNumberOfPdps(groups) || 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) {
+ } catch (final PfModelRuntimeException exp) {
result.put(PapConstants.POLICY_PDPS, exp.getErrorResponse());
isHealthy = false;
}
@@ -198,16 +197,6 @@ public class PolicyComponentsHealthCheckProvider {
return flag;
}
- private List<PdpGroup> fetchPdpGroups() throws PfModelException {
- List<PdpGroup> groups = new ArrayList<>();
- final PolicyModelsProviderFactoryWrapper modelProviderWrapper =
- Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
- try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
- groups = databaseProvider.getPdpGroups(null);
- }
- return groups;
- }
-
private HealthCheckReport fetchPolicyComponentHealthStatus(HttpClient httpClient) {
HealthCheckReport clientReport;
try {