- 客戶(能夠是 OpenStack最終用戶,也能夠是其餘程序)向 cinder-api發送請求:「幫我建立一個 volume。GUI 上操做的菜單爲 Project -> Volumes -> Volumes -> Create Volume
- 設置 volume 的名稱,volume type,大小,Availability Zone 等基本信息
- 這裏咱們沒有設置 Volume Source,這樣會建立一個空白的 volume。
|
|
- 查看 cinder-api 日誌僅摘錄重要的日誌,後同 :
- cinder-api 接收到一個 POST 類型的 REST API,通過對 HTTP body 的分析,該請求是:建立一個 1GB 的 volume。
|
|
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]
POST http://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查到
|
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]
Create volume request body: {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',
...
|
|
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]
Create volume of 1 GB
|
|
- 緊接着,cinder-api 啓動了一個 Flow(工做流)volume_create_api。 Flow 的執行狀態依次爲 PENDING, RUNNING 和 SUCCESS。volume_create_api 當前的狀態由 PENDING 變爲 RUNNING。
|
|
Jun 11 16:51:13 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Flow 'volume_create_api' (3c60509d-1a85-43c9-96fb-be0a949d0eea) transitioned into state
'RUNNING' 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函數 |
- volume_create_api 工做流包含若干 Task,每一個 Task 完成特定的任務。 這些任務依次爲 ExtractVolumeRequestTask, QuotaReserveTask, EntryCreateTask, QuotaCommitTask, VolumeCastTask,這幾個任務在源碼中都是類,在源碼中的位置是
|
/opt/stack/cinder/cinder
/volume/flows/api/create_volume.py
|
|
。 Task 的執行狀態也會經歷 PENDING, RUNNING 和 SUCCESS 三個階段
|
|
- ExtractVolumeRequestTask 獲取 request 信息Processes an api request values into a validated set of values.(將api請求值處理爲通過驗證的值集。)
|
|
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.ExtractVolumeRequestTask;volume:create'
(4865720e-3012-4135-8683-e14e5ac151f9) transitioned into state 'RUNNING' 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函數
|
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.ExtractVolumeRequestTask;volume:create'
(4865720e-3012-4135-8683-e14e5ac151f9) transitioned into state 'SUCCESS' 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 預留配額 ˈkwoʊtə 定量;定額;配額(分配的數額) Reserves a single volume with the given size & the given volume type(用給定大小和給定卷類型預留單個卷)
|
|
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.QuotaReserveTask;volume:create' ...
transitioned into state 'RUNNING' from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
|
|
Jun 11 16:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.quota [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Created reservations ['ca6af98f-f4fc-4798-b457-0c80cd44fb80', ...
{{(pid=28564) reserve /opt/stack/cinder/cinder/quota.py:1029
|
|
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 'cinder.volume.flows.api.create_volume.QuotaReserveTask;volume:create' ...
transitioned into state 'SUCCESS' 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 在數據庫中建立 volume 條目Creates an entry for the given volume creation in the database
|
|
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.EntryCreateTask;volume:create' ...
transitioned into state 'RUNNING' from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
|
|
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.EntryCreateTask;volume:create' ...
transitioned into state 'SUCCESS' from state 'RUNNING' with result ...
|
|
- QuotaCommitTask 確認配額 Commits the reservation
|
|
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.QuotaCommitTask;volume:create' ...
transitioned into state 'RUNNING' from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
|
|
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.QuotaCommitTask;volume:create' ...
transitioned into state 'SUCCESS' 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 發送消息,開始調度工做 Performs a volume create cast to the scheduler or to the volume manager
|
|
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;volume:create' ...
transitioned into state 'RUNNING' from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
|
|
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;volume:create' ...
transitioned into state 'SUCCESS' 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 已經完成,狀態由 RUNNING 變爲 SUCCESS,建立volume 請求成功發佈cinder-api 已經成功處理了 volume create 請求,將消息發給了 cinder-scheduler
|
|
Jun 11 11:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Flow 'volume_create_api' (3c60509d-1a85-43c9-96fb-be0a949d0eea)
transitioned into state 'SUCCESS' from state 'RUNNING'
{{(pid=28564) _flow_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:145
|
|
Jun 11 11:51:14 controller devstack@c-api.service[28558]:
INFO cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Create volume request issued successfully.
|
|
- 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.python
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)
#...web
|
若是咱們須要將一個函數運行在遠程計算機上而且等待從那兒獲取結果時,該怎麼辦呢?這就是另外的故事了。這種模式一般被稱爲遠程過程調用(Remote Procedure Call)或者 RPC,使用 RabbitMQ 來構建一個 RPC 系統 |