Querying Snapshot Tasks

Notes

  • You can query snapshot tasks by task ID, task status, time range, page number, or compound query.
  • In the query results, if the page number and maximum number of displayed records are not specified, but the number of records is greater than 10, 10 records are displayed by default on each page.

Query by Task ID

1
2
3
4
5
6
7
// A maximum of 10 task IDs are supported.
queryThumbTaskRequest.setTaskId(new String[]{"1234","2345","3456"});

// Send a request to MPC.
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// Return a message.
System.out.println(new Gson().toJson(queryThumbTaskResponse));

Query by Page Number

1
2
3
4
5
6
7
// Set the page number and number of records on each page.
queryThumbTaskRequest.setPage(1);
queryThumbTaskRequest.setSize(10);
// Send a request to MPC.
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// Return a message.
System.out.println(new Gson().toJson(queryThumbTaskResponse));

Query by Time Range

1
2
3
4
5
6
7
// Set the start time and end time.
queryThumbTaskRequest.setStartTime("20180520131400");
queryThumbTaskRequest.setEndTime("20180520141300");
// Send a request to MPC.
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// Return a message.
System.out.println(new Gson().toJson(queryThumbTaskResponse));

Query by Task Status

1
2
3
4
5
6
// Set the task status.
// queryThumbTaskRequest.setStatus(QueryThumbTaskRequest.STATUS_SUCCEEDED);
// Send a request to MPC.
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// Return a message.
System.out.println(new Gson().toJson(queryThumbTaskResponse));

Compound Query

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// Set the following parameters:
queryThumbTaskRequest.setPage(1);
queryThumbTaskRequest.setSize(10);
queryThumbTaskRequest.setStartTime("20180520131400");
queryThumbTaskRequest.setEndTime("20180520141300");
queryThumbTaskRequest.setStatus(QueryThumbTaskRequest.STATUS_SUCCEEDED);
// Send a request to MPC.
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// Return a message.
System.out.println(new Gson().toJson(queryThumbTaskResponse));

Full Code

 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
import com.google.gson.Gson;
import com.huawei.mpc.client.ClientConfig;
import com.huawei.mpc.client.MpcClient;
import com.huawei.mpc.client.MpcConfig;
import com.huawei.mpc.model.thumbnail.QueryThumbTaskRequest;
import com.huawei.mpc.model.thumbnail.QueryThumbTaskResponse;
// Set the method for constructing MPC configuration items.
MpcConfig mpcConfig = new MpcConfig();

// Mandatory. Set the endpoint of MPC. For details, see section "Obtaining Key Parameters."
mpcConfig.setEndPoint(endPoint);
// Mandatory. Set the user's project ID. For details, see section "Obtaining Key Parameters."
mpcConfig.setProjectId(projectId);

// Mandatory. Set the SK. For details, see section "Obtaining Key Parameters."
mpcConfig.setSk(sk);

// Mandatory. Set the AK. For details, see section "Obtaining Key Parameters."
mpcConfig.setAk(ak);
       
/*if you need proxy*/
// Optional. Set the proxy if necessary.
/*
ClientConfig clientConfig = new ClientConfig();
// Set the IP address of the proxy server.
clientConfig.setProxyHost(proxyHost);
// Set the port number of the proxy server.
clientConfig.setProxyPort(Integer.parseInt(proxyPort));
// Set the username for accessing the proxy server.
clientConfig.setProxyUserName(proxyUserName);
// Set the password for accessing the proxy server.
clientConfig.setProxyPassword(proxyPassword);
*/

// MPC construction method
MpcClient mpcClient = new MpcClient(mpcConfig);

// Set request parameters.
QueryThumbTaskRequest queryThumbTaskRequest = new QueryThumbTaskRequest();

// 1. Query by task ID. A maximum of 10 task IDs are supported.
queryThumbTaskRequest.setTaskId(new String[]{"1234","2345","3456"});

// 2. Query by page number
// queryThumbTaskRequest.setPage(1);
// queryThumbTaskRequest.setSize(10);

// 3. Query by time range
// queryThumbTaskRequest.setStartTime("20180520131400");
// queryThumbTaskRequest.setEndTime("20180520141300");

// 4. Query by task status
// queryThumbTaskRequest.setStatus(QueryThumbTaskRequest.STATUS_SUCCEEDED);

// 5. Compound query
// queryThumbTaskRequest.setPage(1);
// queryThumbTaskRequest.setSize(10);
// queryThumbTaskRequest.setStartTime("20180520131400");
// queryThumbTaskRequest.setEndTime("20180520141300");
// queryThumbTaskRequest.setStatus(QueryThumbTaskRequest.STATUS_SUCCEEDED);

// Send a request to MPC.
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// Return a message.
System.out.println(new Gson().toJson(queryThumbTaskResponse));