Search in sources :

Example 1 with AutoScalingGroup

use of com.amazonaws.services.autoscaling.model.AutoScalingGroup in project incubator-gobblin by apache.

the class GobblinAWSClusterLauncher method getReconnectableClusterId.

@VisibleForTesting
Optional<String> getReconnectableClusterId() throws IOException {
    // List ASGs with Tag of cluster name
    final Tag clusterNameTag = new Tag().withKey(CLUSTER_NAME_ASG_TAG).withValue(this.clusterName);
    final List<AutoScalingGroup> autoScalingGroups = this.awsSdkClient.getAutoScalingGroupsWithTag(clusterNameTag);
    // If no auto scaling group is found, we don't have an existing cluster to connect to
    if (autoScalingGroups.size() == 0) {
        return Optional.absent();
    }
    // If more than 0 auto scaling groups are found, validate the setup
    if (autoScalingGroups.size() != 2) {
        throw new IOException("Expected 2 auto scaling groups (1 each for master and workers) but found: " + autoScalingGroups.size());
    }
    // Retrieve cluster information from ASGs
    Optional<String> clusterId = Optional.absent();
    Optional<AutoScalingGroup> masterAsg = Optional.absent();
    Optional<AutoScalingGroup> workersAsg = Optional.absent();
    for (TagDescription tagDescription : autoScalingGroups.get(0).getTags()) {
        LOGGER.info("Found tag: " + tagDescription);
        if (tagDescription.getKey().equalsIgnoreCase(CLUSTER_ID_ASG_TAG)) {
            clusterId = Optional.of(tagDescription.getValue());
        }
        if (tagDescription.getKey().equalsIgnoreCase(ASG_TYPE_ASG_TAG)) {
            if (tagDescription.getValue().equalsIgnoreCase(ASG_TYPE_MASTER)) {
                masterAsg = Optional.of(autoScalingGroups.get(0));
                workersAsg = Optional.of(autoScalingGroups.get(1));
            } else {
                masterAsg = Optional.of(autoScalingGroups.get(1));
                workersAsg = Optional.of(autoScalingGroups.get(0));
            }
        }
    }
    if (!clusterId.isPresent()) {
        throw new IOException("Found 2 auto scaling group names for: " + this.clusterName + " but tags seem to be corrupted, hence could not determine cluster id");
    }
    if (!masterAsg.isPresent() || !workersAsg.isPresent()) {
        throw new IOException("Found 2 auto scaling group names for: " + this.clusterName + " but tags seem to be corrupted, hence could not determine master and workers ASG");
    }
    // Get Master and Workers launch config name and auto scaling group name
    this.masterAutoScalingGroupName = masterAsg.get().getAutoScalingGroupName();
    this.masterLaunchConfigName = masterAsg.get().getLaunchConfigurationName();
    this.workerAutoScalingGroupName = workersAsg.get().getAutoScalingGroupName();
    this.workerLaunchConfigName = workersAsg.get().getLaunchConfigurationName();
    LOGGER.info("Trying to find cluster master public ip");
    this.masterPublicIp = getMasterPublicIp();
    LOGGER.info("Master public ip: " + this.masterPublicIp);
    return clusterId;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) Tag(com.amazonaws.services.autoscaling.model.Tag) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with AutoScalingGroup

use of com.amazonaws.services.autoscaling.model.AutoScalingGroup in project cloudbreak by hortonworks.

the class AwsResourceConnector method resumeAutoScalingPolicies.

private void resumeAutoScalingPolicies(AuthenticatedContext ac, CloudStack stack) {
    for (Group instanceGroup : stack.getGroups()) {
        try {
            String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, instanceGroup.getName(), ac.getCloudContext().getLocation().getRegion().value());
            if (asGroupName != null) {
                AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
                List<AutoScalingGroup> asGroups = amazonASClient.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asGroupName)).getAutoScalingGroups();
                if (!asGroups.isEmpty()) {
                    if (!asGroups.get(0).getSuspendedProcesses().isEmpty()) {
                        amazonASClient.updateAutoScalingGroup(new UpdateAutoScalingGroupRequest().withAutoScalingGroupName(asGroupName).withMinSize(0).withDesiredCapacity(0));
                        amazonASClient.resumeProcesses(new ResumeProcessesRequest().withAutoScalingGroupName(asGroupName));
                    }
                }
            } else {
                LOGGER.info("Autoscaling Group's physical id is null (the resource doesn't exist), it is not needed to resume scaling policies.");
            }
        } catch (AmazonServiceException e) {
            if (e.getErrorMessage().matches("Resource.*does not exist for stack.*") || e.getErrorMessage().matches("Stack '.*' does not exist.*")) {
                LOGGER.info(e.getMessage());
            } else {
                throw e;
            }
        }
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) AmazonServiceException(com.amazonaws.AmazonServiceException) UpdateAutoScalingGroupRequest(com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest) ResumeProcessesRequest(com.amazonaws.services.autoscaling.model.ResumeProcessesRequest)

Example 3 with AutoScalingGroup

use of com.amazonaws.services.autoscaling.model.AutoScalingGroup in project eureka by Netflix.

the class AwsAsgUtil method retrieveAutoScalingGroup.

/**
 * Queries AWS to get the autoscaling information given the asgName.
 *
 * @param asgName
 *            - The name of the ASG.
 * @return - The auto scaling group information.
 */
private AutoScalingGroup retrieveAutoScalingGroup(String asgName) {
    if (Strings.isNullOrEmpty(asgName)) {
        logger.warn("null asgName specified, not attempting to retrieve AutoScalingGroup from AWS");
        return null;
    }
    // You can pass one name or a list of names in the request
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asgName);
    DescribeAutoScalingGroupsResult result = awsClient.describeAutoScalingGroups(request);
    List<AutoScalingGroup> asgs = result.getAutoScalingGroups();
    if (asgs.isEmpty()) {
        return null;
    } else {
        return asgs.get(0);
    }
}
Also used : DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)

Example 4 with AutoScalingGroup

use of com.amazonaws.services.autoscaling.model.AutoScalingGroup 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;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Instance(com.amazonaws.services.autoscaling.model.Instance) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) Cluster(com.netflix.simianarmy.conformity.Cluster) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) SuspendedProcess(com.amazonaws.services.autoscaling.model.SuspendedProcess) Map(java.util.Map)

Example 5 with AutoScalingGroup

use of com.amazonaws.services.autoscaling.model.AutoScalingGroup 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)

Aggregations

AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)34 Test (org.testng.annotations.Test)16 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)11 Instance (com.amazonaws.services.autoscaling.model.Instance)9 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)9 Resource (com.netflix.simianarmy.Resource)8 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)5 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)4 HashSet (java.util.HashSet)4 SuspendedProcess (com.amazonaws.services.autoscaling.model.SuspendedProcess)3 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)3 BasicInstanceGroup (com.netflix.simianarmy.basic.chaos.BasicInstanceGroup)3 TunableInstanceGroup (com.netflix.simianarmy.tunable.TunableInstanceGroup)3 AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)2 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)2 LaunchConfiguration (com.amazonaws.services.autoscaling.model.LaunchConfiguration)2 AWSResource (com.netflix.simianarmy.aws.AWSResource)2 InstanceGroup (com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup)2 Cluster (com.netflix.simianarmy.conformity.Cluster)2 ArrayList (java.util.ArrayList)2