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