08.存储Cinder→5.场景学习→02.Create Volume→1.cinder-api处理过程

1.在创建volume时将所有的日志都实时打开以便记笔记

2.在运行完创建volume的过程,停掉xshell,否则由于xshell显示屏有数量限制,新生成的日志会冲掉之前的日志。而且日志本身也有大小限制,时间
太久的日志也会丢失。
描述详细
  1. 客户(可以是 OpenStack最终用户,也可以是其他程序)向 cinder-api发送请求:“帮我创建一个 volume。GUI 上操作的菜单为 Project -> Volumes -> Volumes -> Create Volume
    1. 设置 volume 的名称,volume type,大小,Availability Zone 等基本信息
    2. 这里我们没有设置 Volume Source,这样会创建一个空白的 volume。paste-126491081834499.jpg
paste-112042811850755.jpg
  1. 查看 cinder-api 日志仅摘录重要的日志,后同
    1.  cinder-api 接收到一个 POST 类型的 REST API,经过对 HTTP body 的分析,该请求是:创建一个 1GB 的 volume。

1
2
3
Jun 11 16:51:13 controller devstack@c-api.service[28558]: 
INFO cinder.api.openstack.wsgi [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
//192.168.32.73/volume/v3/20c966be6e644bdfa8858d7940d0781f/volumes
1.WSGI是Web Server Gateway Interface的缩写
当使用RESTful web服务的时候:GET用于从服务器取回数据;POST请求通常用来创建一个实体;PUT请求和POST请求类似,但是一般用来更新一个已有的实体;DELETE方法用来从服务器上删除资源;HEAS请求和GET请求资源类似,但是仅仅返回响应的头部(没有具体的响应体)
2.http://192.168.32.73/volume/v3/20c966be6e644bdfa8858d7940d0781f/volumes可以通过openstack endpoint list查到
1
2
3
4
5
Jun 11 16:51:13 controller devstack@c-api.service[28558]: 
DEBUG cinder.api.v3.volumes [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
: {u'volume': {u'status': u'creating', u'size': 1, u'backup_id':
None, u'user_id': None, u'name': u'vol-1', u'imageRef': None, u'availability_zone': u'nova',
...
1
2
3
Jun 11 16:51:13 controller devstack@c-api.service[28558]: 
INFO cinder.api.v3.volumes [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
  1. 紧接着,cinder-api 启动了一个 Flow(工作流)volume_create_api。 Flow 的执行状态依次为 PENDING, RUNNING 和 SUCCESS。volume_create_api 当前的状态由 PENDING 变为 RUNNING。
1
2
3
4
5
Jun 11 16:51:13 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
(3c60509d-1a85-43c9-96fb-be0a949d0eea) transitioned into state
from state 'PENDING' {{(pid=28564) _flow_receiver
/usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:145
当执行工作流时,就会调用/usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py文件中的_flow_receiver函数
  1. volume_create_api 工作流包含若干 Task,每个 Task 完成特定的任务。 这些任务依次为 ExtractVolumeRequestTask, QuotaReserveTask, EntryCreateTask, QuotaCommitTask, VolumeCastTask,这几个任务在源码中都是类,在源码中的位置是
    1
    2
     
                   
    /opt/stack/cinder/cinder
    /volume/flows/api/create_volume.py
    。 Task 的执行状态也会经历 PENDING, RUNNING 和 SUCCESS 三个阶段

    1. ExtractVolumeRequestTask 获取 request 信息Processes an api request values into a validated set of values.(将api请求值处理为经过验证的值集。)
1
2
3
4
5
Jun 11 16:51:13 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.;volume:create'
(4865720e-3012-4135-8683-e14e5ac151f9) transitioned into state from state 'PENDING'
{{(pid=28564) _task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
当执行task时,就会调用/usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py文件中的_task_receiver函数
1
2
3
4
5
6
7
Jun 11 16:51:13 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task
(4865720e-3012-4135-8683-e14e5ac151f9) transitioned into state from state 'RUNNING'
with result '{'volume_type_id': u'e3695232-2b2d-4e2d-a184-1bcde93cd8fa', 'backup_id': None,
...
{{(pid=28564) _task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:183
  1. QuotaReserveTask 预留配额   ˈkwoʊtə 定量;定额;配额(分配的数额)    Reserves a single volume with the given size & the given volume type(用给定大小和给定卷类型预留单个卷) 
1
2
3
4
5
Jun 11 16:51:13 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.;volume:create' ...
transitioned into state from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
1
2
3
4
Jun 11 16:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.quota [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
['ca6af98f-f4fc-4798-b457-0c80cd44fb80', ...
{{(pid=28564) reserve /opt/stack/cinder/cinder/quota.py:1029
1
2
3
4
5
6
Jun 11 16:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task ...
transitioned into state from state 'RUNNING' with result
'{'reservations': ['ca6af98f-f4fc-4798-b457-0c80cd44fb80', ...
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:183

  1. EntryCreateTask 在数据库中创建 volume 条目Creates an entry for the given volume creation in the database
1
2
3
4
5
Jun 11 11:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.;volume:create' ...
transitioned into state from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
1
2
3
4
Jun 11 11:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.;volume:create' ...
transitioned into state from state 'RUNNING' with result ...
  1. QuotaCommitTask 确认配额 Commits the reservation
1
2
3
4
5
Jun 11 11:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.;volume:create' ...
transitioned into state from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
1
2
3
4
5
Jun 11 11:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task ...
transitioned into state from state 'RUNNING' with result '{'volume_properties': ...
{{(pid=28564) _task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:183
  1. 最后 VolumeCastTask 是向 cinder-sheduler 发送消息,开始调度工作   Performs a volume create cast to the scheduler or to the volume manager
1
2
3
4
5
Jun 11 11:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.VolumeCastTask;:create' ...
transitioned into state from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
1
2
3
4
5
Jun 11 11:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.;volume:create' ...
transitioned into state from state 'RUNNING' with result 'None' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:183
  1. 至此,Flow volume_create_api 已经完成,状态由 RUNNING 变为 SUCCESS,创建volume 请求成功发布cinder-api 已经成功处理了 volume create 请求,将消息发给了 cinder-scheduler
1
2
3
4
5
Jun 11 11:51:14 controller devstack@c-api.service[28558]: 
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
(3c60509d-1a85-43c9-96fb-be0a949d0eea)
transitioned into state from state 'RUNNING'
{{(pid=28564) _flow_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:145
1
2
3
Jun 11 11:51:14 controller devstack@c-api.service[28558]: 
INFO cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
  1. cinder-api 向 RabbitMQ 发送了一条消息:“让cinder-scheduler 创建一个 volume”,消息是由 VolumeCastTask 发出的,因为 VolumeCastTask 没有打印相关日志,我们只能通过源代码查看 /opt/stack/cinder/cinder/volume/flows/api/create_volume.py ,方法为 create_volume。

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class VolumeCastTask(flow_utils.CinderTask):
"""Performs a volume create cast to the scheduler or to the volume manager.

This will signal a transition of the api workflow to another child and/or
related workflow on another component.

Reversion strategy: rollback source volume status and error out newly
created volume.
"""
#...
def _cast_create_volume(self, context, request_spec, filter_properties):
#...
self.scheduler_rpcapi.create_volume(
context,
volume,
snapshot_id=snapshot_id,
image_id=image_id,
request_spec=request_spec,
filter_properties=filter_properties,
backup_id=backup_id)
#...

如果我们需要将一个函数运行在远程计算机上并且等待从那儿获取结果时,该怎么办呢?这就是另外的故事了。这种模式通常被称为远程过程调用(Remote Procedure Call)或者 RPC,使用 RabbitMQ 来构建一个 RPC 系统
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值