@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getInstanceId() == null) ? 0 : getInstanceId().hashCode()); hashCode = prime * hashCode + ((getAutoScalingGroupName() == null) ? 0 : getAutoScalingGroupName().hashCode()); hashCode = prime * hashCode + ((getAvailabilityZone() == null) ? 0 : getAvailabilityZone().hashCode()); hashCode = prime * hashCode + ((getLifecycleState() == null) ? 0 : getLifecycleState().hashCode()); hashCode = prime * hashCode + ((getHealthStatus() == null) ? 0 : getHealthStatus().hashCode()); hashCode = prime * hashCode + ((getLaunchConfigurationName() == null) ? 0 : getLaunchConfigurationName().hashCode()); hashCode = prime * hashCode + ((getLaunchTemplate() == null) ? 0 : getLaunchTemplate().hashCode()); hashCode = prime * hashCode + ((getProtectedFromScaleIn() == null) ? 0 : getProtectedFromScaleIn().hashCode()); return hashCode; }
public AutoScalingInstanceDetails unmarshall(StaxUnmarshallerContext context) throws Exception { AutoScalingInstanceDetails autoScalingInstanceDetails = new AutoScalingInstanceDetails(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; autoScalingInstanceDetails.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setAutoScalingGroupName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setLifecycleState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setHealthStatus(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setLaunchConfigurationName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setLaunchTemplate(LaunchTemplateSpecificationStaxUnmarshaller.getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setProtectedFromScaleIn(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue;
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; } }
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; }
public boolean enterStandby(final String groupId, boolean decrementDesiredCapacity) { try { DescribeAutoScalingInstancesResult result = asyncClient.describeAutoScalingInstances(new DescribeAutoScalingInstancesRequest().withMaxRecords(1).withInstanceIds(instanceId)); Optional<AutoScalingInstanceDetails> state = result.getAutoScalingInstances() .stream() .filter(asi -> asi.getInstanceId().equals(instanceId)).findFirst(); state.ifPresent(s -> LOG.trace("enterStandby() instance {} current state : {}", instanceId, s.getLifecycleState())); if (state.isPresent() && state.get().getLifecycleState().equalsIgnoreCase(AwsState.STANDBY.name())) { return true; } else { asyncClient.enterStandby(new EnterStandbyRequest().withAutoScalingGroupName(groupId).withInstanceIds(instanceId).withShouldDecrementDesiredCapacity(decrementDesiredCapacity)); return true; } } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); return false; } }
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); } }
public Map<String, String> getDeployTags() { Map<String, String> tags = new HashMap<>(3); Optional<AutoScalingInstanceDetails> details = describeInstance(); details.ifPresent(autoScalingInstanceDetails -> { autoScalingInstanceDetails.getAutoScalingGroupName(); List<Filter> filters = Collections.singletonList( new Filter().withName("auto-scaling-group").withValues(autoScalingInstanceDetails.getAutoScalingGroupName()) ); DescribeTagsResult result = asyncClient.describeTags(new DescribeTagsRequest().withFilters(filters)); result.getTags().forEach(t -> tags.put(t.getKey(), t.getValue())); }); return tags; }
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; } }
return false; AutoScalingInstanceDetails other = (AutoScalingInstanceDetails) obj; if (other.getInstanceId() == null ^ this.getInstanceId() == null) return false; if (other.getInstanceId() != null && other.getInstanceId().equals(this.getInstanceId()) == false) return false; if (other.getAutoScalingGroupName() == null ^ this.getAutoScalingGroupName() == null) return false; if (other.getAutoScalingGroupName() != null && other.getAutoScalingGroupName().equals(this.getAutoScalingGroupName()) == false) return false; if (other.getAvailabilityZone() == null ^ this.getAvailabilityZone() == null) return false; if (other.getAvailabilityZone() != null && other.getAvailabilityZone().equals(this.getAvailabilityZone()) == false) return false; if (other.getLifecycleState() == null ^ this.getLifecycleState() == null) return false; if (other.getLifecycleState() != null && other.getLifecycleState().equals(this.getLifecycleState()) == false) return false; if (other.getHealthStatus() == null ^ this.getHealthStatus() == null) return false; if (other.getHealthStatus() != null && other.getHealthStatus().equals(this.getHealthStatus()) == false) return false; if (other.getLaunchConfigurationName() == null ^ this.getLaunchConfigurationName() == null) return false; if (other.getLaunchConfigurationName() != null && other.getLaunchConfigurationName().equals(this.getLaunchConfigurationName()) == false) return false; if (other.getLaunchTemplate() == null ^ this.getLaunchTemplate() == null) return false; if (other.getLaunchTemplate() != null && other.getLaunchTemplate().equals(this.getLaunchTemplate()) == false)
public AutoScalingInstanceDetails unmarshall(StaxUnmarshallerContext context) throws Exception { AutoScalingInstanceDetails autoScalingInstanceDetails = new AutoScalingInstanceDetails(); autoScalingInstanceDetails.setInstanceId(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue; autoScalingInstanceDetails.setAutoScalingGroupName(StringStaxUnmarshaller .getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setAvailabilityZone(StringStaxUnmarshaller .getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setLifecycleState(StringStaxUnmarshaller .getInstance().unmarshall(context)); continue; autoScalingInstanceDetails.setHealthStatus(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue; autoScalingInstanceDetails.setLaunchConfigurationName(StringStaxUnmarshaller .getInstance().unmarshall(context)); continue; .setLaunchTemplate(LaunchTemplateSpecificationStaxUnmarshaller .getInstance().unmarshall(context)); continue;
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"; }
StringBuilder sb = new StringBuilder(); sb.append("{"); if (getInstanceId() != null) sb.append("InstanceId: ").append(getInstanceId()).append(","); if (getAutoScalingGroupName() != null) sb.append("AutoScalingGroupName: ").append(getAutoScalingGroupName()).append(","); if (getAvailabilityZone() != null) sb.append("AvailabilityZone: ").append(getAvailabilityZone()).append(","); if (getLifecycleState() != null) sb.append("LifecycleState: ").append(getLifecycleState()).append(","); if (getHealthStatus() != null) sb.append("HealthStatus: ").append(getHealthStatus()).append(","); if (getLaunchConfigurationName() != null) sb.append("LaunchConfigurationName: ").append(getLaunchConfigurationName()).append(","); if (getLaunchTemplate() != null) sb.append("LaunchTemplate: ").append(getLaunchTemplate()).append(","); if (getProtectedFromScaleIn() != null) sb.append("ProtectedFromScaleIn: ").append(getProtectedFromScaleIn()); 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"; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getInstanceId() == null) ? 0 : getInstanceId().hashCode()); hashCode = prime * hashCode + ((getAutoScalingGroupName() == null) ? 0 : getAutoScalingGroupName().hashCode()); hashCode = prime * hashCode + ((getAvailabilityZone() == null) ? 0 : getAvailabilityZone().hashCode()); hashCode = prime * hashCode + ((getLifecycleState() == null) ? 0 : getLifecycleState().hashCode()); hashCode = prime * hashCode + ((getHealthStatus() == null) ? 0 : getHealthStatus().hashCode()); hashCode = prime * hashCode + ((getLaunchConfigurationName() == null) ? 0 : getLaunchConfigurationName() .hashCode()); hashCode = prime * hashCode + ((getLaunchTemplate() == null) ? 0 : getLaunchTemplate().hashCode()); hashCode = prime * hashCode + ((getProtectedFromScaleIn() == null) ? 0 : getProtectedFromScaleIn().hashCode()); return hashCode; }
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; } }
/** * 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 (getInstanceId() != null) sb.append("InstanceId: " + getInstanceId() + ","); if (getAutoScalingGroupName() != null) sb.append("AutoScalingGroupName: " + getAutoScalingGroupName() + ","); if (getAvailabilityZone() != null) sb.append("AvailabilityZone: " + getAvailabilityZone() + ","); if (getLifecycleState() != null) sb.append("LifecycleState: " + getLifecycleState() + ","); if (getHealthStatus() != null) sb.append("HealthStatus: " + getHealthStatus() + ","); if (getLaunchConfigurationName() != null) sb.append("LaunchConfigurationName: " + getLaunchConfigurationName() + ","); if (getLaunchTemplate() != null) sb.append("LaunchTemplate: " + getLaunchTemplate() + ","); if (getProtectedFromScaleIn() != null) sb.append("ProtectedFromScaleIn: " + getProtectedFromScaleIn()); sb.append("}"); return sb.toString(); }
if (other.getInstanceId() == null ^ this.getInstanceId() == null) return false; if (other.getInstanceId() != null && other.getInstanceId().equals(this.getInstanceId()) == false) return false; if (other.getAutoScalingGroupName() == null ^ this.getAutoScalingGroupName() == null) return false; if (other.getAutoScalingGroupName() != null && other.getAutoScalingGroupName().equals(this.getAutoScalingGroupName()) == false) return false; if (other.getAvailabilityZone() == null ^ this.getAvailabilityZone() == null) return false; if (other.getAvailabilityZone() != null && other.getAvailabilityZone().equals(this.getAvailabilityZone()) == false) return false; if (other.getLifecycleState() == null ^ this.getLifecycleState() == null) return false; if (other.getLifecycleState() != null && other.getLifecycleState().equals(this.getLifecycleState()) == false) return false; if (other.getHealthStatus() == null ^ this.getHealthStatus() == null) return false; if (other.getHealthStatus() != null && other.getHealthStatus().equals(this.getHealthStatus()) == false) return false; if (other.getLaunchConfigurationName() == null ^ this.getLaunchConfigurationName() == null) return false; if (other.getLaunchConfigurationName() != null && other.getLaunchConfigurationName().equals(this.getLaunchConfigurationName()) == false)
public void marshall(AutoScalingInstanceDetails _autoScalingInstanceDetails, Request<?> request, String _prefix) { String prefix; if (_autoScalingInstanceDetails.getInstanceId() != null) { prefix = _prefix + "InstanceId"; String instanceId = _autoScalingInstanceDetails.getInstanceId(); request.addParameter(prefix, StringUtils.fromString(instanceId)); if (_autoScalingInstanceDetails.getAutoScalingGroupName() != null) { prefix = _prefix + "AutoScalingGroupName"; String autoScalingGroupName = _autoScalingInstanceDetails.getAutoScalingGroupName(); request.addParameter(prefix, StringUtils.fromString(autoScalingGroupName)); if (_autoScalingInstanceDetails.getAvailabilityZone() != null) { prefix = _prefix + "AvailabilityZone"; String availabilityZone = _autoScalingInstanceDetails.getAvailabilityZone(); request.addParameter(prefix, StringUtils.fromString(availabilityZone)); if (_autoScalingInstanceDetails.getLifecycleState() != null) { prefix = _prefix + "LifecycleState"; String lifecycleState = _autoScalingInstanceDetails.getLifecycleState(); request.addParameter(prefix, StringUtils.fromString(lifecycleState)); if (_autoScalingInstanceDetails.getHealthStatus() != null) { prefix = _prefix + "HealthStatus"; String healthStatus = _autoScalingInstanceDetails.getHealthStatus(); request.addParameter(prefix, StringUtils.fromString(healthStatus)); if (_autoScalingInstanceDetails.getLaunchConfigurationName() != null) { prefix = _prefix + "LaunchConfigurationName";