Search in sources :

Example 31 with Resource

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

the class ManagedThreadFactoryManager method delete.

public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
    if (jndiName == null) {
        String msg = localStrings.getLocalString("managed.thread.factory.noJndiName", "No JNDI name defined for managed thread factory.");
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    Resource resource = ConnectorsUtil.getResourceByName(resources, ManagedThreadFactory.class, jndiName);
    // ensure we already have this resource
    if (resource == null) {
        String msg = localStrings.getLocalString("delete.managed.thread.factory.notfound", "A managed thread factory named {0} does not exist.", jndiName);
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    if (SYSTEM_ALL_REQ.equals(resource.getObjectType())) {
        String msg = localStrings.getLocalString("delete.concurrent.resource.notAllowed", "The {0} resource cannot be deleted as it is required to be configured in the system.", jndiName);
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    if (environment.isDas()) {
        if ("domain".equals(target)) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                String msg = localStrings.getLocalString("delete.managed.thread.factory.resource-ref.exist", "This managed thread factory [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        } else {
            if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
                String msg = localStrings.getLocalString("delete.managed.thread.factory.no.resource-ref", "This managed thread factory [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
                String msg = localStrings.getLocalString("delete.managed.thread.factory.multiple.resource-refs", "This managed thread factory [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        }
    }
    try {
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete managed-thread-factory
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ManagedThreadFactory resource = (ManagedThreadFactory) ConnectorsUtil.getResourceByName(resources, ManagedThreadFactory.class, jndiName);
                return param.getResources().remove(resource);
            }
        }, resources) == null) {
            String msg = localStrings.getLocalString("delete.managed.thread.factory.failed", "Managed thread factory {0} deletion failed", jndiName);
            return new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("delete.managed.thread.factory.failed", "Managed thread factory {0} deletion failed ", jndiName);
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("delete.managed.thread.factory.success", "Managed thread factory {0} deleted successfully", jndiName);
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources) ManagedThreadFactory(org.glassfish.concurrent.config.ManagedThreadFactory)

Example 32 with Resource

use of com.sun.enterprise.config.serverbeans.Resource 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 33 with Resource

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

the class ResourcesDeployer method deployResources.

public void deployResources(String applicationName, String moduleName, Collection<com.sun.enterprise.config.serverbeans.Resource> resources, boolean postDeployPhase) throws Exception {
    for (Resource resource : resources) {
        if (resource instanceof BindableResource) {
            BindableResource bindableResource = (BindableResource) resource;
            ResourceInfo resourceInfo = new ResourceInfo(bindableResource.getJndiName(), applicationName, moduleName);
            if (getResourceDeployer(bindableResource).canDeploy(postDeployPhase, resources, bindableResource)) {
                resourcesBinder.deployResource(resourceInfo, bindableResource);
            }
        } else {
            if (getResourceDeployer(resource).canDeploy(postDeployPhase, resources, resource)) {
                getResourceDeployer(resource).deployResource(resource, applicationName, moduleName);
            }
        }
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) Resource(com.sun.enterprise.config.serverbeans.Resource) Resource(org.glassfish.resources.api.Resource)

Example 34 with Resource

use of com.sun.enterprise.config.serverbeans.Resource 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 Resource

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

the class CreateJavaMailResourceTest method testExecuteFailDuplicateResource.

/**
 * Test of execute method, of class CreateJavaMailResource.
 * asadmin create-javamail-resource --mailuser=test --mailhost=localhost
 * --fromaddress=test@sun.com dupRes
 * asadmin create-javamail-resource --mailuser=test --mailhost=localhost
 * --fromaddress=test@sun.com dupRes
 */
@Test
public void testExecuteFailDuplicateResource() {
    parameters.set("mailhost", "localhost");
    parameters.set("mailuser", "test");
    parameters.set("fromaddress", "test@sun.com");
    parameters.set("jndi_name", "dupRes");
    org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command1 = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
    assertTrue(command1 != null);
    cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command1);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof MailResource) {
            MailResource jr = (MailResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                isCreated = true;
                logger.fine("MailResource config bean dupRes is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command2 = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
    cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
    assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
    int numDupRes = 0;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof MailResource) {
            MailResource jr = (MailResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                numDupRes = numDupRes + 1;
            }
        }
    }
    assertEquals(1, numDupRes);
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : MailResource(org.glassfish.resources.javamail.config.MailResource) Resource(com.sun.enterprise.config.serverbeans.Resource) MailResource(org.glassfish.resources.javamail.config.MailResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Aggregations

Resource (com.sun.enterprise.config.serverbeans.Resource)44 Resources (com.sun.enterprise.config.serverbeans.Resources)14 Test (org.junit.Test)14 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)13 ParameterMap (org.glassfish.api.admin.ParameterMap)10 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)9 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 Domain (com.sun.enterprise.config.serverbeans.Domain)6 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)6 JdbcResource (org.glassfish.jdbc.config.JdbcResource)6 MailResource (org.glassfish.resources.javamail.config.MailResource)6 ResourceException (javax.resource.ResourceException)5 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)5 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)5 Resource (org.glassfish.resources.api.Resource)5 CustomResource (org.glassfish.resources.config.CustomResource)5 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)5 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)4 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)4 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)4