Search in sources :

Example 96 with PropertyVetoException

use of java.beans.PropertyVetoException 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 97 with PropertyVetoException

use of java.beans.PropertyVetoException in project Payara by payara.

the class DeleteJavaMailResource 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();
    // ensure we already have this resource
    if (!isResourceExists(domain.getResources(), jndiName)) {
        report.setMessage(localStrings.getLocalString("delete.mail.resource.notfound", "A Mail resource named {0} does not exist.", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (environment.isDas()) {
        if ("domain".equals(target)) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                report.setMessage(localStrings.getLocalString("delete.mail.resource.resource-ref.exist", "mail-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        } else {
            if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
                report.setMessage(localStrings.getLocalString("delete.mail.resource.no.resource-ref", "mail-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
                report.setMessage(localStrings.getLocalString("delete.mail.resource.multiple.resource-refs", "mail-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    try {
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete java-mail-resource
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                MailResource resource = (MailResource) ResourceUtil.getBindableResourceByName(domain.getResources(), jndiName);
                return param.getResources().remove(resource);
            }
        }, domain.getResources());
        report.setMessage(localStrings.getLocalString("delete.mail.resource.success", "Mail resource {0} deleted", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.mail.resource.failed", "Unable to delete mail resource {0}", jndiName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport) MailResource(org.glassfish.resources.javamail.config.MailResource)

Example 98 with PropertyVetoException

use of java.beans.PropertyVetoException in project Payara by payara.

the class JavaMailResourceManager method create.

public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
    setAttributes(attributes, target);
    ResourceStatus validationStatus = isValid(resources, true, target);
    if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
        return validationStatus;
    }
    // ensure we don't already have one of this name
    if (ResourceUtil.getBindableResourceByName(resources, jndiName) != null) {
        String msg = localStrings.getLocalString("create.mail.resource.duplicate.1", "A Mail Resource named {0} already exists.", jndiName);
        return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                MailResource newResource = createConfigBean(param, properties);
                param.getResources().add(newResource);
                return newResource;
            }
        }, resources);
        resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
        String msg = localStrings.getLocalString("create.mail.resource.success", "Mail Resource {0} created.", jndiName);
        return new ResourceStatus(ResourceStatus.SUCCESS, msg, true);
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("" + "create.mail.resource.fail", "Unable to create Mail Resource {0}.", jndiName) + " " + tfe.getLocalizedMessage();
        return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources) MailResource(org.glassfish.resources.javamail.config.MailResource)

Example 99 with PropertyVetoException

use of java.beans.PropertyVetoException in project Payara by payara.

the class DeleteJavaMailResourceTest method tearDown.

@After
public void tearDown() throws TransactionFailure {
    ConfigSupport.apply(new SingleConfigCode<Resources>() {

        public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
            Resource target = null;
            for (Resource resource : param.getResources()) {
                if (resource instanceof MailResource) {
                    MailResource r = (MailResource) resource;
                    if (r.getJndiName().equals("mail/MyMailSession")) {
                        target = resource;
                        break;
                    }
                }
            }
            if (target != null) {
                param.getResources().remove(target);
            }
            return null;
        }
    }, resources);
    parameters = new ParameterMap();
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) MailResource(org.glassfish.resources.javamail.config.MailResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) Resources(com.sun.enterprise.config.serverbeans.Resources) MailResource(org.glassfish.resources.javamail.config.MailResource) After(org.junit.After)

Example 100 with PropertyVetoException

use of java.beans.PropertyVetoException in project Payara by payara.

the class CustomResourceManager method create.

public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
    setAttributes(attributes, target);
    ResourceStatus validationStatus = isValid(resources, true, target);
    if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
        return validationStatus;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                return createResource(param, properties);
            }
        }, resources);
        resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("create.custom.resource.fail", "Unable to create custom resource {0}.", jndiName) + " " + tfe.getLocalizedMessage();
        return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
    }
    String msg = localStrings.getLocalString("create.custom.resource.success", "Custom Resource {0} created.", jndiName);
    return new ResourceStatus(ResourceStatus.SUCCESS, msg, true);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources)

Aggregations

PropertyVetoException (java.beans.PropertyVetoException)342 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)118 ActionReport (org.glassfish.api.ActionReport)64 Expression (cbit.vcell.parser.Expression)41 ExpressionException (cbit.vcell.parser.ExpressionException)40 ArrayList (java.util.ArrayList)40 Config (com.sun.enterprise.config.serverbeans.Config)31 ModelException (cbit.vcell.model.ModelException)26 Structure (cbit.vcell.model.Structure)25 Property (org.jvnet.hk2.config.types.Property)25 ModelVetoException (com.sun.jdo.api.persistence.model.ModelVetoException)24 List (java.util.List)24 Model (cbit.vcell.model.Model)22 DataAccessException (org.vcell.util.DataAccessException)19 SpeciesContext (cbit.vcell.model.SpeciesContext)18 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)18 Resources (com.sun.enterprise.config.serverbeans.Resources)18 Element (org.jdom.Element)18 MathException (cbit.vcell.math.MathException)16 IOException (java.io.IOException)16