예제 #1
0
파일: znode.py 프로젝트: znavy/zkdash
    def response(self):
        '''客户端同步状况查看
        '''
        # md5 value in zookeeper
        znode_value = ZookeeperService.get(self.cluster_name, self.path)
        znode_md5_value = hashlib.md5(znode_value).hexdigest()

        # agent value, idc转换为zookeeper集群名称,方便统一管理
        qconf_feedbacks = ZdQconfFeedback.select().where(
            (ZdQconfFeedback.idc == self.cluster_name)
            & (ZdQconfFeedback.path == self.path)
            & (ZdQconfFeedback.deleted == '0'))

        # check sync_status
        for feedback in qconf_feedbacks:
            # 只检查agent反馈记录中get_conf命令获取的值, 2代表get_conf命令的反馈记录
            if feedback.data_type != '2':
                continue
            if znode_md5_value == feedback.md5_value:
                feedback.sync_status = "已同步"
            else:
                feedback.sync_status = "未同步"

        return self.render('config/znode/syncstatus.html',
                           path=self.path,
                           idc=self.cluster_name,
                           feedbacks=qconf_feedbacks)
예제 #2
0
파일: znode.py 프로젝트: duduwang/zkdash
def save_znode_tree(cluster_name,node_path,new_node_path):
    data = ZookeeperService.get(cluster_name, node_path)
    znode = ZdZnode.one(cluster_name=cluster_name, path=node_path, deleted="0")
    if znode is None:
        return False
    set_znode(cluster_name, new_node_path, data, znode_type=znode.type, business=znode.business)
    return True;
예제 #3
0
파일: znode.py 프로젝트: znavy/zkdash
    def response(self):
        '''edit
        '''
        node_type = data = download_link = ""

        normalized_path = normalize_path(self.path)
        znode = ZdZnode.one(path=normalized_path,
                            cluster_name=self.cluster_name,
                            deleted='0')
        business = ""
        if znode:
            node_type = znode.type
            business = znode.business

        # "0"代表普通节点, "1"代表文本节点
        if node_type == "1":
            # 文件节点提供下载路径
            download_link = "/config/znode/download?path={0}&cluster_name={1}".format(
                self.path, self.cluster_name)

        else:
            data = ZookeeperService.get(self.cluster_name, self.path)

        return self.render('config/znode/edit.html',
                           action='/config/znode/save',
                           cluster_name=self.cluster_name,
                           path=normalized_path,
                           data=data,
                           business=business,
                           download_link=download_link)
예제 #4
0
파일: znode.py 프로젝트: 87439247/zkdash
    def response(self):
        '''edit
        '''
        node_type = data = download_link = ""

        normalized_path = normalize_path(self.path)
        znode = ZdZnode.one(path=normalized_path, cluster_name=self.cluster_name, deleted='0')
        if znode:
            node_type = znode.type

        # "0"代表普通节点, "1"代表文本节点
        if node_type == "1":
            # 文件节点提供下载路径
            download_link = "/config/znode/download?path={0}&cluster_name={1}".format(
                self.path, self.cluster_name)

        else:
            data = ZookeeperService.get(self.cluster_name, self.path)

        return self.render('config/znode/edit.html',
                           action='/config/znode/save',
                           cluster_name=self.cluster_name,
                           path=normalized_path,
                           data=data,
                           download_link=download_link)
예제 #5
0
파일: znode.py 프로젝트: liucyao/zkdash
    def response(self):
        """返回指定zookeeper集群的znode信息, 响应ajax请求
        """
        nodes = []
        normalized_path = normalize_path(self.path)

        if USE_QCONF:
            ZnodeService.get_znode_tree_from_qconf(self.cluster_name, normalized_path, nodes)
        else:
            zoo_client = ZookeeperService.get_zoo_client(self.cluster_name)
            if not zoo_client:
                return self.ajax_popup(code=300, msg="连接zookeeper出错!")
            ZnodeService.get_znode_tree(zoo_client, normalized_path, nodes)

        if normalized_path != "/" and len(nodes) <= 1:
            return self.ajax_popup(code=300, msg="对不起,该节点路径下(%s)无数据!" % self.path)

        for node in nodes:
            zk_node = ZdZnode.one(path=node["path"], cluster_name=self.cluster_name)
            if zk_node:
                node['type'] = zk_node.type
                node['business'] = zk_node.business
                node['data'] = ZookeeperService.get(self.cluster_name, node["path"])

        znodes_data = json.dumps(nodes)
        return self.render('config/znode/displaytree.html',
                           cluster_name=self.cluster_name,
                           znodes_data=znodes_data)
예제 #6
0
    def response(self):
        """返回指定zookeeper集群的znode信息, 响应ajax请求
        """
        nodes = []
        normalized_path = normalize_path(self.path)

        zoo_client = ZookeeperService.get_zoo_client(self.cluster_name)
        if not zoo_client:
            return self.ajax_popup(code=300, msg="连接zookeeper出错!")
        ZnodeService.get_znode_tree(zoo_client, normalized_path, nodes)

        #if normalized_path != "/" and len(nodes) <= 1:
        #    return self.ajax_popup(
        #        code=300, msg="对不起,该节点路径下(%s)无数据!" % self.path)

        for node in nodes:
            zk_node = ZdZnode.one(path=node["path"],
                                  cluster_name=self.cluster_name)
            if zk_node:
                node['description'] = zk_node.description
                node['data'] = ZookeeperService.get(self.cluster_name,
                                                    node["path"])

        znodes_data = json.dumps(nodes)
        return self.render('config/znode/displaytree.html',
                           cluster_name=self.cluster_name,
                           service_name=self.service_name,
                           znodes_data=znodes_data)
예제 #7
0
def make_snapshot(cluster_name, path, data=None):
    """生成快照,包括快照树结构信息(zd_snapshot_tree)和快照数据(zd_snapshot)
    """
    if data is None:
        data = ZookeeperService.get(cluster_name, path)

    # 验证节点路径是否已经存在,不存在才创建相应树结构节点
    if not _is_tree_node_exists(cluster_name, path):
        if path.strip() == "/":
            # 增加根节点
            _add_tree_root(cluster_name=cluster_name, node_path=path)
        else:
            # 增加子节点
            parent_path = _extract_parent_path(path)
            parent_node = ZdSnapshotTree.one(cluster_name=cluster_name, node_path=parent_path)
            if not parent_node:
                raise MakeSnapshotError("Parent node does not exists, could not build tree!")
            _add_tree_node(cluster_name=cluster_name, parent_node=parent_node, node_path=path)

    # 检验快照是否重复生成
    commit_md5 = hashlib.md5(data).hexdigest()
    if is_snapshot_redundant(cluster_name, path, commit_md5):
        log.warn("Snapshot already exists for znode in cluster: %s, path: %s", cluster_name, path)
        return
    # 保存快照信息
    snapshot = ZdSnapshot(
        cluster_name=cluster_name, path=path, data=data, create_time=datetime.now(), commit=commit_md5
    )
    snapshot.save()
예제 #8
0
    def response(self):
        '''edit
        '''
        node_type = data = download_link = ""

        normalized_path = normalize_path(self.path)
        znode = ZdZnode.one(path=normalized_path,
                            cluster_name=self.cluster_name,
                            deleted='0')
        description = ""
        if znode:
            #node_type = znode.type
            description = znode.description

        # "0"代表普通节点, "1"代表文本节点
        #if node_type == "1":
        #    # 文件节点提供下载路径
        #    download_link = "/config/znode/download?path={0}&cluster_name={1}".format(
        #        self.path, self.cluster_name)

        #else:
        #    data = ZookeeperService.get(self.cluster_name, self.path)

        data = ZookeeperService.get(self.cluster_name, self.path)
        return self.render('config/znode/edit.html',
                           action='/config/znode/save',
                           cluster_name=self.cluster_name,
                           path=normalized_path,
                           data=data,
                           description=description,
                           download_link=download_link)
예제 #9
0
    def response(self):
        '''客户端同步状况查看
        '''
        # md5 value in zookeeper
        znode_value = ZookeeperService.get(self.cluster_name, self.path)
        #znode_md5_value = hashlib.md5(znode_value).hexdigest()

        # agent value, idc转换为zookeeper集群名称,方便统一管理
        feedbacks = ZdFeedback.select().where(
            (ZdFeedback.cluster == self.cluster_name)
            & (ZdFeedback.path == self.path) & (ZdFeedback.deleted == '0'))

        count = feedbacks.count()
        equal_counts = 0
        not_equal_counts = 0
        # check sync_status
        for feedback in feedbacks:
            feedback.znode_value = znode_value
            if znode_value == feedback.value:
                feedback.sync_status = "相等"
                equal_counts = equal_counts + 1
            else:
                feedback.sync_status = "不等"
                not_equal_counts = not_equal_counts + 1

        return self.render('config/znode/syncstatus.html',
                           path=self.path,
                           count=count,
                           equal_counts=equal_counts,
                           not_equal_counts=not_equal_counts,
                           cluster=self.cluster_name,
                           feedbacks=feedbacks)
예제 #10
0
파일: znode.py 프로젝트: 87439247/zkdash
    def response(self):
        '''客户端同步状况查看
        '''
        # md5 value in zookeeper
        znode_value = ZookeeperService.get(self.cluster_name, self.path)
        znode_md5_value = hashlib.md5(znode_value).hexdigest()

        # agent value, idc转换为zookeeper集群名称,方便统一管理
        qconf_feedbacks = ZdQconfFeedback.select().where(
            (ZdQconfFeedback.idc == self.cluster_name) & (ZdQconfFeedback.path == self.path) &
            (ZdQconfFeedback.deleted == '0')
        )

        # check sync_status
        for feedback in qconf_feedbacks:
            # 只检查agent反馈记录中get_conf命令获取的值, 2代表get_conf命令的反馈记录
            if feedback.data_type != '2':
                continue
            if znode_md5_value == feedback.md5_value:
                feedback.sync_status = "已同步"
            else:
                feedback.sync_status = "未同步"

        return self.render('config/znode/syncstatus.html',
                           path=self.path,
                           idc=self.cluster_name,
                           feedbacks=qconf_feedbacks)
예제 #11
0
파일: znode.py 프로젝트: ireaderlab/zkdash
    def response(self):
        """edit
        """
        node_type = data = download_link = ""

        normalized_path = normalize_path(self.path)
        znode = ZdZnode.one(path=normalized_path, cluster_name=self.cluster_name, deleted="0")
        business = ""
        if znode:
            node_type = znode.type
            business = znode.business

        # "0"代表普通节点, "1"代表文本节点
        if node_type == "1":
            # 文件节点提供下载路径
            download_link = "/config/znode/download?path={0}&cluster_name={1}".format(self.path, self.cluster_name)

        else:
            data = ZookeeperService.get(self.cluster_name, self.path)

        return self.render(
            "config/znode/edit.html",
            action="/config/znode/save",
            cluster_name=self.cluster_name,
            path=normalized_path,
            data=data,
            business=business,
            download_link=download_link,
        )
예제 #12
0
파일: znode.py 프로젝트: znavy/zkdash
    def response(self):
        """返回指定zookeeper集群的znode信息, 响应ajax请求
        """
        nodes = []
        normalized_path = normalize_path(self.path)

        if USE_QCONF:
            ZnodeService.get_znode_tree_from_qconf(self.cluster_name,
                                                   normalized_path, nodes)
        else:
            zoo_client = ZookeeperService.get_zoo_client(self.cluster_name)
            if not zoo_client:
                return self.ajax_popup(code=300, msg="连接zookeeper出错!")
            ZnodeService.get_znode_tree(zoo_client, normalized_path, nodes)

        if normalized_path != "/" and len(nodes) <= 1:
            return self.ajax_popup(code=300,
                                   msg="对不起,该节点路径下(%s)无数据!" % self.path)

        for node in nodes:
            zk_node = ZdZnode.one(path=node["path"],
                                  cluster_name=self.cluster_name)
            if zk_node:
                node['type'] = zk_node.type
                node['business'] = zk_node.business
                node['data'] = ZookeeperService.get(self.cluster_name,
                                                    node["path"])

        znodes_data = json.dumps(nodes)
        return self.render('config/znode/displaytree.html',
                           cluster_name=self.cluster_name,
                           znodes_data=znodes_data)
예제 #13
0
def make_snapshot(cluster_name, path, data=None):
    """生成快照,包括快照树结构信息(zd_snapshot_tree)和快照数据(zd_snapshot)
    """
    if data is None:
        data = ZookeeperService.get(cluster_name, path)

    # 验证节点路径是否已经存在,不存在才创建相应树结构节点
    if not _is_tree_node_exists(cluster_name, path):
        if path.strip() == "/":
            # 增加根节点
            _add_tree_root(cluster_name=cluster_name, node_path=path)
        else:
            # 增加子节点
            parent_path = _extract_parent_path(path)
            parent_node = ZdSnapshotTree.one(cluster_name=cluster_name, node_path=parent_path)
            if not parent_node:
                raise MakeSnapshotError("Parent node does not exists, could not build tree!")
            _add_tree_node(cluster_name=cluster_name,
                           parent_node=parent_node,
                           node_path=path)

    # 检验快照是否重复生成
    commit_md5 = hashlib.md5(data).hexdigest()
    if is_snapshot_redundant(cluster_name, path, commit_md5):
        log.warn("Snapshot already exists for znode in cluster: %s, path: %s", cluster_name, path)
        return
    # 保存快照信息
    snapshot = ZdSnapshot(cluster_name=cluster_name,
                          path=path,
                          data=data,
                          create_time=datetime.now(),
                          commit=commit_md5)
    snapshot.save()
예제 #14
0
파일: znode.py 프로젝트: ireaderlab/zkdash
 def response(self):
     """导出数据到文件中
     """
     data = ZookeeperService.get(self.cluster_name, self.path)
     filename = "{}".format(self.path.rsplit("/")[-1])
     self.set_header("Content-Type", "application/octet-stream")
     self.set_header("Content-Disposition", "attachment; filename={}".format(filename))
     self.finish(data)
예제 #15
0
파일: znode.py 프로젝트: duduwang/zkdash
 def response(self):
     '''导出数据到文件中
     '''
     data = ZookeeperService.get(self.cluster_name, self.path)
     filename = "{}".format(self.path.rsplit('/')[-1])
     self.set_header('Content-Type', 'application/octet-stream')
     self.set_header('Content-Disposition', 'attachment; filename={}'.format(filename))
     self.finish(data)
예제 #16
0
파일: znode.py 프로젝트: 87439247/zkdash
 def response(self):
     '''导出数据到文件中
     '''
     data = ZookeeperService.get(self.cluster_name, self.path)
     filename = "{}".format(self.path.rsplit('/')[-1])
     self.set_header('Content-Type', 'application/octet-stream')
     self.set_header('Content-Disposition', 'attachment; filename={}'.format(filename))
     self.finish(data)
예제 #17
0
def save_znode_tree(cluster_name, node_path, new_node_path):
    data = ZookeeperService.get(cluster_name, node_path)
    znode = ZdZnode.one(cluster_name=cluster_name, path=node_path, deleted="0")
    if znode is None:
        return False
    set_znode(cluster_name,
              new_node_path,
              data,
              znode_type=znode.type,
              business=znode.business)
    return True
예제 #18
0
파일: znode.py 프로젝트: ireaderlab/zkdash
    def response(self):
        """获取zookeeper节点的节点值
        """
        download_link = data = node_type = ""

        znode = ZdZnode.one(path=self.path, cluster_name=self.cluster_name, deleted="0")
        if znode:
            node_type = znode.type

        # 0代表普通节点,1代表文本节点
        if node_type == "1":
            download_link = "/config/znode/download?path={0}&cluster_name={1}".format(self.path, self.cluster_name)
        else:
            data = ZookeeperService.get(self.cluster_name, self.path)

        return self.render("config/znode/view.html", data=data, download_link=download_link)
예제 #19
0
파일: znode.py 프로젝트: duduwang/zkdash
    def response(self):
        """获取zookeeper节点的节点值
        """
        download_link = data = node_type = ""

        znode = ZdZnode.one(path=self.path, cluster_name=self.cluster_name, deleted="0")
        if znode:
            node_type = znode.type

        # 0代表普通节点,1代表文本节点
        if node_type == "1":
            download_link = "/config/znode/download?path={0}&cluster_name={1}".format(
                self.path, self.cluster_name)
        else:
            data = ZookeeperService.get(self.cluster_name, self.path)

        return self.render('config/znode/view.html',
                           data=data,
                           download_link=download_link)