Search in sources :

Example 1 with NotificationServiceConfiguration

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

the class BaseGetNotifierConfiguration 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();
    ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
    notifierConfigurationClass = (Class<NC>) genericSuperclass.getActualTypeArguments()[0];
    NotificationServiceConfiguration configuration = config.getExtensionByType(NotificationServiceConfiguration.class);
    NC nc = configuration.getNotifierConfigurationByType(notifierConfigurationClass);
    String message;
    Properties extraProps = new Properties();
    Map<String, Object> configMap = getNotifierConfiguration(nc);
    if (nc == null) {
        message = "Notifier Configuration is not defined";
    } else {
        message = listConfiguration(nc);
    }
    mainActionReport.setMessage(message);
    extraProps.put("notifierConfiguration", configMap);
    mainActionReport.setExtraProperties(extraProps);
    mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) NotificationServiceConfiguration(fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 2 with NotificationServiceConfiguration

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

the class BaseNotificationConfigurer method execute.

@Override
public void execute(final AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    Config configuration = targetUtil.getConfig(target);
    final NotificationServiceConfiguration notificationServiceConfiguration = configuration.getExtensionByType(NotificationServiceConfiguration.class);
    ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
    notifierConfigurationClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
    C c = notificationServiceConfiguration.getNotifierConfigurationByType(notifierConfigurationClass);
    try {
        if (c == null) {
            ConfigSupport.apply(new SingleConfigCode<NotificationServiceConfiguration>() {

                @Override
                public Object run(final NotificationServiceConfiguration notificationServiceConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    C c = notificationServiceConfigurationProxy.createChild(notifierConfigurationClass);
                    applyValues(c);
                    notificationServiceConfigurationProxy.getNotifierConfigurationList().add(c);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    ParameterMap params = new ParameterMap();
                    params.add("enabled", Boolean.TRUE.toString());
                    params.add("dynamic", Boolean.TRUE.toString());
                    params.add("target", target);
                    ActionReport healthCheckSubReport = actionReport.addSubActionsReport();
                    CommandRunner.CommandInvocation healthCheckCommandInvocation = commandRunner.getCommandInvocation(getHealthCheckNotifierCommandName(), healthCheckSubReport, context.getSubject());
                    healthCheckCommandInvocation.parameters(params);
                    healthCheckCommandInvocation.execute();
                    if (healthCheckSubReport.hasFailures()) {
                        logger.log(Level.SEVERE, "Error occurred while configuring notifier with command: " + getHealthCheckNotifierCommandName());
                    }
                    ActionReport requestTracingSubReport = actionReport.addSubActionsReport();
                    CommandRunner.CommandInvocation requestTracingCommandInvocation = commandRunner.getCommandInvocation(getRequestTracingNotifierCommandName(), requestTracingSubReport, context.getSubject());
                    requestTracingCommandInvocation.parameters(params);
                    requestTracingCommandInvocation.execute();
                    if (requestTracingSubReport.hasFailures()) {
                        logger.log(Level.SEVERE, "Error occurred while configuring notifier with command: " + getRequestTracingNotifierCommandName());
                    }
                    return notificationServiceConfigurationProxy;
                }
            }, notificationServiceConfiguration);
        } else {
            ConfigSupport.apply(new SingleConfigCode<C>() {

                public Object run(C cProxy) throws PropertyVetoException, TransactionFailure {
                    applyValues(cProxy);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return cProxy;
                }
            }, c);
        }
        if (dynamic) {
            if (server.isDas()) {
                if (targetUtil.getConfig(target).isDas()) {
                    configureDynamically();
                }
            } else {
                configureDynamically();
            }
        }
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Exception during command ", ex);
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ParameterizedType(java.lang.reflect.ParameterizedType) PropertyVetoException(java.beans.PropertyVetoException) NotificationServiceConfiguration(fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration)

Example 3 with NotificationServiceConfiguration

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

use of fish.payara.nucleus.notification.configuration.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.nucleus.notification.configuration.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)4 NotificationServiceConfiguration (fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration)4 Properties (java.util.Properties)4 ActionReport (org.glassfish.api.ActionReport)4 PropertyVetoException (java.beans.PropertyVetoException)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 NotifierConfiguration (fish.payara.nucleus.notification.configuration.NotifierConfiguration)1 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)1 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)1 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)1 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)1 ConfigView (org.jvnet.hk2.config.ConfigView)1