Search in sources :

Example 1 with LogNotifierConfiguration

use of fish.payara.nucleus.notification.log.LogNotifierConfiguration in project Payara by payara.

the class GetNotificationConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    // Get the command report
    final ActionReport report = context.getActionReport();
    // Get the target configuration
    final Config targetConfig = targetUtil.getConfig(target);
    if (targetConfig == null) {
        report.setMessage("No such config named: " + target);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    final NotificationServiceConfiguration configuration = targetConfig.getExtensionByType(NotificationServiceConfiguration.class);
    final String notificationServiceEnabled = configuration.getEnabled();
    final List<ServiceHandle<PayaraNotifier>> notifierHandles = habitat.getAllServiceHandles(PayaraNotifier.class);
    if (notifierHandles.isEmpty()) {
        report.setMessage("No notifiers defined");
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
        return;
    }
    String[] headers = { "Notifier Name", "Enabled", "Notifier Enabled", "Notifier Noisy" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    Properties extraProps = new Properties();
    for (ServiceHandle<PayaraNotifier> serviceHandle : notifierHandles) {
        final Class<?> notifierClass = serviceHandle.getActiveDescriptor().getImplementationClass();
        Object[] values = new Object[4];
        values[0] = getNotifierName(serviceHandle.getActiveDescriptor());
        values[1] = notificationServiceEnabled;
        // Get the notifier config if applicable
        PayaraNotifierConfiguration notifierConfig = null;
        if (serviceHandle.getService() instanceof PayaraConfiguredNotifier) {
            // Get the associated configuration
            notifierConfig = configuration.getNotifierConfigurationByType(NotifierUtils.getConfigurationClass(notifierClass));
        }
        if (notifierConfig == null) {
            values[2] = PayaraNotifierConfiguration.DEFAULT_ENABLED_VALUE;
            values[3] = PayaraNotifierConfiguration.DEFAULT_NOISY_VALUE;
        } else {
            values[2] = notifierConfig.getEnabled();
            values[3] = notifierConfig.getNoisy();
        }
        columnFormatter.addRow(values);
        Map<String, Object> map = new HashMap<>(3);
        map.put("enabled", values[1]);
        map.put("notifierEnabled", values[2]);
        map.put("noisy", values[3]);
        if (notifierConfig != null && notifierConfig instanceof LogNotifierConfiguration) {
            map.put("useSeparateLogFile", ((LogNotifierConfiguration) notifierConfig).getUseSeparateLogFile());
        }
        extraProps.put("getNotificationConfiguration" + notifierClass.getSimpleName(), map);
    }
    report.setMessage(columnFormatter.toString());
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    report.setExtraProperties(extraProps);
}
Also used : PayaraNotifier(fish.payara.internal.notification.PayaraNotifier) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) PayaraConfiguredNotifier(fish.payara.internal.notification.PayaraConfiguredNotifier) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) NotificationServiceConfiguration(fish.payara.internal.notification.admin.NotificationServiceConfiguration) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) PayaraNotifierConfiguration(fish.payara.internal.notification.PayaraNotifierConfiguration) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 2 with LogNotifierConfiguration

use of fish.payara.nucleus.notification.log.LogNotifierConfiguration 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)

Example 3 with LogNotifierConfiguration

use of fish.payara.nucleus.notification.log.LogNotifierConfiguration in project Payara by payara.

the class LogNotifierConfigurationExecutionOptionsFactoryMock method notifierConfigurationExecutionOptionBuildsSuccessfullyForLog.

@Test
public void notifierConfigurationExecutionOptionBuildsSuccessfullyForLog() {
    LogNotifierConfiguration logNotifierConfiguration = mock(LogNotifierConfiguration.class);
    when(logNotifierConfiguration.getEnabled()).thenReturn("true");
    LogNotifierConfigurationExecutionOptions executionOptions = factory.build(logNotifierConfiguration);
    assertThat(executionOptions.getNotifierType(), is(NotifierType.LOG));
    assertThat(executionOptions.isEnabled(), is(true));
}
Also used : LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) LogNotifierConfigurationExecutionOptions(fish.payara.nucleus.notification.log.LogNotifierConfigurationExecutionOptions) Test(org.junit.Test)

Aggregations

LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)3 Config (com.sun.enterprise.config.serverbeans.Config)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)2 Properties (java.util.Properties)2 ActionReport (org.glassfish.api.ActionReport)2 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)2 PayaraConfiguredNotifier (fish.payara.internal.notification.PayaraConfiguredNotifier)1 PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)1 PayaraNotifierConfiguration (fish.payara.internal.notification.PayaraNotifierConfiguration)1 NotificationServiceConfiguration (fish.payara.internal.notification.admin.NotificationServiceConfiguration)1 NotificationServiceConfiguration (fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration)1 NotifierConfiguration (fish.payara.nucleus.notification.configuration.NotifierConfiguration)1 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)1 LogNotifierConfigurationExecutionOptions (fish.payara.nucleus.notification.log.LogNotifierConfigurationExecutionOptions)1 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ConfigView (org.jvnet.hk2.config.ConfigView)1