Ejemplo n.º 1
0
 def response(self):
     '''add
     '''
     if self.id:
         # 修改记录
         tb_inst = ZdZookeeper.one(id=self.id)
     else:
         # 新增记录
         zookeeper = ZdZookeeper.one(cluster_name=self.cluster_name,
                                     deleted='0')
         # 检验集群名称是否重复
         if zookeeper:
             return self.ajax_popup(code=300, msg="zookeeper集群名称重复!")
         else:
             tb_inst = ZdZookeeper()
     if self.id:
         tb_inst.id = self.id
     if self.cluster_name:
         tb_inst.cluster_name = self.cluster_name
     if self.hosts:
         tb_inst.hosts = self.hosts
     if self.business:
         tb_inst.business = self.business
     tb_inst.save()
     return self.ajax_ok(forward="/config/zookeeper/index")
Ejemplo n.º 2
0
 def response(self):
     '''delete
     '''
     if self.info_ids:
         id_li = self.info_ids.split(',')
         for user_id in id_li:
             ZdZookeeper.one(id=user_id).delete_instance()
     return self.ajax_ok(close_current=False)
Ejemplo n.º 3
0
 def response(self):
     '''delete
     '''
     if self.info_ids:
         id_li = self.info_ids.split(',')
         for user_id in id_li:
             ZdZookeeper.one(id=user_id).delete_instance()
     return self.ajax_ok(close_current=False)
Ejemplo n.º 4
0
def get_zoo_client(cluster_name="qconf"):
    """get zoo client by cluster_name
    """
    global ZOO_CLIENTS

    if cluster_name not in ZOO_CLIENTS:
        # get zookeeper hosts info
        zookeeper = ZdZookeeper.one(cluster_name=cluster_name, deleted="0")
        if not zookeeper:
            raise ZookeeperConfError(
                "Zookeeper not configured for cluster: {}!".format(
                    cluster_name))
        # connect to zookeeper
        try:
            client = KazooClient(hosts=zookeeper.hosts,
                                 connection_retry={
                                     "max_tries": 3,
                                     "backoff": 2
                                 })
            client.start(3)
            ZOO_CLIENTS[cluster_name] = client
        except KazooTimeoutError as exc:
            log.error('Failed to connnect zookeeper, %s', str(exc))
            return

    # check connection's state, if not connected, reconect
    zoo_client = ZOO_CLIENTS[cluster_name]
    if not zoo_client.connected:
        zoo_client.start()
    return zoo_client
Ejemplo n.º 5
0
def get_zoo_client(cluster_name="qconf"):
    """get zoo client by cluster_name
    """
    global ZOO_CLIENTS

    if cluster_name not in ZOO_CLIENTS:
        # get zookeeper hosts info
        zookeeper = ZdZookeeper.one(cluster_name=cluster_name, deleted="0")
        if not zookeeper:
            raise ZookeeperConfError("Zookeeper not configured for cluster: {}!".format(cluster_name))
        # connect to zookeeper
        try:
            client = KazooClient(hosts=zookeeper.hosts,
                                 connection_retry={"max_tries": 3, "backoff": 2})
            client.start(3)
            ZOO_CLIENTS[cluster_name] = client
        except KazooTimeoutError as exc:
            log.error('Failed to connnect zookeeper, %s', str(exc))
            return

    # check connection's state, if not connected, reconect
    zoo_client = ZOO_CLIENTS[cluster_name]
    if not zoo_client.connected:
        zoo_client.restart()
    return zoo_client
Ejemplo n.º 6
0
def get_zoo_client(cluster_name="qconf"):
    """get zoo client by cluster_name
    """
    global ZOO_CLIENTS

    if cluster_name not in ZOO_CLIENTS:
        # get zookeeper hosts info
        zookeeper = ZdZookeeper.one(cluster_name=cluster_name, deleted="0")
        if not zookeeper:
            raise ZookeeperConfError("Zookeeper not configured for cluster: {}!".format(cluster_name))
        # connect to zookeeper
        try:
            username = ZK_AUTH.get('user')
            pwd = ZK_AUTH.get('pwd')
            client = KazooClient(hosts=zookeeper.hosts,
                                 connection_retry={"max_tries": 3, "backoff": 2},
                                 default_acl=make_digest_acl(username, pwd, 
                                          read=True, write=True, create=True, delete=True, admin=True), 
                                 auth_data=[("digest", '%s:%s' % (username, pwd))]
                                )
            client.start(timeout=3)
            ZOO_CLIENTS[cluster_name] = client
        except KazooTimeoutError as exc:
            log.error('Failed to connnect zookeeper, %s', str(exc))
            return

    # check connection's state, if not connected, reconect
    zoo_client = ZOO_CLIENTS[cluster_name]
    if not zoo_client.connected:
        zoo_client.start()
    return zoo_client
Ejemplo n.º 7
0
 def response(self):
     '''edit
     '''
     if self.info_ids:
         id_li = self.info_ids.split(',')
         if len(id_li) != 1:
             return self.ajax_popup(close_current=False, code=300, msg="请选择单条记录进行修改")
         record = ZdZookeeper.one(id=id_li[0])
         return self.render('config/zookeeper/edit.html',
                            action='/config/zookeeper/save',
                            record=record)
     else:
         return self.ajax_popup(close_current=False, code=300, msg="请选择某条记录进行修改")
Ejemplo n.º 8
0
 def response(self):
     '''edit
     '''
     if self.info_ids:
         id_li = self.info_ids.split(',')
         if len(id_li) != 1:
             return self.ajax_popup(close_current=False, code=300, msg="请选择单条记录进行修改")
         record = ZdZookeeper.one(id=id_li[0])
         return self.render('config/zookeeper/edit.html',
                            action='/config/zookeeper/save',
                            record=record)
     else:
         return self.ajax_popup(close_current=False, code=300, msg="请选择某条记录进行修改")
Ejemplo n.º 9
0
 def response(self):
     '''add
     '''
     if self.id:
         # 修改记录
         tb_inst = ZdZookeeper.one(id=self.id)
     else:
         # 新增记录
         zookeeper = ZdZookeeper.one(cluster_name=self.cluster_name, deleted='0')
         # 检验集群名称是否重复
         if zookeeper:
             return self.ajax_popup(code=300, msg="zookeeper集群名称重复!")
         else:
             tb_inst = ZdZookeeper()
     if self.id:
         tb_inst.id = self.id
     if self.cluster_name:
         tb_inst.cluster_name = self.cluster_name
     if self.hosts:
         tb_inst.hosts = self.hosts
     if self.business:
         tb_inst.business = self.business
     tb_inst.save()
     return self.ajax_ok(forward="/config/zookeeper/index")
Ejemplo n.º 10
0
    def response(self):
        '''delete
        '''
        if not self.info_ids:
            return self.ajax_popup(close_current=False, code=300, msg="请选择某条记录进行删除")

        id_list = self.info_ids.split(',')
        for zookeeper_id in id_list:
            zookeeper = ZdZookeeper.one(id=zookeeper_id)
            zookeeper.deleted = '1'
            zookeeper.save()
            services = ZdService.select().where(ZdService.zookeeper == zookeeper.id and ZdService.deleted == '0')
            for service in services:
                service.deleted = '1'
                service.save()
        return self.ajax_ok(close_current=False)
Ejemplo n.º 11
0
def get_zoo_client(cluster_name="qconf"):
    """get zoo client by cluster_name
    """
    global ZOO_CLIENTS

    zookeeper = ZdZookeeper.one(cluster_name=cluster_name, deleted="0")
    if not zookeeper:
        raise ZookeeperConfError("Zookeeper not configured for cluster {}!".format(cluster_name))

    if cluster_name not in ZOO_CLIENTS:
        try:
            client = KazooClient(hosts=zookeeper.hosts, connection_retry={"max_tries": 1, "backoff": 1})
            client.start(timeout=3)
            ZOO_CLIENTS[cluster_name] = client
        except KazooTimeoutError as exc:
            log.error('Failed to connnect zookeeper, %s', str(exc))
            return

    return ZOO_CLIENTS[cluster_name]
Ejemplo n.º 12
0
    def response(self):
        zookeeper = ZdZookeeper.one(cluster_name=self.cluster, deleted='0')
        #self.set_header('Content-Type', 'application/json; charset=UTF-8')
        #self.write(json.dumps({'message': 'ok'}))
        #self.finish()
        if zookeeper is not None:
            services = ZdService.select().where((ZdService.zookeeper == zookeeper.id) & (ZdService.deleted == '0'))
            if services.count() >= 1:
                json_data = '{"service_names":['
                for service in services:
                    json_data += '"'
                    json_data += service.service_name
                    json_data += '",'
                json_data = json_data[0:len(json_data)-1]
                json_data += "]}"
                return json_data
	    else:
		json_data = ''
                self.finish()
	else:
            self.finish()
Ejemplo n.º 13
0
    def response(self):
        '''add
        '''
        if self.id:
            # 修改记录
            tb_inst = ZdService.one(id=self.id)
        else:
            zookeeper = ZdZookeeper.one(cluster_name=self.cluster_name, deleted='0')
            if zookeeper is None:
                return self.ajax_popup(code=300, msg="zookeeper集群不存在!")
            else:
                # 新增记录
                service = ZdService.one(zookeeper=zookeeper.id, service_name=self.service_name, deleted='0')
                # 检验集群下是否已经有该服务
                if service:
                    return self.ajax_popup(code=300, msg="service名称重复!")
                else:
                    tb_inst = ZdService()
        if self.id:
            tb_inst.id = self.id
        if self.service_name:
            tb_inst.service_name = self.service_name
	tb_inst.zookeeper = zookeeper
        tb_inst.save()
        # 更新在zookeeper和mysql上存储的配置信息, 同时进行快照备份
        # 当一个节点的父节点存在时才会保存快照
        ZnodeService.set_znode(cluster_name=self.cluster_name,
                               path='/',
                               data='',
                               znode_type='0',
                               description='')
        ZnodeService.set_znode(cluster_name=self.cluster_name,
                               path='/' + self.service_name,
                               data='',
                               znode_type='0',
                               description='')
        return self.ajax_ok(forward="/config/service/index")