Search in sources :

Example 11 with Resource

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

the class ResourcesXMLParser method generateCustomResource.

/*
     * Generate the Custom resource
     */
private void generateCustomResource(Node nextKid, String scope) throws Exception {
    NamedNodeMap attributes = nextKid.getAttributes();
    if (attributes == null)
        return;
    Node jndiNameNode = attributes.getNamedItem(JNDI_NAME);
    String jndiName = getScopedName(jndiNameNode.getNodeValue(), scope);
    Node resTypeNode = attributes.getNamedItem(RES_TYPE);
    String resType = resTypeNode.getNodeValue();
    Node factoryClassNode = attributes.getNamedItem(FACTORY_CLASS);
    String factoryClass = factoryClassNode.getNodeValue();
    Node enabledNode = attributes.getNamedItem(ENABLED);
    Resource customResource = new Resource(Resource.CUSTOM_RESOURCE);
    customResource.setAttribute(JNDI_NAME, jndiName);
    customResource.setAttribute(RES_TYPE, resType);
    customResource.setAttribute(FACTORY_CLASS, factoryClass);
    if (enabledNode != null) {
        String sEnabled = enabledNode.getNodeValue();
        customResource.setAttribute(ENABLED, sEnabled);
    }
    NodeList children = nextKid.getChildNodes();
    generatePropertyElement(customResource, children);
    vResources.add(customResource);
    resourceMap.put(customResource, nextKid);
    // debug strings
    printResourceElements(customResource);
}
Also used : Resource(org.glassfish.resources.api.Resource)

Example 12 with Resource

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

the class ResourcesXMLParser method generateConnectorResource.

/**
 * Generate the Connector resource
 */
private void generateConnectorResource(Node nextKid, String scope) throws Exception {
    NamedNodeMap attributes = nextKid.getAttributes();
    if (attributes == null)
        return;
    Node jndiNameNode = attributes.getNamedItem(JNDI_NAME);
    String jndiName = getScopedName(jndiNameNode.getNodeValue(), scope);
    Node poolNameNode = attributes.getNamedItem(POOL_NAME);
    String poolName = getScopedName(poolNameNode.getNodeValue(), scope);
    Node resTypeNode = attributes.getNamedItem(RESOURCE_TYPE);
    Node enabledNode = attributes.getNamedItem(ENABLED);
    org.glassfish.resources.api.Resource connectorResource = new Resource(org.glassfish.resources.api.Resource.CONNECTOR_RESOURCE);
    connectorResource.setAttribute(JNDI_NAME, jndiName);
    connectorResource.setAttribute(POOL_NAME, poolName);
    if (resTypeNode != null) {
        String resType = resTypeNode.getNodeValue();
        connectorResource.setAttribute(RESOURCE_TYPE, resType);
    }
    if (enabledNode != null) {
        String sEnabled = enabledNode.getNodeValue();
        connectorResource.setAttribute(ENABLED, sEnabled);
    }
    NodeList children = nextKid.getChildNodes();
    generatePropertyElement(connectorResource, children);
    vResources.add(connectorResource);
    resourceMap.put(connectorResource, nextKid);
    // debug strings
    printResourceElements(connectorResource);
}
Also used : Resource(org.glassfish.resources.api.Resource) Resource(org.glassfish.resources.api.Resource)

Example 13 with Resource

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

the class ResourcesDeployer method deployResources.

public void deployResources(String applicationName, String moduleName, Collection<com.sun.enterprise.config.serverbeans.Resource> resources, boolean postDeployPhase) throws Exception {
    for (Resource resource : resources) {
        if (resource instanceof BindableResource) {
            BindableResource bindableResource = (BindableResource) resource;
            ResourceInfo resourceInfo = new ResourceInfo(bindableResource.getJndiName(), applicationName, moduleName);
            if (getResourceDeployer(bindableResource).canDeploy(postDeployPhase, resources, bindableResource)) {
                resourcesBinder.deployResource(resourceInfo, bindableResource);
            }
        } else {
            if (getResourceDeployer(resource).canDeploy(postDeployPhase, resources, resource)) {
                getResourceDeployer(resource).deployResource(resource, applicationName, moduleName);
            }
        }
    }
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) Resource(com.sun.enterprise.config.serverbeans.Resource) Resource(org.glassfish.resources.api.Resource)

Example 14 with Resource

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

the class ResourceUtilities method getResourceConflictsWithDomainXML.

/**
 * Checks if any of the Resource in the given set has a conflict with
 * resource definitions in the domain.xml. A <b> conflict </b> is defined
 * based on the type of the resource. For example, a JDBC Resource has "jndi-name"
 * that is the identifying key where as for a JDBC Connection Pool, it is
 * the "name" that must be unique.
 *
 * @param resList a Set of Resource elements.
 * @param resources all resources from domain.xml
 *
 * @throws org.glassfish.resources.api.ResourceConflictException an exception is thrown when an archive is found to
 * have two or more resources that conflict with resources already present in domain.xml.
 */
public static void getResourceConflictsWithDomainXML(final List<Resource> resList, final Resources resources) throws ResourceConflictException {
    if (resList != null) {
        Iterator<org.glassfish.resources.api.Resource> iterRes = resList.iterator();
        StringBuffer conflictingResources = new StringBuffer();
        while (iterRes.hasNext()) {
            org.glassfish.resources.api.Resource res = iterRes.next();
            final String id = getIdToCompare(res);
            if (resources.getResourceByName(res.getClass(), id) != null) {
                conflictingResources.append("\n");
                String message = localStrings.getString("conflict.resource.with.domain.xml", getIdToCompare(res));
                conflictingResources.append(message);
                _logger.warning(message);
                if (_logger.isLoggable(Level.FINE))
                    logAttributes(res);
            }
        }
        if (conflictingResources.toString().length() > 0) {
            throw new ResourceConflictException(conflictingResources.toString());
        }
    }
}
Also used : Resource(org.glassfish.resources.api.Resource) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) Resource(org.glassfish.resources.api.Resource)

Example 15 with Resource

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

the class ResourcesXMLParser method getResourcesOfType.

/**
 * Sorts the resources defined in the resources configuration xml file into
 * two buckets
 *  a) list of resources that needs to be created prior to
 *  module deployment. This includes all non-Connector resources
 *  and resource-adapter-config
 *  b) includes all connector resources in the order in which the resources needs
 *  to be created
 *  and returns the requested resources bucker to the caller.
 *
 *  @param resources Resources list as defined in sun-resources.xml
 *  @param type Specified either ResourcesXMLParser.CONNECTOR or
 *  ResourcesXMLParser.NONCONNECTOR to indicate the type of
 *  resources are needed by the client of the ResourcesXMLParser
 *  @param isResourceCreation During the resource Creation Phase, RA configs are
 *  added to the nonConnector resources list so that they can be created in the
 *  <code>PreResCreationPhase</code>. When the isResourceCreation is false, the
 *  RA config resuorces are added to the Connector Resources list, so that they
 *  can be deleted as all other connector resources in the
 *  <code>PreResDeletionPhase</code>
 */
private static List<org.glassfish.resources.api.Resource> getResourcesOfType(List<Resource> resources, int type, boolean isResourceCreation, boolean ignoreDuplicates) {
    List<Resource> nonConnectorResources = new ArrayList<org.glassfish.resources.api.Resource>();
    List<org.glassfish.resources.api.Resource> connectorResources = new ArrayList<org.glassfish.resources.api.Resource>();
    for (Resource res : resources) {
        if (isConnectorResource(res)) {
            if (res.getType().equals(Resource.RESOURCE_ADAPTER_CONFIG)) {
                if (isResourceCreation) {
                    // RA config is considered as a nonConnector Resource,
                    // during sun-resources.xml resource-creation phase, so that
                    // it could be created before the RAR is deployed.
                    addToList(nonConnectorResources, res, ignoreDuplicates);
                } else {
                    addToList(connectorResources, res, ignoreDuplicates);
                }
            } else {
                addToList(connectorResources, res, ignoreDuplicates);
            }
        } else {
            addToList(nonConnectorResources, res, ignoreDuplicates);
        }
    }
    List<org.glassfish.resources.api.Resource> finalSortedConnectorList = sortConnectorResources(connectorResources);
    List<org.glassfish.resources.api.Resource> finalSortedNonConnectorList = sortNonConnectorResources(nonConnectorResources);
    if (type == CONNECTOR) {
        return finalSortedConnectorList;
    } else {
        return finalSortedNonConnectorList;
    }
}
Also used : Resource(org.glassfish.resources.api.Resource)

Aggregations

Resource (org.glassfish.resources.api.Resource)24 Resource (com.sun.enterprise.config.serverbeans.Resource)5 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)5 org.glassfish.resources.api (org.glassfish.resources.api)4 IOException (java.io.IOException)3 ResourceException (javax.resource.ResourceException)3 DeploymentException (org.glassfish.deployment.common.DeploymentException)3 File (java.io.File)2 ResourcesXMLParser (org.glassfish.resources.admin.cli.ResourcesXMLParser)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)1 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)1 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)1 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)1 ResourceManager (org.glassfish.resources.admin.cli.ResourceManager)1 org.jvnet.hk2.config (org.jvnet.hk2.config)1