Search in sources :

Example 11 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class JavaMailResourceManager 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());
    }
}
Also used : ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ResourceException(javax.resource.ResourceException)

Example 12 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class CreateJndiResource 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(JNDI_LOOKUP, jndiLookupName);
    attrList.put(ENABLED, enabled.toString());
    attrList.put(JNDI_NAME, jndiName);
    attrList.put(ServerTags.DESCRIPTION, description);
    ResourceStatus rs;
    try {
        rs = jndiResManager.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        Logger.getLogger(CreateJndiResource.class.getName()).log(Level.SEVERE, "Unable to create jndi resource " + jndiName, e);
        String def = "jndi resource: {0} could not be created, reason: {1}";
        report.setMessage(localStrings.getLocalString("create.jndi.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.jndi.resource.fail", "jndi resource {0} creation failed", 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 13 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class JndiResourceManager 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());
    }
}
Also used : ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ResourceException(javax.resource.ResourceException)

Example 14 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class ResourcesManager method createResources.

/**
 * Creating resources from sun-resources.xml file. This method is used by
 * the admin framework when the add-resources command is used to create
 * resources
 */
public static ArrayList createResources(Resources resources, File resourceXMLFile, String target, org.glassfish.resources.admin.cli.ResourceFactory resourceFactory) throws Exception {
    ArrayList results = new ArrayList();
    org.glassfish.resources.admin.cli.ResourcesXMLParser resourcesParser = new org.glassfish.resources.admin.cli.ResourcesXMLParser(resourceXMLFile);
    List<Resource> vResources = resourcesParser.getResourcesList();
    // First add all non connector resources.
    Iterator<Resource> nonConnectorResources = org.glassfish.resources.admin.cli.ResourcesXMLParser.getNonConnectorResourcesList(vResources, false, false).iterator();
    while (nonConnectorResources.hasNext()) {
        Resource resource = (Resource) nonConnectorResources.next();
        HashMap attrList = resource.getAttributes();
        String desc = resource.getDescription();
        if (desc != null)
            attrList.put("description", desc);
        Properties props = resource.getProperties();
        ResourceStatus rs;
        try {
            org.glassfish.resources.admin.cli.ResourceManager rm = resourceFactory.getResourceManager(resource);
            rs = rm.create(resources, attrList, props, target);
        } catch (Exception e) {
            String msg = e.getMessage();
            rs = new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
        results.add(rs);
    }
    // Now add all connector resources
    Iterator connectorResources = org.glassfish.resources.admin.cli.ResourcesXMLParser.getConnectorResourcesList(vResources, false, false).iterator();
    while (connectorResources.hasNext()) {
        Resource resource = (Resource) connectorResources.next();
        HashMap attrList = resource.getAttributes();
        String desc = resource.getDescription();
        if (desc != null)
            attrList.put("description", desc);
        Properties props = resource.getProperties();
        ResourceStatus rs;
        try {
            org.glassfish.resources.admin.cli.ResourceManager rm = resourceFactory.getResourceManager(resource);
            rs = rm.create(resources, attrList, props, target);
        } catch (Exception e) {
            String msg = e.getMessage();
            rs = new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
        results.add(rs);
    }
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Resource(org.glassfish.resources.api.Resource) Properties(java.util.Properties) Iterator(java.util.Iterator) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus)

Example 15 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class JNDIConfigSource method setValue.

public boolean setValue(String propertyName, String propertyValue, String target) {
    boolean result = false;
    HashMap<String, String> attrList = new HashMap<>();
    attrList.put("factory-class", "org.glassfish.resources.custom.factory.PrimitivesAndStringFactory");
    attrList.put("res-type", "java.lang.String");
    attrList.put(ResourceConstants.ENABLED, Boolean.TRUE.toString());
    attrList.put(JNDI_NAME, propertyName);
    attrList.put(ServerTags.DESCRIPTION, "MicroProfile Config property for " + propertyName);
    Properties props = new Properties();
    props.put("value", propertyValue);
    try {
        CustomResourceManager customResMgr = Globals.getDefaultHabitat().getService(CustomResourceManager.class);
        ResourceStatus status = customResMgr.create(domainConfiguration.getResources(), attrList, props, target);
        if (status.getStatus() == ResourceStatus.SUCCESS) {
            result = true;
        } else {
            if (status.isAlreadyExists()) {
                Logger.getLogger(JNDIConfigSource.class.getName()).log(Level.WARNING, "Unable to set MicroProfile JNDI Config property as it already exists please delete it using delete-config-property --source jndi --propertyname {0}", propertyName);
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(JNDIConfigSource.class.getName()).log(Level.WARNING, "Unable to set MicroProfile JNDI Config property " + propertyName, ex);
    }
    return result;
}
Also used : CustomResourceManager(org.glassfish.resources.admin.cli.CustomResourceManager) HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Properties(java.util.Properties) NamingException(javax.naming.NamingException) PropertyVetoException(java.beans.PropertyVetoException)

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 Module (com.sun.enterprise.config.serverbeans.Module)1 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)1