批量计算使用 MNS 来实现消息通知。您负责主题的创建、管理和订阅,并在创建集群或提交作业时指定相关配置。批量计算会依据配置向指定的主题推送消息,您可在 MNS 控制台配置 URL、队列、邮件和短信四种方式获取消息通知。
说明
支持的事件
目前批量计算支持两类事件,您可以按需配置:
- 集群事件:
- 集群已删除:
OnClusterDeleted
; - 实例已创建:
OnInstanceCreated
; - 实例已运行:
OnInstanceActive
;
- 集群已删除:
- 作业事件:
- 作业等待中:
OnJobWaiting
; - 作业运行中:
OnJobRunning
; - 作业已停止:
OnJobStopped
; - 作业已结束:
OnJobFinished
; - 作业已失败:
OnJobFailed
; - 任务等待中:
OnTaskWaiting
; - 任务运行中:
OnTaskRunning
; - 任务停止中:
OnTaskStopped
; - 任务已结束:
OnTaskFinished
; - 任务已失败:
OnTaskFailed
; - 实例等待中:
OnInstanceWaiting
; - 实例运行中:
OnInstanceRunning
; - 实例已停止:
OnInstanceStopped
; - 实例已结束:
OnInstanceFinished
; - 实例已失败:
OnInstanceFailed
; - 优先级改变:
OnPriorityChange
。
- 作业等待中:
消息格式
适用于 OnClusterDeleted
。
{
"Category": "Cluster",
"ClusterId": "cls-hr2rbl6qt5gki7392b8001",
"ClusterName": "test-cluster",
"CreationTime": "2016-11-01T15:25:02.837728Z",
"State": "Deleted",
"Event": "OnClusterDeleted"
}
适用于 OnInstanceCreated
、OnInstanceActive
。
{
"Category": "Cluster",
"ClusterId": "cls-hr2rbl6qt5gki7392b8001",
"Group": "group1",
"InstanceId": "i-wz9c51g2s6zsrtnqi4fa",
"InnerIpAddress": "10.45.168.26",
"Hints": "",
"State": "Starting",
"CreationTime": "2016-11-01T15:25:02.837728Z",
"Event": "OnInstanceCreated"
}
适用于 OnJobWaiting
、OnJobRunning
、OnJobStopped
、OnJobFinished
、OnJobFailed
。
{
"Category": "Job",
"JobId": "job-0000000058524720000077E900007257",
"JobName": "test-job",
"Event": "OnJobWaiting",
"State": "Waiting",
"CreationTime": "2016-11-01T15:25:02.837728Z",
"StartTime": "2016-11-01T15:35:02.837728Z",
"EndTime": "2016-11-01T15:45:02.837728Z",
"Message": ""
}
适用于 OnTaskWaiting
、OnTaskRunning
、OnTaskStopped
、OnTaskFinished
、OnTaskFailed
。
{
"Category": "Job",
"JobId": "job-0000000058524720000077E900007257",
"Task": "Echo",
"Event": "OnTaskWaiting",
"State": "Waiting",
"StartTime": "2016-11-01T15:35:02.837728Z",
"EndTime": "2016-11-01T15:45:02.837728Z"
}
适用于 OnInstanceWaiting
、OnInstanceRunning
、OnInstanceStopped
、OnInstanceFinished
、OnInstanceFailed
。
{
"Category": "Job",
"JobId": "job-0000000058524720000077E900007257",
"Task": "Echo",
"InstanceId": "0",
"Event": "OnInstanceWaiting",
"State": "Waiting",
"StartTime": "2016-11-01T15:35:02.837728Z",
"EndTime": "2016-11-01T15:45:02.837728Z",
"RetryCount": "0",
"Progress": "0",
"StdoutRedirectPath": "oss://bucket/tests/a44c0ad8-a003-11e6-8f8e-fefec0a80e06/logs/stderr.job-0000000058184218000008150000000D.task.0",
"StderrRedirectPath": "oss://bucket/tests/a44c0ad8-a003-11e6-8f8e-fefec0a80e06/logs/stdout.job-0000000058184218000008150000000D.task.0",
"ExitCode": "0",
"ErrorCode": "",
"ErrorMessage": "",
"Detail": ""
}
适用于 OnPriorityChange
。
{
"Category": "Job",
"JobId": "job-0000000058524720000077E900007257",
"JobName": "test-job",
"Event": "OnPriorityChange",
"State": "Waiting",
"CreationTime": "2016-11-01T15:45:02.837728Z",
"StartTime": "2016-11-01T15:55:02.837728Z",
"EndTime": "2016-11-01T15:57:02.837728Z",
"Message": "",
"From": "10",
"To": "20"
}
使用
使用消息队列必须同时指定 MNS 主题名称 (Name)、MNS 私网 Endpoint (Endpoint) 和关注的事件 (Events)。
以下我们将展示通过 SDK 展示如何使用 MNS 消息队列,其中 MNS 主题名称为test
,MNS私网 Endpoint 为http://xxx.mns.cn-beijing.aliyuncs.com/
,关注的事件为OnClusterDeleted
、OnInstanceCreated
和OnInstanceActive
。
SDK
from batchcompute.resources import (
ClusterDescription, Notification, Topic
)
cluster_desc = ClusterDescription()
notification = Notification()
topic = Topic()
topic.Name = 'test'
topic.Endpoint = 'http://xxx.mns.cn-beijing.aliyuncs.com/'
topic.Events = ["OnClusterDeleted", "OnInstanceCreated", "OnInstanceActive"]
notification.Topic = topic
cluster_desc.Notification = notification
文档内容是否对您有帮助?