Search in sources :

Example 1 with MonitoringServiceConfiguration

use of fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration in project Payara by payara.

the class GetMonitoringConfiguration method execute.

/**
 * Method that is invoked when the asadmin command is performed.
 *  Pretty prints the Monitoring Service Configuration values.
 * @param context
 */
@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config name: " + targetUtil);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    ActionReport actionReport = context.getActionReport();
    ActionReport notifiersReport = actionReport.addSubActionsReport();
    ActionReport attributeReport = actionReport.addSubActionsReport();
    ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
    ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
    MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
    List<ServiceHandle<BaseNotifierService>> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
    actionReport.appendMessage("Monitoring Service Configuration is enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getEnabled())) + "\n");
    actionReport.appendMessage("Monitoring Service Configuration has AMX enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getAmx())) + "\n");
    actionReport.appendMessage("Monitoring Service Configuration log frequency? " + monitoringConfig.getLogFrequency() + " " + monitoringConfig.getLogFrequencyUnit());
    actionReport.appendMessage(StringUtils.EOL);
    Map<String, Object> map = new HashMap<>();
    Properties extraProps = new Properties();
    map.put("enabled", monitoringConfig.getEnabled());
    map.put("amx", monitoringConfig.getAmx());
    map.put("logfrequency", monitoringConfig.getLogFrequency());
    map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
    extraProps.put("jmxmonitoringConfiguration", map);
    List<Map<String, String>> monitoredAttributes = new ArrayList<>();
    for (MonitoredAttribute monitoredBean : monitoringConfig.getMonitoredAttributes()) {
        Object[] values = new Object[3];
        values[0] = monitoredBean.getObjectName();
        values[1] = monitoredBean.getAttributeName();
        values[2] = monitoredBean.getDescription();
        Map<String, String> monitoredAttribute = new HashMap<>();
        monitoredAttribute.put(monitoredBean.getObjectName(), monitoredBean.getAttributeName());
        monitoredAttributes.add(monitoredAttribute);
        attributeColumnFormatter.addRow(values);
    }
    // Cannot change key in line below - required for admingui propertyDescTable.inc
    extraProps.put("monitored-beans", monitoredAttributes);
    actionReport.setExtraProperties(extraProps);
    if (!monitoringConfig.getNotifierList().isEmpty()) {
        List<Class<Notifier>> notifierClassList = Lists.transform(monitoringConfig.getNotifierList(), new Function<Notifier, Class<Notifier>>() {

            @Override
            public Class<Notifier> apply(Notifier input) {
                return resolveNotifierClass(input);
            }
        });
        Properties notifierProps = new Properties();
        for (ServiceHandle<BaseNotifierService> serviceHandle : allNotifierServiceHandles) {
            Notifier notifier = monitoringConfig.getNotifierByType(serviceHandle.getService().getNotifierType());
            if (notifier != null) {
                ConfigView view = ConfigSupport.getImpl(notifier);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                if (notifierClassList.contains(view.<Notifier>getProxyType())) {
                    Object[] values = new Object[2];
                    values[0] = annotation.type();
                    values[1] = notifier.getEnabled();
                    notifiersColumnFormatter.addRow(values);
                    Map<String, Object> mapNotifiers = new HashMap<>(2);
                    mapNotifiers.put("notifierName", values[0]);
                    mapNotifiers.put("notifierEnabled", values[1]);
                    notifierProps.put("notifierList" + annotation.type(), mapNotifiers);
                }
            }
            actionReport.getExtraProperties().putAll(notifierProps);
        }
    }
    notifiersReport.setMessage(notifiersColumnFormatter.toString());
    notifiersReport.appendMessage(StringUtils.EOL);
    attributeReport.setMessage(attributeColumnFormatter.toString());
    attributeReport.appendMessage(StringUtils.EOL);
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : MonitoredAttribute(fish.payara.jmx.monitoring.configuration.MonitoredAttribute) HashMap(java.util.HashMap) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) Notifier(fish.payara.nucleus.notification.configuration.Notifier) NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MonitoringServiceConfiguration

use of fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration in project Payara by payara.

the class BaseMonitoringNotifierConfigurer 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 config = targetUtil.getConfig(target);
    final MonitoringServiceConfiguration configuration = config.getExtensionByType(MonitoringServiceConfiguration.class);
    ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
    notifierClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
    C c = configuration.getNotifierByType(notifierClass);
    try {
        if (c == null) {
            ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {

                @Override
                public Object run(final MonitoringServiceConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure {
                    C c = configurationProxy.createChild(notifierClass);
                    applyValues(c);
                    configurationProxy.getNotifierList().add(c);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return configurationProxy;
                }
            }, configuration);
        } else {
            ConfigSupport.apply(new SingleConfigCode<C>() {

                @Override
                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 : ParameterizedType(java.lang.reflect.ParameterizedType) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 3 with MonitoringServiceConfiguration

use of fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration in project Payara by payara.

the class SetMonitoringConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    final MonitoringService service = serviceLocator.getService(MonitoringService.class);
    if (service == null) {
        actionReport.appendMessage("Could not find a monitoring service.");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    monitoringConfig = 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;
            }
        }, monitoringConfig);
        if (dynamic) {
            enableOnTarget(actionReport, context, enabled);
        }
    } catch (TransactionFailure ex) {
        Logger.getLogger(SetMonitoringConfiguration.class.getName()).log(Level.WARNING, "Exception during command " + "set-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) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) MonitoringService(fish.payara.jmx.monitoring.MonitoringService)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)3 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)3 ActionReport (org.glassfish.api.ActionReport)3 PropertyVetoException (java.beans.PropertyVetoException)2 Properties (java.util.Properties)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 MonitoringService (fish.payara.jmx.monitoring.MonitoringService)1 MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)1 ConfigView (org.jvnet.hk2.config.ConfigView)1