Search in sources :

Example 16 with Resource

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

the class DeleteCustomResourceTest method testExecuteSuccessDefaultTarget.

/**
 * Test of execute method, of class DeleteCustomResource.
 * delete-custom-resource sample_custom_resource
 */
@Test
public void testExecuteSuccessDefaultTarget() {
    org.glassfish.resources.admin.cli.CreateCustomResource createCommand = habitat.getService(org.glassfish.resources.admin.cli.CreateCustomResource.class);
    assertTrue(createCommand != null);
    parameters.set("restype", "topic");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("jndi_name", "sample_custom_resource");
    cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    parameters = new ParameterMap();
    org.glassfish.resources.admin.cli.DeleteCustomResource deleteCommand = habitat.getService(org.glassfish.resources.admin.cli.DeleteCustomResource.class);
    assertTrue(deleteCommand != null);
    parameters.set("jndi_name", "sample_custom_resource");
    cr.getCommandInvocation("delete-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    boolean isDeleted = true;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof CustomResource) {
            CustomResource jr = (CustomResource) resource;
            if (jr.getJndiName().equals("sample_custom_resource")) {
                isDeleted = false;
                logger.fine("CustomResource config bean sample_custom_resource is deleted.");
                break;
            }
        }
    }
    assertTrue(isDeleted);
    logger.fine("msg: " + context.getActionReport().getMessage());
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    Servers servers = habitat.getService(Servers.class);
    boolean isRefDeleted = true;
    for (Server server : servers.getServer()) {
        if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            for (ResourceRef ref : server.getResourceRef()) {
                if (ref.getRef().equals("sample_custom_resource")) {
                    isRefDeleted = false;
                    break;
                }
            }
        }
    }
    assertTrue(isRefDeleted);
}
Also used : CustomResource(org.glassfish.resources.config.CustomResource) CustomResource(org.glassfish.resources.config.CustomResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ParameterMap(org.glassfish.api.admin.ParameterMap) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 17 with Resource

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

the class DeleteAdminObject 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();
    if (jndiName == null) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.noJndiName", "No JNDI name defined for administered object."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we already have this resource
    if (!isResourceExists(domain.getResources(), jndiName)) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.notfound", "An administered object named {0} does not exist.", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (environment.isDas()) {
        if (domain.getConfigNamed(target) != null) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                report.setMessage(localStrings.getLocalString("delete.admin.object.resource-ref.exist", "admin-object [ {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.admin.object.no.resource-ref", "admin-object [ {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.admin.object.multiple.resource-refs", "admin-object [ {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 admin-object-resource
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                Resource resource = ConnectorsUtil.getResourceByName(domain.getResources(), AdminObjectResource.class, jndiName);
                return param.getResources().remove(resource);
            }
        }, domain.getResources()) == null) {
            report.setMessage(localStrings.getLocalString("delete.admin.object.fail", "Unable to delete administered object {0}", jndiName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.fail", "Unable to delete administered object {0}", jndiName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage(localStrings.getLocalString("delete.admin.object.success", "Administered object {0} deleted", jndiName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Example 18 with Resource

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

the class CreateCustomResourceTest method testExecuteSuccess.

/**
 * Test of execute method, of class CreateCustomResource.
 * asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
 * sample_custom_resource
 */
@Test
public void testExecuteSuccess() {
    parameters.set("restype", "topic");
    parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
    parameters.set("jndi_name", "sample_custom_resource");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource was created
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof CustomResource) {
            CustomResource r = (CustomResource) resource;
            if (r.getJndiName().equals("sample_custom_resource")) {
                assertEquals("topic", r.getResType());
                assertEquals("javax.naming.spi.ObjectFactory", r.getFactoryClass());
                assertEquals("true", r.getEnabled());
                isCreated = true;
                logger.fine("Custom Resource config bean sample_custom_resource is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
    // Check resource-ref created
    Servers servers = habitat.getService(Servers.class);
    boolean isRefCreated = false;
    for (Server server : servers.getServer()) {
        if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            for (ResourceRef ref : server.getResourceRef()) {
                if (ref.getRef().equals("sample_custom_resource")) {
                    assertEquals("true", ref.getEnabled());
                    isRefCreated = true;
                    break;
                }
            }
        }
    }
    assertTrue(isRefCreated);
}
Also used : CustomResource(org.glassfish.resources.config.CustomResource) CustomResource(org.glassfish.resources.config.CustomResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 19 with Resource

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

the class ListCustomResourcesTest method setUp.

@Before
public void setUp() {
    parameters = new ParameterMap();
    cr = habitat.getService(CommandRunner.class);
    context = new AdminCommandContextImpl(LogDomains.getLogger(ListCustomResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    Resources resources = habitat.<Domain>getService(Domain.class).getResources();
    assertTrue(resources != null);
    for (Resource resource : resources.getResources()) {
        if (resource instanceof org.glassfish.resources.config.CustomResource) {
            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 20 with Resource

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

the class AppSpecificConnectorClassLoaderUtil method detectResourceInRA.

private void detectResourceInRA(Application app, String moduleName, String jndiName) {
    // domain.xml
    Resource res = null;
    if (jndiName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)) /*|| jndiName.startsWith("java:global/")*/
    {
        ApplicationInfo appInfo = appRegistry.get(app.getName());
        res = getApplicationScopedResource(jndiName, BindableResource.class, appInfo);
    } else if (jndiName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX)) {
        ApplicationInfo appInfo = appRegistry.get(app.getName());
        res = getModuleScopedResource(jndiName, moduleName, BindableResource.class, appInfo);
    } else {
        res = ConnectorsUtil.getResourceByName(getResources(), BindableResource.class, jndiName);
    }
    // (and .ear may refer to these resources in DD)
    if (res != null) {
        if (ConnectorResource.class.isAssignableFrom(res.getClass())) {
            ConnectorResource connResource = (ConnectorResource) res;
            String poolName = connResource.getPoolName();
            Resource pool;
            ApplicationInfo appInfo = appRegistry.get(app.getName());
            if (jndiName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)) /*|| jndiName.startsWith("java:global/")*/
            {
                pool = getApplicationScopedResource(poolName, ResourcePool.class, appInfo);
            } else if (jndiName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX)) {
                pool = getModuleScopedResource(poolName, moduleName, ResourcePool.class, appInfo);
            } else {
                pool = ConnectorsUtil.getResourceByName(getResources(), ResourcePool.class, poolName);
            }
            if (ConnectorConnectionPool.class.isAssignableFrom(pool.getClass())) {
                String raName = ((ConnectorConnectionPool) pool).getResourceAdapterName();
                app.addResourceAdapter(raName);
            }
        } else if (AdminObjectResource.class.isAssignableFrom(res.getClass())) {
            String raName = ((AdminObjectResource) res).getResAdapter();
            app.addResourceAdapter(raName);
        }
    } else {
        boolean found = false;
        // detect sun-ra.xml
        // find all the standalone connector modules
        List<com.sun.enterprise.config.serverbeans.Application> applications = getApplications().getApplicationsWithSnifferType(com.sun.enterprise.config.serverbeans.ServerTags.CONNECTOR, true);
        Iterator itr = applications.iterator();
        while (itr.hasNext()) {
            com.sun.enterprise.config.serverbeans.Application application = (com.sun.enterprise.config.serverbeans.Application) itr.next();
            String appName = application.getName();
            ApplicationInfo appInfo = appRegistry.get(appName);
            if (appInfo == null) {
                // the app is not deployed on this node
                continue;
            }
            Application dolApp = appInfo.getMetaData(Application.class);
            Collection<ConnectorDescriptor> rarDescriptors = dolApp.getBundleDescriptors(ConnectorDescriptor.class);
            for (ConnectorDescriptor desc : rarDescriptors) {
                SunConnector sunraDesc = desc.getSunDescriptor();
                if (sunraDesc != null) {
                    String sunRAJndiName = (String) sunraDesc.getResourceAdapter().getValue(ResourceAdapter.JNDI_NAME);
                    if (jndiName.equals(sunRAJndiName)) {
                        app.addResourceAdapter(desc.getName());
                        found = true;
                        break;
                    }
                } else {
                    // check whether it is default resource in the connector
                    if (desc.getDefaultResourcesNames().contains(jndiName)) {
                        app.addResourceAdapter(desc.getName());
                        found = true;
                        break;
                    }
                }
            }
        }
        if (!found) {
            if (DOLUtils.getDefaultLogger().isLoggable(Level.FINEST)) {
                DOLUtils.getDefaultLogger().log(Level.FINEST, "could not find resource by name : " + jndiName);
            }
        }
    }
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) 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) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) Iterator(java.util.Iterator) SunConnector(com.sun.enterprise.deployment.runtime.connector.SunConnector) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Application(com.sun.enterprise.deployment.Application) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

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