获取实例信息

接口

getInstance

参数

参数 类型 是否必选 说明
jobId String 作业ID
taskName String 任务名称
instanceId int 实例ID

返回值

成功后返回一个 GetInstanceResponse 实例, 可以通过这个实例的 getInstance() 方法,获取 Instance 对象;Instance的具体属性信息参考API文档。如果失败,抛出异常: ClientException

例子

Java 源码

  1. import com.aliyuncs.batchcompute.main.v20151111.*;
  2. import com.aliyuncs.batchcompute.model.v20151111.*;
  3. import com.aliyuncs.batchcompute.pojo.v20151111.*;
  4. import com.aliyuncs.exceptions.ClientException;
  5. public class GetInstance {
  6. static String ACCESS_KEY_ID = "xxx"; //这里填写您的 AccessKeyId
  7. static String ACCESS_KEY_SECRET = "xxx"; //这里填写您的 AccessKeySecret
  8. static String REGION_ID = "cn-xxx"; //这里填写 region
  9. static String jobId = "job-000000005BE3E897000007FA00114EE9";
  10. static String taskName = "javaSdkTask";
  11. static int instanceId = 0;
  12. public static void main(String[] args) {
  13. BatchCompute client = new BatchComputeClient(REGION_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
  14. try{
  15. GetInstanceResponse response = client.getInstance(jobId,taskName, instanceId);
  16. //成功
  17. Instance ins = response.getInstance();
  18. System.out.println("InstanceId: " + ins.getInstanceId());
  19. System.out.println("InstanceState: " + ins.getState());
  20. System.out.println("InstanceIP: " + ins.getNodeIp());
  21. }catch(ClientException e){
  22. e.printStackTrace();
  23. //失败
  24. }
  25. }
  26. }

执行结果:

  1. {
  2. InstanceId: 0
  3. InstanceState: Stopped
  4. InstanceIP: 10.1.98.3
  5. }