博客
关于我
Swift的WSGI Application到对应的Controller
阅读量:167 次
发布时间:2019-02-28

本文共 3215 字,大约阅读时间需要 10 分钟。

proxy-server将根据请求中的信息调用相应Controller中的数据进行处理。
# /swift/proxy/server.pyclass Application(object):    def __call__(self, env, start_response):        """        WSGI entry point.        Wraps env in swob.Request object and passes it down.        :param env: WSGI environment dictionary        :param start_response: WSGI callable        """        try:            if self.memcache is None:                self.memcache = cache_from_env(env, True)            req = self.update_request(Request(env))            #处理消息入口            return self.handle_request(req)(env, start_response)    def handle_request(self, req):                try:                #根据请求中的信息得到相应Controller中的函数                handler = getattr(controller, req.method)                getattr(handler, 'publicly_accessible')            except AttributeError:                allowed_methods = getattr(controller, 'allowed_methods', set())                return HTTPMethodNotAllowed(                    request=req, headers={'Allow': ', '.join(allowed_methods)})            if 'swift.authorize' in req.environ:                resp = req.environ['swift.authorize'](req)                if not resp and not req.headers.get('X-Copy-From-Account') \                        and not req.headers.get('Destination-Account'):                    del req.environ['swift.authorize']                else:                    if not getattr(handler, 'delay_denial', None):                        return resp            req.environ['swift.orig_req_method'] = req.method            调用相应Controller中的函数进行处理            return handler(req)
与对象的三个层次相对应,分别有三种Controller:AccountController、ContainerController以及ObjectController,这三种Controller的实现都位于swift/proxy/controllers目录。
以AccountController为例:
#swift/proxy/controllers/account.pyclass AccountController(Controller):    def PUT(self, req):        """HTTP PUT request handler."""        if not self.app.allow_account_management:            return HTTPMethodNotAllowed(                request=req,                headers={'Allow': ', '.join(self.allowed_methods)})        error_response = check_metadata(req, 'account')        if error_response:            return error_response        if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:            resp = HTTPBadRequest(request=req)            resp.body = 'Account name length of %d longer than %d' % \                        (len(self.account_name),                         constraints.MAX_ACCOUNT_NAME_LENGTH)            return resp        #account_ring即为Proxy Server在初始化时为Account创建的Ring        #get_nodes()返回包含该Account内容的Partition        account_partition, accounts = \            self.app.account_ring.get_nodes(self.account_name)        headers = self.generate_request_headers(req, transfer=True)        clear_info_cache(self.app, req.environ, self.account_name)        #make_requests()会首先获得包含该parttion及其副本的所有节点,然后依次将请求发送到每个节点,直到其中一个节点返回正确的结果为止        resp = self.make_requests(            req, self.app.account_ring, account_partition, 'PUT',            req.swift_entity_path, [headers] * len(accounts))        self.add_acls_from_sys_metadata(resp)        return resp
参考
https://www.ibm.com/developerworks/cn/cloud/library/1310_zhanghua_openstackswift/index.html

转载地址:http://ylej.baihongyu.com/

你可能感兴趣的文章
NIFI大数据进阶_NIFI监控功能实际操作_Summary查看系统和处理器运行情况_viewDataProvenance查看_---大数据之Nifi工作笔记0026
查看>>
NIFI大数据进阶_NIFI监控的强大功能介绍_处理器面板_进程组面板_summary监控_data_provenance事件源---大数据之Nifi工作笔记0025
查看>>
NIFI大数据进阶_NIFI集群知识点_认识NIFI集群以及集群的组成部分---大数据之Nifi工作笔记0014
查看>>
NIFI大数据进阶_NIFI集群知识点_集群的断开_重连_退役_卸载_总结---大数据之Nifi工作笔记0018
查看>>
NIFI大数据进阶_使用NIFI表达式语言_来获取自定义属性中的数据_NIFI表达式使用体验---大数据之Nifi工作笔记0024
查看>>
NIFI大数据进阶_内嵌ZK模式集群1_搭建过程说明---大数据之Nifi工作笔记0015
查看>>
NIFI大数据进阶_内嵌ZK模式集群2_实际操作搭建NIFI内嵌模式集群---大数据之Nifi工作笔记0016
查看>>
NIFI大数据进阶_外部ZK模式集群1_实际操作搭建NIFI外部ZK模式集群---大数据之Nifi工作笔记0017
查看>>
NIFI大数据进阶_实时同步MySql的数据到Hive中去_可增量同步_实时监控MySql数据库变化_实际操作_03---大数据之Nifi工作笔记0035
查看>>
NIFI大数据进阶_实时同步MySql的数据到Hive中去_可增量同步_实时监控MySql数据库变化_操作方法说明_01---大数据之Nifi工作笔记0033
查看>>
NIFI大数据进阶_实时同步MySql的数据到Hive中去_可增量同步_实时监控MySql数据库变化_操作方法说明_02---大数据之Nifi工作笔记0034
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_01_实际操作---大数据之Nifi工作笔记0029
查看>>