Search in sources :

Example 1 with BaseNotifierService

use of fish.payara.nucleus.notification.service.BaseNotifierService 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 BaseNotifierService

use of fish.payara.nucleus.notification.service.BaseNotifierService in project Payara by payara.

the class GetNotificationConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    ActionReport mainActionReport = context.getActionReport();
    final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class);
    NotificationServiceConfiguration configuration = config.getExtensionByType(NotificationServiceConfiguration.class);
    List<ServiceHandle<BaseNotifierService>> allServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
    String[] headers = { "Enabled", "Notifier Enabled" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    if (configuration.getNotifierConfigurationList().isEmpty()) {
        mainActionReport.setMessage("No notifier defined");
    } else {
        List<Class<NotifierConfiguration>> notifierConfigurationClassList = Lists.transform(configuration.getNotifierConfigurationList(), new Function<NotifierConfiguration, Class<NotifierConfiguration>>() {

            @Override
            public Class<NotifierConfiguration> apply(NotifierConfiguration input) {
                return resolveNotifierConfigurationClass(input);
            }
        });
        Properties extraProps = new Properties();
        for (ServiceHandle<BaseNotifierService> serviceHandle : allServiceHandles) {
            NotifierConfiguration notifierConfiguration = configuration.getNotifierConfigurationByType(serviceHandle.getService().getNotifierConfigType());
            if (notifierConfiguration != null) {
                ConfigView view = ConfigSupport.getImpl(notifierConfiguration);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                if (notifierConfigurationClassList.contains(view.<NotifierConfiguration>getProxyType())) {
                    Object[] values = new Object[2];
                    values[0] = notificationServiceConfiguration.getEnabled();
                    values[1] = notifierConfiguration.getEnabled();
                    columnFormatter.addRow(values);
                    Map<String, Object> map;
                    if (NotifierType.LOG.equals(annotation.type())) {
                        map = new HashMap<>(3);
                        map.put("enabled", values[0]);
                        map.put("notifierEnabled", values[1]);
                        LogNotifierConfiguration logNotifierConfiguration = (LogNotifierConfiguration) notifierConfiguration;
                        map.put("useSeparateLogFile", logNotifierConfiguration.getUseSeparateLogFile());
                    } else {
                        map = new HashMap<>(2);
                        map.put("enabled", values[0]);
                        map.put("notifierEnabled", values[1]);
                    }
                    extraProps.put("getNotificationConfiguration" + annotation.type(), map);
                }
            }
        }
        mainActionReport.setExtraProperties(extraProps);
        mainActionReport.setMessage(columnFormatter.toString());
    }
    mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) NotifierConfiguration(fish.payara.nucleus.notification.configuration.NotifierConfiguration) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) NotificationServiceConfiguration(fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)2 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)2 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)2 Properties (java.util.Properties)2 ActionReport (org.glassfish.api.ActionReport)2 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)2 ConfigView (org.jvnet.hk2.config.ConfigView)2 MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)1 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)1 NotificationServiceConfiguration (fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration)1 Notifier (fish.payara.nucleus.notification.configuration.Notifier)1 NotifierConfiguration (fish.payara.nucleus.notification.configuration.NotifierConfiguration)1 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1