Search in sources :

Example 1 with Tag

use of com.amazonaws.services.elasticloadbalancing.model.Tag 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)1 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)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