Esempio 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)
Esempio 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()
Esempio n. 3
0
def getDatabaseCcms(sapUtils, systemName):
    '''
    Discovers Databases from Computing Center Management System
    @Types SapUtils, str -> list[tuple[db.DatabaseServer, jdbc.Datasource]]
    '''
    logger.debug('Getting database details from CCMS.getDatabase')
    databases = sapUtils.getDatabase(systemName)
    databaseCount = databases.getRowCount()
    logger.debug('Found %s databases' % databaseCount)
    database_datasource_pairs = []
    for i in range(databaseCount):
        type_ = databases.getCell(i, 1)
        name = databases.getCell(i, 0)
        host = databases.getCell(i, 3)
        if not type_:
            logger.warn("Unknown type of '%s' database at '%s'" % (name, host))
            continue
        type_ = type_.upper()
        dbVersion = databases.getCell(i, 2)
        details = ('name:', name, ' Type:', type_,
                   ' Version:', dbVersion, ' on Host:', host)
        logger.debug('Found Database with following details:', details)
        dbPlatform = db_platform.findPlatformBySignature(type_)
        if not dbPlatform:
            logger.debug('Unknown platform for DB type %s' % type_)
        port = None
        server = db_builder.buildDatabaseServerPdo(type_, name, host, port)
        server.setVersion(dbVersion)

        datasource = jdbc.Datasource(name)
        database_datasource_pairs.append((server, datasource))
    return database_datasource_pairs
Esempio n. 4
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)
Esempio n. 5
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()
Esempio n. 6
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
Esempio n. 7
0
def buildDatabaseServerPdo(type_, db_name, address, port):
    r'''
    @types: str, str, str, str -> db.DatabaseServer
    @raise ValueError: Platform is not found
    '''
    platform = db_platform.findPlatformBySignature(type_)
    args = (type_, db_name, address, port, platform)
    builder_fn = _db_pdo_builder_by_platform.get(platform)
    builder_fn = builder_fn or _buildGenericDatabaseServerPdo
    return builder_fn(*args)
Esempio n. 8
0
def buildDatabaseServerPdo(type_, db_name, address, port):
    r'''
    @types: str, str, str, str -> db.DatabaseServer
    @raise ValueError: Platform is not found
    '''
    platform = db_platform.findPlatformBySignature(type_)
    args = (type_, db_name, address, port, platform)
    builder_fn = _db_pdo_builder_by_platform.get(platform)
    builder_fn = builder_fn or _buildGenericDatabaseServerPdo
    return builder_fn(*args)
Esempio n. 9
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
Esempio n. 10
0
    def _converttoDbInstance(self, item):
        r'''@types: com.amazonaws.services.rds.model.DBInstance -> aws_rds.Instance

        getDBParameterGroups()#rovides the list of DB Parameter Groups applied to this DB Instance.
            com.amazonaws.services.rds.model.DBParameterGroupStatus
            getDBParameterGroupName() # The name of the DP Parameter Group.
            getParameterApplyStatus() # The status of parameter updates.
        getDBSecurityGroups() # Provides List of DB Security Group elements containing only DBSecurityGroup.Name and DBSecurityGroup.Status subelements.
            com.amazonaws.services.rds.model.DBSecurityGroupMembership
            getDBSecurityGroupName()
            getStatus()
        '''

        dbName = item.getDBName()
        platform = db_platform.findPlatformBySignature(item.getEngine())
        vendor = platform and platform.vendor
        databases = dbName and [db.Database(dbName)]
        endpoint = self._convertToTcpEndpoint(item.getEndpoint())
        server = db.DatabaseServer(endpoint.getAddress(),
                                   endpoint.getPort(),
                                   databases=databases,
                                   vendor=vendor,
                                   version=item.getEngineVersion(),
                                   platform=platform)

        sizeInGb = item.getAllocatedStorage()
        sizeInMb = ((sizeInGb and str(sizeInGb).isnumeric) and sizeInGb * 1024
                    or None)
        return aws_rds.Instance(
            item.getDBInstanceIdentifier(),
            server,
            type=item.getDBInstanceClass(),
            status=item.getDBInstanceStatus(),
            licenseModel=item.getLicenseModel(),
            sizeInMb=sizeInMb,
            availabilityZoneName=item.getAvailabilityZone(),
            creationTime=item.getInstanceCreateTime(),
            engineName=item.getEngine(),
            parameterGroups=map(self._convertToParameterGroupStatus,
                                item.getDBParameterGroups()),
            securityGroups=map(self._convertToSecurityGroupMembership,
                               item.getDBSecurityGroups()))
Esempio n. 11
0
    def _converttoDbInstance(self, item):
        r"""@types: com.amazonaws.services.rds.model.DBInstance -> aws_rds.Instance

        getDBParameterGroups()#rovides the list of DB Parameter Groups applied to this DB Instance.
            com.amazonaws.services.rds.model.DBParameterGroupStatus
            getDBParameterGroupName() # The name of the DP Parameter Group.
            getParameterApplyStatus() # The status of parameter updates.
        getDBSecurityGroups() # Provides List of DB Security Group elements containing only DBSecurityGroup.Name and DBSecurityGroup.Status subelements.
            com.amazonaws.services.rds.model.DBSecurityGroupMembership
            getDBSecurityGroupName()
            getStatus()
        """

        dbName = item.getDBName()
        platform = db_platform.findPlatformBySignature(item.getEngine())
        vendor = platform and platform.vendor
        databases = dbName and [db.Database(dbName)]
        endpoint = self._convertToTcpEndpoint(item.getEndpoint())
        server = db.DatabaseServer(
            endpoint.getAddress(),
            endpoint.getPort(),
            databases=databases,
            vendor=vendor,
            version=item.getEngineVersion(),
            platform=platform,
        )

        sizeInGb = item.getAllocatedStorage()
        sizeInMb = (sizeInGb and str(sizeInGb).isnumeric) and sizeInGb * 1024 or None
        return aws_rds.Instance(
            item.getDBInstanceIdentifier(),
            server,
            type=item.getDBInstanceClass(),
            status=item.getDBInstanceStatus(),
            licenseModel=item.getLicenseModel(),
            sizeInMb=sizeInMb,
            availabilityZoneName=item.getAvailabilityZone(),
            creationTime=item.getInstanceCreateTime(),
            engineName=item.getEngine(),
            parameterGroups=map(self._convertToParameterGroupStatus, item.getDBParameterGroups()),
            securityGroups=map(self._convertToSecurityGroupMembership, item.getDBSecurityGroups()),
        )
Esempio n. 12
0
 def _convertToDbSnapshot(self, item):
     r"@types: com.amazonaws.services.rds.model.DBSnapshot -> aws_rds.Snapshot"
     sizeInGb = item.getAllocatedStorage()
     sizeInMb = (sizeInGb and str(sizeInGb).isnumeric) and sizeInGb * 1024 or None
     # create database server
     platform = db_platform.findPlatformBySignature(item.getEngine())
     vendor = platform and platform.vendor
     server = db.DatabaseServer(port=item.getPort(), vendor=vendor, versionDescription=item.getEngineVersion())
     # create DB Instance based on server
     instance = aws_rds.Instance(
         item.getDBInstanceIdentifier(),
         server,
         licenseModel=item.getLicenseModel(),
         sizeInMb=sizeInMb,
         availabilityZoneName=item.getAvailabilityZone(),
         creationTime=item.getInstanceCreateTime(),
     )
     # create DB Snapshot based on instance
     return aws_rds.Snapshot(
         item.getDBSnapshotIdentifier(), instance, creationTime=item.getSnapshotCreateTime(), status=item.getStatus()
     )
Esempio n. 13
0
 def _convertToDbSnapshot(self, item):
     r'@types: com.amazonaws.services.rds.model.DBSnapshot -> aws_rds.Snapshot'
     sizeInGb = item.getAllocatedStorage()
     sizeInMb = ((sizeInGb and str(sizeInGb).isnumeric) and sizeInGb * 1024
                 or None)
     # create database server
     platform = db_platform.findPlatformBySignature(item.getEngine())
     vendor = platform and platform.vendor
     server = db.DatabaseServer(port=item.getPort(),
                                vendor=vendor,
                                versionDescription=item.getEngineVersion())
     # create DB Instance based on server
     instance = aws_rds.Instance(
         item.getDBInstanceIdentifier(),
         server,
         licenseModel=item.getLicenseModel(),
         sizeInMb=sizeInMb,
         availabilityZoneName=item.getAvailabilityZone(),
         creationTime=item.getInstanceCreateTime())
     # create DB Snapshot based on instance
     return aws_rds.Snapshot(item.getDBSnapshotIdentifier(),
                             instance,
                             creationTime=item.getSnapshotCreateTime(),
                             status=item.getStatus())
Esempio n. 14
0
                    and engine.getVersion() == dbServer.getVersion()):
                # recreate server with additional information
                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:
Esempio n. 15
0
                # recreate server with additional information
                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)