use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class JDBCConnectionPoolManager method create.
@Override
public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
setAttributes(attributes);
ResourceStatus validationStatus = isValid(resources);
if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
return validationStatus;
}
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
@Override
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
return createResource(param, properties);
}
}, resources);
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("create.jdbc.connection.pool.fail", "JDBC connection pool {0} create failed: {1}", jdbcconnectionpoolid, tfe.getMessage());
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
String msg = localStrings.getLocalString("create.jdbc.connection.pool.success", "JDBC connection pool {0} created successfully", jdbcconnectionpoolid);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class ResourceAdapterConfigManager method createConfigBean.
public Resource createConfigBean(Resources resources, HashMap attributes, Properties properties, boolean validate) throws Exception {
setParams(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());
}
}
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 CreateConnectorResource 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(POOL_NAME, poolName);
attrList.put(ResourceConstants.ENABLED, enabled.toString());
attrList.put(JNDI_NAME, jndiName);
attrList.put(ServerTags.DESCRIPTION, description);
attrList.put(ServerTags.OBJECT_TYPE, objectType);
ResourceStatus rs;
try {
rs = connResMgr.create(domain.getResources(), attrList, properties, target);
} catch (Exception e) {
Logger.getLogger(CreateConnectorResource.class.getName()).log(Level.SEVERE, "Unable to create connector resource " + jndiName, e);
String def = "Connector resource: {0} could not be created, reason: {1}";
report.setMessage(localStrings.getLocalString("create.connector.resource.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.connector.resource.fail", "Connector resource {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 AddResources 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();
// Check if the path xmlFile exists
if (!xmlFile.exists()) {
report.setMessage(localStrings.getLocalString("FileNotFound", "The system cannot find the path specified: {0}", xmlFile.getName()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
final ArrayList results = ResourcesManager.createResources(domain.getResources(), xmlFile, target, resourceFactory);
final Iterator resultsIter = results.iterator();
report.getTopMessagePart().setChildrenType("Command");
boolean isSuccess = false;
while (resultsIter.hasNext()) {
ResourceStatus rs = ((ResourceStatus) resultsIter.next());
final String msgToAdd = rs.getMessage();
if ((msgToAdd != null) && (!msgToAdd.equals(""))) {
final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(msgToAdd);
}
if (rs.getStatus() == ResourceStatus.SUCCESS || rs.isAlreadyExists())
isSuccess = true;
}
report.setActionExitCode((isSuccess) ? ActionReport.ExitCode.SUCCESS : ActionReport.ExitCode.FAILURE);
if (!isSuccess)
report.setMessage(localStrings.getLocalString("add.resources.failed", "add-resources <{0}> failed", xmlFile.getName()));
} catch (Exception ex) {
Logger.getLogger(AddResources.class.getName()).log(Level.SEVERE, "Something went wrong in add-resources", ex);
report.setMessage(localStrings.getLocalString("add.resources.failed", "add-resources <{0}> failed", xmlFile.getName()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
// Need to fix, doesn't show the error from exception, though it writes in the log
report.setFailureCause(ex);
}
}
Aggregations