示例#1
0
 def expire(self, session_id=None):
   if session_id is None:
     if self._zh is None:
       raise self.NotStarted('Must specify session id if no client connection available!')
     session_id, _ = zookeeper.client_id(self._zh)
   expireResponse = self.angrybird.expireSession(ExpireSessionRequest(sessionId=session_id))
   return expireResponse.responseCode == ResponseCode.OK
示例#2
0
 def expire(self, session_id=None):
   if session_id is None:
     if self._zh is None:
       raise self.NotStarted('Must specify session id if no client connection available!')
     session_id, _ = zookeeper.client_id(self._zh)
   expireResponse = self.angrybird.expireSession(ExpireSessionRequest(sessionId=session_id))
   return expireResponse.responseCode == ResponseCode.OK
示例#3
0
    def __get_host_node_path__(self) :
        client_id = zookeeper.client_id(self.handle)[0]

        if self.is_running_service == True :
            return self.local_ip + SEP_CHAR + self.service_version + SEP_CHAR + str(client_id) + SEP_CHAR
        else :
            return self.local_ip + SEP_CHAR + str(self.service_port) + SEP_CHAR + self.service_version + SEP_CHAR + str(client_id) + SEP_CHAR
示例#4
0
 def _global_watch(self, zh, event, state, path):
   """Called when the connection to zookeeper has a state change."""
   if state == zookeeper.EXPIRED_SESSION_STATE:
     self._connect()
   if state == zookeeper.CONNECTED_STATE:
     self._clientid = zookeeper.client_id(self._zookeeper)
     # Catch up all gets requested before we were able to connect.
     while self._pending_gets:
       path, w, h = self._pending_gets.pop()
       zookeeper.aget(self._zookeeper, path, w, h)
示例#5
0
    def client_id(self):
        """Returns the client id that identifies the server side session.

        A client id is a tuple represented by the session id and
        session password. It can be used to manually connect to an
        extant server session (which contains associated ephemeral
        nodes and watches)/ The connection's client id is also useful
        when introspecting the server logs for specific client
        activity.
        """
        if self.handle is None:
            return None
        try:
            return zookeeper.client_id(self.handle)
        # Invalid handle
        except zookeeper.ZooKeeperException:
            return None
示例#6
0
    def testclientid(self):
        cv = threading.Condition()
        self.connected = False
        def connection_watcher(handle, type, state, path):
            cv.acquire()
            self.connected = True
            cv.notify()
            cv.release()

        cv.acquire()
        self.handle = zookeeper.init(self.host, connection_watcher,10000,(123456,"mypassword"))
        self.assertEqual(self.handle, zookeeper.OK)
        cv.wait(15.0)
        cv.release()
        self.assertEqual(self.connected, True, "Connection timed out to " + self.host)
        (cid,passwd) = zookeeper.client_id(self.handle)
        self.assertEqual(cid,123456)
        self.assertEqual(passwd,"mypassword")   
示例#7
0
  def _global_watch(self, zh, event, state, path):
    """Called when the connection to zookeeper has a state change."""
    logging.debug('Global watch fired: %s %s %s' % (event, state, path))
    if state == zookeeper.EXPIRED_SESSION_STATE:
      self._clientid = None
      self._connect()
    elif state == zookeeper.CONNECTED_STATE:
      self._clientid = zookeeper.client_id(self._zookeeper)
      # Re-get all existing watched files.
      logging.debug('Registering watches on existing watch objects.')
      for path in self._watches.iterkeys():
        logging.debug('Registering watch against: %s' % path)
        h = self._handler_wrapper(path)
        zookeeper.aget(self._zookeeper, path, self._watcher, h)

      # Catch up all gets requested before we were able to connect.
      while self._pending_gets:
        path, w, h = self._pending_gets.pop()
        zookeeper.aget(self._zookeeper, path, w, h)
    def testclientid(self):
        cv = threading.Condition()
        self.connected = False

        def connection_watcher(handle, type, state, path):
            cv.acquire()
            self.connected = True
            cv.notify()
            cv.release()

        cv.acquire()
        self.handle = zookeeper.init(self.host, connection_watcher, 10000,
                                     (123456, "mypassword"))
        self.assertEqual(self.handle, zookeeper.OK)
        cv.wait(15.0)
        cv.release()
        self.assertEqual(self.connected, True,
                         "Connection timed out to " + self.host)
        (cid, passwd) = zookeeper.client_id(self.handle)
        self.assertEqual(cid, 123456)
        self.assertEqual(passwd, "mypassword")
import os

import zookeeper
import pykeeper

host = os.environ['DOTCLOUD_ZOOKEEPER_CONNECTION_HOST']
port = os.environ['DOTCLOUD_ZOOKEEPER_CONNECTION_PORT']
connection_str = '%s:%s' % (host, port)
#client = pykeeper.ZooKeeper(connection_str)

def callback(*args, **kwargs):
    print args
    print kwargs

handle = zookeeper.init(connection_str, callback)

zookeeper.client_id(handle)
zookeeper.exists(handle, '/')
zookeeper.get(handle, '/')
zookeeper.get_children(handle, '/')
zookeeper.state(handle)
示例#10
0
 def session_id(self):
   session_id, _ = zookeeper.client_id(self._zh)
   return session_id
import os

import zookeeper
import pykeeper

host = os.environ['DOTCLOUD_ZOOKEEPER_CONNECTION_HOST']
port = os.environ['DOTCLOUD_ZOOKEEPER_CONNECTION_PORT']
connection_str = '%s:%s' % (host, port)
#client = pykeeper.ZooKeeper(connection_str)


def callback(*args, **kwargs):
    print args
    print kwargs


handle = zookeeper.init(connection_str, callback)

zookeeper.client_id(handle)
zookeeper.exists(handle, '/')
zookeeper.get(handle, '/')
zookeeper.get_children(handle, '/')
zookeeper.state(handle)
示例#12
0
 def client_id(self):
     if self._handle is not None:
         return zookeeper.client_id(self._handle)
     return None
示例#13
0
 def session_id(self):
   try:
     session_id, _ = zookeeper.client_id(self._zh)
     return session_id
   except:
     return None
示例#14
0
 def client_id(self):
     return zookeeper.client_id(self._zhandle)
示例#15
0
文件: client.py 项目: nkvoll/pykeeper
 def client_id(self):
     if self.handle is None:
         return None
     return zookeeper.client_id(self.handle)
示例#16
0
 def session(self):
     """Returns zookeeper api (session, session_password) tuple."""
     return zookeeper.client_id(self.handle)
示例#17
0
 def client_id(self):
     if self._handle is not None:
         return zookeeper.client_id(self._handle)
     return None
示例#18
0
 def session_id(self):
     session_id, _ = zookeeper.client_id(self._zh)
     return session_id
示例#19
0
文件: client.py 项目: young8/pykeeper
 def client_id(self):
     if self.handle is None:
         return None
     return zookeeper.client_id(self.handle)
示例#20
0
 def session_id(self):
     try:
         session_id, _ = zookeeper.client_id(self._zh)
         return session_id
     except:
         return None
示例#21
0
 def session(self):
     """Returns zookeeper api (session, session_password) tuple."""
     return zookeeper.client_id(self.handle)