use of com.amazonaws.services.autoscaling.model.LaunchConfiguration in project SimianArmy by Netflix.
the class LaunchConfigJanitorCrawler method getLaunchConfigResources.
private List<Resource> getLaunchConfigResources(String... launchConfigNames) {
List<Resource> resources = Lists.newArrayList();
AWSClient awsClient = getAWSClient();
Set<String> usedLCs = Sets.newHashSet();
for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups()) {
usedLCs.add(asg.getLaunchConfigurationName());
}
for (LaunchConfiguration launchConfiguration : awsClient.describeLaunchConfigurations(launchConfigNames)) {
String lcName = launchConfiguration.getLaunchConfigurationName();
Resource lcResource = new AWSResource().withId(lcName).withRegion(getAWSClient().region()).withResourceType(AWSResourceType.LAUNCH_CONFIG).withLaunchTime(launchConfiguration.getCreatedTime());
lcResource.setOwnerEmail(getOwnerEmailForResource(lcResource));
lcResource.setAdditionalField(LAUNCH_CONFIG_FIELD_USED_BY_ASG, String.valueOf(usedLCs.contains(lcName)));
resources.add(lcResource);
}
return resources;
}
use of com.amazonaws.services.autoscaling.model.LaunchConfiguration in project SimianArmy by Netflix.
the class ASGJanitorCrawler method getASGResources.
private List<Resource> getASGResources(String... asgNames) {
AWSClient awsClient = getAWSClient();
List<LaunchConfiguration> launchConfigurations = awsClient.describeLaunchConfigurations();
for (LaunchConfiguration lc : launchConfigurations) {
nameToLaunchConfig.put(lc.getLaunchConfigurationName(), lc);
}
List<Resource> resources = new LinkedList<Resource>();
for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups(asgNames)) {
Resource asgResource = new AWSResource().withId(asg.getAutoScalingGroupName()).withResourceType(AWSResourceType.ASG).withRegion(awsClient.region()).withLaunchTime(asg.getCreatedTime());
for (TagDescription tag : asg.getTags()) {
asgResource.setTag(tag.getKey(), tag.getValue());
}
asgResource.setDescription(String.format("%d instances", asg.getInstances().size()));
asgResource.setOwnerEmail(getOwnerEmailForResource(asgResource));
if (asg.getStatus() != null) {
((AWSResource) asgResource).setAWSResourceState(asg.getStatus());
}
Integer maxSize = asg.getMaxSize();
if (maxSize != null) {
asgResource.setAdditionalField(ASG_FIELD_MAX_SIZE, String.valueOf(maxSize));
}
// Adds instances and ELBs as additional fields.
List<String> instances = new ArrayList<String>();
for (Instance instance : asg.getInstances()) {
instances.add(instance.getInstanceId());
}
asgResource.setAdditionalField(ASG_FIELD_INSTANCES, StringUtils.join(instances, ","));
asgResource.setAdditionalField(ASG_FIELD_ELBS, StringUtils.join(asg.getLoadBalancerNames(), ","));
String lcName = asg.getLaunchConfigurationName();
LaunchConfiguration lc = nameToLaunchConfig.get(lcName);
if (lc != null) {
asgResource.setAdditionalField(ASG_FIELD_LC_NAME, lcName);
}
if (lc != null && lc.getCreatedTime() != null) {
asgResource.setAdditionalField(ASG_FIELD_LC_CREATION_TIME, String.valueOf(lc.getCreatedTime().getTime()));
}
// sets the field for the time when the ASG's traffic is suspended from ELB
for (SuspendedProcess sp : asg.getSuspendedProcesses()) {
if ("AddToLoadBalancer".equals(sp.getProcessName())) {
String suspensionTime = getSuspensionTimeString(sp.getSuspensionReason());
if (suspensionTime != null) {
LOGGER.info(String.format("Suspension time of ASG %s is %s", asg.getAutoScalingGroupName(), suspensionTime));
asgResource.setAdditionalField(ASG_FIELD_SUSPENSION_TIME, suspensionTime);
break;
}
}
}
resources.add(asgResource);
}
return resources;
}
use of com.amazonaws.services.autoscaling.model.LaunchConfiguration in project SimianArmy by Netflix.
the class TestLaunchConfigJanitorCrawler method testInstancesWithResourceType.
@Test
public void testInstancesWithResourceType() {
int n = 2;
List<LaunchConfiguration> lcList = createLaunchConfigList(n);
LaunchConfigJanitorCrawler crawler = new LaunchConfigJanitorCrawler(createMockAWSClient(createASGList(n), lcList));
for (AWSResourceType resourceType : AWSResourceType.values()) {
List<Resource> resources = crawler.resources(resourceType);
if (resourceType == AWSResourceType.LAUNCH_CONFIG) {
verifyLaunchConfigList(resources, lcList);
} else {
Assert.assertTrue(resources.isEmpty());
}
}
}
Aggregations