aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java34
1 files changed, 31 insertions, 3 deletions
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 dbbb49e8..f7cfb363 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 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.
@@ -25,8 +25,12 @@ 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.models.base.PfModelRuntimeException;
import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.startstop.PapActivator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@@ -42,21 +46,45 @@ public class HealthCheckProvider {
private static final String URL = NetworkUtil.getHostname();
private static final String NAME = "Policy PAP";
+ @Autowired
+ private PolicyStatusProvider policyStatusProvider;
+ private static final Logger LOGGER = LoggerFactory.getLogger(HealthCheckProvider.class);
+
/**
* Performs the health check of PAP service.
*
+ * @param checkDbConnectivity flag to enable pap to db connectivity verification
* @return Report containing health check status
*/
- public HealthCheckReport performHealthCheck() {
+ public HealthCheckReport performHealthCheck(boolean checkDbConnectivity) {
final var report = new HealthCheckReport();
report.setName(NAME);
report.setUrl(URL);
boolean alive = Registry.get(PapConstants.REG_PAP_ACTIVATOR, PapActivator.class).isAlive();
+ if (alive && checkDbConnectivity) {
+ alive = verifyPapDbConnectivity();
+ }
+
report.setHealthy(alive);
- report.setCode(alive ? 200 : 500);
+ report.setCode(alive ? 200 : 503);
report.setMessage(alive ? ALIVE : NOT_ALIVE);
return report;
}
+
+ /**
+ * Verifies the connectivity between pap component & policy database.
+ *
+ * @return boolean signaling the verification result
+ */
+ private boolean verifyPapDbConnectivity() {
+ try {
+ policyStatusProvider.getPolicyStatus();
+ return true;
+ } catch (PfModelRuntimeException pfModelRuntimeException) {
+ LOGGER.warn("Policy pap to database connection check failed. Details - ", pfModelRuntimeException);
+ return false;
+ }
+ }
}