use of com.netflix.simianarmy.client.aws.AWSClient in project SimianArmy by Netflix.
the class EBSSnapshotJanitorCrawler method getSnapshotResources.
private List<Resource> getSnapshotResources(String... snapshotIds) {
refreshSnapshotToAMIs();
List<Resource> resources = new LinkedList<Resource>();
AWSClient awsClient = getAWSClient();
for (Snapshot snapshot : awsClient.describeSnapshots(snapshotIds)) {
Resource snapshotResource = new AWSResource().withId(snapshot.getSnapshotId()).withRegion(getAWSClient().region()).withResourceType(AWSResourceType.EBS_SNAPSHOT).withLaunchTime(snapshot.getStartTime()).withDescription(snapshot.getDescription());
for (Tag tag : snapshot.getTags()) {
LOGGER.debug(String.format("Adding tag %s = %s to resource %s", tag.getKey(), tag.getValue(), snapshotResource.getId()));
snapshotResource.setTag(tag.getKey(), tag.getValue());
}
snapshotResource.setOwnerEmail(getOwnerEmailForResource(snapshotResource));
((AWSResource) snapshotResource).setAWSResourceState(snapshot.getState());
Collection<String> amis = snapshotToAMIs.get(snapshotResource.getId());
if (amis != null) {
snapshotResource.setAdditionalField(SNAPSHOT_FIELD_AMIS, StringUtils.join(amis, ","));
}
resources.add(snapshotResource);
}
return resources;
}
use of com.netflix.simianarmy.client.aws.AWSClient in project SimianArmy by Netflix.
the class ELBJanitorCrawler method buildELBtoASGMap.
private Map<String, List<String>> buildELBtoASGMap() {
AWSClient awsClient = getAWSClient();
LOGGER.info(String.format("Getting all ELBs associated with ASGs in region %s", awsClient.region()));
List<AutoScalingGroup> autoScalingGroupList = awsClient.describeAutoScalingGroups();
HashMap<String, List<String>> asgMap = new HashMap<>();
for (AutoScalingGroup asg : autoScalingGroupList) {
String asgName = asg.getAutoScalingGroupName();
if (asg.getLoadBalancerNames() != null) {
for (String elbName : asg.getLoadBalancerNames()) {
List<String> asgList = asgMap.get(elbName);
if (asgList == null) {
asgList = new ArrayList<>();
asgMap.put(elbName, asgList);
}
asgList.add(asgName);
LOGGER.debug(String.format("Found ASG %s associated with ELB %s", asgName, elbName));
}
}
}
return asgMap;
}
use of com.netflix.simianarmy.client.aws.AWSClient 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.netflix.simianarmy.client.aws.AWSClient in project SimianArmy by Netflix.
the class BasicSimianArmyContext method createClient.
/**
* Create the specific client within passed region, using the appropriate AWS credentials provider
* and client configuration.
* @param clientRegion
*/
protected void createClient(String clientRegion) {
this.client = new AWSClient(clientRegion, awsCredentialsProvider, awsClientConfig);
setCloudClient(this.client);
}
use of com.netflix.simianarmy.client.aws.AWSClient in project SimianArmy by Netflix.
the class TestSimpleDBJanitorResourceTracker method makeMockAWSClient.
private static AWSClient makeMockAWSClient() {
AmazonSimpleDB sdbMock = mock(AmazonSimpleDB.class);
AWSClient awsClient = mock(AWSClient.class);
when(awsClient.sdbClient()).thenReturn(sdbMock);
return awsClient;
}
Aggregations