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)
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;
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)
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)
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)
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)
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, )
def response(self): """获取zookeeper节点的元数据信息 """ metainfo = dict() zk_node = ZdZnode.one(path=self.path, cluster_name=self.cluster_name) if zk_node: metainfo['type'] = zk_node.type metainfo['business'] = zk_node.business return json.dumps(metainfo)
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
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)
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)
def set_znode(cluster_name, path, data, znode_type='0', business=''): """更新或增加znode节点,包括存储于mysql的元数据和存储于zookeeper上的data """ path = normalize_path(path) ZookeeperService.set_or_create(cluster_name, path, data) # 在mysql上存储znode的相关元数据,节点类型和业务说明 znode = ZdZnode.one(cluster_name=cluster_name, path=path, deleted="0") if znode is None: znode = ZdZnode(cluster_name=cluster_name, path=path) znode.type = znode_type znode.business = business znode.save() try: # 自动快照(如果配置信息没有变更,实际不会进行快照) SnapshotService.make_snapshot(cluster_name, path, data) except MakeSnapshotError as exc: log.error('make snapshot error: %s', str(exc))