use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class AppSpecificConnectorClassLoaderUtil method detectResourceInRA.
private void detectResourceInRA(Application app, String moduleName, String jndiName) {
// domain.xml
Resource res = null;
if (jndiName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)) /*|| jndiName.startsWith("java:global/")*/
{
ApplicationInfo appInfo = appRegistry.get(app.getName());
res = getApplicationScopedResource(jndiName, BindableResource.class, appInfo);
} else if (jndiName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX)) {
ApplicationInfo appInfo = appRegistry.get(app.getName());
res = getModuleScopedResource(jndiName, moduleName, BindableResource.class, appInfo);
} else {
res = ConnectorsUtil.getResourceByName(getResources(), BindableResource.class, jndiName);
}
// (and .ear may refer to these resources in DD)
if (res != null) {
if (ConnectorResource.class.isAssignableFrom(res.getClass())) {
ConnectorResource connResource = (ConnectorResource) res;
String poolName = connResource.getPoolName();
Resource pool;
ApplicationInfo appInfo = appRegistry.get(app.getName());
if (jndiName.startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)) /*|| jndiName.startsWith("java:global/")*/
{
pool = getApplicationScopedResource(poolName, ResourcePool.class, appInfo);
} else if (jndiName.startsWith(ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX)) {
pool = getModuleScopedResource(poolName, moduleName, ResourcePool.class, appInfo);
} else {
pool = ConnectorsUtil.getResourceByName(getResources(), ResourcePool.class, poolName);
}
if (ConnectorConnectionPool.class.isAssignableFrom(pool.getClass())) {
String raName = ((ConnectorConnectionPool) pool).getResourceAdapterName();
app.addResourceAdapter(raName);
}
} else if (AdminObjectResource.class.isAssignableFrom(res.getClass())) {
String raName = ((AdminObjectResource) res).getResAdapter();
app.addResourceAdapter(raName);
}
} else {
boolean found = false;
// detect sun-ra.xml
// find all the standalone connector modules
List<com.sun.enterprise.config.serverbeans.Application> applications = getApplications().getApplicationsWithSnifferType(com.sun.enterprise.config.serverbeans.ServerTags.CONNECTOR, true);
Iterator itr = applications.iterator();
while (itr.hasNext()) {
com.sun.enterprise.config.serverbeans.Application application = (com.sun.enterprise.config.serverbeans.Application) itr.next();
String appName = application.getName();
ApplicationInfo appInfo = appRegistry.get(appName);
if (appInfo == null) {
// the app is not deployed on this node
continue;
}
Application dolApp = appInfo.getMetaData(Application.class);
Collection<ConnectorDescriptor> rarDescriptors = dolApp.getBundleDescriptors(ConnectorDescriptor.class);
for (ConnectorDescriptor desc : rarDescriptors) {
SunConnector sunraDesc = desc.getSunDescriptor();
if (sunraDesc != null) {
String sunRAJndiName = (String) sunraDesc.getResourceAdapter().getValue(ResourceAdapter.JNDI_NAME);
if (jndiName.equals(sunRAJndiName)) {
app.addResourceAdapter(desc.getName());
found = true;
break;
}
} else {
// check whether it is default resource in the connector
if (desc.getDefaultResourcesNames().contains(jndiName)) {
app.addResourceAdapter(desc.getName());
found = true;
break;
}
}
}
}
if (!found) {
if (DOLUtils.getDefaultLogger().isLoggable(Level.FINEST)) {
DOLUtils.getDefaultLogger().log(Level.FINEST, "could not find resource by name : " + jndiName);
}
}
}
}
use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class DeleteConnectorResource method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
if (jndiName == null) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.noJndiName", "No JNDI name defined for connector resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// ensure we already have this resource
Resource r = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
if (r == null) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.notfound", "A connector resource named {0} does not exist.", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if ("system-all-req".equals(r.getObjectType())) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.notAllowed", "The {0} resource cannot be deleted as it is required to be configured in the system.", 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.connector.resource.resource-ref.exist", "connector-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.connector.resource.no.resource-ref", "connector-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.connector.resource.multiple.resource-refs", "connector 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 connector-resource
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
ConnectorResource resource = (ConnectorResource) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
return param.getResources().remove(resource);
}
}, domain.getResources()) == null) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.fail", "Connector resource {0} delete failed ", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.fail", "Connector resource {0} delete failed ", jndiName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
report.setMessage(localStrings.getLocalString("delete.connector.resource.success", "Connector resource {0} deleted successfully", jndiName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class ConnectorResourceDeployer method deployResource.
/**
* {@inheritDoc}
*/
public synchronized void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
// deployResource is not synchronized as there is only one caller
// ResourceProxy which is synchronized
ConnectorResource domainResource = (ConnectorResource) resource;
ResourceInfo resourceInfo = new ResourceInfo(domainResource.getJndiName(), applicationName, moduleName);
PoolInfo poolInfo = new PoolInfo(domainResource.getPoolName(), applicationName, moduleName);
createConnectorResource(domainResource, resourceInfo, poolInfo);
}
use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class JMSConnectionFactoryDefinitionDeployer method deployResource.
public void deployResource(Object resource) throws Exception {
final JMSConnectionFactoryDefinitionDescriptor desc = (JMSConnectionFactoryDefinitionDescriptor) resource;
String poolName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), JMSCFDDPOOL);
String resourceName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), desc.getResourceType());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "JMSConnectionFactoryDefinitionDeployer.deployResource() : pool-name [" + poolName + "], " + " resource-name [" + resourceName + "]");
}
ConnectorConnectionPool connectorCp = new MyJMSConnectionFactoryConnectionPool(desc, poolName);
// deploy pool
getDeployer(connectorCp).deployResource(connectorCp);
// deploy resource
ConnectorResource connectorResource = new MyJMSConnectionFactoryResource(poolName, resourceName);
getDeployer(connectorResource).deployResource(connectorResource);
}
use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class ConnectorsRecoveryResourceHandler method loadAllConnectorResources.
/**
* does a lookup of resources so that they are loaded for sure.
*/
private void loadAllConnectorResources() {
try {
Collection<ConnectorResource> connResources = getAllConnectorResources();
InitialContext ic = new InitialContext();
for (ConnectorResource connResource : connResources) {
if (getResourcesUtil().isEnabled(connResource)) {
try {
ic.lookup(connResource.getJndiName());
// } catch (NameNotFoundException ne) {
} catch (NamingException ne) {
// So we need to explicitly load that rar and create the resources
try {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(connResource);
ConnectorConnectionPool connConnectionPool = ResourcesUtil.createInstance().getConnectorConnectionPoolOfResource(resourceInfo);
if (connConnectionPool != null) {
// TODO V3 ideally this should not happen if connector modules (and embedded rars)
// TODO are loaded before recovery
createActiveResourceAdapter(connConnectionPool.getResourceAdapterName());
getConnectorResourceDeployer().deployResource(connResource);
}
} catch (Exception ex) {
_logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", connResource.getJndiName());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, ne.toString(), ne);
}
_logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", connResource.getJndiName());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, ex.toString(), ex);
}
}
} catch (Exception ex) {
_logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", connResource.getJndiName());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, ex.toString(), ex);
}
}
}
}
} catch (NamingException ne) {
_logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", ne.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, ne.toString(), ne);
}
}
}
Aggregations