Baidu AI Cloud
中国站

百度智能云

MapReduce

Instance

Query Instance Lists

The following code is used to query the instance of the specified cluster and instance group:

public void listInstances(BmrClient client, String clusterId, String instanceGroupId) {
    try {
        ListInstancesResponse response = client.listInstances(clusterId, instanceGroupId);
        for (Instance instance : response.getIntances()) {
            System.out.println(instance.getId() + "," + instance.getPrivateIpAddress()
                    + "," + instance.getPublicIpAddress());
        }
    } catch (BceServiceException e) {
        System.out.println("List instance failed: " + e.getErrorMessage());
    }
}

The ListInstancesResponse object returned under request contains the instance object array List, and the instance object array is obtained via response.getInstances(). The properties of instance object (i.e., Instance) include private IP, public IP, and other configuration information, and every property has its getter accessor method.

public class Instance {
    private String id;
    private String privateIpAddress;
    private String publicIpAddress;
}
Previous
Install SDK Kit
Next
InstanceGroup