use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class ConnectorResourceManager method createResource.
private ConnectorResource createResource(Resources param, Properties props) throws PropertyVetoException, TransactionFailure {
ConnectorResource newResource = createConfigBean(param, props);
param.getResources().add(newResource);
return newResource;
}
use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class ActiveJmsResourceAdapter method setValuesFromConfiguration.
private void setValuesFromConfiguration(String cfName, EjbMessageBeanDescriptor descriptor_) throws ConnectorRuntimeException {
// todo: need to enable
List<Property> ep = null;
try {
/*Resources rbeans = getAllResources();//ServerBeansFactory.getDomainBean(ctx).getResources();
ConnectorResource res = (ConnectorResource)
rbeans.getResourceByName(ConnectorResource.class, cfName);*/
String appName = descriptor_.getApplication().getAppName();
String moduleName = ConnectorsUtil.getModuleName(descriptor_);
ConnectorResource res = (ConnectorResource) ResourcesUtil.createInstance().getResource(cfName, appName, moduleName, ConnectorResource.class);
if (res == null) {
String msg = sm.getString("ajra.mdb_cf_not_created", cfName);
throw new ConnectorRuntimeException(msg);
}
ConnectorConnectionPool ccp = (ConnectorConnectionPool) ResourcesUtil.createInstance().getResource(res.getPoolName(), appName, moduleName, ConnectorConnectionPool.class);
// rbeans.getResourceByName(ConnectorConnectionPool.class, res.getPoolName());
ep = ccp.getProperty();
} catch (Exception ce) {
String msg = sm.getString("ajra.mdb_cf_not_created", cfName);
ConnectorRuntimeException cre = new ConnectorRuntimeException(msg);
cre.initCause(ce);
throw cre;
}
if (ep == null) {
String msg = sm.getString("ajra.cannot_find_phy_dest");
throw new ConnectorRuntimeException(msg);
}
for (int i = 0; i < ep.size(); i++) {
Property prop = ep.get(i);
String name = prop.getName();
if (name.equals(MCFADDRESSLIST)) {
name = ADDRESSLIST;
}
String val = prop.getValue();
if (val == null || val.equals("")) {
continue;
}
descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(name, val, null));
}
}
use of org.glassfish.connectors.config.ConnectorResource in project Payara by payara.
the class DeleteJMSResource 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
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
if (jndiName == null) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.noJndiName", "No JNDI name defined for JMS Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
jndiNameForConnectionPool = jndiName + JNDINAME_APPENDER;
ActionReport subReport = report.addSubActionsReport();
ConnectorResource cresource = null;
Resource res = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
if (res instanceof ConnectorResource) {
cresource = (ConnectorResource) res;
}
/* for (ConnectorResource cr : connResources) {
if (cr.getJndiName().equals(jndiName))
cresource = cr;
} */
if (cresource == null) {
ParameterMap params = new ParameterMap();
params.set("jndi_name", jndiName);
params.set("DEFAULT", jndiName);
params.set("target", target);
commandRunner.getCommandInvocation("delete-admin-object", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSAdminObject", "Unable to Delete Admin Object."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
if (!cascade) {
Collection<ConnectorResource> connectorResources = domain.getResources().getResources(ConnectorResource.class);
String connPoolName = jndiName + JNDINAME_APPENDER;
int count = 0;
for (ConnectorResource resource : connectorResources) {
if (connPoolName.equals(resource.getPoolName())) {
count++;
if (count > 1)
break;
}
}
if (count > 1) {
report.setMessage(localStrings.getLocalString("found.more.connector.resources", "Some connector resources are referencing connection pool {0}. Use 'cascade' option to delete them", connPoolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ActionReport listReport = habitat.getService(ActionReport.class);
ParameterMap listParams = new ParameterMap();
listParams.set("target", target);
commandRunner.getCommandInvocation("list-jms-resources", listReport, context.getSubject()).parameters(listParams).execute();
if (ActionReport.ExitCode.FAILURE.equals(listReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Properties extraProps = listReport.getExtraProperties();
if (extraProps != null && extraProps.size() > 0) {
boolean resourceExist = false;
for (int i = 0; i < extraProps.size(); i++) {
List<Map<String, String>> nameList = (List) extraProps.get("jmsResources");
for (Map<String, String> m : nameList) {
String jndi = (String) m.get("name");
if (jndiName.equals(jndi)) {
resourceExist = true;
break;
}
}
if (resourceExist)
break;
}
if (!resourceExist) {
report.setMessage(localStrings.getLocalString("jms.resources.not.found", "JMS Resource {0} not found", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// Delete the connector resource and connector connection pool
String defPoolName = jndiNameForConnectionPool;
String poolName = cresource.getPoolName();
if (poolName != null && poolName.equals(defPoolName)) {
ParameterMap params = new ParameterMap();
params.set("DEFAULT", jndiName);
params.set("connector_resource_name", jndiName);
params.set("target", target);
commandRunner.getCommandInvocation("delete-connector-resource", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSResource", "Unable to Delete Connector Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
params = new ParameterMap();
params.set("poolname", jndiName);
params.set("cascade", cascade.toString());
params.set("DEFAULT", jndiNameForConnectionPool);
commandRunner.getCommandInvocation("delete-connector-connection-pool", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSPool", "Unable to Delete Connector Connection Pool."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// clear the message set by the delete-connector-connection-pool command this is to prevent the 'connection pool deleted' message from displaying
subReport.setMessage("");
} else {
// There is no connector pool with the default poolName.
// However, no need to throw exception as the connector
// resource might still be there. Try to delete the
// connector-resource without touching the ref. as
// ref. might have been deleted while deleting connector-connection-pool
// as the ref. is the same.
ParameterMap params = new ParameterMap();
params.set("DEFAULT", jndiName);
params.set("connector_resource_name", jndiName);
params.set("target", target);
commandRunner.getCommandInvocation("delete-connector-resource", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSResource", "Unable to Delete Connector Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
report.setActionExitCode(ec);
}
Aggregations