文档

获取实例列表

listInstances

参数

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

返回值

成功后返回一个 ListInstancesResponse 实例,可以通过这个实例的 getInstanceList() 方法,获取 List<Instance> 对象。 如果失败,抛出异常: ClientExceptionInstance 的属性信息参考API文档

例子

Java 源码

  1. import com.aliyuncs.batchcompute.main.v20151111.*;
  2. import com.aliyuncs.batchcompute.model.v20151111.*;
  3. import com.aliyuncs.batchcompute.pojo.v20151111.Instance;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import java.util.List;
  6. import java.util.ArrayList;
  7. public class ListInstancesDemo {
  8. static String ACCESS_KEY_ID = "xxx"; //这里填写您的 AccessKeyId
  9. static String ACCESS_KEY_SECRET = "xxx"; //这里填写您的 AccessKeySecret
  10. static String REGION_ID = "cn-xxx"; //这里填写 region
  11. static String jobId = "job-000000005BE3E897000007FA00114EE9";
  12. static String taskName = "javaSdkTask";
  13. static String marker = ""; //上次listJobs返回的nextMarker,第一次查询不用填。
  14. static int maxItemCount = 100; //最大100,默认50
  15. public static void main(String[] args) {
  16. BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
  17. try{
  18. List<Instance> list = new ArrayList<>();
  19. do{
  20. ListInstancesResponse response = client.listInstances(jobId, taskName, marker, maxItemCount);
  21. //成功
  22. list.addAll(response.getItems());
  23. //下一页的marker,查询下一页的时候,需要带上这个参数
  24. marker = response.getNextMarker();
  25. }while(marker!=null && !marker.equals(""));
  26. for (Instance ins: list){
  27. System.out.println("InstanceId: " + ins.getInstanceId());
  28. System.out.println("InstanceState: " + ins.getState());
  29. System.out.println("InstanceIP: " + ins.getNodeIp());
  30. }
  31. }catch(ClientException e){
  32. e.printStackTrace();
  33. //失败
  34. }
  35. }
  36. }

执行结果:

  1. {
  2. InstanceId: 0
  3. InstanceState: Stopped
  4. InstanceIP: 10.1.98.3
  5. }
  • 本页导读 (0)
文档反馈