Beispiel #1
0
 def object_fetch(self, account, container, obj, ranges=None,
                  headers=None):
     meta, raw_chunks = self.object_analyze(
         account, container, obj, headers=headers)
     chunk_method = meta['chunk-method']
     storage_method = STORAGE_METHODS.load(chunk_method)
     chunks = _sort_chunks(raw_chunks, storage_method.ec)
     if storage_method.ec:
         stream = self._fetch_stream_ec(meta, chunks, ranges,
                                        storage_method, headers)
     else:
         stream = self._fetch_stream(meta, chunks, ranges, storage_method,
                                     headers)
     return meta, stream
Beispiel #2
0
    def _object_create(self, account, container, obj_name, source,
                       sysmeta, metadata=None, policy=None, headers=None):
        meta, raw_chunks = self._content_prepare(
            account, container, obj_name, sysmeta['content_length'],
            policy=policy, headers=headers)

        sysmeta['chunk_size'] = int(meta['X-oio-ns-chunk-size'])
        sysmeta['id'] = meta[object_headers['id']]
        sysmeta['version'] = meta[object_headers['version']]
        sysmeta['policy'] = meta[object_headers['policy']]
        sysmeta['mime_type'] = meta[object_headers['mime_type']]
        sysmeta['chunk_method'] = meta[object_headers['chunk_method']]

        storage_method = STORAGE_METHODS.load(sysmeta['chunk_method'])

        chunks = _sort_chunks(raw_chunks, storage_method.ec)
        sysmeta['content_path'] = obj_name
        sysmeta['container_id'] = utils.name2cid(account, container)

        if storage_method.ec:
            handler = ECWriteHandler(source, sysmeta, chunks, storage_method,
                                     headers=headers)
        else:
            handler = ReplicatedWriteHandler(source, sysmeta, chunks,
                                             storage_method, headers=headers)

        final_chunks, bytes_transferred, content_checksum = handler.stream()

        etag = sysmeta['etag']
        if etag and etag.lower() != content_checksum.lower():
            raise exc.EtagMismatch(
                "given etag %s != computed %s" % (etag, content_checksum))
        sysmeta['etag'] = content_checksum

        h = {}
        h[object_headers['size']] = bytes_transferred
        h[object_headers['hash']] = sysmeta['etag']
        h[object_headers['version']] = sysmeta['version']
        h[object_headers['id']] = sysmeta['id']
        h[object_headers['policy']] = sysmeta['policy']
        h[object_headers['mime_type']] = sysmeta['mime_type']
        h[object_headers['chunk_method']] = sysmeta['chunk_method']

        if metadata:
            for k, v in metadata.iteritems():
                h['%sx-%s' % (constants.OBJECT_METADATA_PREFIX, k)] = v

        m, body = self._content_create(account, container, obj_name,
                                       final_chunks, headers=h)
        return final_chunks, bytes_transferred, content_checksum
Beispiel #3
0
    def setUp(self):
        self.chunk_method = 'plain/nb_copy=3'
        storage_method = STORAGE_METHODS.load(self.chunk_method)
        self.storage_method = storage_method
        self.cid = \
            '3E32B63E6039FD3104F63BFAE034FADAA823371DD64599A8779BA02B3439A268'
        self.sysmeta = {
            'id': '705229BB7F330500A65C3A49A3116B83',
            'version': '1463998577463950',
            'chunk_method': self.chunk_method,
            'container_id': self.cid,
            'policy': 'REPLI3',
            'content_path': 'test',
        }

        self._meta_chunk = [
                {'url': 'http://127.0.0.1:7000/0', 'pos': '0'},
                {'url': 'http://127.0.0.1:7001/1', 'pos': '0'},
                {'url': 'http://127.0.0.1:7002/2', 'pos': '0'},
        ]
Beispiel #4
0
 def setUp(self):
     self.chunk_method = 'ec/algo=liberasurecode_rs_vand,k=6,m=2'
     storage_method = STORAGE_METHODS.load(self.chunk_method)
     self.storage_method = storage_method
     self.cid = \
         '3E32B63E6039FD3104F63BFAE034FADAA823371DD64599A8779BA02B3439A268'
     self.sysmeta = {
         'id': '705229BB7F330500A65C3A49A3116B83',
         'version': '1463998577463950',
         'chunk_method': self.chunk_method,
         'container_id': self.cid,
         'policy': 'EC',
         'content_path': 'test',
     }
     self._meta_chunk = [
             {'url': 'http://127.0.0.1:7000/0', 'pos': '0.0', 'num': 0},
             {'url': 'http://127.0.0.1:7001/1', 'pos': '0.1', 'num': 1},
             {'url': 'http://127.0.0.1:7002/2', 'pos': '0.2', 'num': 2},
             {'url': 'http://127.0.0.1:7003/3', 'pos': '0.3', 'num': 3},
             {'url': 'http://127.0.0.1:7004/4', 'pos': '0.4', 'num': 4},
             {'url': 'http://127.0.0.1:7005/5', 'pos': '0.5', 'num': 5},
             {'url': 'http://127.0.0.1:7006/6', 'pos': '0.6', 'num': 6},
             {'url': 'http://127.0.0.1:7007/7', 'pos': '0.7', 'num': 7},
     ]