Search in sources :

Example 6 with NotifierConfigurationType

use of fish.payara.nucleus.notification.configuration.NotifierConfigurationType in project Payara by payara.

the class RequestTracingService method bootstrapNotifierList.

/**
 * Configures notifiers with request tracing and starts any enabled ones.
 * If no options are set then the log notifier is automatically turned on.
 * @since 4.1.2.173
 */
public void bootstrapNotifierList() {
    executionOptions.resetNotifierExecutionOptions();
    if (configuration.getNotifierList() != null) {
        for (Notifier notifier : configuration.getNotifierList()) {
            ConfigView view = ConfigSupport.getImpl(notifier);
            NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
            executionOptions.addNotifierExecutionOption(executionOptionsFactoryStore.get(annotation.type()).build(notifier));
        }
    }
    if (executionOptions.getNotifierExecutionOptionsList().isEmpty()) {
        // Add logging execution options by default
        LogNotifierExecutionOptions logNotifierExecutionOptions = new LogNotifierExecutionOptions();
        logNotifierExecutionOptions.setEnabled(true);
        executionOptions.addNotifierExecutionOption(logNotifierExecutionOptions);
    }
}
Also used : NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) LogNotifier(fish.payara.nucleus.notification.log.LogNotifier) Notifier(fish.payara.nucleus.notification.configuration.Notifier) LogNotifierExecutionOptions(fish.payara.nucleus.notification.log.LogNotifierExecutionOptions)

Example 7 with NotifierConfigurationType

use of fish.payara.nucleus.notification.configuration.NotifierConfigurationType in project Payara by payara.

the class NotificationService method bootstrapNotificationService.

public void bootstrapNotificationService() {
    if (configuration != null) {
        executionOptions = new NotificationExecutionOptions();
        executionOptions.setEnabled(Boolean.parseBoolean(configuration.getEnabled()));
        for (NotifierConfiguration notifierConfiguration : configuration.getNotifierConfigurationList()) {
            NotifierType type = null;
            try {
                ConfigView view = ConfigSupport.getImpl(notifierConfiguration);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                type = annotation.type();
                executionOptions.addNotifierConfigurationExecutionOption(factoryStore.get(type).build(notifierConfiguration));
            } catch (UnsupportedEncodingException e) {
                logger.log(Level.SEVERE, "Notifier configuration with type " + type + " cannot be configured due to encoding problems in configuration parameters", e);
            }
        }
        if (executionOptions.isEnabled()) {
            logger.info("Payara Notification Service bootstrapped with configuration: " + executionOptions);
        }
    }
}
Also used : NotifierType(fish.payara.nucleus.notification.configuration.NotifierType) NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotifierConfiguration(fish.payara.nucleus.notification.configuration.NotifierConfiguration) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) NotificationExecutionOptions(fish.payara.nucleus.notification.domain.NotificationExecutionOptions)

Example 8 with NotifierConfigurationType

use of fish.payara.nucleus.notification.configuration.NotifierConfigurationType 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

NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)8 Notifier (fish.payara.nucleus.notification.configuration.Notifier)6 ConfigView (org.jvnet.hk2.config.ConfigView)5 Config (com.sun.enterprise.config.serverbeans.Config)4 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)4 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)4 Properties (java.util.Properties)4 ActionReport (org.glassfish.api.ActionReport)4 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)4 LogNotifierExecutionOptions (fish.payara.nucleus.notification.log.LogNotifierExecutionOptions)3 HashMap (java.util.HashMap)3 NotifierConfiguration (fish.payara.nucleus.notification.configuration.NotifierConfiguration)2 LogNotifier (fish.payara.nucleus.notification.log.LogNotifier)2 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)2 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 StuckThreadsChecker (fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker)1