Search in sources :

Example 1 with ExternalJndiResource

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

the class JndiResourceManager method createResource.

private Object createResource(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
    ExternalJndiResource newResource = createConfigBean(param, properties);
    param.getResources().add(newResource);
    return newResource;
}
Also used : ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource)

Example 2 with ExternalJndiResource

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

the class JndiResourceManager method createConfigBean.

private ExternalJndiResource createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
    ExternalJndiResource newResource = param.createChild(ExternalJndiResource.class);
    newResource.setJndiName(jndiName);
    newResource.setFactoryClass(factoryClass);
    newResource.setJndiLookupName(jndiLookupName);
    newResource.setResType(resType);
    newResource.setEnabled(enabled);
    if (description != null) {
        newResource.setDescription(description);
    }
    if (properties != null) {
        for (Map.Entry e : properties.entrySet()) {
            Property prop = newResource.createChild(Property.class);
            prop.setName((String) e.getKey());
            prop.setValue((String) e.getValue());
            newResource.getProperty().add(prop);
        }
    }
    return newResource;
}
Also used : ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) HashMap(java.util.HashMap) Map(java.util.Map) Property(org.jvnet.hk2.config.types.Property)

Example 3 with ExternalJndiResource

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

the class ListJndiResources 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();
    try {
        List<String> list = new ArrayList<String>();
        Collection<ExternalJndiResource> jndiResources = domain.getResources().getResources(ExternalJndiResource.class);
        for (ExternalJndiResource jndiResource : jndiResources) {
            if (bindableResourcesHelper.resourceExists(jndiResource.getJndiName(), targetOperand)) {
                list.add(jndiResource.getJndiName());
            }
        }
        for (String jndiName : list) {
            final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
            part.setMessage(jndiName);
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("" + "list.jndi.resources.fail", "Unable to list jndi resources.") + " " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource)

Example 4 with ExternalJndiResource

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

the class CreateJndiResourceTest method testExecuteWithOptionalValuesSet.

/**
 * Test of execute method, of class CreateJndiResource.
 * asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
 * --enabled=false --description=External JNDI Resource
 * sample_jndi_resource
 */
@Test
public void testExecuteWithOptionalValuesSet() {
    parameters.set("jndilookupname", "sample_jndi");
    parameters.set("restype", "queue");
    parameters.set("factoryclass", "sampleClass");
    parameters.set("enabled", "false");
    parameters.set("description", "External JNDI Resource");
    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("sampleClass", r.getFactoryClass());
                assertEquals("sample_jndi", r.getJndiLookupName());
                // expect enabled for the resource to be true as resource-ref's enabled
                // would be set to false
                assertEquals("true", r.getEnabled());
                assertEquals("External JNDI Resource", r.getDescription());
                isCreated = true;
                logger.fine("Jndi Resource config bean sample_jndi_resource is created.");
                break;
            }
        }
    }
    assertTrue(isCreated);
    /*
        ResourceRef ref = server.getResourceRef("sample_jndi_resource");
        assertTrue(ref != null);
        assertEquals("false", ref.getEnabled());
*/
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Resource(com.sun.enterprise.config.serverbeans.Resource) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 5 with ExternalJndiResource

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

the class ExternalJndiResourceDeployer method undeployResource.

/**
 * {@inheritDoc}
 */
@Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
    ExternalJndiResource jndiRes = (ExternalJndiResource) resource;
    ResourceInfo resourceInfo = new ResourceInfo(jndiRes.getJndiName(), applicationName, moduleName);
    deleteResource(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