use of com.netflix.simianarmy.client.aws.AWSClient in project SimianArmy by Netflix.
the class AWSClusterCrawler method clusters.
/**
* In this implementation, every auto scaling group is considered a cluster.
* @param clusterNames
* the cluster names
* @return the list of clusters matching the names, when names are empty, return all clusters
*/
@Override
public List<Cluster> clusters(String... clusterNames) {
List<Cluster> list = Lists.newArrayList();
for (Map.Entry<String, AWSClient> entry : regionToAwsClient.entrySet()) {
String region = entry.getKey();
AWSClient awsClient = entry.getValue();
Set<String> asgInstances = Sets.newHashSet();
LOGGER.info(String.format("Crawling clusters in region %s", region));
for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups(clusterNames)) {
List<String> instances = Lists.newArrayList();
for (Instance instance : asg.getInstances()) {
instances.add(instance.getInstanceId());
asgInstances.add(instance.getInstanceId());
}
com.netflix.simianarmy.conformity.AutoScalingGroup conformityAsg = new com.netflix.simianarmy.conformity.AutoScalingGroup(asg.getAutoScalingGroupName(), instances.toArray(new String[instances.size()]));
for (SuspendedProcess sp : asg.getSuspendedProcesses()) {
if ("AddToLoadBalancer".equals(sp.getProcessName())) {
LOGGER.info(String.format("ASG %s is suspended: %s", asg.getAutoScalingGroupName(), asg.getSuspendedProcesses()));
conformityAsg.setSuspended(true);
}
}
Cluster cluster = new Cluster(asg.getAutoScalingGroupName(), region, conformityAsg);
List<TagDescription> tagDescriptions = asg.getTags();
for (TagDescription tagDescription : tagDescriptions) {
if (BasicSimianArmyContext.GLOBAL_OWNER_TAGKEY.equalsIgnoreCase(tagDescription.getKey())) {
String value = tagDescription.getValue();
if (value != null) {
cluster.setOwnerEmail(value);
}
}
}
updateCluster(cluster);
list.add(cluster);
}
// Cluster containing all solo instances
Set<String> instances = Sets.newHashSet();
for (com.amazonaws.services.ec2.model.Instance awsInstance : awsClient.describeInstances()) {
if (!asgInstances.contains(awsInstance.getInstanceId())) {
LOGGER.info(String.format("Adding instance %s to soloInstances cluster.", awsInstance.getInstanceId()));
instances.add(awsInstance.getInstanceId());
}
}
// Only create cluster if we have solo instances.
if (!instances.isEmpty()) {
Cluster cluster = new Cluster("SoloInstances", region, instances);
updateCluster(cluster);
list.add(cluster);
}
}
return list;
}
use of com.netflix.simianarmy.client.aws.AWSClient in project SimianArmy by Netflix.
the class InstanceInSecurityGroup method getInstanceSecurityGroups.
/**
* Gets the security groups for a list of instance ids of the same region. The default implementation
* is using an AWS client. The method can be overridden in subclasses to get the security groups differently.
* @param region
* the region of the instances
* @param instanceIds
* the instance ids, all instances should be in the same region.
* @return
* the map from instance id to the list of security group names the instance has
*/
protected Map<String, List<String>> getInstanceSecurityGroups(String region, String... instanceIds) {
Map<String, List<String>> result = Maps.newHashMap();
if (instanceIds == null || instanceIds.length == 0) {
return result;
}
AWSClient awsClient = new AWSClient(region, awsCredentialsProvider);
for (Instance instance : awsClient.describeInstances(instanceIds)) {
// Ignore instances that are in VPC
if (StringUtils.isNotEmpty(instance.getVpcId())) {
LOGGER.info(String.format("Instance %s is in VPC and is ignored.", instance.getInstanceId()));
continue;
}
if (!"running".equals(instance.getState().getName())) {
LOGGER.info(String.format("Instance %s is not running, state is %s.", instance.getInstanceId(), instance.getState().getName()));
continue;
}
List<String> sgs = Lists.newArrayList();
for (GroupIdentifier groupId : instance.getSecurityGroups()) {
sgs.add(groupId.getGroupName());
}
result.put(instance.getInstanceId(), sgs);
}
return result;
}
use of com.netflix.simianarmy.client.aws.AWSClient in project SimianArmy by Netflix.
the class SameZonesInElbAndAsg method getAwsClient.
private AWSClient getAwsClient(String region) {
AWSClient awsClient = regionToAwsClient.get(region);
if (awsClient == null) {
awsClient = new AWSClient(region, awsCredentialsProvider);
regionToAwsClient.put(region, awsClient);
}
return awsClient;
}
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 CrossZoneLoadBalancing method getAwsClient.
private AWSClient getAwsClient(String region) {
AWSClient awsClient = regionToAwsClient.get(region);
if (awsClient == null) {
awsClient = new AWSClient(region, awsCredentialsProvider);
regionToAwsClient.put(region, awsClient);
}
return awsClient;
}
Aggregations