Search in sources :

Example 6 with Resource

use of org.glassfish.resources.api.Resource 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 7 with Resource

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

the class ResourcesXMLParser method generateAdminObjectResource.

/**
 * Generate the Admin Object resource
 */
private void generateAdminObjectResource(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 classNameNode = attributes.getNamedItem(ADMIN_OBJECT_CLASS_NAME);
    String className = null;
    if (classNameNode != null) {
        className = classNameNode.getNodeValue();
    }
    Node resAdapterNode = attributes.getNamedItem(RES_ADAPTER);
    String resAdapter = resAdapterNode.getNodeValue();
    Node enabledNode = attributes.getNamedItem(ENABLED);
    org.glassfish.resources.api.Resource adminObjectResource = new org.glassfish.resources.api.Resource(Resource.ADMIN_OBJECT_RESOURCE);
    adminObjectResource.setAttribute(JNDI_NAME, jndiName);
    adminObjectResource.setAttribute(RES_TYPE, resType);
    if (classNameNode != null) {
        adminObjectResource.setAttribute(ADMIN_OBJECT_CLASS_NAME, className);
    }
    adminObjectResource.setAttribute(RES_ADAPTER, resAdapter);
    if (enabledNode != null) {
        String sEnabled = enabledNode.getNodeValue();
        adminObjectResource.setAttribute(ENABLED, sEnabled);
    }
    NodeList children = nextKid.getChildNodes();
    generatePropertyElement(adminObjectResource, children);
    vResources.add(adminObjectResource);
    resourceMap.put(adminObjectResource, nextKid);
    // debug strings
    printResourceElements(adminObjectResource);
}
Also used : Resource(org.glassfish.resources.api.Resource) Resource(org.glassfish.resources.api.Resource)

Example 8 with Resource

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

the class ResourcesXMLParser method sortNonConnectorResources.

/**
 * Sort non connector resources
 * JDBC Pools are added first to the list, so that the conncetion
 * pools can be created prior to any other jdbc resource defined
 * in the resources configuration xml file.
 * @param nonConnectorResources List of Resources to be sorted.
 * @return The sorted list.
 */
private static List<org.glassfish.resources.api.Resource> sortNonConnectorResources(List<org.glassfish.resources.api.Resource> nonConnectorResources) {
    List<org.glassfish.resources.api.Resource> jdbccps = new ArrayList<Resource>();
    List<org.glassfish.resources.api.Resource> pmfs = new ArrayList<Resource>();
    List<org.glassfish.resources.api.Resource> others = new ArrayList<Resource>();
    List<org.glassfish.resources.api.Resource> finalSortedNonConnectorList = new ArrayList<org.glassfish.resources.api.Resource>();
    for (Resource resource : nonConnectorResources) {
        if (resource.getType().equals(org.glassfish.resources.api.Resource.JDBC_CONNECTION_POOL)) {
            jdbccps.add(resource);
        } else if (resource.getType().equals(org.glassfish.resources.api.Resource.PERSISTENCE_MANAGER_FACTORY_RESOURCE)) {
            // TODO throw exception as pmf resource is not supported anymore
            pmfs.add(resource);
        } else {
            others.add(resource);
        }
    }
    finalSortedNonConnectorList.addAll(jdbccps);
    finalSortedNonConnectorList.addAll(others);
    finalSortedNonConnectorList.addAll(pmfs);
    return finalSortedNonConnectorList;
}
Also used : Resource(org.glassfish.resources.api.Resource)

Example 9 with Resource

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

the class ResourcesXMLParser method generateWorkSecurityMap.

private void generateWorkSecurityMap(Node node, String scope) throws Exception {
    // ignore "scope" as work-security-map is not a bindable resource
    NamedNodeMap attributes = node.getAttributes();
    if (attributes == null) {
        return;
    }
    Node nameNode = attributes.getNamedItem(WORK_SECURITY_MAP_NAME);
    Resource workSecurityMapResource = new Resource(org.glassfish.resources.api.Resource.CONNECTOR_WORK_SECURITY_MAP);
    if (nameNode != null) {
        String name = nameNode.getNodeValue();
        workSecurityMapResource.setAttribute(WORK_SECURITY_MAP_NAME, name);
    }
    Node raNameNode = attributes.getNamedItem(WORK_SECURITY_MAP_RA_NAME);
    if (raNameNode != null) {
        workSecurityMapResource.setAttribute(WORK_SECURITY_MAP_RA_NAME, raNameNode.getNodeValue());
    }
    NodeList children = node.getChildNodes();
    if (children != null) {
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            String nodeName = child.getNodeName();
            if (nodeName.equals(WORK_SECURITY_MAP_GROUP_MAP)) {
                Properties groupMaps = new Properties();
                NamedNodeMap childAttributes = child.getAttributes();
                if (childAttributes != null) {
                    Node eisGroup = childAttributes.getNamedItem(WORK_SECURITY_MAP_EIS_GROUP);
                    Node mappedGroup = childAttributes.getNamedItem(WORK_SECURITY_MAP_MAPPED_GROUP);
                    if (eisGroup != null && mappedGroup != null) {
                        String eisGroupValue = eisGroup.getNodeValue();
                        String serverGroupValue = mappedGroup.getNodeValue();
                        if (eisGroupValue != null && serverGroupValue != null) {
                            groupMaps.put(eisGroupValue, serverGroupValue);
                        }
                    }
                    workSecurityMapResource.setAttribute(WORK_SECURITY_MAP_GROUP_MAP, groupMaps);
                }
            } else if (nodeName.equals(WORK_SECURITY_MAP_PRINCIPAL_MAP)) {
                Properties principalMaps = new Properties();
                NamedNodeMap childAttributes = child.getAttributes();
                if (childAttributes != null) {
                    Node eisPrincipal = childAttributes.getNamedItem(WORK_SECURITY_MAP_EIS_PRINCIPAL);
                    Node mappedPrincipal = childAttributes.getNamedItem(WORK_SECURITY_MAP_MAPPED_PRINCIPAL);
                    if (eisPrincipal != null && mappedPrincipal != null) {
                        String eisPrincipalValue = eisPrincipal.getNodeValue();
                        String serverPrincipalValue = mappedPrincipal.getNodeValue();
                        if (eisPrincipalValue != null && serverPrincipalValue != null) {
                            principalMaps.put(eisPrincipalValue, serverPrincipalValue);
                        }
                    }
                    workSecurityMapResource.setAttribute(WORK_SECURITY_MAP_PRINCIPAL_MAP, principalMaps);
                }
            }
        }
    }
    vResources.add(workSecurityMapResource);
    resourceMap.put(workSecurityMapResource, node);
    // debug strings
    printResourceElements(workSecurityMapResource);
}
Also used : Resource(org.glassfish.resources.api.Resource)

Example 10 with Resource

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

the class ResourcesXMLParser method generateConnectorConnectionPoolResource.

/**
 * Generate the Connector Connection pool Resource
 */
private void generateConnectorConnectionPoolResource(Node nextKid, String scope) throws Exception {
    NamedNodeMap attributes = nextKid.getAttributes();
    if (attributes == null)
        return;
    Node nameNode = attributes.getNamedItem(CONNECTOR_CONNECTION_POOL_NAME);
    Node raConfigNode = attributes.getNamedItem(RESOURCE_ADAPTER_CONFIG_NAME);
    Node conDefNode = attributes.getNamedItem(CONN_DEF_NAME);
    Node steadyPoolSizeNode = attributes.getNamedItem(CONN_STEADY_POOL_SIZE);
    Node maxPoolSizeNode = attributes.getNamedItem(CONN_MAX_POOL_SIZE);
    Node poolResizeNode = attributes.getNamedItem(CONN_POOL_RESIZE_QUANTITY);
    Node idleTimeOutNode = attributes.getNamedItem(CONN_IDLE_TIME_OUT);
    Node failAllConnNode = attributes.getNamedItem(CONN_FAIL_ALL_CONNECTIONS);
    Node maxWaitTimeMillisNode = attributes.getNamedItem(MAX_WAIT_TIME_IN_MILLIS);
    Node transactionSupportNode = attributes.getNamedItem(CONN_TRANSACTION_SUPPORT);
    Node connValidationReqdNode = attributes.getNamedItem(IS_CONNECTION_VALIDATION_REQUIRED);
    Node validateAtmostOncePeriodNode = attributes.getNamedItem(VALIDATE_ATMOST_ONCE_PERIOD_IN_SECONDS);
    Node connLeakTimeoutNode = attributes.getNamedItem(CONNECTION_LEAK_TIMEOUT_IN_SECONDS);
    Node connLeakReclaimNode = attributes.getNamedItem(CONNECTION_LEAK_RECLAIM);
    Node connCreationRetryAttemptsNode = attributes.getNamedItem(CONNECTION_CREATION_RETRY_ATTEMPTS);
    Node connCreationRetryIntervalNode = attributes.getNamedItem(CONNECTION_CREATION_RETRY_INTERVAL_IN_SECONDS);
    Node lazyConnEnlistmentNode = attributes.getNamedItem(LAZY_CONNECTION_ENLISTMENT);
    Node lazyConnAssociationNode = attributes.getNamedItem(LAZY_CONNECTION_ASSOCIATION);
    Node associateWithThreadNode = attributes.getNamedItem(ASSOCIATE_WITH_THREAD);
    Node matchConnectionsNode = attributes.getNamedItem(MATCH_CONNECTIONS);
    Node maxConnUsageCountNode = attributes.getNamedItem(MAX_CONNECTION_USAGE_COUNT);
    Node poolingNode = attributes.getNamedItem(POOLING);
    Node pingNode = attributes.getNamedItem(PING);
    String poolName = null;
    org.glassfish.resources.api.Resource connectorConnPoolResource = new Resource(org.glassfish.resources.api.Resource.CONNECTOR_CONNECTION_POOL);
    if (nameNode != null) {
        poolName = getScopedName(nameNode.getNodeValue(), scope);
        connectorConnPoolResource.setAttribute(CONNECTION_POOL_NAME, poolName);
    }
    if (raConfigNode != null) {
        String raConfig = raConfigNode.getNodeValue();
        connectorConnPoolResource.setAttribute(RESOURCE_ADAPTER_CONFIG_NAME, raConfig);
    }
    if (conDefNode != null) {
        String conDef = conDefNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONN_DEF_NAME, conDef);
    }
    if (steadyPoolSizeNode != null) {
        String steadyPoolSize = steadyPoolSizeNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONN_STEADY_POOL_SIZE, steadyPoolSize);
    }
    if (maxPoolSizeNode != null) {
        String maxPoolSize = maxPoolSizeNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONN_MAX_POOL_SIZE, maxPoolSize);
    }
    if (poolResizeNode != null) {
        String poolResize = poolResizeNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONN_POOL_RESIZE_QUANTITY, poolResize);
    }
    if (idleTimeOutNode != null) {
        String idleTimeOut = idleTimeOutNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONN_IDLE_TIME_OUT, idleTimeOut);
    }
    if (failAllConnNode != null) {
        String failAllConn = failAllConnNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONN_FAIL_ALL_CONNECTIONS, failAllConn);
    }
    if (maxWaitTimeMillisNode != null) {
        String maxWaitTimeMillis = maxWaitTimeMillisNode.getNodeValue();
        connectorConnPoolResource.setAttribute(MAX_WAIT_TIME_IN_MILLIS, maxWaitTimeMillis);
    }
    if (transactionSupportNode != null) {
        String transactionSupport = transactionSupportNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONN_TRANSACTION_SUPPORT, transactionSupport);
    }
    if (connValidationReqdNode != null) {
        String connValidationReqd = connValidationReqdNode.getNodeValue();
        connectorConnPoolResource.setAttribute(IS_CONNECTION_VALIDATION_REQUIRED, connValidationReqd);
    }
    if (validateAtmostOncePeriodNode != null) {
        String validateAtmostOncePeriod = validateAtmostOncePeriodNode.getNodeValue();
        connectorConnPoolResource.setAttribute(VALIDATE_ATMOST_ONCE_PERIOD_IN_SECONDS, validateAtmostOncePeriod);
    }
    if (connLeakTimeoutNode != null) {
        String connLeakTimeout = connLeakTimeoutNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONNECTION_LEAK_TIMEOUT_IN_SECONDS, connLeakTimeout);
    }
    if (connLeakReclaimNode != null) {
        String connLeakReclaim = connLeakReclaimNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONNECTION_LEAK_RECLAIM, connLeakReclaim);
    }
    if (connCreationRetryAttemptsNode != null) {
        String connCreationRetryAttempts = connCreationRetryAttemptsNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONNECTION_CREATION_RETRY_ATTEMPTS, connCreationRetryAttempts);
    }
    if (connCreationRetryIntervalNode != null) {
        String connCreationRetryInterval = connCreationRetryIntervalNode.getNodeValue();
        connectorConnPoolResource.setAttribute(CONNECTION_CREATION_RETRY_INTERVAL_IN_SECONDS, connCreationRetryInterval);
    }
    if (lazyConnEnlistmentNode != null) {
        String lazyConnEnlistment = lazyConnEnlistmentNode.getNodeValue();
        connectorConnPoolResource.setAttribute(LAZY_CONNECTION_ENLISTMENT, lazyConnEnlistment);
    }
    if (lazyConnAssociationNode != null) {
        String lazyConnAssociation = lazyConnAssociationNode.getNodeValue();
        connectorConnPoolResource.setAttribute(LAZY_CONNECTION_ASSOCIATION, lazyConnAssociation);
    }
    if (associateWithThreadNode != null) {
        String associateWithThread = associateWithThreadNode.getNodeValue();
        connectorConnPoolResource.setAttribute(ASSOCIATE_WITH_THREAD, associateWithThread);
    }
    if (matchConnectionsNode != null) {
        String matchConnections = matchConnectionsNode.getNodeValue();
        connectorConnPoolResource.setAttribute(MATCH_CONNECTIONS, matchConnections);
    }
    if (maxConnUsageCountNode != null) {
        String maxConnUsageCount = maxConnUsageCountNode.getNodeValue();
        connectorConnPoolResource.setAttribute(MAX_CONNECTION_USAGE_COUNT, maxConnUsageCount);
    }
    if (poolingNode != null) {
        String pooling = poolingNode.getNodeValue();
        connectorConnPoolResource.setAttribute(POOLING, pooling);
    }
    if (pingNode != null) {
        String ping = pingNode.getNodeValue();
        connectorConnPoolResource.setAttribute(PING, ping);
    }
    NodeList children = nextKid.getChildNodes();
    // get description
    generatePropertyElement(connectorConnPoolResource, children);
    vResources.add(connectorConnPoolResource);
    resourceMap.put(connectorConnPoolResource, nextKid);
    // with the given poolname ..create security-map
    if (children != null) {
        for (int i = 0; i < children.getLength(); i++) {
            if ((children.item(i).getNodeName().equals(SECURITY_MAP)))
                generateSecurityMap(poolName, children.item(i), scope);
        }
    }
    // debug strings
    printResourceElements(connectorConnPoolResource);
}
Also used : Resource(org.glassfish.resources.api.Resource) 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