def get_connected_zookeeper_client(): zookeeper_client = KazooClient('33.33.33.10:2181') zookeeper_client zookeeper_client.connect() return zookeeper_client
def expire_session(self, client_id=None): """Force ZK to expire a client session :param client_id: id of client to expire. If unspecified, the id of self.client will be used. """ client_id = client_id or self.client.client_id client = KazooClient(self.cluster[1].address, client_id=client_id) client.connect() client.stop()
def connect_to_zookeeper(hostlist, credentials): """Create a connection to the ZooKeeper ensemble. If authentication credentials are provided (as a two-tuple: username, password), we will ensure that they are provided to the server whenever we establish a connection. """ client = KazooClient(hostlist, timeout=5, max_retries=3) # convenient helper function for making credentials client.make_acl = functools.partial(make_digest_acl, *credentials) client.connect() client.add_auth("digest", ":".join(credentials)) return client
if 'SENTRY_DSN' in app.config: sentry = Sentry(app) jones_credential = make_digest_acl_credential( 'Jones', app.config['ZK_DIGEST_PASSWORD'] ) zk = KazooClient( app.config['ZK_CONNECTION_STRING'], default_acl=( # grants read permissions to anyone. make_acl('world', 'anyone', read=True), # grants all permissions to the creator of the node. make_acl('auth', '', all=True) ) ) zk.connect() zk.add_auth('digest', jones_credential) zk.ensure_path('/services') def request_wants(t): types = ['text/plain', 'text/html', 'application/json'] assert t in types best = request.accept_mimetypes \ .best_match(types) return best == t @app.template_filter() def as_json(d, indent=None): return Markup(json.dumps(d, indent=indent))
parser = OptionParser() parser.add_option('--zookeeper', help='zookeeper hosts', default=None) parser.add_option('--log-level', dest='loglevel', help='log level', default='DEBUG') options, args = parser.parse_args() zookeeper_kwargs = {} if options.zookeeper is not None: zookeeper_kwargs['hosts'] = options.zookeeper logger = logging.getLogger() logger.setLevel(getattr(logging, options.loglevel.upper())) logger.addHandler(logging.StreamHandler()) zookeeper = KazooClient(**zookeeper_kwargs) zookeeper.connect() kafka = Cluster(zookeeper) exposed = { 'kafka': kafka, 'zookeeper': zookeeper, } banner = """--- Welcome to PyKafka! We've provided some local variables for you: %s ---""" % '\n'.join('> %s: %s' % (key, repr(value)) for key, value in exposed.iteritems()) code.interact(banner, local=exposed)
dest='loglevel', help='log level', default='DEBUG') options, args = parser.parse_args() zookeeper_kwargs = {} if options.zookeeper is not None: zookeeper_kwargs['hosts'] = options.zookeeper logger = logging.getLogger() logger.setLevel(getattr(logging, options.loglevel.upper())) logger.addHandler(logging.StreamHandler()) zookeeper = KazooClient(**zookeeper_kwargs) zookeeper.connect() kafka = Cluster(zookeeper) exposed = { 'kafka': kafka, 'zookeeper': zookeeper, } banner = """--- Welcome to Samsa! We've provided some local variables for you: %s ---""" % '\n'.join('> %s: %s' % (key, repr(value)) for key, value in exposed.iteritems()) code.interact(banner, local=exposed)