Search in sources :

Example 21 with Resource

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

the class AppSpecificConnectorClassLoaderUtil method getModuleScopedResource.

private <T> Resource getModuleScopedResource(String name, String moduleName, Class<T> type, ApplicationInfo appInfo) {
    Resource foundRes = null;
    if (appInfo != null) {
        com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
        Resources resources = null;
        if (app != null) {
            Module module = null;
            List<Module> modules = app.getModule();
            for (Module m : modules) {
                if (ConnectorsUtil.getActualModuleName(m.getName()).equals(moduleName)) {
                    module = m;
                    break;
                }
            }
            if (module != null) {
                resources = appInfo.getTransientAppMetaData(module.getName() + "-resources", Resources.class);
            }
        }
        if (resources != null) {
            boolean bindableResource = BindableResource.class.isAssignableFrom(type);
            boolean poolResource = ResourcePool.class.isAssignableFrom(type);
            boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
            boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
            Iterator itr = resources.getResources().iterator();
            while (itr.hasNext()) {
                String resourceName = null;
                Resource res = (Resource) itr.next();
                if (bindableResource && res instanceof BindableResource) {
                    resourceName = ((BindableResource) res).getJndiName();
                } else if (poolResource && res instanceof ResourcePool) {
                    resourceName = ((ResourcePool) res).getName();
                } else if (rac && res instanceof ResourceAdapterConfig) {
                    resourceName = ((ResourceAdapterConfig) res).getName();
                } else if (workSecurityMap && res instanceof WorkSecurityMap) {
                    resourceName = ((WorkSecurityMap) res).getName();
                }
                if (resourceName != null) {
                    if (!(resourceName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
                        resourceName = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + resourceName;
                    }
                    if (!(name.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
                        name = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + name;
                    }
                    if (name.equals(resourceName)) {
                        foundRes = res;
                        break;
                    }
                }
            }
        }
    }
    return foundRes;
}
Also used : AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module)

Example 22 with Resource

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

the class AppSpecificConnectorClassLoaderUtil method getApplicationScopedResource.

private <T> Resource getApplicationScopedResource(String name, Class<T> type, ApplicationInfo appInfo) {
    Resource foundRes = null;
    if (appInfo != null) {
        com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
        Resources resources = null;
        if (app != null) {
            resources = appInfo.getTransientAppMetaData(app.getName() + "-resources", Resources.class);
        }
        if (resources != null) {
            boolean bindableResource = BindableResource.class.isAssignableFrom(type);
            boolean poolResource = ResourcePool.class.isAssignableFrom(type);
            boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
            boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
            Iterator itr = resources.getResources().iterator();
            while (itr.hasNext()) {
                String resourceName = null;
                Resource res = (Resource) itr.next();
                if (bindableResource && res instanceof BindableResource) {
                    resourceName = ((BindableResource) res).getJndiName();
                } else if (poolResource && res instanceof ResourcePool) {
                    resourceName = ((ResourcePool) res).getName();
                } else if (rac && res instanceof ResourceAdapterConfig) {
                    resourceName = ((ResourceAdapterConfig) res).getName();
                } else if (workSecurityMap && res instanceof WorkSecurityMap) {
                    resourceName = ((WorkSecurityMap) res).getName();
                }
                if (resourceName != null) {
                    if (!(resourceName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX))) {
                        resourceName = ConnectorConstants.JAVA_APP_SCOPE_PREFIX + resourceName;
                    }
                    if (!(name.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX))) {
                        name = ConnectorConstants.JAVA_APP_SCOPE_PREFIX + name;
                    }
                    if (name.equals(resourceName)) {
                        foundRes = res;
                        break;
                    }
                }
            }
        }
    }
    return foundRes;
}
Also used : AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 23 with Resource

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

the class ListJdbcResourcesTest method testExecuteSuccessListNoBob.

/**
 * Test of execute method, of class ListJdbcResource.
 * delete-jdbc-resource bob
 * list-jdbc-resources
 */
@Test
public void testExecuteSuccessListNoBob() {
    // Create JDBC Resource bob
    assertTrue(resources != null);
    // Get an instance of the CreateJdbcResource command
    createCommand = habitat.getService(CreateJdbcResource.class);
    assertTrue(createCommand != null);
    parameters.add("connectionpoolid", "DerbyPool");
    parameters.add("DEFAULT", "bob2");
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Delete JDBC Resource bob
    // assertTrue(resources!=null);
    // Get an instance of the CreateJdbcResource command
    deleteCommand = habitat.getService(DeleteJdbcResource.class);
    assertTrue(deleteCommand != null);
    parameters = new ParameterMap();
    parameters.add("DEFAULT", "bob2");
    cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // List JDBC Resources and check if bob is in the list
    // Get an instance of the ListJdbcResources command
    listCommand = habitat.getService(ListJdbcResources.class);
    parameters = new ParameterMap();
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
    List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
    int numResources = 0;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof JdbcResource) {
            numResources = numResources + 1;
        }
    }
    assertEquals(numResources, list.size());
    List<String> listStr = new java.util.ArrayList();
    for (MessagePart mp : list) {
        listStr.add(mp.getMessage());
    }
    assertFalse(listStr.contains("bob2"));
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) MessagePart(org.glassfish.api.ActionReport.MessagePart) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 24 with Resource

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

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

the class ResourceAdapterAdminServiceImpl method reCreateActiveResourceAdapter.

/**
 * The ActiveResourceAdapter object which abstract the rar module is
 * recreated in the connector container/registry. All the pools and
 * resources are killed. But the infrastructure to create the pools and and
 * resources is untouched. Only the actual pool is killed.
 *
 * @param moduleName
 *                     rar module Name.
 * @throws ConnectorRuntimeException
 *                      if recreation fails.
 */
public void reCreateActiveResourceAdapter(String moduleName) throws ConnectorRuntimeException {
    ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
    if (isRarDeployed(moduleName)) {
        if (!ConnectorsUtil.belongsToSystemRA(moduleName)) {
            ConnectorApplication app = _registry.getConnectorApplication(moduleName);
            app.undeployResources();
            stopAndRemoveActiveResourceAdapter(moduleName);
            String moduleDir = ConnectorsUtil.getLocation(moduleName);
            createActiveResourceAdapter(moduleDir, moduleName, app.getClassLoader());
            _registry.getConnectorApplication(moduleName).deployResources();
        } else {
            Collection<Resource> resources = getResourcesUtil().filterConnectorResources(getResourcesUtil().getGlobalResources(), moduleName, true);
            runtime.getGlobalResourceManager().undeployResources(resources);
            stopAndRemoveActiveResourceAdapter(moduleName);
            String moduleDir = ConnectorsUtil.getLocation(moduleName);
            createActiveResourceAdapter(moduleDir, moduleName, runtime.getSystemRARClassLoader(moduleName));
            runtime.getGlobalResourceManager().deployResources(resources);
        }
    }
/*   //No need to deploy the .rar, it may be a case where rar is not deployed yet
        //Also, when the rar is started, RA-Config is anyway used
        else {
            ConnectorApplication app = _registry.getConnectorApplication(moduleName);
            createActiveResourceAdapter(moduleDir, moduleName, app.getClassLoader());
            _registry.getConnectorApplication(moduleName).deployResources();
        }*/
}
Also used : ConnectorApplication(com.sun.enterprise.connectors.module.ConnectorApplication) Resource(com.sun.enterprise.config.serverbeans.Resource) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

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