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


Python bulk.Bulk类代码示例

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


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

示例1: __init__

 def __init__(self, app, conf):
     self.conf = conf
     self.app = app
     self.logger = get_logger(conf, log_route="slo")
     self.max_manifest_segments = int(self.conf.get("max_manifest_segments", 1000))
     self.max_manifest_size = int(self.conf.get("max_manifest_size", 1024 * 1024 * 2))
     self.min_segment_size = int(self.conf.get("min_segment_size", 1024 * 1024))
     self.bulk_deleter = Bulk(app, {"max_deletes_per_request": self.max_manifest_segments})
开发者ID:GitFloki,项目名称:Shake,代码行数:8,代码来源:slo.py

示例2: __init__

 def __init__(self, app, conf):
     self.conf = conf
     self.app = app
     self.logger = get_logger(conf, log_route='slo')
     self.max_manifest_segments = int(self.conf.get('max_manifest_segments',
                                      1000))
     self.max_manifest_size = int(self.conf.get('max_manifest_size',
                                  1024 * 1024 * 2))
     self.min_segment_size = int(self.conf.get('min_segment_size',
                                 1024 * 1024))
     self.bulk_deleter = Bulk(app, {})
开发者ID:674009287,项目名称:swift,代码行数:11,代码来源:slo.py

示例3: __init__

 def __init__(self, app, conf, min_segment_size=DEFAULT_MIN_SEGMENT_SIZE,
              max_manifest_segments=DEFAULT_MAX_MANIFEST_SEGMENTS,
              max_manifest_size=DEFAULT_MAX_MANIFEST_SIZE):
     self.conf = conf
     self.app = app
     self.logger = get_logger(conf, log_route='slo')
     self.max_manifest_segments = max_manifest_segments
     self.max_manifest_size = max_manifest_size
     self.min_segment_size = min_segment_size
     self.max_get_time = int(self.conf.get('max_get_time', 86400))
     self.rate_limit_after_segment = int(self.conf.get(
         'rate_limit_after_segment', '10'))
     self.rate_limit_segments_per_sec = int(self.conf.get(
         'rate_limit_segments_per_sec', '0'))
     self.bulk_deleter = Bulk(app, {}, logger=self.logger)
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:15,代码来源:slo.py

示例4: __init__

 def __init__(self, app, conf):
     self.conf = conf
     self.app = app
     self.logger = get_logger(conf, log_route='slo')
     self.max_manifest_segments = int(self.conf.get('max_manifest_segments',
                                      1000))
     self.max_manifest_size = int(self.conf.get('max_manifest_size',
                                  1024 * 1024 * 2))
     self.min_segment_size = int(self.conf.get('min_segment_size',
                                 1024 * 1024))
     self.max_get_time = int(self.conf.get('max_get_time', 86400))
     self.rate_limit_after_segment = int(self.conf.get(
         'rate_limit_after_segment', '10'))
     self.rate_limit_segments_per_sec = int(self.conf.get(
         'rate_limit_segments_per_sec', '0'))
     self.bulk_deleter = Bulk(app, {})
开发者ID:ajju4988,项目名称:swift,代码行数:16,代码来源:slo.py

示例5: __init__

 def __init__(self, app, conf,
              max_manifest_segments=DEFAULT_MAX_MANIFEST_SEGMENTS,
              max_manifest_size=DEFAULT_MAX_MANIFEST_SIZE):
     self.conf = conf
     self.app = app
     self.logger = get_logger(conf, log_route='slo')
     self.max_manifest_segments = max_manifest_segments
     self.max_manifest_size = max_manifest_size
     self.max_get_time = int(self.conf.get('max_get_time', 86400))
     self.rate_limit_under_size = int(self.conf.get(
         'rate_limit_under_size', DEFAULT_RATE_LIMIT_UNDER_SIZE))
     self.rate_limit_after_segment = int(self.conf.get(
         'rate_limit_after_segment', '10'))
     self.rate_limit_segments_per_sec = int(self.conf.get(
         'rate_limit_segments_per_sec', '1'))
     delete_concurrency = int(self.conf.get('delete_concurrency', '2'))
     self.bulk_deleter = Bulk(
         app, {}, delete_concurrency=delete_concurrency, logger=self.logger)
开发者ID:ISCAS-VDI,项目名称:swift-base,代码行数:18,代码来源:slo.py

示例6: StaticLargeObject

class StaticLargeObject(object):
    """
    StaticLargeObject Middleware

    See above for a full description.

    The proxy logs created for any subrequests made will have swift.source set
    to "SLO".

    :param app: The next WSGI filter or app in the paste.deploy chain.
    :param conf: The configuration dict for the middleware.
    """

    def __init__(self, app, conf, min_segment_size=DEFAULT_MIN_SEGMENT_SIZE,
                 max_manifest_segments=DEFAULT_MAX_MANIFEST_SEGMENTS,
                 max_manifest_size=DEFAULT_MAX_MANIFEST_SIZE):
        self.conf = conf
        self.app = app
        self.logger = get_logger(conf, log_route='slo')
        self.max_manifest_segments = max_manifest_segments
        self.max_manifest_size = max_manifest_size
        self.min_segment_size = min_segment_size
        self.max_get_time = int(self.conf.get('max_get_time', 86400))
        self.rate_limit_after_segment = int(self.conf.get(
            'rate_limit_after_segment', '10'))
        self.rate_limit_segments_per_sec = int(self.conf.get(
            'rate_limit_segments_per_sec', '0'))
        self.bulk_deleter = Bulk(app, {}, logger=self.logger)

    def handle_multipart_get_or_head(self, req, start_response):
        """
        Handles the GET or HEAD of a SLO manifest.

        The response body (only on GET, of course) will consist of the
        concatenation of the segments.

        :params req: a swob.Request with a path referencing an object
        :raises: HttpException on errors
        """
        return SloGetContext(self).handle_slo_get_or_head(req, start_response)

    def copy_hook(self, inner_hook):

        def slo_hook(source_req, source_resp, sink_req):
            x_slo = source_resp.headers.get('X-Static-Large-Object')
            if (config_true_value(x_slo)
                    and source_req.params.get('multipart-manifest') != 'get'
                    and 'swift.post_as_copy' not in source_req.environ):
                source_resp = SloGetContext(self).get_or_head_response(
                    source_req, source_resp.headers.items(),
                    source_resp.app_iter)
            return inner_hook(source_req, source_resp, sink_req)

        return slo_hook

    def handle_multipart_put(self, req, start_response):
        """
        Will handle the PUT of a SLO manifest.
        Heads every object in manifest to check if is valid and if so will
        save a manifest generated from the user input. Uses WSGIContext to
        call self and start_response and returns a WSGI iterator.

        :params req: a swob.Request with an obj in path
        :raises: HttpException on errors
        """
        try:
            vrs, account, container, obj = req.split_path(1, 4, True)
        except ValueError:
            return self.app(req.environ, start_response)
        if req.content_length > self.max_manifest_size:
            raise HTTPRequestEntityTooLarge(
                "Manifest File > %d bytes" % self.max_manifest_size)
        if req.headers.get('X-Copy-From'):
            raise HTTPMethodNotAllowed(
                'Multipart Manifest PUTs cannot be COPY requests')
        if req.content_length is None and \
                req.headers.get('transfer-encoding', '').lower() != 'chunked':
            raise HTTPLengthRequired(request=req)
        parsed_data = parse_and_validate_input(
            req.body_file.read(self.max_manifest_size),
            req.path, self.min_segment_size)
        problem_segments = []

        if len(parsed_data) > self.max_manifest_segments:
            raise HTTPRequestEntityTooLarge(
                'Number of segments must be <= %d' %
                self.max_manifest_segments)
        total_size = 0
        out_content_type = req.accept.best_match(ACCEPTABLE_FORMATS)
        if not out_content_type:
            out_content_type = 'text/plain'
        data_for_storage = []
        slo_etag = md5()
        last_obj_path = None
        for index, seg_dict in enumerate(parsed_data):
            obj_name = seg_dict['path']
            if isinstance(obj_name, six.text_type):
                obj_name = obj_name.encode('utf-8')
            obj_path = '/'.join(['', vrs, account, obj_name.lstrip('/')])

#.........这里部分代码省略.........
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:101,代码来源:slo.py

示例7: StaticLargeObject

class StaticLargeObject(object):
    """
    StaticLargeObject Middleware

    See above for a full description.

    The proxy logs created for any subrequests made will have swift.source set
    to "SLO".

    :param app: The next WSGI filter or app in the paste.deploy chain.
    :param conf: The configuration dict for the middleware.
    """

    def __init__(self, app, conf):
        self.conf = conf
        self.app = app
        self.logger = get_logger(conf, log_route='slo')
        self.max_manifest_segments = int(self.conf.get('max_manifest_segments',
                                         1000))
        self.max_manifest_size = int(self.conf.get('max_manifest_size',
                                     1024 * 1024 * 2))
        self.min_segment_size = int(self.conf.get('min_segment_size',
                                    1024 * 1024))
        self.bulk_deleter = Bulk(
            app, {'max_deletes_per_request': self.max_manifest_segments})

    def handle_multipart_put(self, req):
        """
        Will handle the PUT of a SLO manifest.
        Heads every object in manifest to check if is valid and if so will
        save a manifest generated from the user input.

        :params req: a swob.Request with an obj in path
        :raises: HttpException on errors
        """
        try:
            vrs, account, container, obj = req.split_path(1, 4, True)
        except ValueError:
            return self.app
        if req.content_length > self.max_manifest_size:
            raise HTTPRequestEntityTooLarge(
                "Manifest File > %d bytes" % self.max_manifest_size)
        if req.headers.get('X-Copy-From'):
            raise HTTPMethodNotAllowed(
                'Multipart Manifest PUTs cannot be Copy requests')
        if req.content_length is None and \
                req.headers.get('transfer-encoding', '').lower() != 'chunked':
            raise HTTPLengthRequired(request=req)
        parsed_data = parse_input(req.body_file.read(self.max_manifest_size))
        problem_segments = []

        if len(parsed_data) > self.max_manifest_segments:
            raise HTTPRequestEntityTooLarge(
                'Number segments must be <= %d' % self.max_manifest_segments)
        total_size = 0
        out_content_type = req.accept.best_match(ACCEPTABLE_FORMATS)
        if not out_content_type:
            out_content_type = 'text/plain'
        data_for_storage = []
        for index, seg_dict in enumerate(parsed_data):
            obj_path = '/'.join(
                ['', vrs, account, seg_dict['path'].lstrip('/')])
            try:
                seg_size = int(seg_dict['size_bytes'])
            except (ValueError, TypeError):
                raise HTTPBadRequest('Invalid Manifest File')
            if seg_size < self.min_segment_size and \
                    (index == 0 or index < len(parsed_data) - 1):
                raise HTTPBadRequest(
                    'Each segment, except the last, must be larger than '
                    '%d bytes.' % self.min_segment_size)

            new_env = req.environ.copy()
            if isinstance(obj_path, unicode):
                obj_path = obj_path.encode('utf-8')
            new_env['PATH_INFO'] = obj_path
            new_env['REQUEST_METHOD'] = 'HEAD'
            new_env['swift.source'] = 'SLO'
            del(new_env['wsgi.input'])
            del(new_env['QUERY_STRING'])
            new_env['CONTENT_LENGTH'] = 0
            new_env['HTTP_USER_AGENT'] = \
                '%s MultipartPUT' % req.environ.get('HTTP_USER_AGENT')
            head_seg_resp = \
                Request.blank(obj_path, new_env).get_response(self.app)
            if head_seg_resp.status_int // 100 == 2:
                total_size += seg_size
                if seg_size != head_seg_resp.content_length:
                    problem_segments.append([quote(obj_path), 'Size Mismatch'])
                if seg_dict['etag'] != head_seg_resp.etag:
                    problem_segments.append([quote(obj_path), 'Etag Mismatch'])
                if head_seg_resp.last_modified:
                    last_modified = head_seg_resp.last_modified
                else:
                    # shouldn't happen
                    last_modified = datetime.now()

                last_modified_formatted = \
                    last_modified.strftime('%Y-%m-%dT%H:%M:%S.%f')
                data_for_storage.append(
#.........这里部分代码省略.........
开发者ID:GoodDingo,项目名称:openstack-swift,代码行数:101,代码来源:slo.py

示例8: StaticLargeObject

class StaticLargeObject(object):
    """
    StaticLargeObject Middleware

    See above for a full description.

    The proxy logs created for any subrequests made will have swift.source set
    to "SLO".

    :param app: The next WSGI filter or app in the paste.deploy chain.
    :param conf: The configuration dict for the middleware.
    """

    def __init__(self, app, conf):
        self.conf = conf
        self.app = app
        self.logger = get_logger(conf, log_route='slo')
        self.max_manifest_segments = int(self.conf.get('max_manifest_segments',
                                         1000))
        self.max_manifest_size = int(self.conf.get('max_manifest_size',
                                     1024 * 1024 * 2))
        self.min_segment_size = int(self.conf.get('min_segment_size',
                                    1024 * 1024))
        self.bulk_deleter = Bulk(app, {})

    def handle_multipart_put(self, req, start_response):
        """
        Will handle the PUT of a SLO manifest.
        Heads every object in manifest to check if is valid and if so will
        save a manifest generated from the user input. Uses WSGIContext to
        call self.app and start_response and returns a WSGI iterator.

        :params req: a swob.Request with an obj in path
        :raises: HttpException on errors
        """
        try:
            vrs, account, container, obj = req.split_path(1, 4, True)
        except ValueError:
            return self.app(req.environ, start_response)
        if req.content_length > self.max_manifest_size:
            raise HTTPRequestEntityTooLarge(
                "Manifest File > %d bytes" % self.max_manifest_size)
        if req.headers.get('X-Copy-From'):
            raise HTTPMethodNotAllowed(
                'Multipart Manifest PUTs cannot be Copy requests')
        if req.content_length is None and \
                req.headers.get('transfer-encoding', '').lower() != 'chunked':
            raise HTTPLengthRequired(request=req)
        parsed_data = parse_input(req.body_file.read(self.max_manifest_size))
        problem_segments = []

        if len(parsed_data) > self.max_manifest_segments:
            raise HTTPRequestEntityTooLarge(
                'Number segments must be <= %d' % self.max_manifest_segments)
        total_size = 0
        out_content_type = req.accept.best_match(ACCEPTABLE_FORMATS)
        if not out_content_type:
            out_content_type = 'text/plain'
        data_for_storage = []
        slo_etag = md5()
        for index, seg_dict in enumerate(parsed_data):
            obj_name = seg_dict['path']
            if isinstance(obj_name, unicode):
                obj_name = obj_name.encode('utf-8')
            obj_path = '/'.join(['', vrs, account, obj_name.lstrip('/')])
            try:
                seg_size = int(seg_dict['size_bytes'])
            except (ValueError, TypeError):
                raise HTTPBadRequest('Invalid Manifest File')
            if seg_size < self.min_segment_size and \
                    (index == 0 or index < len(parsed_data) - 1):
                raise HTTPBadRequest(
                    'Each segment, except the last, must be larger than '
                    '%d bytes.' % self.min_segment_size)

            new_env = req.environ.copy()
            new_env['PATH_INFO'] = obj_path
            new_env['REQUEST_METHOD'] = 'HEAD'
            new_env['swift.source'] = 'SLO'
            del(new_env['wsgi.input'])
            del(new_env['QUERY_STRING'])
            new_env['CONTENT_LENGTH'] = 0
            new_env['HTTP_USER_AGENT'] = \
                '%s MultipartPUT' % req.environ.get('HTTP_USER_AGENT')
            head_seg_resp = \
                Request.blank(obj_path, new_env).get_response(self.app)
            if head_seg_resp.is_success:
                total_size += seg_size
                if seg_size != head_seg_resp.content_length:
                    problem_segments.append([quote(obj_name), 'Size Mismatch'])
                if seg_dict['etag'] == head_seg_resp.etag:
                    slo_etag.update(seg_dict['etag'])
                else:
                    problem_segments.append([quote(obj_name), 'Etag Mismatch'])
                if head_seg_resp.last_modified:
                    last_modified = head_seg_resp.last_modified
                else:
                    # shouldn't happen
                    last_modified = datetime.now()

#.........这里部分代码省略.........
开发者ID:674009287,项目名称:swift,代码行数:101,代码来源:slo.py

示例9: StaticLargeObject

class StaticLargeObject(object):
    

    def __init__(self, app, conf):
        self.conf = conf
        self.app = app
        self.logger = get_logger(conf, log_route='slo')
        
        self.max_manifest_segments = int(self.conf.get('max_manifest_segments',
                                         1000))
        
        self.max_manifest_size = int(self.conf.get('max_manifest_size',
                                     1024 * 1024 * 2))
        self.min_segment_size = int(self.conf.get('min_segment_size',
                                    1024 * 1024))
        self.bulk_deleter = Bulk(
            app, {'max_deletes_per_request': self.max_manifest_segments})

    def handle_multipart_put(self, req):
                
        try:
            vrs, account, container, obj = split_path(req.path,1, 4, True)
        except ValueError:
            return self.app
        if req.content_length > self.max_manifest_size:
            raise HTTPRequestEntityTooLarge(
                "Manifest File > %d bytes" % self.max_manifest_size)
            
        if req.headers.get('X-Copy-From') or req.headers.get('Destination'):
            raise HTTPMethodNotAllowed(
                'Multipart Manifest PUTs cannot be Copy requests')
        if req.content_length is None and \
                req.headers.get('transfer-encoding', '').lower() != 'chunked':
            raise HTTPLengthRequired(request=req)
        parsed_data = parse_input(req.environ['wsgi.input'].read(self.max_manifest_size))
        problem_segments = []

        if len(parsed_data) > self.max_manifest_segments:
            raise HTTPRequestEntityTooLarge(
                'Number segments must be <= %d' % self.max_manifest_segments)
            
        total_size = 0
        out_content_type = 'application/json'
        if not out_content_type:
            out_content_type = 'text/plain'
        data_for_storage = []
        for index, seg_dict in enumerate(parsed_data):
            obj_path = '/'.join(
                ['', vrs, account, seg_dict['path'].lstrip('/')])
            try:
                seg_size = int(seg_dict['size_bytes'])
            except (ValueError, TypeError):
                raise HTTPBadRequest('Invalid Manifest File')
            
            new_env = req.environ.copy()
            if isinstance(obj_path, unicode):
                obj_path = obj_path.encode('utf-8')
            new_env['PATH_INFO'] = obj_path
            new_env['REQUEST_METHOD'] = 'HEAD'
            new_env['swift.source'] = 'SLO'
            del(new_env['wsgi.input'])
            del(new_env['QUERY_STRING'])
            new_env['CONTENT_LENGTH'] = 0
            new_env['HTTP_USER_AGENT'] = \
                '%s MultipartPUT' % req.environ.get('HTTP_USER_AGENT')
            head_seg_resp = \
                Request.blank(obj_path, new_env).get_response(self.app)
                
            if head_seg_resp.status_int // 100 == 2:
                total_size += seg_size
                if seg_size != head_seg_resp.content_length:
                    problem_segments.append([quote(obj_path), 'Size Mismatch'])
                if seg_dict['etag'] != head_seg_resp.etag:
                    problem_segments.append([quote(obj_path), 'Etag Mismatch'])
                                
                data_for_storage.append(
                    {'name': '/' + seg_dict['path'].lstrip('/'),
                     'bytes': seg_size,
                     'hash': seg_dict['etag']})

            else:
                problem_segments.append([quote(obj_path),
                                         head_seg_resp.status])
        if problem_segments:
            resp_body = get_response_body(
                out_content_type, {}, problem_segments)
            raise jresponse('-1','badrequest',req,400,param=resp_body)
        env = req.environ

        
        env['swift.content_type_overriden'] = True
        
        env['HTTP_X_STATIC_LARGE_OBJECT'] = 'True'
        json_data = json.dumps(data_for_storage)
        env['CONTENT_LENGTH'] = str(len(json_data))
        env['wsgi.input'] = StringIO(json_data)
        return self.app

    def handle_multipart_delete(self, req):
        
#.........这里部分代码省略.........
开发者ID:sun3shines,项目名称:swift-1.7.4,代码行数:101,代码来源:slo.py

示例10: StaticLargeObject

class StaticLargeObject(object):
    """
    StaticLargeObject Middleware

    See above for a full description.

    The proxy logs created for any subrequests made will have swift.source set
    to "SLO".

    :param app: The next WSGI filter or app in the paste.deploy chain.
    :param conf: The configuration dict for the middleware.
    """

    def __init__(
        self,
        app,
        conf,
        min_segment_size=DEFAULT_MIN_SEGMENT_SIZE,
        max_manifest_segments=DEFAULT_MAX_MANIFEST_SEGMENTS,
        max_manifest_size=DEFAULT_MAX_MANIFEST_SIZE,
    ):
        self.conf = conf
        self.app = app
        self.logger = get_logger(conf, log_route="slo")
        self.max_manifest_segments = max_manifest_segments
        self.max_manifest_size = max_manifest_size
        self.min_segment_size = min_segment_size
        self.max_get_time = int(self.conf.get("max_get_time", 86400))
        self.rate_limit_after_segment = int(self.conf.get("rate_limit_after_segment", "10"))
        self.rate_limit_segments_per_sec = int(self.conf.get("rate_limit_segments_per_sec", "0"))
        self.bulk_deleter = Bulk(app, {}, logger=self.logger)

    def handle_multipart_get_or_head(self, req, start_response):
        """
        Handles the GET or HEAD of a SLO manifest.

        The response body (only on GET, of course) will consist of the
        concatenation of the segments.

        :params req: a swob.Request with a path referencing an object
        :raises: HttpException on errors
        """
        return SloGetContext(self).handle_slo_get_or_head(req, start_response)

    def copy_hook(self, inner_hook):
        def slo_hook(source_req, source_resp, sink_req):
            x_slo = source_resp.headers.get("X-Static-Large-Object")
            if (
                config_true_value(x_slo)
                and source_req.params.get("multipart-manifest") != "get"
                and "swift.post_as_copy" not in source_req.environ
            ):
                source_resp = SloGetContext(self).get_or_head_response(
                    source_req, source_resp.headers.items(), source_resp.app_iter
                )
            return inner_hook(source_req, source_resp, sink_req)

        return slo_hook

    def handle_multipart_put(self, req, start_response):
        """
        Will handle the PUT of a SLO manifest.
        Heads every object in manifest to check if is valid and if so will
        save a manifest generated from the user input. Uses WSGIContext to
        call self and start_response and returns a WSGI iterator.

        :params req: a swob.Request with an obj in path
        :raises: HttpException on errors
        """
        try:
            vrs, account, container, obj = req.split_path(1, 4, True)
        except ValueError:
            return self.app(req.environ, start_response)
        if req.content_length > self.max_manifest_size:
            raise HTTPRequestEntityTooLarge("Manifest File > %d bytes" % self.max_manifest_size)
        if req.headers.get("X-Copy-From"):
            raise HTTPMethodNotAllowed("Multipart Manifest PUTs cannot be COPY requests")
        if req.content_length is None and req.headers.get("transfer-encoding", "").lower() != "chunked":
            raise HTTPLengthRequired(request=req)
        parsed_data = parse_input(req.body_file.read(self.max_manifest_size))
        problem_segments = []

        if len(parsed_data) > self.max_manifest_segments:
            raise HTTPRequestEntityTooLarge("Number of segments must be <= %d" % self.max_manifest_segments)
        total_size = 0
        out_content_type = req.accept.best_match(ACCEPTABLE_FORMATS)
        if not out_content_type:
            out_content_type = "text/plain"
        data_for_storage = []
        slo_etag = md5()
        last_obj_path = None
        for index, seg_dict in enumerate(parsed_data):
            obj_name = seg_dict["path"]
            if isinstance(obj_name, unicode):
                obj_name = obj_name.encode("utf-8")
            obj_path = "/".join(["", vrs, account, obj_name.lstrip("/")])
            if req.path == quote(obj_path):
                raise HTTPConflict('Manifest object name "%s" ' "cannot be included in the manifest" % obj_name)
            try:
                seg_size = int(seg_dict["size_bytes"])
#.........这里部分代码省略.........
开发者ID:pchng,项目名称:swift,代码行数:101,代码来源:slo.py

示例11: StaticLargeObject

class StaticLargeObject(object):
    """
    StaticLargeObject Middleware

    See above for a full description.

    The proxy logs created for any subrequests made will have swift.source set
    to "SLO".

    :param app: The next WSGI filter or app in the paste.deploy chain.
    :param conf: The configuration dict for the middleware.
    """

    def __init__(self, app, conf):
        self.conf = conf
        self.app = app
        self.logger = get_logger(conf, log_route="slo")
        self.max_manifest_segments = int(self.conf.get("max_manifest_segments", 1000))
        self.max_manifest_size = int(self.conf.get("max_manifest_size", 1024 * 1024 * 2))
        self.min_segment_size = int(self.conf.get("min_segment_size", 1024 * 1024))
        self.bulk_deleter = Bulk(app, {"max_deletes_per_request": self.max_manifest_segments})

    def handle_multipart_put(self, req):
        """
        Will handle the PUT of a SLO manifest.
        Heads every object in manifest to check if is valid and if so will
        save a manifest generated from the user input.

        :params req: a swob.Request with an obj in path
        :raises: HttpException on errors
        """
        try:
            vrs, account, container, obj = req.split_path(1, 4, True)
        except ValueError:
            return self.app
        if req.content_length > self.max_manifest_size:
            raise HTTPRequestEntityTooLarge("Manifest File > %d bytes" % self.max_manifest_size)
        if req.headers.get("X-Copy-From"):
            raise HTTPMethodNotAllowed("Multipart Manifest PUTs cannot be Copy requests")
        if req.content_length is None and req.headers.get("transfer-encoding", "").lower() != "chunked":
            raise HTTPLengthRequired(request=req)
        parsed_data = parse_input(req.body_file.read(self.max_manifest_size))
        problem_segments = []

        if len(parsed_data) > self.max_manifest_segments:
            raise HTTPRequestEntityTooLarge("Number segments must be <= %d" % self.max_manifest_segments)
        total_size = 0
        out_content_type = req.accept.best_match(ACCEPTABLE_FORMATS)
        if not out_content_type:
            out_content_type = "text/plain"
        data_for_storage = []
        for index, seg_dict in enumerate(parsed_data):
            obj_path = "/".join(["", vrs, account, seg_dict["path"].lstrip("/")])
            try:
                seg_size = int(seg_dict["size_bytes"])
            except (ValueError, TypeError):
                raise HTTPBadRequest("Invalid Manifest File")
            if seg_size < self.min_segment_size and (index == 0 or index < len(parsed_data) - 1):
                raise HTTPBadRequest(
                    "Each segment, except the last, must be larger than " "%d bytes." % self.min_segment_size
                )

            new_env = req.environ.copy()
            if isinstance(obj_path, unicode):
                obj_path = obj_path.encode("utf-8")
            new_env["PATH_INFO"] = obj_path
            new_env["REQUEST_METHOD"] = "HEAD"
            new_env["swift.source"] = "SLO"
            del (new_env["wsgi.input"])
            del (new_env["QUERY_STRING"])
            new_env["CONTENT_LENGTH"] = 0
            new_env["HTTP_USER_AGENT"] = "%s MultipartPUT" % req.environ.get("HTTP_USER_AGENT")
            head_seg_resp = Request.blank(obj_path, new_env).get_response(self.app)
            if head_seg_resp.is_success:
                total_size += seg_size
                if seg_size != head_seg_resp.content_length:
                    problem_segments.append([quote(obj_path), "Size Mismatch"])
                if seg_dict["etag"] != head_seg_resp.etag:
                    problem_segments.append([quote(obj_path), "Etag Mismatch"])
                if head_seg_resp.last_modified:
                    last_modified = head_seg_resp.last_modified
                else:
                    # shouldn't happen
                    last_modified = datetime.now()

                last_modified_formatted = last_modified.strftime("%Y-%m-%dT%H:%M:%S.%f")
                seg_data = {
                    "name": "/" + seg_dict["path"].lstrip("/"),
                    "bytes": seg_size,
                    "hash": seg_dict["etag"],
                    "content_type": head_seg_resp.content_type,
                    "last_modified": last_modified_formatted,
                }
                if config_true_value(head_seg_resp.headers.get("X-Static-Large-Object")):
                    seg_data["sub_slo"] = True
                data_for_storage.append(seg_data)

            else:
                problem_segments.append([quote(obj_path), head_seg_resp.status])
        if problem_segments:
#.........这里部分代码省略.........
开发者ID:GitFloki,项目名称:Shake,代码行数:101,代码来源:slo.py


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