Search in sources :

Example 6 with HealthCheckServiceConfiguration

use of fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration in project Payara by payara.

the class BaseHealthCheckNotifierConfigurer method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    Config configuration = targetUtil.getConfig(target);
    final HealthCheckServiceConfiguration healthCheckServiceConfiguration = configuration.getExtensionByType(HealthCheckServiceConfiguration.class);
    ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
    notifierClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
    C c = healthCheckServiceConfiguration.getNotifierByType(notifierClass);
    final C[] config = ObjectArrays.newArray(notifierClass, 1);
    try {
        if (c == null) {
            ConfigSupport.apply(new SingleConfigCode<HealthCheckServiceConfiguration>() {

                @Override
                public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    C c = healthCheckServiceConfigurationProxy.createChild(notifierClass);
                    applyValues(c);
                    healthCheckServiceConfigurationProxy.getNotifierList().add(c);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return healthCheckServiceConfigurationProxy;
                }
            }, healthCheckServiceConfiguration);
        } else {
            config[0] = c;
            ConfigSupport.apply(new SingleConfigCode<C>() {

                public Object run(C cProxy) throws PropertyVetoException, TransactionFailure {
                    applyValues(cProxy);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return cProxy;
                }
            }, c);
        }
        if (dynamic) {
            if (server.isDas()) {
                if (targetUtil.getConfig(target).isDas()) {
                    configureDynamically();
                }
            } else {
                configureDynamically();
            }
        }
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) HealthCheckServiceConfiguration(fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ParameterizedType(java.lang.reflect.ParameterizedType) PropertyVetoException(java.beans.PropertyVetoException)

Example 7 with HealthCheckServiceConfiguration

use of fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration in project Payara by payara.

the class StuckThreadsConfigurer method execute.

@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    StuckThreadsHealthCheck service = habitat.getService(StuckThreadsHealthCheck.class);
    final ActionReport actionReport = context.getActionReport();
    if (service == null) {
        actionReport.appendMessage(strings.getLocalString("healthcheck.stuckthreads.configure.status.error", "Stuck Threads Checker Service could not be found"));
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
        StuckThreadsChecker stuckThreadConfiguration = healthCheckServiceConfiguration.getCheckerByType(StuckThreadsChecker.class);
        if (stuckThreadConfiguration == null) {
            ConfigSupport.apply(new SingleConfigCode<HealthCheckServiceConfiguration>() {

                @Override
                public Object run(final HealthCheckServiceConfiguration healthCheckServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    StuckThreadsChecker checkerProxy = healthCheckServiceConfigurationProxy.createChild(StuckThreadsChecker.class);
                    applyValues(checkerProxy);
                    healthCheckServiceConfigurationProxy.getCheckerList().add(checkerProxy);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return healthCheckServiceConfigurationProxy;
                }
            }, healthCheckServiceConfiguration);
        } else {
            ConfigSupport.apply(new SingleConfigCode<StuckThreadsChecker>() {

                @Override
                public Object run(final StuckThreadsChecker hoggingThreadConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    applyValues(hoggingThreadConfigurationProxy);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return hoggingThreadConfigurationProxy;
                }
            }, stuckThreadConfiguration);
        }
        if (dynamic) {
            if (server.isDas()) {
                if (targetUtil.getConfig(target).isDas()) {
                    StuckThreadsChecker checkerByType = healthCheckServiceConfiguration.getCheckerByType(StuckThreadsChecker.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
                StuckThreadsChecker checkerByType = healthCheckServiceConfiguration.getCheckerByType(StuckThreadsChecker.class);
                service.setOptions(service.constructOptions(stuckThreadConfiguration));
                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);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) StuckThreadsChecker(fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker) Config(com.sun.enterprise.config.serverbeans.Config) HealthCheckServiceConfiguration(fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) StuckThreadsHealthCheck(fish.payara.nucleus.healthcheck.stuck.StuckThreadsHealthCheck)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)7 HealthCheckServiceConfiguration (fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration)7 ActionReport (org.glassfish.api.ActionReport)7 PropertyVetoException (java.beans.PropertyVetoException)5 Properties (java.util.Properties)5 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)5 Checker (fish.payara.nucleus.healthcheck.configuration.Checker)2 HoggingThreadsChecker (fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker)2 StuckThreadsChecker (fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker)2 ThresholdDiagnosticsChecker (fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker)2 BaseHealthCheck (fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 BaseThresholdHealthCheck (fish.payara.nucleus.healthcheck.preliminary.BaseThresholdHealthCheck)1 HoggingThreadsHealthCheck (fish.payara.nucleus.healthcheck.preliminary.HoggingThreadsHealthCheck)1 StuckThreadsHealthCheck (fish.payara.nucleus.healthcheck.stuck.StuckThreadsHealthCheck)1 Notifier (fish.payara.nucleus.notification.configuration.Notifier)1 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)1 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 HashMap (java.util.HashMap)1