Search in sources :

Example 6 with ExternalJndiResource

use of org.glassfish.resources.config.ExternalJndiResource in project Payara by payara.

the class DeleteJndiResource 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 (!doesResourceExist(domain.getResources(), jndiName)) {
        report.setMessage(localStrings.getLocalString("delete.jndi.resource.notfound", "A jndi 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.jndi.resource.resource-ref.exist", "external-jndi-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.jndi.resource.no.resource-ref", "external-jndi-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.jndi.resource.multiple.resource-refs", "external-jndi-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 external-jndi-resource
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

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

Example 7 with ExternalJndiResource

use of org.glassfish.resources.config.ExternalJndiResource in project Payara by payara.

the class CreateJndiResourceTest method testExecuteSuccess.

/**
 * Test of execute method, of class CreateJndiResource.
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * sample_jndi_resource
 */
@Test
public void testExecuteSuccess() {
    parameters.set("jndilookupname", "sample_jndi");
    parameters.set("restype", "queue");
    parameters.set("factoryclass", "sampleClass");
    parameters.set("jndi_name", "sample_jndi_resource");
    org.glassfish.resources.admin.cli.CreateJndiResource command = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
    cr.getCommandInvocation("create-jndi-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof ExternalJndiResource) {
            ExternalJndiResource r = (ExternalJndiResource) resource;
            if (r.getJndiName().equals("sample_jndi_resource")) {
                assertEquals("queue", r.getResType());
                assertEquals("sample_jndi", r.getJndiLookupName());
                assertEquals("sampleClass", r.getFactoryClass());
                assertEquals("true", r.getEnabled());
                isCreated = true;
                logger.fine("Jndi Resource config bean sample_jndi_resource is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
    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_jndi_resource")) {
                    assertEquals("true", ref.getEnabled());
                    isRefCreated = true;
                    break;
                }
            }
        }
    }
    assertTrue(isRefCreated);
}
Also used : BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 8 with ExternalJndiResource

use of org.glassfish.resources.config.ExternalJndiResource in project Payara by payara.

the class ExternalJndiResourceDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void undeployResource(Object resource) throws Exception {
    ExternalJndiResource jndiRes = (ExternalJndiResource) resource;
    ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(jndiRes);
    deleteResource(jndiRes, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource)

Example 9 with ExternalJndiResource

use of org.glassfish.resources.config.ExternalJndiResource in project Payara by payara.

the class ExternalJndiResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
    ExternalJndiResource jndiRes = (ExternalJndiResource) resource;
    ResourceInfo resourceInfo = new ResourceInfo(jndiRes.getJndiName(), applicationName, moduleName);
    createExternalJndiResource(jndiRes, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource)

Example 10 with ExternalJndiResource

use of org.glassfish.resources.config.ExternalJndiResource in project Payara by payara.

the class ExternalJndiResourceDeployer method deployResource.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void deployResource(Object resource) throws Exception {
    ExternalJndiResource jndiRes = (ExternalJndiResource) resource;
    ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(jndiRes);
    createExternalJndiResource(jndiRes, resourceInfo);
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource)

Aggregations

ExternalJndiResource (org.glassfish.resources.config.ExternalJndiResource)12 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)4 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)2 Resource (com.sun.enterprise.config.serverbeans.Resource)2 ActionReport (org.glassfish.api.ActionReport)2 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)2 Test (org.junit.Test)2 Property (org.jvnet.hk2.config.types.Property)2 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)1 Resources (com.sun.enterprise.config.serverbeans.Resources)1 ResourceProperty (com.sun.enterprise.repository.ResourceProperty)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1