Search in sources :

Example 56 with ResourceStatus

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);
}
Also used : HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Example 57 with ResourceStatus

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;
}
Also used : ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) MailResource(org.glassfish.resources.javamail.config.MailResource)

Example 58 with ResourceStatus

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Example 59 with ResourceStatus

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);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 60 with ResourceStatus

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;
}
Also used : ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource)

Aggregations

ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)60 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)17 HashMap (java.util.HashMap)15 ActionReport (org.glassfish.api.ActionReport)15 Resources (com.sun.enterprise.config.serverbeans.Resources)14 PropertyVetoException (java.beans.PropertyVetoException)14 ResourceException (javax.resource.ResourceException)13 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 ContextService (org.glassfish.concurrent.config.ContextService)2 ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)2 ManagedThreadFactory (org.glassfish.concurrent.config.ManagedThreadFactory)2 JdbcResource (org.glassfish.jdbc.config.JdbcResource)2 MailResource (org.glassfish.resources.javamail.config.MailResource)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)1 NamingException (javax.naming.NamingException)1