From e6f2ac5b421e4980e03fd548861bdcfb17491c87 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Tue, 4 Sep 2018 17:29:29 +0100 Subject: [PATCH 01/11] PAYARA-2479 Created MP-Healthcheck checker for Payara Healthcheck --- .../packager/microprofile-package/pom.xml | 5 + .../healthcheck-checker/pom.xml | 97 ++++++++ .../fish/payara/healthcheck/mp/MPChecker.java | 191 +++++++++++++++ .../mp/MPCheckerConfiguration.java | 71 ++++++ .../healthcheck/mp/MPCheckerConfigurer.java | 217 ++++++++++++++++++ .../TimeoutHealthCheckExecutionOptions.java | 72 ++++++ .../admin/GetHealthCheckConfiguration.java | 2 + .../admin/HealthCheckServiceConfigurer.java | 5 +- .../configuration/CheckerType.java | 5 +- .../preliminary/LocalStrings.properties | 5 +- 10 files changed, 663 insertions(+), 7 deletions(-) create mode 100644 appserver/payara-appserver-modules/healthcheck-checker/pom.xml create mode 100644 appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPChecker.java create mode 100644 appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfiguration.java create mode 100644 appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfigurer.java create mode 100644 appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/TimeoutHealthCheckExecutionOptions.java diff --git a/appserver/packager/microprofile-package/pom.xml b/appserver/packager/microprofile-package/pom.xml index 7751e0b88b7..0f906b681bf 100644 --- a/appserver/packager/microprofile-package/pom.xml +++ b/appserver/packager/microprofile-package/pom.xml @@ -207,6 +207,11 @@ microprofile-healthcheck ${project.version} + + fish.payara.appserver + healthcheck-checker + ${project.version} + diff --git a/appserver/payara-appserver-modules/healthcheck-checker/pom.xml b/appserver/payara-appserver-modules/healthcheck-checker/pom.xml new file mode 100644 index 00000000000..6e0156e3213 --- /dev/null +++ b/appserver/payara-appserver-modules/healthcheck-checker/pom.xml @@ -0,0 +1,97 @@ + + + + + 4.0.0 + + org.glassfish.main + payara-appserver-modules + 5.184-SNAPSHOT + + fish.payara.appserver + healthcheck-checker + glassfish-jar + Healthcheck Checker + Microprofile Healthcheck Checker + + + + fish.payara.payara-modules + healthcheck-core + ${project.version} + + + fish.payara.payara-modules + notification-core + ${project.version} + + + org.eclipse.microprofile.health + microprofile-health-api + ${microprofile-healthcheck.version} + + + fish.payara.microprofile.healthcheck + microprofile-healthcheck + ${project.version} + + + org.glassfish.main.admin + config-api + ${project.version} + + + fish.payara.admingui + console-common + 5.182-SNAPSHOT + jar + + + javax + javaee-api + ${javaee.api.version} + provided + + + diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPChecker.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPChecker.java new file mode 100644 index 00000000000..cb669f048fc --- /dev/null +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPChecker.java @@ -0,0 +1,191 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2018] 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 + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.healthcheck.mp; + +import com.sun.enterprise.config.serverbeans.Domain; +import java.net.URI; +import java.net.URISyntaxException; +import javax.inject.Inject; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import com.sun.enterprise.config.serverbeans.Server; +import com.sun.enterprise.v3.services.impl.GrizzlyService; +import fish.payara.microprofile.healthcheck.config.MetricsHealthCheckConfiguration; +import fish.payara.notification.healthcheck.HealthCheckResultEntry; +import fish.payara.notification.healthcheck.HealthCheckResultStatus; +import fish.payara.nucleus.executorservice.PayaraExecutorService; +import fish.payara.nucleus.healthcheck.HealthCheckResult; +import fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.ws.rs.ProcessingException; +import org.glassfish.config.support.PropertyResolver; +import org.glassfish.config.support.TranslatedConfigView; +import org.glassfish.grizzly.config.dom.NetworkListener; +import org.glassfish.hk2.api.PostConstruct;; +import org.glassfish.hk2.runlevel.RunLevel; +import org.glassfish.internal.api.Target; +import org.jvnet.hk2.annotations.Service; + +/** + * Health Check service that pokes MP Healthcheck endpoints of instances + * in the current domain to see if they are responsive + * + * @author jonathan coustick + * @since 5.184 + */ +@Service(name = "healthcheck-mp") +@RunLevel(10) +public class MPChecker extends BaseHealthCheck implements PostConstruct { + + private static final Logger LOGGER = Logger.getLogger("HEALTHCHECK"); + + @Inject + private Target targetUtil; + + @Inject + private PayaraExecutorService payaraExecutorService; + + @Inject + GrizzlyService grizzlyService; + + @Inject + Domain domain; + + @Override + public void postConstruct() { + postConstruct(this, MPCheckerConfiguration.class); + } + + @Override + public HealthCheckResult doCheck() { + HealthCheckResult result = new HealthCheckResult(); + + //get all instances that this server knows about + for (Server server : domain.getServers().getServer()) { + + Future taskResult = payaraExecutorService.submit(() -> { + + //get the remote server's MP HealthCheck config + MetricsHealthCheckConfiguration metricsConfig = server.getConfig().getExtensionByType(MetricsHealthCheckConfiguration.class); + if (metricsConfig != null && Boolean.valueOf(metricsConfig.getEnabled())) { + try { + String endpoint = metricsConfig.getEndpoint(); + + URI remote = buildURI(server, endpoint); + + //send request to remote healthcheck endpoint to get the status + Client jaxrsClient = ClientBuilder.newClient(); + WebTarget target = jaxrsClient.target(remote); + + Response metricsResponse = target.request().accept(MediaType.APPLICATION_JSON).get(); + switch (metricsResponse.getStatus()) { + case 200: + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.GOOD, "UP")); + break; + case 503: + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.WARNING, "DOWN")); + break; + case 500: + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "FAILURE")); + break; + default: + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "UNKNOWN RESPONSE")); + break; + } + + } catch (URISyntaxException ex) { + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "INVALID ENDPOINT: " + ex.getInput())); + } catch (ProcessingException ex) { + LOGGER.log(Level.FINE, "Error sending JAX-RS Request", ex); + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "UNABLE TO CONNECT - " + ex.getMessage())); + } + } + + }); + try { + taskResult.get(options.getTimeout(), TimeUnit.MILLISECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException ex) { + LOGGER.log(Level.FINE, "Error processing MP Healcheck checker", ex); + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "UNABLE TO CONNECT - " + ex.toString())); + } + } + + return result; + } + + @Override + public TimeoutHealthCheckExecutionOptions constructOptions(MPCheckerConfiguration c) { + return new TimeoutHealthCheckExecutionOptions(Boolean.valueOf(c.getEnabled()), Long.parseLong(c.getTime()), asTimeUnit(c.getUnit()), + Long.parseLong(c.getTimeout())); + } + + @Override + protected String getDescription() { + return "healthcheck.description.MPhealthcheck"; + } + + private URI buildURI(Server server, String endpoint) throws URISyntaxException { + NetworkListener listener = server.getConfig().getNetworkConfig().getNetworkListeners().getNetworkListener().get(0); + String protocol = Boolean.parseBoolean(listener.findHttpProtocol().getSecurityEnabled()) ? "https" : "http"; + String basePort = listener.getPort(); + Integer truePort = 8080; + try { + truePort = Integer.parseInt(basePort); + } catch (NumberFormatException e) { + PropertyResolver configProps = new PropertyResolver(domain, server.getName()); + String sysPropsPort = configProps.getPropertyValue(basePort); + truePort = Integer.parseInt(sysPropsPort); + } + return new URI(protocol, null, (String) TranslatedConfigView.getTranslatedValue(listener.getAddress()), truePort, "/" + endpoint, null, null); + } + +} diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfiguration.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfiguration.java new file mode 100644 index 00000000000..9e65b51d3e5 --- /dev/null +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfiguration.java @@ -0,0 +1,71 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2018] 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 + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.healthcheck.mp; + +import fish.payara.nucleus.healthcheck.configuration.Checker; +import fish.payara.nucleus.healthcheck.configuration.CheckerConfigurationType; +import fish.payara.nucleus.healthcheck.configuration.CheckerType; +import java.beans.PropertyVetoException; +import javax.validation.constraints.Min; +import org.jvnet.hk2.config.Attribute; +import org.jvnet.hk2.config.Configured; + +/** + * + * @author jonathan coustick + * @since 5.184 + */ +@Configured +@CheckerConfigurationType(type = CheckerType.MP_HEALTH) +public interface MPCheckerConfiguration extends Checker { + + @Attribute(defaultValue = "MP") + String getName(); + void setName(String value) throws PropertyVetoException; + + @Attribute(defaultValue = "30000", dataType = Long.class) + @Min(value = 0) + String getTimeout(); + void setTimeout(String value) throws PropertyVetoException; + +} diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfigurer.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfigurer.java new file mode 100644 index 00000000000..07b64004ebc --- /dev/null +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfigurer.java @@ -0,0 +1,217 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2018] 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 + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.healthcheck.mp; + +import com.sun.enterprise.config.serverbeans.Config; +import fish.payara.nucleus.healthcheck.HealthCheckService; +import fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration; +import java.beans.PropertyVetoException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.inject.Inject; +import javax.validation.constraints.Min; +import org.glassfish.api.ActionReport; +import org.glassfish.api.I18n; +import org.glassfish.api.Param; +import org.glassfish.api.admin.AdminCommand; +import org.glassfish.api.admin.AdminCommandContext; +import org.glassfish.api.admin.CommandLock; +import org.glassfish.api.admin.ExecuteOn; +import org.glassfish.api.admin.RestEndpoint; +import org.glassfish.api.admin.RestEndpoints; +import org.glassfish.api.admin.RuntimeType; +import org.glassfish.api.admin.ServerEnvironment; +import org.glassfish.config.support.CommandTarget; +import org.glassfish.config.support.TargetType; +import org.glassfish.hk2.api.PerLookup; +import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.internal.api.Target; +import org.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.config.ConfigSupport; +import org.jvnet.hk2.config.SingleConfigCode; +import org.jvnet.hk2.config.TransactionFailure; + +/** + * Configure the Microprofile Healthcheck Checker + * @author jonathan coustick + * @since 5.184 + */ +@Service(name = "healthcheck-mp-configure") +@PerLookup +@CommandLock(CommandLock.LockType.NONE) +@I18n("healthcheck.mphealthecheck.configure") +@ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) +@TargetType({CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@RestEndpoints({ + @RestEndpoint(configBean = HealthCheckServiceConfiguration.class, + opType = RestEndpoint.OpType.POST, + path = "healthcheck-mp-configure", + description = "Configures the Microprofile Healthcheck Checker") +}) +public class MPCheckerConfigurer implements AdminCommand { + + private static final Logger LOGGER = Logger.getLogger("HEALTHCHECK-MP"); + + @Inject + ServiceLocator habitat; + + @Inject + protected Target targetUtil; + + @Inject + HealthCheckService healthCheckService; + + @Param(name = "enabled", optional = false) + private Boolean enabled; + + @Param(name = "time", optional = true) + @Min(value = 1, message = "Time period must be 1 or more") + private String time; + + @Param(name = "unit", optional = true, acceptableValues = "DAYS,HOURS,MICROSECONDS,MILLISECONDS,MINUTES,NANOSECONDS,SECONDS") + private String unit; + + @Param(name = "checkerName", optional = true) + private String checkerName; + + @Param(name = "timeout", optional = true) + @Min(value = 1, message = "Time period must be 1 or more") + private String timeout; + + @Param(name = "dynamic", optional = true, defaultValue = "false") + protected Boolean dynamic; + + @Param(name = "target", optional = true, defaultValue = "server-config") + protected String target; + + @Inject + ServerEnvironment server; + + @Override + public void execute(AdminCommandContext context) { + final ActionReport actionReport = context.getActionReport(); + + Config config = targetUtil.getConfig(target); + MPChecker service = habitat.getService(MPChecker.class); + if (service == null) { + actionReport.appendMessage("Microprofile Healthcheck Checker Service could not be found"); + actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); + return; + } + + try { + HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class); + MPCheckerConfiguration hoggingThreadConfiguration = healthCheckServiceConfiguration.getCheckerByType(MPCheckerConfiguration.class); + if (hoggingThreadConfiguration == null) { + ConfigSupport.apply(new SingleConfigCode() { + @Override + public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfigurationProxy) throws + PropertyVetoException, TransactionFailure { + MPCheckerConfiguration checkerProxy = healthCheckServiceConfigurationProxy.createChild(MPCheckerConfiguration.class); + applyValues(checkerProxy); + healthCheckServiceConfigurationProxy.getCheckerList().add(checkerProxy); + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); + return healthCheckServiceConfigurationProxy; + } + }, healthCheckServiceConfiguration); + } else { + ConfigSupport.apply(new SingleConfigCode() { + @Override + public Object run(final MPCheckerConfiguration hoggingThreadConfigurationProxy) throws + PropertyVetoException, TransactionFailure { + applyValues(hoggingThreadConfigurationProxy); + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); + return hoggingThreadConfigurationProxy; + } + }, hoggingThreadConfiguration); + } + + if (dynamic) { + if (server.isDas()) { + if (targetUtil.getConfig(target).isDas()) { + MPCheckerConfiguration checkerByType = healthCheckServiceConfiguration.getCheckerByType(MPCheckerConfiguration.class); + service.setOptions(service.constructOptions(checkerByType)); + healthCheckService.registerCheck(checkerByType.getName(), service); + healthCheckService.reboot(); + } + } else { + // it implicitly targetted to us as we are not the DAS + // restart the service + MPCheckerConfiguration checkerByType = healthCheckServiceConfiguration.getCheckerByType(MPCheckerConfiguration.class); + service.setOptions(service.constructOptions(hoggingThreadConfiguration)); + healthCheckService.registerCheck(checkerByType.getName(), service); + healthCheckService.reboot(); + } + } + + } catch (TransactionFailure ex) { + LOGGER.log(Level.WARNING, "Exception during command ", ex); + actionReport.setMessage(ex.getCause().getMessage()); + actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE); + } + } + + + private void applyValues(MPCheckerConfiguration checkerProxy) throws PropertyVetoException { + if (enabled != null) { + checkerProxy.setEnabled(enabled.toString()); + } + + if (checkerName != null) { + checkerProxy.setName(checkerName); + } + + if (time != null) { + checkerProxy.setTime(time); + } + + if (unit != null) { + checkerProxy.setUnit(unit); + } + + if (timeout != null) { + checkerProxy.setTimeout(timeout); + } + + } +} diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/TimeoutHealthCheckExecutionOptions.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/TimeoutHealthCheckExecutionOptions.java new file mode 100644 index 00000000000..03d5e084301 --- /dev/null +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/TimeoutHealthCheckExecutionOptions.java @@ -0,0 +1,72 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2018] 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 + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.healthcheck.mp; + +import fish.payara.nucleus.healthcheck.HealthCheckExecutionOptions; +import java.util.concurrent.TimeUnit; + +/** + * Execution Options for the Microprofile Healthcheck checker. + * + * This contains the timeout for getting the healthcheck from the remote endpoint + * @author jonathan coustick + * @since 5.184 + */ +public class TimeoutHealthCheckExecutionOptions extends HealthCheckExecutionOptions { + + private final long timeout; + + public TimeoutHealthCheckExecutionOptions(boolean enabled, long time, TimeUnit unit, long timeout) { + super(enabled, time, unit); + this.timeout = timeout; + } + + /** + * The timeout for getting a response from the remove server + * @return The connection timeout in milliseconds + */ + public long getTimeout() { + return timeout; + } + +} diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java index 3cd99b39968..5aae0238392 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java @@ -100,6 +100,7 @@ public class GetHealthCheckConfiguration implements AdminCommand, HealthCheckCon final static String thresholdDiagnosticsHeaders[] = {"Name", "Enabled", "Time", "Unit", "Critical Threshold", "Warning Threshold", "Good Threshold"}; final static String stuckThreadsHeaders[] = {"Name", "Enabled", "Time", "Unit", "Threshold Time", "Threshold Unit"}; + final static String MPHealthCheckHeaders[] = {"Name", "Enabled", "Time", "Unit", "ConnectTime", "Read Time"}; final static String notifierHeaders[] = {"Name", "Notifier Enabled"}; private final String garbageCollectorPropertyName = "garbageCollector"; @@ -139,6 +140,7 @@ public void execute(AdminCommandContext context) { ColumnFormatter hoggingThreadsColumnFormatter = new ColumnFormatter(hoggingThreadsHeaders); ColumnFormatter stuckThreadsColumnFormatter = new ColumnFormatter(stuckThreadsHeaders); ColumnFormatter thresholdDiagnosticsColumnFormatter = new ColumnFormatter(thresholdDiagnosticsHeaders); + ColumnFormatter mpHealthCheckColumnFormatter = new ColumnFormatter(MPHealthCheckHeaders); ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(notifierHeaders); HealthCheckServiceConfiguration configuration = config.getExtensionByType(HealthCheckServiceConfiguration.class); diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceConfigurer.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceConfigurer.java index a46ddee5898..f8443bf7cd4 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceConfigurer.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/HealthCheckServiceConfigurer.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2018] 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 @@ -40,7 +40,6 @@ package fish.payara.nucleus.healthcheck.admin; import com.sun.enterprise.config.serverbeans.Config; -import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.util.LocalStringManagerImpl; import fish.payara.nucleus.healthcheck.HealthCheckService; import fish.payara.nucleus.healthcheck.configuration.Checker; @@ -112,7 +111,7 @@ public class HealthCheckServiceConfigurer implements AdminCommand { @Param(name = "serviceName", optional = false, acceptableValues = "healthcheck-cpu,healthcheck-gc,healthcheck-cpool,healthcheck-heap,healthcheck-threads," - + "healthcheck-machinemem,healthcheck-stuck") + + "healthcheck-machinemem,healthcheck-stuck,healthcheck-mp") private String serviceName; @Param(name = "name", optional = true) diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/CheckerType.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/CheckerType.java index ce8e01e724f..a9802e30397 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/CheckerType.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/CheckerType.java @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2017 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2017-2018 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 @@ -49,5 +49,6 @@ public enum CheckerType { HEAP_MEMORY_USAGE, HOGGING_THREADS, MACHINE_MEMORY_USAGE, - STUCK_THREAD + STUCK_THREAD, + MP_HEALTH } diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/LocalStrings.properties b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/LocalStrings.properties index 9c84f95a2d8..e1fb86ace0e 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/LocalStrings.properties +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/LocalStrings.properties @@ -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-2018 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,4 +43,5 @@ healthcheck.description.garbageCollector=Provides ratio on garbage collection co healthcheck.description.heapMemory=Provides ratio on used heap memory with severity according to defined threshold values healthcheck.description.hoggingThreads=Lists hogging threads with their id when given thresholds exceed healthcheck.description.machineMemory=Provides ratio on used machine memory with severity according to defined threshold values -healthcheck.description.stuckThreads=Provides thread name, id and stack trace for requests which reach over defined threshold values \ No newline at end of file +healthcheck.description.stuckThreads=Provides thread name, id and stack trace for requests which reach over defined threshold values +healthcheck.description.MPhealthcheck=Checks that all instances are responding to Microprofile Healthcheck requests with an UP response \ No newline at end of file From 72cc206dade8053e807ed0c7fe1572c878c9ae3a Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 6 Sep 2018 10:54:43 +0100 Subject: [PATCH 02/11] PAYARA-2479 added admin console integration for mp healthcheck checker --- .../admingui/healthcheck/Strings.properties | 9 +- .../checkers/mphealthcheckConfiguration.jsf | 129 ++++++++++++++++++ .../healthcheck/healthcheckConfigTabs.inc | 11 +- .../fish/payara/healthcheck/mp/MPChecker.java | 1 + .../healthcheck/mp/MPCheckerConfigurer.java | 1 + appserver/payara-appserver-modules/pom.xml | 1 + .../healthcheck/HealthCheckConstants.java | 4 +- .../admin/GetHealthCheckConfiguration.java | 48 ++++++- .../MPCheckerConfiguration.java | 5 +- 9 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf rename {appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp => nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration}/MPCheckerConfiguration.java (92%) diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties index dca34927d41..4086583e9b5 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties @@ -1,6 +1,6 @@ # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # -# Copyright (c) [2017] Payara Foundation and/or its affiliates. All rights reserved. +# Copyright (c) [20172-2018] 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 @@ -70,6 +70,8 @@ healthcheck.configuration.stuckThreadsCheckerTabTitle=Stuck Threads healthcheck.configuration.stuckThreadsCheckerTabTitleToolTip=Configures the Stuck Threads HealthCheck. healthcheck.configuration.garbageCollectorCheckerTabTitle=Garbage Collector healthcheck.configuration.garbageCollectorCheckerTabTitleToolTip=Configures the Garbage Collector HealthCheck. +healthcheck.configuration.mircroprofileHealthcheckCheckerTabTitle=Microprofile Healthcheck +healthcheck.configuration.mircroprofileHealthcheckCheckerTabTitleToolTip=Configures the Microprofile Healthcheck HealthCheck healthcheck.checker.configuration.enabledLabel=Enabled healthcheck.checker.configuration.enabledLabelHelpText=Enables or Disables the checker. @@ -119,6 +121,11 @@ healthcheck.checker.configuration.hoggingThreads.retryCountLabelHelpText=Number healthcheck.checker.configuration.garbageCollector.pageTitle=Garbage Collector healthcheck.checker.configuration.garbageCollector.pageTitleHelpText=Configuration options for the Garbage Collector HealthCheck. +healthcheck.checker.configuration.mircroprofileHealthcheckChecker.pageTitle=Garbage Collector +healthcheck.checker.configuration.mircroprofileHealthcheckChecker.pageTitleHelpText=Configuration options for the Microprofile Healthcheck HealthCheck.
Checks the status of the Microprofile Healthcheck endpoint for all instances in the domain +healthcheck.checker.configuration.mircroprofileHealthcheckChecker.timeoutLabel=Timeout +healthcheck.checker.configuration.mircroprofileHealthcheckChecker.timeoutLabelHelpText=Time in milliseconds before an instance is considered nonresponsive + healthcheck.checker.configuration.stuckThreads.pageTitle=Stuck Threads healthcheck.checker.configuration.stuckThreads.pageTitleHelpText=Configuration options for the Stuck Threads HealthCheck. healthcheck.checker.configuration.stuckThreads.timeThresholdLabel=Threshold time diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf new file mode 100644 index 00000000000..16f934e6ccd --- /dev/null +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf @@ -0,0 +1,129 @@ + + + + + + + + + + + + +#include "/common/shared/alertMsg_1.inc" +#include "/healthcheck/healthcheck/healthcheckConfigTabs.inc + + + + + + + + + + +#include "/common/shared/configNameSection.inc" + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc index 34eee4be64a..da40cf231e6 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc @@ -1,6 +1,6 @@ diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/HealthCheckConstants.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/HealthCheckConstants.java index f74abbefde2..ca54e97f14d 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/HealthCheckConstants.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/HealthCheckConstants.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2018] 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 @@ -74,6 +74,7 @@ public interface HealthCheckConstants { final String DEFAULT_UNIT = "MINUTES"; final String DEFAULT_RETRY_COUNT = "3"; final String DEFAULT_THRESHOLD_PERCENTAGE = "95"; + final String DEFAULT_TIMEOUT = "30000"; final String DEFAULT_GARBAGE_COLLECTOR_NAME = "GBGC"; final String DEFAULT_CONNECTION_POOL_NAME = "CONP"; @@ -82,4 +83,5 @@ public interface HealthCheckConstants { final String DEFAULT_MACHINE_MEMORY_USAGE_NAME = "MEMM"; final String DEFAULT_HOGGING_THREADS_NAME = "HOGT"; final String DEFAULT_STUCK_THREAD_NAME = "STUCK"; + final String DEFAULT_MICROPROFILE_HEALTHCHECK_NAME = "MP"; } diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java index 5aae0238392..1a3f2491e6c 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2016-2017 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2018 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 @@ -49,6 +49,7 @@ import fish.payara.nucleus.healthcheck.configuration.CheckerConfigurationType; import fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration; import fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker; +import fish.payara.nucleus.healthcheck.configuration.MPCheckerConfiguration; import fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker; import fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck; import fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker; @@ -100,7 +101,7 @@ public class GetHealthCheckConfiguration implements AdminCommand, HealthCheckCon final static String thresholdDiagnosticsHeaders[] = {"Name", "Enabled", "Time", "Unit", "Critical Threshold", "Warning Threshold", "Good Threshold"}; final static String stuckThreadsHeaders[] = {"Name", "Enabled", "Time", "Unit", "Threshold Time", "Threshold Unit"}; - final static String MPHealthCheckHeaders[] = {"Name", "Enabled", "Time", "Unit", "ConnectTime", "Read Time"}; + final static String MPHealthCheckHeaders[] = {"Name", "Enabled", "Time", "Unit", "Timeout"}; final static String notifierHeaders[] = {"Name", "Notifier Enabled"}; private final String garbageCollectorPropertyName = "garbageCollector"; @@ -110,6 +111,7 @@ public class GetHealthCheckConfiguration implements AdminCommand, HealthCheckCon private final String machineMemoryUsagePropertyName = "machineMemoryUsage"; private final String hoggingThreadsPropertyName = "hoggingThreads"; private final String stuckThreadsPropertyName = "stuckThreads"; + private final String mpHealthcheckPropertyName = "mpHealthcheck"; @Inject ServiceLocator habitat; @@ -135,6 +137,7 @@ public void execute(AdminCommandContext context) { ActionReport hoggingThreadsActionReport = mainActionReport.addSubActionsReport(); // subReport(1) ActionReport thresholdDiagnosticsActionReport = mainActionReport.addSubActionsReport(); // subReport(2) ActionReport stuckThreadsActionReport = mainActionReport.addSubActionsReport(); //subReport(3) + ActionReport mpHealthcheckCheckerActionReport = mainActionReport.addSubActionsReport(); //subReport(4) ColumnFormatter baseColumnFormatter = new ColumnFormatter(baseHeaders); ColumnFormatter hoggingThreadsColumnFormatter = new ColumnFormatter(hoggingThreadsHeaders); @@ -216,6 +219,7 @@ public Class apply(Notifier input) { Properties hoggingThreadsExtraProps = new Properties(); Properties stuckThreadsExtrasProps = new Properties(); Properties thresholdDiagnosticsExtraProps = new Properties(); + Properties mpHealthcheckExtrasProps = new Properties(); for (ServiceHandle serviceHandle : allServiceHandles) { Checker checker = configuration.getCheckerByType(serviceHandle.getService().getCheckerType()); @@ -267,7 +271,20 @@ public Class apply(Notifier input) { addStuckThreadsCheckerExtrasProps(stuckThreadsExtrasProps, stuckThreadsChecker); - } else if (checker != null) { + } else if (checker instanceof MPCheckerConfiguration) { + MPCheckerConfiguration mpHealthcheckChecker = (MPCheckerConfiguration) checker; + + Object[] values = new Object[5]; + values[0] = mpHealthcheckChecker.getName(); + values[1] = mpHealthcheckChecker.getEnabled(); + values[2] = mpHealthcheckChecker.getTime(); + values[3] = mpHealthcheckChecker.getUnit(); + values[4] = mpHealthcheckChecker.getTimeout(); + mpHealthCheckColumnFormatter.addRow(values); + + addMPHealthcheckCheckerExtrasProps(mpHealthcheckExtrasProps, mpHealthcheckChecker); + + }else if (checker != null) { Object values[] = new Object[4]; values[0] = checker.getName(); values[1] = checker.getEnabled(); @@ -296,6 +313,10 @@ public Class apply(Notifier input) { stuckThreadsActionReport.setMessage(stuckThreadsColumnFormatter.toString()); stuckThreadsActionReport.appendMessage(StringUtils.EOL); } + if (!mpHealthCheckColumnFormatter.getContent().isEmpty()) { + mpHealthcheckCheckerActionReport.setMessage(mpHealthCheckColumnFormatter.toString()); + mpHealthcheckCheckerActionReport.appendMessage(StringUtils.EOL); + } // Populate the extraProps with defaults for any checker that isn't present baseExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, garbageCollectorPropertyName); @@ -309,12 +330,14 @@ public Class apply(Notifier input) { heapMemoryUsagePropertyName); thresholdDiagnosticsExtraProps = checkCheckerPropertyPresence(thresholdDiagnosticsExtraProps, machineMemoryUsagePropertyName); + mpHealthcheckExtrasProps = checkCheckerPropertyPresence(mpHealthcheckExtrasProps, mpHealthcheckPropertyName); // Add the extra props to their respective action reports baseActionReport.setExtraProperties(baseExtraProps); hoggingThreadsActionReport.setExtraProperties(hoggingThreadsExtraProps); thresholdDiagnosticsActionReport.setExtraProperties(thresholdDiagnosticsExtraProps); stuckThreadsActionReport.setExtraProperties(stuckThreadsExtrasProps); + mpHealthcheckCheckerActionReport.setExtraProperties(mpHealthcheckExtrasProps); mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); } @@ -347,6 +370,18 @@ private void addStuckThreadsCheckerExtrasProps(Properties stuckThreadsExtrasProp } + private void addMPHealthcheckCheckerExtrasProps(Properties mpHealthcheckExtrasProps, MPCheckerConfiguration mpHealthcheckCheck) { + Map extraPropsMap = new HashMap(5); + extraPropsMap.put("checkerName", mpHealthcheckCheck.getName()); + extraPropsMap.put("enabled", mpHealthcheckCheck.getEnabled()); + extraPropsMap.put("time", mpHealthcheckCheck.getTime()); + extraPropsMap.put("unit", mpHealthcheckCheck.getUnit()); + extraPropsMap.put("timeout", mpHealthcheckCheck.getTimeout()); + + mpHealthcheckExtrasProps.put(mpHealthcheckPropertyName, extraPropsMap); + + } + private void addThresholdDiagnosticsCheckerExtraProps(Properties thresholdDiagnosticsExtraProps, ThresholdDiagnosticsChecker thresholdDiagnosticsChecker) { @@ -445,6 +480,11 @@ private Properties checkCheckerPropertyPresence(Properties extraProps, String ch extraPropsMap.put("checkerName", DEFAULT_STUCK_THREAD_NAME); extraProps.put(checkerName, populateDefaultValuesMap(extraPropsMap)); break; + case mpHealthcheckPropertyName: + extraPropsMap = new HashMap<>(5); + extraPropsMap.put("checkerName", DEFAULT_MICROPROFILE_HEALTHCHECK_NAME); + extraProps.put(checkerName, populateDefaultValuesMap(extraPropsMap)); + break; } } @@ -464,6 +504,8 @@ private Map populateDefaultValuesMap(Map extraPr } else if (extraPropsMap.containsValue(DEFAULT_STUCK_THREAD_NAME)){ extraPropsMap.put("threshold", DEFAULT_TIME); extraPropsMap.put("thresholdUnit", DEFAULT_UNIT); + } else if (extraPropsMap.containsValue(DEFAULT_MICROPROFILE_HEALTHCHECK_NAME)) { + extraPropsMap.put("timeout", DEFAULT_TIMEOUT); } else { extraPropsMap.put("thresholdCritical", THRESHOLD_DEFAULTVAL_CRITICAL); extraPropsMap.put("thresholdWarning", THRESHOLD_DEFAULTVAL_WARNING); diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfiguration.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MPCheckerConfiguration.java similarity index 92% rename from appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfiguration.java rename to nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MPCheckerConfiguration.java index 9e65b51d3e5..bffa3d2d4de 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfiguration.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MPCheckerConfiguration.java @@ -40,11 +40,8 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package fish.payara.healthcheck.mp; +package fish.payara.nucleus.healthcheck.configuration; -import fish.payara.nucleus.healthcheck.configuration.Checker; -import fish.payara.nucleus.healthcheck.configuration.CheckerConfigurationType; -import fish.payara.nucleus.healthcheck.configuration.CheckerType; import java.beans.PropertyVetoException; import javax.validation.constraints.Min; import org.jvnet.hk2.config.Attribute; From 60a4bd5ddaabcd9c98035eb51534bc9a37ec1270 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Mon, 10 Sep 2018 17:13:57 +0100 Subject: [PATCH 03/11] PAYARA-2479 resolve typos and other review comments --- .../payara/admingui/healthcheck/Strings.properties | 14 +++++++------- .../checkers/mphealthcheckConfiguration.jsf | 10 +++++----- .../healthcheck-checker/pom.xml | 3 +-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties index 4086583e9b5..0218a0bb1fd 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/fish/payara/admingui/healthcheck/Strings.properties @@ -1,6 +1,6 @@ # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # -# Copyright (c) [20172-2018] Payara Foundation and/or its affiliates. All rights reserved. +# Copyright (c) [2017-2018] 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 @@ -70,8 +70,8 @@ healthcheck.configuration.stuckThreadsCheckerTabTitle=Stuck Threads healthcheck.configuration.stuckThreadsCheckerTabTitleToolTip=Configures the Stuck Threads HealthCheck. healthcheck.configuration.garbageCollectorCheckerTabTitle=Garbage Collector healthcheck.configuration.garbageCollectorCheckerTabTitleToolTip=Configures the Garbage Collector HealthCheck. -healthcheck.configuration.mircroprofileHealthcheckCheckerTabTitle=Microprofile Healthcheck -healthcheck.configuration.mircroprofileHealthcheckCheckerTabTitleToolTip=Configures the Microprofile Healthcheck HealthCheck +healthcheck.configuration.microprofileHealthcheckCheckerTabTitle=MicroProfile Healthcheck Checker +healthcheck.configuration.microprofileHealthcheckCheckerTabTitleToolTip=Configures the MicroProfile Healthcheck HealthCheck healthcheck.checker.configuration.enabledLabel=Enabled healthcheck.checker.configuration.enabledLabelHelpText=Enables or Disables the checker. @@ -121,10 +121,10 @@ healthcheck.checker.configuration.hoggingThreads.retryCountLabelHelpText=Number healthcheck.checker.configuration.garbageCollector.pageTitle=Garbage Collector healthcheck.checker.configuration.garbageCollector.pageTitleHelpText=Configuration options for the Garbage Collector HealthCheck. -healthcheck.checker.configuration.mircroprofileHealthcheckChecker.pageTitle=Garbage Collector -healthcheck.checker.configuration.mircroprofileHealthcheckChecker.pageTitleHelpText=Configuration options for the Microprofile Healthcheck HealthCheck.
Checks the status of the Microprofile Healthcheck endpoint for all instances in the domain -healthcheck.checker.configuration.mircroprofileHealthcheckChecker.timeoutLabel=Timeout -healthcheck.checker.configuration.mircroprofileHealthcheckChecker.timeoutLabelHelpText=Time in milliseconds before an instance is considered nonresponsive +healthcheck.checker.configuration.microprofileHealthcheckChecker.pageTitle=Microprofile Healthcheck Checker +healthcheck.checker.configuration.microprofileHealthcheckChecker.pageTitleHelpText=Configuration options for the Microprofile Healthcheck HealthCheck.
Checks the status of the Microprofile Healthcheck endpoint for all instances in the domain +healthcheck.checker.configuration.microprofileHealthcheckChecker.timeoutLabel=Timeout +healthcheck.checker.configuration.microprofileHealthcheckChecker.timeoutLabelHelpText=Time in milliseconds before an instance is considered nonresponsive healthcheck.checker.configuration.stuckThreads.pageTitle=Stuck Threads healthcheck.checker.configuration.stuckThreads.pageTitleHelpText=Configuration options for the Stuck Threads HealthCheck. diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf index 16f934e6ccd..becc972f950 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf @@ -41,7 +41,7 @@ setResourceBundle(key="i18nhx" bundle="fish.payara.admingui.healthcheck.Strings"); /> + guiTitle="$resource{i18nhx.healthcheck.checker.configuration.microprofileHealthcheckChecker.pageTitle}"> @@ -69,8 +69,8 @@ #include "/common/shared/alertMsg_1.inc" #include "/healthcheck/healthcheck/healthcheckConfigTabs.inc - + + label="$resource{i18nhx.healthcheck.checker.configuration.microprofileHealthcheckChecker.timeoutLabel}" + helpText="$resource{i18nhx.healthcheck.checker.configuration.microprofileHealthcheckChecker.timeoutLabelHelpText}"> diff --git a/appserver/payara-appserver-modules/healthcheck-checker/pom.xml b/appserver/payara-appserver-modules/healthcheck-checker/pom.xml index 6e0156e3213..d0b7d5bec6f 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/pom.xml +++ b/appserver/payara-appserver-modules/healthcheck-checker/pom.xml @@ -84,8 +84,7 @@ fish.payara.admingui console-common - 5.182-SNAPSHOT - jar + ${project.version} javax From 9dbe47a0120cf9a46da653f3ec47a6cb98392c90 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Tue, 11 Sep 2018 11:03:32 +0100 Subject: [PATCH 04/11] PAYAAR-2479 renamed configuration command --- ...onfigurer.java => SetHealthcheckMPCheckerConfiguration.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/{MPCheckerConfigurer.java => SetHealthcheckMPCheckerConfiguration.java} (99%) diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfigurer.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/SetHealthcheckMPCheckerConfiguration.java similarity index 99% rename from appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfigurer.java rename to appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/SetHealthcheckMPCheckerConfiguration.java index 0ba2e2993cf..642adb081c3 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPCheckerConfigurer.java +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/SetHealthcheckMPCheckerConfiguration.java @@ -77,7 +77,7 @@ * @author jonathan coustick * @since 5.184 */ -@Service(name = "healthcheck-mp-configure") +@Service(name = "set-healthcheck-mp-checker-configuration") @PerLookup @CommandLock(CommandLock.LockType.NONE) @I18n("healthcheck.mphealthecheck.configure") From eb7006fd4f0bdfb5ea2a0eefc107ce12aadd3631 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Wed, 12 Sep 2018 15:13:21 +0100 Subject: [PATCH 05/11] PAYARA-2479 actually rename class --- .../healthcheck/mp/SetHealthcheckMPCheckerConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/SetHealthcheckMPCheckerConfiguration.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/SetHealthcheckMPCheckerConfiguration.java index 642adb081c3..ce93eb4d57d 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/SetHealthcheckMPCheckerConfiguration.java +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/SetHealthcheckMPCheckerConfiguration.java @@ -89,7 +89,7 @@ path = "healthcheck-mp-configure", description = "Configures the Microprofile Healthcheck Checker") }) -public class MPCheckerConfigurer implements AdminCommand { +public class SetHealthcheckMPCheckerConfiguration implements AdminCommand { private static final Logger LOGGER = Logger.getLogger("HEALTHCHECK-MP"); From bd4e3d179d062a42a3c73ad4849f0ef37b8b548c Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 13 Sep 2018 15:16:25 +0100 Subject: [PATCH 06/11] PAYARA-2479 corrected more typos --- .../src/main/resources/healthcheck/healthcheckConfigTabs.inc | 4 ++-- .../src/main/java/fish/payara/healthcheck/mp/MPChecker.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc index da40cf231e6..b70a2a728a2 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc @@ -116,8 +116,8 @@ + text="$resource{i18nhx.healthcheck.configuration.microprofileHealthcheckCheckerTabTitle}" + toolTip="$resource{i18nhx.healthcheck.configuration.microprofileHealthcheckCheckerTabTitleToolTip}"> implements PostConstruct { - private static final Logger LOGGER = Logger.getLogger("HEALTHCHECK"); + private static final Logger LOGGER = Logger.getLogger(MPChecker.class.getPackage().getName()); @Inject private Target targetUtil; @@ -155,7 +155,7 @@ public HealthCheckResult doCheck() { try { taskResult.get(options.getTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException ex) { - LOGGER.log(Level.FINE, "Error processing MP Healcheck checker", ex); + LOGGER.log(Level.FINE, "Error processing MP Healthcheck checker", ex); result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "UNABLE TO CONNECT - " + ex.toString())); } } From 846bec90cac364fca07d78bc48469b991d591cf0 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 20 Sep 2018 13:13:58 +0100 Subject: [PATCH 07/11] PAYARA-2479 review comments included, can now only run on DAS --- .../HealthCheckTimeoutExecutionOptions.java} | 6 +-- .../MicroProfileHealthChecker.java} | 25 ++++++++---- ...croProfileHealthCheckerConfiguration.java} | 38 ++++++++++--------- .../admin/GetHealthCheckConfiguration.java | 10 ++--- ...croProfileHealthCheckerConfiguration.java} | 2 +- 5 files changed, 47 insertions(+), 34 deletions(-) rename appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/{mp/TimeoutHealthCheckExecutionOptions.java => mphealth/HealthCheckTimeoutExecutionOptions.java} (94%) rename appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/{mp/MPChecker.java => mphealth/MicroProfileHealthChecker.java} (89%) rename appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/{mp/SetHealthcheckMPCheckerConfiguration.java => mphealth/SetMicroProfileHealthCheckerConfiguration.java} (82%) rename nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/{MPCheckerConfiguration.java => MicroProfileHealthCheckerConfiguration.java} (97%) diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/TimeoutHealthCheckExecutionOptions.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/HealthCheckTimeoutExecutionOptions.java similarity index 94% rename from appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/TimeoutHealthCheckExecutionOptions.java rename to appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/HealthCheckTimeoutExecutionOptions.java index 03d5e084301..220034e120a 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/TimeoutHealthCheckExecutionOptions.java +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/HealthCheckTimeoutExecutionOptions.java @@ -40,7 +40,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package fish.payara.healthcheck.mp; +package fish.payara.healthcheck.mphealth; import fish.payara.nucleus.healthcheck.HealthCheckExecutionOptions; import java.util.concurrent.TimeUnit; @@ -52,11 +52,11 @@ * @author jonathan coustick * @since 5.184 */ -public class TimeoutHealthCheckExecutionOptions extends HealthCheckExecutionOptions { +public class HealthCheckTimeoutExecutionOptions extends HealthCheckExecutionOptions { private final long timeout; - public TimeoutHealthCheckExecutionOptions(boolean enabled, long time, TimeUnit unit, long timeout) { + public HealthCheckTimeoutExecutionOptions(boolean enabled, long time, TimeUnit unit, long timeout) { super(enabled, time, unit); this.timeout = timeout; } diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPChecker.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java similarity index 89% rename from appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPChecker.java rename to appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java index b3fd710583d..a4b65e2dc3e 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mp/MPChecker.java +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/MicroProfileHealthChecker.java @@ -40,7 +40,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package fish.payara.healthcheck.mp; +package fish.payara.healthcheck.mphealth; import com.sun.enterprise.config.serverbeans.Domain; import java.net.URI; @@ -54,7 +54,7 @@ import com.sun.enterprise.config.serverbeans.Server; import com.sun.enterprise.v3.services.impl.GrizzlyService; -import fish.payara.nucleus.healthcheck.configuration.MPCheckerConfiguration; +import fish.payara.nucleus.healthcheck.configuration.MicroProfileHealthCheckerConfiguration; import fish.payara.microprofile.healthcheck.config.MetricsHealthCheckConfiguration; import fish.payara.notification.healthcheck.HealthCheckResultEntry; import fish.payara.notification.healthcheck.HealthCheckResultStatus; @@ -68,6 +68,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.ws.rs.ProcessingException; +import org.glassfish.api.admin.ServerEnvironment; import org.glassfish.config.support.PropertyResolver; import org.glassfish.config.support.TranslatedConfigView; import org.glassfish.grizzly.config.dom.NetworkListener; @@ -77,7 +78,7 @@ import org.jvnet.hk2.annotations.Service; /** - * Health Check service that pokes MP Healthcheck endpoints of instances + * Health Check service that pokes MicroProfile Healthcheck endpoints of instances * in the current domain to see if they are responsive * * @author jonathan coustick @@ -85,9 +86,9 @@ */ @Service(name = "healthcheck-mp") @RunLevel(10) -public class MPChecker extends BaseHealthCheck implements PostConstruct { +public class MicroProfileHealthChecker extends BaseHealthCheck implements PostConstruct { - private static final Logger LOGGER = Logger.getLogger(MPChecker.class.getPackage().getName()); + private static final Logger LOGGER = Logger.getLogger(MicroProfileHealthChecker.class.getPackage().getName()); @Inject private Target targetUtil; @@ -100,15 +101,23 @@ public class MPChecker extends BaseHealthCheck() { @Override public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure { - MPCheckerConfiguration checkerProxy = healthCheckServiceConfigurationProxy.createChild(MPCheckerConfiguration.class); + MicroProfileHealthCheckerConfiguration checkerProxy = + healthCheckServiceConfigurationProxy.createChild(MicroProfileHealthCheckerConfiguration.class); applyValues(checkerProxy); healthCheckServiceConfigurationProxy.getCheckerList().add(checkerProxy); actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); @@ -156,21 +158,22 @@ public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfig } }, healthCheckServiceConfiguration); } else { - ConfigSupport.apply(new SingleConfigCode() { + ConfigSupport.apply(new SingleConfigCode() { @Override - public Object run(final MPCheckerConfiguration hoggingThreadConfigurationProxy) throws + public Object run(final MicroProfileHealthCheckerConfiguration hoggingThreadConfigurationProxy) throws PropertyVetoException, TransactionFailure { applyValues(hoggingThreadConfigurationProxy); actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); return hoggingThreadConfigurationProxy; } - }, hoggingThreadConfiguration); + }, healthCheckerConfiguration); } if (dynamic) { if (server.isDas()) { if (targetUtil.getConfig(target).isDas()) { - MPCheckerConfiguration checkerByType = healthCheckServiceConfiguration.getCheckerByType(MPCheckerConfiguration.class); + MicroProfileHealthCheckerConfiguration checkerByType = + healthCheckServiceConfiguration.getCheckerByType(MicroProfileHealthCheckerConfiguration.class); service.setOptions(service.constructOptions(checkerByType)); healthCheckService.registerCheck(checkerByType.getName(), service); healthCheckService.reboot(); @@ -178,8 +181,9 @@ public Object run(final MPCheckerConfiguration hoggingThreadConfigurationProxy) } else { // it implicitly targetted to us as we are not the DAS // restart the service - MPCheckerConfiguration checkerByType = healthCheckServiceConfiguration.getCheckerByType(MPCheckerConfiguration.class); - service.setOptions(service.constructOptions(hoggingThreadConfiguration)); + MicroProfileHealthCheckerConfiguration checkerByType = + healthCheckServiceConfiguration.getCheckerByType(MicroProfileHealthCheckerConfiguration.class); + service.setOptions(service.constructOptions(healthCheckerConfiguration)); healthCheckService.registerCheck(checkerByType.getName(), service); healthCheckService.reboot(); } @@ -193,7 +197,7 @@ public Object run(final MPCheckerConfiguration hoggingThreadConfigurationProxy) } - private void applyValues(MPCheckerConfiguration checkerProxy) throws PropertyVetoException { + private void applyValues(MicroProfileHealthCheckerConfiguration checkerProxy) throws PropertyVetoException { if (enabled != null) { checkerProxy.setEnabled(enabled.toString()); } diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java index 1a3f2491e6c..e0d52b4d971 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/admin/GetHealthCheckConfiguration.java @@ -49,7 +49,7 @@ import fish.payara.nucleus.healthcheck.configuration.CheckerConfigurationType; import fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration; import fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker; -import fish.payara.nucleus.healthcheck.configuration.MPCheckerConfiguration; +import fish.payara.nucleus.healthcheck.configuration.MicroProfileHealthCheckerConfiguration; import fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker; import fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck; import fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker; @@ -111,7 +111,7 @@ public class GetHealthCheckConfiguration implements AdminCommand, HealthCheckCon private final String machineMemoryUsagePropertyName = "machineMemoryUsage"; private final String hoggingThreadsPropertyName = "hoggingThreads"; private final String stuckThreadsPropertyName = "stuckThreads"; - private final String mpHealthcheckPropertyName = "mpHealthcheck"; + private final String mpHealthcheckPropertyName = "mpHealth"; @Inject ServiceLocator habitat; @@ -271,8 +271,8 @@ public Class apply(Notifier input) { addStuckThreadsCheckerExtrasProps(stuckThreadsExtrasProps, stuckThreadsChecker); - } else if (checker instanceof MPCheckerConfiguration) { - MPCheckerConfiguration mpHealthcheckChecker = (MPCheckerConfiguration) checker; + } else if (checker instanceof MicroProfileHealthCheckerConfiguration) { + MicroProfileHealthCheckerConfiguration mpHealthcheckChecker = (MicroProfileHealthCheckerConfiguration) checker; Object[] values = new Object[5]; values[0] = mpHealthcheckChecker.getName(); @@ -370,7 +370,7 @@ private void addStuckThreadsCheckerExtrasProps(Properties stuckThreadsExtrasProp } - private void addMPHealthcheckCheckerExtrasProps(Properties mpHealthcheckExtrasProps, MPCheckerConfiguration mpHealthcheckCheck) { + private void addMPHealthcheckCheckerExtrasProps(Properties mpHealthcheckExtrasProps, MicroProfileHealthCheckerConfiguration mpHealthcheckCheck) { Map extraPropsMap = new HashMap(5); extraPropsMap.put("checkerName", mpHealthcheckCheck.getName()); extraPropsMap.put("enabled", mpHealthcheckCheck.getEnabled()); diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MPCheckerConfiguration.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MicroProfileHealthCheckerConfiguration.java similarity index 97% rename from nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MPCheckerConfiguration.java rename to nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MicroProfileHealthCheckerConfiguration.java index bffa3d2d4de..0ff41a20a2d 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MPCheckerConfiguration.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/configuration/MicroProfileHealthCheckerConfiguration.java @@ -54,7 +54,7 @@ */ @Configured @CheckerConfigurationType(type = CheckerType.MP_HEALTH) -public interface MPCheckerConfiguration extends Checker { +public interface MicroProfileHealthCheckerConfiguration extends Checker { @Attribute(defaultValue = "MP") String getName(); From 05d662b341b142b2000a1363c549facfdfff71d8 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 20 Sep 2018 14:56:16 +0100 Subject: [PATCH 08/11] PAYARA-2479 config now only shows up for server-config --- .../healthcheck/checkers/mphealthcheckConfiguration.jsf | 2 +- .../src/main/resources/healthcheck/healthcheckConfigTabs.inc | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf index becc972f950..f3fbfb5f698 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/checkers/mphealthcheckConfiguration.jsf @@ -54,7 +54,7 @@ gf.restRequest(endpoint="#{pageSession.HEALTHCHECK_CONFIG_URL}/get-healthcheck-configuration?target=#{pageSession.configName}" method="GET" result="#{requestScope.resp}"); setPageSessionAttribute(key="valueMap", - value="#{requestScope.resp.data.subReports.get(4).extraProperties.mpHealthcheck}"); + value="#{requestScope.resp.data.subReports.get(4).extraProperties.mpHealth}"); mapPut(map="#{pageSession.valueMap}" key="target" value="#{pageSession.configName}"); setPageSessionAttribute(key="convertToFalseList", value={"enabled", "dynamic"}); diff --git a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc index b70a2a728a2..f03e1c98c51 100644 --- a/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc +++ b/appserver/admingui/healthcheck-service-console-plugin/src/main/resources/healthcheck/healthcheckConfigTabs.inc @@ -117,7 +117,8 @@ + toolTip="$resource{i18nhx.healthcheck.configuration.microprofileHealthcheckCheckerTabTitleToolTip}" + visible="#{pageSession.configName == 'server-config'}"> Date: Thu, 20 Sep 2018 15:37:56 +0100 Subject: [PATCH 09/11] PAYARA-2479 update woodstock version from proper use of visible --- appserver/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appserver/pom.xml b/appserver/pom.xml index b5f4ed63659..d36527a3e6f 100644 --- a/appserver/pom.xml +++ b/appserver/pom.xml @@ -190,7 +190,7 @@ 0.2 2.1.2 - 4.0.2.10.payara-p12 + 4.0.2.10.payara-p13 1.122-57.2889 1.122-57.2889 From 624fffa941ffc3a2807d0bce11ae4a545d254431 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Tue, 25 Sep 2018 10:50:19 +0100 Subject: [PATCH 10/11] PAYARA-3118 MP Health checker now works with micro instances in cluster --- .../healthcheck-checker/pom.xml | 5 + .../mphealth/MicroProfileHealthChecker.java | 111 ++++++++++++++---- ...icroProfileHealthCheckerConfiguration.java | 2 +- 3 files changed, 91 insertions(+), 27 deletions(-) diff --git a/appserver/payara-appserver-modules/healthcheck-checker/pom.xml b/appserver/payara-appserver-modules/healthcheck-checker/pom.xml index d0b7d5bec6f..a56d222bf62 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/pom.xml +++ b/appserver/payara-appserver-modules/healthcheck-checker/pom.xml @@ -86,6 +86,11 @@ console-common ${project.version} + + fish.payara.micro + payara-micro-service + ${project.version} + javax javaee-api 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 a4b65e2dc3e..c1d88740473 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 @@ -54,6 +54,9 @@ import com.sun.enterprise.config.serverbeans.Server; import com.sun.enterprise.v3.services.impl.GrizzlyService; +import fish.payara.appserver.micro.services.PayaraInstanceImpl; +import fish.payara.micro.ClusterCommandResult; +import fish.payara.micro.data.InstanceDescriptor; import fish.payara.nucleus.healthcheck.configuration.MicroProfileHealthCheckerConfiguration; import fish.payara.microprofile.healthcheck.config.MetricsHealthCheckConfiguration; import fish.payara.notification.healthcheck.HealthCheckResultEntry; @@ -61,6 +64,9 @@ import fish.payara.nucleus.executorservice.PayaraExecutorService; import fish.payara.nucleus.healthcheck.HealthCheckResult; import fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck; +import java.net.URL; +import java.util.HashSet; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -72,7 +78,7 @@ import org.glassfish.config.support.PropertyResolver; import org.glassfish.config.support.TranslatedConfigView; import org.glassfish.grizzly.config.dom.NetworkListener; -import org.glassfish.hk2.api.PostConstruct;; +import org.glassfish.hk2.api.PostConstruct; import org.glassfish.hk2.runlevel.RunLevel; import org.glassfish.internal.api.Target; import org.jvnet.hk2.annotations.Service; @@ -89,22 +95,26 @@ public class MicroProfileHealthChecker extends BaseHealthCheck implements PostConstruct { private static final Logger LOGGER = Logger.getLogger(MicroProfileHealthChecker.class.getPackage().getName()); - + private static final String GET_MP_CONFIG_STRING = "get-microprofile-healthcheck-configuration"; + @Inject private Target targetUtil; @Inject private PayaraExecutorService payaraExecutorService; - + @Inject GrizzlyService grizzlyService; - + @Inject Domain domain; - + @Inject ServerEnvironment envrionment; + @Inject + private PayaraInstanceImpl payaraMicro; + @Override public void postConstruct() { postConstruct(this, MicroProfileHealthCheckerConfiguration.class); @@ -113,14 +123,20 @@ public void postConstruct() { @Override public HealthCheckResult doCheck() { HealthCheckResult result = new HealthCheckResult(); - + if (!envrionment.isDas()) { //currrently this should only run on DAS return result; } + Map> configs = payaraMicro.executeClusteredASAdmin(GET_MP_CONFIG_STRING, new String[0]); + + HashSet usedInstances = new HashSet(); + //get all instances that this server knows about for (Server server : domain.getServers().getServer()) { + + usedInstances.add(server.getName()); Future taskResult = payaraExecutorService.submit(() -> { @@ -132,25 +148,7 @@ public HealthCheckResult doCheck() { URI remote = buildURI(server, endpoint); - //send request to remote healthcheck endpoint to get the status - Client jaxrsClient = ClientBuilder.newClient(); - WebTarget target = jaxrsClient.target(remote); - - Response metricsResponse = target.request().accept(MediaType.APPLICATION_JSON).get(); - switch (metricsResponse.getStatus()) { - case 200: - result.add(new HealthCheckResultEntry(HealthCheckResultStatus.GOOD, "UP")); - break; - case 503: - result.add(new HealthCheckResultEntry(HealthCheckResultStatus.WARNING, "DOWN")); - break; - case 500: - result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "FAILURE")); - break; - default: - result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "UNKNOWN RESPONSE")); - break; - } + result.add(pingHealthEndpoint(remote)); } catch (URISyntaxException ex) { result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "INVALID ENDPOINT: " + ex.getInput())); @@ -168,13 +166,56 @@ public HealthCheckResult doCheck() { result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "UNABLE TO CONNECT - " + ex.toString())); } } + + for (InstanceDescriptor instance : payaraMicro.getClusteredPayaras()) { + + if (usedInstances.contains(instance.getInstanceName())) { + continue; + } + + Future taskResult = payaraExecutorService.submit(() -> { + try { + + ClusterCommandResult mpHealthConfigResult = configs.get(instance.getMemberUUID()).get(); + String values = mpHealthConfigResult.getOutput().split("\n")[1]; + Boolean enabled = Boolean.parseBoolean(values.split(" ")[0]); + if (enabled) { + + String endpoint = values.split(" ", 2)[1].trim(); + + URL usedURL = instance.getApplicationURLS().get(0); + URI remote = new URI(usedURL.getProtocol(), usedURL.getUserInfo(), usedURL.getHost(), usedURL.getPort(), "/" + endpoint, null, null); + + result.add(pingHealthEndpoint(remote)); + + } + } catch (InterruptedException | ExecutionException ex) { + LOGGER.log(Level.FINE, "Error processing MP Healthcheck checker", ex); + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "UNABLE TO CONNECT - " + ex.toString())); + } catch (URISyntaxException ex) { + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "INVALID ENDPOINT: " + ex.getInput())); + } catch (ProcessingException ex) { + LOGGER.log(Level.FINE, "Error sending JAX-RS Request", ex); + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "UNABLE TO CONNECT - " + ex.getMessage())); + } + + }); + + try { + taskResult.get(options.getTimeout(), TimeUnit.MILLISECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException ex) { + LOGGER.log(Level.FINE, "Error processing MP Healthcheck checker", ex); + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "UNABLE TO CONNECT - " + ex.toString())); + } + + } return result; } @Override public HealthCheckTimeoutExecutionOptions constructOptions(MicroProfileHealthCheckerConfiguration c) { - return new HealthCheckTimeoutExecutionOptions(Boolean.valueOf(c.getEnabled()), Long.parseLong(c.getTime()), asTimeUnit(c.getUnit()), + return new HealthCheckTimeoutExecutionOptions(Boolean.valueOf(c.getEnabled()), Long.parseLong(c.getTime()), asTimeUnit(c.getUnit()), Long.parseLong(c.getTimeout())); } @@ -198,4 +239,22 @@ private URI buildURI(Server server, String endpoint) throws URISyntaxException { return new URI(protocol, null, (String) TranslatedConfigView.getTranslatedValue(listener.getAddress()), truePort, "/" + endpoint, null, null); } + //send request to remote healthcheck endpoint to get the status + private HealthCheckResultEntry pingHealthEndpoint(URI remote) { + Client jaxrsClient = ClientBuilder.newClient(); + WebTarget target = jaxrsClient.target(remote); + + Response metricsResponse = target.request().accept(MediaType.APPLICATION_JSON).get(); + switch (metricsResponse.getStatus()) { + case 200: + return new HealthCheckResultEntry(HealthCheckResultStatus.GOOD, "UP"); + case 503: + return new HealthCheckResultEntry(HealthCheckResultStatus.WARNING, "DOWN"); + case 500: + return new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "FAILURE"); + default: + return new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "UNKNOWN RESPONSE"); + } + } + } diff --git a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/SetMicroProfileHealthCheckerConfiguration.java b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/SetMicroProfileHealthCheckerConfiguration.java index 95781f8f9f7..a7034fef3ac 100644 --- a/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/SetMicroProfileHealthCheckerConfiguration.java +++ b/appserver/payara-appserver-modules/healthcheck-checker/src/main/java/fish/payara/healthcheck/mphealth/SetMicroProfileHealthCheckerConfiguration.java @@ -82,7 +82,7 @@ @CommandLock(CommandLock.LockType.NONE) @I18n("healthcheck.mphealthecheck.configure") @ExecuteOn({RuntimeType.DAS}) -@TargetType({CommandTarget.DAS}) +@TargetType({CommandTarget.DAS, CommandTarget.CONFIG}) @RestEndpoints({ @RestEndpoint(configBean = HealthCheckServiceConfiguration.class, opType = RestEndpoint.OpType.POST, From 75a8393a8bbb1eb484aadfc446e0a39cde71cf68 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Mon, 29 Oct 2018 12:37:00 +0000 Subject: [PATCH 11/11] PAYARA-2479 missing version upgrade --- appserver/admingui/war/src/main/webapp/WEB-INF/sun-web.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appserver/admingui/war/src/main/webapp/WEB-INF/sun-web.xml b/appserver/admingui/war/src/main/webapp/WEB-INF/sun-web.xml index 06c4d1beaf3..853e60821ab 100644 --- a/appserver/admingui/war/src/main/webapp/WEB-INF/sun-web.xml +++ b/appserver/admingui/war/src/main/webapp/WEB-INF/sun-web.xml @@ -61,6 +61,6 @@ - +