全部产品
云市场

获取集群列表

更新时间:2018-11-18 12:15:43

接口

接口名称:listClusters

参数

参数 类型 是否必选 说明
marker String 本页起始资源标识符。默认为空字符串。
maxItemCount int 返回条数,最大取值200,默认200

返回值

list_clusters方法返回一个 ListResponse 对象。返回样式如下:

  1. {
  2. "Date": "Wed, 07 Nov 2018 10:20:48 GMT",
  3. "Items": [
  4. ],
  5. "NextMarker": "cls-6ki3sg6sqlno7nt8fu000m",
  6. "RequestId": "ACBB5876-888B-4336-AA72-BD532FE0F0F0",
  7. "StatusCode": 200
  8. }

篇幅有限,我们已把 Items 内容省去。

例子

下面例子遍历出所有的集群,并把集群 ID 和 状态打印出来,并统计出总共的数量。

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 ListClusters {
  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. public static void main(String[] args) {
  11. BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
  12. try{
  13. ListClustersResponse response = client.listClusters();
  14. //成功
  15. List<Cluster> list = response.getItems();
  16. for (int i = 0; i < list.size(); i++){
  17. Cluster clster = list.get(i);
  18. String state = clster.getState();
  19. String name = clster.getName();
  20. System.out.println("{");
  21. System.out.println("\tId:" + clster.getId());
  22. System.out.println("\tName:" + name);
  23. System.out.println("\tState:" + state);
  24. System.out.println("},");
  25. }
  26. }catch(ClientException e){
  27. e.printStackTrace();
  28. //失败
  29. }
  30. }
  31. }

执行结果

  1. [
  2. {
  3. Id:cls-6ki3npokblk1091cbko00f
  4. Name:test-centos-vpc
  5. State:Deleting
  6. },
  7. {
  8. Id:cls-6ki3npokblk1091cbko00i
  9. Name:test-ubuntu-vpc
  10. State:Deleting
  11. },
  12. {
  13. Id:cls-6ki3npokblk1091cbko00k
  14. Name:test-windows-vpc
  15. State:Deleting
  16. },
  17. {
  18. Id:cls-6kie8e833lnov8gg50k00j
  19. Name:cluster_test
  20. State:Active
  21. },
  22. {
  23. Id:cls-6kildmf3sllvkra43i2007
  24. Name:Cluster_Test
  25. State:Active
  26. }
  27. ]