Search in sources :

Example 31 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class SetFaultToleranceConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext acc) {
    Config targetConfig = targetUtil.getConfig(target);
    FaultToleranceServiceConfiguration faultToleranceServiceConfiguration = targetConfig.getExtensionByType(FaultToleranceServiceConfiguration.class);
    try {
        ConfigSupport.apply((FaultToleranceServiceConfiguration configProxy) -> {
            if (managedExecutorServiceName != null) {
                configProxy.setManagedExecutorService(managedExecutorServiceName);
            }
            if (managedScheduledExecutorServiceName != null) {
                configProxy.setManagedScheduledExecutorService(managedScheduledExecutorServiceName);
            }
            return null;
        }, faultToleranceServiceConfiguration);
    } catch (TransactionFailure ex) {
        acc.getActionReport().failure(logger, "Failed to update Fault Tolerance configuration", ex);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) FaultToleranceServiceConfiguration(fish.payara.microprofile.faulttolerance.FaultToleranceServiceConfiguration)

Example 32 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class GetMetricsConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext adminCommandContext) {
    Config targetConfig = targetUtil.getConfig(target);
    if (targetConfig == null) {
        adminCommandContext.getActionReport().setMessage("No such config name: " + targetUtil);
        adminCommandContext.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    MetricsServiceConfiguration metricsConfiguration = targetConfig.getExtensionByType(MetricsServiceConfiguration.class);
    ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
    Object[] outputValues = { metricsConfiguration.getEnabled(), metricsConfiguration.getSecure() };
    columnFormatter.addRow(outputValues);
    adminCommandContext.getActionReport().appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("enabled", metricsConfiguration.getEnabled());
    extraPropertiesMap.put("secure", metricsConfiguration.getSecure());
    Properties extraProperties = new Properties();
    extraProperties.put("metricsConfiguration", extraPropertiesMap);
    adminCommandContext.getActionReport().setExtraProperties(extraProperties);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 33 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class GetZendeskSupportConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext acc) {
    Config configNode = targetUtil.getConfig(config);
    ZendeskSupportConfiguration zendeskSupportConfiguration = configNode.getExtensionByType(ZendeskSupportConfiguration.class);
    ActionReport actionReport = acc.getActionReport();
    final String[] outputHeaders = { "Enabled", "Email Address" };
    ColumnFormatter columnFormatter = new ColumnFormatter(outputHeaders);
    Object[] outputValues = { zendeskSupportConfiguration.getEnabled(), zendeskSupportConfiguration.getEmailAddress() };
    columnFormatter.addRow(outputValues);
    actionReport.appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropsMap = new HashMap<>();
    extraPropsMap.put("enabled", zendeskSupportConfiguration.getEnabled());
    extraPropsMap.put("emailAddress", zendeskSupportConfiguration.getEmailAddress());
    Properties extraProps = new Properties();
    extraProps.put("zendeskSupportConfiguration", extraPropsMap);
    actionReport.setExtraProperties(extraProps);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ZendeskSupportConfiguration(fish.payara.appserver.zendesk.config.ZendeskSupportConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 34 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class TestEmailNotifier 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;
    }
    EmailNotifierConfiguration emailConfig = config.getExtensionByType(EmailNotifierConfiguration.class);
    if (jndiName == null) {
        jndiName = emailConfig.getJndiName();
    }
    if (to == null) {
        to = emailConfig.getTo();
    }
    // prepare email
    EmailNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    EmailMessageQueue queue = new EmailMessageQueue();
    queue.addMessage(new EmailMessage(event, event.getSubject(), event.getMessage()));
    EmailNotifierConfigurationExecutionOptions options = new EmailNotifierConfigurationExecutionOptions();
    options.setJndiName(jndiName);
    options.setTo(to);
    Session session;
    try {
        InitialContext initialContext = new InitialContext();
        session = (Session) initialContext.lookup(jndiName);
    } catch (NamingException ex) {
        Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, "Unable to find session" + jndiName);
        context.getActionReport().setMessage("Unable to find session: " + jndiName);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    EmailNotificationRunnable notifierRun = new EmailNotificationRunnable(queue, session, options);
    // set up logger to store result
    Logger logger = Logger.getLogger(EmailNotificationRunnable.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler(10);
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    // send message, this occurs in its own thread
    Thread notifierThread = new Thread(notifierRun, "test-email-notifier-thread");
    notifierThread.start();
    try {
        notifierThread.join();
    } catch (InterruptedException ex) {
        Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        logger.setLevel(oldLevel);
    }
    LogRecord message = bqh.poll();
    logger.removeHandler(bqh);
    if (message == null) {
        // something's gone wrong
        Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, "Failed to send email");
        actionReport.setMessage("Failed to send email message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        if (message.getLevel() == Level.FINE) {
            actionReport.setMessage(message.getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setMessage(message.getMessage() + message.getThrown().getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) InitialContext(javax.naming.InitialContext) BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) NamingException(javax.naming.NamingException) Level(java.util.logging.Level) Session(javax.mail.Session)

Example 35 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class SetBatchRuntimeConfiguration 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);
    }
    if (dataSourceLookupName == null && executorServiceLookupName == null) {
        actionReport.setMessage("Either dataSourceLookupName or executorServiceLookupName must be specified.");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        Config config = targetUtil.getConfig(target);
        BatchRuntimeConfiguration batchRuntimeConfiguration = config.getExtensionByType(BatchRuntimeConfiguration.class);
        if (batchRuntimeConfiguration != null) {
            ConfigSupport.apply(new SingleConfigCode<BatchRuntimeConfiguration>() {

                @Override
                public Object run(final BatchRuntimeConfiguration batchRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    boolean encounteredError = false;
                    int tableprefixlength = 0;
                    int tablesuffixlength = 0;
                    if (dataSourceLookupName != null) {
                        try {
                            validateDataSourceLookupName(context, target, dataSourceLookupName);
                            batchRuntimeConfigurationProxy.setDataSourceLookupName(dataSourceLookupName);
                            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                        } catch (GlassFishBatchValidationException ex) {
                            logger.log(Level.WARNING, ex.getMessage());
                            actionReport.setMessage(dataSourceLookupName + " is not mapped to a DataSource");
                            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
                            throw new GlassFishBatchValidationException(dataSourceLookupName + " is not mapped to a DataSource");
                        }
                    }
                    if (executorServiceLookupName != null && !encounteredError) {
                        try {
                            validateExecutorServiceLookupName(context, target, executorServiceLookupName);
                            batchRuntimeConfigurationProxy.setExecutorServiceLookupName(executorServiceLookupName);
                            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                        } catch (GlassFishBatchValidationException ex) {
                            logger.log(Level.WARNING, ex.getMessage());
                            actionReport.setMessage("No executor service bound to name = " + executorServiceLookupName);
                            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
                            throw new GlassFishBatchValidationException("No executor service bound to name = " + executorServiceLookupName);
                        }
                    }
                    if (schemaName != null && !encounteredError) {
                        batchRuntimeConfigurationProxy.setSchemaName(schemaName);
                        actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    }
                    if (tablePrefix != null && !encounteredError) {
                        tableprefixlength = tablePrefix.length();
                        batchRuntimeConfigurationProxy.setTablePrefix(tablePrefix);
                        actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    }
                    if (tableSuffix != null && !encounteredError) {
                        tablesuffixlength = tableSuffix.length();
                        batchRuntimeConfigurationProxy.setTableSuffix(tableSuffix);
                        actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    }
                    if (targetUtil.isThisDAS() && isOracle(dataSourceLookupName)) {
                        if (tablesuffixlength + tableprefixlength + MAX_TABLE_LENGTH > 30) {
                            actionReport.setMessage("The table name cannot be greater than 30 characters in Oracle, please amend the table prefix or suffix size ");
                            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
                            throw new GlassFishBatchValidationException("The table name cannot be greater than 30 characters in Oracle, please amend the table prefix or suffix size ");
                        }
                    }
                    return null;
                }
            }, batchRuntimeConfiguration);
        }
    } catch (TransactionFailure txfEx) {
        logger.log(Level.WARNING, "Exception during command ", txfEx);
        actionReport.setMessage(txfEx.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) GlassFishBatchValidationException(org.glassfish.batch.spi.impl.GlassFishBatchValidationException) BatchRuntimeConfiguration(org.glassfish.batch.spi.impl.BatchRuntimeConfiguration) ActionReport(org.glassfish.api.ActionReport)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)152 ActionReport (org.glassfish.api.ActionReport)73 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)50 PropertyVetoException (java.beans.PropertyVetoException)34 Target (org.glassfish.internal.api.Target)31 CommandTarget (org.glassfish.config.support.CommandTarget)30 Properties (java.util.Properties)28 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)23 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 HashMap (java.util.HashMap)17 Server (com.sun.enterprise.config.serverbeans.Server)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Logger (java.util.logging.Logger)14 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)13 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Level (java.util.logging.Level)10 LogRecord (java.util.logging.LogRecord)10