Search in sources :

Example 76 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode 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)

Example 77 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class CreateJMSHost method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Config targetConfig = domain.getConfigNamed(target);
    if (targetConfig != null)
        config = targetConfig;
    Server targetServer = domain.getServerNamed(target);
    // String configRef = targetServer.getConfigRef();
    if (targetServer != null) {
        config = domain.getConfigNamed(targetServer.getConfigRef());
    }
    com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
    if (cluster != null) {
        config = domain.getConfigNamed(cluster.getConfigRef());
    }
    if (jmsHostName == null) {
        report.setMessage(localStrings.getLocalString("create.jms.host.noJmsHost", "No JMS Host name specified."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    JmsService jmsservice = config.getExtensionByType(JmsService.class);
    // ensure we don't already have one of this name before creating it.
    for (JmsHost jmsHost : jmsservice.getJmsHost()) {
        if (jmsHostName.equals(jmsHost.getName())) {
            if (force) {
                ActionReport deleteReport = report.addSubActionsReport();
                ParameterMap parameters = new ParameterMap();
                parameters.set("DEFAULT", jmsHostName);
                parameters.set("target", target);
                commandRunner.getCommandInvocation("delete-jms-host", deleteReport, context.getSubject()).parameters(parameters).execute();
                if (ActionReport.ExitCode.FAILURE.equals(deleteReport.getActionExitCode())) {
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    return;
                }
                break;
            } else {
                report.setMessage(localStrings.getLocalString("create.jms.host.duplicate", "A JMS Host named {0} already exists.", jmsHostName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<JmsService>() {

            public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
                // TODO: need a way to create a JmsHost instance
                JmsHost jmsHost = param.createChild(JmsHost.class);
                jmsHost.setAdminPassword(mqpassword);
                jmsHost.setAdminUserName(mquser);
                jmsHost.setName(jmsHostName);
                jmsHost.setHost(mqhost);
                jmsHost.setPort(mqport);
                if (props != null) {
                    for (Map.Entry e : props.entrySet()) {
                        Property prop = jmsHost.createChild(Property.class);
                        prop.setName((String) e.getKey());
                        prop.setValue((String) e.getValue());
                        jmsHost.getProperty().add(prop);
                    }
                }
                param.getJmsHost().add(jmsHost);
                return jmsHost;
            }
        }, jmsservice);
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("create.jms.host.fail", "Unable to create jms host {0}.", jmsHostName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage(localStrings.getLocalString("create.jms.host.success", "Jms Host {0} created.", jmsHostName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) com.sun.enterprise.config.serverbeans(com.sun.enterprise.config.serverbeans) PropertyVetoException(java.beans.PropertyVetoException) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) Property(org.jvnet.hk2.config.types.Property)

Example 78 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class PersistenceManagerFactoryResourceMigrator method postConstruct.

public void postConstruct() {
    Collection<PersistenceManagerFactoryResource> pmfResources = resources.getResources(PersistenceManagerFactoryResource.class);
    for (final PersistenceManagerFactoryResource pmfResource : pmfResources) {
        String jdbcResourceName = pmfResource.getJdbcResourceJndiName();
        final JdbcResource jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jdbcResourceName);
        try {
            ConfigSupport.apply(new SingleConfigCode<Resources>() {

                public Object run(Resources resources) throws PropertyVetoException, TransactionFailure {
                    // delete the persitence-manager-factory resource
                    resources.getResources().remove(pmfResource);
                    // create a jdbc resource which points to same connection pool and has same jndi name as pmf resource.
                    JdbcResource newResource = resources.createChild(JdbcResource.class);
                    newResource.setJndiName(pmfResource.getJndiName());
                    newResource.setDescription("Created to migrate persistence-manager-factory-resource from V2 domain");
                    newResource.setPoolName(jdbcResource.getPoolName());
                    newResource.setEnabled("true");
                    resources.getResources().add(newResource);
                    return newResource;
                }
            }, resources);
        } catch (TransactionFailure tf) {
            Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading persistence-manager-factory-resource", tf);
            throw new RuntimeException(tf);
        }
    }
// end of iteration
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) PersistenceManagerFactoryResource(org.glassfish.connectors.config.PersistenceManagerFactoryResource) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 79 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class SetMonitoringConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    final MonitoringService service = serviceLocator.getService(MonitoringService.class);
    if (service == null) {
        actionReport.appendMessage("Could not find a monitoring service.");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
    try {
        ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {

            @Override
            public Object run(final MonitoringServiceConfiguration monitoringConfigProxy) throws PropertyVetoException, TransactionFailure {
                updateConfiguration(monitoringConfigProxy);
                updateAttributes(monitoringConfigProxy, actionReport);
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitoringConfigProxy;
            }
        }, monitoringConfig);
        if (dynamic) {
            enableOnTarget(actionReport, context, enabled);
        }
    } catch (TransactionFailure ex) {
        Logger.getLogger(SetMonitoringConfiguration.class.getName()).log(Level.WARNING, "Exception during command " + "set-monitoring-configuration: " + ex.getCause().getMessage());
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) MonitoringService(fish.payara.jmx.monitoring.MonitoringService)

Example 80 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class SetZendeskSupportConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext acc) {
    Config config = targetUtil.getConfig(target);
    ActionReport actionReport = acc.getActionReport();
    ZendeskSupportConfiguration zendeskSupportConfiguration = config.getExtensionByType(ZendeskSupportConfiguration.class);
    if (zendeskSupportConfiguration != null) {
        try {
            ConfigSupport.apply(new SingleConfigCode<ZendeskSupportConfiguration>() {

                @Override
                public Object run(ZendeskSupportConfiguration config) {
                    if (enabled != null) {
                        config.setEnabled(Boolean.toString(enabled));
                    }
                    if (!Strings.isNullOrEmpty(emailAddress)) {
                        config.setEmailAddress(emailAddress);
                    }
                    return null;
                }
            }, zendeskSupportConfiguration);
        } catch (TransactionFailure ex) {
            // Set failure
            actionReport.failure(Logger.getLogger(SetZendeskSupportConfigurationCommand.class.getName()), "Failed to update configuration", ex);
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) ZendeskSupportConfiguration(fish.payara.appserver.zendesk.config.ZendeskSupportConfiguration)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)153 PropertyVetoException (java.beans.PropertyVetoException)130 ActionReport (org.glassfish.api.ActionReport)76 Config (com.sun.enterprise.config.serverbeans.Config)47 Property (org.jvnet.hk2.config.types.Property)27 Resources (com.sun.enterprise.config.serverbeans.Resources)25 List (java.util.List)23 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)19 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 CommandTarget (org.glassfish.config.support.CommandTarget)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Target (org.glassfish.internal.api.Target)15 Test (org.junit.Test)15 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)13 ArrayList (java.util.ArrayList)11 Protocols (org.glassfish.grizzly.config.dom.Protocols)11 Resource (com.sun.enterprise.config.serverbeans.Resource)9 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)9 Properties (java.util.Properties)9