예제 #1
0
    def runner(self, args, display=True):
        '''
            Main section.
        '''
        LOGGER.debug("runner started")

        plugin_args = args.split() \
            if args is not None and (len(args.strip()) > 0) \
            else ""

        options = self.read_args(plugin_args)

        self.broker_list = options.brokerlist.split(",")
        self.zk_list = options.zkconnect.split(",")
        self.prod2cons = options.prod2cons

        zknodes = self.getzknodes(options.zkconnect)
        LOGGER.debug(zknodes)
        prev_zk_data = None
        zk_data = None
        brokers = None
        for zkn in zknodes.list:
            LOGGER.debug("processing %s:%d", zkn.host, zkn.port)
            if zkn.alive is True:
                try:
                    client = ZkClient(zkn.host, zkn.port)
                    brokers = client.brokers()
                    topics = client.topics()
                    for topic in topics:
                        if not topic.id in self.topic_list:
                            self.topic_list.append(topic.id)
                            LOGGER.debug("adding %s to the topic list",
                                         topic.id)

                    zk_data = self.process(zknodes, brokers, topics)
                except ZkError, exc:
                    LOGGER.error('Failed to access Zookeeper: %s', str(exc))
                    break
                except ProcessorError, exc:
                    LOGGER.error('Failed to process: %s', str(exc))
                    break
                if prev_zk_data is not None:
                    if (prev_zk_data.num_partitions != zk_data.num_partitions
                            or prev_zk_data.num_part_ok != zk_data.num_part_ok
                            or
                            prev_zk_data.num_part_ko != zk_data.num_part_ko):
                        LOGGER.error(
                            "Inconsistency found in zk (%s,%d) tree comparison",
                            zkn.host, zkn.port)
                    else:
                        LOGGER.debug("No inconsistency found in zk (%s,%d) tree comparison", \
                                     zkn.host, zkn.port)
                prev_zk_data = zk_data
예제 #2
0
    def getzknodes(self, zconnect):
        '''
            Returns a list of zknodes tuples, where each tuple represents
            a zk node with host/port and alive status.
        '''

        LOGGER.debug("getzknodes started")
        zok = 0
        zko = 0
        node_list = []
        bconnect = ""
        berror = ""
        zconnectsplit = zconnect.split(",")
        for zpart in zconnectsplit:
            if ':' in zpart:
                host, port = zpart.split(':', 1)
                port = int(port)
                if bconnect != "":
                    bconnect += ","
                bconnect += "%s:%d" % (host, port)
                try:
                    client = ZkClient(host, port)
                    if client.ping():
                        node_list.append(ZkNode(host, port, True))
                        zok += 1
                    else:
                        if berror != "":
                            berror += ","
                        berror += "%s:%d" % (host, port)
                        node_list.append(ZkNode(host, port, False))
                        zko += 1
                        LOGGER.error("Zookeeper node unreachable (%s:%d)",
                                     host, port)
                except ZkError:
                    LOGGER.error("Zookeeper node unreachable (%s:%d)", host,
                                 port)
                    zko += 1
                    node_list.append(ZkNode(host, port, False))
        LOGGER.debug("getzknodes finished")
        return ZkNodesHealth(bconnect, berror, zok, zko, node_list)
예제 #3
0
def getzknodes(zconnect):
    '''
        Returns a list of zknodes tuples, where each tuple represents
        a zk node with host/port and alive status.
    '''

    LOGGER.debug("getzknodes started")
    zok = 0
    zko = 0
    seq = []
    bconnect = ""
    berror = ""
    zconnectsplit = zconnect.split(",")
    for zpart in zconnectsplit:
        if ':' in zpart:
            host, port = zpart.split(':', 1)
            port = int(port)
            if bconnect != "":
                bconnect += ","
            bconnect += "%s:%d" % (host, port)
            try:
                client = ZkClient(host, port)
                if client.ping():
                    seq.append(ZkNode(host, port, True))
                    zok += 1
                else:
                    if berror != "":
                        berror += ","
                    berror += "%s:%d" % (host, port)
                    seq.append(ZkNode(host, port, False))
                    zko += 1
                    LOGGER.error(
                        "Zookeeper node unreachable (%s:%d)", host, port)
            except ZkError:
                LOGGER.error(
                    "Zookeeper node unreachable (%s:%d)", host, port)
                zko += 1
                seq.append(ZkNode(host, port, False))
    LOGGER.debug("getzknodes finished")
    return ZkNodesHealth(bconnect, berror, zok, zko, seq)