Ejemplo n.º 1
0
def buildDBObjects(db_type, host_ip, db_port, db_name, db_sid, appServerOSH, OSHVResult):
	logger.debug('building TNS Entry ', db_type, host_ip, db_name, db_port, db_sid)

	oshs = []
	hostOSH = modeling.createHostOSH(host_ip)
	oshs.append(hostOSH)
	dbOSH, ipseOsh, databaseOshs = None, None, None

	platform = db_platform.findPlatformBySignature(db_type)
	if not platform:
		logger.warn("Failed to determine platform for %s" % db_type)
	else:
		dbserver = db_builder.buildDatabaseServerPdo(db_type, db_name, host_ip, db_port)
		if not db_name and not db_port:
			builder = db_builder.Generic()
		else:
			builder = db_builder.getBuilderByPlatform(platform)

		dbTopologyReporter = db.TopologyReporter(builder)
		result = dbTopologyReporter.reportServerWithDatabases(dbserver,
															  hostOSH,
															  (appServerOSH,))
		dbOSH, ipseOsh, databaseOshs, vector_ = result
		oshs.extend(vector_)

	OSHVResult.addAll(oshs)
Ejemplo n.º 2
0
    def reportDatabaseTopology(self, dsnInfo, dependentObject):
        """

        :param dsnInfo: list of all DSN's for which need to report topology
        :type dsnInfo: odbc.DSNInfo
        :return: vector which include all osh's for created topology
        :rtype: appilog.common.system.types.vectors.ObjectStateHolderVector
        """
        vector = ObjectStateHolderVector()
        try:
            database_pdo = self.__builder.buildDatabaseServerPdo(dsnInfo)
            platform = db_platform.findPlatformBySignature(dsnInfo.driver)
            builder = db_builder.getBuilderByPlatform(platform)
            db_reporter = db.getReporter(platform, builder)
            host_descriptor = self.__builder.buildHostDescriptor(dsnInfo.address)
            host_descriptor = host_descriptor._replace(name=None)
            reporter = host_topology.Reporter()
            host_osh, ip_oshs, oshs = reporter.report_host(host_descriptor)
            server_osh, ipseOsh, database_oshs, topology = db_reporter.reportServerWithDatabases(database_pdo, host_osh, [dependentObject])
            vector.addAll(topology)
            vector.addAll(oshs)
            return vector
        except dns_resolver.ResolveException:
            logger.reportWarning("Cannot resolve ip of node")
            return ObjectStateHolderVector()
Ejemplo n.º 3
0
def _reportDatabase(dbInfo):
    dbServer, platform, ips = dbInfo
    hostReporter = sap.HostReporter(sap.HostBuilder())
    hostOsh, hVector = hostReporter.reportHostWithIps(*ips)
    builder = db_builder.getBuilderByPlatform(platform)
    reporter = db.TopologyReporter(builder)
    serverOsh = reporter.reportServer(dbServer, hostOsh)

    vector = ObjectStateHolderVector()
    vector.add(serverOsh)
    vector.addAll(hVector)
    return vector
Ejemplo n.º 4
0
def report_db(server, host_osh, dependants):
    r'''@types: db.DatabaseServer, osh, seq[osh] -> tuple[osh, list[osh]]
    @raise ValueError: Platform is not found
    @return: tuple of built server OSH and vector where all related topology
    included
    '''
    oshs = []

    builder = db_builder.getBuilderByPlatform(server.getPlatform())
    reporter = db.getReporter(server.getPlatform(), builder)

    result = reporter.reportServerWithDatabases(server, host_osh, dependants)
    server_osh, _, _, vector_ = result
    oshs.extend(vector_)
    return server_osh, oshs
Ejemplo n.º 5
0
 def reportDatasources(self, container, *datasources):
     r'@types: entity.HasOsh, tuple(jdbc.Datasource)'
     if not (container and container.getOsh()):
         raise ValueError("Datasource container is not specified or not built")
     vector = ObjectStateHolderVector()
     for datasource in datasources:
         vector.addAll(self.reportDataSource(datasource, container))
         # based on URL we can report information about database server and used databases
         if datasource.url:
             try:
                 urlParser = jdbc_url_parser.getUrlParser(datasource.url)
             except (Exception, JException):
                 logger.warnException("Failed to find appropriate parser for the url %s " % datasource.url)
             else:
                 logger.debug("Use %s for %s" % (urlParser, datasource.url))
                 try:
                     parsedResult = urlParser.parse(datasource.url)
                 except (Exception, JException):
                     logger.warnException("Failed to parse datasource URL")
                 else:
                     # dispatch reporting of parsed result as parse method
                     # may return different types like DatabaseServer and OracleRac
                     vector.addAll(self.__reportParsedData(
                         urlParser.getPlatform(), datasource, parsedResult))
         elif datasource.getServer():
             # resolve address
             server = datasource.getServer()
             if server.address:
                 try:
                     ips = self.__dnsResolver.resolveIpsByHostname(server.address)
                     server.address = ips[0]
                 except (Exception, JException):
                     logger.warnException("Failed to resolve IP for the %s" % server)
                 else:
                     # report database server using generic builder if one is not found by the signature
                     signature = ';'.join(map(str, (datasource.description, datasource.driverClass)))
                     platform = db_platform.findPlatformBySignature(signature)
                     if platform:
                         databaseBuilder = db_builder.getBuilderByPlatform(platform)
                     else:
                         databaseBuilder = db_builder.Generic()
                     databaseServerReporter = db.getReporter(platform, databaseBuilder)
                     _, _, _, oshs = databaseServerReporter.reportServerWithDatabasesFromAddress(server, (datasource.getOsh(), ))
                     vector.addAll(oshs)
     return vector
Ejemplo n.º 6
0
 def __reportParsedServer(self, platform, datasource, databaseServer):
     vector = ObjectStateHolderVector()
     # get merged database server instance
     server = self.__mergeDatabaseServers(datasource.getServer(), databaseServer)
     # If server doesn't contain databases we can create one from the datasource information if present
     if not server.getDatabases() and datasource.databaseName:
         server.addDatabases(db.Database(datasource.databaseName))
     # resolve address
     try:
         ips = self.__dnsResolver.resolveIpsByHostname(server.address)
         server.address = ips[0]
     except (Exception, JException):
         logger.warnException("Failed to resolve IP for the %s" % server.address)
     else:
         # report database server
         databaseBuilder = db_builder.getBuilderByPlatform(platform)
         databaseServerReporter = db.getReporter(platform, databaseBuilder)
         _, _, _, oshs = databaseServerReporter.reportServerWithDatabasesFromAddress(server, (datasource.getOsh(), ))
         vector.addAll(oshs)
     return vector
Ejemplo n.º 7
0
    def __reportOracleRac(self, platform, datasource, rac):
        r'@types: db_platform.Oracle, jdbc.Datasource, db.OracleRac -> ObjectStateHolderVector'
        logger.info("Report Oracle RAC %s" % rac)
        # Resolve addresses for all server instances in the RAC
        resolvedServers = []
        for server in rac.getServers():
            if not netutils.isValidIp(server.address):
                try:
                    ips = self.__dnsResolver.resolveIpsByHostname(server.address)
                    server.address = ips[0]
                    resolvedServers.append(server)
                except (Exception, JException):
                    logger.warnException("Failed to resolve IP for the %s" % server)
            else:
                resolvedServers.append(server)
        # After attempt to resolve addresses of RAC instances we will use only
        # with resolved address
        resolvedServers = filter(db.DatabaseServer.getPort, resolvedServers)
        if not resolvedServers:
            raise ValueError("None of RAC instances were resolved")
        # Prepare builders and reporters for RAC and db servers
        databaseBuilder = db_builder.getBuilderByPlatform(platform)
        databaseServerReporter = db.TopologyReporter(databaseBuilder)
        racReporter = db.OracleRacTopologyReporter(db_builder.OracleRacBuilder())

        vector = ObjectStateHolderVector()
        # Report RAC
        racOsh = racReporter.reportRac(rac)
        vector.add(racOsh)
        for server in resolvedServers:
            # Report each resolved server
            vector.addAll(databaseServerReporter.reportDatabaseServerFromAddress(server))
            # report link between RAC and server
            vector.add(racReporter.linkRacWithDbServer(racOsh, server.getOsh()))
        # Report dependency link between datasource and RAC
        vector.add(modeling.createLinkOSH('depend', datasource.getOsh(), racOsh))
        return vector
Ejemplo n.º 8
0
                dbServer = db.DatabaseServer(
                    dbServer.address,
                    dbServer.getPort(),
                    dbServer.instance,
                    dbServer.getDatabases(),
                    dbServer.vendor,
                    engine.getVersionDescription(),
                    dbServer.getPlatform(),
                    dbServer.getVersion(),
                    engine.getDescription(),
                )
                break

        # determine builder using vendor of instance DB software
        platform = dbServer.getPlatform() or db_platform.findPlatformBySignature(dbServer.vendor)
        dbReporter = db.TopologyReporter(db_builder.getBuilderByPlatform(platform))

        rdsReporter = aws_rds.Reporter(aws_rds.Builder())
        # report instance node
        nodeOsh = rdsReporter.reportInstanceNode(instance)
        vector.add(nodeOsh)
        vector.add(rdsReporter.linkAccountWithInstanceNode(accountOsh, nodeOsh))
        # report instance (node as container)
        instanceOsh = dbReporter.reportServer(dbServer, nodeOsh)
        vector.add(instanceOsh)
        # membership link between instance node + availability zone
        zoneName = instance.getAvailabilityZoneName()
        if zoneName:
            zoneOsh = awsReporter.reportAvailabilityZoneByName(zoneName)
            vector.add(zoneOsh)
            vector.add(rdsReporter.linkZoneWithInstanceNode(zoneOsh, nodeOsh))