Search in sources :

Example 6 with PayaraNotifier

use of fish.payara.internal.notification.PayaraNotifier in project Payara by payara.

the class GetJMXMonitoringConfiguration 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 jmxMonitoringReport = actionReport.addSubActionsReport();
    ActionReport notifiersReport = actionReport.addSubActionsReport();
    ActionReport attributeReport = actionReport.addSubActionsReport();
    ColumnFormatter jmxMonitoringColumnFormatter = new ColumnFormatter(JMX_MONITORING_HEADERS);
    ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
    ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
    MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
    List<ServiceHandle<PayaraNotifier>> allNotifierServiceHandles = habitat.getAllServiceHandles(PayaraNotifier.class);
    jmxMonitoringColumnFormatter.addRow(new Object[] { monitoringConfig.getEnabled(), monitoringConfig.getLogFrequency(), monitoringConfig.getLogFrequencyUnit() });
    Map<String, Object> map = new HashMap<>();
    map.put("enabled", monitoringConfig.getEnabled());
    map.put("logfrequency", monitoringConfig.getLogFrequency());
    map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
    Properties extraProps = new Properties();
    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<String> notifiers = monitoringConfig.getNotifierList();
        Properties notifierProps = new Properties();
        for (ServiceHandle<PayaraNotifier> serviceHandle : allNotifierServiceHandles) {
            final String notifierClassName = serviceHandle.getActiveDescriptor().getImplementationClass().getSimpleName();
            final String notifierName = NotifierUtils.getNotifierName(serviceHandle.getActiveDescriptor());
            Object[] values = new Object[2];
            values[0] = notifierName;
            values[1] = notifiers.contains(notifierName);
            notifiersColumnFormatter.addRow(values);
            Map<String, Object> mapNotifiers = new HashMap<>(2);
            mapNotifiers.put("notifierName", values[0]);
            mapNotifiers.put("notifierEnabled", values[1]);
            notifierProps.put("notifierList" + notifierClassName, mapNotifiers);
        }
        actionReport.getExtraProperties().putAll(notifierProps);
    }
    jmxMonitoringReport.setMessage(jmxMonitoringColumnFormatter.toString());
    jmxMonitoringReport.appendMessage(StringUtils.EOL);
    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) PayaraNotifier(fish.payara.internal.notification.PayaraNotifier) HashMap(java.util.HashMap) 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) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) HashMap(java.util.HashMap) Map(java.util.Map) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Aggregations

PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)6 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)6 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 ActionReport (org.glassfish.api.ActionReport)5 Config (com.sun.enterprise.config.serverbeans.Config)4 PayaraConfiguredNotifier (fish.payara.internal.notification.PayaraConfiguredNotifier)2 PayaraNotifierConfiguration (fish.payara.internal.notification.PayaraNotifierConfiguration)2 NotificationServiceConfiguration (fish.payara.internal.notification.admin.NotificationServiceConfiguration)2 AdminAuditConfiguration (fish.payara.audit.AdminAuditConfiguration)1 MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)1 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)1 Checker (fish.payara.nucleus.healthcheck.configuration.Checker)1 HealthCheckServiceConfiguration (fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration)1 HoggingThreadsChecker (fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker)1 MicroProfileHealthCheckerConfiguration (fish.payara.nucleus.healthcheck.configuration.MicroProfileHealthCheckerConfiguration)1 MicroProfileMetricsChecker (fish.payara.nucleus.healthcheck.configuration.MicroProfileMetricsChecker)1 MonitoredMetric (fish.payara.nucleus.healthcheck.configuration.MonitoredMetric)1 StuckThreadsChecker (fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker)1