更新时间:2025-09-19 GMT+08:00
分享

查询实例任务详情

功能介绍

用户可以调用此接口查询设备接入实例任务详情。

调用方法

请参见如何调用API

URI

GET /v5/iot/{project_id}/iotda-instances/{instance_id}/tasks/{task_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数说明:项目ID。获取方法请参见 获取项目ID

instance_id

String

参数说明:实例ID。

取值范围:长度不超过36,由小写字母[a-f]、数字、连接符(-)的组成。

task_id

String

参数说明:实例任务Id。

取值范围:长度不超过64,由小写字母[a-f]、数字、连接符(-)的组成。

请求参数

响应参数

状态码:200

表2 响应Body参数

参数

参数类型

描述

task_id

String

参数说明:实例任务Id。

取值范围:长度不超过64,由小写字母[a-f]、数字、连接符(-)的组成。

type

String

参数说明:实例任务类型。

取值范围

  • CREATE:创建实例任务

  • MODIFY:实例规格变更任务

  • DELETE:实例删除任务

  • FREEZE:实例冻结任务

  • UNFREEZE:实例解冻任务

  • UPDATE_ACCESS_CONFIG:修改实例接入信息任务

  • UPDATE_ALLOW_LISTS: 修改实例接入白名单任务

  • OPEN_SNAT:启用实例SNAT配置任务

status

String

参数说明:任务状态。

取值范围

  • PENDING:等待执行

  • RUNNING:执行中

  • SUCCESS:执行成功

  • FAILED:执行失败

status_detail

String

参数说明:任务状态描述。

create_time

String

参数说明:实例任务的创建时间。格式为:"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

start_time

String

参数说明:实例任务的开始时间。格式为:"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

end_time

String

参数说明:实例任务的结束时间。格式为:"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

target_config

TargetConfig object

实例规格变更时,实例的目标规格配置。

operate_window

OperateWindow object

实例维护时间窗,用户在变更实例规格时,可以指定在该时间窗内进行变更。

progress

Integer

参数说明:任务进度"

表3 TargetConfig

参数

参数类型

描述

flavor

Flavor object

参数说明:设备接入实例的规格参数。

charge_mode

String

参数说明:实例的付费方式。

取值范围

  • prePaid:包年/包月

  • postPaid:按需计费

表4 Flavor

参数

参数类型

描述

type

String

参数说明:待创建设备接入实例的规格名称。详情请参见产品规格说明中的规格编码。

size

Integer

参数说明:待创建设备接入标准版实例的单元数量。详情请参见产品规格说明。当instance_type是standard时,该参数必填。

表5 OperateWindow

参数

参数类型

描述

start_time

String

参数说明:变更时间窗开始时间,UTC时间,格式为:"HH:mm"

end_time

String

参数说明:变更时间窗结束时间,UTC时间,格式为:"HH:mm"

请求示例

查询实例任务详情。

GET https://{endpoint}/v5/iot/{project_id}/iotda-instances/{instance_id}/tasks/{task_id}

响应示例

状态码:200

OK

{
  "task_id" : "075f413d-a3bb-4243-974d-8eb9221c1234",
  "type" : "MODIFY",
  "status" : "PENDING",
  "create_time" : "2021-08-19T01:52:49.493Z",
  "start_time" : "2021-08-19T01:52:49.492Z",
  "end_time" : "2021-08-19T01:52:49.492Z",
  "target_config" : {
    "flavor" : {
      "type" : "iotda.standard.s2",
      "size" : 2
    }
  },
  "operate_window" : {
    "start_time" : "18:00",
    "end_time" : "22:00"
  },
  "progress" : 80
}

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
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.iotdm.v5.region.IoTDMRegion;
import com.huaweicloud.sdk.iotdm.v5.*;
import com.huaweicloud.sdk.iotdm.v5.model.*;


public class ShowInstanceTaskSolution {

    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);

        IoTDMClient client = IoTDMClient.newBuilder()
                .withCredential(auth)
                .withRegion(IoTDMRegion.valueOf("<YOUR REGION>"))
                .build();
        ShowInstanceTaskRequest request = new ShowInstanceTaskRequest();
        request.withInstanceId("{instance_id}");
        request.withTaskId("{task_id}");
        try {
            ShowInstanceTaskResponse response = client.showInstanceTask(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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkiotdm.v5.region.iotdm_region import IoTDMRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkiotdm.v5 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 = IoTDMClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(IoTDMRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ShowInstanceTaskRequest()
        request.instance_id = "{instance_id}"
        request.task_id = "{task_id}"
        response = client.show_instance_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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    iotdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/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 := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := iotdm.NewIoTDMClient(
        iotdm.IoTDMClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ShowInstanceTaskRequest{}
	request.InstanceId = "{instance_id}"
	request.TaskId = "{task_id}"
	response, err := client.ShowInstanceTask(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK

400

Bad Request

401

Unauthorized

403

Forbidden

错误码

请参见错误码

相关文档