use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class CreateJavaMailResource 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 attributes = new HashMap();
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME, jndiName);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_HOST, mailHost);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_USER, mailUser);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_PASSWORD, mailPassword);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_AUTH, auth.toString());
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_FROM_ADDRESS, fromAddress);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO, storeProtocol);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO_CLASS, storeProtocolClass);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO, transportProtocol);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO_CLASS, transportProtocolClass);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_DEBUG, debug.toString());
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.ENABLED, enabled.toString());
attributes.put(ServerTags.DESCRIPTION, description);
ResourceStatus rs;
try {
rs = mailResMgr.create(domain.getResources(), attributes, properties, target);
} catch (Exception e) {
Logger.getLogger(CreateJavaMailResource.class.getName()).log(Level.SEVERE, "Unable to create Mail Resource " + jndiName, e);
String def = "Mail resource: {0} could not be created";
report.setMessage(localStrings.getLocalString("create.mail.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.mail.resource.fail", "Unable to create Mail Resource {0}.", 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 JavaMailResourceManager method isValid.
private ResourceStatus isValid(Resources resources, boolean validateResourceRef, String target) {
ResourceStatus status;
if (mailHost == null) {
String msg = localStrings.getLocalString("create.mail.resource.noHostName", "No host name defined for Mail Resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
if (mailUser == null) {
String msg = localStrings.getLocalString("create.mail.resource.noUserName", "No user name defined for Mail Resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
if (fromAddress == null) {
String msg = localStrings.getLocalString("create.mail.resource.noFrom", "From not defined for Mail Resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
status = resourcesHelper.validateBindableResourceForDuplicates(resources, jndiName, validateResourceRef, target, MailResource.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 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);
}
}
use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.
the class JndiResourceManager 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.jndi.resource.fail", "Unable to create jndi resource {0}.", jndiName) + " " + tfe.getLocalizedMessage();
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
String msg = localStrings.getLocalString("create.jndi.resource.success", "jndi 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 JndiResourceManager method isValid.
private ResourceStatus isValid(Resources resources, boolean validateResourceRef, String target) {
ResourceStatus status;
if (resType == null) {
String msg = localStrings.getLocalString("create.jndi.resource.noResType", "No type defined for JNDI resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
if (factoryClass == null) {
String msg = localStrings.getLocalString("create.jndi.resource.noFactoryClassName", "No Factory class name defined for JNDI resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
if (jndiLookupName == null) {
String msg = localStrings.getLocalString("create.jndi.resource.noJndiLookupName", "No Jndi Lookup name defined for JNDI resource.");
return new ResourceStatus(ResourceStatus.FAILURE, msg, true);
}
status = resourcesHelper.validateBindableResourceForDuplicates(resources, jndiName, validateResourceRef, target, ExternalJndiResource.class);
if (status.getStatus() == ResourceStatus.FAILURE) {
return status;
}
return status;
}
Aggregations