Search in sources :

Example 1 with DescribeAutoScalingGroupsRequest

use of com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest in project iep by Netflix.

the class PaginationTest method autoscalingN.

private void autoscalingN(int n) throws Exception {
    SortedSet<String> pages = newPageSet(n);
    final Iterator<String> reqIt = pages.iterator();
    final Iterator<String> resIt = pages.iterator();
    Function<DescribeAutoScalingGroupsRequest, DescribeAutoScalingGroupsResult> f = r -> {
        if (r.getNextToken() != null) {
            Assert.assertEquals(reqIt.next(), r.getNextToken());
        }
        return new DescribeAutoScalingGroupsResult().withNextToken(resIt.hasNext() ? resIt.next() : null);
    };
    Publisher<DescribeAutoScalingGroupsResult> publisher = Pagination.createPublisher(new DescribeAutoScalingGroupsRequest(), f);
    Iterable<String> iter = Flowable.fromPublisher(publisher).filter(r -> r.getNextToken() != null).map(DescribeAutoScalingGroupsResult::getNextToken).blockingIterable();
    SortedSet<String> results = new TreeSet<>();
    for (String s : iter) {
        results.add(s);
    }
    Assert.assertEquals(pages, results);
    Assert.assertFalse(reqIt.hasNext());
}
Also used : ListHostedZonesResult(com.amazonaws.services.route53.model.ListHostedZonesResult) ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) SortedSet(java.util.SortedSet) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ListMetricsResult(com.amazonaws.services.cloudwatch.model.ListMetricsResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) Function(java.util.function.Function) TreeSet(java.util.TreeSet) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) Flowable(io.reactivex.Flowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) ListClustersResult(com.amazonaws.services.elasticmapreduce.model.ListClustersResult) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) Iterator(java.util.Iterator) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) Publisher(org.reactivestreams.Publisher) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) ListResourceRecordSetsResult(com.amazonaws.services.route53.model.ListResourceRecordSetsResult) ListHostedZonesRequest(com.amazonaws.services.route53.model.ListHostedZonesRequest) ListClustersRequest(com.amazonaws.services.elasticmapreduce.model.ListClustersRequest) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) PutMetricDataResult(com.amazonaws.services.cloudwatch.model.PutMetricDataResult) Assert(org.junit.Assert) ListResourceRecordSetsRequest(com.amazonaws.services.route53.model.ListResourceRecordSetsRequest) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) TreeSet(java.util.TreeSet) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)

Example 2 with DescribeAutoScalingGroupsRequest

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

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

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

the class AWSSdkClient method getAutoScalingGroupsWithTag.

/**
 * Get list of {@link AutoScalingGroup}s for a given tag
 *
 * @param tag Tag to filter the auto scaling groups
 * @return List of {@link AutoScalingGroup}s qualifying the filter tag
 */
public List<AutoScalingGroup> getAutoScalingGroupsWithTag(Tag tag) {
    final AmazonAutoScaling autoScaling = getAmazonAutoScalingClient();
    final DescribeAutoScalingGroupsRequest describeAutoScalingGroupsRequest = new DescribeAutoScalingGroupsRequest();
    final List<AutoScalingGroup> allAutoScalingGroups = autoScaling.describeAutoScalingGroups(describeAutoScalingGroupsRequest).getAutoScalingGroups();
    final List<AutoScalingGroup> filteredAutoScalingGroups = Lists.newArrayList();
    for (AutoScalingGroup autoScalingGroup : allAutoScalingGroups) {
        for (TagDescription tagDescription : autoScalingGroup.getTags()) {
            if (tagDescription.getKey().equalsIgnoreCase(tag.getKey()) && tagDescription.getValue().equalsIgnoreCase(tag.getValue())) {
                filteredAutoScalingGroups.add(autoScalingGroup);
            }
        }
    }
    return filteredAutoScalingGroups;
}
Also used : DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling)

Example 5 with DescribeAutoScalingGroupsRequest

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

the class CloudFormationStackUtil method getInstanceIds.

public List<String> getInstanceIds(AmazonAutoScaling amazonASClient, String asGroupName) {
    DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = amazonASClient.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asGroupName));
    List<String> instanceIds = new ArrayList<>();
    if (describeAutoScalingGroupsResult.getAutoScalingGroups().get(0).getInstances() != null) {
        for (Instance instance : describeAutoScalingGroupsResult.getAutoScalingGroups().get(0).getInstances()) {
            if ("InService".equals(instance.getLifecycleState())) {
                instanceIds.add(instance.getInstanceId());
            }
        }
    }
    return instanceIds;
}
Also used : DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) Instance(com.amazonaws.services.autoscaling.model.Instance) ArrayList(java.util.ArrayList) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)

Aggregations

DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)6 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)4 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)4 AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)2 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 Instance (com.amazonaws.services.autoscaling.model.Instance)1 ResumeProcessesRequest (com.amazonaws.services.autoscaling.model.ResumeProcessesRequest)1 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)1 UpdateAutoScalingGroupRequest (com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest)1 ListMetricsRequest (com.amazonaws.services.cloudwatch.model.ListMetricsRequest)1 ListMetricsResult (com.amazonaws.services.cloudwatch.model.ListMetricsResult)1 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1