use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class CreateCustomResource 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();
HashMap attrList = new HashMap();
attrList.put("factory-class", factoryClass);
attrList.put("res-type", resType);
attrList.put(ResourceConstants.ENABLED, enabled.toString());
attrList.put(JNDI_NAME, jndiName);
attrList.put(ServerTags.DESCRIPTION, description);
ResourceStatus rs;
try {
rs = customResMgr.create(domain.getResources(), attrList, properties, target);
} catch (Exception e) {
Logger.getLogger(CreateCustomResource.class.getName()).log(Level.SEVERE, "Unable to create custom resource " + jndiName, e);
String def = "Custom resource: {0} could not be created, reason: {1}";
report.setMessage(localStrings.getLocalString("create.custom.resource.fail", def, jndiName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
if (rs.getStatus() == ResourceStatus.FAILURE) {
ec = ActionReport.ExitCode.FAILURE;
if (rs.getMessage() == null) {
report.setMessage(localStrings.getLocalString("create.custom.resource.fail", "Custom resource {0} creation failed", jndiName, ""));
}
if (rs.getException() != null)
report.setFailureCause(rs.getException());
}
if (rs.getMessage() != null) {
report.setMessage(rs.getMessage());
}
report.setActionExitCode(ec);
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class CustomResourceManager method isValid.
private ResourceStatus isValid(Resources resources, boolean validateResourceRef, String target) {
ResourceStatus status;
if (resType == null) {
String msg = localStrings.getLocalString("create.custom.resource.noResType", "No type defined for Custom Resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
if (factoryClass == null) {
String msg = localStrings.getLocalString("create.custom.resource.noFactoryClassName", "No Factory class name defined for Custom Resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
status = resourcesHelper.validateBindableResourceForDuplicates(resources, jndiName, validateResourceRef, target, CustomResource.class);
if (status.getStatus() == ResourceStatus.FAILURE) {
return status;
}
return status;
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class CustomResourceManager method createConfigBean.
public Resource createConfigBean(Resources resources, HashMap attributes, Properties properties, boolean validate) throws Exception {
setAttributes(attributes, null);
ResourceStatus status = null;
if (!validate) {
status = new ResourceStatus(ResourceStatus.SUCCESS, "");
} else {
status = isValid(resources, false, null);
}
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 CustomResourceManager 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.custom.resource.fail", "Unable to create custom resource {0}.", jndiName) + " " + tfe.getLocalizedMessage();
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
String msg = localStrings.getLocalString("create.custom.resource.success", "Custom Resource {0} created.", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg, true);
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class JavaMailResourceManager 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;
}
// ensure we don't already have one of this name
if (ResourceUtil.getBindableResourceByName(resources, jndiName) != null) {
String msg = localStrings.getLocalString("create.mail.resource.duplicate.1", "A Mail Resource named {0} already exists.", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
MailResource newResource = createConfigBean(param, properties);
param.getResources().add(newResource);
return newResource;
}
}, resources);
resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
String msg = localStrings.getLocalString("create.mail.resource.success", "Mail Resource {0} created.", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg, true);
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("" + "create.mail.resource.fail", "Unable to create Mail Resource {0}.", jndiName) + " " + tfe.getLocalizedMessage();
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
}
Aggregations