Example #1
0
    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)
Example #2
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)
Example #3
0
    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)
Example #4
0
    def response(self):
        '''savecopy
        '''
        # node_name中不可包含`/`特殊字符
        if self.path and not ZnodeService.is_node_name_ok(self.path):
            return self.ajax_popup(code=300, msg="节点名不允许包含特殊字符'/'!")

        zk_path = ""
        if not self.path:
            # 新增节点需要进行存在检验
            return self.ajax_popup(code=300, msg="节点名称不能为空!")
        else:
            zk_path = os.path.join(self.parent_path, self.path)
            if ZookeeperService.exists(self.cluster_name, zk_path):
                return self.ajax_popup(code=300, msg="节点已经存在!")

        normalized_path = normalize_path(self.old_path)
        nodes = []

        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)

        path = full_path(self.path,self.parent_path)
        #ZnodeService.save_znode_tree(self.cluster_name , normalized_path , path)

        index = self.old_path.rfind('/')
        old_node_name = self.old_path[index+1:]

        for node in nodes:
            new_path = node['path'].replace(old_node_name,self.path,1)
            ZnodeService.save_znode_tree(self.cluster_name , node['path'] ,new_path)
        #ret = ZnodeService.save_znode_tree(self.cluster_name ,self.parent_path,self.old_path,self.path)

        #if not ret:
        #    return self.ajax_popup(code=300,msg='添加失败')
        return self.ajax_ok(close_current=True)