/** * 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); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAutoScalingGroups() == null) ? 0 : getAutoScalingGroups().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
public DescribeAutoScalingGroupsResult unmarshall(StaxUnmarshallerContext context) throws Exception { DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return describeAutoScalingGroupsResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("AutoScalingGroups", targetDepth)) { describeAutoScalingGroupsResult.withAutoScalingGroups(new ArrayList<AutoScalingGroup>()); continue; } if (context.testExpression("AutoScalingGroups/member", targetDepth)) { describeAutoScalingGroupsResult.withAutoScalingGroups(AutoScalingGroupStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("NextToken", targetDepth)) { describeAutoScalingGroupsResult.setNextToken(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return describeAutoScalingGroupsResult; } } } }
public DescribeAutoScalingGroupsResult describeAutoScalingGroups(DescribeAutoScalingGroupsRequest request) { return new DescribeAutoScalingGroupsResult() .withAutoScalingGroups( describe(request, "autoScalingGroupNames", "autoScalingGroups", AutoScalingGroup.class)); }
/** * <p> * The groups. * </p> * * @param autoScalingGroups * The groups. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeAutoScalingGroupsResult withAutoScalingGroups(java.util.Collection<AutoScalingGroup> autoScalingGroups) { setAutoScalingGroups(autoScalingGroups); return this; }
public DescribeAutoScalingGroupsResult describeAutoScalingGroups(DescribeAutoScalingGroupsRequest request) { return new DescribeAutoScalingGroupsResult().withAutoScalingGroups(describe(request, "autoScalingGroupNames", "autoScalingGroups", AutoScalingGroup.class, new TypeReference<List<AutoScalingGroup>>() { })); }
/** * <p> * The groups. * </p> * <p> * <b>NOTE:</b> This method appends the values to the existing list (if any). Use * {@link #setAutoScalingGroups(java.util.Collection)} or {@link #withAutoScalingGroups(java.util.Collection)} if * you want to override the existing values. * </p> * * @param autoScalingGroups * The groups. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeAutoScalingGroupsResult withAutoScalingGroups(AutoScalingGroup... autoScalingGroups) { if (this.autoScalingGroups == null) { setAutoScalingGroups(new com.amazonaws.internal.SdkInternalList<AutoScalingGroup>(autoScalingGroups.length)); } for (AutoScalingGroup ele : autoScalingGroups) { this.autoScalingGroups.add(ele); } return this; }
.withAutoScalingGroupNames(asgName); DescribeAutoScalingGroupsResult result = autoScalingClient.describeAutoScalingGroups(request); List<AutoScalingGroup> asgs = result.getAutoScalingGroups(); if (asgs.isEmpty()) { return null;
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeAutoScalingGroupsResult == false) return false; DescribeAutoScalingGroupsResult other = (DescribeAutoScalingGroupsResult) obj; if (other.getAutoScalingGroups() == null ^ this.getAutoScalingGroups() == null) return false; if (other.getAutoScalingGroups() != null && other.getAutoScalingGroups().equals(this.getAutoScalingGroups()) == false) return false; if (other.getNextToken() == null ^ this.getNextToken() == null) return false; if (other.getNextToken() != null && other.getNextToken().equals(this.getNextToken()) == false) return false; return true; }
public DescribeAutoScalingGroupsResult unmarshall(StaxUnmarshallerContext context) throws Exception { DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = new DescribeAutoScalingGroupsResult(); if (context.testExpression("AutoScalingGroups/member", targetDepth)) { describeAutoScalingGroupsResult .withAutoScalingGroups(AutoScalingGroupStaxUnmarshaller.getInstance() .unmarshall(context)); continue; describeAutoScalingGroupsResult.setNextToken(StringStaxUnmarshaller .getInstance().unmarshall(context)); continue;
/** * <p> * The groups. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param autoScalingGroups <p> * The groups. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public DescribeAutoScalingGroupsResult withAutoScalingGroups( java.util.Collection<AutoScalingGroup> autoScalingGroups) { setAutoScalingGroups(autoScalingGroups); return this; }
for (AutoScalingGroup asg : res.getAutoScalingGroups()) { for (Instance ins : asg.getInstances()) if (!(ins.getLifecycleState().equalsIgnoreCase("Terminating")
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getAutoScalingGroups() != null) sb.append("AutoScalingGroups: ").append(getAutoScalingGroups()).append(","); if (getNextToken() != null) sb.append("NextToken: ").append(getNextToken()); sb.append("}"); return sb.toString(); }
for (AutoScalingGroup asg : res.getAutoScalingGroups()) { for (Instance ins : asg.getInstances()) if (!(ins.getLifecycleState().equalsIgnoreCase("Terminating")
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAutoScalingGroups() == null) ? 0 : getAutoScalingGroups().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
/*** * 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; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeAutoScalingGroupsResult == false) return false; DescribeAutoScalingGroupsResult other = (DescribeAutoScalingGroupsResult) obj; if (other.getAutoScalingGroups() == null ^ this.getAutoScalingGroups() == null) return false; if (other.getAutoScalingGroups() != null && other.getAutoScalingGroups().equals(this.getAutoScalingGroups()) == false) return false; if (other.getNextToken() == null ^ this.getNextToken() == null) return false; if (other.getNextToken() != null && other.getNextToken().equals(this.getNextToken()) == false) return false; return true; } }
/** Actual membership AWS source of truth... */ @Override public int getRacMembershipSize() { AmazonAutoScaling client = null; try { client = getAutoScalingClient(); DescribeAutoScalingGroupsRequest asgReq = new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(instanceInfo.getAutoScalingGroup()); DescribeAutoScalingGroupsResult res = client.describeAutoScalingGroups(asgReq); int size = 0; for (AutoScalingGroup asg : res.getAutoScalingGroups()) { size += asg.getMaxSize(); } logger.info("Query on ASG returning {} instances", size); return size; } finally { if (client != null) client.shutdown(); } }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getAutoScalingGroups() != null) sb.append("AutoScalingGroups: " + getAutoScalingGroups() + ","); if (getNextToken() != null) sb.append("NextToken: " + getNextToken()); sb.append("}"); return sb.toString(); }
@Override public void expandRacMembership(int count) { AmazonAutoScaling client = null; try { client = getAutoScalingClient(); DescribeAutoScalingGroupsRequest asgReq = new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(instanceInfo.getAutoScalingGroup()); DescribeAutoScalingGroupsResult res = client.describeAutoScalingGroups(asgReq); AutoScalingGroup asg = res.getAutoScalingGroups().get(0); UpdateAutoScalingGroupRequest ureq = new UpdateAutoScalingGroupRequest(); ureq.setAutoScalingGroupName(asg.getAutoScalingGroupName()); ureq.setMinSize(asg.getMinSize() + 1); ureq.setMaxSize(asg.getMinSize() + 1); ureq.setDesiredCapacity(asg.getMinSize() + 1); client.updateAutoScalingGroup(ureq); } finally { if (client != null) client.shutdown(); } }