use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class CreateAdminObject 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();
HashMap attrList = new HashMap();
attrList.put(RES_TYPE, resType);
attrList.put(ADMIN_OBJECT_CLASS_NAME, className);
attrList.put(ResourceConstants.ENABLED, enabled.toString());
attrList.put(JNDI_NAME, jndiName);
attrList.put(ServerTags.DESCRIPTION, description);
attrList.put(RES_ADAPTER, raName);
ResourceStatus rs;
try {
AdminObjectManager adminObjMgr = adminObjectManagerProvider.get();
rs = adminObjMgr.create(domain.getResources(), attrList, properties, target);
} catch (Exception e) {
Logger.getLogger(CreateAdminObject.class.getName()).log(Level.SEVERE, "Something went wrong in create-admin-object", e);
String def = "Admin object: {0} could not be created, reason: {1}";
report.setMessage(localStrings.getLocalString("create.admin.object.fail", def, jndiName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
if (rs.getMessage() != null) {
report.setMessage(rs.getMessage());
}
if (rs.getStatus() == ResourceStatus.FAILURE) {
ec = ActionReport.ExitCode.FAILURE;
if (rs.getMessage() == null) {
report.setMessage(localStrings.getLocalString("create.admin.object.fail", "Admin object {0} creation failed", jndiName, ""));
}
if (rs.getException() != null)
report.setFailureCause(rs.getException());
}
report.setActionExitCode(ec);
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class JDBCResourceManager method delete.
public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
if (jndiName == null) {
String msg = localStrings.getLocalString("jdbc.resource.noJndiName", "No JNDI name defined for JDBC resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
// ensure we already have this resource
if (ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jndiName) == null) {
String msg = localStrings.getLocalString("delete.jdbc.resource.notfound", "A JDBC resource named {0} does not exist.", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
if (environment.isDas()) {
if ("domain".equals(target)) {
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
String msg = localStrings.getLocalString("delete.jdbc.resource.resource-ref.exist", "jdbc-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} else {
if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
String msg = localStrings.getLocalString("delete.jdbc.resource.no.resource-ref", "jdbc-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
String msg = localStrings.getLocalString("delete.jdbc.resource.multiple.resource-refs", "jdbc resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
}
}
try {
JdbcResource jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jndiName);
if (ResourceConstants.SYSTEM_ALL_REQ.equals(jdbcResource.getObjectType())) {
String msg = localStrings.getLocalString("delete.jdbc.resource.system-all-req.object-type", "The jdbc resource [ {0} ] cannot be deleted as it is required to be configured in the system.", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
// delete resource-ref
resourceUtil.deleteResourceRef(jndiName, target);
// delete jdbc-resource
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
JdbcResource resource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jndiName);
return param.getResources().remove(resource);
}
}, resources) == null) {
String msg = localStrings.getLocalString("jdbc.resource.deletionFailed", "JDBC resource {0} delete failed ", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("jdbc.resource.deletionFailed", "JDBC resource {0} delete failed ", jndiName);
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("jdbc.resource.deleteSuccess", "JDBC resource {0} deleted successfully", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class JDBCResourceManager method isValid.
private ResourceStatus isValid(Resources resources, boolean validateResourceRef, String target) {
ResourceStatus status;
if (jndiName == null) {
String msg = localStrings.getLocalString("create.jdbc.resource.noJndiName", "No JNDI name defined for JDBC resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
status = resourcesHelper.validateBindableResourceForDuplicates(resources, jndiName, validateResourceRef, target, JdbcResource.class);
if (status.getStatus() == ResourceStatus.FAILURE) {
return status;
}
if (ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolName) == null) {
String msg = localStrings.getLocalString("create.jdbc.resource.connPoolNotFound", "Attribute value (pool-name = {0}) is not found in list of jdbc connection pools.", poolName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
return status;
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class DeleteJdbcConnectionPool 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 {
JDBCConnectionPoolManager jdbcConnMgr = new JDBCConnectionPoolManager();
ResourceStatus rs = jdbcConnMgr.delete(servers, clusters, domain.getResources(), cascade.toString(), poolName);
if (rs.getMessage() != null)
report.setMessage(rs.getMessage());
if (rs.getStatus() == ResourceStatus.SUCCESS) {
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} else {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
if (rs.getException() != null) {
report.setFailureCause(rs.getException());
Logger.getLogger(DeleteJdbcConnectionPool.class.getName()).log(Level.SEVERE, "Something went wrong in delete-jdbc-connection-pool", rs.getException());
}
}
} catch (Exception e) {
Logger.getLogger(DeleteJdbcConnectionPool.class.getName()).log(Level.SEVERE, "Something went wrong in delete-jdbc-connection-pool", e);
String msg = e.getMessage() != null ? e.getMessage() : localStrings.getLocalString("delete.jdbc.connection.pool.fail", "{0} delete failed ", poolName);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class JDBCConnectionPoolManager method createConfigBean.
public Resource createConfigBean(Resources resources, HashMap attributes, Properties properties, boolean validate) throws Exception {
setAttributes(attributes);
ResourceStatus status = null;
if (!validate) {
status = new ResourceStatus(ResourceStatus.SUCCESS, "");
} else {
status = isValid(resources);
}
if (status.getStatus() == ResourceStatus.SUCCESS) {
return createConfigBean(resources, properties);
} else {
throw new ResourceException(status.getMessage());
}
}
Aggregations