Masakari 中的通知¶
与 OpenStack 的其他服务类似,Masakari 通过 oslo.messaging 提供的 Notifier 类向消息总线发出通知。从通知消费者角度来看,通知由两部分组成:一个具有由 oslo.messaging 定义的固定结构的信封,以及一个由发出通知的服务定义的有效负载。信封格式如下
{
"priority": <string, selected from a predefined list by the sender>,
"event_type": <string, defined by the sender>,
"timestamp": <string, the isotime of when the notification emitted>,
"publisher_id": <string, defined by the sender>,
"message_id": <uuid, generated by oslo>,
"payload": <json serialized dict, defined by the sender>
}
- oslo.messaging 提供了以下通知驱动程序的选择
驱动程序
描述
messaging
使用 1.0 消息格式发送通知
messagingv2
使用 2.0 消息格式(带有消息信封)发送通知
routing
可配置的路由通知器(按优先级或 event_type)
log
通过 Python 日志记录基础设施发布通知
test
将通知存储在内存中以进行测试验证
noop
完全禁用发送通知
因此,可以通过在 Masakari 配置文件中设置以下内容来完全禁用通知
[oslo_messaging_notifications]
driver = noop
Masakari 仅支持版本化通知。
版本化通知¶
Masakari 代码使用 masakari.rpc.get_notifier 调用来获取配置的 oslo.messaging Notifier 对象,并使用 oslo 提供的函数在 Notifier 对象上发出通知。返回的 Notifier 对象的配置取决于 get_notifier 调用的参数以及 oslo.messaging 配置选项 driver 和 topics 的值。版本化通知的有效负载不是自由形式的字典,而是序列化的 oslo.versionedobjects。
例如,segment.update 通知的线路格式如下所示
{
"event_type": "api.update.segments.start",
"timestamp": "2018-11-27 14:32:20.396940",
"payload": {
"masakari_object.name": "SegmentApiPayload",
"masakari_object.data": {
"description": null,
"fault": null,
"recovery_method": "auto",
"name": "test",
"service_type": "compute",
"id": 877,
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
}, "
"masakari_object.version": "1.0",
"masakari_object.namespace": "masakari"
},
"priority": "INFO",
"publisher_id": "masakari-api:test-virtualbox",
"message_id": "e6322900-025d-4dd6-a3a1-3e0e1e9badeb"
}
序列化的 oslo versionedobject 作为有效负载为消费者提供版本号,以便消费者可以检测到有效负载的结构是否已更改。Masakari 提供了关于版本化通知有效负载的以下约定
有效负载中由
masakari_object.version字段定义的有效负载版本仅在有效负载的masakari_object.data字段的语法或语义发生更改时才会增加。次要版本更新表示向后兼容的更改,这意味着仅向有效负载添加新字段,因此编写良好的消费者仍然可以在不进行任何更改的情况下使用新的有效负载。
主要版本更新表示有效负载的向后不兼容的更改,这意味着有效负载中可能存在已删除的字段、类型更改等。
除了
masakari_object.data和masakari_object.version之外,每个有效负载都有一个额外的字段masakari_object.name。该字段包含 Masakari 内部有效负载类型表示形式的名称。客户端代码不应依赖此名称。
现有的版本化通知¶
这提供了带有示例有效负载的现有版本化通知列表。
| 事件类型 | 通知类 | 有效负载类 | 示例 |
error.exception |
ExceptionNotification |
ExceptionPayload |
{
"event_type": "segment.create.error",
"message_id": "e5405591-1d19-4a8c-aa92-4d551165d863",
"payload": {
"masakari_object.data": {
"description": null,
"fault": {
"masakari_object.data": {
"exception": "DBError",
"exception_message": "(pymysql.err.Internal Error) (1054, u\"Unknown column 'name' in 'field list'\" ...",
"function_name": "raise_mysql_exception",
"module_name": "pymysql.err",
"traceback": "Traceback (most recent call last):\n File \"/opt/stack/masakari/masakari/ha/api.py\", line ..."
},
"masakari_object.name": "ExceptionPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"name": "testT6",
"recovery_method": "auto",
"service_type": "compute"
},
"masakari_object.name": "SegmentApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "ERROR",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-28 14:24:27.902437"
} |
create.host.end |
HostApiNotification |
HostApiPayload |
{
"event_type": "host.create.end",
"message_id": "e437834a-73e1-4c47-939a-83f6aca2e7ac",
"payload": {
"masakari_object.data": {
"control_attributes": "TEST",
"failover_segment": {
"masakari_object.data": {
"created_at": "2018-11-27T09:26:30Z",
"deleted": false,
"deleted_at": null,
"description": null,
"id": 877,
"name": "test",
"recovery_method": "auto",
"service_type": "compute",
"updated_at": "2018-11-27T09:54:50Z",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "FailoverSegment",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"failover_segment_id": "89597691-bebd-4860-a93e-1b6e9de34b9e",
"fault": null,
"id": 70,
"name": "fake-mini",
"on_maintenance": false,
"reserved": false,
"type": "COMPUTE",
"uuid": "d6a2d900-1977-48fd-aa52-ad7a41fc068b"
},
"masakari_object.name": "HostApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 13:09:30.737034"
} |
create.host.start |
HostApiNotification |
HostApiPayload |
{
"event_type": "host.create.start",
"message_id": "0ed836cc-353a-40bc-b86b-d89e6632d838",
"payload": {
"masakari_object.data": {
"control_attributes": "TEST",
"failover_segment": {
"masakari_object.data": {
"created_at": "2018-11-27T09:26:30Z",
"deleted": false,
"deleted_at": null,
"description": null,
"id": 877,
"name": "test",
"recovery_method": "auto",
"service_type": "compute",
"updated_at": "2018-11-27T09:54:50Z",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "FailoverSegment",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"failover_segment_id": "89597691-bebd-4860-a93e-1b6e9de34b9e",
"fault": null,
"name": "fake-mini",
"on_maintenance": false,
"reserved": false,
"type": "COMPUTE"
},
"masakari_object.name": "HostApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 13:09:30.716747"
} |
delete.host.end |
HostApiNotification |
HostApiPayload |
{
"event_type": "host.delete.end",
"message_id": "64d61bcf-c875-41c3-b795-19a076f6de96",
"payload": {
"masakari_object.data": {
"control_attributes": "TEST",
"failover_segment": {
"masakari_object.data": {
"created_at": "2018-11-27T09:26:30Z",
"deleted": false,
"deleted_at": null,
"description": null,
"id": 877,
"name": "test",
"recovery_method": "auto",
"service_type": "compute",
"updated_at": "2018-11-27T09:54:50Z",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "FailoverSegment",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"failover_segment_id": "89597691-bebd-4860-a93e-1b6e9de34b9e",
"fault": null,
"name": "fake-mini",
"on_maintenance": false,
"reserved": false,
"type": "COMPUTE",
"uuid": "3d8d1751-9cab-4a48-8801-96f102200077"
},
"masakari_object.name": "HostApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 13:35:09.882636"
} |
delete.host.start |
HostApiNotification |
HostApiPayload |
{
"event_type": "host.delete.start",
"message_id": "b5914f94-99dd-42fa-aaf3-3cedacda6b67",
"payload": {
"masakari_object.data": {
"control_attributes": "TEST",
"failover_segment": {
"masakari_object.data": {
"created_at": "2018-11-27T09:26:30Z",
"deleted": false,
"deleted_at": null,
"description": null,
"id": 877,
"name": "test",
"recovery_method": "auto",
"service_type": "compute",
"updated_at": "2018-11-27T09:54:50Z",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "FailoverSegment",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"failover_segment_id": "89597691-bebd-4860-a93e-1b6e9de34b9e",
"fault": null,
"id": 71,
"name": "fake-mini",
"on_maintenance": false,
"reserved": false,
"type": "COMPUTE",
"uuid": "3d8d1751-9cab-4a48-8801-96f102200077"
},
"masakari_object.name": "HostApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 13:31:47.451466"
} |
update.host.end |
HostApiNotification |
HostApiPayload |
{
"event_type": "host.update.end",
"message_id": "e7f85d49-7d02-4713-b90b-433f8e447558",
"payload": {
"masakari_object.data": {
"control_attributes": "TEST",
"failover_segment": {
"masakari_object.data": {
"created_at": "2018-11-27T09:26:30Z",
"deleted": false,
"deleted_at": null,
"description": null,
"id": 877,
"name": "test",
"recovery_method": "auto",
"service_type": "compute",
"updated_at": "2018-11-27T09:54:50Z",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "FailoverSegment",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"failover_segment_id": "89597691-bebd-4860-a93e-1b6e9de34b9e",
"fault": null,
"id": 70,
"name": "fake-mini",
"on_maintenance": false,
"reserved": false,
"type": "COMPUTE",
"uuid": "d6a2d900-1977-48fd-aa52-ad7a41fc068b"
},
"masakari_object.name": "HostApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 13:13:25.361394"
} |
update.host.start |
HostApiNotification |
HostApiPayload |
{
"event_type": "host.update.start",
"message_id": "d1a3ae84-7f41-4884-bc3f-fa34c7cd1424",
"payload": {
"masakari_object.data": {
"control_attributes": "TEST",
"failover_segment": {
"masakari_object.data": {
"created_at": "2018-11-27T09:26:30Z",
"deleted": false,
"deleted_at": null,
"description": null,
"id": 877,
"name": "test",
"recovery_method": "auto",
"service_type": "compute",
"updated_at": "2018-11-27T09:54:50Z",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "FailoverSegment",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"failover_segment_id": "89597691-bebd-4860-a93e-1b6e9de34b9e",
"fault": null,
"id": 70,
"name": "fake-mini",
"on_maintenance": false,
"reserved": false,
"type": "COMPUTE",
"uuid": "d6a2d900-1977-48fd-aa52-ad7a41fc068b"
},
"masakari_object.name": "HostApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 13:13:25.298007"
} |
create.notification.end |
NotificationApiNotification |
NotificationApiPayload |
{
"event_type": "notification.create.end",
"message_id": "500447b9-4797-4090-9189-b56bc3521b75",
"payload": {
"masakari_object.data": {
"fault": null,
"generated_time": "2017-06-13T15:34:55Z",
"id": 1,
"notification_uuid": "e6b1996f-7792-4a65-83c3-23f2d4721eb0",
"payload": {
"process_name": "nova-compute"
},
"source_host_uuid": "d4ffe3a4-b2a8-41f3-a2b0-bae3b06fc1a3",
"status": "new",
"type": "VM"
},
"masakari_object.name": "NotificationApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 13:46:25.496514"
} |
create.notification.start |
NotificationApiNotification |
NotificationApiPayload |
{
"event_type": "notification.create.start",
"message_id": "5e2e4699-0bbd-4583-b1e2-a87c458f84eb",
"payload": {
"masakari_object.data": {
"fault": null,
"generated_time": "2017-06-13T15:34:55Z",
"payload": {
"process_name": "nova-compute"
},
"source_host_uuid": "d4ffe3a4-b2a8-41f3-a2b0-bae3b06fc1a3",
"status": "new",
"type": "VM"
},
"masakari_object.name": "NotificationApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 13:46:23.060352"
} |
process.notification.end |
NotificationApiNotification |
NotificationApiPayload |
{
"event_type": "notification.process.end",
"message_id": "c081eb25-7450-4fa2-bb19-ae6d4466e14e",
"payload": {
"masakari_object.data": {
"fault": null,
"generated_time": "2017-06-13T15:34:55Z",
"id": 47,
"notification_uuid": "15505a8c-8856-4f3d-9747-55b6e899c0f5",
"payload": {
"process_name": "nova-compute"
},
"source_host_uuid": "6bfaf80d-7592-4ea8-ad12-60d45476d056",
"status": "ignored",
"type": "VM"
},
"masakari_object.name": "NotificationApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-engine:fake-mini",
"timestamp": "2018-12-20 05:26:05.075917"
} |
process.notification.error |
NotificationApiNotification |
NotificationApiPayload |
{
"event_type": "notification.process.error",
"message_id": "5f3c9705-b3fb-41f9-a4e0-4868db93178c",
"payload": {
"masakari_object.data": {
"fault": {
"masakari_object.data": {
"exception": "str",
"exception_message": "Failed to execute process recovery workflow.",
"function_name": "_handle_notification_type_process",
"module_name": "masakari.engine.manager",
"traceback": "Traceback (most recent call last):\n File \"/opt/stack/masakari/masakari/engine/manager.py\", line ..."
},
"masakari_object.name": "ExceptionPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"generated_time": "2017-06-13T15:34:55Z",
"id": 51,
"notification_uuid": "0adb94e0-8283-4702-9793-186d4ed914e8",
"payload": {
"process_name": "nova-compute"
},
"source_host_uuid": "6bfaf80d-7592-4ea8-ad12-60d45476d056",
"status": "running",
"type": "PROCESS"
},
"masakari_object.name": "NotificationApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "ERROR",
"publisher_id": "masakari-engine:fake-mini",
"timestamp": "2018-12-20 06:21:19.315761"
} |
process.notification.start |
NotificationApiNotification |
NotificationApiPayload |
{
"event_type": "notification.process.start",
"message_id": "285be756-ac29-4b78-9e2b-9756f5077012",
"payload": {
"masakari_object.data": {
"fault": null,
"generated_time": "2017-06-13T15:34:55Z",
"id": 47,
"notification_uuid": "15505a8c-8856-4f3d-9747-55b6e899c0f5",
"payload": {
"process_name": "nova-compute"
},
"source_host_uuid": "6bfaf80d-7592-4ea8-ad12-60d45476d056",
"status": "new",
"type": "VM"
},
"masakari_object.name": "NotificationApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-engine:fake-mini",
"timestamp": "2018-12-20 05:26:05.002421"
} |
create.segment.end |
SegmentApiNotification |
SegmentApiPayload |
{
"event_type": "segment.create.end",
"message_id": "b8478b31-5943-4495-8867-e8291655f660",
"payload": {
"masakari_object.data": {
"description": null,
"fault": null,
"id": 850,
"name": "test",
"recovery_method": "auto",
"service_type": "compute",
"uuid": "5cce639c-da08-4e78-b615-66c88aa49d50"
},
"masakari_object.name": "SegmentApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-22 09:25:12.813483"
} |
create.segment.start |
SegmentApiNotification |
SegmentApiPayload |
{
"event_type": "segment.create.start",
"message_id": "e44cb15b-dcba-409e-b0e1-9ee103b9a168",
"payload": {
"masakari_object.data": {
"description": null,
"fault": null,
"name": "test",
"recovery_method": "auto",
"service_type": "compute"
},
"masakari_object.name": "SegmentApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-22 09:25:12.393979"
} |
delete.segment.end |
SegmentApiNotification |
SegmentApiPayload |
{
"event_type": "segment.delete.end",
"message_id": "00184d05-7a96-4021-b44e-03912a6c0b0d",
"payload": {
"masakari_object.data": {
"description": null,
"fault": null,
"name": "test2",
"recovery_method": "auto",
"service_type": "compute",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "SegmentApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 14:36:07.457369"
} |
delete.segment.start |
SegmentApiNotification |
SegmentApiPayload |
{
"event_type": "segment.delete.start",
"message_id": "e6c32ecb-eacc-433d-ba8c-6390ea3da6d2",
"payload": {
"masakari_object.data": {
"description": null,
"fault": null,
"id": 877,
"name": "test2",
"recovery_method": "auto",
"service_type": "compute",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "SegmentApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 14:36:07.442538"
} |
update.segment.end |
SegmentApiNotification |
SegmentApiPayload |
{
"event_type": "segment.update.end",
"message_id": "3fbe50a5-9175-4161-85f0-e502f9024657",
"payload": {
"masakari_object.data": {
"description": null,
"fault": null,
"id": 877,
"name": "test2",
"recovery_method": "auto",
"service_type": "compute",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "SegmentApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 14:32:20.417745"
} |
update.segment.start |
SegmentApiNotification |
SegmentApiPayload |
{
"event_type": "segment.update.start",
"message_id": "e6322900-025d-4dd6-a3a1-3e0e1e9badeb",
"payload": {
"masakari_object.data": {
"description": null,
"fault": null,
"id": 877,
"name": "test",
"recovery_method": "auto",
"service_type": "compute",
"uuid": "89597691-bebd-4860-a93e-1b6e9de34b9e"
},
"masakari_object.name": "SegmentApiPayload",
"masakari_object.namespace": "masakari",
"masakari_object.version": "1.0"
},
"priority": "INFO",
"publisher_id": "masakari-api:fake-mini",
"timestamp": "2018-11-27 14:32:20.396940"
} |