def _findWebModule(self, name, path):
        r''' Module detected by presence of file 'WEB-INF/web.xml' in specified path
        @types: str, str -> jee.WebModule
        @raise ValueError: JEE descriptor is not found
        '''
        webModule = jee.WebModule(name)

        logger.info("Find WAR descriptor files for '%s'" % name)
        path = self.getLayout().path().normalizePath(path)
        files = self.getLayout().findWebDescriptorFiles(path)

        # split descriptors by type - jee or runtime
        jeeDescriptors, runtimeDescriptors = self._splitDescriptorFilesByType(files, 'web.xml')
        if jeeDescriptors:
            try:
                logger.info('Get WEB deployment descriptor content')
                file = self.getLayout().getFileContent(jeeDescriptors[0].path)
                webModule.addConfigFiles(jee.createXmlConfigFile(file))
                descriptor = self._getDescriptorParser().parseWebApplicationDescriptor(file.content)
                for servlet in descriptor.getServlets():
                    webModule.addEntry(servlet)
            except (Exception, JException):
                logger.warnException("Failed to process web.xml")
            # process runtime descriptor files
            for file in runtimeDescriptors:
                try:
                    fileWithContent = self.getLayout().getFileContent(file.path)
                    webModule.addConfigFiles(jee.createXmlConfigFile(fileWithContent))
                except (Exception, JException):
                    logger.warnException("Failed to load content for runtime descriptor: %s" % file.name)
        else:
            raise ValueError("JEE descriptor is not found")
        return webModule
    def discoverEarApplication(self, name, path, jndiNameToName = None):
        application = jee_discoverer.BaseApplicationDiscovererByShell.discoverEarApplication(self, name, path, jndiNameToName)
        # app scope jdbc & jms
        files = filter(lambda f: re.match(self._getDescriptorParser().WEBLOGIC_APPLICATION_FILE_NAME, f.getName(), re.IGNORECASE),
                           application.getConfigFiles())
        if files:
            try:
                logger.debug('Parsing weblogic application file %s for %s' % (files[0].name, application))
                application_resources = self._getDescriptorParser().parseWeblogicApplicationDescriptor(files[0].content)
                # jdbc & jms
                for resource_type in ('JDBC', 'JMS'):
                    for config in application_resources.getResourceByType(resource_type):
                        config_file = config['path']
                        if not self.getLayout().path().isAbsolute( config_file ):
                            config_file = self.getLayout().path().join(path, config_file)
                        config_file = self.getLayout().path().normalizePath(config_file)
                        try:
                            logger.debug('Parsing %s config file %s for %s' % (resource_type, config_file, application))
                            fileWithContent = self.getLayout().getFileContent(config_file)
                            application.addConfigFiles(jee.createXmlConfigFile(fileWithContent))
                        except (Exception, JException):
                            logger.warnException(
                                "Failed to load content for %s descriptor: %s" % (resource_type, config_file))
            except (Exception, JException):
                logger.warnException('Failed to process weblogic application file %s for %s' % (files[0].name, application))

        return application
Example #3
0
    def discoverEarApplication(self, name, path, jndiNameToName=None):
        application = jee_discoverer.BaseApplicationDiscovererByShell.discoverEarApplication(
            self, name, path, jndiNameToName)
        # app scope jdbc & jms
        files = filter(
            lambda f: re.match(
                self._getDescriptorParser().WEBLOGIC_APPLICATION_FILE_NAME,
                f.getName(), re.IGNORECASE), application.getConfigFiles())
        if files:
            try:
                logger.debug('Parsing weblogic application file %s for %s' %
                             (files[0].name, application))
                application_resources = self._getDescriptorParser(
                ).parseWeblogicApplicationDescriptor(files[0].content)
                # jdbc & jms
                for resource_type in ('JDBC', 'JMS'):
                    for config in application_resources.getResourceByType(
                            resource_type):
                        config_file = config['path']
                        if not self.getLayout().path().isAbsolute(config_file):
                            config_file = self.getLayout().path().join(
                                path, config_file)
                        config_file = self.getLayout().path().normalizePath(
                            config_file)
                        try:
                            logger.debug(
                                'Parsing %s config file %s for %s' %
                                (resource_type, config_file, application))
                            fileWithContent = self.getLayout().getFileContent(
                                config_file)
                            application.addConfigFiles(
                                jee.createXmlConfigFile(fileWithContent))
                        except (Exception, JException):
                            logger.warnException(
                                "Failed to load content for %s descriptor: %s"
                                % (resource_type, config_file))
            except (Exception, JException):
                logger.warnException(
                    'Failed to process weblogic application file %s for %s' %
                    (files[0].name, application))

        return application
Example #4
0
                # find unique endpoints

                if len(adminServerEndpointByName) > 1:
                    logger.info("""After analyze of running processes in single domain \
                    found servers pointing to different administrative servers
                    """)
                    logger.debug(adminServerEndpointByName)
                adminServerEndpoint = (len(adminServerEndpointByName) == 1 and
                                        adminServerEndpointByName.values()[0])

                domain = jee.Domain(domainDescriptor.getName())
                # add known clusters to the domain
                clusters = domainDescriptor.getClusters()
                each(domain.addCluster, clusters)
                # add config.xml to the domain
                domain.addConfigFiles(jee.createXmlConfigFile(domainDescriptorFile))

                deploymentTargetByName = applyMapping(jee.Cluster.getName, clusters)

                machineByName = applyMapping(
                    weblogic_discoverer.DomainConfigurationDescriptor.Machine.getName,
                    domainDescriptor.getMachines()
                )

                # find corresponding process for each discovered server to
                # provide additional information that can be overridden
                resolvedServers = []
                servers = domainDescriptor.getServers()
                # for 7-8 versions config.xml hasn't info about admin-server at all
                # try to get 1st server created by config wizard to set is as admin:
                if platformTrait.majorVersion.value() < 9:
Example #5
0
                debugGroupping(runtimesByCellName)
                if len(runtimesByCellName) > 1:
                    logger.warn("Configuration where more than one cell in one profile is not supported")
                    continue
                # parse cell configuration and get deployment type
                profileHomeDirPath = pathUtil.dirName(configDirPath)
                profileLayout = websphere_discoverer.ProfileLayout(
                                   profileHomeDirPath, fs)
                cellName = runtimesByCellName.keys()[0]
                cellLayout = websphere_discoverer.CellLayout(
                                    profileLayout.composeCellHomePath(cellName), fs)
                cellConfigFile = cellLayout.getFileContent(cellLayout.getConfigFilePath() )
                cell = parser.parseCellConfig(cellConfigFile.content)

                securityConfigFile = cellLayout.getFile(cellLayout.getSecurityConfigFilePath())
                cell.addConfigFile(jee.createXmlConfigFile(securityConfigFile))

                cellConfigFileToReport = cellLayout.getFile(cellLayout.getConfigFilePath())
                cell.addConfigFile(jee.createXmlConfigFile(cellConfigFileToReport))

                cellResourceConfigFile = cellLayout.getFile(cellLayout.getResourcesConfigFilePath())
                cell.addConfigFile(jee.createXmlConfigFile(cellResourceConfigFile))

                NameBindingContent = None
                try:
                    NameBindingConfigFile = cellLayout.getFile(cellLayout.getNameBindingConfigFile())
                    cell.addConfigFile(jee.createXmlConfigFile(NameBindingConfigFile))
                    NameBindingContent = cellLayout.getFileContent(cellLayout.getNameBindingConfigFile())
                except:
                    logger.debug('Cannot find namebindings.xml for cell: ', cell)
     logger.info("Find EAR descriptor files for '%s'" % name)
     path = self.getLayout().path().normalizePath(path)
     files = self.getLayout().findEarDescriptorFiles(path)
 except (Exception, JException), exc:
     logger.warn("Failed to find descriptor files for enterprise application. %s" % exc)
 else:
     jeeDescriptors, runtimeDescriptors = self._splitDescriptorFilesByType(files, 'application.xml')
     if jeeDescriptors:
         try:
             logger.info("Get JEE deployment descriptor content")
             file = self.getLayout().getFileContent(jeeDescriptors[0].path)
             descriptor = self._getDescriptorParser().parseApplicationDescriptor(file.content)
         except (Exception, JException), exc:
             logger.warnException("Failed to parse application.xml. %s" % exc)
         else:
             application.addConfigFiles(jee.createXmlConfigFile(file))
             # discover details about WEB modules if they are unpacked
             # web modules after deploy are unpacked in the EAR folder
             # as contain static data accessible by the web container
             for module in descriptor.getWebModules():
                 webModule = module
                 modulePath = self.getLayout().composeModulePathByEarPath(path, module.getName())
                 try:
                     webModule = self._findWebModule(module.getName(), modulePath)
                 except file_system.PathNotFoundException, e:
                     logger.warn("Failed to get web module descriptor. %s" % e)
                 except (Exception, JException), e:
                     logger.warnException("Failed to find descriptor files for web application. %s" % e)
                 if module.contextRoot:
                     webModule.contextRoot = module.contextRoot
                 application.addModules(webModule)
Example #7
0
                    )
                    continue
                # parse cell configuration and get deployment type
                profileHomeDirPath = pathUtil.dirName(configDirPath)
                profileLayout = websphere_discoverer.ProfileLayout(
                    profileHomeDirPath, fs)
                cellName = runtimesByCellName.keys()[0]
                cellLayout = websphere_discoverer.CellLayout(
                    profileLayout.composeCellHomePath(cellName), fs)
                cellConfigFile = cellLayout.getFileContent(
                    cellLayout.getConfigFilePath())
                cell = parser.parseCellConfig(cellConfigFile.content)

                securityConfigFile = cellLayout.getFile(
                    cellLayout.getSecurityConfigFilePath())
                cell.addConfigFile(jee.createXmlConfigFile(securityConfigFile))

                cellConfigFileToReport = cellLayout.getFile(
                    cellLayout.getConfigFilePath())
                cell.addConfigFile(
                    jee.createXmlConfigFile(cellConfigFileToReport))

                cellResourceConfigFile = cellLayout.getFile(
                    cellLayout.getResourcesConfigFilePath())
                cell.addConfigFile(
                    jee.createXmlConfigFile(cellResourceConfigFile))

                NameBindingContent = None
                try:
                    NameBindingConfigFile = cellLayout.getFile(
                        cellLayout.getNameBindingConfigFile())
Example #8
0
                if len(adminServerEndpointByName) > 1:
                    logger.info(
                        """After analyze of running processes in single domain \
                    found servers pointing to different administrative servers
                    """)
                    logger.debug(adminServerEndpointByName)
                adminServerEndpoint = (len(adminServerEndpointByName) == 1 and
                                       adminServerEndpointByName.values()[0])

                domain = jee.Domain(domainDescriptor.getName())
                # add known clusters to the domain
                clusters = domainDescriptor.getClusters()
                each(domain.addCluster, clusters)
                # add config.xml to the domain
                domain.addConfigFiles(
                    jee.createXmlConfigFile(domainDescriptorFile))

                deploymentTargetByName = applyMapping(jee.Cluster.getName,
                                                      clusters)

                machineByName = applyMapping(
                    weblogic_discoverer.DomainConfigurationDescriptor.Machine.
                    getName, domainDescriptor.getMachines())

                # find corresponding process for each discovered server to
                # provide additional information that can be overridden
                resolvedServers = []
                servers = domainDescriptor.getServers()
                # for 7-8 versions config.xml hasn't info about admin-server at all
                # try to get 1st server created by config wizard to set is as admin:
                if platformTrait.majorVersion.value() < 9: