예제 #1
0
 def get(self, path, watch=None):
     if not isinstance(path, six.string_types):
         raise TypeError("Invalid type for 'path' (string expected)")
     if path == '/no_node':
         raise NoNodeError
     elif '/members/' in path:
         return (
             b'postgres://*****:*****@localhost:5434/postgres?application_name=http://127.0.0.1:8009/patroni',
             ZnodeStat(0, 0, 0, 0, 0, 0, 0, 0 if self.exists else -1, 0, 0,
                       0))
     elif path.endswith('/leader'):
         if self.leader:
             return (b'foo', ZnodeStat(0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0))
         return (b'foo', ZnodeStat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
     elif path.endswith('/initialize'):
         return (b'foo', ZnodeStat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
     return (b'', ZnodeStat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
예제 #2
0
    def deserialize(cls, bytes, offset):
        count = int_struct.unpack_from(bytes, offset)[0]
        offset += int_struct.size
        if count == -1:  # pragma: nocover
            return []

        acls = []
        for c in range(count):
            acl, offset = read_acl(bytes, offset)
            acls.append(acl)
        stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
        return acls, stat
예제 #3
0
    def deserialize(cls, bytes, offset):
        count = int_struct.unpack_from(bytes, offset)[0]
        offset += int_struct.size
        if count == -1:  # pragma: nocover
            return []

        children = []
        for c in range(count):
            child, offset = read_string(bytes, offset)
            children.append(child)
        stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
        return children, stat
예제 #4
0
    def deserialize(cls, bytes, offset):
        count = int_struct.unpack_from(bytes, offset)[0]
        offset += int_struct.size
        if count == -1:  # pragma: nocover
            return []

        children = []
        for c in range(count):
            child, offset = read_string(bytes, offset)
            children.append(child)
        stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
        return children, stat
예제 #5
0
    def deserialize(cls, bytes, offset):
        count = int_struct.unpack_from(bytes, offset)[0]
        offset += int_struct.size
        if count == -1:  # pragma: nocover
            return []

        acls = []
        for c in range(count):
            acl, offset = read_acl(bytes, offset)
            acls.append(acl)
        stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
        return acls, stat
예제 #6
0
 def stat(self):
     return ZnodeStat(czxid=0,
                      mzxid=0,
                      ctime=time.time(),
                      mtime=time.time(),
                      version=self.version,
                      cversion=0,
                      aversion=0,
                      ephemeralOwner=0,
                      dataLength=len(self._value),
                      numChildren=len(self._children),
                      pzxid=0)
예제 #7
0
    def test_save_watcher_to_dict_with_disabled_cache(self, mocked_save_dict):
        # If caching is disabled, it should return quickly
        fake_node_data = {
            'children': {},
            'data': None,
            'path': '/services/ssh',
            'stat': ZnodeStat(
                czxid=505, mzxid=505, ctime=1355719651687,
                mtime=1355719651687, version=0, cversion=1,
                aversion=0, ephemeralOwner=0, dataLength=0,
                numChildren=0, pzxid=506)}

        self.ndsr._cachefile = False
        self.ndsr._save_watcher_to_dict(fake_node_data)
        self.assertItemsEqual(mocked_save_dict.mock_calls, [])
예제 #8
0
    def test_save_watcher_to_dict(self, mocked_save_dict):
        # A normal data node storing some real data should be cachable
        fake_node_data = {
            'children': {},
            'data': {'some': 'data'},
            'path': '/mydata',
            'stat': ZnodeStat(
                czxid=505, mzxid=505, ctime=1355719651687,
                mtime=1355719651687, version=0, cversion=1,
                aversion=0, ephemeralOwner=0, dataLength=0,
                numChildren=0, pzxid=506)}

        self.ndsr._cachefile = True
        self.ndsr._save_watcher_to_dict(fake_node_data)
        mocked_save_dict.assert_called_with(
            {'/mydata': fake_node_data}, True)
예제 #9
0
    def test_save_watcher_to_dict_with_empty_data(self, mocked_save_dict):
        # A data node though that has NO DATA is assumed to be a path used
        # only for storing ephemeral node lists (server registrations).
        # In this case, if the children-list AND data-list are empty, we
        # do not cache this.
        fake_node_data = {
            'children': {},
            'data': None,
            'path': '/services/ssh',
            'stat': ZnodeStat(
                czxid=505, mzxid=505, ctime=1355719651687,
                mtime=1355719651687, version=0, cversion=1,
                aversion=0, ephemeralOwner=0, dataLength=0,
                numChildren=0, pzxid=506)}

        self.ndsr._cachefile = True
        self.ndsr._save_watcher_to_dict(fake_node_data)
        self.assertItemsEqual(mocked_save_dict.mock_calls, [])
예제 #10
0
 def deserialize(cls, bytes, offset):
     header = MultiHeader(None, False, None)
     results = []
     response = None
     while not header.done:
         if header.type == Create.type:
             response, offset = read_string(bytes, offset)
         elif header.type == Delete.type:
             response = True
         elif header.type == SetData.type:
             response = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
             offset += stat_struct.size
         elif header.type == CheckVersion.type:
             response = True
         elif header.type == -1:
             err = int_struct.unpack_from(bytes, offset)[0]
             offset += int_struct.size
             response = EXCEPTIONS[err]()
         if response:
             results.append(response)
         header, offset = MultiHeader.deserialize(bytes, offset)
     return results
    def getStats(self, paths, options):
        """
        Returns Stat[]
        Parameters:
            paths: List<String>options: int
        @Override


        """
        if paths == None or paths.__len__() == 0:
            self.LOG.error("paths is null or empty")
            #            return new Stat[0]
            return []
        # Stat[]
        stats = [ZnodeStat() for path in paths]
        # long
        startT = time.time()
        try:
            # ExistsCallbackHandler[]
            cbList = [ExistsCallbackHandler() for path in paths.__len__]
            for i in range(len(paths)):  # String
                path = paths[i]
                cbList[i] = ExistsCallbackHandler()
                self._zkClient.asyncExists(path, cbList[i])

            for i in range(len(cbList)):  # ExistsCallbackHandler
                cb = cbList[i]
                cb.waitForSuccess()
                stats[i] = cb._stat

            return stats
        finally:
            # long
            endT = time.time()
            #                if self.LOG.isDebugEnabled():
            self.LOG.debug("exists_async, size: " + str(paths.__len__()) +
                           ", paths: " + str(paths.__getitem__(0)) +
                           ",... time: " + str((endT - startT)) + " ns")
예제 #12
0
 def deserialize(cls, bytes, offset):
     header = MultiHeader(None, False, None)
     results = []
     response = None
     while not header.done:
         if header.type == Create.type:
             response, offset = read_string(bytes, offset)
         elif header.type == Delete.type:
             response = True
         elif header.type == SetData.type:
             response = ZnodeStat._make(
                 stat_struct.unpack_from(bytes, offset))
             offset += stat_struct.size
         elif header.type == CheckVersion.type:
             response = True
         elif header.type == -1:
             err = int_struct.unpack_from(bytes, offset)[0]
             offset += int_struct.size
             response = EXCEPTIONS[err]()
         if response:
             results.append(response)
         header, offset = MultiHeader.deserialize(bytes, offset)
     return results
예제 #13
0
 def deserialize(cls, bytes, offset):
     return ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
예제 #14
0
 def deserialize(cls, bytes, offset):
     return ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
예제 #15
0
 def deserialize(cls, bytes, offset):
     data, offset = read_buffer(bytes, offset)
     stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
     return data, stat
예제 #16
0
 def deserialize(cls, bytes, offset):
     stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
     return stat if stat.czxid != -1 else None
예제 #17
0
 def deserialize(cls, bytes, offset):
     data, offset = read_buffer(bytes, offset)
     stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
     return data, stat
예제 #18
0
 def deserialize(cls, bytes, offset):
     stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
     return stat if stat.czxid != -1 else None
예제 #19
0
def _parse_znode_stat(data):
    return ZnodeStat(*map(_b_to_uint, (data[8 * i:8 * (i + 1)]
                                       for i in range(11))))
예제 #20
0
 def deserialize(cls, bytes, offset):
     path, offset = read_string(bytes, offset)
     stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
     return path, stat