use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class ListJMSResources 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
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
ArrayList<Map<String, String>> list = new ArrayList<>();
Properties extraProperties = new Properties();
Collection adminObjectResourceList = domain.getResources().getResources(AdminObjectResource.class);
Collection connectorResourcesList = domain.getResources().getResources(ConnectorResource.class);
Object[] connectorResources = connectorResourcesList.toArray();
Object[] adminObjectResources = adminObjectResourceList.toArray();
if (resourceType == null) {
try {
// list all JMS resources
for (Object r : adminObjectResources) {
AdminObjectResource adminObject = (AdminObjectResource) r;
if (JMSRA.equals(adminObject.getResAdapter())) {
Map<String, String> m = new HashMap<>();
m.put("name", adminObject.getJndiName());
list.add(m);
}
}
for (Object c : connectorResources) {
ConnectorResource cr = (ConnectorResource) c;
ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
if (cp != null && JMSRA.equals(cp.getResourceAdapterName())) {
Map<String, String> m = new HashMap<>();
m.put("name", cr.getJndiName());
list.add(m);
}
}
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources") + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
} else {
switch(resourceType) {
case TOPIC_CF:
case QUEUE_CF:
case UNIFIED_CF:
for (Object c : connectorResources) {
ConnectorResource cr = (ConnectorResource) c;
ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
if (cp != null && resourceType.equals(cp.getConnectionDefinitionName()) && JMSRA.equals(cp.getResourceAdapterName())) {
Map<String, String> m = new HashMap<>();
m.put("name", cr.getJndiName());
list.add(m);
}
}
break;
case TOPIC:
case QUEUE:
for (Object r : adminObjectResources) {
AdminObjectResource res = (AdminObjectResource) r;
if (resourceType.equals(res.getResType()) && JMSRA.equals(res.getResAdapter())) {
Map<String, String> m = new HashMap<>();
m.put("name", res.getJndiName());
list.add(m);
}
}
break;
}
}
if (!list.isEmpty()) {
List<Map<String, String>> resourceList = CommandTarget.DOMAIN.isValid(habitat, target) ? list : filterListForTarget(list);
List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
for (Map<String, String> m : resourceList) {
String jndiName = m.get("name");
final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jndiName);
String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
if (logicalName != null) {
m.put("logical-jndi-name", logicalName);
}
}
extraProperties.put("jmsResources", resourceList);
}
report.setExtraProperties(extraProperties);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class ConnectorResourceManager method createConfigBean.
private ConnectorResource createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
ConnectorResource newResource = param.createChild(ConnectorResource.class);
newResource.setJndiName(jndiName);
if (description != null) {
newResource.setDescription(description);
}
newResource.setPoolName(poolName);
newResource.setEnabled(enabled);
newResource.setObjectType(objectType);
if (properties != null) {
for (Map.Entry e : properties.entrySet()) {
Property prop = newResource.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
newResource.getProperty().add(prop);
}
}
return newResource;
}
use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class ListConnectorResources 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();
try {
Collection<ConnectorResource> connectorResources = domain.getResources().getResources(ConnectorResource.class);
for (ConnectorResource resource : connectorResources) {
if (bindableResourcesHelper.resourceExists(resource.getJndiName(), target)) {
ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(resource.getJndiName());
}
}
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.connector.resources.fail", "List connector resources failed") + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.connectors.config.ConnectorResource 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.connectors.config.ConnectorResource in project Payara by payara.
the class ConnectionFactoryDefinitionDeployer method undeployResource.
public void undeployResource(Object resource) throws Exception {
final ConnectionFactoryDefinitionDescriptor desc = (ConnectionFactoryDefinitionDescriptor) resource;
String poolName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), CFDPOOL);
String resourceName = ConnectorsUtil.deriveResourceName(desc.getResourceId(), desc.getName(), desc.getResourceType());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "ConnectionFactoryDefinitionDeployer.undeployResource() : pool-name [" + poolName + "], " + " resource-name [" + resourceName + "]");
}
// undeploy resource
ConnectorResource connectorResource = new MyConnectorResource(poolName, resourceName);
getDeployer(connectorResource).undeployResource(connectorResource);
// undeploy pool
ConnectorConnectionPool connectorCp = new MyConnectorConnectionPool(desc, poolName);
getDeployer(connectorCp).undeployResource(connectorCp);
}
Aggregations