# 修改调度任务 - UpdateOperationalTask
#### 功能介绍
修改调度任务。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-dws/dws_02_0062.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-dws/dws_02_0056.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项                               | 访问级别  | 资源类型（\*为必须） | 条件键                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | 别名                          | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | dws:cluster:updateOperationalTask | Write | cluster \*  | - g:ResourceTag/\<tag-key\>   - g:EnterpriseProjectId    | dws:operationalTask:operate | -      |
     
  
 
#### URI
POST /v1/{project_id}/cluster/{cluster_id}/operational-tasks/{task_id}
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|:---|:---|:---|:---|
| project_id | 是    | String | **参数解释**： 项目ID。获取方法请参见[获取项目ID](https://support.huaweicloud.com/api-dws/dws_02_0011.html)。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。  |
| cluster_id | 是    | String | **参数解释**： 集群ID。获取方法请参见[获取集群ID](https://support.huaweicloud.com/api-dws/dws_02_00068.html)。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。 |
| task_id    | 是    | String | **参数解释**： 任务ID，可先通过任务列表接口查询所有任务。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。                                                           |
   
#### 请求参数
表2请求Body参数 
| 参数                      | 是否必选 | 参数类型                                                                                                                | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
|:---|:---|:---|:---|
| 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                                                                                                                                |
   
 表3DateInfo 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
|:---|:---|:---|:---|
| date_type  | 否    | String | **参数解释**： 日期类型，如每月1号执行则为1th。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。 |
| date_start | 否    | String | **参数解释**： 开始时间，如：04:00:00。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。   |
| date_end   | 否    | String | **参数解释**： 结束时间，如：08:00:00。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。   |
   
 表4TableInfoOpen 
| 参数            | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|:---|:---|:---|:---|
| database_name | 否    | String | **参数解释**： 数据库名。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。 |
| schema_name   | 否    | String | **参数解释**： 模式名。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。  |
| table_name    | 否    | String | **参数解释**： 表名。 **约束限制**： 不涉及。 **取值范围**： 不涉及。 **默认取值**： 不涉及。   |
   
#### 响应参数
**状态码：200**
请求成功。
无
#### 请求示例
修改配置。
```
post https://{Endpoint}/v1/169439ece752470aa5171633e9d3e47f/clusters/50aee999-9215-4dd0-a142-254ac6bf80e7/operational-tasks/rc32293bc4df4449984fb5314b490cc4
{
  "category" : "VacuumFull",
  "description" : "desc",
  "type" : "Window",
  "task_name" : "test1",
  "start_time" : "2025-12-31T20:00:00Z",
  "end_time" : "2026-01-01T00:00:00Z",
  "white_list" : [ {
    "date_type" : "31th",
    "date_start" : "20:00:00",
    "date_end" : "23:59:59"
  }, {
    "date_type" : "1th",
    "date_start" : "00:00:00",
    "date_end" : "00:00:00"
  } ],
  "vacuum_mode" : "manual",
  "vacuum_target" : "",
  "vacuum_threshold" : "",
  "vacuum_retrieving_space" : "",
  "priority" : [ {
    "database_name" : null,
    "schema_name" : "public",
    "table_name" : "a"
  } ],
  "time_zone" : null
}
```
#### 响应示例
**状态码：200**
```
{ }
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  修改配置。
  ```
  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 UpdateOperationalTaskSolution {
      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();
          UpdateOperationalTaskRequest request = new UpdateOperationalTaskRequest();
          request.withClusterId("{cluster_id}");
          request.withTaskId("{task_id}");
          TaskInfo body = new TaskInfo();
          List<TableInfoOpen> listbodyPriority = new ArrayList<>();
          listbodyPriority.add(
              new TableInfoOpen()
                  .withSchemaName("public")
                  .withTableName("a")
          );
          List<DateInfo> listbodyWhiteList = new ArrayList<>();
          listbodyWhiteList.add(
              new DateInfo()
                  .withDateType("31th")
                  .withDateStart("20:00:00")
                  .withDateEnd("23:59:59")
          );
          listbodyWhiteList.add(
              new DateInfo()
                  .withDateType("1th")
                  .withDateStart("00:00:00")
                  .withDateEnd("00:00:00")
          );
          body.withCategory("VacuumFull");
          body.withPriority(listbodyPriority);
          body.withVacuumRetrievingSpace("");
          body.withVacuumThreshold("");
          body.withVacuumTarget("");
          body.withVacuumMode("manual");
          body.withType("Window");
          body.withWhiteList(listbodyWhiteList);
          body.withEndTime("2026-01-01T00:00:00Z");
          body.withStartTime("2025-12-31T20:00:00Z");
          body.withDescription("desc");
          body.withTaskName("test1");
          request.withBody(body);
          try {
              UpdateOperationalTaskResponse response = client.updateOperationalTask(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());
          }
      }
  }
  ```
- [Python]
  修改配置。
  ```
  # 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 = UpdateOperationalTaskRequest()
          request.cluster_id = "{cluster_id}"
          request.task_id = "{task_id}"
          listPrioritybody = [
              TableInfoOpen(
                  schema_name="public",
                  table_name="a"
              )
          ]
          listWhiteListbody = [
              DateInfo(
                  date_type="31th",
                  date_start="20:00:00",
                  date_end="23:59:59"
              ),
              DateInfo(
                  date_type="1th",
                  date_start="00:00:00",
                  date_end="00:00:00"
              )
          ]
          request.body = TaskInfo(
              category="VacuumFull",
              priority=listPrioritybody,
              vacuum_retrieving_space="",
              vacuum_threshold="",
              vacuum_target="",
              vacuum_mode="manual",
              type="Window",
              white_list=listWhiteListbody,
              end_time="2026-01-01T00:00:00Z",
              start_time="2025-12-31T20:00:00Z",
              description="desc",
              task_name="test1"
          )
          response = client.update_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)
  ```
- [Go]
  修改配置。
  ```
  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.UpdateOperationalTaskRequest{}
  request.ClusterId = "{cluster_id}"
  request.TaskId = "{task_id}"
  schemaNamePriority:= "public"
  tableNamePriority:= "a"
  var listPrioritybody = []model.TableInfoOpen{
          {
              SchemaName: &schemaNamePriority,
              TableName: &tableNamePriority,
          },
      }
  dateTypeWhiteList:= "31th"
  dateStartWhiteList:= "20:00:00"
  dateEndWhiteList:= "23:59:59"
  dateTypeWhiteList1:= "1th"
  dateStartWhiteList1:= "00:00:00"
  dateEndWhiteList1:= "00:00:00"
  var listWhiteListbody = []model.DateInfo{
          {
              DateType: &dateTypeWhiteList,
              DateStart: &dateStartWhiteList,
              DateEnd: &dateEndWhiteList,
          },
          {
              DateType: &dateTypeWhiteList1,
              DateStart: &dateStartWhiteList1,
              DateEnd: &dateEndWhiteList1,
          },
      }
  categoryTaskInfo:= "VacuumFull"
  vacuumRetrievingSpaceTaskInfo:= ""
  vacuumThresholdTaskInfo:= ""
  vacuumTargetTaskInfo:= ""
  vacuumModeTaskInfo:= "manual"
  typeTaskInfo:= "Window"
  endTimeTaskInfo:= "2026-01-01T00:00:00Z"
  startTimeTaskInfo:= "2025-12-31T20:00:00Z"
  descriptionTaskInfo:= "desc"
  taskNameTaskInfo:= "test1"
  request.Body = &model.TaskInfo{
  Category: &categoryTaskInfo,
  Priority: &listPrioritybody,
  VacuumRetrievingSpace: &vacuumRetrievingSpaceTaskInfo,
  VacuumThreshold: &vacuumThresholdTaskInfo,
  VacuumTarget: &vacuumTargetTaskInfo,
  VacuumMode: &vacuumModeTaskInfo,
  Type: &typeTaskInfo,
  WhiteList: &listWhiteListbody,
  EndTime: &endTimeTaskInfo,
  StartTime: &startTimeTaskInfo,
  Description: &descriptionTaskInfo,
  TaskName: &taskNameTaskInfo,
  }
  response, err := client.UpdateOperationalTask(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/DWS/sdk?api=UpdateOperationalTask)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述      |
|:---|:---|
| 200 | 请求成功。   |
| 400 | 请求错误。   |
| 401 | 鉴权失败。   |
| 403 | 没有操作权限。 |
| 404 | 找不到资源。  |
| 500 | 服务内部错误。 |
| 503 | 服务不可用。  |
   
