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