use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class AppSpecificConnectorClassLoaderUtil method getModuleScopedResource.
private <T> Resource getModuleScopedResource(String name, String moduleName, Class<T> type, ApplicationInfo appInfo) {
Resource foundRes = null;
if (appInfo != null) {
com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
Resources resources = null;
if (app != null) {
Module module = null;
List<Module> modules = app.getModule();
for (Module m : modules) {
if (ConnectorsUtil.getActualModuleName(m.getName()).equals(moduleName)) {
module = m;
break;
}
}
if (module != null) {
resources = appInfo.getTransientAppMetaData(module.getName() + "-resources", Resources.class);
}
}
if (resources != null) {
boolean bindableResource = BindableResource.class.isAssignableFrom(type);
boolean poolResource = ResourcePool.class.isAssignableFrom(type);
boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
Iterator itr = resources.getResources().iterator();
while (itr.hasNext()) {
String resourceName = null;
Resource res = (Resource) itr.next();
if (bindableResource && res instanceof BindableResource) {
resourceName = ((BindableResource) res).getJndiName();
} else if (poolResource && res instanceof ResourcePool) {
resourceName = ((ResourcePool) res).getName();
} else if (rac && res instanceof ResourceAdapterConfig) {
resourceName = ((ResourceAdapterConfig) res).getName();
} else if (workSecurityMap && res instanceof WorkSecurityMap) {
resourceName = ((WorkSecurityMap) res).getName();
}
if (resourceName != null) {
if (!(resourceName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
resourceName = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + resourceName;
}
if (!(name.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX))) {
name = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX + name;
}
if (name.equals(resourceName)) {
foundRes = res;
break;
}
}
}
}
}
return foundRes;
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class AppSpecificConnectorClassLoaderUtil method getApplicationScopedResource.
private <T> Resource getApplicationScopedResource(String name, Class<T> type, ApplicationInfo appInfo) {
Resource foundRes = null;
if (appInfo != null) {
com.sun.enterprise.config.serverbeans.Application app = appInfo.getTransientAppMetaData(com.sun.enterprise.config.serverbeans.ServerTags.APPLICATION, com.sun.enterprise.config.serverbeans.Application.class);
Resources resources = null;
if (app != null) {
resources = appInfo.getTransientAppMetaData(app.getName() + "-resources", Resources.class);
}
if (resources != null) {
boolean bindableResource = BindableResource.class.isAssignableFrom(type);
boolean poolResource = ResourcePool.class.isAssignableFrom(type);
boolean workSecurityMap = WorkSecurityMap.class.isAssignableFrom(type);
boolean rac = ResourceAdapterConfig.class.isAssignableFrom(type);
Iterator itr = resources.getResources().iterator();
while (itr.hasNext()) {
String resourceName = null;
Resource res = (Resource) itr.next();
if (bindableResource && res instanceof BindableResource) {
resourceName = ((BindableResource) res).getJndiName();
} else if (poolResource && res instanceof ResourcePool) {
resourceName = ((ResourcePool) res).getName();
} else if (rac && res instanceof ResourceAdapterConfig) {
resourceName = ((ResourceAdapterConfig) res).getName();
} else if (workSecurityMap && res instanceof WorkSecurityMap) {
resourceName = ((WorkSecurityMap) res).getName();
}
if (resourceName != null) {
if (!(resourceName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX))) {
resourceName = ConnectorConstants.JAVA_APP_SCOPE_PREFIX + resourceName;
}
if (!(name.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX))) {
name = ConnectorConstants.JAVA_APP_SCOPE_PREFIX + name;
}
if (name.equals(resourceName)) {
foundRes = res;
break;
}
}
}
}
}
return foundRes;
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ListJdbcResourcesTest method testExecuteSuccessListNoBob.
/**
* Test of execute method, of class ListJdbcResource.
* delete-jdbc-resource bob
* list-jdbc-resources
*/
@Test
public void testExecuteSuccessListNoBob() {
// Create JDBC Resource bob
assertTrue(resources != null);
// Get an instance of the CreateJdbcResource command
createCommand = habitat.getService(CreateJdbcResource.class);
assertTrue(createCommand != null);
parameters.add("connectionpoolid", "DerbyPool");
parameters.add("DEFAULT", "bob2");
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Delete JDBC Resource bob
// assertTrue(resources!=null);
// Get an instance of the CreateJdbcResource command
deleteCommand = habitat.getService(DeleteJdbcResource.class);
assertTrue(deleteCommand != null);
parameters = new ParameterMap();
parameters.add("DEFAULT", "bob2");
cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// List JDBC Resources and check if bob is in the list
// Get an instance of the ListJdbcResources command
listCommand = habitat.getService(ListJdbcResources.class);
parameters = new ParameterMap();
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
int numResources = 0;
for (Resource resource : resources.getResources()) {
if (resource instanceof JdbcResource) {
numResources = numResources + 1;
}
}
assertEquals(numResources, list.size());
List<String> listStr = new java.util.ArrayList();
for (MessagePart mp : list) {
listStr.add(mp.getMessage());
}
assertFalse(listStr.contains("bob2"));
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
use of com.sun.enterprise.config.serverbeans.Resource 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.Resource in project Payara by payara.
the class ResourceAdapterAdminServiceImpl method reCreateActiveResourceAdapter.
/**
* The ActiveResourceAdapter object which abstract the rar module is
* recreated in the connector container/registry. All the pools and
* resources are killed. But the infrastructure to create the pools and and
* resources is untouched. Only the actual pool is killed.
*
* @param moduleName
* rar module Name.
* @throws ConnectorRuntimeException
* if recreation fails.
*/
public void reCreateActiveResourceAdapter(String moduleName) throws ConnectorRuntimeException {
ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
if (isRarDeployed(moduleName)) {
if (!ConnectorsUtil.belongsToSystemRA(moduleName)) {
ConnectorApplication app = _registry.getConnectorApplication(moduleName);
app.undeployResources();
stopAndRemoveActiveResourceAdapter(moduleName);
String moduleDir = ConnectorsUtil.getLocation(moduleName);
createActiveResourceAdapter(moduleDir, moduleName, app.getClassLoader());
_registry.getConnectorApplication(moduleName).deployResources();
} else {
Collection<Resource> resources = getResourcesUtil().filterConnectorResources(getResourcesUtil().getGlobalResources(), moduleName, true);
runtime.getGlobalResourceManager().undeployResources(resources);
stopAndRemoveActiveResourceAdapter(moduleName);
String moduleDir = ConnectorsUtil.getLocation(moduleName);
createActiveResourceAdapter(moduleDir, moduleName, runtime.getSystemRARClassLoader(moduleName));
runtime.getGlobalResourceManager().deployResources(resources);
}
}
/* //No need to deploy the .rar, it may be a case where rar is not deployed yet
//Also, when the rar is started, RA-Config is anyway used
else {
ConnectorApplication app = _registry.getConnectorApplication(moduleName);
createActiveResourceAdapter(moduleDir, moduleName, app.getClassLoader());
_registry.getConnectorApplication(moduleName).deployResources();
}*/
}
Aggregations