Search in sources :

Example 1 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter 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 ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class GetSlackNotifierConfiguration method listConfiguration.

@Override
protected String listConfiguration(SlackNotifierConfiguration configuration) {
    String[] headers = { "Enabled", "Token 1", "Token 2", "Token 3" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Object[] values = new Object[4];
    values[0] = configuration.getEnabled();
    values[1] = configuration.getToken1();
    values[2] = configuration.getToken2();
    values[3] = configuration.getToken3();
    columnFormatter.addRow(values);
    return columnFormatter.toString();
}
Also used : ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 3 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class GetSnmpNotifierConfiguration method listConfiguration.

@Override
protected String listConfiguration(SnmpNotifierConfiguration configuration) {
    String[] headers = { "Enabled", "Community", "OID", "Version", "Host", "Port" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Object[] values = new Object[6];
    values[0] = configuration.getEnabled();
    values[1] = configuration.getCommunity();
    values[2] = configuration.getOid();
    values[3] = configuration.getVersion();
    values[4] = configuration.getHost();
    values[5] = configuration.getPort();
    columnFormatter.addRow(values);
    return columnFormatter.toString();
}
Also used : ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 4 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class GetZendeskSupportConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext acc) {
    Config configNode = targetUtil.getConfig(config);
    ZendeskSupportConfiguration zendeskSupportConfiguration = configNode.getExtensionByType(ZendeskSupportConfiguration.class);
    ActionReport actionReport = acc.getActionReport();
    final String[] outputHeaders = { "Enabled", "Email Address" };
    ColumnFormatter columnFormatter = new ColumnFormatter(outputHeaders);
    Object[] outputValues = { zendeskSupportConfiguration.getEnabled(), zendeskSupportConfiguration.getEmailAddress() };
    columnFormatter.addRow(outputValues);
    actionReport.appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropsMap = new HashMap<>();
    extraPropsMap.put("enabled", zendeskSupportConfiguration.getEnabled());
    extraPropsMap.put("emailAddress", zendeskSupportConfiguration.getEmailAddress());
    Properties extraProps = new Properties();
    extraProps.put("zendeskSupportConfiguration", extraPropsMap);
    actionReport.setExtraProperties(extraProps);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ZendeskSupportConfiguration(fish.payara.appserver.zendesk.config.ZendeskSupportConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 5 with ColumnFormatter

use of com.sun.enterprise.util.ColumnFormatter in project Payara by payara.

the class ListLoggers method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    String header_name = localStrings.getLocalString("list.loggers.header.name", "Logger Name");
    String header_subsystem = localStrings.getLocalString("list.loggers.header.subsystem", "Subsystem");
    String header_description = localStrings.getLocalString("list.loggers.header.description", "Logger Description");
    ColumnFormatter colFormatter = new ColumnFormatter(new String[] { header_name, header_subsystem, header_description });
    // An option to specify client locale should be supported. However, it probably
    // should not be specific to this command. For now, localize using the default locale.
    Locale locale = Locale.getDefault();
    try {
        Set<String> loggers = loggerInfoMetadataService.getLoggerNames();
        Set<String> sortedLoggers = new TreeSet<String>(loggers);
        // The following Map & List are used to hold the REST data
        Map<String, String> loggerSubsystems = new TreeMap<String, String>();
        Map<String, String> loggerDescriptions = new TreeMap<String, String>();
        List<String> loggerList = new ArrayList<String>();
        for (String logger : sortedLoggers) {
            String subsystem = loggerInfoMetadataService.getSubsystem(logger);
            String desc = loggerInfoMetadataService.getDescription(logger, locale);
            boolean published = loggerInfoMetadataService.isPublished(logger);
            if (subsystem == null)
                subsystem = UNKNOWN;
            if (desc == null)
                desc = UNKNOWN;
            if (published || listInternalLoggers) {
                colFormatter.addRow(new Object[] { logger, subsystem, desc });
                loggerSubsystems.put(logger, subsystem);
                // Needed for REST xml and JSON output
                loggerDescriptions.put(logger, desc);
                // Needed for REST xml and JSON output
                loggerList.add(logger);
            }
        }
        report.appendMessage(colFormatter.toString());
        report.appendMessage(System.getProperty("line.separator"));
        // Populate the extraProperties data structure for REST...
        Properties restData = new Properties();
        restData.put("loggerSubsystems", loggerSubsystems);
        restData.put("loggerDescriptions", loggerDescriptions);
        restData.put("loggers", loggerList);
        report.setExtraProperties(restData);
    } catch (Exception ex) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ex.printStackTrace(new PrintStream(out));
        report.setMessage(localStrings.getLocalString("list.loggers.failed", "Error listing loggers: {0}", out.toString()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Locale(java.util.Locale) PrintStream(java.io.PrintStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ActionReport(org.glassfish.api.ActionReport) TreeMap(java.util.TreeMap) Properties(java.util.Properties) TreeSet(java.util.TreeSet) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Aggregations

ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)53 Properties (java.util.Properties)24 HashMap (java.util.HashMap)22 ActionReport (org.glassfish.api.ActionReport)22 Config (com.sun.enterprise.config.serverbeans.Config)21 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)8 ArrayList (java.util.ArrayList)7 PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)5 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)3 AMXConfiguration (fish.payara.admin.amx.config.AMXConfiguration)2 MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)2 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)2 BaseHealthCheck (fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck)2 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)2 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)2 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)2 File (java.io.File)2 TaggedJobExecution (com.ibm.jbatch.spi.TaggedJobExecution)1 DomainConfig (com.sun.enterprise.admin.servermgmt.DomainConfig)1 DomainException (com.sun.enterprise.admin.servermgmt.DomainException)1