aboutsummaryrefslogtreecommitdiffstats
path: root/feature-healthcheck/src/main/java
diff options
context:
space:
mode:
authormmis <michael.morris@ericsson.com>2018-07-19 13:21:08 +0100
committermmis <michael.morris@ericsson.com>2018-07-25 09:14:33 +0100
commit64f53ef14f5a9ea98208fd2b835bfb01fda9a5f9 (patch)
tree60afa251c126287a85c89e0b1dc7fd5d1a766439 /feature-healthcheck/src/main/java
parente8f1b7235f8338fbb9eba28d8cff29d3d6adf6e7 (diff)
Copy policy-endpoints from drools-pdp to common
Removed policy-endpoints, and 3 classes from policy-core. Replaced refenences to the deleted classes with references to the corresponding classes in policy-common Issue-ID: POLICY-967 Change-Id: I547cde4894424b8f40b7ddd4e2342ebb729cb588 Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'feature-healthcheck/src/main/java')
-rw-r--r--feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java482
1 files changed, 243 insertions, 239 deletions
diff --git a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
index fb3da657..9c543412 100644
--- a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
+++ b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
@@ -26,10 +26,12 @@ import java.util.Properties;
import javax.ws.rs.core.Response;
-import org.onap.policy.drools.http.client.HttpClient;
-import org.onap.policy.drools.http.server.HttpServletServer;
+import org.onap.policy.common.capabilities.Startable;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.impl.IndexedHttpClientFactory;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.impl.IndexedHttpServletServerFactory;
import org.onap.policy.drools.persistence.SystemPersistence;
-import org.onap.policy.drools.properties.Startable;
import org.onap.policy.drools.system.PolicyEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,56 +41,56 @@ import org.slf4j.LoggerFactory;
*/
public interface HealthCheck extends Startable {
- /**
- * Healthcheck Monitor
- */
- public static final HealthCheck monitor = new HealthCheckMonitor();
-
- /**
- * Healthcheck Report
- */
- public static class Report {
- /**
- * Named Entity in the report
- */
- private String name;
-
- /**
- * URL queried
- */
- private String url;
-
- /**
- * healthy?
- */
- private boolean healthy;
-
- /**
- * return code
- */
- private int code;
-
- /**
- * Message from remote entity
- */
- private String message;
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Report [name=");
- builder.append(getName());
- builder.append(", url=");
- builder.append(getUrl());
- builder.append(", healthy=");
- builder.append(isHealthy());
- builder.append(", code=");
- builder.append(getCode());
- builder.append(", message=");
- builder.append(getMessage());
- builder.append("]");
- return builder.toString();
- }
+ /**
+ * Healthcheck Monitor
+ */
+ public static final HealthCheck monitor = new HealthCheckMonitor();
+
+ /**
+ * Healthcheck Report
+ */
+ public static class Report {
+ /**
+ * Named Entity in the report
+ */
+ private String name;
+
+ /**
+ * URL queried
+ */
+ private String url;
+
+ /**
+ * healthy?
+ */
+ private boolean healthy;
+
+ /**
+ * return code
+ */
+ private int code;
+
+ /**
+ * Message from remote entity
+ */
+ private String message;
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Report [name=");
+ builder.append(getName());
+ builder.append(", url=");
+ builder.append(getUrl());
+ builder.append(", healthy=");
+ builder.append(isHealthy());
+ builder.append(", code=");
+ builder.append(getCode());
+ builder.append(", message=");
+ builder.append(getMessage());
+ builder.append("]");
+ return builder.toString();
+ }
public String getName() {
return name;
@@ -129,25 +131,25 @@ public interface HealthCheck extends Startable {
public void setMessage(String message) {
this.message = message;
}
- }
-
- /**
- * Report aggregation
- */
- public static class Reports {
- private boolean healthy;
- private List<Report> details = new ArrayList<>();
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Reports [healthy=");
- builder.append(isHealthy());
- builder.append(", details=");
- builder.append(getDetails());
- builder.append("]");
- return builder.toString();
- }
+ }
+
+ /**
+ * Report aggregation
+ */
+ public static class Reports {
+ private boolean healthy;
+ private List<Report> details = new ArrayList<>();
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Reports [healthy=");
+ builder.append(isHealthy());
+ builder.append(", details=");
+ builder.append(getDetails());
+ builder.append("]");
+ return builder.toString();
+ }
public boolean isHealthy() {
return healthy;
@@ -164,188 +166,190 @@ public interface HealthCheck extends Startable {
public void setDetails(List<Report> details) {
this.details = details;
}
- }
-
- /**
- * perform a healthcheck
- * @return a report
- */
- public Reports healthCheck();
+ }
+
+ /**
+ * perform a healthcheck
+ *
+ * @return a report
+ */
+ public Reports healthCheck();
}
+
/**
* Healthcheck Monitor
*/
class HealthCheckMonitor implements HealthCheck {
- /**
- * Logger
- */
- private static Logger logger = LoggerFactory.getLogger(HealthCheckMonitor.class);
-
- /**
- * attached http servers
- */
- protected volatile List<HttpServletServer> servers = new ArrayList<>();
-
- /**
- * attached http clients
- */
- protected volatile List<HttpClient> clients = new ArrayList<>();
-
- /**
- * healthcheck configuration
- */
- protected volatile Properties healthCheckProperties = null;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Reports healthCheck() {
- Reports reports = new Reports();
- reports.setHealthy(PolicyEngine.manager.isAlive());
-
- HealthCheck.Report engineReport = new Report();
- engineReport.setHealthy(PolicyEngine.manager.isAlive());
- engineReport.setName("PDP-D");
- engineReport.setUrl("self");
- engineReport.setCode(PolicyEngine.manager.isAlive() ? 200 : 500);
- engineReport.setMessage(PolicyEngine.manager.isAlive() ? "alive" : "not alive");
- reports.getDetails().add(engineReport);
-
- for (HttpClient client : clients) {
- HealthCheck.Report report = new Report();
- report.setName(client.getName());
- report.setUrl(client.getBaseUrl());
- report.setHealthy(true);
- try {
- Response response = client.get();
- report.setCode(response.getStatus());
- if (report.getCode() != 200) {
- report.setHealthy(false);
- reports.setHealthy(false);
- }
-
- report.setMessage(getHttpBody(response, client));
- } catch (Exception e) {
- logger.warn("{}: cannot contact http-client {}", this, client, e);
-
- report.setHealthy(false);
- reports.setHealthy(false);
- }
- reports.getDetails().add(report);
- }
- return reports;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean start() {
-
- try {
- this.healthCheckProperties = SystemPersistence.manager.getProperties(HealthCheckFeature.CONFIGURATION_PROPERTIES_NAME);
- this.servers = HttpServletServer.factory.build(healthCheckProperties);
- this.clients = HttpClient.factory.build(healthCheckProperties);
-
- for (HttpServletServer server : servers) {
- startServer(server);
- }
- } catch (Exception e) {
- logger.warn("{}: cannot start {}", this, e);
- return false;
- }
-
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean stop() {
-
- for (HttpServletServer server : servers) {
- try {
- server.stop();
- } catch (Exception e) {
- logger.warn("{}: cannot stop http-server {}", this, server, e);
- }
- }
-
- for (HttpClient client : clients) {
- try {
- client.stop();
- } catch (Exception e) {
- logger.warn("{}: cannot stop http-client {}", this, client, e);
- }
- }
-
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void shutdown() {
- this.stop();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public synchronized boolean isAlive() {
- return this.healthCheckProperties != null;
- }
-
- /**
- * @return list of attached Http Servers
- */
- public List<HttpServletServer> getServers() {
- return this.servers;
- }
-
- /**
- * @return list of attached Http Clients
- */
- public List<HttpClient> getClients() {
- return this.clients;
- }
-
- public String getHttpBody(Response response, HttpClient client) {
-
- String body = null;
+ /**
+ * Logger
+ */
+ private static Logger logger = LoggerFactory.getLogger(HealthCheckMonitor.class);
+
+ /**
+ * attached http servers
+ */
+ protected volatile List<HttpServletServer> servers = new ArrayList<>();
+
+ /**
+ * attached http clients
+ */
+ protected volatile List<HttpClient> clients = new ArrayList<>();
+
+ /**
+ * healthcheck configuration
+ */
+ protected volatile Properties healthCheckProperties = null;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Reports healthCheck() {
+ Reports reports = new Reports();
+ reports.setHealthy(PolicyEngine.manager.isAlive());
+
+ HealthCheck.Report engineReport = new Report();
+ engineReport.setHealthy(PolicyEngine.manager.isAlive());
+ engineReport.setName("PDP-D");
+ engineReport.setUrl("self");
+ engineReport.setCode(PolicyEngine.manager.isAlive() ? 200 : 500);
+ engineReport.setMessage(PolicyEngine.manager.isAlive() ? "alive" : "not alive");
+ reports.getDetails().add(engineReport);
+
+ for (HttpClient client : clients) {
+ HealthCheck.Report report = new Report();
+ report.setName(client.getName());
+ report.setUrl(client.getBaseUrl());
+ report.setHealthy(true);
+ try {
+ Response response = client.get();
+ report.setCode(response.getStatus());
+ if (report.getCode() != 200) {
+ report.setHealthy(false);
+ reports.setHealthy(false);
+ }
+
+ report.setMessage(getHttpBody(response, client));
+ } catch (Exception e) {
+ logger.warn("{}: cannot contact http-client {}", this, client, e);
+
+ report.setHealthy(false);
+ reports.setHealthy(false);
+ }
+ reports.getDetails().add(report);
+ }
+ return reports;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean start() {
+
+ try {
+ this.healthCheckProperties =
+ SystemPersistence.manager.getProperties(HealthCheckFeature.CONFIGURATION_PROPERTIES_NAME);
+ this.servers = IndexedHttpServletServerFactory.getInstance().build(healthCheckProperties);
+ this.clients = IndexedHttpClientFactory.getInstance().build(healthCheckProperties);
+
+ for (HttpServletServer server : servers) {
+ startServer(server);
+ }
+ } catch (Exception e) {
+ logger.warn("{}: cannot start {}", this, e);
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean stop() {
+
+ for (HttpServletServer server : servers) {
+ try {
+ server.stop();
+ } catch (Exception e) {
+ logger.warn("{}: cannot stop http-server {}", this, server, e);
+ }
+ }
+
+ for (HttpClient client : clients) {
+ try {
+ client.stop();
+ } catch (Exception e) {
+ logger.warn("{}: cannot stop http-client {}", this, client, e);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void shutdown() {
+ this.stop();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized boolean isAlive() {
+ return this.healthCheckProperties != null;
+ }
+
+ /**
+ * @return list of attached Http Servers
+ */
+ public List<HttpServletServer> getServers() {
+ return this.servers;
+ }
+
+ /**
+ * @return list of attached Http Clients
+ */
+ public List<HttpClient> getClients() {
+ return this.clients;
+ }
+
+ public String getHttpBody(Response response, HttpClient client) {
+
+ String body = null;
try {
body = HttpClient.getBody(response, String.class);
} catch (Exception e) {
- logger.info("{}: cannot get body from http-client {}", this,
- client, e);
+ logger.info("{}: cannot get body from http-client {}", this, client, e);
}
-
+
return body;
- }
-
- public void startServer(HttpServletServer server) {
+ }
+
+ public void startServer(HttpServletServer server) {
try {
server.start();
} catch (Exception e) {
logger.warn("{}: cannot start http-server {}", this, server, e);
}
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("HealthCheckMonitor [servers=");
- builder.append(servers);
- builder.append(", clients=");
- builder.append(clients);
- builder.append("]");
- return builder.toString();
- }
-
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("HealthCheckMonitor [servers=");
+ builder.append(servers);
+ builder.append(", clients=");
+ builder.append(clients);
+ builder.append("]");
+ return builder.toString();
+ }
+
}