Authored by qinchao

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

... ... @@ -3,6 +3,7 @@ package com.yoho.ops.cmdb.aws.ec2;
import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
import com.amazonaws.services.ec2.model.DescribeInstancesResult;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.services.ec2.model.Tag;
import com.yoho.ops.cmdb.aws.AwsClientFactory;
import com.yoho.ops.cmdb.models.DataCenter;
import com.yoho.ops.cmdb.models.Host;
... ... @@ -13,6 +14,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Stream;
/**
* Aws EC2 信息查询
... ... @@ -47,7 +49,15 @@ public class AwsEc2Fetcher {
}
private String getName(Instance instance){
return instance.getTags().stream().filter(tag ->tag.getKey().equals("Name")).findFirst().get().getValue();
String name="";
List<Tag> tags=instance.getTags();
if(tags!=null&&tags.size()>0){
Stream<Tag> streams= tags.stream().filter(tag -> tag.getKey().equals("Name"));
if(streams!=null){
name= streams.findFirst().get().getValue();
}
}
return name;
}
}
... ...