use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.
the class RegistrationSupport method processResourceRef.
/**
* Examine the MBean to see if it is a ResourceRef that should be manifested under this server,
* and if so, register a JSR 77 MBean for it.
*/
public ObjectName processResourceRef(final ResourceRef ref) {
if (ref == null) {
throw new IllegalArgumentException("resource-ref is null");
}
if (!mServer.getName().equals(ref.getParent(Server.class).getName())) {
cdebug("ResourceRef is not a child of server " + getObjectName(mServer));
return null;
}
// find the referenced resource
Resource res = null;
List<Resource> resources = getDomain().getResources().getResources();
for (Resource resource : resources) {
String name = null;
if (resource instanceof BindableResource) {
name = ((BindableResource) resource).getJndiName();
}
if (resource instanceof Named) {
name = ((Named) resource).getName();
}
if (resource instanceof ResourcePool) {
name = ((ResourcePool) resource).getName();
}
if (name != null && name.equals(ref.getRef()))
res = resource;
}
if (res == null) {
throw new IllegalArgumentException("ResourceRef refers to non-existent resource: " + ref);
}
final String configType = Util.getTypeProp(getObjectName(res));
final Class<J2EEManagedObjectImplBase> implClass = CONFIG_RESOURCE_TYPES.get(configType);
if (implClass == null) {
mLogger.fine("Unrecognized resource type for JSR 77 purposes: " + getObjectName(res));
return null;
}
final Class<J2EEManagedObject> intf = (Class) ClassUtil.getFieldValue(implClass, "INTF");
ObjectName mbean77 = null;
try {
final MetadataImpl meta = new MetadataImpl();
meta.setCorrespondingRef(getObjectName(ref));
meta.setCorrespondingConfig(getObjectName(res));
mbean77 = registerJ2EEChild(mJ2EEServer.objectName(), meta, intf, implClass, Util.getNameProp(getObjectName(res)));
synchronized (mConfigRefTo77) {
mConfigRefTo77.put(getObjectName(ref), mbean77);
}
} catch (final Exception e) {
mLogger.log(Level.INFO, AMXEELoggerInfo.cantRegisterMbean, new Object[] { getObjectName(ref), e });
}
// cdebug( "Registered " + child + " for config resource " + amx.objectName() );
return mbean77;
}
use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.
the class CreateJndiResourceTest method testExecuteFailDuplicateResource.
/**
* Test of execute method, of class CreateJndiResource.
* asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
* dupRes
* asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
* dupRes
*/
@Test
public void testExecuteFailDuplicateResource() {
parameters.set("jndilookupname", "sample_jndi");
parameters.set("restype", "queue");
parameters.set("factoryclass", "sampleClass");
parameters.set("jndi_name", "dupRes");
org.glassfish.resources.admin.cli.CreateJndiResource command1 = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
cr.getCommandInvocation("create-jndi-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command1);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isCreated = false;
for (Resource resource : resources.getResources()) {
if (resource instanceof BindableResource) {
BindableResource jr = (BindableResource) resource;
if (jr.getJndiName().equals("dupRes")) {
isCreated = true;
logger.fine("Jndi Resource config bean dupRes is created.");
break;
}
}
}
assertTrue(isCreated);
org.glassfish.resources.admin.cli.CreateJndiResource command2 = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
cr.getCommandInvocation("create-jndi-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
int numDupRes = 0;
for (Resource resource : resources.getResources()) {
if (resource instanceof BindableResource) {
BindableResource jr = (BindableResource) resource;
if (jr.getJndiName().equals("dupRes")) {
numDupRes = numDupRes + 1;
}
}
}
assertEquals(1, numDupRes);
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.
the class DeleteJndiResourceTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
parameters = new ParameterMap();
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
Resource target = null;
for (Resource resource : param.getResources()) {
if (resource instanceof BindableResource) {
BindableResource r = (BindableResource) resource;
if (r.getJndiName().equals("sample_jndi_resource") || r.getJndiName().equals("dupRes")) {
target = resource;
break;
}
}
}
if (target != null) {
param.getResources().remove(target);
}
return null;
}
}, resources);
}
use of com.sun.enterprise.config.serverbeans.BindableResource in project Payara by payara.
the class JdbcConnectionPoolDeployer method handlePoolRecreationForExistingProxies.
private void handlePoolRecreationForExistingProxies(ConnectorConnectionPool connConnPool) {
recreatePool(connConnPool);
Collection<BindableResource> resourcesList;
if (!connConnPool.isApplicationScopedResource()) {
resourcesList = JdbcResourcesUtil.getResourcesOfPool(domain.getResources(), connConnPool.getName());
} else {
PoolInfo poolInfo = connConnPool.getPoolInfo();
Resources resources = ResourcesUtil.createInstance().getResources(poolInfo);
resourcesList = JdbcResourcesUtil.getResourcesOfPool(resources, connConnPool.getName());
}
for (BindableResource bindableResource : resourcesList) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(bindableResource);
ConnectorRegistry.getInstance().updateResourceInfoVersion(resourceInfo);
}
}
Aggregations