From 564f81837de6d50681270ed3f559cb7be068d3cd Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Fri, 30 Jun 2017 13:29:03 -0500 Subject: [POLICY-66] rename of policy-healthcheck using "feature-" naming convention. Change-Id: I13d6b75750d369ed9e61f3c9c9408b31eac6bb2d Signed-off-by: Jorge Hernandez --- feature-healthcheck/pom.xml | 120 +++++++++ feature-healthcheck/src/assembly/assemble_zip.xml | 85 +++++++ .../policy/drools/healthcheck/HealthCheck.java | 277 +++++++++++++++++++++ .../drools/healthcheck/HealthCheckFeature.java | 78 ++++++ .../policy/drools/healthcheck/RestHealthCheck.java | 77 ++++++ ...p.policy.drools.features.PolicyEngineFeatureAPI | 1 + packages/install/pom.xml | 2 +- packages/install/src/files/base.conf | 4 +- policy-healthcheck/pom.xml | 120 --------- policy-healthcheck/src/assembly/assemble_zip.xml | 85 ------- .../policy/drools/healthcheck/HealthCheck.java | 277 --------------------- .../drools/healthcheck/HealthCheckFeature.java | 78 ------ .../policy/drools/healthcheck/RestHealthCheck.java | 77 ------ ...p.policy.drools.features.PolicyEngineFeatureAPI | 1 - .../server/config/feature-healthcheck.properties | 44 ++++ .../server/config/policy-healthcheck.properties | 44 ---- pom.xml | 2 +- 17 files changed, 686 insertions(+), 686 deletions(-) create mode 100644 feature-healthcheck/pom.xml create mode 100644 feature-healthcheck/src/assembly/assemble_zip.xml create mode 100644 feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java create mode 100644 feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java create mode 100644 feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java create mode 100644 feature-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI delete mode 100644 policy-healthcheck/pom.xml delete mode 100644 policy-healthcheck/src/assembly/assemble_zip.xml delete mode 100644 policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java delete mode 100644 policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java delete mode 100644 policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java delete mode 100644 policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI create mode 100644 policy-management/src/main/server/config/feature-healthcheck.properties delete mode 100644 policy-management/src/main/server/config/policy-healthcheck.properties diff --git a/feature-healthcheck/pom.xml b/feature-healthcheck/pom.xml new file mode 100644 index 00000000..58ea7681 --- /dev/null +++ b/feature-healthcheck/pom.xml @@ -0,0 +1,120 @@ + + + + + 4.0.0 + + + org.openecomp.policy.drools-pdp + drools-pdp + 1.1.0-SNAPSHOT + + + feature-healthcheck + + feature-healthcheck + Loadable module that performs remote system healthchecks + + + 1.8 + 1.8 + + + + + + maven-assembly-plugin + 2.6 + + + zipfile + + single + + package + + true + ${project.artifactId}-${project.version} + + src/assembly/assemble_zip.xml + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.8 + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/lib + false + true + true + false + false + false + org.opendaylight,com.brocade.odl + provided + + + + + + + + + + io.swagger + swagger-jersey2-jaxrs + provided + + + org.openecomp.policy.drools-pdp + policy-core + ${project.version} + provided + + + org.openecomp.policy.drools-pdp + policy-endpoints + ${project.version} + provided + + + org.openecomp.policy.drools-pdp + policy-management + ${project.version} + provided + + + + diff --git a/feature-healthcheck/src/assembly/assemble_zip.xml b/feature-healthcheck/src/assembly/assemble_zip.xml new file mode 100644 index 00000000..51a752a3 --- /dev/null +++ b/feature-healthcheck/src/assembly/assemble_zip.xml @@ -0,0 +1,85 @@ + + + + + + runtime + + zip + + + + false + + + + target + lib/opt + + feature-healthcheck-${project.version}.jar + + + + target/assembly/ + . + + + + + . + lib + + *.jar + + + + src/main/server-gen/bin + bin + 0744 + + + + + src/main/server/bin + bin + 0744 + + + + + src/main/server-gen/scripts + scripts + + + src/main/server/scripts + scripts + + + src/main/server/config + config + + + + diff --git a/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java b/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java new file mode 100644 index 00000000..324ea11b --- /dev/null +++ b/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java @@ -0,0 +1,277 @@ +/*- + * ============LICENSE_START======================================================= + * feature-healthcheck + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.healthcheck; + +import java.util.ArrayList; +import java.util.Properties; + +import javax.ws.rs.core.Response; + +import org.openecomp.policy.drools.http.client.HttpClient; +import org.openecomp.policy.drools.http.server.HttpServletServer; +import org.openecomp.policy.drools.persistence.SystemPersistence; +import org.openecomp.policy.drools.properties.Startable; +import org.openecomp.policy.drools.system.PolicyEngine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Healthcheck + */ +public interface HealthCheck extends Startable { + + /** + * Healthcheck Report + */ + public static class Report { + /** + * Named Entity in the report + */ + public String name; + + /** + * URL queried + */ + public String url; + + /** + * healthy? + */ + public boolean healthy; + + /** + * return code + */ + public int code; + + /** + * Message from remote entity + */ + public String message; + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Report [name="); + builder.append(name); + builder.append(", url="); + builder.append(url); + builder.append(", healthy="); + builder.append(healthy); + builder.append(", code="); + builder.append(code); + builder.append(", message="); + builder.append(message); + builder.append("]"); + return builder.toString(); + } + } + + /** + * Report aggregation + */ + public static class Reports { + public boolean healthy; + public ArrayList details = new ArrayList<>(); + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Reports [healthy="); + builder.append(healthy); + builder.append(", details="); + builder.append(details); + builder.append("]"); + return builder.toString(); + } + } + + /** + * perform a healthcheck + * @return a report + */ + public Reports healthCheck(); + + /** + * Healthcheck Monitor + */ + public static final HealthCheck monitor = new HealthCheckMonitor(); +} + +/** + * Healthcheck Monitor + */ +class HealthCheckMonitor implements HealthCheck { + + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(HealthCheckMonitor.class); + + /** + * attached http servers + */ + protected volatile ArrayList servers = new ArrayList<>(); + + /** + * attached http clients + */ + protected volatile ArrayList clients = new ArrayList<>(); + + /** + * healthcheck configuration + */ + protected volatile Properties healthCheckProperties = null; + + /** + * {@inheritDoc} + */ + public Reports healthCheck() { + Reports reports = new Reports(); + reports.healthy = PolicyEngine.manager.isAlive(); + + HealthCheck.Report engineReport = new Report(); + engineReport.healthy = PolicyEngine.manager.isAlive(); + engineReport.name = "PDP-D"; + engineReport.url = "self"; + engineReport.code = (PolicyEngine.manager.isAlive()) ? 200 : 500; + engineReport.message = (PolicyEngine.manager.isAlive()) ? "alive" : "not alive"; + reports.details.add(engineReport); + + for (HttpClient client : clients) { + HealthCheck.Report report = new Report(); + report.name = client.getName(); + report.url = client.getBaseUrl(); + report.healthy = true; + try { + Response response = client.get(); + report.code = response.getStatus(); + if (report.code != 200) { + report.healthy = false; + reports.healthy = false; + } + + try { + report.message = HttpClient.getBody(response, String.class); + } catch (Exception e) { + logger.warn("{}: cannot get body from http-client {}", this, client, e); + } + } catch (Exception e) { + report.healthy = false; + reports.healthy = false; + } + reports.details.add(report); + } + return reports; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean start() throws IllegalStateException { + + 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) { + try { + server.start(); + } catch (Exception e) { + logger.warn("{}: cannot start http-server {}", this, server, e); + } + } + } catch (Exception e) { + return false; + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean stop() throws IllegalStateException { + + 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() throws IllegalStateException { + this.stop(); + } + + /** + * {@inheritDoc} + */ + @Override + public synchronized boolean isAlive() { + return this.healthCheckProperties != null; + } + + /** + * @return list of attached Http Servers + */ + public ArrayList getServers() { + return this.servers; + } + + /** + * @return list of attached Http Clients + */ + public ArrayList getClients() { + return this.clients; + } + + @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(); + } + +} diff --git a/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java b/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java new file mode 100644 index 00000000..ac5b4b49 --- /dev/null +++ b/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * feature-healthcheck + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.drools.healthcheck; + +import org.openecomp.policy.drools.features.PolicyEngineFeatureAPI; +import org.openecomp.policy.drools.system.PolicyEngine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This feature provides healthcheck verification of remotely associated RESTful components + */ +public class HealthCheckFeature implements PolicyEngineFeatureAPI { + + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(HealthCheckFeature.class); + + /** + * Properties Configuration Name + */ + public static final String CONFIGURATION_PROPERTIES_NAME = "feature-healthcheck"; + + @Override + public int getSequenceNumber() { + return 1000; + } + + @Override + public boolean afterStart(PolicyEngine engine) { + try { + HealthCheck.monitor.start(); + } catch (IllegalStateException e) { + logger.error("Healthcheck Monitor cannot be started", e); + } + + return false; + } + + @Override + public boolean afterShutdown(PolicyEngine engine) { + try { + HealthCheck.monitor.stop(); + } catch (IllegalStateException e) { + logger.error("Healthcheck Monitor cannot be stopped", e); + } + + return false; + } + + /** + * gets the monitor + * @return the healthcheck monitor + */ + public HealthCheck getMonitor() { + return HealthCheck.monitor; + } + +} diff --git a/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java b/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java new file mode 100644 index 00000000..f90363fc --- /dev/null +++ b/feature-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * feature-healthcheck + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * 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. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.drools.healthcheck; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.openecomp.policy.drools.healthcheck.HealthCheck.Reports; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.Info; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; + +@Path("/") +@Api +@Produces(MediaType.APPLICATION_JSON) +@SwaggerDefinition( + info = @Info( + description = "PDP-D Healthcheck Service", + version = "v1.0", + title = "PDP-D Healthcheck" + ), + consumes = {MediaType.APPLICATION_JSON}, + produces = {MediaType.APPLICATION_JSON}, + schemes = {SwaggerDefinition.Scheme.HTTP}, + tags = { + @Tag(name = "pdp-d-healthcheck", description = "Drools PDP Healthcheck Operations") + } +) +public class RestHealthCheck { + + @GET + @Path("healthcheck") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + value="Perform a system healthcheck", + notes="Provides healthy status of the PDP-D plus the components defined in its configuration by using a REST interface", + response=Reports.class + ) + public Response healthcheck() { + return Response.status(Response.Status.OK).entity(HealthCheck.monitor.healthCheck()).build(); + } + + @GET + @Path("healthcheck/configuration") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + value="Configuration", + notes="Provides the Healthcheck server configuration and monitored REST clients", + response=HealthCheck.class + ) + public HealthCheck configuration() { + return HealthCheck.monitor; + } +} diff --git a/feature-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI b/feature-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI new file mode 100644 index 00000000..7e307d08 --- /dev/null +++ b/feature-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI @@ -0,0 +1 @@ +org.openecomp.policy.drools.healthcheck.HealthCheckFeature diff --git a/packages/install/pom.xml b/packages/install/pom.xml index 4f9b6cec..7a00999b 100644 --- a/packages/install/pom.xml +++ b/packages/install/pom.xml @@ -73,7 +73,7 @@ org.openecomp.policy.drools-pdp - policy-healthcheck + feature-healthcheck ${project.version} zip diff --git a/packages/install/src/files/base.conf b/packages/install/src/files/base.conf index 9278f0b1..b33cf586 100644 --- a/packages/install/src/files/base.conf +++ b/packages/install/src/files/base.conf @@ -23,9 +23,9 @@ JAVA_HOME=/opt/jdk1.8.0_77 M2_HOME=/opt/app/policy/3rdparty/apache-maven-3.3.1 ENGINE_MANAGEMENT_PORT=9696 -ENGINE_MANAGEMENT_HOST=localhost +ENGINE_MANAGEMENT_HOST=0.0.0.0 ENGINE_MANAGEMENT_USER=@1b3rt -ENGINE_MANAGEMENT_PASSWORD=31nst@1n +ENGINE_MANAGEMENT_PASSWORD=31nst31n # To use a Nexus repository for rules artifacts, # following properties must be uncommented and set: diff --git a/policy-healthcheck/pom.xml b/policy-healthcheck/pom.xml deleted file mode 100644 index ab0e02db..00000000 --- a/policy-healthcheck/pom.xml +++ /dev/null @@ -1,120 +0,0 @@ - - - - - 4.0.0 - - - org.openecomp.policy.drools-pdp - drools-pdp - 1.1.0-SNAPSHOT - - - policy-healthcheck - - policy-healthcheck - Loadable module that performs remote system healthchecks - - - 1.8 - 1.8 - - - - - - maven-assembly-plugin - 2.6 - - - zipfile - - single - - package - - true - ${project.artifactId}-${project.version} - - src/assembly/assemble_zip.xml - - false - - - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.8 - - - copy-dependencies - - copy-dependencies - - prepare-package - - false - ${project.build.directory}/assembly/lib - false - true - true - false - false - false - org.opendaylight,com.brocade.odl - provided - - - - - - - - - - io.swagger - swagger-jersey2-jaxrs - provided - - - org.openecomp.policy.drools-pdp - policy-core - ${project.version} - provided - - - org.openecomp.policy.drools-pdp - policy-endpoints - ${project.version} - provided - - - org.openecomp.policy.drools-pdp - policy-management - ${project.version} - provided - - - - diff --git a/policy-healthcheck/src/assembly/assemble_zip.xml b/policy-healthcheck/src/assembly/assemble_zip.xml deleted file mode 100644 index 266e1d0a..00000000 --- a/policy-healthcheck/src/assembly/assemble_zip.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - runtime - - zip - - - - false - - - - target - lib/opt - - policy-healthcheck-${project.version}.jar - - - - target/assembly/ - . - - - - - . - lib - - *.jar - - - - src/main/server-gen/bin - bin - 0744 - - - - - src/main/server/bin - bin - 0744 - - - - - src/main/server-gen/scripts - scripts - - - src/main/server/scripts - scripts - - - src/main/server/config - config - - - - diff --git a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java deleted file mode 100644 index b45065e9..00000000 --- a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java +++ /dev/null @@ -1,277 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * policy-healthcheck - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.drools.healthcheck; - -import java.util.ArrayList; -import java.util.Properties; - -import javax.ws.rs.core.Response; - -import org.openecomp.policy.drools.http.client.HttpClient; -import org.openecomp.policy.drools.http.server.HttpServletServer; -import org.openecomp.policy.drools.persistence.SystemPersistence; -import org.openecomp.policy.drools.properties.Startable; -import org.openecomp.policy.drools.system.PolicyEngine; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Healthcheck - */ -public interface HealthCheck extends Startable { - - /** - * Healthcheck Report - */ - public static class Report { - /** - * Named Entity in the report - */ - public String name; - - /** - * URL queried - */ - public String url; - - /** - * healthy? - */ - public boolean healthy; - - /** - * return code - */ - public int code; - - /** - * Message from remote entity - */ - public String message; - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Report [name="); - builder.append(name); - builder.append(", url="); - builder.append(url); - builder.append(", healthy="); - builder.append(healthy); - builder.append(", code="); - builder.append(code); - builder.append(", message="); - builder.append(message); - builder.append("]"); - return builder.toString(); - } - } - - /** - * Report aggregation - */ - public static class Reports { - public boolean healthy; - public ArrayList details = new ArrayList<>(); - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Reports [healthy="); - builder.append(healthy); - builder.append(", details="); - builder.append(details); - builder.append("]"); - return builder.toString(); - } - } - - /** - * perform a healthcheck - * @return a report - */ - public Reports healthCheck(); - - /** - * Healthcheck Monitor - */ - public static final HealthCheck monitor = new HealthCheckMonitor(); -} - -/** - * Healthcheck Monitor - */ -class HealthCheckMonitor implements HealthCheck { - - /** - * Logger - */ - private static Logger logger = LoggerFactory.getLogger(HealthCheckMonitor.class); - - /** - * attached http servers - */ - protected volatile ArrayList servers = new ArrayList<>(); - - /** - * attached http clients - */ - protected volatile ArrayList clients = new ArrayList<>(); - - /** - * healthcheck configuration - */ - protected volatile Properties healthCheckProperties = null; - - /** - * {@inheritDoc} - */ - public Reports healthCheck() { - Reports reports = new Reports(); - reports.healthy = PolicyEngine.manager.isAlive(); - - HealthCheck.Report engineReport = new Report(); - engineReport.healthy = PolicyEngine.manager.isAlive(); - engineReport.name = "PDP-D"; - engineReport.url = "self"; - engineReport.code = (PolicyEngine.manager.isAlive()) ? 200 : 500; - engineReport.message = (PolicyEngine.manager.isAlive()) ? "alive" : "not alive"; - reports.details.add(engineReport); - - for (HttpClient client : clients) { - HealthCheck.Report report = new Report(); - report.name = client.getName(); - report.url = client.getBaseUrl(); - report.healthy = true; - try { - Response response = client.get(); - report.code = response.getStatus(); - if (report.code != 200) { - report.healthy = false; - reports.healthy = false; - } - - try { - report.message = HttpClient.getBody(response, String.class); - } catch (Exception e) { - logger.warn("{}: cannot get body from http-client {}", this, client, e); - } - } catch (Exception e) { - report.healthy = false; - reports.healthy = false; - } - reports.details.add(report); - } - return reports; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean start() throws IllegalStateException { - - 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) { - try { - server.start(); - } catch (Exception e) { - logger.warn("{}: cannot start http-server {}", this, server, e); - } - } - } catch (Exception e) { - return false; - } - - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean stop() throws IllegalStateException { - - 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() throws IllegalStateException { - this.stop(); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized boolean isAlive() { - return this.healthCheckProperties != null; - } - - /** - * @return list of attached Http Servers - */ - public ArrayList getServers() { - return this.servers; - } - - /** - * @return list of attached Http Clients - */ - public ArrayList getClients() { - return this.clients; - } - - @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(); - } - -} diff --git a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java deleted file mode 100644 index 0f16d8cf..00000000 --- a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * policy-healthcheck - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.drools.healthcheck; - -import org.openecomp.policy.drools.features.PolicyEngineFeatureAPI; -import org.openecomp.policy.drools.system.PolicyEngine; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This feature provides healthcheck verification of remotely associated RESTful components - */ -public class HealthCheckFeature implements PolicyEngineFeatureAPI { - - /** - * Logger - */ - private static Logger logger = LoggerFactory.getLogger(HealthCheckFeature.class); - - /** - * Properties Configuration Name - */ - public static final String CONFIGURATION_PROPERTIES_NAME = "policy-healthcheck"; - - @Override - public int getSequenceNumber() { - return 1000; - } - - @Override - public boolean afterStart(PolicyEngine engine) { - try { - HealthCheck.monitor.start(); - } catch (IllegalStateException e) { - logger.error("Healthcheck Monitor cannot be started", e); - } - - return false; - } - - @Override - public boolean afterShutdown(PolicyEngine engine) { - try { - HealthCheck.monitor.stop(); - } catch (IllegalStateException e) { - logger.error("Healthcheck Monitor cannot be stopped", e); - } - - return false; - } - - /** - * gets the monitor - * @return the healthcheck monitor - */ - public HealthCheck getMonitor() { - return HealthCheck.monitor; - } - -} diff --git a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java deleted file mode 100644 index 3f4c34f8..00000000 --- a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * policy-healthcheck - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * 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. - * ============LICENSE_END========================================================= - */ -package org.openecomp.policy.drools.healthcheck; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.openecomp.policy.drools.healthcheck.HealthCheck.Reports; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.Info; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Tag; - -@Path("/") -@Api -@Produces(MediaType.APPLICATION_JSON) -@SwaggerDefinition( - info = @Info( - description = "PDP-D Healthcheck Service", - version = "v1.0", - title = "PDP-D Healthcheck" - ), - consumes = {MediaType.APPLICATION_JSON}, - produces = {MediaType.APPLICATION_JSON}, - schemes = {SwaggerDefinition.Scheme.HTTP}, - tags = { - @Tag(name = "pdp-d-healthcheck", description = "Drools PDP Healthcheck Operations") - } -) -public class RestHealthCheck { - - @GET - @Path("healthcheck") - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation( - value="Perform a system healthcheck", - notes="Provides healthy status of the PDP-D plus the components defined in its configuration by using a REST interface", - response=Reports.class - ) - public Response healthcheck() { - return Response.status(Response.Status.OK).entity(HealthCheck.monitor.healthCheck()).build(); - } - - @GET - @Path("healthcheck/configuration") - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation( - value="Configuration", - notes="Provides the Healthcheck server configuration and monitored REST clients", - response=HealthCheck.class - ) - public HealthCheck configuration() { - return HealthCheck.monitor; - } -} diff --git a/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI b/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI deleted file mode 100644 index 7e307d08..00000000 --- a/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI +++ /dev/null @@ -1 +0,0 @@ -org.openecomp.policy.drools.healthcheck.HealthCheckFeature diff --git a/policy-management/src/main/server/config/feature-healthcheck.properties b/policy-management/src/main/server/config/feature-healthcheck.properties new file mode 100644 index 00000000..d91c2cc4 --- /dev/null +++ b/policy-management/src/main/server/config/feature-healthcheck.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# policy-management +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. 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. +# 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. +# ============LICENSE_END========================================================= +### + +http.server.services=HEALTHCHECK +http.server.services.HEALTHCHECK.host=0.0.0.0 +http.server.services.HEALTHCHECK.port=6969 +http.server.services.HEALTHCHECK.restClasses=org.openecomp.policy.drools.healthcheck.RestHealthCheck +http.server.services.HEALTHCHECK.managed=false +http.server.services.HEALTHCHECK.swagger=true + +http.client.services=PAP,PDP + +http.client.services.PAP.host=${{PAP_HOST}} +http.client.services.PAP.port=9091 +http.client.services.PAP.contextUriPath=pap/test +http.client.services.PAP.https=false +http.client.services.PAP.userName=${{PAP_USERNAME}} +http.client.services.PAP.password=${{PAP_PASSWORD}} +http.client.services.PAP.managed=true + +http.client.services.PDP.host=${{PDP_HOST}} +http.client.services.PDP.port=8081 +http.client.services.PDP.contextUriPath=pdp/test +http.client.services.PDP.https=false +http.client.services.PDP.userName=${{PDP_USERNAME}} +http.client.services.PDP.password=${{PDP_PASSWORD}} +http.client.services.PDP.managed=false diff --git a/policy-management/src/main/server/config/policy-healthcheck.properties b/policy-management/src/main/server/config/policy-healthcheck.properties deleted file mode 100644 index d91c2cc4..00000000 --- a/policy-management/src/main/server/config/policy-healthcheck.properties +++ /dev/null @@ -1,44 +0,0 @@ -### -# ============LICENSE_START======================================================= -# policy-management -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. 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. -# 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. -# ============LICENSE_END========================================================= -### - -http.server.services=HEALTHCHECK -http.server.services.HEALTHCHECK.host=0.0.0.0 -http.server.services.HEALTHCHECK.port=6969 -http.server.services.HEALTHCHECK.restClasses=org.openecomp.policy.drools.healthcheck.RestHealthCheck -http.server.services.HEALTHCHECK.managed=false -http.server.services.HEALTHCHECK.swagger=true - -http.client.services=PAP,PDP - -http.client.services.PAP.host=${{PAP_HOST}} -http.client.services.PAP.port=9091 -http.client.services.PAP.contextUriPath=pap/test -http.client.services.PAP.https=false -http.client.services.PAP.userName=${{PAP_USERNAME}} -http.client.services.PAP.password=${{PAP_PASSWORD}} -http.client.services.PAP.managed=true - -http.client.services.PDP.host=${{PDP_HOST}} -http.client.services.PDP.port=8081 -http.client.services.PDP.contextUriPath=pdp/test -http.client.services.PDP.https=false -http.client.services.PDP.userName=${{PDP_USERNAME}} -http.client.services.PDP.password=${{PDP_PASSWORD}} -http.client.services.PDP.managed=false diff --git a/pom.xml b/pom.xml index 30a0cdcf..4f7fba6f 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ policy-core policy-endpoints policy-management - policy-healthcheck + feature-healthcheck feature-eelf packages -- cgit 1.2.3-korg