博客
关于我
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/

你可能感兴趣的文章
MySQL5.7.37windows解压版的安装使用
查看>>
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>