Search in sources :

Example 6 with BindableResource

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

the class RegistrationSupport method processResourceRef.

/**
 *        Examine the MBean to see if it is a ResourceRef that should be manifested under this server,
 *        and if so, register a JSR 77 MBean for it.
 */
public ObjectName processResourceRef(final ResourceRef ref) {
    if (ref == null) {
        throw new IllegalArgumentException("resource-ref is null");
    }
    if (!mServer.getName().equals(ref.getParent(Server.class).getName())) {
        cdebug("ResourceRef is not a child of server " + getObjectName(mServer));
        return null;
    }
    // find the referenced resource
    Resource res = null;
    List<Resource> resources = getDomain().getResources().getResources();
    for (Resource resource : resources) {
        String name = null;
        if (resource instanceof BindableResource) {
            name = ((BindableResource) resource).getJndiName();
        }
        if (resource instanceof Named) {
            name = ((Named) resource).getName();
        }
        if (resource instanceof ResourcePool) {
            name = ((ResourcePool) resource).getName();
        }
        if (name != null && name.equals(ref.getRef()))
            res = resource;
    }
    if (res == null) {
        throw new IllegalArgumentException("ResourceRef refers to non-existent resource: " + ref);
    }
    final String configType = Util.getTypeProp(getObjectName(res));
    final Class<J2EEManagedObjectImplBase> implClass = CONFIG_RESOURCE_TYPES.get(configType);
    if (implClass == null) {
        mLogger.fine("Unrecognized resource type for JSR 77 purposes: " + getObjectName(res));
        return null;
    }
    final Class<J2EEManagedObject> intf = (Class) ClassUtil.getFieldValue(implClass, "INTF");
    ObjectName mbean77 = null;
    try {
        final MetadataImpl meta = new MetadataImpl();
        meta.setCorrespondingRef(getObjectName(ref));
        meta.setCorrespondingConfig(getObjectName(res));
        mbean77 = registerJ2EEChild(mJ2EEServer.objectName(), meta, intf, implClass, Util.getNameProp(getObjectName(res)));
        synchronized (mConfigRefTo77) {
            mConfigRefTo77.put(getObjectName(ref), mbean77);
        }
    } catch (final Exception e) {
        mLogger.log(Level.INFO, AMXEELoggerInfo.cantRegisterMbean, new Object[] { getObjectName(ref), e });
    }
    // cdebug( "Registered " + child + " for  config resource " + amx.objectName() );
    return mbean77;
}
Also used : Named(org.glassfish.api.admin.config.Named) Server(com.sun.enterprise.config.serverbeans.Server) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource)

Example 7 with BindableResource

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

the class CreateJndiResourceTest method testExecuteFailDuplicateResource.

/**
 * Test of execute method, of class CreateJndiResource.
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * dupRes
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * dupRes
 */
@Test
public void testExecuteFailDuplicateResource() {
    parameters.set("jndilookupname", "sample_jndi");
    parameters.set("restype", "queue");
    parameters.set("factoryclass", "sampleClass");
    parameters.set("jndi_name", "dupRes");
    org.glassfish.resources.admin.cli.CreateJndiResource command1 = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
    cr.getCommandInvocation("create-jndi-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 BindableResource) {
            BindableResource jr = (BindableResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                isCreated = true;
                logger.fine("Jndi Resource config bean dupRes is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    org.glassfish.resources.admin.cli.CreateJndiResource command2 = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
    cr.getCommandInvocation("create-jndi-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 BindableResource) {
            BindableResource jr = (BindableResource) resource;
            if (jr.getJndiName().equals("dupRes")) {
                numDupRes = numDupRes + 1;
            }
        }
    }
    assertEquals(1, numDupRes);
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 8 with BindableResource

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

the class DeleteJndiResourceTest method tearDown.

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

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

Example 9 with BindableResource

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

the class JdbcConnectionPoolDeployer method handlePoolRecreationForExistingProxies.

private void handlePoolRecreationForExistingProxies(ConnectorConnectionPool connConnPool) {
    recreatePool(connConnPool);
    Collection<BindableResource> resourcesList;
    if (!connConnPool.isApplicationScopedResource()) {
        resourcesList = JdbcResourcesUtil.getResourcesOfPool(domain.getResources(), connConnPool.getName());
    } else {
        PoolInfo poolInfo = connConnPool.getPoolInfo();
        Resources resources = ResourcesUtil.createInstance().getResources(poolInfo);
        resourcesList = JdbcResourcesUtil.getResourcesOfPool(resources, connConnPool.getName());
    }
    for (BindableResource bindableResource : resourcesList) {
        ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(bindableResource);
        ConnectorRegistry.getInstance().updateResourceInfoVersion(resourceInfo);
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) Resources(com.sun.enterprise.config.serverbeans.Resources)

Aggregations

BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)9 Resource (com.sun.enterprise.config.serverbeans.Resource)6 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)4 Resources (com.sun.enterprise.config.serverbeans.Resources)3 Iterator (java.util.Iterator)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)2 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)2 ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)2 WorkSecurityMap (org.glassfish.connectors.config.WorkSecurityMap)2 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)2 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)2 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)2 Test (org.junit.Test)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 Module (com.sun.enterprise.config.serverbeans.Module)1 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)1 Server (com.sun.enterprise.config.serverbeans.Server)1 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)1 ResourcePool (com.sun.enterprise.resource.pool.ResourcePool)1