示例#1
0
def build_client(Config, z_url):
	# Parse URL
	url_pieces = urlparse(z_url)
	url_netloc = url_pieces.netloc
	url_path = url_pieces.path

	# If there is no location, use implied
	if not url_netloc:
		# if server entry is missing exit
		if Config.has_option("asab:zookeeper", "servers"):
			L.error("Servers entry not passed in the configuration.")
			return None, None

		url_netloc = Config["asab:zookeeper"]["servers"]

	if url_path.startswith("./"):
		# if path entry is missing exit
		if Config.has_option("asab:zookeeper", "path"):
			L.error("Path entry not passed in the configuration.")
			return None, None

		url_path = Config["asab:zookeeper"]["path"] + url_path[1:]

	# Create and return the client and the url-path
	client = aiozk.ZKClient(url_netloc)
	return client, url_path
示例#2
0
async def main():
    zk = aiozk.ZKClient('localhost:2181')
    await zk.start()
    lock = zk.recipes.Lock('/path/to/lock')
    async with await lock.acquire():
        print('do some critical stuff')
    await zk.close()
示例#3
0
 def __init__(self, app, config_section_name, config=None):
     super().__init__(config_section_name=config_section_name,
                      config=config)
     self.App = app
     self.ConfigSectionName = config_section_name
     self.ZooKeeper = aiozk.ZKClient(self.Config["urls"])
     self.ZooKeeperPath = self.Config["path"]
示例#4
0
	def __init__(self, app, config_section_name, config=None):
		super().__init__(config_section_name=config_section_name, config=config)
		self.App = app
		self.Data = None
		self.ZooNode = '/defaultpath'
		self.ConfigSectionName = config_section_name
		self.ZooKeeper = aiozk.ZKClient(self.Config["servers"])
		self.ZooKeeperPath = self.Config["path"]
示例#5
0
async def main():
    ready = asyncio.Event()
    zk = aiozk.ZKClient('{}:2181'.format(os.environ.get("HOST_OF_TEST")))
    await zk.start()
    await zk.ensure_path("test")
    watcher = zk.recipes.ChildrenWatcher()
    watcher.set_client(zk)
    watcher.add_callback("test", children_callback)
    await asyncio.wait([ready.wait()], timeout=0.1)
示例#6
0
async def main():
    zk = aiozk.ZKClient('server1:2181,server2:2181,server3:2181')
    await zk.start()
    await zk.ensure_path('/greeting/to')
    await zk.create('/greeting/to/world', 'hello world')
    data, stat = await zk.get('/greeting/to/world')
    print(type(data))
    print(type(stat))
    print(data)
    # b'hello world' is printed
    await zk.delete('/greeting/to/world')
    await zk.close()
示例#7
0
文件: zktest.py 项目: jackwmj12/txrpc
async def main():
    zk = aiozk.ZKClient('{}:2181'.format(os.environ.get("HOST_OF_TEST")))
    await zk.start()
    await zk.ensure_path('/test')
    await zk.create('/test/to', 'hello world')
    data, stat = await zk.get('/test/to')
    print(type(data))
    print(type(stat))
    print(data)
    # b'hello world' is printed
    await zk.delete('/test/to')
    await zk.close()
示例#8
0
async def client_test():
    zk = aiozk.ZKClient('{}:2181'.format(os.environ.get("TEST_ZK_HOST")))
    await zk.start()
    await zk.ensure_path('/greeting/to')
    await zk.delete('/greeting/to/words')
    await zk.create('/greeting/to/words', "hello")
    data, stat = await zk.get('/greeting/to/words')
    # logger.debug(type(data))
    # logger.debug(type(stat))
    logger.debug(data.decode())
    # b'hello world' is printed
    # await zk.delete('/greeting/to/words')
    # await zk.close()
    return f"this is a response from client : {data.decode()}"
示例#9
0
文件: config.py 项目: TeskaLabs/asab
 async def download_from_zookeeper():
     try:
         zk = aiozk.ZKClient(
             url_netloc,
             allow_read_only=True,
             read_timeout=60,  # seconds #
         )
         await zk.start()
         data = await zk.get_data(url_path)
         # convert bytes to string
         encode_config = str(data, 'utf-8')
         self.read_string(encode_config)
         # Include in the list of config file contents
         self.config_contents_list.append(encode_config)
         await zk.close()
         # Re-enable logging output
     except Exception as e:
         L.error(
             "Failed to obtain configuration from zookeeper server(s): '{}'."
             .format(e))
         sys.exit(1)
示例#10
0
文件: server.py 项目: jackwmj12/txrpc
import aiozk
from twisted.internet import defer

from txrpc.globalobject import GlobalObject
from txrpc.utils import asDeferred
from txrpc.server import RPCServer

from loguru import logger

NODE_NAME = "SERVER"

with open(os.sep.join([os.path.dirname(os.path.abspath(__file__)),"config.json"])) as f:
    GlobalObject().config = json.load(f)

zk = aiozk.ZKClient('{}:2181'.format(os.environ.get("TEST_ZK_HOST")))

async def data_callback(d):
    logger.debug(d)
    # await asyncio.sleep(0.1)
    # try:
    #     await zk.delete('/greeting/to/words')
    # except Exception as e:
    #     logger.error(e)

@asDeferred
async def create_zk_water():
    await zk.start()
    await zk.ensure_path('/greeting/to')
    # watcher = zk.recipes.DataWatcher()
    # watcher.set_client(zk)
示例#11
0
async def main():
    zk = aiozk.ZKClient('localhost:2181')
    await zk.start()
    for acl in await zk.get_acl('/'):
        print(acl.id, acl.perms)
    await zk.close()