Search in sources :

Example 31 with Resources

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

the class ConcurrentModificationsTest method collectionTest.

@Test(expected = TransactionFailure.class)
public void collectionTest() throws TransactionFailure {
    ServiceLocator habitat = super.getHabitat();
    final Resources resources = habitat.<Domain>getService(Domain.class).getResources();
    assertTrue(resources != null);
    ConfigSupport.apply(new SingleConfigCode<Resources>() {

        public Object run(Resources writeableResources) throws PropertyVetoException, TransactionFailure {
            assertTrue(writeableResources != null);
            JdbcResource newResource = writeableResources.createChild(JdbcResource.class);
            newResource.setJndiName("foo");
            newResource.setDescription("Random ");
            newResource.setPoolName("bar");
            newResource.setEnabled("true");
            writeableResources.getResources().add(newResource);
            // now let's check I have my copy...
            boolean found = false;
            for (Resource resource : writeableResources.getResources()) {
                if (resource instanceof JdbcResource) {
                    JdbcResource jdbc = (JdbcResource) resource;
                    if (jdbc.getJndiName().equals("foo")) {
                        found = true;
                        break;
                    }
                }
            }
            assertTrue(found);
            // now let's check that my readonly copy does not see it...
            boolean shouldNot = false;
            for (Resource resource : resources.getResources()) {
                if (resource instanceof JdbcResource) {
                    JdbcResource jdbc = (JdbcResource) resource;
                    if (jdbc.getJndiName().equals("foo")) {
                        shouldNot = true;
                        break;
                    }
                }
            }
            assertFalse(shouldNot);
            // now I am throwing a transaction failure since I don't care about saving it
            throw new TransactionFailure("Test passed", null);
        }
    }, resources);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Resources(com.sun.enterprise.config.serverbeans.Resources) Domain(com.sun.enterprise.config.serverbeans.Domain) Test(org.junit.Test)

Example 32 with Resources

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

the class ManagedConnectionImpl method getJdbcConnectionPool.

private JdbcConnectionPool getJdbcConnectionPool(javax.resource.spi.ManagedConnectionFactory mcf) {
    if (Globals.getDefaultHabitat().getService(ProcessEnvironment.class).getProcessType() != ProcessEnvironment.ProcessType.Server) {
        // otherwise we bave no domain to draw upon
        return null;
    }
    JdbcConnectionPool jdbcConnectionPool = null;
    ManagedConnectionFactoryImpl spiMCF = (ManagedConnectionFactoryImpl) mcf;
    Resources resources = Globals.getDefaultHabitat().getService(Domain.class).getResources();
    ResourcePool pool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, spiMCF.getPoolName());
    if (pool instanceof JdbcConnectionPool) {
        jdbcConnectionPool = (JdbcConnectionPool) pool;
    }
    return jdbcConnectionPool;
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) Resources(com.sun.enterprise.config.serverbeans.Resources) Domain(com.sun.enterprise.config.serverbeans.Domain)

Example 33 with Resources

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

the class JdbcResourceDeployer method checkAndDeletePool.

/**
 * Checks if no more resource-refs to resources exists for the
 * JDBC connection pool and then deletes the pool
 *
 * @param cr Jdbc Resource Config bean
 * @throws Exception if unable to access configuration/undeploy resource.
 * @since 8.1 pe/se/ee
 */
private void checkAndDeletePool(JdbcResource cr) throws Exception {
    String poolName = cr.getPoolName();
    ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(cr);
    PoolInfo poolInfo = new PoolInfo(poolName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
    Resources resources = (Resources) cr.getParent();
    // Its possible that the JdbcResource here is a DataSourceDefinition. Ignore optimization.
    if (resources != null) {
        try {
            boolean poolReferred = JdbcResourcesUtil.createInstance().isJdbcPoolReferredInServerInstance(poolInfo);
            if (!poolReferred) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.fine("Deleting JDBC pool [" + poolName + " ] as there are no more " + "resource-refs to the pool in this server instance");
                }
                JdbcConnectionPool jcp = (JdbcConnectionPool) ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, poolName);
                // Delete/Undeploy Pool
                runtime.getResourceDeployer(jcp).undeployResource(jcp);
            }
        } catch (Exception ce) {
            _logger.warning(ce.getMessage());
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("Exception while deleting pool [ " + poolName + " ] : " + ce);
            }
            throw ce;
        }
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) Resources(com.sun.enterprise.config.serverbeans.Resources) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException)

Example 34 with Resources

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

the class ListJndiResourcesTest method setUp.

@Before
public void setUp() {
    habitat = getHabitat();
    cr = habitat.getService(CommandRunner.class);
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListJndiResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    parameters = new ParameterMap();
    Resources resources = habitat.<Domain>getService(Domain.class).getResources();
    for (Resource resource : resources.getResources()) {
        if (resource instanceof org.glassfish.resources.config.ExternalJndiResource) {
            origNum = origNum + 1;
        }
    }
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) Resources(com.sun.enterprise.config.serverbeans.Resources) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) Domain(com.sun.enterprise.config.serverbeans.Domain) CommandRunner(org.glassfish.api.admin.CommandRunner) Before(org.junit.Before)

Example 35 with Resources

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

the class DeleteCustomResource 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 (domain.getResources().getResourceByName(CustomResource.class, jndiName) == null) {
        report.setMessage(localStrings.getLocalString("delete.custom.resource.notfound", "A custom 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.custom.resource.resource-ref.exist", "custom-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.custom.resource.no.resource-ref", "custom-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.custom.resource.multiple.resource-refs", "custom-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 custom-resource
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                CustomResource resource = (CustomResource) domain.getResources().getResourceByName(CustomResource.class, jndiName);
                if (resource != null && resource.getJndiName().equals(jndiName)) {
                    return param.getResources().remove(resource);
                }
                return null;
            }
        }, domain.getResources());
        report.setMessage(localStrings.getLocalString("delete.custom.resource.success", "Custom resource {0} deleted", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.custom.resource.fail", "Unable to delete custom 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) CustomResource(org.glassfish.resources.config.CustomResource) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Aggregations

Resources (com.sun.enterprise.config.serverbeans.Resources)41 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)25 PropertyVetoException (java.beans.PropertyVetoException)18 Resource (com.sun.enterprise.config.serverbeans.Resource)14 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)14 Domain (com.sun.enterprise.config.serverbeans.Domain)7 ActionReport (org.glassfish.api.ActionReport)7 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)7 JdbcResource (org.glassfish.jdbc.config.JdbcResource)6 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)5 ParameterMap (org.glassfish.api.admin.ParameterMap)4 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)4 ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)4 JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)4 MailResource (org.glassfish.resources.javamail.config.MailResource)4 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)3 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)3 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)3 CommandRunner (org.glassfish.api.admin.CommandRunner)3 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)3