批量計(jì)算服務(wù)(BatchCompute)使用 MNS 提供的主題模式來(lái)實(shí)現(xiàn)消息通知。

用戶負(fù)責(zé)主題(Topic)的創(chuàng)建、管理和訂閱,并在使用 BatchCompute 創(chuàng)建集群或提交作業(yè)時(shí)指定主題相關(guān)的配置。BatchCompute 依據(jù)配置向指定用戶主題推送消息。用戶可在 MNS 控制臺(tái)配置 URL、隊(duì)列、郵件和短信四種方式獲取消息通知。目前,BatchCompute 主要支持兩大類消息事件,即集群事件和作業(yè)事件。

A) 開通消息服務(wù)

B) 創(chuàng)建 MNS 主題

C) 創(chuàng)建 MNS 主題訂閱

1. 授權(quán) BatchCompute 推送消息

請(qǐng)登錄控制臺(tái)上進(jìn)行一鍵授權(quán)。如果沒有授權(quán)過,控制臺(tái)會(huì)出現(xiàn)這個(gè)提示:授權(quán)如果已經(jīng)授權(quán),過請(qǐng)忽略。

2. 計(jì)費(fèi)相關(guān)

消息通知產(chǎn)生的費(fèi)用統(tǒng)一由 消息服務(wù)結(jié)算 ,批量計(jì)算不再額外收取。

3. 消息類型

A) 集群事件

使用 SDK 或控制臺(tái)創(chuàng)建集群(cluster)時(shí),可以配置如下類型消息事件。

{
    "Notification": {
        "Topic": {
            "Name": "test-topic",
            "Endpoint": "http://[UserId].mns.[Region].aliyuncs.com/", 
            "Events": [
                "OnClusterDeleted",
                "OnInstanceCreated",
                "OnInstanceActive"
            ]
        }
    }
}
字段 說明
Name MNS 主題名稱
Endpoint MNS 私網(wǎng) Endpoint,參考 如何獲取 Endpoint

B) 作業(yè)事件

使用 SDK 或控制臺(tái)創(chuàng)建作業(yè)(job)時(shí),可以配置如下類型消息事件。

{
    "Notification": {
        "Topic": {
            "Name": "test-topic",
            "Endpoint": "http://[UserId].mns.[Region].aliyuncs.com/",
            "Events": [
                "OnJobWaiting",
                "OnJobRunning",
                "OnJobStopped",
                "OnJobFinished",
                "OnJobFailed",
                "OnTaskWaiting",
                "OnTaskRunning",
                "OnTaskStopped",
                "OnTaskFinished",
                "OnTaskFailed",
                "OnInstanceWaiting",
                "OnInstanceRunning",
                "OnInstanceStopped",
                "OnInstanceFinished",
                "OnInstanceFailed",
                "OnPriorityChange"
            ]
        }
    }
}
字段 說明
Name MNS主題名稱
Endpoint MNS私網(wǎng)Endpoint,參考 如何獲取 Endpoint

4. 消息格式

消息格式目前支持 json string。

A) 集群事件

適用于 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"
}

B) 作業(yè)事件

適用于 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"
}