Beispiel #1
0
 def get_sap_system(self):
     '''
     get SAP system from profile path
     @types:  -> sap.System?
     '''
     #r: check client code that system can be None
     system, pf_name = sap_discoverer.parsePfDetailsFromPath(self._pf_path)
     try:
         system = sap_discoverer.parseSapSystemFromInstanceProfileName(pf_name)
     except ValueError, ve:
         msg = str(ve)
         logger.warn("Failed to parse %s profile name. " % self.SERVER_TYPE, msg)
Beispiel #2
0
    def process(self, context):
        r''' @types: applications.ApplicationSignatureContext '''
        # ------------------------------------------------------------ DISCOVERY
        "SAP TREX plug-in DISCOVERY start" | info
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # x) get process related application
        hostOsh = context.hostOsh
        application = context.application
        destinationIp = application.getConnectionIp()
        "x) Find TREX Daemon process that has profile path as parameter" | info
        mainProcess = findFirst(isMainTrexProcess,
                                context.application.getProcesses())
        profilePath = sap_discoverer.getProfilePathFromCommandline(
            mainProcess.commandLine)
        "x) Read profile content: %s" % profilePath | info
        getFileContent = Sfn(
            Fn(self.__getFileWithContent, shell, pathtools, __))
        profileFile = profilePath and getFileContent(profilePath)
        if not profileFile:
            "Plug-in flow broken. Failed to read instance profile\
content based on path from the TREXDaemon command line"                                                        | warn
            return

        "x) Instance profile parsing" | info
        sapIniParser = sap_discoverer.IniParser()
        instanceProfileParser = sap_discoverer.InstanceProfileParser(
            sapIniParser)
        defaultProfileParser = sap_trex_discoverer.DefaultProfileParser(
            sapIniParser)
        try:
            resultAsIni = instanceProfileParser.parseAsIniResult(
                profileFile.content)
            instanceProfile = instanceProfileParser.parse(resultAsIni)
            defaultProfile = defaultProfileParser.parse(resultAsIni)
        except Exception:
            logger.warnException("Failed to parse instance profile")
            return

        rfcConfigs = []
        trexSystem = defaultProfile.getSystem()
        trexInstance = instanceProfile.getInstance()
        trexInstanceName = trexInstance.getName() + trexInstance.getNumber()

        isBiaProduct = 0
        versionInfo = None
        #        # master by default, if topology file is not found that means
        #        # that current one is the only instance
        #        isMaster = 1

        trexTopology = None

        "x) Initialize TREX instance layout" | debug
        systemName = trexSystem.getName()
        systemBasePath = sap_discoverer.findSystemBasePath(
            mainProcess.getExecutablePath(), systemName)
        if systemBasePath:
            systemLayout = sap_trex_discoverer.SystemLayout(
                pathtools, systemBasePath, systemName)
            'System path: %s' % systemLayout.getRootPath() | info
            instancePath = systemLayout.composeInstanceDirPath(
                trexInstanceName)
            'Instance path: %s' % instancePath | debug
            instanceLayout = sap_trex_discoverer.InstanceLayout(
                pathtools, instancePath, trexInstanceName)

            "x) Get content of default profile as it contains information about product"
            "x) Determine whether we deal with BIA based on version information" | debug
            defaultProfilePath = systemLayout.getDefaultProfileFilePath()
            defaultProfileFile = getFileContent(defaultProfilePath)
            try:
                resultAsIni = instanceProfileParser.parseAsIniResult(
                    defaultProfileFile.content)
                defaultProfile = defaultProfileParser.parse(resultAsIni)
            except Exception:
                logger.warnException("Failed to parse default profile")
            else:
                isBiaProduct = defaultProfile.getProductType(
                ) == sap_trex.Product.BIA
            (isBiaProduct and "BIA" or "non-BIA", "product detected") | info

            # get instance host name from profile name
            instanceHostname = None
            try:
                destinationSystem = sap_discoverer.parseSapSystemFromInstanceProfileName(
                    profileFile.getName())
            except Exception:
                msg = "Failed to parse instance hostname from profile file name"
                logger.debugException(msg)
            else:
                instanceHostname = first(
                    destinationSystem.getInstances()).getHostname()

            "x) Discover whole topology from (topology.ini)" | info
            # topology.ini file location and format differs depending on the
            # product:
            # -a) BIA (has plain-ini file at <SID>/sys/global/trex/data/topology.ini
            # -b) TREX (has several places where topology.ini can be stored)
            discoverTopologyIniFilePath = fptools.safeFunc(
                sap_trex_discoverer.discoverTopologyIniFilePath)
            topologyFilePath = (isBiaProduct
                                and systemLayout.getTopologyIniPath()
                                or discoverTopologyIniFilePath(
                                    fs, instanceLayout, instanceHostname))

            topologyFile = topologyFilePath and getFileContent(
                topologyFilePath)
            if topologyFile:
                try:
                    configParser = sap_trex_discoverer.TopologyConfigParser()
                    trexTopology = sap_trex_discoverer.TrexTopologyConfig(
                        configParser.parse(topologyFile.content))
                    # find instance between master end-points


#                    landscapeSnapshot = topology.getGlobals().getLandscapeSnapshot()
#                    masterEndpoints = landscapeSnapshot.getMasterEndpoints()
#                    activeMasterEndpoints = landscapeSnapshot.getActiveMasterEndpoints()
#                    topologyNodes = topology.getHostNodes()
##
#                    isEndpointWithInstanceHostname = (lambda
#                        ep, hostname = instanceHostname: ep.getAddress() == hostname)
#                    isMaster = len(filter(isEndpointWithInstanceHostname,
#                           landscapeSnapshot.getMasterEndpoints()))
#                    "host role is %s" % (isMaster and "master" or "slave") | info
                except:
                    logger.warnException(
                        "Failed to parse topology configuration")
            else:
                logger.warn(
                    "Failed to get content for the topology configuration")

            "x) Discover TREX version information from saptrexmanifest.mf" | info
            # read version info from manifest file
            manifestFile = getFileContent(instanceLayout.getManifestFilePath())
            if manifestFile:
                manifestParser = sap_trex_discoverer.SapTrexManifestParser(
                    sapIniParser)
                versionInfo = manifestParser.parseVersion(manifestFile.content)
            else:
                'Failed to discover version from manifest file' | warn
                'Second attept to get version from updateConfig.ini file' | info
                profileSystem = Sfn(
                    sap_discoverer.parseSapSystemFromInstanceProfileName)(
                        profileFile.getName())
                if profileSystem:
                    hostname = first(
                        profileSystem.getInstances()).getHostname()
                    updateConfigFile = getFileContent(
                        instanceLayout.composeUpdateConfigIniFilePath(
                            hostname))
                    versionInfo = updateConfigFile and sap.VersionInfo(
                        updateConfigFile.content.strip())

            "x) Discover served systems ( in case if RFC configuration established )" | info
            rfcServerIniFilePath = (
                isBiaProduct and systemLayout.getRfcServerConfigFilePath()
                or instanceLayout.composeTrexRfcServerIniFilePath(
                    instanceHostname))

            rfcServerIniFile = getFileContent(rfcServerIniFilePath)
            if rfcServerIniFile:
                rfcConfigs = filter(None, (fptools.safeFunc(
                    sap_trex_discoverer.parseConnectionsInRfcServerIni)(
                        rfcServerIniFile.content)))

        # -------------------------------------------------------- REPORTING
        "SAP TREX plug-in REPORTING start" | info
        trexOsh = application.getOsh()
        vector = context.resultsVector
        configFileReporter = file_topology.Reporter(file_topology.Builder())
        trexReporter = sap_trex.Reporter(sap_trex.Builder())
        linkReporter = sap.LinkReporter()
        softwareBuilder = sap.SoftwareBuilder()
        "x) - report profile content as configuration document for the application" | info
        vector.add(configFileReporter.report(profileFile, trexOsh))
        ("x) - report %s" % trexSystem) | info
        trexSystemOsh = trexReporter.reportSystem(trexSystem)
        vector.add(trexSystemOsh)
        vector.add(linkReporter.reportMembership(trexSystemOsh, trexOsh))
        "x) - report instance name and version" | info
        softwareBuilder.updateName(trexOsh, trexInstanceName)
        "x) report instance number: %s" % trexInstance.getNumber() | info
        instanceBuilder = sap_trex.Builder()
        instanceBuilder.updateInstanceNumber(trexOsh, trexInstance.getNumber())
        if versionInfo:
            softwareBuilder.updateVersionInfo(trexOsh, versionInfo)
        if isBiaProduct:
            softwareBuilder.updateDiscoveredProductName(
                trexOsh, sap_trex.Product.BIA.instanceProductName)
        "x) report RFC connections" | info
        dnsResolver = netutils.DnsResolverByShell(shell, destinationIp)
        vector.addAll(reportRfcConfigs(rfcConfigs, dnsResolver, hostOsh))

        "x) report all topology nodes" | info
        if trexTopology:
            reportHostNode = fptools.partiallyApply(reportTrexHostNode,
                                                    fptools._, trexTopology,
                                                    isBiaProduct)
            vectors = map(reportHostNode, trexTopology.getHostNodes())
            fptools.each(vector.addAll, vectors)
Beispiel #3
0
    def process(self, context):
        r''' @types: applications.ApplicationSignatureContext '''
        # ------------------------------------------------------------ DISCOVERY
        "SAP TREX plug-in DISCOVERY start" | info
        shell = context.client
        fs = file_system.createFileSystem(shell)
        pathtools = file_system.getPath(fs)
        # x) get process related application
        hostOsh = context.hostOsh
        application = context.application
        destinationIp = application.getConnectionIp()
        "x) Find TREX Daemon process that has profile path as parameter" | info
        mainProcess = findFirst(isMainTrexProcess, context.application.getProcesses())
        profilePath = sap_discoverer.getProfilePathFromCommandline(mainProcess.commandLine)
        "x) Read profile content: %s" % profilePath | info
        getFileContent = Sfn(Fn(self.__getFileWithContent, shell, pathtools, __))
        profileFile = profilePath and getFileContent(profilePath)
        if not profileFile:
            "Plug-in flow broken. Failed to read instance profile\
content based on path from the TREXDaemon command line" | warn
            return

        "x) Instance profile parsing" | info
        sapIniParser = sap_discoverer.IniParser()
        instanceProfileParser = sap_discoverer.InstanceProfileParser(sapIniParser)
        defaultProfileParser = sap_trex_discoverer.DefaultProfileParser(sapIniParser)
        try:
            resultAsIni = instanceProfileParser.parseAsIniResult(profileFile.content)
            instanceProfile = instanceProfileParser.parse(resultAsIni)
            defaultProfile = defaultProfileParser.parse(resultAsIni)
        except Exception:
            logger.warnException("Failed to parse instance profile")
            return

        rfcConfigs = []
        trexSystem = defaultProfile.getSystem()
        trexInstance = instanceProfile.getInstance()
        trexInstanceName = trexInstance.getName() + trexInstance.getNumber()

        isBiaProduct = 0
        versionInfo = None
#        # master by default, if topology file is not found that means
#        # that current one is the only instance
#        isMaster = 1

        trexTopology = None

        "x) Initialize TREX instance layout" | debug
        systemName = trexSystem.getName()
        systemBasePath = sap_discoverer.findSystemBasePath(
                            mainProcess.getExecutablePath(), systemName )
        if systemBasePath:
            systemLayout = sap_trex_discoverer.SystemLayout(pathtools, systemBasePath, systemName)
            'System path: %s' % systemLayout.getRootPath() | info
            instancePath = systemLayout.composeInstanceDirPath(trexInstanceName)
            'Instance path: %s' % instancePath | debug
            instanceLayout = sap_trex_discoverer.InstanceLayout(pathtools, instancePath, trexInstanceName)

            "x) Get content of default profile as it contains information about product"
            "x) Determine whether we deal with BIA based on version information" | debug
            defaultProfilePath = systemLayout.getDefaultProfileFilePath()
            defaultProfileFile = getFileContent(defaultProfilePath)
            try:
                resultAsIni = instanceProfileParser.parseAsIniResult(defaultProfileFile.content)
                defaultProfile = defaultProfileParser.parse(resultAsIni)
            except Exception:
                logger.warnException("Failed to parse default profile")
            else:
                isBiaProduct = defaultProfile.getProductType() == sap_trex.Product.BIA
            (isBiaProduct and "BIA" or "non-BIA", "product detected") | info

            # get instance host name from profile name
            instanceHostname = None
            try:
                destinationSystem = sap_discoverer.parseSapSystemFromInstanceProfileName(profileFile.getName())
            except Exception:
                msg = "Failed to parse instance hostname from profile file name"
                logger.debugException(msg)
            else:
                instanceHostname = first(destinationSystem.getInstances()).getHostname()

            "x) Discover whole topology from (topology.ini)" | info
            # topology.ini file location and format differs depending on the
            # product:
            # -a) BIA (has plain-ini file at <SID>/sys/global/trex/data/topology.ini
            # -b) TREX (has several places where topology.ini can be stored)
            discoverTopologyIniFilePath = fptools.safeFunc(sap_trex_discoverer.discoverTopologyIniFilePath)
            topologyFilePath = (isBiaProduct
                and systemLayout.getTopologyIniPath()
                or  discoverTopologyIniFilePath(fs, instanceLayout, instanceHostname))

            topologyFile = topologyFilePath and getFileContent(topologyFilePath)
            if topologyFile:
                try:
                    configParser = sap_trex_discoverer.TopologyConfigParser()
                    trexTopology = sap_trex_discoverer.TrexTopologyConfig(
                                configParser.parse(topologyFile.content))
                    # find instance between master end-points
#                    landscapeSnapshot = topology.getGlobals().getLandscapeSnapshot()
#                    masterEndpoints = landscapeSnapshot.getMasterEndpoints()
#                    activeMasterEndpoints = landscapeSnapshot.getActiveMasterEndpoints()
#                    topologyNodes = topology.getHostNodes()
##
#                    isEndpointWithInstanceHostname = (lambda
#                        ep, hostname = instanceHostname: ep.getAddress() == hostname)
#                    isMaster = len(filter(isEndpointWithInstanceHostname,
#                           landscapeSnapshot.getMasterEndpoints()))
#                    "host role is %s" % (isMaster and "master" or "slave") | info
                except:
                    logger.warnException("Failed to parse topology configuration")
            else:
                logger.warn("Failed to get content for the topology configuration")

            "x) Discover TREX version information from saptrexmanifest.mf" | info
            # read version info from manifest file
            manifestFile = getFileContent(instanceLayout.getManifestFilePath())
            if manifestFile:
                manifestParser = sap_trex_discoverer.SapTrexManifestParser(sapIniParser)
                versionInfo = manifestParser.parseVersion(manifestFile.content)
            else:
                'Failed to discover version from manifest file' | warn
                'Second attept to get version from updateConfig.ini file' | info
                profileSystem = Sfn(sap_discoverer.parseSapSystemFromInstanceProfileName)(profileFile.getName())
                if profileSystem:
                    hostname = first(profileSystem.getInstances()).getHostname()
                    updateConfigFile = getFileContent(instanceLayout.composeUpdateConfigIniFilePath(hostname))
                    versionInfo = updateConfigFile and sap.VersionInfo(updateConfigFile.content.strip())

            "x) Discover served systems ( in case if RFC configuration established )" | info
            rfcServerIniFilePath = (isBiaProduct
                    and systemLayout.getRfcServerConfigFilePath()
                    or instanceLayout.composeTrexRfcServerIniFilePath(instanceHostname))

            rfcServerIniFile = getFileContent(rfcServerIniFilePath)
            if rfcServerIniFile:
                rfcConfigs = filter(None, (fptools.safeFunc(
                    sap_trex_discoverer.parseConnectionsInRfcServerIni)
                        (rfcServerIniFile.content)))

        # -------------------------------------------------------- REPORTING
        "SAP TREX plug-in REPORTING start" | info
        trexOsh = application.getOsh()
        vector = context.resultsVector
        configFileReporter = file_topology.Reporter(file_topology.Builder())
        trexReporter = sap_trex.Reporter(sap_trex.Builder())
        linkReporter = sap.LinkReporter()
        softwareBuilder = sap.SoftwareBuilder()
        "x) - report profile content as configuration document for the application" | info
        vector.add(configFileReporter.report(profileFile, trexOsh))
        ("x) - report %s" % trexSystem) | info
        trexSystemOsh = trexReporter.reportSystem(trexSystem)
        vector.add(trexSystemOsh)
        vector.add(linkReporter.reportMembership(trexSystemOsh, trexOsh))
        "x) - report instance name and version" | info
        softwareBuilder.updateName(trexOsh, trexInstanceName)
        "x) report instance number: %s" % trexInstance.getNumber() | info
        instanceBuilder = sap_trex.Builder()
        instanceBuilder.updateInstanceNumber(trexOsh, trexInstance.getNumber())
        if versionInfo:
            softwareBuilder.updateVersionInfo(trexOsh, versionInfo)
        if isBiaProduct:
            softwareBuilder.updateDiscoveredProductName(trexOsh,
                                    sap_trex.Product.BIA.instanceProductName)
        "x) report RFC connections" | info
        dnsResolver = netutils.DnsResolverByShell(shell, destinationIp)
        vector.addAll(reportRfcConfigs(rfcConfigs, dnsResolver, hostOsh))

        "x) report all topology nodes" | info
        if trexTopology:
            reportHostNode = fptools.partiallyApply(reportTrexHostNode,
                                     fptools._, trexTopology, isBiaProduct)
            vectors = map(reportHostNode, trexTopology.getHostNodes())
            fptools.each(vector.addAll, vectors)