diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java index 2f6fca8fce2..e69568c7552 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java @@ -59,8 +59,8 @@ import fish.payara.appserver.micro.services.PayaraInstanceImpl; import fish.payara.micro.ClusterCommandResult; import fish.payara.micro.data.InstanceDescriptor; +import fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration; import fish.payara.nucleus.healthcheck.configuration.MicroProfileHealthCheckerConfiguration; -import fish.payara.microprofile.healthcheck.config.MetricsHealthCheckConfiguration; import fish.payara.monitoring.collect.MonitoringData; import fish.payara.monitoring.collect.MonitoringDataCollector; import fish.payara.monitoring.collect.MonitoringDataSource; @@ -229,10 +229,10 @@ private Map> pingAllInstances(long timeoutMillis) { String instanceName = server.getName(); tasks.put(instanceName, payaraExecutorService.submit(() -> { // get the remote server's MP HealthCheck config - MetricsHealthCheckConfiguration metricsConfig = server.getConfig() - .getExtensionByType(MetricsHealthCheckConfiguration.class); - if (metricsConfig != null && Boolean.valueOf(metricsConfig.getEnabled())) { - return pingHealthEndpoint(buildURI(server, metricsConfig.getEndpoint())); + MicroprofileHealthCheckConfiguration healthCheckConfig = server.getConfig() + .getExtensionByType(MicroprofileHealthCheckConfiguration.class); + if (healthCheckConfig != null && Boolean.valueOf(healthCheckConfig.getEnabled())) { + return pingHealthEndpoint(buildURI(server, healthCheckConfig.getEndpoint())); } return -1; })); diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/HealthCheckService.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/HealthCheckService.java index b1d12eedf8a..f9597f22b5a 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/HealthCheckService.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/HealthCheckService.java @@ -39,18 +39,16 @@ */ package fish.payara.microprofile.healthcheck; -import fish.payara.microprofile.healthcheck.config.MetricsHealthCheckConfiguration; -import fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck; -import fish.payara.nucleus.healthcheck.configuration.Checker; -import fish.payara.nucleus.healthcheck.events.PayaraHealthCheckServiceEvents; -import fish.payara.monitoring.collect.MonitoringData; -import fish.payara.monitoring.collect.MonitoringDataCollector; -import fish.payara.monitoring.collect.MonitoringDataSource; -import fish.payara.monitoring.collect.MonitoringWatchCollector; -import fish.payara.monitoring.collect.MonitoringWatchSource; +import static fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS; +import static fish.payara.microprofile.healthcheck.HealthCheckType.READINESS; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonMap; +import static java.util.logging.Level.WARNING; +import static java.util.stream.Collectors.joining; import java.beans.PropertyChangeEvent; import java.io.IOException; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -70,12 +68,14 @@ import javax.json.Json; import javax.json.JsonArrayBuilder; import javax.json.JsonObjectBuilder; +import javax.json.JsonWriter; +import javax.json.JsonWriterFactory; +import javax.json.stream.JsonGenerator; import javax.servlet.http.HttpServletResponse; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; -import org.eclipse.microprofile.health.HealthCheckResponse.State; +import org.eclipse.microprofile.health.HealthCheckResponse.Status; import org.glassfish.api.StartupRunLevel; import org.glassfish.api.event.EventListener; import org.glassfish.api.event.Events; @@ -88,17 +88,15 @@ import org.jvnet.hk2.config.UnprocessedChangeEvent; import org.jvnet.hk2.config.UnprocessedChangeEvents; -import static fish.payara.microprofile.healthcheck.HealthCheckType.HEALTH; -import static fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS; -import static fish.payara.microprofile.healthcheck.HealthCheckType.READINESS; -import java.io.StringWriter; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonMap; -import static java.util.logging.Level.WARNING; -import static java.util.stream.Collectors.joining; -import javax.json.JsonWriter; -import javax.json.JsonWriterFactory; -import javax.json.stream.JsonGenerator; +import fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck; +import fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration; +import fish.payara.monitoring.collect.MonitoringData; +import fish.payara.monitoring.collect.MonitoringDataCollector; +import fish.payara.monitoring.collect.MonitoringDataSource; +import fish.payara.monitoring.collect.MonitoringWatchCollector; +import fish.payara.monitoring.collect.MonitoringWatchSource; +import fish.payara.nucleus.healthcheck.configuration.Checker; +import fish.payara.nucleus.healthcheck.events.PayaraHealthCheckServiceEvents; /** * Service that handles the registration, execution, and response of MicroProfile HealthChecks. @@ -116,16 +114,10 @@ public class HealthCheckService implements EventListener, ConfigListener, Monito private ApplicationRegistry applicationRegistry; @Inject - private MetricsHealthCheckConfiguration configuration; - - @Inject - private ConfigProviderResolver microConfigResolver; - - private boolean backwardCompEnabled; + private MicroprofileHealthCheckConfiguration configuration; private static final Logger LOG = Logger.getLogger(HealthCheckService.class.getName()); - private final Map> health = new ConcurrentHashMap<>(); private final Map> readiness = new ConcurrentHashMap<>(); private final Map> liveness = new ConcurrentHashMap<>(); @@ -134,37 +126,29 @@ public class HealthCheckService implements EventListener, ConfigListener, Monito private final AtomicReference>> checksCollected = new AtomicReference<>(); - private static final String BACKWARD_COMP_ENABLED_PROPERTY = "MP_HEALTH_BACKWARD_COMPATIBILITY_ENABLED"; - @PostConstruct public void postConstruct() { if (events == null) { events = Globals.getDefaultBaseServiceLocator().getService(Events.class); } events.register(this); - this.backwardCompEnabled = microConfigResolver.getConfig() - .getOptionalValue(BACKWARD_COMP_ENABLED_PROPERTY, Boolean.class) - .orElse(false); } @Override @MonitoringData(ns = "health", intervalSeconds = 12) public void collect(MonitoringDataCollector collector) { Map> collected = new HashMap<>(); - Map> healthResponsesByAppName = collectChecks(collector, health, collected); Map> readinessResponsesByAppName = collectChecks(collector, readiness, collected); Map> livenessResponsesByAppName = collectChecks(collector, liveness, collected); checksCollected.set(collected); if (!collected.isEmpty()) { List overall = new ArrayList<>(); - overall.addAll(collectJointType(collector, "Health", healthResponsesByAppName)); overall.addAll(collectJointType(collector, "Readiness", readinessResponsesByAppName)); overall.addAll(collectJointType(collector, "Liveness", livenessResponsesByAppName)); collectUpDown(collector, computeJointState("Overall", overall)); } for (String appName : collected.keySet()) { List overallByApp = new ArrayList<>(); - overallByApp.addAll(healthResponsesByAppName.getOrDefault(appName, emptyList())); overallByApp.addAll(readinessResponsesByAppName.getOrDefault(appName, emptyList())); overallByApp.addAll(livenessResponsesByAppName.getOrDefault(appName, emptyList())); collectUpDown(collector.group(appName), computeJointState("Overall", overallByApp)); @@ -172,7 +156,7 @@ public void collect(MonitoringDataCollector collector) { } private static void collectUpDown(MonitoringDataCollector collector, HealthCheckResponse response) { - collector.collect(response.getName(), response.getState() == State.UP ? 1 : 0); + collector.collect(response.getName(), response.getStatus() == Status.UP ? 1 : 0); } private static List collectJointType(MonitoringDataCollector collector, String type, @@ -196,16 +180,14 @@ public void collect(MonitoringWatchCollector collector) { for (String metric : e.getValue()) { addWatch(collector, appName, metric); } - addWatch(collector, appName, "Health"); addWatch(collector, appName, "Readiness"); addWatch(collector, appName, "Liveness"); - addWatch(collector, appName, "Overall"); + addWatch(collector, appName, "Health"); } if (!collected.isEmpty()) { - addWatch(collector, null, "Health"); addWatch(collector, null, "Readiness"); addWatch(collector, null, "Liveness"); - addWatch(collector, null, "Overall"); + addWatch(collector, null, "Health"); } } } @@ -221,7 +203,7 @@ private static void addWatch(MonitoringWatchCollector collector, String appName, private Map> collectChecks(MonitoringDataCollector collector, Map> checks, Map> collected) { - Map> stateByApp = new HashMap<>(); + Map> statusByApp = new HashMap<>(); for (Entry> entry : checks.entrySet()) { String appName = entry.getKey(); MonitoringDataCollector appCollector = collector.group(appName); @@ -231,29 +213,29 @@ private Map> collectChecks(MonitoringDataColle Set appCollected = collected.get(appName); // prevent adding same check more then once, unfortunately we have to run it to find that out if (appCollected == null || !appCollected.contains(metric)) { - stateByApp.computeIfAbsent(appName, key -> new ArrayList<>()).add(response); + statusByApp.computeIfAbsent(appName, key -> new ArrayList<>()).add(response); collectUpDown(appCollector, response); - if (response.getState() == State.DOWN && response.getData().isPresent()) { + if (response.getStatus() == Status.DOWN && response.getData().isPresent()) { appCollector.annotate(metric, 0L, createAnnotation(response.getData().get())); } collected.computeIfAbsent(appName, key -> new HashSet<>()).add(metric); } } } - return stateByApp; + return statusByApp; } private static HealthCheckResponse computeJointState(String name, Collection responses) { - long ups = responses.stream().filter(response -> response.getState() == State.UP).count(); + long ups = responses.stream().filter(response -> response.getStatus() == Status.UP).count(); if (ups == responses.size()) { return HealthCheckResponse.up(name); } String upNames = responses.stream() - .filter(r -> r.getState() == State.UP) + .filter(r -> r.getStatus() == Status.UP) .map(r -> r.getName()) .collect(joining(",")); String downNames = responses.stream() - .filter(r -> r.getState() == State.DOWN) + .filter(r -> r.getStatus() == Status.DOWN) .map(r -> r.getName()) .collect(joining(",")); return HealthCheckResponse.named(name).down() @@ -275,7 +257,7 @@ private static String[] createAnnotation(Map data) { } @Override - public void event(Event event) { + public void event(Event event) { // Remove healthchecks when the app is undeployed. Deployment.APPLICATION_UNLOADED.onMatch(event, appInfo -> unregisterHealthCheck(appInfo.getName())); @@ -341,7 +323,6 @@ public void registerHealthCheck(String healthCheckName, HealthCheck healthCheck, public void unregisterHealthCheck(String appName) { readiness.remove(appName); liveness.remove(appName); - health.remove(appName); applicationClassLoaders.remove(appName); applicationsLoaded.remove(appName); } @@ -367,15 +348,19 @@ public void registerClassLoader(String appName, ClassLoader classloader) { } private Map> getHealthChecks(HealthCheckType type) { - final Map> healthChecks; - if (type == READINESS) { - healthChecks = readiness; - } else if (type == LIVENESS) { - healthChecks = liveness; - } else { - healthChecks = health; + if (type == null) { + type = HealthCheckType.UNKNOWN; + } + switch (type) { + case LIVENESS: + return liveness; + case READINESS: + return readiness; + case UNKNOWN: + default: + LOG.warning("Unrecognised HealthCheckType: " + type); + return new HashMap<>(); } - return healthChecks; } private Map> getCollectiveHealthChecks(HealthCheckType type) { @@ -385,7 +370,7 @@ private Map> getCollectiveHealthChecks(HealthCheckType } else if (type == LIVENESS) { healthChecks = liveness; } else { - healthChecks = new HashMap<>(health); + healthChecks = new HashMap<>(); BiConsumer> mergeHealthCheckMap = (key, value) -> healthChecks.merge(key, value, (oldValue, newValue) -> { oldValue.addAll(newValue); @@ -463,12 +448,9 @@ private void constructResponse(HttpServletResponse httpResponse, for (HealthCheckResponse healthCheckResponse : healthCheckResponses) { JsonObjectBuilder healthCheckObject = Json.createObjectBuilder(); - // Add the name and state + // Add the name and status healthCheckObject.add("name", healthCheckResponse.getName()); - healthCheckObject.add( - backwardCompEnabled && type == HEALTH ? "state" : "status", - healthCheckResponse.getState().toString() - ); + healthCheckObject.add("status", healthCheckResponse.getStatus().toString()); // Add data if present JsonObjectBuilder healthCheckData = Json.createObjectBuilder(); @@ -484,7 +466,7 @@ private void constructResponse(HttpServletResponse httpResponse, // Check if we need to set the response as 503. Check against status 200 so we don't repeatedly set it if (httpResponse.getStatus() == 200 - && healthCheckResponse.getState().equals(HealthCheckResponse.State.DOWN)) { + && healthCheckResponse.getStatus().equals(HealthCheckResponse.Status.DOWN)) { httpResponse.setStatus(503); } } @@ -493,10 +475,7 @@ private void constructResponse(HttpServletResponse httpResponse, JsonObjectBuilder responseObject = Json.createObjectBuilder(); // Set the aggregate status - responseObject.add( - backwardCompEnabled && type == HEALTH ? "outcome" : "status", - httpResponse.getStatus() == 200 ? "UP" : "DOWN" - ); + responseObject.add("status", httpResponse.getStatus() == 200 ? "UP" : "DOWN"); // Add all of the checks responseObject.add("checks", checksArray); diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/HealthCheckType.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/HealthCheckType.java index f9ffea41327..ea70320e17d 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/HealthCheckType.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/HealthCheckType.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2019-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -41,39 +41,38 @@ import java.lang.annotation.Annotation; import java.util.Set; + import javax.enterprise.util.AnnotationLiteral; -import org.eclipse.microprofile.health.Health; + import org.eclipse.microprofile.health.Liveness; import org.eclipse.microprofile.health.Readiness; public enum HealthCheckType { - READINESS("/ready", new AnnotationLiteral() { - }), - LIVENESS("/live", new AnnotationLiteral() { - }), - HEALTH(null, new AnnotationLiteral() { - }); + READINESS("/ready", new Readiness.Literal()), + LIVENESS("/live", new Liveness.Literal()), + UNKNOWN(null, null); - String path; - AnnotationLiteral literal; + private String path; + private AnnotationLiteral literal; - private HealthCheckType(String path, AnnotationLiteral literal) { + private HealthCheckType(String path, AnnotationLiteral literal) { this.path = path; this.literal = literal; } - public AnnotationLiteral getLiteral() { + public AnnotationLiteral getLiteral() { return literal; } public static HealthCheckType fromPath(String path) { for (HealthCheckType value : values()) { - if (value.path != null && value.path.equals(path)) { + // If the path is equal (with or without the slash) + if (value.path != null && (value.path.equals(path) || value.path.substring(1).equals(path))) { return value; } } - return HEALTH; + return UNKNOWN; } public static HealthCheckType fromQualifiers(Set qualifiers) { diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/activation/HealthSniffer.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/activation/HealthSniffer.java index de086ec2f30..cdc36b517a7 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/activation/HealthSniffer.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/activation/HealthSniffer.java @@ -55,7 +55,6 @@ public class HealthSniffer extends MicroProfileSniffer { public Class[] getAnnotationTypes() { return new Class[] { // Search for Health annotations - org.eclipse.microprofile.health.Health.class, org.eclipse.microprofile.health.Readiness.class, org.eclipse.microprofile.health.Liveness.class, diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/admin/GetMPHealthCheckConfiguration.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/admin/GetMPHealthCheckConfiguration.java index 5326166f170..59c06c0afd8 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/admin/GetMPHealthCheckConfiguration.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/admin/GetMPHealthCheckConfiguration.java @@ -44,7 +44,7 @@ import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.util.ColumnFormatter; -import fish.payara.microprofile.healthcheck.config.MetricsHealthCheckConfiguration; +import fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -72,7 +72,7 @@ @ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) @TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CONFIG, CommandTarget.DEPLOYMENT_GROUP}) @RestEndpoints({ - @RestEndpoint(configBean = MetricsHealthCheckConfiguration.class, + @RestEndpoint(configBean = MicroprofileHealthCheckConfiguration.class, opType = RestEndpoint.OpType.GET, path = "get-microprofile-healthcheck-configuration", description = "Gets the Microprofile Health Check Configuration") @@ -97,8 +97,8 @@ public void execute(AdminCommandContext context) { return; } - MetricsHealthCheckConfiguration healthCheckConfiguration = targetConfig - .getExtensionByType(MetricsHealthCheckConfiguration.class); + MicroprofileHealthCheckConfiguration healthCheckConfiguration = targetConfig + .getExtensionByType(MicroprofileHealthCheckConfiguration.class); ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS); Object[] outputValues = { diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/admin/SetMPHealthCheckConfiguration.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/admin/SetMPHealthCheckConfiguration.java index 8e4e5c3bc11..eb45969530c 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/admin/SetMPHealthCheckConfiguration.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/admin/SetMPHealthCheckConfiguration.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2018-2019] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2018-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -43,9 +43,8 @@ package fish.payara.microprofile.healthcheck.admin; import com.sun.enterprise.config.serverbeans.Config; -import com.sun.enterprise.config.serverbeans.Domain; import fish.payara.microprofile.SetSecureMicroprofileConfigurationCommand; -import fish.payara.microprofile.healthcheck.config.MetricsHealthCheckConfiguration; +import fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration; import java.util.logging.Logger; import javax.inject.Inject; import javax.security.auth.Subject; @@ -80,7 +79,7 @@ @PerLookup @I18n("set-microprofile-healthcheck-configuration") @RestEndpoints({ - @RestEndpoint(configBean = MetricsHealthCheckConfiguration.class, + @RestEndpoint(configBean = MicroprofileHealthCheckConfiguration.class, opType = RestEndpoint.OpType.POST, description = "Configures Microprofile HealthCheck") }) @@ -106,15 +105,12 @@ public class SetMPHealthCheckConfiguration extends SetSecureMicroprofileConfigur @Inject UnprocessedConfigListener unprocessedListener; - @Inject - private Domain domain; - @Override public void execute(AdminCommandContext context) { ActionReport actionReport = context.getActionReport(); Subject subject = context.getSubject(); Config targetConfig = targetUtil.getConfig(target); - MetricsHealthCheckConfiguration config = targetConfig.getExtensionByType(MetricsHealthCheckConfiguration.class); + MicroprofileHealthCheckConfiguration config = targetConfig.getExtensionByType(MicroprofileHealthCheckConfiguration.class); if (Boolean.TRUE.equals(securityEnabled) || Boolean.parseBoolean(config.getSecurityEnabled())) { diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/cdi/extension/HealthCDIExtension.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/cdi/extension/HealthCDIExtension.java index 36dd82eb863..4978735a23a 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/cdi/extension/HealthCDIExtension.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/cdi/extension/HealthCDIExtension.java @@ -15,7 +15,6 @@ import javax.enterprise.inject.spi.Extension; import javax.enterprise.inject.spi.ProcessBean; -import org.eclipse.microprofile.health.Health; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.Liveness; import org.eclipse.microprofile.health.Readiness; @@ -46,8 +45,7 @@ public HealthCDIExtension() { void processBean(@Observes ProcessBean event) { final Annotated annotated = event.getAnnotated(); if (annotated.isAnnotationPresent(Readiness.class) - || annotated.isAnnotationPresent(Liveness.class) - || annotated.isAnnotationPresent(Health.class)) { + || annotated.isAnnotationPresent(Liveness.class)) { this.healthCheckBeans.add(event.getBean()); } } diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/checks/PayaraHealthCheck.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/checks/PayaraHealthCheck.java index a818963bde1..125b828e230 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/checks/PayaraHealthCheck.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/checks/PayaraHealthCheck.java @@ -53,9 +53,9 @@ public class PayaraHealthCheck implements HealthCheck { private String name; - private BaseHealthCheck checker; + private BaseHealthCheck checker; - public PayaraHealthCheck(String name, BaseHealthCheck checker) { + public PayaraHealthCheck(String name, BaseHealthCheck checker) { this.name = name; this.checker = checker; } @@ -63,14 +63,14 @@ public PayaraHealthCheck(String name, BaseHealthCheck checker) { @Override public HealthCheckResponse call() { HealthCheckResponseBuilder responseBuilder = HealthCheckResponse.named(name); - boolean state = true; + boolean status = true; checker.doCheck(); List healthCheckResults = checker.getMostRecentResult().getEntries(); if (healthCheckResults.isEmpty()) { responseBuilder.withData("Message", "No result to display"); - return responseBuilder.state(state).build(); + return responseBuilder.status(status).build(); } for (HealthCheckResultEntry healthCheckResultEntry : healthCheckResults) { @@ -81,10 +81,10 @@ public HealthCheckResponse call() { if (!healthStatus.trim().isEmpty()) { responseBuilder.withData("HealthCheckStatus", healthStatus); if (healthStatus.equals("CRITICAL") || healthStatus.equals("CHECK_ERROR")) { - state = false; + status = false; } } - return responseBuilder.state(state).build(); + return responseBuilder.status(status).build(); } } diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/config/MetricsHealthCheckConfiguration.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/config/MicroprofileHealthCheckConfiguration.java similarity index 94% rename from appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/config/MetricsHealthCheckConfiguration.java rename to appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/config/MicroprofileHealthCheckConfiguration.java index 90aefe4a660..2636ab5bc23 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/config/MetricsHealthCheckConfiguration.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/config/MicroprofileHealthCheckConfiguration.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2018-2019] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2018-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -46,7 +46,6 @@ import java.beans.PropertyVetoException; import org.glassfish.api.admin.config.ConfigExtension; import org.jvnet.hk2.config.Attribute; -import org.jvnet.hk2.config.ConfigBeanProxy; import org.jvnet.hk2.config.Configured; /** @@ -54,8 +53,8 @@ * @author jonathan coustick * @since 4.1.2.182 */ -@Configured -public interface MetricsHealthCheckConfiguration extends ConfigBeanProxy, ConfigExtension { +@Configured(name = "microprofile-healthcheck-configuration") +public interface MicroprofileHealthCheckConfiguration extends ConfigExtension { /** * @return a Boolean value determining if the service is enabled or diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/response/HealthCheckResponseBuilderImpl.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/response/HealthCheckResponseBuilderImpl.java index 100fd87fff2..df56b513f69 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/response/HealthCheckResponseBuilderImpl.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/response/HealthCheckResponseBuilderImpl.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2017-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -43,7 +43,7 @@ import java.util.Map; import java.util.Optional; import org.eclipse.microprofile.health.HealthCheckResponse; -import org.eclipse.microprofile.health.HealthCheckResponse.State; +import org.eclipse.microprofile.health.HealthCheckResponse.Status; import org.eclipse.microprofile.health.HealthCheckResponseBuilder; import static org.glassfish.common.util.StringHelper.isEmpty; @@ -54,7 +54,7 @@ public class HealthCheckResponseBuilderImpl extends HealthCheckResponseBuilder { private String name; - private State state; + private Status status; private final Optional> data = Optional.of(new HashMap<>()); @Override @@ -103,22 +103,22 @@ public HealthCheckResponseBuilder withData(String key, boolean value) { @Override public HealthCheckResponseBuilder up() { - this.state = State.UP; + this.status = Status.UP; return this; } @Override public HealthCheckResponseBuilder down() { - this.state = State.DOWN; + this.status = Status.DOWN; return this; } @Override - public HealthCheckResponseBuilder state(boolean up) { + public HealthCheckResponseBuilder status(boolean up) { if (up) { - this.state = State.UP; + this.status = Status.UP; } else { - this.state = State.DOWN; + this.status = Status.DOWN; } return this; @@ -126,9 +126,9 @@ public HealthCheckResponseBuilder state(boolean up) { @Override public HealthCheckResponse build() { - validate(); + validate(); // Just use the basic HealthCheckResponse implementation - HealthCheckResponse healthCheckResponse = new HealthCheckResponseImpl(name, state, data); + HealthCheckResponse healthCheckResponse = new HealthCheckResponseImpl(name, status, data); return healthCheckResponse; } @@ -136,8 +136,8 @@ private void validate() { if (isEmpty(name)) { throw new IllegalArgumentException("Healthcheck name is not defined"); } - if (state == null) { - throw new IllegalArgumentException(String.format("Healthcheck [%s] state is not defined", name)); + if (status == null) { + throw new IllegalArgumentException(String.format("Healthcheck [%s] status is not defined", name)); } } diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/response/HealthCheckResponseImpl.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/response/HealthCheckResponseImpl.java index db602a1ae1d..b595f641395 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/response/HealthCheckResponseImpl.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/response/HealthCheckResponseImpl.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2017-2020] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -50,12 +50,12 @@ public class HealthCheckResponseImpl extends HealthCheckResponse { private final String name; - private final State state; + private final Status status; private final Optional> data; - public HealthCheckResponseImpl(String name, State state, Optional> data) { + public HealthCheckResponseImpl(String name, Status status, Optional> data) { this.name = name; - this.state = state; + this.status = status; this.data = data; } @@ -65,8 +65,8 @@ public String getName() { } @Override - public State getState() { - return state; + public Status getStatus() { + return status; } @Override diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/servlet/HealthCheckServlet.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/servlet/HealthCheckServlet.java index ba3932b1955..ee8bea6531a 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/servlet/HealthCheckServlet.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/servlet/HealthCheckServlet.java @@ -55,13 +55,16 @@ */ public class HealthCheckServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + /** - * Processes requests for both HTTP GET and POST methods. + * Processes requests for both HTTP GET and POST + * methods. * - * @param request servlet request + * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs + * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -78,7 +81,6 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re } healthCheckService.performHealthChecks(response, HealthCheckType.fromPath(request.getPathInfo()), request.getParameter("pretty")); - } // diff --git a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/servlet/HealthCheckServletContainerInitializer.java b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/servlet/HealthCheckServletContainerInitializer.java index 87641c1be41..d14988cc62d 100644 --- a/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/servlet/HealthCheckServletContainerInitializer.java +++ b/appserver/payara-appserver-modules/microprofile/healthcheck/src/main/java/fish/payara/microprofile/healthcheck/servlet/HealthCheckServletContainerInitializer.java @@ -52,7 +52,6 @@ import java.util.Map; import java.util.Set; -import java.util.logging.Logger; import javax.servlet.HttpConstraintElement; import javax.servlet.ServletContainerInitializer; @@ -63,7 +62,7 @@ import org.glassfish.internal.api.Globals; -import fish.payara.microprofile.healthcheck.config.MetricsHealthCheckConfiguration; +import fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration; /** * Servlet Container Initializer that registers the HealthCheckServlet, as well @@ -73,15 +72,13 @@ */ public class HealthCheckServletContainerInitializer implements ServletContainerInitializer { - private static final Logger LOGGER = Logger.getLogger(HealthCheckServletContainerInitializer.class.getName()); - @Override public void onStartup(Set> c, ServletContext ctx) throws ServletException { // Check if this context is the root one ("/") if (ctx.getContextPath().isEmpty()) { // Check if there is already a servlet for healthcheck Map registrations = ctx.getServletRegistrations(); - MetricsHealthCheckConfiguration configuration = Globals.getDefaultHabitat().getService(MetricsHealthCheckConfiguration.class); + MicroprofileHealthCheckConfiguration configuration = Globals.getDefaultHabitat().getService(MicroprofileHealthCheckConfiguration.class); if (!Boolean.parseBoolean(configuration.getEnabled())) { return; //MP Healthcheck disabled diff --git a/appserver/tests/payara-samples/samples/microprofile-healthcheck/src/test/java/fish/payara/samples/microprofile/healthcheck/SystemLivenessCheck.java b/appserver/tests/payara-samples/samples/microprofile-healthcheck/src/test/java/fish/payara/samples/microprofile/healthcheck/SystemLivenessCheck.java index 32dbfd4b93d..e3d17fbba84 100644 --- a/appserver/tests/payara-samples/samples/microprofile-healthcheck/src/test/java/fish/payara/samples/microprofile/healthcheck/SystemLivenessCheck.java +++ b/appserver/tests/payara-samples/samples/microprofile-healthcheck/src/test/java/fish/payara/samples/microprofile/healthcheck/SystemLivenessCheck.java @@ -57,6 +57,6 @@ public HealthCheckResponse call() { return HealthCheckResponse.named(SystemLivenessCheck.class.getSimpleName() + " Liveness Check") .withData("memory used", memUsed) .withData("memory max", memMax) - .state(memUsed < memMax * 0.9).build(); + .status(memUsed < memMax * 0.9).build(); } } diff --git a/appserver/tests/payara-samples/samples/microprofile-healthcheck/src/test/java/fish/payara/samples/microprofile/healthcheck/WarCheck1.java b/appserver/tests/payara-samples/samples/microprofile-healthcheck/src/test/java/fish/payara/samples/microprofile/healthcheck/WarCheck1.java index ea80a205e32..9d6eb8e4285 100644 --- a/appserver/tests/payara-samples/samples/microprofile-healthcheck/src/test/java/fish/payara/samples/microprofile/healthcheck/WarCheck1.java +++ b/appserver/tests/payara-samples/samples/microprofile-healthcheck/src/test/java/fish/payara/samples/microprofile/healthcheck/WarCheck1.java @@ -57,6 +57,6 @@ public HealthCheckResponse call() { return HealthCheckResponse.named(WarCheck1.class.getSimpleName() + " Liveness Check") .withData("memory used", memUsed) .withData("memory max", memMax) - .state(memUsed < memMax * 0.9).build(); + .status(memUsed < memMax * 0.9).build(); } } diff --git a/pom.xml b/pom.xml index 2795b4967a2..c534fc42f64 100644 --- a/pom.xml +++ b/pom.xml @@ -237,7 +237,7 @@ 1.4 2.1 1.2.1 - 2.2 + 3.0-RC5 2.3 1.4.1 1.1.2