Authored by qinchao

aws伸缩组获取:刚自动伸缩之后,伸缩组没有name信息

@@ -3,6 +3,7 @@ package com.yoho.ops.cmdb.aws.ec2; @@ -3,6 +3,7 @@ package com.yoho.ops.cmdb.aws.ec2;
3 import com.amazonaws.services.ec2.model.DescribeInstancesRequest; 3 import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
4 import com.amazonaws.services.ec2.model.DescribeInstancesResult; 4 import com.amazonaws.services.ec2.model.DescribeInstancesResult;
5 import com.amazonaws.services.ec2.model.Instance; 5 import com.amazonaws.services.ec2.model.Instance;
  6 +import com.amazonaws.services.ec2.model.Tag;
6 import com.yoho.ops.cmdb.aws.AwsClientFactory; 7 import com.yoho.ops.cmdb.aws.AwsClientFactory;
7 import com.yoho.ops.cmdb.models.DataCenter; 8 import com.yoho.ops.cmdb.models.DataCenter;
8 import com.yoho.ops.cmdb.models.Host; 9 import com.yoho.ops.cmdb.models.Host;
@@ -13,6 +14,7 @@ import java.util.LinkedList; @@ -13,6 +14,7 @@ import java.util.LinkedList;
13 import java.util.List; 14 import java.util.List;
14 import java.util.concurrent.ConcurrentHashMap; 15 import java.util.concurrent.ConcurrentHashMap;
15 import java.util.concurrent.ConcurrentMap; 16 import java.util.concurrent.ConcurrentMap;
  17 +import java.util.stream.Stream;
16 18
17 /** 19 /**
18 * Aws EC2 信息查询 20 * Aws EC2 信息查询
@@ -47,7 +49,15 @@ public class AwsEc2Fetcher { @@ -47,7 +49,15 @@ public class AwsEc2Fetcher {
47 } 49 }
48 50
49 private String getName(Instance instance){ 51 private String getName(Instance instance){
50 - return instance.getTags().stream().filter(tag ->tag.getKey().equals("Name")).findFirst().get().getValue(); 52 + String name="";
  53 + List<Tag> tags=instance.getTags();
  54 + if(tags!=null&&tags.size()>0){
  55 + Stream<Tag> streams= tags.stream().filter(tag -> tag.getKey().equals("Name"));
  56 + if(streams!=null){
  57 + name= streams.findFirst().get().getValue();
  58 + }
  59 + }
  60 + return name;
51 } 61 }
52 62
53 } 63 }