@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAutoScalingInstances() == null) ? 0 : getAutoScalingInstances().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
/** * <p> * The instances. * </p> * * @param autoScalingInstances * The instances. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeAutoScalingInstancesResult withAutoScalingInstances(java.util.Collection<AutoScalingInstanceDetails> autoScalingInstances) { setAutoScalingInstances(autoScalingInstances); return this; }
/** * <p> * The token to use when requesting the next set of items. If there are no additional items to return, the string is * empty. * </p> * * @param nextToken * The token to use when requesting the next set of items. If there are no additional items to return, the * string is empty. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeAutoScalingInstancesResult withNextToken(String nextToken) { setNextToken(nextToken); return this; }
static String getAutoScaleGroup() { try { String credFileProperty = System.getProperty( AwsPropertyKeys.AWS_CREDENTIALS_FILE.getBundle()); AWSCredentials credentials; if (credFileProperty != null) { credentials = new PropertiesCredentials(new File(credFileProperty)); } else { credentials = new DefaultAWSCredentialsProviderChain().getCredentials(); } AmazonAutoScaling autoScalingClient = AwsServiceClients.autoScaling(credentials); List<AutoScalingInstanceDetails> autoScalingInstances = autoScalingClient.describeAutoScalingInstances( new DescribeAutoScalingInstancesRequest().withInstanceIds(getInstanceId())).getAutoScalingInstances(); return autoScalingInstances.isEmpty() ? UNDEFINED : autoScalingInstances.get(0).getAutoScalingGroupName(); } catch (Exception e) { getLogger().error("Unable to get ASG name.", e); return UNDEFINED; } }
public DescribeAutoScalingInstancesResult unmarshall(StaxUnmarshallerContext context) throws Exception { DescribeAutoScalingInstancesResult describeAutoScalingInstancesResult = new DescribeAutoScalingInstancesResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return describeAutoScalingInstancesResult; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("AutoScalingInstances", targetDepth)) { describeAutoScalingInstancesResult.withAutoScalingInstances(new ArrayList<AutoScalingInstanceDetails>()); continue; } if (context.testExpression("AutoScalingInstances/member", targetDepth)) { describeAutoScalingInstancesResult.withAutoScalingInstances(AutoScalingInstanceDetailsStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("NextToken", targetDepth)) { describeAutoScalingInstancesResult.setNextToken(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return describeAutoScalingInstancesResult; } } } }
/** * <p> * The instances. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param autoScalingInstances <p> * The instances. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public DescribeAutoScalingInstancesResult withAutoScalingInstances( AutoScalingInstanceDetails... autoScalingInstances) { if (getAutoScalingInstances() == null) { this.autoScalingInstances = new java.util.ArrayList<AutoScalingInstanceDetails>( autoScalingInstances.length); } for (AutoScalingInstanceDetails value : autoScalingInstances) { this.autoScalingInstances.add(value); } return this; }
public DescribeAutoScalingInstancesResult unmarshall(StaxUnmarshallerContext context) throws Exception { DescribeAutoScalingInstancesResult describeAutoScalingInstancesResult = new DescribeAutoScalingInstancesResult(); if (context.testExpression("AutoScalingInstances/member", targetDepth)) { describeAutoScalingInstancesResult .withAutoScalingInstances(AutoScalingInstanceDetailsStaxUnmarshaller .getInstance().unmarshall(context)); continue; describeAutoScalingInstancesResult.setNextToken(StringStaxUnmarshaller .getInstance().unmarshall(context)); continue;
public Observable<AwsState> pollForInstanceState() { try { return Observable.from(asyncClient.describeAutoScalingInstancesAsync(new DescribeAutoScalingInstancesRequest().withInstanceIds(instanceId))) .flatMap(result -> { Optional<String> optState = result.getAutoScalingInstances().stream().filter(i -> i.getInstanceId().equals(instanceId)).map(AutoScalingInstanceDetails::getLifecycleState).findFirst(); return just(optState.map(AwsState::map).orElse(AwsState.UNKNOWN)); }); } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); throw new AwsException(e); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeAutoScalingInstancesResult == false) return false; DescribeAutoScalingInstancesResult other = (DescribeAutoScalingInstancesResult) obj; if (other.getAutoScalingInstances() == null ^ this.getAutoScalingInstances() == null) return false; if (other.getAutoScalingInstances() != null && other.getAutoScalingInstances().equals(this.getAutoScalingInstances()) == 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; }
/** * <p> * The instances. * </p> * <p> * <b>NOTE:</b> This method appends the values to the existing list (if any). Use * {@link #setAutoScalingInstances(java.util.Collection)} or {@link #withAutoScalingInstances(java.util.Collection)} * if you want to override the existing values. * </p> * * @param autoScalingInstances * The instances. * @return Returns a reference to this object so that method calls can be chained together. */ public DescribeAutoScalingInstancesResult withAutoScalingInstances(AutoScalingInstanceDetails... autoScalingInstances) { if (this.autoScalingInstances == null) { setAutoScalingInstances(new com.amazonaws.internal.SdkInternalList<AutoScalingInstanceDetails>(autoScalingInstances.length)); } for (AutoScalingInstanceDetails ele : autoScalingInstances) { this.autoScalingInstances.add(ele); } return this; }
@Override public Optional<AutoScalingInstanceDetails> getCurrentAutoScalingGroup(String instanceId) { try { DescribeAutoScalingInstancesRequest request = new DescribeAutoScalingInstancesRequest().withInstanceIds(instanceId); DescribeAutoScalingInstancesResult describeResult = asg.describeAutoScalingInstances(request); List<AutoScalingInstanceDetails> asgs = describeResult.getAutoScalingInstances(); if (asgs.isEmpty()) { return Optional.empty(); } return Optional.ofNullable(asgs.iterator().next()); } catch (AmazonClientException e) { LOG.error("Unable to fetch current AutoScaleGroup for instance: {} {}", instanceId, e); return Optional.empty(); } }
/** * 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 (getAutoScalingInstances() != null) sb.append("AutoScalingInstances: ").append(getAutoScalingInstances()).append(","); if (getNextToken() != null) sb.append("NextToken: ").append(getNextToken()); sb.append("}"); return sb.toString(); }
/** * <p> * The instances. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param autoScalingInstances <p> * The instances. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public DescribeAutoScalingInstancesResult withAutoScalingInstances( java.util.Collection<AutoScalingInstanceDetails> autoScalingInstances) { setAutoScalingInstances(autoScalingInstances); return this; }
private Optional<AutoScalingInstanceDetails> describeInstance() { try { DescribeAutoScalingInstancesResult result = asyncClient.describeAutoScalingInstances(new DescribeAutoScalingInstancesRequest().withInstanceIds(Collections.singletonList(instanceId))); return result.getAutoScalingInstances().stream().filter(a -> a.getInstanceId().equals(instanceId)).findFirst(); } catch (AmazonAutoScalingException e) { if (e.getStatusCode() == 403) { LOG.error("Looks like the instance role is not correctly authorized, please see : https://github.com/msoute/vertx-deploy-tools#aws-iam-policy"); } LOG.error(e.getMessage(), e); throw e; } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAutoScalingInstances() == null) ? 0 : getAutoScalingInstances().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
String getAutoscalingGroup(final String instanceId) { final DescribeAutoScalingInstancesRequest describeRequest = new DescribeAutoScalingInstancesRequest().withInstanceIds(Collections.singleton(instanceId)); final DescribeAutoScalingInstancesResult result = autoScalingClient.describeAutoScalingInstances(describeRequest); for (AutoScalingInstanceDetails details : result.getAutoScalingInstances()) { if (StringUtils.equals(instanceId, details.getInstanceId())) { return details.getAutoScalingGroupName(); } } return null; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeAutoScalingInstancesResult == false) return false; DescribeAutoScalingInstancesResult other = (DescribeAutoScalingInstancesResult) obj; if (other.getAutoScalingInstances() == null ^ this.getAutoScalingInstances() == null) return false; if (other.getAutoScalingInstances() != null && other.getAutoScalingInstances().equals(this.getAutoScalingInstances()) == 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; } }
private String getCurrentAsgName() { DescribeAutoScalingInstancesRequest asgInsReq = new DescribeAutoScalingInstancesRequest() .withInstanceIds(AWSUtil.getLocalInstanceId()); DescribeAutoScalingInstancesResult asgInsRes = getAutoScalingClient().describeAutoScalingInstances(asgInsReq); String myAsgName = asgInsRes.getAutoScalingInstances().get(0).getAutoScalingGroupName(); return myAsgName!=null && myAsgName.length() > 0 ? myAsgName : "NdBench_Aws_cluster"; }
/** * 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 (getAutoScalingInstances() != null) sb.append("AutoScalingInstances: " + getAutoScalingInstances() + ","); if (getNextToken() != null) sb.append("NextToken: " + getNextToken()); sb.append("}"); return sb.toString(); }
private String getCurrentAsgName() { DescribeAutoScalingInstancesRequest asgInsReq = new DescribeAutoScalingInstancesRequest() .withInstanceIds(AWSUtil.getLocalInstanceId()); DescribeAutoScalingInstancesResult asgInsRes = getAutoScalingClient().describeAutoScalingInstances(asgInsReq); String myAsgName = asgInsRes.getAutoScalingInstances().get(0).getAutoScalingGroupName(); return myAsgName!=null && myAsgName.length() > 0 ? myAsgName : "NdBench_Aws_cluster"; }