Help Center> Cloud Stream Service> SDK Reference> Getting Started with SDK (Java)> Cluster Management> Querying the List of Jobs Running in an Exclusive Cluster

Querying the List of Jobs Running in an Exclusive Cluster

Sample Code

You can use the API to query the list of jobs running in an exclusive cluster. Sample code is as follows: In this example, the query results are displayed in descending order and information about the jobs whose IDs are less than the value of cursor is displayed. Sample code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Import classes:
import com.huaweicloud.cs.java.v1.client.ApiException;
import com.huaweicloud.cs.java.v1.ClusterApi;


ClusterApi apiInstance = new ClusterApi(apiClient);//apiClient is created when initializing a CS API client.
String xProjectId = "xProjectId_example"; // String | Project ID used for obtaining the token for the project.
Integer clusterId = 56; // Integer | ID of an exclusive cluster.
String name = "name_example"; // String | Job name.
String status = "status_example"; // String | Job status code. For details, see CS documentation.
Boolean showDetail = false; // Boolean | Whether to return job details.
Long cursor = 789L; // Long | Job ID.
Boolean next = true; // Boolean | Whether to turn to the previous or next page.
Integer limit = 20; // Integer | Number of returned data records.
String order = "desc"; // String | Query result display. The query results can be displayed in ascending or descending order.
try {
    QueryJobListResponse result = apiInstance.getClusterJobs(xProjectId, clusterId, name, status, showDetail, cursor, next, limit, order);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling ClusterApi#getClusterJobs");
    System.err.println(e.getResponseBody());
    e.printStackTrace();
}

Parameter Description

Table 1 Parameters

Parameter

Mandatory

Type

Description

xProjectId

Yes

String

Project ID. This parameter is used to obtain the token for the project.

clusterId

Yes

Integer

ID of an exclusive cluster.

name

No

String

Job name.

status

No

String

Job status code. Possible values are:

  • job_init
  • job_submitting
  • job_submit_fail
  • job_running
  • job_running_exception
  • job_canceling
  • job_cancel_success
  • job_cancel_fail

showDetail

No

Boolean

Whether to return the job details. The default value is false.

cursor

No

Long

Job ID.

next

No

Boolean

Whether to switch to the next page. The default value is true.

limit

No

Integer

Number of returned data records. The default value is 20.

order

No

String

Query result display. Value asc indicates that the query results are displayed in ascending order, and value desc indicates that the query results are displayed in descending order. The default value is desc.

Table 2 Parameters involved in QueryJobListResponse

Parameter

Mandatory

Type

Description

messageId

No

String

Message type ID.

message

No

String

Message content.

currentTime

No

Long

Current time, expressed by milliseconds.

payload

No

QueryJobListResponsePayload

For details about parameter types, see Table 3.

Table 3 Parameters involved in QueryJobListResponsePayload

Parameter

Mandatory

Type

Description

total

No

Integer

Number of records in the query result.

jobs

No

Array

For details about parameter types, see Table 4.

Table 4 Parameters involved in JobEntity

Parameter

Mandatory

Type

Description

jobId

No

Long

Job ID.

name

No

String

Job name.

desc

No

String

Job description.

username

No

String

Username. This parameter is used only when show_detail is set to false.

jobType

No

String

Job type.

status

No

String

Job status.

statusDesc

No

String

Description of job status.

createTime

No

Long

Time when a job is created.

startTime

No

Long

Time when a job is enabled. 0 indicates that the job has not been enabled.

duration

No

Long

Job running duration, expressed by milliseconds. This parameter is used only when show_detail is set to false.

userId

No

String

ID of the user who creates the job. This parameter is used only when show_detail is set to true.

clusterId

No

Integer

Resource ID of an exclusive cluster. Ensure that the current user has been authorized to use resources of the exclusive cluster. This parameter is used only when show_detail is set to true.

projectId

No

String

ID of the project to which a job belongs. This parameter is used only when show_detail is set to true.

sqlBody

No

String

Stream SQL statement. This parameter is used only when show_detail is set to true.

runMode

No

RunModeEnum

Job running mode. This parameter is used only when show_detail is set to true.

  • shared_cluster: A job is running on a shared cluster.
  • exclusive_cluster: A job is running on an exclusive cluster.
  • edge_node: A job is running on an edge node.

jobConfig

No

JobConfig

For details about the parameter, see Table 5.

jarUrl

No

String

OBS path of the JAR package. This parameter is used only when show_detail is set to true.

mainClass

No

String

OBS path where users are authorized to save the snapshot when checkpoint_enabled is set to true. This parameter is used only when show_detail is set to true.

args

No

String

Job running parameter of the JAR package. This parameter is used only when show_detail is set to true.

executionGraph

No

String

Job execution plan. This parameter is used only when show_detail is set to true.

updateTime

No

Long

Job update time. This parameter is used only when show_detail is set to true.

Table 5 Parameters involved in JobConfig

Parameter

Mandatory

Type

Description

checkpointEnabled

No

Boolean

Whether to enable the automatic job snapshot function. The default value is false.

  • true: The automatic job snapshot function is enabled.
  • false: The automatic job snapshot function is disabled.

checkpointMode

No

String

Snapshot mode. The following two options are available: exactly_once and at_least_once.

checkpointInterval

No

Integer

Snapshot interval, expressed by seconds.

logEnabled

No

Boolean

Whether to enable the log storage function.

obsBucket

No

String

Name of an OBS bucket.

smnTopic

No

String

SMN topic name.

rootId

No

Integer

Parent job ID.

edgeGroupIds

No

String

List of edge computing group IDs that are separated by commas (,).

managerSpu

No

Integer

Number of SPUs of the management unit.

spuNumber

No

Integer

Number of SPUs selected by a user for a job. This parameter is used only when show_detail is set to true.

parallelNumber

No

Integer

Number of parallel jobs set by a user. This parameter is unique when show_detail is set to true.