Exemplo n.º 1
0
    def _discover_local_databases(self, context, instance_name, application_port, db2_home_path,
                                  discoverer, executor, interpreter):
        db2_instance_osh = context.application.applicationOsh
        get_local_databases = safeFn(discoverer.get_local_databases)
        local_dbs = get_local_databases(executor,
                                              interpreter,
                                              instance_name,
                                              db2_home_path=db2_home_path)

        if local_dbs:
            reporter = db2_topology.Reporter()

            address = context.application.getApplicationIp()
            if not application_port:
                resolve_servicename = safeFn(discoverer.resolve_servicename)
                get_svcename = safeFn(discoverer.get_svcename_by_instancename)
                svce_name = get_svcename(executor, interpreter, instance_name, db2_home_path=db2_home_path)
                if svce_name:
                    net_service = resolve_servicename(executor, svce_name)
                    if net_service:
                        application_port = net_service.port

            inst = DatabaseServer(address, application_port)
            local_dbs = [db2_topology.build_database_pdo(inst, db)
                               for db in local_dbs]
            oshs = reporter.updateInstanceDatabases(db2_instance_osh, local_dbs, context.hostOsh)
            context.resultsVector.addAll(oshs)
        else:
            logger.debug('No local databases found for %s' % instance_name)
Exemplo n.º 2
0
def parse_items(result_set):
    items = []
    from com.ziclix.python.sql import DataHandler
    data_handler = DataHandler()
    try:
        meta_data = result_set.getMetaData()
        while result_set.next():
            attr_name_to_value = {}
            for column_number in range(1, meta_data.getColumnCount() + 1):

                column_type = meta_data.getColumnType(column_number)

                value = None
                try:
                    value = data_handler.getPyObject(_ResultSet(result_set),
                                                     column_number,
                                                     column_type)
                except:
                    column_type_ = meta_data.getColumnTypeName(column_number)
                    errorMessage = ('Unrecognized column type %s (%d), '
                                    'scipping' % (column_type_, column_number))
                    logger.debugException(errorMessage)

                column_name = meta_data.getColumnName(column_number)
                attr_name_to_value[column_name] = value

            items.append(_Item(**attr_name_to_value))
    except SQLException:
        logger.debugException('Failed to process result set')
        raise command.ExecuteException('Failed to execute sql query')
    safeFn(result_set.close)()
    return items
Exemplo n.º 3
0
def parse_items(result_set):
    items = []
    from com.ziclix.python.sql import DataHandler
    data_handler = DataHandler()
    try:
        meta_data = result_set.getMetaData()
        while result_set.next():
            attr_name_to_value = {}
            for column_number in range(1, meta_data.getColumnCount() + 1):

                column_type = meta_data.getColumnType(column_number)

                value = None
                try:
                    value = data_handler.getPyObject(_ResultSet(result_set),
                                                      column_number,
                                                      column_type)
                except:
                    column_type_ = meta_data.getColumnTypeName(column_number)
                    errorMessage = ('Unrecognized column type %s (%d), '
                                    'scipping' % (column_type_,
                                                  column_number))
                    logger.debugException(errorMessage)

                column_name = meta_data.getColumnName(column_number)
                attr_name_to_value[column_name] = value

            items.append(_Item(** attr_name_to_value))
    except SQLException:
        logger.debugException('Failed to process result set')
        raise command.ExecuteException('Failed to execute sql query')
    safeFn(result_set.close)()
    return items
Exemplo n.º 4
0
    def _discover_remote_databases(self, context, instname, db2_home_path,
                                   discoverer, executor, interpreter):
        local_dbserver_osh = context.application.applicationOsh
        get_remote_databases = safeFn(discoverer.get_remote_databases)
        node_db_pairs = get_remote_databases(executor, interpreter, instname, db2_home_path=db2_home_path) or ()

        get_node = safeFn(discoverer.get_node)
        reporter = db2_topology.Reporter()
        node_reporter = host_topology.Reporter()

        shell = context.client
        resolvers = (NsLookupDnsResolver(shell), SocketDnsResolver())
        resolve_ips_fn = FallbackResolver(resolvers).resolve_ips
        for nodename, remote_dbs in node_db_pairs:
            node = get_node(executor, interpreter, instname,
                            nodename, db2_home_path=db2_home_path)
            if node:
                host_osh = None
                address = None
                instance_name_ = None
                if node.is_local():
                    host_osh = context.hostOsh
                    address = context.application.getApplicationIp()
                    instance_name_ = node.instance_name
                else:
                    host = host_base_parser.parse_from_address(node.hostname,
                                     fptools.safeFunc(resolve_ips_fn))
                    if host and host.ips:
                        instance_name_ = node.remote_instance_name
                        address = first(host.ips)
                        host_osh, _, oshs_ = node_reporter.report_host_with_ips(host.ips)
                        context.resultsVector.addAll(oshs_)

                if host_osh:
                    get_port_fn = safeFn(discoverer.get_instance_port_by_node)
                    port = get_port_fn(executor, interpreter, node, db2_home_path=db2_home_path)

                    remote_instance = DatabaseServer(address, port)

                    remote_inst_osh, endpoint_osh, _, vector = reporter.reportServerAndDatabases(remote_instance, host_osh)
                    if instance_name_:
                        SoftwareBuilder.updateName(remote_inst_osh, instance_name_)
                        context.resultsVector.addAll(vector)
                        _, oshs = reporter.reportRemoteDatabases(remote_dbs, local_dbserver_osh, remote_inst_osh)
                        context.resultsVector.addAll(oshs)
                    else:
                        logger.debug('No instance name')
                        if endpoint_osh:
                            context.resultsVector.add(endpoint_osh)
                else:
                    logger.debug('Host is not resolved %s' % node.hostname)
            else:
                logger.debug('No node found with name %s' % nodename)
def get_instance_port_by_node(node, get_svcename_by_instname_fn, resolve_svcename_fn):
    r"@types: db2_base_shell_discoverer.Db2.NodeEntry, (str -> str?), (str -> db2_base_shell_discoverer.NetworkService) -> int?"
    resolve_servicename = safeFn(resolve_svcename_fn)
    get_svcename = safeFn(get_svcename_by_instname_fn)

    svce_name = None
    if node.service_name:
        svce_name = node.service_name
    elif node.instance_name:
        svce_name = get_svcename(node.instance_name)
    if svce_name:
        if svce_name.isdigit():
            return int(svce_name)
        else:
            net_service = resolve_servicename(svce_name)
            return net_service and net_service.port
Exemplo n.º 6
0
def get_instance_port_by_node(node, get_svcename_by_instname_fn,
                              resolve_svcename_fn):
    r'@types: db2_base_shell_discoverer.Db2.NodeEntry, (str -> str?), (str -> db2_base_shell_discoverer.NetworkService) -> int?'
    resolve_servicename = safeFn(resolve_svcename_fn)
    get_svcename = safeFn(get_svcename_by_instname_fn)

    svce_name = None
    if node.service_name:
        svce_name = node.service_name
    elif node.instance_name:
        svce_name = get_svcename(node.instance_name)
    if svce_name:
        if svce_name.isdigit():
            return int(svce_name)
        else:
            net_service = resolve_servicename(svce_name)
            return net_service and net_service.port
Exemplo n.º 7
0
    def get_instance_name(self, context):
        pid = self._main_process.getPid()
        if pid is not None:
            shell = context.client
            os_bitcount = shell.is64BitMachine() and 64 or 32

            reg_provider = regutils.getProvider(shell)
            version = self.get_db2_version(context)
            discoverer = winreg_discoverer.registry.get_discoverer(version,
                                                                   os_bitcount)
            execute_reg_command = Fn(winreg_base_discoverer.execute_reg_query,
                                     reg_provider,
                                     fptools._)
            execute_reg_command = safeFn(execute_reg_command)
            return fptools.findFirst(bool, map(execute_reg_command,
                                  (discoverer.GetInstanceNameByPid(pid),
                                   discoverer.GetClusterInstanceNameByPid(pid))
                                  ))
        else:
            logger.debug('pid is not available for the main db2 process')
Exemplo n.º 8
0
def get_db2_version(sql_executor):
    sqlbased_discoverers = registry.get_discoverers()
    discover_version = Fn(safeFn(__discover_version), sql_executor, fptools._)
    return findFirst(lambda x: x,
                                ifilter(None, imap(discover_version,
                                                   sqlbased_discoverers)))
Exemplo n.º 9
0
def get_db2_version(sql_executor):
    sqlbased_discoverers = registry.get_discoverers()
    discover_version = Fn(safeFn(__discover_version), sql_executor, fptools._)
    return findFirst(
        lambda x: x, ifilter(None, imap(discover_version,
                                        sqlbased_discoverers)))