All Products
Search
Document Center

Batch Compute:Notification

Last Updated:Dec 18, 2023

Batch Compute service sends notification messages based on the topics offered by MNS. You can create, manage, and subscribe to topics, and specify topic configuration when using Batch Compute to create a cluster or submit a job. Batch Compute then pushes messages to the specified topics based on the configuration. You can set four notification methods in the MNS console: URL, MNS queue, email, and SMS. Currently, Batch Compute supports two types of message events: cluster events and job events.

  1. Activate the message service

  2. Create an MNS topic

  3. Create an MNS topic subscription

  4. Authorize Batch Compute message push.

  5. Log on to the console to complete one-key authorization. If you have not completed the authorization, the console displays the following message:

Console

Skip this step if you have completed the authorization.

2. Billing

The message service fee is settled by the message service, and no extra fee is charged for Batch Compute service.

3. Message types

3.1 Cluster events

When using the SDK or console to create a cluster, you can configure the following type of message events.

{
    "Notification": {
        "Topic": {
            "Name": "test-topic",
            "Endpoint": "http://[UserId].mns.[Region].aliyuncs.com/", 
            "Events": [
                "OnClusterDeleted",
                "OnInstanceCreated",
                "OnInstanceActive"
            ]
        }
    }
}

Field

Description

Name

Name of an MNS topic.

Endpoint

MNS intranet endpoint.

3.2 Job events

When using the SDK or console to create a job, you can configure the following type of message events.

{
    "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"
            ]
        }
    }
}

Field

Description

Name

Name of an MNS topic

Endpoint

MNS intranet endpoint.

4. Message format

Currently, messages are sent in JSON string format.

4.1 Cluster events

Message for an OnClusterDeleted event.

 {
    "Category": "Cluster",
    "ClusterId": "cls-hr2rbl6qt5gki7392b8001",
    "ClusterName": "test-cluster",
    "CreationTime": "2016-11-01T15:25:02.837728Z",
    "State": "Deleted",
    "Event": "OnClusterDeleted"
}

Message for an OnInstanceCreated or OnInstanceActive event.

{
    "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"
}

4.2 Job events

Message for an OnJobWaiting, OnJobRunning, OnJobStopped, OnJobFinished, or OnJobFailed event.

{
    "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": ""
}

Message for an OnTaskWaiting, OnTaskRunning, OnTaskStopped,OnTaskFinished, or OnTaskFailed event

{
    "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"
}

Message for an OnInstanceWaiting, OnInstanceRunning, or OnInstanceStopped eventOnInstanceFinished/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": ""
}

Message for an OnPriorityChange event.

{
    "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"
}