Exemple #1
0
 def __init__(self):
     '''
     Constructor
     '''
     self.zkaddress, self.zkport = get_zk_address()
     self.retry = KazooRetry(max_tries=3, delay=0.5)
     self.zk = KazooClient(hosts=self.zkaddress+':'+str(self.zkport), connection_retry=self.retry)
     self.zk.start()
     #self.zk = self.ensureinstance()
     logging.info("instance zk client (%s:%s)" % (self.zkaddress, self.zkport))
Exemple #2
0
 def __init__(self):
     '''
     Constructor
     '''
     self.zkaddress, self.zkport = get_zk_address()
     if "" != self.zkaddress and "" != self.zkport:
         self.zk = KazooClient(hosts=self.zkaddress + ':' +
                               str(self.zkport),
                               connection_retry=self.DEFAULT_RETRY_POLICY,
                               timeout=20)
         self.zk.add_listener(self.listener)
         self.zk.start()
         logging.info("instance zk client (%s:%s)" %
                      (self.zkaddress, self.zkport))
Exemple #3
0
    def _zk_singleton(*args, **kw):

        zk_addr, zk_port = get_zk_address()
        if not (zk_addr and zk_port):
            raise CommonException(
                'zookeeper address and port are not written!')

        if cls not in instances:
            instances[cls] = cls(*args, **kw)

        if instances[cls].zk is None:
            instances[cls] = cls(*args, **kw)

        return instances[cls]
Exemple #4
0
    def _zk_singleton(*args, **kw):

        zk_addr, zk_port = get_zk_address()
        if not (zk_addr and zk_port):
            raise CommonException(
                'zookeeper address and port are not written!')

        if cls not in instances:
            instances[cls] = cls(*args, **kw)

        if instances[cls].zk is None:
            logging.info('zk client disconnect, init another one')
            instances[cls] = cls(*args, **kw)

        return instances[cls]
Exemple #5
0
    def sync(self):
        zk_address, zk_port = get_zk_address()
        if not (zk_address and zk_port):
            logging.info('admin zookeeper first!')
            return

        zkOper = Common_ZkOpers()

        existed = zkOper.existCluster()
        if existed:
            self._sync_server_cluster()
            self._sync_data_node()
        else:
            logging.info(
                "cluster does not exist, may be the first time to sync in a new server cluster"
            )
Exemple #6
0
 def init(self):
     address, port = get_zk_address()
     self.zk_helper = ZkHelper(address, port)