Search in sources :

Example 1 with NotificationServiceConfiguration

use of fish.payara.internal.notification.admin.NotificationServiceConfiguration 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 NotificationServiceConfiguration

use of fish.payara.internal.notification.admin.NotificationServiceConfiguration in project Payara by payara.

the class NotificationConfigurer method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    Config config = targetUtil.getConfig(target);
    final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class);
    if (notificationServiceConfiguration != null) {
        try {
            ConfigSupport.apply(new SingleConfigCode<NotificationServiceConfiguration>() {

                @Override
                public Object run(final NotificationServiceConfiguration notificationServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    if (enabled != null) {
                        notificationServiceConfigurationProxy.enabled(enabled.toString());
                    }
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return notificationServiceConfigurationProxy;
                }
            }, notificationServiceConfiguration);
        } catch (TransactionFailure ex) {
            logger.log(Level.WARNING, "Exception during command ", ex);
            actionReport.setMessage(ex.getCause().getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (dynamic) {
        if (server.isDas()) {
            if (targetUtil.getConfig(target).isDas()) {
                service.bootstrapNotificationService();
            }
        } else {
            // apply as not the DAS so implicitly it is for us
            service.bootstrapNotificationService();
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NotificationServiceConfiguration(fish.payara.internal.notification.admin.NotificationServiceConfiguration) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)2 NotificationServiceConfiguration (fish.payara.internal.notification.admin.NotificationServiceConfiguration)2 Properties (java.util.Properties)2 ActionReport (org.glassfish.api.ActionReport)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 PayaraConfiguredNotifier (fish.payara.internal.notification.PayaraConfiguredNotifier)1 PayaraNotifier (fish.payara.internal.notification.PayaraNotifier)1 PayaraNotifierConfiguration (fish.payara.internal.notification.PayaraNotifierConfiguration)1 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)1 PropertyVetoException (java.beans.PropertyVetoException)1 HashMap (java.util.HashMap)1 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1