当前位置: 首页>>代码示例>>Python>>正文


Python zookeeper.get函数代码示例

本文整理汇总了Python中zookeeper.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sync_getset

 def test_sync_getset(self):
     self.assertEqual(self.connected, True, "Not connected!")
     (data,stat) = zookeeper.get(self.handle, "/zk-python-getsettest", None)
     self.assertEqual(data, "on", "Data is not 'on' as expected: " + data)
     ret = zookeeper.set(self.handle, "/zk-python-getsettest",
                         "off", stat["version"])
     (data,stat) = zookeeper.get(self.handle, "/zk-python-getsettest", None)
     self.assertEqual(data, "off", "Data is not 'off' as expected: " + data)        
开发者ID:jacksonicson,项目名称:twospot,代码行数:8,代码来源:get_set_test.py

示例2: notifyFailedTransaction

  def notifyFailedTransaction(self, app_id, txid):
    """ Notify failed transaction id.

    This method will add the transaction id into black list.
    After this call, the transaction becomes invalid.
    """
    self.__waitForConnect()
    self.checkTransaction(app_id, txid)
    print "notify failed transaction app:%s, txid:%d" % (app_id, txid)
    txpath = self.__getTransactionPath(app_id, txid)
    lockpath = None
    try:
      lockpath = zookeeper.get(self.handle, PATH_SEPARATOR.join([txpath, TX_LOCK_PATH]), None)[0]
    except zookeeper.NoNodeException:
      # there is no lock. it means there is no need to rollback.
      pass

    if lockpath:
      # add transacion id to black list.
      now = str(time.time())
      broot = self.__getBlacklistRootPath(app_id)
      if not zookeeper.exists(self.handle, broot):
        self.__forceCreatePath(broot)
      zookeeper.acreate(self.handle, PATH_SEPARATOR.join([broot, str(txid)]), now, ZOO_ACL_OPEN)
      # update local cache before notification
      if app_id in self.blacklistcache:
        with self.blacklistcv:
          self.blacklistcache[app_id].add(str(txid))
      # copy valid transaction id for each updated key into valid list.
      for child in zookeeper.get_children(self.handle, txpath):
        if re.match("^" + TX_UPDATEDKEY_PREFIX, child):
          value = zookeeper.get(self.handle, PATH_SEPARATOR.join([txpath, child]), None)[0]
          valuelist = value.split(PATH_SEPARATOR)
          key = urllib.unquote_plus(valuelist[0])
          vid = valuelist[1]
          vtxroot = self.__getValidTransactionRootPath(app_id)
          if not zookeeper.exists(self.handle, vtxroot):
            self.__forceCreatePath(vtxroot)
          vtxpath = self.__getValidTransactionPath(app_id, key)
          zookeeper.acreate(self.handle, vtxpath, vid, ZOO_ACL_OPEN)
      # release the lock
      try:
        zookeeper.adelete(self.handle, lockpath)
      except zookeeper.NoNodeException:
        # this should be retry.
        pass

    # just remove transaction node
    try:
      for item in zookeeper.get_children(self.handle, txpath):
        zookeeper.adelete(self.handle, PATH_SEPARATOR.join([txpath, item]))
      zookeeper.adelete(self.handle, txpath)
    except zookeeper.NoNodeException:
      # something wrong. next GC will take care of it.
      return False

    return True
开发者ID:Tomting,项目名称:appscale,代码行数:57,代码来源:zktransaction.py

示例3: test_sync_get_large_datanode

    def test_sync_get_large_datanode(self):
        """
        Test that we can retrieve datanode sizes up to
        1Mb with default parameters (depends on ZooKeeper server).
        """

        data = "".join(["A" for x in xrange(1024 * 1023)])
        self.ensureDeleted("/zk-python-test-large-datanode")
        zookeeper.create(
            self.handle, "/zk-python-test-large-datanode", data, [{"perms": 0x1F, "scheme": "world", "id": "anyone"}]
        )
        (ret, stat) = zookeeper.get(self.handle, "/zk-python-test-large-datanode")
        self.assertEqual(len(ret), 1024 * 1023, "Should have got 1Mb returned, instead got %s" % len(ret))
        (ret, stat) = zookeeper.get(self.handle, "/zk-python-test-large-datanode", None, 500)
        self.assertEqual(len(ret), 500, "Should have got 500 bytes returned, instead got %s" % len(ret))
开发者ID:AkihiroSuda,项目名称:PCheck,代码行数:15,代码来源:get_set_test.py

示例4: getReadLock

    def getReadLock(self, metadata):
        #Acquire read lock on file through ZooKeeper
        fn = metadata.filename
        print "Trying to acquire read lock for " + self.root + fn
        self.zpath = self.createLockNode(fn, 'r')
        myLock = self.zpath.rsplit('/',1)[1]
        while True:
            children = sorted(zookeeper.get_children(self.zh, self.root + fn))
            lastLock = ''
            for child in children:
                try:
                    if child == myLock:
                        break
                    elif zookeeper.get(self.zh, self.root+fn+'/'+child)[0] == 'w':
                        lastLock = child
                except:
                    pass
            if lastLock != '':
                def watcher (handle, type, state, path):
                    self.cv2.acquire()
                    self.cv2.notify()
                    self.cv2.release()

                self.cv2.acquire()
                if zookeeper.exists(self.zh, self.root+fn+'/'+lastLock, watcher):
                    self.cv2.wait()
                self.cv2.release()
            else:
                break
        print "Acquired read lock for " + self.root + fn
开发者ID:ialzuru,项目名称:ncfs,代码行数:30,代码来源:zk.py

示例5: __init__

  def __init__(self, service_name, connect_string, timeout=DEFAULT_TIMEOUT, default_port=6664):
    self.SERVICE_NODE = "/" + service_name
    self.AVAILABILITY_NODE = self.SERVICE_NODE + "/available"
    self.MEMBERSHIP_NODE = self.SERVICE_NODE + "/members"
    self.connected = False
    self.timeout = timeout
    self.default_port = default_port
    self.conn_cv = threading.Condition()
    self.conn_cv.acquire()
    self.handle = zookeeper.init(connect_string, self.connection_watcher, timeout)
    self.conn_cv.wait(timeout / 1000)
    self.conn_cv.release()
    self.watcher_lock = threading.Lock()
    self.logger = logging.getLogger("sincc")

    if not self.connected:
      raise SinClusterClientError("Unable to connect to %s" % connect_string)

    for path in [self.SERVICE_NODE, self.AVAILABILITY_NODE, self.MEMBERSHIP_NODE]:
      if not zookeeper.exists(self.handle, path):
        zookeeper.create(self.handle, path, "", [ZOO_OPEN_ACL_UNSAFE], 0)
    self.listeners = []
    # Start to watch both /members and /available
    zookeeper.get_children(self.handle, self.MEMBERSHIP_NODE, self.watcher)
    available = zookeeper.get_children(self.handle, self.AVAILABILITY_NODE, self.watcher)
    self.available_nodes = {}
    for node_id in available:
      self.available_nodes[int(node_id)] = Node(int(node_id),
                                                zookeeper.get(self.handle, self.AVAILABILITY_NODE + "/" + node_id)[0])
开发者ID:alanma,项目名称:sin,代码行数:29,代码来源:sincc.py

示例6: unlock

 def unlock(self):
     try:
         (data, _) = zookeeper.get(self.handle, self.lockname, None)
         if data == self.uuid:
             zookeeper.delete(self.handle, self.lockname)
     except:
         self.log.exception('unlock')
开发者ID:F-Secure,项目名称:distci,代码行数:7,代码来源:sync.py

示例7: set

    def set(self, path, data='', previous_data=None):
        path = '%s%s' % (self.prefix, path)
        try:
            current_data, current_meta = zookeeper.get(self.handle, path, None)
        except zookeeper.NoNodeException:
            if not previous_data:
                try:
                    zookeeper.create(self.handle, path, data, [ZOO_OPEN_ACL_UNSAFE])
                    return True
                except:
                    self.log.exception('Failed to create a missing key %s', path)
                    return False
            else:
                return False
        except:
            self.log.exception('Failed to set key %s', path)
            return False

        version = None
        if previous_data:
            if current_data != previous_data:
                self.log.error('Previous data constraint failed')
                return False
            version = current_meta['version']

        try:
            if version is None:
                zookeeper.set(self.handle, path, data)
            else:
                zookeeper.set(self.handle, path, data, version)
        except:
            self.log.exception('Set failed')
            return False

        return True
开发者ID:F-Secure,项目名称:distci,代码行数:35,代码来源:sync.py

示例8: __init__

  def __init__(self,queuename, port, is_producer=False):
    self.connected = False
    self.queuename = "/" + queuename
    self.cv = threading.Condition()
    zookeeper.set_log_stream(open("/dev/null"))
    def watcher(handle,type,state,path):
      print "Connected"
      self.cv.acquire()
      self.connected = True
      self.cv.notify()
      self.cv.release()

    self.cv.acquire()
    self.handle = zookeeper.init("localhost:%d" % port, watcher, 10000)
    self.cv.wait(10.0)
    if not self.connected:
      print "Connection to ZooKeeper cluster timed out - is a server running on localhost:%d?" % port
      sys.exit()
    self.cv.release()
    if is_producer:
      while True:
        try:
          zookeeper.create(self.handle,self.queuename,"queue top level", [ZOO_OPEN_ACL_UNSAFE],0)
          print "Fila criada, OK"
          return
        except zookeeper.NodeExistsException:
          print "Tratorando filas existentes"
          while True:
            children = sorted(zookeeper.get_children(self.handle, self.queuename,None))
            if len(children) == 0:
              (data,stat) = zookeeper.get(self.handle, self.queuename, None)
              zookeeper.delete(self.handle, self.queuename, stat["version"])
              break
            for child in children:
              data = self.get_and_delete(self.queuename + "/" + child)
开发者ID:alexcremonezi,项目名称:pyzk-recipes,代码行数:35,代码来源:queue.py

示例9: zookeeper_watch

    def zookeeper_watch(self, zh, event, state, path):
        self.cond.acquire()
        try:
            result = None
            if event == zookeeper.CHILD_EVENT:
                fns = self.child_watches.get(path, None)
                if fns:
                    try:
                        result = zookeeper.get_children(self.handle, path, self.zookeeper_watch)
                    except zookeeper.NoNodeException:
                        result = None
            elif event == zookeeper.CHANGED_EVENT:
                fns = self.content_watches.get(path, None)
                if fns:
                    try:
                        result, _ = zookeeper.get(self.handle, path, self.zookeeper_watch)
                    except zookeeper.NoNodeException:
                        result = None
            else:
                return

            if result != None and fns != None:
                for fn in fns:
                    # Don't allow an individual watch firing an exception to
                    # prevent all other watches from being fired. Just log an
                    # error message and moved on to the next callback.
                    try:
                        fn(result)
                    except Exception:
                        logging.exception("Error executing watch for %s.", path)
        finally:
            self.cond.release()
开发者ID:mydaisy2,项目名称:reactor-core,代码行数:32,代码来源:connection.py

示例10: handle_availability_changed

 def handle_availability_changed(self):
   available = zookeeper.get_children(self.handle, self.AVAILABILITY_NODE, self.watcher)
   self.available_nodes.clear()
   for node_id in available:
     self.available_nodes[int(node_id)] = Node(int(node_id),
                                               zookeeper.get(self.handle, self.AVAILABILITY_NODE + "/" + node_id)[0])
   self.notify_all()
开发者ID:alanma,项目名称:sin,代码行数:7,代码来源:sincc.py

示例11: __tryGC

  def __tryGC(self, app_id, app_path):
    try:
#      print "try to obtrain app %s lock" % app_id
      val = zookeeper.get(self.handle, PATH_SEPARATOR.join([app_path, GC_TIME_PATH]), None)[0]
      lasttime = float(val)
    except zookeeper.NoNodeException:
      lasttime = 0
    if lasttime + GC_INTERVAL < time.time():
      # try to gc this app.
      gc_path = PATH_SEPARATOR.join([app_path, GC_LOCK_PATH])
      try:
        now = str(time.time())
        zookeeper.create(self.handle, gc_path, now, ZOO_ACL_OPEN, zookeeper.EPHEMERAL)
        # succeed to obtain lock.
        # TODO: should we handle the timeout of gc also?
        try:
          self.__executeGC(app_id, app_path)
          # update lasttime when gc was succeeded.
          now = str(time.time())
          self.__updateNode(PATH_SEPARATOR.join([app_path, GC_TIME_PATH]), now)
        except Exception, e:
          print "warning: gc error %s" % e
          traceback.print_exc()
        zookeeper.delete(self.handle, gc_path, -1)
      except zookeeper.NodeExistsException:
        # fail to obtain lock. try next time.
        pass
开发者ID:Tomting,项目名称:appscale,代码行数:27,代码来源:zktransaction.py

示例12: queue_callback

 def queue_callback(self, zh, rc, data):
   if zookeeper.OK == rc:
     try:
       for child in sorted(data):
         action = self.actionNode + '/' + child
         workLog = self.actionNode + '/' + child + '/worklog'
         statusLog = self.statusNode + '/status-'
         """ Launch the task if the task has not been executed """
         if zookeeper.exists(zh, workLog, None) == None:
           self.launch(zh, workLog, action, statusLog)
         else:
           """ If task has been previous launched, check for partial execution """
           buffer = zookeeper.get(zh, workLog, 0)
           state = simplejson.loads(buffer[0])
           """ If task is incompleted in execution, launch again """
           if 'status' in state and state['status'] == 'STARTING':
             logger.info('Relaunch '+child)
             self.launch(zh, workLog, action, statusLog)
           else:
             """ If the task has been launched, and completed, update status queue """
             if zookeeper.exists(zh, statusLog, None) == None:
               logger.info('Update status.')
               self.update(zh, statusLog, state)
     except NoNodeException, err:
       """ Skip no node exception """
     except Exception, err:
       logger.exception(err)
开发者ID:sreev,项目名称:ambari,代码行数:27,代码来源:ZooKeeperCommunicator.py

示例13: notify_failed_transaction

  def notify_failed_transaction(self, app_id, txid):
    """ Marks the given transaction as failed, invalidating its use by future
    callers.

    Args:
      app_id: The application ID whose transaction we wish to invalidate.
      txid: An int representing the transaction ID we wish to invalidate.
    Returns:
      True if the transaction was invalidated, False otherwise.
    """
    logging.warning("Notify failed transaction app: {0}, txid: {1}"\
      .format(app_id, str(txid)))

    self.wait_for_connect()
    lockpath = None
    lock_list = []

    txpath = self.get_transaction_path(app_id, txid)

    try:
      lockpath = zookeeper.get(self.handle, 
          PATH_SEPARATOR.join([txpath, TX_LOCK_PATH]), None)[0]
      lock_list = lockpath.split(LOCK_LIST_SEPARATOR)
    except zookeeper.NoNodeException:
      # There is no need to rollback because there is no lock.
      pass
    except zookeeper.ZooKeeperException, zoo_exception:
      logging.error("Exception seen when notifying a failed transaction {0}"\
        .format(str(zoo_exception)))
      return
开发者ID:deepy,项目名称:appscale-debian,代码行数:30,代码来源:zktransaction.py

示例14: launch

  def launch(self, zh, workLogNode, actionNode, statusNode):
    state = {}
    data = zookeeper.get(zh, actionNode, 0)
    jsonp = simplejson.loads(data[0])
    state['cmdPath'] = jsonp['cmdPath']
    state['actionPath'] = actionNode
    state['actionId'] = jsonp['actionId']
    state['host'] = self.znode
    state['status']='STARTING'
    self.update(zh, workLogNode, state)

    logger.info("Launch: "+simplejson.dumps(jsonp))
    dispatcher = Runner()
    try:
      result = dispatcher.run(jsonp)
      logger.info("Result: "+simplejson.dumps(result))
      if "exit_code" in result and result['exit_code']==0:
        state['status']='SUCCEEDED'
      else:
        state['status']='FAILED'
    except:
      logger.exception('Execution error: '+actionNode)
      state['status']='FAILED'
    self.update(zh, workLogNode, state)
    self.enqueue(zh, statusNode, state)
开发者ID:sreev,项目名称:ambari,代码行数:25,代码来源:ZooKeeperCommunicator.py

示例15: get

def get(path):
    init_client()
    global handle
    try:
        (data,stat) = zookeeper.get(handle,path,None)
        return data
    except zookeeper.NoNodeException:
        return None
开发者ID:snlei,项目名称:jafka,代码行数:8,代码来源:jafka-watcher.py


注:本文中的zookeeper.get函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。