Search in sources :

Example 1 with ResourcesXMLParser

use of org.glassfish.resources.admin.cli.ResourcesXMLParser in project Payara by payara.

the class ResourcesDeployer method processArchive.

private void processArchive(DeploymentContext dc) {
    try {
        ReadableArchive archive = dc.getSource();
        if (ResourceUtil.hasGlassfishResourcesXML(archive, locator) || ResourceUtil.hasPayaraResourcesXML(archive, locator)) {
            Map<String, Map<String, List>> appScopedResources = new HashMap<>();
            Map<String, List<String>> jndiNames = new HashMap<>();
            List<Map.Entry<String, String>> raNames = new ArrayList<>();
            Map<String, String> fileNames = new HashMap<>();
            String appName = getAppNameFromDeployCmdParams(dc);
            // using appName as it is possible that "deploy --name=APPNAME" will
            // be different than the archive name.
            retrieveAllResourcesXMLs(fileNames, archive, appName);
            for (Map.Entry<String, String> entry : fileNames.entrySet()) {
                String moduleName = entry.getKey();
                String fileName = entry.getValue();
                debug("Sun Resources XML : " + fileName);
                moduleName = org.glassfish.resourcebase.resources.util.ResourceUtil.getActualModuleNameWithExtension(moduleName);
                String scope;
                if (appName.equals(moduleName)) {
                    scope = JAVA_APP_SCOPE_PREFIX;
                } else {
                    scope = JAVA_MODULE_SCOPE_PREFIX;
                }
                File file = new File(fileName);
                ResourcesXMLParser parser = new ResourcesXMLParser(file, scope);
                validateResourcesXML(file, parser);
                List list = parser.getResourcesList();
                Map<String, List> resourcesList = new HashMap<>();
                List<String> jndiNamesList = new ArrayList<>();
                List<org.glassfish.resources.api.Resource> nonConnectorResources = ResourcesXMLParser.getNonConnectorResourcesList(list, false, true);
                resourcesList.put(NON_CONNECTOR_RESOURCES, nonConnectorResources);
                for (org.glassfish.resources.api.Resource resource : nonConnectorResources) {
                    String jndiName = extractJNDIName(resource);
                    if (hasRAName(resource)) {
                        raNames.add(new AbstractMap.SimpleEntry<>(extractRAName(resource), resource.getType()));
                    }
                    if (jndiName != null) {
                        jndiNamesList.add(jndiName);
                    }
                }
                List<org.glassfish.resources.api.Resource> connectorResources = ResourcesXMLParser.getConnectorResourcesList(list, false, true);
                resourcesList.put(CONNECTOR_RESOURCES, connectorResources);
                for (org.glassfish.resources.api.Resource resource : connectorResources) {
                    String jndiName = extractJNDIName(resource);
                    if (hasRAName(resource)) {
                        raNames.add(new AbstractMap.SimpleEntry<>(extractRAName(resource), resource.getType()));
                    }
                    if (jndiName != null) {
                        jndiNamesList.add(jndiName);
                    }
                }
                jndiNames.put(moduleName, jndiNamesList);
                appScopedResources.put(moduleName, resourcesList);
            }
            dc.addTransientAppMetaData(APP_SCOPED_RESOURCES_JNDI_NAMES, jndiNames);
            dc.addTransientAppMetaData(APP_SCOPED_RESOURCES_RA_NAMES, raNames);
            dc.addTransientAppMetaData(APP_SCOPED_RESOURCES_MAP, appScopedResources);
            ApplicationInfo appInfo = appRegistry.get(appName);
            if (appInfo != null) {
                Application app = dc.getTransientAppMetaData(ServerTags.APPLICATION, Application.class);
                appInfo.addTransientAppMetaData(ServerTags.APPLICATION, app);
            }
        }
    } catch (Exception e) {
        // in the event notification infrastructure
        throw new DeploymentException("Failue while processing glassfish-resources.xml(s) in the archive ", e);
    }
}
Also used : ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) org.glassfish.resources.api(org.glassfish.resources.api) ResourcesXMLParser(org.glassfish.resources.admin.cli.ResourcesXMLParser) Resource(com.sun.enterprise.config.serverbeans.Resource) Resource(org.glassfish.resources.api.Resource) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) DeploymentException(org.glassfish.deployment.common.DeploymentException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) Resource(org.glassfish.resources.api.Resource) DeploymentException(org.glassfish.deployment.common.DeploymentException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) File(java.io.File)

Example 2 with ResourcesXMLParser

use of org.glassfish.resources.admin.cli.ResourcesXMLParser in project Payara by payara.

the class ResourcesDeployer method getResources.

/**
 * Retrieve connector and non-connector resources from the archive.
 *
 * @param archive Archieve from which the resources to be retrieved.
 * @param appName Name of the application
 * @param connectorResources Connector resources will be added to this list.
 * @param nonConnectorResources Non connector resources will be added to this list.
 * @param resourceXmlParsers Resource xml parsers corresponding to both connector and non connector resources will be stored in this.
 */
public void getResources(ReadableArchive archive, String appName, List<org.glassfish.resources.api.Resource> connectorResources, List<org.glassfish.resources.api.Resource> nonConnectorResources, Map<org.glassfish.resources.api.Resource, ResourcesXMLParser> resourceXmlParsers) {
    try {
        if (ResourceUtil.hasGlassfishResourcesXML(archive, locator) || ResourceUtil.hasPayaraResourcesXML(archive, locator)) {
            Map<String, Map<String, List>> appScopedResources = new HashMap<String, Map<String, List>>();
            Map<String, String> fileNames = new HashMap<String, String>();
            // using appName as it is possible that "deploy --name=APPNAME" will
            // be different than the archive name.
            retrieveAllResourcesXMLs(fileNames, archive, appName);
            for (Map.Entry<String, String> entry : fileNames.entrySet()) {
                String moduleName = entry.getKey();
                String fileName = entry.getValue();
                debug("GlassFish Resources XML : " + fileName);
                moduleName = org.glassfish.resourcebase.resources.util.ResourceUtil.getActualModuleNameWithExtension(moduleName);
                String scope;
                if (appName.equals(moduleName)) {
                    scope = JAVA_APP_SCOPE_PREFIX;
                } else {
                    scope = JAVA_MODULE_SCOPE_PREFIX;
                }
                File file = new File(fileName);
                ResourcesXMLParser parser = new ResourcesXMLParser(file, scope);
                validateResourcesXML(file, parser);
                List<org.glassfish.resources.api.Resource> resources = parser.getResourcesList();
                if (nonConnectorResources != null) {
                    nonConnectorResources.addAll(ResourcesXMLParser.getNonConnectorResourcesList(resources, false, true));
                }
                if (connectorResources != null) {
                    connectorResources.addAll(ResourcesXMLParser.getConnectorResourcesList(resources, false, true));
                }
                if (resourceXmlParsers != null) {
                    for (org.glassfish.resources.api.Resource res : resources) {
                        resourceXmlParsers.put(res, parser);
                    }
                }
            }
        }
    } catch (Exception e) {
        // in the event notification infrastructure
        throw new DeploymentException("Failue while processing glassfish-resources.xml(s) in the archive ", e);
    }
}
Also used : ResourcesXMLParser(org.glassfish.resources.admin.cli.ResourcesXMLParser) Resource(com.sun.enterprise.config.serverbeans.Resource) Resource(org.glassfish.resources.api.Resource) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) DeploymentException(org.glassfish.deployment.common.DeploymentException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) Resource(org.glassfish.resources.api.Resource) DeploymentException(org.glassfish.deployment.common.DeploymentException) org.glassfish.resources.api(org.glassfish.resources.api) File(java.io.File)

Aggregations

Resource (com.sun.enterprise.config.serverbeans.Resource)2 File (java.io.File)2 IOException (java.io.IOException)2 ResourceException (javax.resource.ResourceException)2 DeploymentException (org.glassfish.deployment.common.DeploymentException)2 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)2 ResourcesXMLParser (org.glassfish.resources.admin.cli.ResourcesXMLParser)2 org.glassfish.resources.api (org.glassfish.resources.api)2 Resource (org.glassfish.resources.api.Resource)2 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)1