Search in sources :

Example 1 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class BaseRequestTracingNotifierConfigurer 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 RequestTracingServiceConfiguration configuration = config.getExtensionByType(RequestTracingServiceConfiguration.class);
    ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
    notifierClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
    C c = configuration.getNotifierByType(notifierClass);
    try {
        if (c == null) {
            ConfigSupport.apply(new SingleConfigCode<RequestTracingServiceConfiguration>() {

                @Override
                public Object run(final RequestTracingServiceConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure {
                    C c = configurationProxy.createChild(notifierClass);
                    applyValues(c);
                    configurationProxy.getNotifierList().add(c);
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return configurationProxy;
                }
            }, configuration);
        } 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 : ParameterizedType(java.lang.reflect.ParameterizedType) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) RequestTracingServiceConfiguration(fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration)

Example 2 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class HealthCheckConfigurer method enableLogNotifier.

private void enableLogNotifier(AdminCommandContext context) {
    CommandRunner runner = serviceLocator.getService(CommandRunner.class);
    ActionReport subReport = context.getActionReport().addSubActionsReport();
    CommandRunner.CommandInvocation inv = runner.getCommandInvocation("healthcheck-log-notifier-configure", subReport, context.getSubject());
    ParameterMap params = new ParameterMap();
    params.add("dynamic", dynamic.toString());
    params.add("target", target);
    if (notifierEnabled != null) {
        params.add("enabled", notifierEnabled.toString());
    }
    if (notifierEnabled == null && enabled != null) {
        params.add("enabled", enabled.toString());
    }
    inv.parameters(params);
    inv.execute();
    // swallow the offline warning as it is not a problem
    if (subReport.hasWarnings()) {
        subReport.setMessage("");
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport)

Example 3 with ActionReport

use of org.glassfish.api.ActionReport 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 4 with ActionReport

use of org.glassfish.api.ActionReport 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 5 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class TestLogNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    LogNotifierConfiguration logConfig = config.getExtensionByType(LogNotifierConfiguration.class);
    if (useSeparateLogFile == null) {
        useSeparateLogFile = Boolean.parseBoolean(logConfig.getUseSeparateLogFile());
    }
    // prepare log message
    LogNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    LogNotifierConfigurationExecutionOptions options = new LogNotifierConfigurationExecutionOptions();
    options.setUseSeparateLogFile(useSeparateLogFile);
    // set up logger to store result
    LogNotifierService service = new LogNotifierService();
    Logger logger = Logger.getLogger(LogNotifierService.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler(10);
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    service.handleNotification(event);
    logger.setLevel(oldLevel);
    LogRecord message = bqh.poll();
    logger.removeHandler(bqh);
    if (message == null) {
        // something's gone wrong
        Logger.getLogger(TestLogNotifier.class.getCanonicalName()).log(Level.SEVERE, "Failed to send Log message");
        actionReport.setMessage("Failed to send Log message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        ;
        actionReport.setMessage(message.getMessage());
        if (message.getLevel() == Level.FINE) {
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) Config(com.sun.enterprise.config.serverbeans.Config) Level(java.util.logging.Level) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

Aggregations

ActionReport (org.glassfish.api.ActionReport)585 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)108 Properties (java.util.Properties)100 Config (com.sun.enterprise.config.serverbeans.Config)97 ParameterMap (org.glassfish.api.admin.ParameterMap)93 PropertyVetoException (java.beans.PropertyVetoException)88 IOException (java.io.IOException)62 Logger (java.util.logging.Logger)61 ArrayList (java.util.ArrayList)54 HashMap (java.util.HashMap)49 File (java.io.File)47 CommandRunner (org.glassfish.api.admin.CommandRunner)32 Server (com.sun.enterprise.config.serverbeans.Server)30 CommandTarget (org.glassfish.config.support.CommandTarget)30 Target (org.glassfish.internal.api.Target)30 List (java.util.List)27 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)27 Map (java.util.Map)26 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)26 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)23