@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getInstanceId() == null) ? 0 : getInstanceId().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 Instance unmarshall(StaxUnmarshallerContext context) throws Exception { Instance instance = new Instance(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; instance.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instance.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instance.setLifecycleState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instance.setHealthStatus(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instance.setLaunchConfigurationName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instance.setLaunchTemplate(LaunchTemplateSpecificationStaxUnmarshaller.getInstance().unmarshall(context)); continue; instance.setProtectedFromScaleIn(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue;
for (AutoScalingGroup asg : res.getAutoScalingGroups()) { for (Instance ins : asg.getInstances()) if (!(ins.getLifecycleState().equalsIgnoreCase("Terminating") || ins.getLifecycleState().equalsIgnoreCase("shutting-down") || ins.getLifecycleState().equalsIgnoreCase("Terminated"))) instanceIds.add(ins.getInstanceId());
public boolean checkInstanceInServiceOnAllElb(Instance newInstance, List<String> loadBalancerNames) { if (newInstance == null) { throw new IllegalStateException("Unable to check null instance"); } for (String elb : loadBalancerNames) { DescribeInstanceHealthResult result = awsElbClient.describeInstanceHealth(new DescribeInstanceHealthRequest(elb)); Optional<InstanceState> state = result.getInstanceStates().stream().filter(s -> s.getInstanceId().equals(newInstance.getInstanceId())).findFirst(); if (!state.isPresent()) { log.info("instance state for instance " + newInstance.getInstanceId() + " on elb " + elb + " is unknown"); return false; } log.info("instance state for instance " + newInstance.getInstanceId() + " on elb " + elb + " is " + state.get().getState()); if (!"InService".equals(state.get().getState())) { return false; } } return true; }
private List<Ec2Instance> checkInstances(AwsAutoScalingDeployUtils awsDeployUtils, AutoScalingGroup asGroup, List<Ec2Instance> instances) { List<String> removedInstances = asGroup.getInstances().stream() .filter(i -> i.getLifecycleState().equalsIgnoreCase(AwsState.STANDBY.name())) .map(Instance::getInstanceId) .filter(awsDeployUtils::checkEc2Instance) .collect(Collectors.toList()); if (removedInstances != null && removedInstances.isEmpty()) { return instances.stream() .filter(i -> !removedInstances.contains(i.getInstanceId())) .collect(Collectors.toList()); } return instances; } }
for (AutoScalingGroup asg : res.getAutoScalingGroups()) { for (Instance ins : asg.getInstances()) if (!(ins.getLifecycleState().equalsIgnoreCase("Terminating") || ins.getLifecycleState().equalsIgnoreCase("shutting-down") || ins.getLifecycleState().equalsIgnoreCase("Terminated"))) instanceIds.add(ins.getInstanceId());
if (newInstance != null && !found.get()) { found.set(true); log.info("Found new instance with id " + newInstance.getInstanceId());
default boolean isDeployable(DeployConfiguration activeConfiguration, AutoScalingGroup autoScalingGroup, List<Ec2Instance> instances) { long healthyInstances = autoScalingGroup.getInstances().stream() .filter(i -> i.getLifecycleState().equals(LifecycleState.InService.toString())) .count(); long inStandbyInstances = autoScalingGroup.getInstances().stream() .filter(i -> i.getLifecycleState().equals(LifecycleState.Standby.toString())) .count(); long inServiceInstances = instances.stream().filter(i -> AwsState.INSERVICE.equals(i.getElbState())).count(); return this.calculate(activeConfiguration, autoScalingGroup, inServiceInstances, healthyInstances, inStandbyInstances); }
return false; Instance other = (Instance) obj; if (other.getInstanceId() == null ^ this.getInstanceId() == null) return false; if (other.getInstanceId() != null && other.getInstanceId().equals(this.getInstanceId()) == 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) return false; if (other.getProtectedFromScaleIn() == null ^ this.getProtectedFromScaleIn() == null) return false; if (other.getProtectedFromScaleIn() != null && other.getProtectedFromScaleIn().equals(this.getProtectedFromScaleIn()) == false)
@Override public List<String> getRacMembership() { AmazonAutoScaling client = null; try { client = getAutoScalingClient(); DescribeAutoScalingGroupsRequest asgReq = new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(envVariables.getRack()); DescribeAutoScalingGroupsResult res = client.describeAutoScalingGroups(asgReq); List<String> instanceIds = Lists.newArrayList(); for (AutoScalingGroup asg : res.getAutoScalingGroups()) { for (Instance ins : asg.getInstances()) if (!(ins.getLifecycleState().equalsIgnoreCase("Terminating") || ins.getLifecycleState().equalsIgnoreCase("shutting-down") || ins.getLifecycleState().equalsIgnoreCase("Terminated"))) instanceIds.add(ins.getInstanceId()); } logger.info(String.format("Querying Amazon returned following instance in the ASG: %s --> %s", envVariables.getRack(), StringUtils.join(instanceIds, ","))); return instanceIds; } finally { if (client != null) client.shutdown(); } }
public Instance unmarshall(StaxUnmarshallerContext context) throws Exception { Instance instance = new Instance(); instance.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instance.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; instance.setLifecycleState(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; instance.setHealthStatus(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; instance.setLaunchConfigurationName(StringStaxUnmarshaller.getInstance() .unmarshall(context)); continue; instance.setLaunchTemplate(LaunchTemplateSpecificationStaxUnmarshaller .getInstance().unmarshall(context)); continue; instance.setProtectedFromScaleIn(BooleanStaxUnmarshaller.getInstance() .unmarshall(context)); continue;
Set<String> asgInstances = asg.getInstances().stream().map(x -> x.getInstanceId()).collect(Collectors.toSet()); Set<String> allIds = new HashSet<>(); allIds.addAll(asgInstances);
log.debug("describing elb status"); autoScalingGroup.getLoadBalancerNames().forEach(elb -> this.updateInstancesStateOnLoadBalancer(elb, ec2Instances)); ec2Instances.forEach(i -> i.updateAsState(AwsState.map(instanceMap.get(i.getInstanceId()).getLifecycleState()))); ec2Instances.sort((o1, o2) -> {
/** * 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 (getInstanceId() != null) sb.append("InstanceId: ").append(getInstanceId()).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(); }
@Override public List<String> getCrossAccountRacMembership() { AmazonAutoScaling client = null; try { client = getCrossAccountAutoScalingClient(); DescribeAutoScalingGroupsRequest asgReq = new DescribeAutoScalingGroupsRequest() .withAutoScalingGroupNames(envVariables.getRack()); DescribeAutoScalingGroupsResult res = client.describeAutoScalingGroups(asgReq); List<String> instanceIds = Lists.newArrayList(); for (AutoScalingGroup asg : res.getAutoScalingGroups()) { for (Instance ins : asg.getInstances()) if (!(ins.getLifecycleState().equalsIgnoreCase("Terminating") || ins.getLifecycleState().equalsIgnoreCase("shutting-down") || ins.getLifecycleState().equalsIgnoreCase("Terminated"))) instanceIds.add(ins.getInstanceId()); } logger.info(String.format("Querying Amazon returned following instance in the cross-account ASG: %s --> %s", envVariables.getRack(), StringUtils.join(instanceIds, ","))); return instanceIds; } finally { if (client != null) client.shutdown(); } }
public void preDeploy(List<Ec2Instance> instances, AutoScalingGroup asGroup) throws MojoFailureException, MojoExecutionException { if (asGroup.getInstances().isEmpty()) { log.info("No instances found in autoscaling group, spinning new instance"); WaitForInstanceRequestExecutor.InstanceStatus instanceStatus = newInstance -> awsDeployUtils.checkInstanceInService(newInstance.getInstanceId()); awsDeployUtils.setDesiredCapacity(asGroup, asGroup.getDesiredCapacity() + 1); WaitForInstanceRequestExecutor waitForDeployedInstanceRequestExecutor = new WaitForInstanceRequestExecutor(log, 10); waitForDeployedInstanceRequestExecutor.executeRequest(asGroup, awsDeployUtils, instanceStatus); instances.addAll(awsDeployUtils.getInstancesForAutoScalingGroup(log, awsDeployUtils.getAutoScalingGroup())); } }
|| !activeConfiguration.useElbStatusCheck() && asGroup.getInstances().stream().noneMatch(i -> "InService".equals(i.getLifecycleState()))) { activeConfiguration.setDeployStrategy(DeployStrategyType.WHATEVER); log.info("No instances inService, using deploy strategy " + DeployStrategyType.WHATEVER);
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getInstanceId() == null) ? 0 : getInstanceId().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; }
@Override public List<String> getRacMembership() { AmazonAutoScaling client = null; try { client = getAutoScalingClient(); DescribeAutoScalingGroupsRequest asgReq = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(config.getASGName()); DescribeAutoScalingGroupsResult res = client.describeAutoScalingGroups(asgReq); List<String> instanceIds = Lists.newArrayList(); for (AutoScalingGroup asg : res.getAutoScalingGroups()) { for (Instance ins : asg.getInstances()) if (!(ins.getLifecycleState().equalsIgnoreCase("Terminating") || ins.getLifecycleState().equalsIgnoreCase("shutting-down") || ins.getLifecycleState() .equalsIgnoreCase("Terminated"))) instanceIds.add(ins.getInstanceId()); } logger.info(String.format("Querying Amazon returned following instance in the ASG: %s --> %s", config.getRac(), StringUtils.join(instanceIds, ","))); return instanceIds; } 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 (getInstanceId() != null) sb.append("InstanceId: " + getInstanceId() + ","); 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(); }