新增调度任务 - AddOperationalTask
功能介绍
新增调度任务。
调用方法
请参见如何调用API。
授权信息
账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
- 如果使用身份策略授权,需具备如下身份策略权限。
URI
POST /v1/{project_id}/clusters/{cluster_id}/operational-tasks
请求参数
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| task_info | 否 | TaskInfo object | 参数解释: 任务信息。 约束限制: 不涉及。 取值范围: 非null。 默认取值: 不涉及。 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| task_name | 否 | String | 参数解释: 任务名称。 约束限制: 不涉及。 取值范围: 非null。 默认取值: 不涉及。 |
| description | 否 | String | 参数解释: 描述信息。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
| start_time | 否 | String | 参数解释: 开始时间。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
| end_time | 否 | String | 参数解释: 结束时间。 约束限制: 不涉及。 取值范围: 非null。 默认取值: 不涉及。 |
| white_list | 否 | Array of DateInfo objects | 参数解释: 执行计划。 约束限制: 不涉及。 取值范围: 非null。 默认取值: 不涉及。 |
| type | 否 | String | 参数解释: 任务类型。 约束限制: 不涉及。 取值范围: Date:单次型任务; Window:周期型任务; 默认取值: 不涉及。 |
| vacuum_mode | 否 | String | 参数解释: 任务模式。 约束限制: 不涉及。 取值范围: 非null。 默认取值: 不涉及。 |
| vacuum_target | 否 | String | 参数解释: 自动Vacuum目标。 约束限制: 不涉及。 取值范围: user_vacuumfull:用户表VacuumFull; system_vacuum:系统表VacuumFull; 默认取值: 不涉及。 |
| vacuum_threshold | 否 | String | 参数解释: 膨胀率,单位为百分比。 约束限制: 不涉及。 取值范围: 建议设置为当前集群空间使用率+10%,且最大不超过80%。 默认取值: 不涉及。 |
| vacuum_retrieving_space | 否 | String | 参数解释: 目标表可回收空间。 约束限制: 不涉及。 取值范围: 非null。 默认取值: 不涉及。 |
| vacuum_priority | 否 | String | 参数解释: 优先级。 约束限制: 不涉及。 取值范围: 非null。 默认取值: 不涉及。 |
| time_zone | 否 | String | 参数解释: 时区偏移信息。 约束限制: 不涉及。 取值范围: -2659~+2459 默认取值: 不涉及。 |
| priority | 否 | Array of TableInfoOpen objects | 参数解释: 优先级表信息。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
| category | 否 | String | 参数解释: 分类信息。 约束限制: 不涉及。 取值范围: 当前仅Vacuum一种值。 默认取值: Vacuum |
响应参数
状态码:200
请求成功。
无
请求示例
新增一个单次型任务。
post https://{Endpoint}/v1/169439ece752470aa5171633e9d3e47f/clusters/50aee999-9215-4dd0-a142-254ac6bf80e7/operational-tasks
{
"task_info" : {
"category" : "VacuumFull",
"task_name" : "test1",
"start_time" : 1767211200000,
"end_time" : 1767225600000,
"description" : "desc",
"type" : "Window",
"white_list" : [ {
"date_type" : "1th",
"date_start" : "04:00:00",
"date_end" : "08:00:00"
} ],
"vacuum_mode" : "manual",
"vacuum_target" : "",
"vacuum_priority" : [ {
"db_name" : "postgres",
"schema_name" : "public",
"table_name" : "a"
} ],
"vacuum_threshold" : "",
"vacuum_retrieving_space" : ""
}
} 响应示例
状态码:200
{ } 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 | 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.dws.v2.region.DwsRegion; import com.huaweicloud.sdk.dws.v2.*; import com.huaweicloud.sdk.dws.v2.model.*; import java.util.List; import java.util.ArrayList; public class AddOperationalTaskSolution { 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); DwsClient client = DwsClient.newBuilder() .withCredential(auth) .withRegion(DwsRegion.valueOf("<YOUR REGION>")) .build(); AddOperationalTaskRequest request = new AddOperationalTaskRequest(); request.withClusterId("{cluster_id}"); OperationalTaskRequest body = new OperationalTaskRequest(); List<DateInfo> listTaskInfoWhiteList = new ArrayList<>(); listTaskInfoWhiteList.add( new DateInfo() .withDateType("1th") .withDateStart("04:00:00") .withDateEnd("08:00:00") ); TaskInfo taskInfobody = new TaskInfo(); taskInfobody.withTaskName("test1") .withDescription("desc") .withStartTime("1767211200000") .withEndTime("1767225600000") .withWhiteList(listTaskInfoWhiteList) .withType("Window") .withVacuumMode("manual") .withVacuumTarget("") .withVacuumThreshold("") .withVacuumRetrievingSpace("") .withVacuumPriority("[{db_name=postgres, schema_name=public, table_name=a}]") .withCategory("VacuumFull"); body.withTaskInfo(taskInfobody); request.withBody(body); try { AddOperationalTaskResponse response = client.addOperationalTask(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 | # coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkdws.v2.region.dws_region import DwsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkdws.v2 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 = DwsClient.new_builder() \ .with_credentials(credentials) \ .with_region(DwsRegion.value_of("<YOUR REGION>")) \ .build() try: request = AddOperationalTaskRequest() request.cluster_id = "{cluster_id}" listWhiteListTaskInfo = [ DateInfo( date_type="1th", date_start="04:00:00", date_end="08:00:00" ) ] taskInfobody = TaskInfo( task_name="test1", description="desc", start_time="1767211200000", end_time="1767225600000", white_list=listWhiteListTaskInfo, type="Window", vacuum_mode="manual", vacuum_target="", vacuum_threshold="", vacuum_retrieving_space="", vacuum_priority="[{db_name=postgres, schema_name=public, table_name=a}]", category="VacuumFull" ) request.body = OperationalTaskRequest( task_info=taskInfobody ) response = client.add_operational_task(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 81 82 83 84 85 86 87 88 | package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" dws "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/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 := dws.DwsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). SafeBuild() if err != nil { fmt.Println(err) return } client := dws.NewDwsClient(hcClient) request := &model.AddOperationalTaskRequest{} request.ClusterId = "{cluster_id}" dateTypeWhiteList:= "1th" dateStartWhiteList:= "04:00:00" dateEndWhiteList:= "08:00:00" var listWhiteListTaskInfo = []model.DateInfo{ { DateType: &dateTypeWhiteList, DateStart: &dateStartWhiteList, DateEnd: &dateEndWhiteList, }, } taskNameTaskInfo:= "test1" descriptionTaskInfo:= "desc" startTimeTaskInfo:= "1767211200000" endTimeTaskInfo:= "1767225600000" typeTaskInfo:= "Window" vacuumModeTaskInfo:= "manual" vacuumTargetTaskInfo:= "" vacuumThresholdTaskInfo:= "" vacuumRetrievingSpaceTaskInfo:= "" vacuumPriorityTaskInfo:= "[{db_name=postgres, schema_name=public, table_name=a}]" categoryTaskInfo:= "VacuumFull" taskInfobody := &model.TaskInfo{ TaskName: &taskNameTaskInfo, Description: &descriptionTaskInfo, StartTime: &startTimeTaskInfo, EndTime: &endTimeTaskInfo, WhiteList: &listWhiteListTaskInfo, Type: &typeTaskInfo, VacuumMode: &vacuumModeTaskInfo, VacuumTarget: &vacuumTargetTaskInfo, VacuumThreshold: &vacuumThresholdTaskInfo, VacuumRetrievingSpace: &vacuumRetrievingSpaceTaskInfo, VacuumPriority: &vacuumPriorityTaskInfo, Category: &categoryTaskInfo, } request.Body = &model.OperationalTaskRequest{ TaskInfo: taskInfobody, } response, err := client.AddOperationalTask(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
| 状态码 | 描述 |
|---|---|
| 200 | 请求成功。 |
| 400 | 请求错误。 |
| 401 | 鉴权失败。 |
| 403 | 没有操作权限。 |
| 404 | 找不到资源。 |
| 500 | 服务内部错误。 |
| 503 | 服务不可用。 |