Search in sources :

Example 1 with BaseThresholdHealthCheck

use of fish.payara.nucleus.healthcheck.preliminary.BaseThresholdHealthCheck in project Payara by payara.

the class HealthCheckServiceThresholdConfigurer method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    final AdminCommandContext theContext = context;
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    final BaseThresholdHealthCheck service = habitat.getService(BaseThresholdHealthCheck.class, serviceName);
    Config config = targetUtil.getConfig(target);
    if (service == null) {
        actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.status.error", "Service with name {0} could not be found.", serviceName));
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
    final ThresholdDiagnosticsChecker checker = healthCheckServiceConfiguration.<ThresholdDiagnosticsChecker>getCheckerByType(service.getCheckerType());
    if (checker == null) {
        actionReport.appendMessage(strings.getLocalString("healthcheck.service.configure.threshold.checker.not.exists", "Health Check Service Checker Configuration with name {0} could not be found.", serviceName));
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        evaluateThresholdProp(actionReport, checker, HealthCheckConstants.THRESHOLD_CRITICAL, thresholdCritical);
        evaluateThresholdProp(actionReport, checker, HealthCheckConstants.THRESHOLD_WARNING, thresholdWarning);
        evaluateThresholdProp(actionReport, checker, HealthCheckConstants.THRESHOLD_GOOD, thresholdGood);
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (dynamic) {
        if (service.getOptions() == null) {
            service.setOptions(service.constructOptions(checker));
        }
        if (server.isDas()) {
            if (targetUtil.getConfig(target).isDas()) {
                configureDynamically(actionReport, service);
                healthCheckService.reboot();
            }
        } else {
            // it implicitly targeted to us as we are not the DAS
            // restart the service
            configureDynamically(actionReport, service);
            healthCheckService.reboot();
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) HealthCheckServiceConfiguration(fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration) ThresholdDiagnosticsChecker(fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) BaseThresholdHealthCheck(fish.payara.nucleus.healthcheck.preliminary.BaseThresholdHealthCheck)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)1 HealthCheckServiceConfiguration (fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration)1 ThresholdDiagnosticsChecker (fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker)1 BaseThresholdHealthCheck (fish.payara.nucleus.healthcheck.preliminary.BaseThresholdHealthCheck)1 Properties (java.util.Properties)1 ActionReport (org.glassfish.api.ActionReport)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1