全部产品

获取集群实例列表

接口

listClusterInstances

参数

参数 类型 是否必选 说明
clusterId String 集群ID.
groupName String 实例组名称.
marker String 本页起始资源标识符。默认为空字符串。
maxItemCount int 返回条数,最大取值200,默认200

返回值

成功后返回一个 ListClusterInstancesResponse 实例, 可以通过这个实例的 getClusterInstance 方法, 获取 ClusterInstance 对象。如果失败,抛出异常: ClientException

例子

Java 源码:

  1. import java.util.List;
  2. import com.aliyuncs.batchcompute.main.v20151111.*;
  3. import com.aliyuncs.batchcompute.model.v20151111.*;
  4. import com.aliyuncs.batchcompute.pojo.v20151111.*;
  5. import com.aliyuncs.exceptions.ClientException;
  6. public class ListClusterInstances {
  7. static String ACCESS_KEY_ID = "xxx"; //这里填写您的 AccessKeyId
  8. static String ACCESS_KEY_SECRET = "xxx"; //这里填写您的 AccessKeySecret
  9. static String REGION_ID = "cn-xxx"; //这里填写 region
  10. static String ClusterId = "cls-xxx";
  11. public static void main(String[] args) {
  12. BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
  13. try{
  14. String groupName = "group1";
  15. ListClusterInstancesResponse response = client.listClusterInstances(ClusterId, groupName);
  16. //成功
  17. List<ClusterInstance> list = response.getItems(); //集群实例列表
  18. String marker = response.getNextMarker();//下一个起始Marker
  19. for (int i = 0; i < list.size(); i++){
  20. ClusterInstance clsIns = list.get(i);
  21. System.out.println("{");
  22. System.out.println("\tId:" + clsIns.getId());
  23. System.out.println("\tIP:" + clsIns.getIpAddress());
  24. System.out.println("\tState:" + clsIns.getState());
  25. System.out.println("},");
  26. }
  27. }catch(ClientException e){
  28. e.printStackTrace();
  29. //失败
  30. }
  31. }
  32. }

执行结果:

  1. {
  2. Id:ins-6kivnjur5lnpkvo8276000
  3. IP:10.170.104.77
  4. State:Running
  5. }