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());
}
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;
}
}
}
}
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);
}
}
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;
}
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;
}
Aggregations