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


Python zookeeper.delete函数代码示例

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


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


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