更新时间:2026-09-10 GMT+08:00
分享

创建基线任务 - CreateFactoryBaseline

功能介绍

创建基线任务。

调用方法

请参见如何调用API。

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
  • 如果使用身份策略授权,当前API调用无需身份策略权限。

URI

POST /v2/{project_id}/factory/aiops/{instance_id}/baseline

表1 路径参数

参数

是否必选

参数类型

描述

project_id

是

String

项目ID,获取方法请参见项目ID和账号ID。

instance_id

是

String

DataArts Studio实例ID,获取方法请参见实例ID和工作空间ID。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

否

String

IAM Token,通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值),使用Token认证时必选,最小长度:0,最大长度:4096。

X-Project-Id

否

String

project_id,项目编号。获取方法请参见项目ID和账号ID。

多project场景采用AK/SK认证的接口请求,则该字段必选。

workspace

是

String

工作空间ID,获取方法请参见实例ID和工作空间ID。

Content-Type

是

String

默认值:application/json;charset=UTF-8

可选,有Body体的情况下必选,没有Body体则无需填写和校验。

表3 请求Body参数

参数

是否必选

参数类型

描述

workspace_id

是

String

工作空间ID,获取方法请参见实例ID和工作空间ID。

name

是

String

基线任务名称。只能包含:英文字母、数字、中文、中划线、下划线和点号,且长度不超过128位。

owner_name

是

String

责任人用户名称。

type

是

String

基线任务类型。取值为 DAY和HOUR。

sla_task_ids

是

Array of strings

保障作业ID列表,作业ID可通过查询作业详情接口获取。

priority

是

Integer

优先级,取值范围是1到5。

buffer

是

Integer

预警余量。单位毫秒,取值范围在0到86400000之间,且必须是整数分钟级别的毫秒。

enable

是

Boolean

是否生效,取值为true或者false。默认为true。

alarm_enable

是

Boolean

报警是否打开,取值为true或者false,默认为true。

sign_enable

是

Boolean

基线签署是否打开,取值为true或者false。默认为false。

sla_hour

是

String

天基线承诺小时。

sla_min

是

String

天基线承诺分钟。

baseline_alarm_enable

是

Boolean

基线报警是否打开,取值为true或者false。

smn_topics

否

Array of SmnTopicRequest objects

SMN主题列表。

event_smn_topics

否

Array of SmnTopicRequest objects

事件报警信息。

event_alarm

否

Array of strings

事件告警开启类型,取值为ERROR:出错,SLOW_DOWN:变慢。

period

否

Array of PeriodObject objects

当type取值为HOUR时,该值需要填写。

表4 SmnTopicRequest

参数

是否必选

参数类型

描述

name

否

String

主题名称。

urn

否

String

smn urn,可以在SMN服务查看对应主题的urn。

notify_method

是

String

告警方式:主题、责任人、值班表和钉钉机器人,取值如下:

  • SUBJECT: 主题

  • OWNER: 责任人

  • DUTY_SCHEDULE: 值班表

  • DINGDING: 钉钉机器人

protocol

否

String

告警协议:短信、邮件、电话,示例:["email"] "email":邮件传输协议,"sms":短信传输协议,"callnotify":语音, "dingding":个人钉钉。

other_persons

否

String

抄送人,示例:["lin","hua"]。

max_send_times

是

Integer

最大告警次数,取值为 [1, 50]。

send_interval

是

Integer

告警间隔,取值为[5, 60],单位:分钟。

duty_schedule_name

否

String

值班表名称。

smn_config_name

否

String

机器人名称。

enable_recovery

否

Boolean

是否开启恢复通知。开启后,当作业失败后重跑成功时发送恢复通知。

仅对remind_type=1(运行异常)的规则生效。删除主规则时会自动级联删除恢复子规则。

表5 PeriodObject

参数

是否必选

参数类型

描述

period_num

是

Integer

周期,取值为1到24。

period_time

是

String

小时:分钟,样例:00:59

响应参数

状态码:200

无

状态码:400

表6 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误描述。

请求示例

创建基线任务。

POST /v2/62099355b894428e8916573ae635f1f9/factory/aiops/65212faf-91e2-4914-a116-be71b1aaf49e/baseline

{
  "workspace_id" : "62fbba734e634c5087656fc3ff7adf34",
  "name" : "3333334457",
  "owner_name" : "test",
  "type" : "DAY",
  "sla_task_ids" : [ "935280" ],
  "priority" : 3,
  "buffer" : 3600000,
  "enable" : true,
  "alarm_enable" : true,
  "sign_enable" : false,
  "sla_hour" : "00",
  "sla_min" : "00",
  "baseline_alarm_enable" : true,
  "smn_topics" : [ {
    "name" : null,
    "urn" : null,
    "notify_method" : "DUTY_SCHEDULE",
    "protocol" : "[\"sms\",\"email\",\"callnotify\"]",
    "other_persons" : null,
    "max_send_times" : 1,
    "send_interval" : 60,
    "duty_schedule_name" : "444",
    "smn_config_name" : null
  } ],
  "event_alarm" : [ ]
}

响应示例

状态码:200

无

状态码:400

{
  "error_msg" : "The value of parameter [owner_name] does not exist, please check again its value.",
  "error_code" : "DLF.21203"
}

SDK代码示例

SDK代码示例如下。

创建基线任务。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.dataartsstudio.v1.region.DataArtsStudioRegion;
import com.huaweicloud.sdk.dataartsstudio.v1.*;
import com.huaweicloud.sdk.dataartsstudio.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateFactoryBaselineSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        DataArtsStudioClient client = DataArtsStudioClient.newBuilder()
                .withCredential(auth)
                .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateFactoryBaselineRequest request = new CreateFactoryBaselineRequest();
        request.withInstanceId("{instance_id}");
        CreateBaselineRequest body = new CreateBaselineRequest();
        List<SmnTopicRequest> listbodySmnTopics = new ArrayList<>();
        listbodySmnTopics.add(
            new SmnTopicRequest()
                .withNotifyMethod("DUTY_SCHEDULE")
                .withProtocol("["sms","email","callnotify"]")
                .withMaxSendTimes(1)
                .withSendInterval(60)
                .withDutyScheduleName("444")
        );
        List<String> listbodySlaTaskIds = new ArrayList<>();
        listbodySlaTaskIds.add("935280");
        body.withSmnTopics(listbodySmnTopics);
        body.withBaselineAlarmEnable(true);
        body.withSlaMin("00");
        body.withSlaHour("00");
        body.withSignEnable(false);
        body.withAlarmEnable(true);
        body.withEnable(true);
        body.withBuffer(3600000);
        body.withPriority(3);
        body.withSlaTaskIds(listbodySlaTaskIds);
        body.withType("DAY");
        body.withOwnerName("test");
        body.withName("3333334457");
        body.withWorkspaceId("62fbba734e634c5087656fc3ff7adf34");
        request.withBody(body);
        try {
            CreateFactoryBaselineResponse response = client.createFactoryBaseline(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

创建基线任务。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdataartsstudio.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = DataArtsStudioClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateFactoryBaselineRequest()
        request.instance_id = "{instance_id}"
        listSmnTopicsbody = [
            SmnTopicRequest(
                notify_method="DUTY_SCHEDULE",
                protocol="["sms","email","callnotify"]",
                max_send_times=1,
                send_interval=60,
                duty_schedule_name="444"
            )
        ]
        listSlaTaskIdsbody = [
            "935280"
        ]
        request.body = CreateBaselineRequest(
            smn_topics=listSmnTopicsbody,
            baseline_alarm_enable=True,
            sla_min="00",
            sla_hour="00",
            sign_enable=False,
            alarm_enable=True,
            enable=True,
            buffer=3600000,
            priority=3,
            sla_task_ids=listSlaTaskIdsbody,
            type="DAY",
            owner_name="test",
            name="3333334457",
            workspace_id="62fbba734e634c5087656fc3ff7adf34"
        )
        response = client.create_factory_baseline(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

创建基线任务。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        SafeBuild()

    if err != nil {
        fmt.Println(err)
        return
    }

    hcClient, err := dataartsstudio.DataArtsStudioClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


    if err != nil {
        fmt.Println(err)
        return
    }

    client := dataartsstudio.NewDataArtsStudioClient(hcClient)

    request := &model.CreateFactoryBaselineRequest{}
	request.InstanceId = "{instance_id}"
	protocolSmnTopics:= "["sms","email","callnotify"]"
	dutyScheduleNameSmnTopics:= "444"
	var listSmnTopicsbody = []model.SmnTopicRequest{
        {
            NotifyMethod: "DUTY_SCHEDULE",
            Protocol: &protocolSmnTopics,
            MaxSendTimes: int32(1),
            SendInterval: int32(60),
            DutyScheduleName: &dutyScheduleNameSmnTopics,
        },
    }
	var listSlaTaskIdsbody = []string{
        "935280",
    }
	request.Body = &model.CreateBaselineRequest{
		SmnTopics: &listSmnTopicsbody,
		BaselineAlarmEnable: true,
		SlaMin: "00",
		SlaHour: "00",
		SignEnable: false,
		AlarmEnable: true,
		Enable: true,
		Buffer: int32(3600000),
		Priority: int32(3),
		SlaTaskIds: listSlaTaskIdsbody,
		Type: "DAY",
		OwnerName: "test",
		Name: "3333334457",
		WorkspaceId: "62fbba734e634c5087656fc3ff7adf34",
	}
	response, err := client.CreateFactoryBaseline(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

成功,状态响应200。

400

失败,返回信息。

相关文档