Ejemplo n.º 1
0
    def _init_from_body(self, _body):
        cls = self.__class__

        # H2N
        assert isinstance(_body, dict), _body
        _query = _body['query']

        # Maybe, deserialize chunks
        if 'where' in _query:
            # Copy the dictionary, for not to modify the original
            query = dict(_query)
            _old_where = query['where']

            _CHUNK_FIELDS = cls.CHUNK_FIELDS

            if _CHUNK_FIELDS in _old_where:
                assert _old_where.keys() == [_CHUNK_FIELDS]
                # New condition, with deserialized chunks
                query['where'] = \
                    {_CHUNK_FIELDS: [ChunkInfo.from_json(c)()
                                         for c in _old_where[_CHUNK_FIELDS]]}
            elif 'path' in _old_where:
                query['where'].update({
                    'path': decode_posix_path(_old_where['path']),
                    'rec': bool(_old_where.get('rec', 0))
                })

        else:
            query = _query

        self.query = query
Ejemplo n.º 2
0
    def _expect_map_decode(tr_dict):
        r"""
        Encode the dictionary mapping the Host UUID to the chunk list
        from the transportation form to the original one.

        >>> ReceiveChunksMessage ._expect_map_decode({
        ...     '233ad9c2268f4506ab0f4c71461c5d88':
        ...         [{'crc32': 710928501,
        ...           'maxsize_code': 1,
        ...           'hash': 'YWJjZGFiY2RhYmNkYWJjZGFiY2RhYmNk'
        ...                   'YWJjZGFiY2RhYmNkYWJjZGFiY2RhYmNk'
        ...                   'YWJjZGFiY2RhYmNkYWJjZA==',
        ...           'uuid': '0a7064b3bef645c09e82e9f9a40dfcf3',
        ...           'size': 73819}],
        ...     'e96a073b3cd049a6b14a1fb04c221a9c':
        ...         [{'crc32': 134052443,
        ...           'maxsize_code': 1,
        ...           'hash': 'YWJjZGVmZ2hhYmNkZWZnaGFiY2RlZmdo'
        ...                   'YWJjZGVmZ2hhYmNkZWZnaGFiY2RlZmdo'
        ...                   'YWJjZGVmZ2hhYmNkZWZnaA==',
        ...           'uuid': '5b237ceb300d4c88b4c06331cb14b5b4',
        ...           'size': 2097152},
        ...          {'crc32': 2120017837,
        ...           'maxsize_code': 0,
        ...           'hash': 'MDEyMzQ1NjcwMTIzNDU2NzAxMjM0NTY3'
        ...                   'MDEyMzQ1NjcwMTIzNDU2NzAxMjM0NTY3'
        ...                   'MDEyMzQ1NjcwMTIzNDU2Nw==',
        ...           'uuid': '940f071152d742fbbf4c818580f432dc',
        ...           'size': 143941},
        ...          {'crc32': 3704113112,
        ...           'maxsize_code': 1,
        ...           'hash': 'NzY1NDMyMTA3NjU0MzIxMDc2NTQzMjEw'
        ...                   'NzY1NDMyMTA3NjU0MzIxMDc2NTQzMjEw'
        ...                   'NzY1NDMyMTA3NjU0MzIxMA==',
        ...           'uuid': 'a5b605f26ea549f38658d217b7e8e784',
        ...           'size': 2097151}]
        ... })  # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        {HostUUID('e96a073b-3cd0-49a6-b14a-1fb04c221a9c'):
             [ChunkInfo(uuid=ChunkUUID('5b237ceb-300d-4c88-b4c0-6331cb14b5b4'),
                        maxsize_code=1,
                        hash=unhexlify('6162636465666...67686162636465666768'),
                        size=2097152, crc32=0x07FD7A5B),
              ChunkInfo(uuid=ChunkUUID('940f0711-52d7-42fb-bf4c-818580f432dc'),
                        maxsize_code=0,
                        hash=unhexlify('3031323334353...36373031323334353637'),
                        size=143941, crc32=0x7E5CE7AD),
              ChunkInfo(uuid=ChunkUUID('a5b605f2-6ea5-49f3-8658-d217b7e8e784'),
                        maxsize_code=1,
                        hash=unhexlify('3736353433323...31303736353433323130'),
                        size=2097151, crc32=0xDCC847D8)],
         HostUUID('233ad9c2-268f-4506-ab0f-4c71461c5d88'):
             [ChunkInfo(uuid=ChunkUUID('0a7064b3-bef6-45c0-9e82-e9f9a40dfcf3'),
                        maxsize_code=1,
                        hash=unhexlify('6162636461626...63646162636461626364'),
                        size=73819, crc32=0x2A5FE875)]}
        """
        return {HostUUID(inh_uuid_str):
                        [ChunkInfo.from_json(c)() for c in per_inh]
                    for inh_uuid_str, per_inh in tr_dict.iteritems()}
Ejemplo n.º 3
0
    def _init_from_body(self, body):
        # N2H
        chunks_data = body['chunks']

        self.chunks_map = \
            {Host(uuid=HostUUID(host_uuid), urls=per_host_data['urls']):
                     [ChunkInfo.from_json(ch)()
                          for ch in per_host_data['chunks']]
                 for host_uuid, per_host_data
                     in chunks_data.iteritems()}
Ejemplo n.º 4
0
    def _init_from_body(self, body):
        # N2H
        chunks_data = body['chunks']

        self.chunks_map = \
            {Host(uuid=HostUUID(host_uuid), urls=per_host_data['urls']):
                     [ChunkInfo.from_json(ch)()
                          for ch in per_host_data['chunks']]
                 for host_uuid, per_host_data
                     in chunks_data.iteritems()}
Ejemplo n.º 5
0
    def _init_from_body(self, body):
        r"""
        >>> from common.typed_uuids import ChunkUUID, MessageUUID, PeerUUID

        >>> host = Host(uuid=UUID('00000000-7606-420c-8a98-a6c8728ac98d'))
        >>> node = Node(uuid=UUID('11111111-79b4-49e0-b72e-8c4ce6a2aed9'))

        >>> msg0 = ProgressMessage(
        ...     src=node,
        ...     dst=host,
        ...     uuid=UUID('4ac2536a-4a1e-4b08-ad4e-11bd675fdf15')
        ... )
        >>> ProgressMessage._init_from_body \
        ...                ._without_bunzip2._without_json_loads(msg0, {})

        >>> msg1 = ProgressMessage(
        ...     src=node,
        ...     dst=host,
        ...     uuid=UUID('baebd0f2-fc58-417b-97ee-08a892cd5a8f'),
        ...     status_code=1
        ... )
        >>> # TODO: add other fields, see _get_body() doctest for that.
        >>> data1 = {
        ...     'chunks': [
        ...         {'crc32': 2120017837,
        ...          'maxsize_code': 0,
        ...          'hash': 'MDEyMzQ1NjcwMTIzNDU2NzAxMjM0NTY3'
        ...                  'MDEyMzQ1NjcwMTIzNDU2NzAxMjM0NTY3'
        ...                  'MDEyMzQ1NjcwMTIzNDU2Nw==',
        ...          'uuid': '940f071152d742fbbf4c818580f432dc',
        ...          'size': 143941},
        ...         {'crc32': 3704113112,
        ...          'maxsize_code': 1,
        ...          'hash': 'NzY1NDMyMTA3NjU0MzIxMDc2NTQzMjEw'
        ...                  'NzY1NDMyMTA3NjU0MzIxMDc2NTQzMjEw'
        ...                  'NzY1NDMyMTA3NjU0MzIxMA==',
        ...          'uuid': 'a5b605f26ea549f38658d217b7e8e784',
        ...          'size': 2097152},
        ...         {'crc32': 134052443,
        ...          'maxsize_code': 1,
        ...          'hash': 'YWJjZGVmZ2hhYmNkZWZnaGFiY2RlZmdo'
        ...                  'YWJjZGVmZ2hhYmNkZWZnaGFiY2RlZmdo'
        ...                  'YWJjZGVmZ2hhYmNkZWZnaA==',
        ...          'uuid': '5b237ceb300d4c88b4c06331cb14b5b4',
        ...          'size': 2097152}]
        ... }

        >>> ProgressMessage._init_from_body \
        ...                ._without_bunzip2._without_json_loads(msg1, data1)
        >>> msg1  # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        ProgressMessage(src=Node(uuid=PeerUUID('11111111-...-8c4ce6a2aed9')),
            dst=Host(uuid=PeerUUID('00000000-7606-420c-8a98-a6c8728ac98d')),
            uuid=MessageUUID('baebd0f2-fc58-417b-97ee-08a892cd5a8f'),
            status_code=1
            [
                chunks_by_uuid={ChunkUUID('940f0711-52d7-...-818580f432dc'):
                        ChunkInfo(uuid=ChunkUUID('940f0711-...-818580f432dc'),
                            maxsize_code=0,
                            hash=unhexlify('30313233343...373031323334353637'),
                            size=143941, crc32=0x7E5CE7AD),
                    ChunkUUID('a5b605f2-6ea5-...-d217b7e8e784'):
                        ChunkInfo(uuid=ChunkUUID('a5b605f2-...-d217b7e8e784'),
                            maxsize_code=1,
                            hash=unhexlify('37363534333...303736353433323130'),
                            size=2097152, crc32=0xDCC847D8),
                    ChunkUUID('5b237ceb-300d-4c88-b4c0-6331cb14b5b4'):
                        ChunkInfo(uuid=ChunkUUID('5b237ceb-...-6331cb14b5b4'),
                            maxsize_code=1,
                            hash=unhexlify('61626364656...686162636465666768'),
                            size=2097152, crc32=0x07FD7A5B)}
            ])
        """
        # H2N

        # Parse dataset
        if 'dataset' in body:
            self.completion = False
            self.dataset = DatasetOnChunks.from_json(body['dataset'])()
        elif 'dataset_completed' in body:
            self.completion = True
            self.dataset = \
                DatasetOnChunks.from_json(body['dataset_completed'])()

        # Parse chunks_by_uuid
        chunks_unp = body.get('chunks', None)
        if chunks_unp is not None:
            _chunks = (ChunkInfo.from_json(ch)() for ch in chunks_unp)
            self.chunks_by_uuid = {ch.uuid: ch
                                       for ch in _chunks}

        # Parse host_chunks_map
        host_chunks_map_unp = body.get('host_chunks_map', None)
        if host_chunks_map_unp is not None:
            host_chunks_map = \
                {Host(uuid=UUID(uuid)):
                         [ProgressNotificationPerHost.from_json(pr)()
                              for pr in per_host_notifs]
                     for uuid, per_host_notifs
                         in host_chunks_map_unp.iteritems()}
            self.chunks_map_getter = lambda: host_chunks_map

        # Parse blocks_map
        blocks_map_unp = body.get('blocks_map', None)
        if blocks_map_unp is not None:
            self.blocks_map = [Chunk.Block.from_json(bl)()
                                   for bl in blocks_map_unp]
Ejemplo n.º 6
0
    def _init_from_body(self, body):
        r"""
        >>> from common.typed_uuids import ChunkUUID, MessageUUID, PeerUUID

        >>> host = Host(uuid=UUID('00000000-7606-420c-8a98-a6c8728ac98d'))
        >>> node = Node(uuid=UUID('11111111-79b4-49e0-b72e-8c4ce6a2aed9'))

        >>> msg0 = ProgressMessage(
        ...     src=node,
        ...     dst=host,
        ...     uuid=UUID('4ac2536a-4a1e-4b08-ad4e-11bd675fdf15')
        ... )
        >>> ProgressMessage._init_from_body \
        ...                ._without_bunzip2._without_json_loads(msg0, {})

        >>> msg1 = ProgressMessage(
        ...     src=node,
        ...     dst=host,
        ...     uuid=UUID('baebd0f2-fc58-417b-97ee-08a892cd5a8f'),
        ...     status_code=1
        ... )
        >>> # TODO: add other fields, see _get_body() doctest for that.
        >>> data1 = {
        ...     'chunks': [
        ...         {'crc32': 2120017837,
        ...          'maxsize_code': 0,
        ...          'hash': 'MDEyMzQ1NjcwMTIzNDU2NzAxMjM0NTY3'
        ...                  'MDEyMzQ1NjcwMTIzNDU2NzAxMjM0NTY3'
        ...                  'MDEyMzQ1NjcwMTIzNDU2Nw==',
        ...          'uuid': '940f071152d742fbbf4c818580f432dc',
        ...          'size': 143941},
        ...         {'crc32': 3704113112,
        ...          'maxsize_code': 1,
        ...          'hash': 'NzY1NDMyMTA3NjU0MzIxMDc2NTQzMjEw'
        ...                  'NzY1NDMyMTA3NjU0MzIxMDc2NTQzMjEw'
        ...                  'NzY1NDMyMTA3NjU0MzIxMA==',
        ...          'uuid': 'a5b605f26ea549f38658d217b7e8e784',
        ...          'size': 2097152},
        ...         {'crc32': 134052443,
        ...          'maxsize_code': 1,
        ...          'hash': 'YWJjZGVmZ2hhYmNkZWZnaGFiY2RlZmdo'
        ...                  'YWJjZGVmZ2hhYmNkZWZnaGFiY2RlZmdo'
        ...                  'YWJjZGVmZ2hhYmNkZWZnaA==',
        ...          'uuid': '5b237ceb300d4c88b4c06331cb14b5b4',
        ...          'size': 2097152}]
        ... }

        >>> ProgressMessage._init_from_body \
        ...                ._without_bunzip2._without_json_loads(msg1, data1)
        >>> msg1  # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        ProgressMessage(src=Node(uuid=PeerUUID('11111111-...-8c4ce6a2aed9')),
            dst=Host(uuid=PeerUUID('00000000-7606-420c-8a98-a6c8728ac98d')),
            uuid=MessageUUID('baebd0f2-fc58-417b-97ee-08a892cd5a8f'),
            status_code=1
            [
                chunks_by_uuid={ChunkUUID('940f0711-52d7-...-818580f432dc'):
                        ChunkInfo(uuid=ChunkUUID('940f0711-...-818580f432dc'),
                            maxsize_code=0,
                            hash=unhexlify('30313233343...373031323334353637'),
                            size=143941, crc32=0x7E5CE7AD),
                    ChunkUUID('a5b605f2-6ea5-...-d217b7e8e784'):
                        ChunkInfo(uuid=ChunkUUID('a5b605f2-...-d217b7e8e784'),
                            maxsize_code=1,
                            hash=unhexlify('37363534333...303736353433323130'),
                            size=2097152, crc32=0xDCC847D8),
                    ChunkUUID('5b237ceb-300d-4c88-b4c0-6331cb14b5b4'):
                        ChunkInfo(uuid=ChunkUUID('5b237ceb-...-6331cb14b5b4'),
                            maxsize_code=1,
                            hash=unhexlify('61626364656...686162636465666768'),
                            size=2097152, crc32=0x07FD7A5B)}
            ])
        """
        # H2N

        # Parse dataset
        if 'dataset' in body:
            self.completion = False
            self.dataset = DatasetOnChunks.from_json(body['dataset'])()
        elif 'dataset_completed' in body:
            self.completion = True
            self.dataset = \
                DatasetOnChunks.from_json(body['dataset_completed'])()

        # Parse chunks_by_uuid
        chunks_unp = body.get('chunks', None)
        if chunks_unp is not None:
            _chunks = (ChunkInfo.from_json(ch)() for ch in chunks_unp)
            self.chunks_by_uuid = {ch.uuid: ch for ch in _chunks}

        # Parse host_chunks_map
        host_chunks_map_unp = body.get('host_chunks_map', None)
        if host_chunks_map_unp is not None:
            host_chunks_map = \
                {Host(uuid=UUID(uuid)):
                         [ProgressNotificationPerHost.from_json(pr)()
                              for pr in per_host_notifs]
                     for uuid, per_host_notifs
                         in host_chunks_map_unp.iteritems()}
            self.chunks_map_getter = lambda: host_chunks_map

        # Parse blocks_map
        blocks_map_unp = body.get('blocks_map', None)
        if blocks_map_unp is not None:
            self.blocks_map = [
                Chunk.Block.from_json(bl)() for bl in blocks_map_unp
            ]
Ejemplo n.º 7
0
    def _expect_map_decode(tr_dict):
        r"""
        Encode the dictionary mapping the Host UUID to the chunk list
        from the transportation form to the original one.

        >>> ReceiveChunksMessage ._expect_map_decode({
        ...     '233ad9c2268f4506ab0f4c71461c5d88':
        ...         [{'crc32': 710928501,
        ...           'maxsize_code': 1,
        ...           'hash': 'YWJjZGFiY2RhYmNkYWJjZGFiY2RhYmNk'
        ...                   'YWJjZGFiY2RhYmNkYWJjZGFiY2RhYmNk'
        ...                   'YWJjZGFiY2RhYmNkYWJjZA==',
        ...           'uuid': '0a7064b3bef645c09e82e9f9a40dfcf3',
        ...           'size': 73819}],
        ...     'e96a073b3cd049a6b14a1fb04c221a9c':
        ...         [{'crc32': 134052443,
        ...           'maxsize_code': 1,
        ...           'hash': 'YWJjZGVmZ2hhYmNkZWZnaGFiY2RlZmdo'
        ...                   'YWJjZGVmZ2hhYmNkZWZnaGFiY2RlZmdo'
        ...                   'YWJjZGVmZ2hhYmNkZWZnaA==',
        ...           'uuid': '5b237ceb300d4c88b4c06331cb14b5b4',
        ...           'size': 2097152},
        ...          {'crc32': 2120017837,
        ...           'maxsize_code': 0,
        ...           'hash': 'MDEyMzQ1NjcwMTIzNDU2NzAxMjM0NTY3'
        ...                   'MDEyMzQ1NjcwMTIzNDU2NzAxMjM0NTY3'
        ...                   'MDEyMzQ1NjcwMTIzNDU2Nw==',
        ...           'uuid': '940f071152d742fbbf4c818580f432dc',
        ...           'size': 143941},
        ...          {'crc32': 3704113112,
        ...           'maxsize_code': 1,
        ...           'hash': 'NzY1NDMyMTA3NjU0MzIxMDc2NTQzMjEw'
        ...                   'NzY1NDMyMTA3NjU0MzIxMDc2NTQzMjEw'
        ...                   'NzY1NDMyMTA3NjU0MzIxMA==',
        ...           'uuid': 'a5b605f26ea549f38658d217b7e8e784',
        ...           'size': 2097151}]
        ... })  # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        {HostUUID('e96a073b-3cd0-49a6-b14a-1fb04c221a9c'):
             [ChunkInfo(uuid=ChunkUUID('5b237ceb-300d-4c88-b4c0-6331cb14b5b4'),
                        maxsize_code=1,
                        hash=unhexlify('6162636465666...67686162636465666768'),
                        size=2097152, crc32=0x07FD7A5B),
              ChunkInfo(uuid=ChunkUUID('940f0711-52d7-42fb-bf4c-818580f432dc'),
                        maxsize_code=0,
                        hash=unhexlify('3031323334353...36373031323334353637'),
                        size=143941, crc32=0x7E5CE7AD),
              ChunkInfo(uuid=ChunkUUID('a5b605f2-6ea5-49f3-8658-d217b7e8e784'),
                        maxsize_code=1,
                        hash=unhexlify('3736353433323...31303736353433323130'),
                        size=2097151, crc32=0xDCC847D8)],
         HostUUID('233ad9c2-268f-4506-ab0f-4c71461c5d88'):
             [ChunkInfo(uuid=ChunkUUID('0a7064b3-bef6-45c0-9e82-e9f9a40dfcf3'),
                        maxsize_code=1,
                        hash=unhexlify('6162636461626...63646162636461626364'),
                        size=73819, crc32=0x2A5FE875)]}
        """
        return {
            HostUUID(inh_uuid_str):
            [ChunkInfo.from_json(c)() for c in per_inh]
            for inh_uuid_str, per_inh in tr_dict.iteritems()
        }