summaryrefslogtreecommitdiffstats
path: root/policy-healthcheck
diff options
context:
space:
mode:
Diffstat (limited to 'policy-healthcheck')
-rw-r--r--policy-healthcheck/pom.xml157
-rw-r--r--policy-healthcheck/src/assembly/assemble_zip.xml85
-rw-r--r--policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java178
-rw-r--r--policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java92
-rw-r--r--policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java27
-rw-r--r--policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI1
6 files changed, 540 insertions, 0 deletions
diff --git a/policy-healthcheck/pom.xml b/policy-healthcheck/pom.xml
new file mode 100644
index 00000000..c279cd1d
--- /dev/null
+++ b/policy-healthcheck/pom.xml
@@ -0,0 +1,157 @@
+<!--
+ ============LICENSE_START=======================================================
+ ECOMP Policy Engine - Drools PDP
+ ================================================================================
+ 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=========================================================
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.openecomp.policy.drools-pdp</groupId>
+ <artifactId>drools-pdp</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>policy-healthcheck</artifactId>
+
+ <name>policy-healthcheck</name>
+ <description>Separately loadable module with healthcheck code</description>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>zipfile</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <attach>true</attach>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <descriptors>
+ <descriptor>src/assembly/assemble_zip.xml</descriptor>
+ </descriptors>
+ <appendAssemblyId>false</appendAssemblyId>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.8</version>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <phase>prepare-package</phase>
+ <configuration>
+ <transitive>false</transitive>
+ <outputDirectory>${project.build.directory}/assembly/lib</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ <useRepositoryLayout>false</useRepositoryLayout>
+ <addParentPoms>false</addParentPoms>
+ <copyPom>false</copyPom>
+ <excludeGroupIds>org.opendaylight,com.brocade.odl</excludeGroupIds>
+ <scope>provided</scope>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>copy-version</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <outputDirectory>${basedir}/target/versions</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources/versions</directory>
+ <includes>
+ <include>version.properties</include>
+ </includes>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-resources</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <outputDirectory>${basedir}/target/etc/bvc-extensions</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources/etc/bvc-extensions</directory>
+ <includes>
+ <include>feature_config_template.cfg</include>
+ <include>feature_custom.install</include>
+ </includes>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.policy.drools-pdp</groupId>
+ <artifactId>policy-core</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.policy.drools-pdp</groupId>
+ <artifactId>policy-endpoints</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.policy.drools-pdp</groupId>
+ <artifactId>policy-management</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/policy-healthcheck/src/assembly/assemble_zip.xml b/policy-healthcheck/src/assembly/assemble_zip.xml
new file mode 100644
index 00000000..266e1d0a
--- /dev/null
+++ b/policy-healthcheck/src/assembly/assemble_zip.xml
@@ -0,0 +1,85 @@
+<!--
+ ============LICENSE_START=======================================================
+ policy-persistence
+ ================================================================================
+ 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=========================================================
+ -->
+
+<!-- Defines how we build the .zip file which is our distribution. -->
+
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>runtime</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <!-- we want "system" and related files right at the root level as this
+ file is suppose to be unzip on top of a karaf distro. -->
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory>lib/opt</outputDirectory>
+ <includes>
+ <include>policy-healthcheck-${project.version}.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target/assembly/</directory>
+ <outputDirectory>.</outputDirectory>
+ <excludes>
+ </excludes>
+ </fileSet>
+ <fileSet>
+ <directory>.</directory>
+ <outputDirectory>lib</outputDirectory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/server-gen/bin</directory>
+ <outputDirectory>bin</outputDirectory>
+ <fileMode>0744</fileMode>
+ <excludes>
+ </excludes>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/server/bin</directory>
+ <outputDirectory>bin</outputDirectory>
+ <fileMode>0744</fileMode>
+ <excludes>
+ </excludes>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/server-gen/scripts</directory>
+ <outputDirectory>scripts</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/server/scripts</directory>
+ <outputDirectory>scripts</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/server/config</directory>
+ <outputDirectory>config</outputDirectory>
+ </fileSet>
+ </fileSets>
+
+</assembly>
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
new file mode 100644
index 00000000..2ed2e075
--- /dev/null
+++ b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java
@@ -0,0 +1,178 @@
+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;
+
+public interface HealthCheck extends Startable {
+
+ public static class Report {
+ public String name;
+ public String url;
+ public boolean healthy;
+ public int code;
+ 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();
+ }
+ }
+
+ public static class Reports {
+ public boolean healthy;
+ public ArrayList<Report> 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();
+ }
+ }
+
+ public Reports healthCheck();
+
+ public static final HealthCheck monitor = new HealthCheckMonitor();
+}
+
+class HealthCheckMonitor implements HealthCheck {
+
+ protected volatile ArrayList<HttpServletServer> servers = new ArrayList<>();
+ protected volatile ArrayList<HttpClient> clients = new ArrayList<>();
+ protected volatile Properties healthCheckProperties = null;
+
+ 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) {
+ e.printStackTrace();
+ }
+ } catch (Exception e) {
+ report.healthy = false;
+ reports.healthy = false;
+ }
+ reports.details.add(report);
+ }
+ return reports;
+ }
+
+ @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) {
+ e.printStackTrace();
+ }
+ }
+ } catch (Exception e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean stop() throws IllegalStateException {
+ for (HttpServletServer server : servers) {
+ try {
+ server.stop();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ for (HttpClient client : clients) {
+ try {
+ client.stop();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void shutdown() throws IllegalStateException {
+ this.stop();
+ }
+
+ @Override
+ public synchronized boolean isAlive() {
+ return this.healthCheckProperties != null;
+ }
+
+ public ArrayList<HttpServletServer> getServers() {
+ return this.servers;
+ }
+
+ public ArrayList<HttpClient> 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
new file mode 100644
index 00000000..ce1dd90b
--- /dev/null
+++ b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java
@@ -0,0 +1,92 @@
+package org.openecomp.policy.drools.healthcheck;
+
+import java.util.Properties;
+
+import org.kie.api.runtime.KieSession;
+import org.openecomp.policy.drools.core.FeatureAPI;
+import org.openecomp.policy.drools.core.PolicyContainer;
+import org.openecomp.policy.drools.core.PolicySession;
+
+public class HealthCheckFeature implements FeatureAPI {
+
+ public static final String CONFIGURATION_PROPERTIES_NAME = "policy-healthcheck";
+
+ @Override
+ public int getSequenceNumber() {
+ return 2;
+ }
+
+ @Override
+ public void globalInit(String[] args, String configDir) {
+ return;
+ }
+
+ @Override
+ public KieSession activatePolicySession(PolicyContainer policyContainer, String name, String kieBaseName) {
+ return null;
+ }
+
+ @Override
+ public void disposeKieSession(PolicySession policySession) {
+ return;
+ }
+
+ @Override
+ public void destroyKieSession(PolicySession policySession) {
+ return;
+ }
+
+ @Override
+ public void beforeStartEngine() throws IllegalStateException {
+ return;
+ }
+
+ @Override
+ public void afterStartEngine() {
+ try {
+ HealthCheck.monitor.start();
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void beforeShutdownEngine() {
+ return;
+ }
+
+ @Override
+ public void afterShutdownEngine() {
+ try {
+ HealthCheck.monitor.stop();
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void beforeCreateController(String name, Properties properties) {
+ return;
+ }
+
+ @Override
+ public void afterCreateController(String name) {
+ return;
+ }
+
+ @Override
+ public void beforeStartController(String name) {
+ return;
+ }
+
+ @Override
+ public void afterStartController(String name) {
+ return;
+ }
+
+ @Override
+ public boolean isPersistenceEnabled() {
+ return false;
+ }
+
+}
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
new file mode 100644
index 00000000..e37e758a
--- /dev/null
+++ b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/RestHealthCheck.java
@@ -0,0 +1,27 @@
+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 org.openecomp.policy.drools.healthcheck.HealthCheck.Reports;
+
+@Path("/")
+public class RestHealthCheck {
+
+ @GET
+ @Path("{a:healthcheck|test}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Reports healthcheck() {
+ Reports reports = HealthCheck.monitor.healthCheck();
+ return reports;
+ }
+
+ @GET
+ @Path("healthcheck/configuration")
+ @Produces(MediaType.APPLICATION_JSON)
+ public HealthCheck configuration() {
+ return HealthCheck.monitor;
+ }
+}
diff --git a/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI b/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI
new file mode 100644
index 00000000..7e307d08
--- /dev/null
+++ b/policy-healthcheck/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI
@@ -0,0 +1 @@
+org.openecomp.policy.drools.healthcheck.HealthCheckFeature