use of com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.
the class JdbcResourcesUtil method getJdbcConnectionPoolOfResource.
public JdbcConnectionPool getJdbcConnectionPoolOfResource(ResourceInfo resourceInfo) {
JdbcResource resource = null;
JdbcConnectionPool pool = null;
Resources resources = getResources(resourceInfo);
if (resources != null) {
resource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, resourceInfo.getName());
if (resource != null) {
pool = (JdbcConnectionPool) ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, resource.getPoolName());
}
}
return pool;
}
use of com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.
the class JDBCResourceManager method create.
public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
setAttributes(attributes, target);
ResourceStatus validationStatus = isValid(resources, true, target);
if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
return validationStatus;
}
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
return createResource(param, properties);
}
}, resources);
resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("create.jdbc.resource.fail", "JDBC resource {0} create failed ", jndiName) + " " + tfe.getLocalizedMessage();
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("create.jdbc.resource.success", "JDBC resource {0} created successfully", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of com.sun.enterprise.config.serverbeans.Resources 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 com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.
the class ConnectorResourceDeployer method checkAndDeletePool.
/**
* Checks if no more resource-refs to resources exists for the
* connector connection pool and then deletes the pool
*
* @param cr ConnectorResource
* @throws Exception (ConfigException / undeploy exception)
* @since 8.1 pe/se/ee
*/
private void checkAndDeletePool(ConnectorResource cr) throws Exception {
String poolName = cr.getPoolName();
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(cr);
PoolInfo poolInfo = new PoolInfo(poolName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
Resources resources = (Resources) cr.getParent();
// Its possible that the ConnectorResource here is a ConnectorResourceeDefinition. Ignore optimization.
if (resources != null) {
try {
boolean poolReferred = ResourcesUtil.createInstance().isPoolReferredInServerInstance(poolInfo);
if (!poolReferred) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Deleting connector connection pool [" + poolName + "] as there are no more " + "resource-refs to the pool in this server instance");
}
ConnectorConnectionPool ccp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(resources, ConnectorConnectionPool.class, poolName);
// Delete/Undeploy Pool
runtime.getResourceDeployer(ccp).undeployResource(ccp);
}
} catch (Exception ce) {
_logger.warning(ce.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Exception while deleting pool [ " + poolName + " ] : " + ce);
}
throw ce;
}
}
}
use of com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.
the class ContextServiceManager method create.
public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
setAttributes(attributes, target);
ResourceStatus validationStatus = isValid(resources, true, target);
if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
return validationStatus;
}
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
return createResource(param, properties);
}
}, resources);
resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("create.context.service.failed", "Context service {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("create.context.service.success", "Context service {0} created successfully", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Aggregations