| 客戶(可以是 OpenStack最終用戶,也可以是其他程序)向 cinder-api發(fā)送請求:“幫我創(chuàng)建一個 volume。GUI 上操作的菜單為 Project -> Volumes -> Volumes -> Create Volume設(shè)置 volume 的名稱,volume type,大小,Availability Zone 等基本信息這里我們沒有設(shè)置 Volume Source,這樣會創(chuàng)建一個空白的 volume。 | |
| 查看 cinder-api 日志僅摘錄重要的日志,后同 :?cinder-api 接收到一個 POST 類型的 REST API,經(jīng)過對 HTTP body 的分析,該請求是:創(chuàng)建一個 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的縮寫當(dāng)使用RESTful web服務(wù)的時候:GET用于從服務(wù)器取回數(shù)據(jù);POST請求通常用來創(chuàng)建一個實體;PUT請求和POST請求類似,但是一般用來更新一個已有的實體;DELETE方法用來從服務(wù)器上刪除資源;HEAS請求和GET請求資源類似,但是僅僅返回響應(yīng)的頭部(沒有具體的響應(yīng)體)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]
|
|
| 緊接著,cinder-api 啟動了一個 Flow(工作流)volume_create_api。 Flow 的執(zhí)行狀態(tài)依次為 PENDING, RUNNING 和 SUCCESS。volume_create_api 當(dāng)前的狀態(tài)由 PENDING 變?yōu)?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 | 當(dāng)執(zhí)行工作流時,就會調(diào)用/usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py文件中的_flow_receiver函數(shù) |
volume_create_api 工作流包含若干 Task,每個 Task 完成特定的任務(wù)。 這些任務(wù)依次為 ExtractVolumeRequestTask, QuotaReserveTask, EntryCreateTask, QuotaCommitTask, VolumeCastTask,這幾個任務(wù)在源碼中都是類,在源碼中的位置是1
2 | /opt/stack/cinder/cinder /volume/flows/api/create_volume.py
|
| 。 Task 的執(zhí)行狀態(tài)也會經(jīng)歷 PENDING, RUNNING 和 SUCCESS 三個階段 |
|
| ExtractVolumeRequestTask 獲取 request 信息Processes an api request values into a validated set of values.(將api請求值處理為經(jīng)過驗證的值集。) | 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
| 當(dāng)執(zhí)行task時,就會調(diào)用/usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py文件中的_task_receiver函數(shù)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 |
|
| QuotaReserveTask?預(yù)留配額 ???kwo?t? 定量;定額;配額(分配的數(shù)額) ? ?Reserves a single volume with the given size & the given volume type(用給定大小和給定卷類型預(yù)留單個卷)? | 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
|
|
| EntryCreateTask 在數(shù)據(jù)庫中創(chuàng)建 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 ...
|
|
| QuotaCommitTask 確認(rèn)配額 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 |
|
| 最后 VolumeCastTask 是向 cinder-sheduler 發(fā)送消息,開始調(diào)度工作 ? 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 |
|
| 至此,Flow volume_create_api 已經(jīng)完成,狀態(tài)由 RUNNING 變?yōu)?SUCCESS,創(chuàng)建volume 請求成功發(fā)布cinder-api 已經(jīng)成功處理了 volume create 請求,將消息發(fā)給了 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]
|
|
| cinder-api 向 RabbitMQ 發(fā)送了一條消息:“讓cinder-scheduler 創(chuàng)建一個 volume”,消息是由 VolumeCastTask 發(fā)出的,因為 VolumeCastTask 沒有打印相關(guān)日志,我們只能通過源代碼查看 /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) #... | 如果我們需要將一個函數(shù)運行在遠(yuǎn)程計算機上并且等待從那兒獲取結(jié)果時,該怎么辦呢?這就是另外的故事了。這種模式通常被稱為遠(yuǎn)程過程調(diào)用(Remote Procedure Call)或者 RPC,使用 RabbitMQ 來構(gòu)建一個 RPC 系統(tǒng) |