Search in sources :

Example 6 with 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;
}
Also used : Snapshot(com.amazonaws.services.ec2.model.Snapshot) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Tag(com.amazonaws.services.ec2.model.Tag) LinkedList(java.util.LinkedList)

Example 7 with AWSClient

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;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) AWSClient(com.netflix.simianarmy.client.aws.AWSClient)

Example 8 with AWSClient

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;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) LaunchConfiguration(com.amazonaws.services.autoscaling.model.LaunchConfiguration) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSClient(com.netflix.simianarmy.client.aws.AWSClient)

Example 9 with AWSClient

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);
}
Also used : AWSClient(com.netflix.simianarmy.client.aws.AWSClient)

Example 10 with AWSClient

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;
}
Also used : AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) AWSClient(com.netflix.simianarmy.client.aws.AWSClient)

Aggregations

AWSClient (com.netflix.simianarmy.client.aws.AWSClient)37 Resource (com.netflix.simianarmy.Resource)18 Test (org.testng.annotations.Test)15 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)11 AWSResource (com.netflix.simianarmy.aws.AWSResource)10 Instance (com.amazonaws.services.ec2.model.Instance)7 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)6 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)5 LinkedList (java.util.LinkedList)4 Tag (com.amazonaws.services.ec2.model.Tag)3 Instance (com.amazonaws.services.autoscaling.model.Instance)2 LaunchConfiguration (com.amazonaws.services.autoscaling.model.LaunchConfiguration)2 SuspendedProcess (com.amazonaws.services.autoscaling.model.SuspendedProcess)2 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)2 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)2 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)2 Cluster (com.netflix.simianarmy.conformity.Cluster)2 GroupIdentifier (com.amazonaws.services.ec2.model.GroupIdentifier)1 Snapshot (com.amazonaws.services.ec2.model.Snapshot)1 Volume (com.amazonaws.services.ec2.model.Volume)1