Search in sources :

Example 1 with Instance

use of com.amazonaws.services.elasticloadbalancing.model.Instance in project ignite by apache.

the class TcpDiscoveryElbIpFinder method getRegisteredAddresses.

/**
 * {@inheritDoc}
 */
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
    initClients();
    List<String> instanceIds = new ArrayList<>();
    DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest().withLoadBalancerNames(loadBalancerName);
    List<LoadBalancerDescription> descs = amazonELBClient.describeLoadBalancers(req).getLoadBalancerDescriptions();
    for (LoadBalancerDescription desc : descs) {
        for (Instance instance : desc.getInstances()) instanceIds.add(instance.getInstanceId());
    }
    DescribeInstancesRequest instReq = new DescribeInstancesRequest().withInstanceIds(instanceIds);
    List<Reservation> reservations = amazonEC2Client.describeInstances(instReq).getReservations();
    List<InetSocketAddress> addrs = new ArrayList<>();
    for (Reservation reservation : reservations) {
        List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances();
        for (com.amazonaws.services.ec2.model.Instance instance : instances) addrs.add(new InetSocketAddress(instance.getPrivateIpAddress(), 0));
    }
    return addrs;
}
Also used : Instance(com.amazonaws.services.elasticloadbalancing.model.Instance) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) Reservation(com.amazonaws.services.ec2.model.Reservation) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)

Example 2 with Instance

use of com.amazonaws.services.elasticloadbalancing.model.Instance in project SimianArmy by Netflix.

the class TestELBJanitorCrawler method mkELB.

private LoadBalancerDescription mkELB(String elbName, boolean includeInstances) {
    LoadBalancerDescription elb = new LoadBalancerDescription().withLoadBalancerName(elbName);
    if (includeInstances) {
        List<Instance> instances = new LinkedList<>();
        Instance i1 = new Instance().withInstanceId("i-000001");
        Instance i2 = new Instance().withInstanceId("i-000002");
        elb.setInstances(instances);
    }
    return elb;
}
Also used : Instance(com.amazonaws.services.elasticloadbalancing.model.Instance) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) LinkedList(java.util.LinkedList)

Example 3 with Instance

use of com.amazonaws.services.elasticloadbalancing.model.Instance in project SimianArmy by Netflix.

the class ELBJanitorCrawler method getELBResources.

private List<Resource> getELBResources(String... elbNames) {
    List<Resource> resources = new LinkedList<Resource>();
    AWSClient awsClient = getAWSClient();
    for (LoadBalancerDescription elb : awsClient.describeElasticLoadBalancers(elbNames)) {
        Resource resource = new AWSResource().withId(elb.getLoadBalancerName()).withRegion(getAWSClient().region()).withResourceType(AWSResourceType.ELB).withLaunchTime(elb.getCreatedTime());
        resource.setOwnerEmail(getOwnerEmailForResource(resource));
        resources.add(resource);
        List<Instance> instances = elb.getInstances();
        if (instances == null || instances.size() == 0) {
            resource.setAdditionalField("instanceCount", "0");
            resource.setDescription("instances=none");
            LOGGER.debug(String.format("No instances found for ELB %s", resource.getId()));
        } else {
            resource.setAdditionalField("instanceCount", "" + instances.size());
            ArrayList<String> instanceList = new ArrayList<String>(instances.size());
            LOGGER.debug(String.format("Found %d instances for ELB %s", instances.size(), resource.getId()));
            for (Instance instance : instances) {
                String instanceId = instance.getInstanceId();
                instanceList.add(instanceId);
            }
            String instancesStr = StringUtils.join(instanceList, ",");
            resource.setDescription(String.format("instances=%s", instances));
            LOGGER.debug(String.format("Resource ELB %s has instances %s", resource.getId(), instancesStr));
        }
        for (TagDescription tagDescription : awsClient.describeElasticLoadBalancerTags(resource.getId())) {
            for (Tag tag : tagDescription.getTags()) {
                LOGGER.debug(String.format("Adding tag %s = %s to resource %s", tag.getKey(), tag.getValue(), resource.getId()));
                resource.setTag(tag.getKey(), tag.getValue());
            }
        }
    }
    Map<String, List<String>> elbtoASGMap = buildELBtoASGMap();
    for (Resource resource : resources) {
        List<String> asgList = elbtoASGMap.get(resource.getId());
        if (asgList != null && asgList.size() > 0) {
            resource.setAdditionalField("referencedASGCount", "" + asgList.size());
            String asgStr = StringUtils.join(asgList, ",");
            resource.setDescription(resource.getDescription() + ", ASGS=" + asgStr);
            LOGGER.debug(String.format("Resource ELB %s is referenced by ASGs %s", resource.getId(), asgStr));
        } else {
            resource.setAdditionalField("referencedASGCount", "0");
            resource.setDescription(resource.getDescription() + ", ASGS=none");
            LOGGER.debug(String.format("No ASGs found for ELB %s", resource.getId()));
        }
    }
    return resources;
}
Also used : Instance(com.amazonaws.services.elasticloadbalancing.model.Instance) TagDescription(com.amazonaws.services.elasticloadbalancing.model.TagDescription) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) AWSResource(com.netflix.simianarmy.aws.AWSResource) Tag(com.amazonaws.services.elasticloadbalancing.model.Tag) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)

Aggregations

Instance (com.amazonaws.services.elasticloadbalancing.model.Instance)3 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)3 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 DescribeLoadBalancersRequest (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)1 Tag (com.amazonaws.services.elasticloadbalancing.model.Tag)1 TagDescription (com.amazonaws.services.elasticloadbalancing.model.TagDescription)1 Resource (com.netflix.simianarmy.Resource)1 AWSResource (com.netflix.simianarmy.aws.AWSResource)1 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1