Search in sources :

Example 1 with GlassFishBatchValidationException

use of org.glassfish.batch.spi.impl.GlassFishBatchValidationException in project Payara by payara.

the class SetBatchRuntimeConfiguration method validateDataSourceLookupName.

public void validateDataSourceLookupName(AdminCommandContext context, String targetName, String dsLookupName) {
    try {
        CommandRunner runner = serviceLocator.getService(CommandRunner.class);
        ActionReport subReport = context.getActionReport().addSubActionsReport();
        CommandRunner.CommandInvocation inv = runner.getCommandInvocation("list-jdbc-resources", subReport, context.getSubject());
        ParameterMap params = new ParameterMap();
        params.add("target", targetName);
        inv.parameters(params);
        inv.execute();
        Properties props = subReport.getExtraProperties();
        if (props != null) {
            if (props.get("jdbcResources") != null) {
                List<HashMap<String, String>> map = (List<HashMap<String, String>>) props.get("jdbcResources");
                for (HashMap<String, String> e : map) {
                    if (e.get("name").equals(dsLookupName)) {
                        return;
                    }
                }
            }
        }
        throw new GlassFishBatchValidationException("No DataSource mapped to " + dsLookupName);
    } catch (Exception ex) {
        throw new GlassFishBatchValidationException("Exception during validation: ", ex);
    }
}
Also used : GlassFishBatchValidationException(org.glassfish.batch.spi.impl.GlassFishBatchValidationException) ActionReport(org.glassfish.api.ActionReport) GlassFishBatchValidationException(org.glassfish.batch.spi.impl.GlassFishBatchValidationException) NamingException(javax.naming.NamingException) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException)

Example 2 with GlassFishBatchValidationException

use of org.glassfish.batch.spi.impl.GlassFishBatchValidationException in project Payara by payara.

the class SetBatchRuntimeConfiguration method validateExecutorServiceLookupName.

public void validateExecutorServiceLookupName(AdminCommandContext context, String targetName, String exeLookupName) {
    if ("concurrent/__defaultManagedExecutorService".equals(exeLookupName)) {
        return;
    }
    try {
        CommandRunner runner = serviceLocator.getService(CommandRunner.class);
        ActionReport subReport = context.getActionReport().addSubActionsReport();
        CommandRunner.CommandInvocation inv = runner.getCommandInvocation("list-managed-executor-services", subReport, context.getSubject());
        ParameterMap params = new ParameterMap();
        params.add("target", targetName);
        inv.parameters(params);
        inv.execute();
        Properties props = subReport.getExtraProperties();
        if (props != null) {
            if (props.get("managedExecutorServices") != null) {
                List<HashMap<String, String>> map = (List<HashMap<String, String>>) props.get("managedExecutorServices");
                for (HashMap<String, String> e : map) {
                    if (e.get("name").equals(exeLookupName)) {
                        return;
                    }
                }
            }
        }
        throw new GlassFishBatchValidationException("No ExecutorService mapped to " + exeLookupName);
    } catch (Exception ex) {
        throw new GlassFishBatchValidationException("Exception during validation: ", ex);
    }
}
Also used : GlassFishBatchValidationException(org.glassfish.batch.spi.impl.GlassFishBatchValidationException) ActionReport(org.glassfish.api.ActionReport) GlassFishBatchValidationException(org.glassfish.batch.spi.impl.GlassFishBatchValidationException) NamingException(javax.naming.NamingException) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException)

Example 3 with GlassFishBatchValidationException

use of org.glassfish.batch.spi.impl.GlassFishBatchValidationException 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

PropertyVetoException (java.beans.PropertyVetoException)3 ActionReport (org.glassfish.api.ActionReport)3 GlassFishBatchValidationException (org.glassfish.batch.spi.impl.GlassFishBatchValidationException)3 SQLException (java.sql.SQLException)2 NamingException (javax.naming.NamingException)2 Config (com.sun.enterprise.config.serverbeans.Config)1 BatchRuntimeConfiguration (org.glassfish.batch.spi.impl.BatchRuntimeConfiguration)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1