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;
}
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;
}
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);
}
}
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());
}
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);
}
Aggregations