use of org.glassfish.resourcebase.resources.api.ResourceInfo 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);
}
use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class PersistenceHelper method getResourceInfo.
private static ResourceInfo getResourceInfo(DeploymentContext ctx, String dataSourceName) {
ResourceInfo resourceInfo;
if (dataSourceName.startsWith("java:app")) /* || jndiName.startsWith("java:module") // Use of module scoped resources from JPA still needs to be speced out*/
{
String applicationName = ctx.getCommandParameters(OpsParams.class).name();
resourceInfo = new ResourceInfo(dataSourceName, applicationName);
} else {
resourceInfo = new ResourceInfo(dataSourceName);
}
return resourceInfo;
}
use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class ConnectorObjectFactory method getObjectInstance.
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception {
Reference ref = (Reference) obj;
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "ConnectorObjectFactory: " + ref + " Name:" + name);
}
PoolInfo poolInfo = (PoolInfo) ref.get(0).getContent();
String moduleName = (String) ref.get(1).getContent();
ResourceInfo resourceInfo = (ResourceInfo) ref.get(2).getContent();
if (getRuntime().isACCRuntime() || getRuntime().isNonACCRuntime()) {
ConnectorDescriptor connectorDescriptor = null;
String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
Context ic = new InitialContext(env);
connectorDescriptor = (ConnectorDescriptor) ic.lookup(descriptorJNDIName);
try {
getRuntime().createActiveResourceAdapter(connectorDescriptor, moduleName, null);
} catch (ConnectorRuntimeException e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Failed to look up ConnectorDescriptor from JNDI", moduleName);
}
NamingException ne = new NamingException("Failed to look up ConnectorDescriptor from JNDI");
ne.setRootCause(e);
throw ne;
}
}
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (!getRuntime().checkAccessibility(moduleName, loader)) {
String msg = localStrings.getString("cof.no_access_to_embedded_rar", moduleName);
throw new NamingException(msg);
}
Object cf = null;
try {
ManagedConnectionFactory mcf = getRuntime().obtainManagedConnectionFactory(poolInfo, env);
if (mcf == null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Failed to create MCF ", poolInfo);
}
throw new ConnectorRuntimeException("Failed to create MCF");
}
boolean forceNoLazyAssoc = false;
String jndiName = name.toString();
if (jndiName.endsWith(ConnectorConstants.PM_JNDI_SUFFIX)) {
forceNoLazyAssoc = true;
}
String derivedJndiName = ConnectorsUtil.deriveJndiName(jndiName, env);
ConnectionManagerImpl mgr = (ConnectionManagerImpl) getRuntime().obtainConnectionManager(poolInfo, forceNoLazyAssoc, resourceInfo);
mgr.setJndiName(derivedJndiName);
mgr.setRarName(moduleName);
String logicalName = (String) env.get(GlassfishNamingManager.LOGICAL_NAME);
if (logicalName != null) {
mgr.setLogicalName(logicalName);
}
mgr.initialize();
cf = mcf.createConnectionFactory(mgr);
if (cf == null) {
String msg = localStrings.getString("cof.no.resource.adapter");
throw new RuntimeException(new ConfigurationException(msg));
}
if (getRuntime().isServer() || getRuntime().isEmbedded()) {
ConnectorRegistry registry = ConnectorRegistry.getInstance();
if (registry.isTransparentDynamicReconfigPool(poolInfo)) {
Resources resources = getRuntime().getResources(poolInfo);
ResourcePool resourcePool = null;
if (resources != null) {
resourcePool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolInfo.getName());
if (resourcePool != null) {
ResourceDeployer deployer = getRuntime().getResourceDeployer(resourcePool);
if (deployer != null && deployer.supportsDynamicReconfiguration() && ConnectorsUtil.isDynamicReconfigurationEnabled(resourcePool)) {
Object o = env.get(ConnectorConstants.DYNAMIC_RECONFIGURATION_PROXY_CALL);
if (o == null || Boolean.valueOf(o.toString()).equals(false)) {
// TODO use list ? (even in the ResourceDeployer API)
Class[] classes = deployer.getProxyClassesForDynamicReconfiguration();
Class[] proxyClasses = new Class[classes.length + 1];
for (int i = 0; i < classes.length; i++) {
proxyClasses[i] = classes[i];
}
proxyClasses[proxyClasses.length - 1] = DynamicallyReconfigurableResource.class;
cf = getProxyObject(cf, proxyClasses, resourceInfo);
}
}
}
}
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Connection Factory:" + cf);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return cf;
}
use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class ConnectorsRecoveryResourceHandler method loadXAResourcesAndItsConnections.
/**
* {@inheritDoc}
*/
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
// Done so as to initialize connectors-runtime before loading connector-resources. need a better way ?
ConnectorRuntime crt = connectorRuntimeProvider.get();
// ApplicationLoaderService already guarantees that connectors are loaded before any other applications.
// Recovery will not start sooner than transaction is first needed on EE application startup, therefore
// it is safe to continue here without waiting for startupProvider, as that ultimately creates a deadlock
// between ApplicationLoaderService needed a transaction manager, and recovery wainting for applications
// to finish loading.
Collection<ConnectorResource> connectorResources = getAllConnectorResources();
if (connectorResources == null || connectorResources.size() == 0) {
return;
}
List<ConnectorConnectionPool> connPools = new ArrayList<ConnectorConnectionPool>();
for (Resource resource : connectorResources) {
ConnectorResource connResource = (ConnectorResource) resource;
if (getResourcesUtil().isEnabled(connResource)) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(connResource);
ConnectorConnectionPool pool = ResourcesUtil.createInstance().getConnectorConnectionPoolOfResource(resourceInfo);
if (pool != null && ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING.equals(getTransactionSupport(pool))) {
connPools.add(pool);
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("ConnectorsRecoveryResourceHandler loadXAResourcesAndItsConnections :: " + "adding : " + connResource.getPoolName());
}
}
}
}
loadAllConnectorResources();
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Recovering pools : " + connPools.size());
}
for (ConnectorConnectionPool connPool : connPools) {
PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(connPool);
try {
String[] dbUserPassword = getdbUserPasswordOfConnectorConnectionPool(connPool);
if (dbUserPassword == null) {
continue;
}
String dbUser = dbUserPassword[0];
String dbPassword = dbUserPassword[1];
Subject subject = new Subject();
// username [pointbase interprets this as "root"]/password.
if (dbPassword == null) {
dbPassword = "";
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "datasource.xadatasource_nullpassword_error", poolInfo);
}
}
if (dbUser == null) {
dbUser = "";
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "datasource.xadatasource_nulluser_error", poolInfo);
}
}
String rarName = connPool.getResourceAdapterName();
// TODO V3 JMS-RA ??
if (ConnectorAdminServiceUtils.isJMSRA(rarName)) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Performing recovery for JMS RA, poolName " + poolInfo);
}
ManagedConnectionFactory[] mcfs = crt.obtainManagedConnectionFactories(poolInfo);
_logger.log(Level.INFO, "JMS resource recovery has created CFs = " + mcfs.length);
for (int i = 0; i < mcfs.length; i++) {
PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
pc.setManagedConnectionFactory(mcfs[i]);
Principal prin = new ResourcePrincipal(dbUser, dbPassword);
subject.getPrincipals().add(prin);
subject.getPrivateCredentials().add(pc);
ManagedConnection mc = mcfs[i].createManagedConnection(subject, null);
connList.add(mc);
try {
XAResource xares = mc.getXAResource();
if (xares != null) {
xaresList.add(xares);
}
} catch (ResourceException ex) {
// ignored. Not at XA_TRANSACTION level
}
}
} else {
ManagedConnectionFactory mcf = crt.obtainManagedConnectionFactory(poolInfo);
PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
pc.setManagedConnectionFactory(mcf);
Principal prin = new ResourcePrincipal(dbUser, dbPassword);
subject.getPrincipals().add(prin);
subject.getPrivateCredentials().add(pc);
ManagedConnection mc = mcf.createManagedConnection(subject, null);
connList.add(mc);
try {
XAResource xares = mc.getXAResource();
if (xares != null) {
xaresList.add(xares);
}
} catch (ResourceException ex) {
// ignored. Not at XA_TRANSACTION level
}
}
} catch (Exception ex) {
_logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
}
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Total XAResources identified for recovery is " + xaresList.size());
_logger.log(Level.FINE, "Total connections identified for recovery is " + connList.size());
}
}
use of org.glassfish.resourcebase.resources.api.ResourceInfo in project Payara by payara.
the class ActiveResourceAdapterImpl method deleteDefaultConnectorResources.
/**
* Deletes the default connector resources.
*/
protected void deleteDefaultConnectorResources() {
for (ConnectionDefDescriptor aConnectionDefs_ : connectionDefs_) {
String connectionDefName = aConnectionDefs_.getConnectionFactoryIntf();
String resourceJndiName = connectorRuntime_.getDefaultResourceName(moduleName_, connectionDefName);
try {
ResourceInfo resourceInfo = new ResourceInfo(resourceJndiName);
connectorRuntime_.deleteConnectorResource(resourceInfo);
} catch (ConnectorRuntimeException cre) {
_logger.log(Level.WARNING, "rar.undeployment.default_resource_delete_fail", resourceJndiName);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Error while trying to delete the default connector resource", cre);
}
}
}
}
Aggregations