• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python zookeeper.delete函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __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


示例2: setUp

 def setUp(self):
   zktestbase.TestBase.setUp(self)
   try:
     zookeeper.delete(self.handle, "/zk-python-acltest")
     zookeeper.delete(self.handle, "/zk-python-aacltest")
   except:
     pass
开发者ID:10fish,项目名称:datafari,代码行数:7,代码来源:acl_test.py


示例3: __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


示例4: remove_machine

 def remove_machine(self, machine):
     try:
         zookeeper.delete(self._z,
                          machine)
         return True
     except zookeeper.NoNodeException:
         return False
开发者ID:sholiday,项目名称:odin,代码行数:7,代码来源:odin.py


示例5: post

    def post(self):
	request_dict = self.request.arguments
	node_key = (request_dict['node_key'])[0]
        cluster_name  = (request_dict['cluster_name'])[0]
        zk=zookeeper.init(self.zk_connect(cluster_name))


        data = []
        def get_node_tree(node_key):
            if node_key == "/":
                for node in zookeeper.get_children(zk,node_key):
                     key =  "/" + node
                     if (zookeeper.get(zk,key)[1])['numChildren'] > 0:
                          get_node_tree(key)
                          print key
                     else:
                          print key
            else:
                for node in zookeeper.get_children(zk,node_key):
                     key =  node_key + "/" + node
                     if (zookeeper.get(zk,key)[1])['numChildren'] > 0:
                          get_node_tree(key)
                          data.append(key)
                     else:
                          data.append(key)
        
            return data

	get_node_tree(node_key)
	data.append(node_key)

	for items in data:
	    zookeeper.delete(zk,items)
        zookeeper.close(zk)                                                                                                                          
        self.write("删除成功")
开发者ID:xiaoyang2008mmm,项目名称:zkdash,代码行数:35,代码来源:views.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: delete_tree

def delete_tree (zh, path):
	path = path.replace('//', '/')
	try:
		for n in tuple(zookeeper.get_children(zh, path)):
			delete_tree(zh, path + '/' + n)
		zookeeper.delete(zh, path)
	except:
		pass
开发者ID:amogrid,项目名称:redcurrant,代码行数:8,代码来源:zk-reset.py


示例8: delete_recursive

def delete_recursive(handle, path):
  try:
    children = zookeeper.get_children(handle, path)
    for child in children:
      delete_recursive(handle, PATH_SEPARATOR.join([path, child]))
    zookeeper.delete(handle, path, -1)
  except zookeeper.NoNodeException:
    pass
开发者ID:deepy,项目名称:appscale-debian,代码行数:8,代码来源:flush_zk.py


示例9: deleteRecursive

 def deleteRecursive(self, path):
   self.__waitForConnect()
   try:
     children = zookeeper.get_children(self.handle, path)
     for child in children:
       self.deleteRecursive(PATH_SEPARATOR.join([path, child]))
     zookeeper.delete(self.handle, path, -1)
   except zookeeper.NoNodeException:
     pass
开发者ID:Tomting,项目名称:appscale,代码行数:9,代码来源:zktransaction.py


示例10: remove_node

  def remove_node(self, node_id):
    """Remove a node from the cluster."""

    path = self.MEMBERSHIP_NODE + "/" + str(node_id)
    try:
      zookeeper.delete(self.handle, path)
      self.logger.info("Node %d is removed" % node_id)
    except zookeeper.NoNodeException:
      self.logger.warn("%s does not exist" % path)
开发者ID:alanma,项目名称:sin,代码行数:9,代码来源:sincc.py


示例11: get_and_delete

 def get_and_delete(self,node):
     try:
         (data,stat) = zookeeper.get(self.handle, node, None)
         zookeeper.delete(self.handle, node, stat["version"])
         return data
     except IOError, e:
         if e.message == zookeeper.zerror(zookeeper.NONODE):
             return None 
         raise e
开发者ID:JackyYangPassion,项目名称:hbase-code,代码行数:9,代码来源:zk_queue.py


示例12: write

    def write(self, path, contents, ephemeral=False, exclusive=False):
        """ 
        Writes the contents to the path in zookeeper. It will create the path in
        zookeeper if it does not already exist.

        This method will return True if the value is written, False otherwise.
        (The value will not be written if the exclusive is True and the node
        already exists.)
        """
        partial_path = ''

        # We start from the second element because we do not want to inclued
        # the initial empty string before the first "/" because all paths begin
        # with "/". We also don't want to include the final node because that
        # is dealt with later.

        for path_part in path.split("/")[1:-1]:
            partial_path = partial_path + "/" + path_part
            if not(zookeeper.exists(self.handle, partial_path)):
                try:
                    zookeeper.create(self.handle, partial_path, '', [self.acl], 0)
                except zookeeper.NodeExistsException:
                    pass

        exists = zookeeper.exists(self.handle, path)

        # Don't create it if we're exclusive.
        if exists and exclusive:
            return False

        # We make sure that we have the creation flags for ephemeral nodes,
        # otherwise they could be associated with previous connections that
        # have not yet timed out.
        if ephemeral and exists:
            try:
                zookeeper.delete(self.handle, path)
            except zookeeper.NoNodeException:
                pass
            exists = False

        if exists:
            zookeeper.set(self.handle, path, contents)
            return True
        else:
            flags = (ephemeral and zookeeper.EPHEMERAL or 0)
            try:
                zookeeper.create(self.handle, path, contents, [self.acl], flags)
                return True
            except zookeeper.NodeExistsException:
                if not(exclusive):
                    # Woah, something happened between the top and here.
                    # We just restart and retry the whole routine.
                    self.write(path, contents, ephemeral=ephemeral)
                    return True
                else:
                    return False
开发者ID:rmahmood,项目名称:reactor-core,代码行数:56,代码来源:connection.py


示例13: mark_node_unavailable

  def mark_node_unavailable(self, node_id):
    """Mark a node unavailable."""

    path = self.AVAILABILITY_NODE + "/" + str(node_id)
    try:
      data = zookeeper.get(self.handle, path)[0]
      zookeeper.delete(self.handle, path)
      self.logger.info("Node %d: %s is now unavailable" % (node_id, data))
    except zookeeper.NoNodeException:
      self.logger.warn("Tried to mark node %s unavailable, but it did not exist" % path)
开发者ID:alanma,项目名称:sin,代码行数:10,代码来源:sincc.py


示例14: deleteNode

 def deleteNode(self, zpath):
     #Delete a node recursively until root node
     while zpath != self.root[:-1]:
         try:
             zookeeper.delete(self.zh, zpath)
         except zookeeper.NoNodeException:
             pass
         except zookeeper.NotEmptyException:
             break
         finally:
             zpath = zpath[:-1].rsplit('/', 1)[0]
开发者ID:ialzuru,项目名称:ncfs,代码行数:11,代码来源:zk.py


示例15: reset

  def reset(self):
    """Reset both MEMBERSHIP_NODE and AVAILABILITY_NODE to empty nodes."""

    nodes = zookeeper.get_children(self.handle, self.MEMBERSHIP_NODE)
    for node_id in nodes:
      path = self.MEMBERSHIP_NODE + "/" + node_id
      try:
        zookeeper.delete(self.handle, path)
        self.logger.info("Node %s is removed (because of reset)" % node_id)
      except zookeeper.NoNodeException:
        self.logger.warn("%s does not exist" % path)
开发者ID:alanma,项目名称:sin,代码行数:11,代码来源:sincc.py


示例16: delete

 def delete(self, path, version=-1, recursive=False):
     """
     删除节点,可以制定特定版本的节点,默认是-1,即删除所有版本节点
     """
     if recursive:
         for child in self.get_children(path):
             self.delete(path=os.path.join(path, child), recursive=True)
     zookeeper.delete(self.handle, path, version)
     if not self.exists(path):
         return 1
     else:
         return 0
开发者ID:slient2010,项目名称:ManageGame,代码行数:12,代码来源:zkclient.py


示例17: clean_tree

 def clean_tree(zh, root):
   """Recursively removes the zookeeper subtree underneath :root given zookeeper handle :zh."""
   try:
     if not zookeeper.exists(zh, root):
       return True
     for child in zookeeper.get_children(zh, root):
       if not ZookeeperUtil.clean_tree(zh, posixpath.join(root, child)):
         return False
     zookeeper.delete(zh, root)
   except zookeeper.ZooKeeperException as e:
     return False
   return True
开发者ID:BabyDuncan,项目名称:commons,代码行数:12,代码来源:util.py


示例18: deleteTree

 def deleteTree(self, path="/", handle=1):
     """
     Destroy all the nodes in zookeeper path
     """
     for child in zookeeper.get_children(handle, path):
         if child == "zookeeper":  # skip the metadata node
             continue
         child_path = "/" + ("%s/%s" % (path, child)).strip("/")
         try:
             self.deleteTree(child_path, handle)
             zookeeper.delete(handle, child_path, -1)
         except zookeeper.ZooKeeperException, e:
             print "Error on path", child_path, e
开发者ID:Wallix-Resilience,项目名称:LogMonitor,代码行数:13,代码来源:test_logMonitor.py


示例19: release

 def release(self):
     # All release has to do, if you follow the logic in acquire, is delete the unique ID that this lock created.  That will wake
     # up all the other waiters and whoever is first in line can then have the lock.
     global handle
     released = False
     while not released:
         try:
             zookeeper.delete(handle, self.znode)
             released = True
         except zookeeper.ConnectionLossException:
             reconnect()
     self.znode = None
     self.keyname = None
开发者ID:dllhlx,项目名称:zklock,代码行数:13,代码来源:zklock.py


示例20: _write

    def _write(self, path, contents, ephemeral, exclusive, sequential, mustexist):
        # We start from the second element because we do not want to inclued
        # the initial empty string before the first "/" because all paths begin
        # with "/". We also don't want to include the final node because that
        # is dealt with later.
        partial_path = ''
        for path_part in path.split("/")[1:-1]:
            partial_path = partial_path + "/" + path_part
            if not(zookeeper.exists(self.handle, partial_path)):
                try:
                    zookeeper.create(self.handle, partial_path, '', [self.acl], 0)
                except zookeeper.NodeExistsException:
                    pass

        if sequential:
            exists = False
        else:
            exists = zookeeper.exists(self.handle, path)

        # Don't create it if we're exclusive.
        if exists and exclusive:
            return False

        # Check if we require the node to exist.
        if not exists and mustexist:
            return False

        # We make sure that we have the creation flags for ephemeral nodes,
        # otherwise they could be associated with previous connections that
        # have not yet timed out.
        if ephemeral and exists:
            try:
                zookeeper.delete(self.handle, path)
            except zookeeper.NoNodeException:
                pass
            exists = False

        if exists:
            zookeeper.set(self.handle, path, contents)
            return path
        else:
            flags = 0
            if ephemeral:
                flags = flags | zookeeper.EPHEMERAL
            if sequential:
                flags = flags | zookeeper.SEQUENCE

            # NOTE: We return the final path created.
            return zookeeper.create(self.handle, path, contents, [self.acl], flags)
开发者ID:mydaisy2,项目名称:reactor-core,代码行数:49,代码来源:connection.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python zookeeper.exists函数代码示例发布时间:2022-05-26
下一篇:
Python zookeeper.create函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap