Search in sources :

Example 1 with JMXMonitoringService

use of fish.payara.jmx.monitoring.JMXMonitoringService in project Payara by payara.

the class SetJMXMonitoringConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        actionReport.setMessage("Cound not find target: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    final JMXMonitoringService jmxMonitoringService = serviceLocator.getService(JMXMonitoringService.class);
    if (jmxMonitoringService == null) {
        actionReport.appendMessage("Could not find a monitoring service.");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    jmxMonitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
    try {
        ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {

            @Override
            public Object run(final MonitoringServiceConfiguration monitoringConfigProxy) throws PropertyVetoException, TransactionFailure {
                updateConfiguration(monitoringConfigProxy);
                updateAttributes(monitoringConfigProxy, actionReport);
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitoringConfigProxy;
            }
        }, jmxMonitoringConfig);
        if (dynamic) {
            enableOnTarget(actionReport, context, enabled);
        }
        // If the JMX Monitoring is enabled, enable Mbeans too as without it you have nothing to monitor
        if (enabled != null && enabled) {
            MonitoringService monitoringService = config.getMonitoringService();
            ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {

                @Override
                public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
                    monitoringServiceProxy.setMbeanEnabled((String.valueOf(enabled)));
                    return monitoringServiceProxy;
                }
            }, monitoringService);
        }
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Falied to excute the command " + "set-jmx-monitoring-configuration: " + ex.getCause().getMessage());
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JMXMonitoringService(fish.payara.jmx.monitoring.JMXMonitoringService) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) JMXMonitoringService(fish.payara.jmx.monitoring.JMXMonitoringService) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)1 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)1 JMXMonitoringService (fish.payara.jmx.monitoring.JMXMonitoringService)1 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)1 PropertyVetoException (java.beans.PropertyVetoException)1 ActionReport (org.glassfish.api.ActionReport)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1