Search in sources :

Example 1 with PayaraNotifierConfiguration

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

the class NotificationService method initialize.

@PostConstruct
void initialize() {
    // Get the config if it's not been injected
    if (configuration == null) {
        configuration = serviceLocator.getService(NotificationServiceConfiguration.class);
    }
    // Register an event listener
    if (events != null) {
        events.register(this);
    }
    // Is this service running on an instance?
    final ServerEnvironment env = serviceLocator.getService(ServerEnvironment.class);
    isInstance = env.isInstance();
    // Find and register all notifier services
    final List<ServiceHandle<PayaraNotifier>> notifierHandles = serviceLocator.getAllServiceHandles(PayaraNotifier.class);
    for (ServiceHandle<PayaraNotifier> handle : notifierHandles) {
        NotifierHandler handler;
        final boolean isNotifierConfigurable = handle.getActiveDescriptor().getAdvertisedContracts().contains(PayaraConfiguredNotifier.class.getName());
        if (isNotifierConfigurable) {
            PayaraNotifierConfiguration notifierConfig = getOrCreateNotifierConfiguration(handle);
            handler = new NotifierHandler(handle, notifierConfig);
        } else {
            handler = new NotifierHandler(handle);
        }
        notifiers.add(handler);
    }
}
Also used : PayaraNotifier(fish.payara.internal.notification.PayaraNotifier) NotificationServiceConfiguration(fish.payara.internal.notification.admin.NotificationServiceConfiguration) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) PayaraConfiguredNotifier(fish.payara.internal.notification.PayaraConfiguredNotifier) PayaraNotifierConfiguration(fish.payara.internal.notification.PayaraNotifierConfiguration) PostConstruct(javax.annotation.PostConstruct)

Example 2 with PayaraNotifierConfiguration

use of fish.payara.internal.notification.PayaraNotifierConfiguration 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 3 with PayaraNotifierConfiguration

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

the class NotifierHandler method reconfigure.

protected void reconfigure() {
    // Get the current configuration
    PayaraNotifierConfiguration currentConfig = null;
    if (config != null) {
        currentConfig = PayaraConfiguredNotifier.class.cast(notifier).getConfiguration();
        if (currentConfig == null) {
            currentConfig = config;
        }
    }
    final boolean enabled = config != null && valueOf(config.getEnabled());
    final boolean wasEnabled = config != null && valueOf(currentConfig.getEnabled());
    if (!enabled) {
        if (wasEnabled) {
            // If the notifier isn't enabled but was before
            destroy();
        }
    } else {
        if (wasEnabled) {
            // If the notifier is enabled and was before
            destroy();
            bootstrap();
        } else {
            // If the notifier is enabled and wasn't before
            bootstrap();
        }
    }
}
Also used : PayaraNotifierConfiguration(fish.payara.internal.notification.PayaraNotifierConfiguration)

Aggregations

PayaraNotifierConfiguration (fish.payara.internal.notification.PayaraNotifierConfiguration)3 PayaraConfiguredNotifier (fish.payara.internal.notification.PayaraConfiguredNotifier)2 PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)2 NotificationServiceConfiguration (fish.payara.internal.notification.admin.NotificationServiceConfiguration)2 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)2 Config (com.sun.enterprise.config.serverbeans.Config)1 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 PostConstruct (javax.annotation.PostConstruct)1 ActionReport (org.glassfish.api.ActionReport)1 ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)1