private static String ip(Instance instance) { String ip = instance.getPublicIpAddress(); if( ip != null && ip.length() != 0 ) if( instance.getState().getName().equals("running") ) return ip; return null; }
/*** * Get list of EC2 {@link Instance}s for a auto scaling group * * @param groupName Auto scaling group name * @param status Instance status (eg. running) * @return List of EC2 instances found for the input auto scaling group */ public List<Instance> getInstancesForGroup(String groupName, String status) { final AmazonEC2 amazonEC2 = getEc2Client(); final DescribeInstancesResult instancesResult = amazonEC2.describeInstances(new DescribeInstancesRequest() .withFilters(new Filter().withName("tag:aws:autoscaling:groupName").withValues(groupName))); final List<Instance> instances = new ArrayList<>(); for (Reservation reservation : instancesResult.getReservations()) { for (Instance instance : reservation.getInstances()) { if (null == status|| null == instance.getState() || status.equals(instance.getState().getName())) { instances.add(instance); LOGGER.info("Found instance: " + instance + " which qualified filter: " + status); } else { LOGGER.info("Found instance: " + instance + " but did not qualify for filter: " + status); } } } return instances; }
hashCode = prime * hashCode + ((getPublicIpAddress() == null) ? 0 : getPublicIpAddress().hashCode()); hashCode = prime * hashCode + ((getRamdiskId() == null) ? 0 : getRamdiskId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getStateTransitionReason() == null) ? 0 : getStateTransitionReason().hashCode()); hashCode = prime * hashCode + ((getSubnetId() == null) ? 0 : getSubnetId().hashCode());
if (other.getRamdiskId() != null && other.getRamdiskId().equals(this.getRamdiskId()) == false) return false; if (other.getState() == null ^ this.getState() == null) return false; if (other.getState() != null && other.getState().equals(this.getState()) == false) return false; if (other.getStateTransitionReason() == null ^ this.getStateTransitionReason() == null)
instance.getImageId(), instance.getInstanceType(), instance.getState().getName(), instance.getMonitoring().getState());
if (getInstanceId() != null) sb.append("InstanceId: " + getInstanceId() + ","); if (getImageId() != null) sb.append("ImageId: " + getImageId() + ","); if (getState() != null) sb.append("State: " + getState() + ","); if (getPrivateDnsName() != null) sb.append("PrivateDnsName: " + getPrivateDnsName() + ","); if (getPublicDnsName() != null) sb.append("PublicDnsName: " + getPublicDnsName() + ",");
/** * Constructs and returns an BasicInstance object, using information from <code>ec2</code> * * @param ec2 * @return */ protected static Instance toInstance( com.amazonaws.services.ec2.model.Instance ec2 ) { Instance instance; BasicInstanceSpec spec; spec = new BasicInstanceSpec(); spec.setImageId( ec2.getImageId() ); spec.setKeyName( ec2.getKeyName() ); spec.setType( ec2.getInstanceType() ); instance = new BasicInstance( ec2.getInstanceId(), spec, InstanceState.fromValue( ec2.getState().getName() ), ec2.getPrivateDnsName(), ec2.getPublicDnsName(), ec2.getPrivateIpAddress(), ec2.getPublicIpAddress() ); return instance; }
/** * Returns the state of the specified instance * * @param instanceId The id of the instance to get the state for * @return The state of the specified instance */ public InstanceState getInstanceState(String instanceId) { return getInstanceDescription(instanceId).getState(); }
if (other.getImageId() == null ^ this.getImageId() == null) return false; if (other.getImageId() != null && other.getImageId().equals(this.getImageId()) == false) return false; if (other.getState() == null ^ this.getState() == null) return false; if (other.getState() != null && other.getState().equals(this.getState()) == false) return false; if (other.getPrivateDnsName() == null ^ this.getPrivateDnsName() == null) return false; if (other.getPrivateDnsName() != null && other.getPrivateDnsName().equals(this.getPrivateDnsName()) == false) return false;
@Override public boolean test(Instance state) { return this.acceptableStates.contains(state.getState().getName()); } }
private boolean anyInstancesStateEqual(List<Instance> instances, InstanceStateName name) { for (Iterator<Instance> iterator = instances.iterator(); iterator.hasNext();) { Instance instance = (Instance) iterator.next(); // if one of instance is not running, return false if (InstanceStateName.fromValue(instance.getState().getName()) == name) { return true; } } return false; }
private boolean allInstancesStateEqual(List<Instance> instances, InstanceStateName name) { for (Iterator<Instance> iterator = instances.iterator(); iterator.hasNext();) { Instance instance = (Instance) iterator.next(); // if one of instance is not running, return false if (InstanceStateName.fromValue(instance.getState().getName()) != name) { return false; } } return true; }
protected boolean isAlive(boolean force) { fetchLiveInstanceData(force); if (lastFetchInstance == null) return false; if (lastFetchInstance.getState().getName().equals(InstanceStateName.Terminated.toString())) return false; return true; }
protected boolean isAlive(boolean force) { fetchLiveInstanceData(force); if (lastFetchInstance == null) return false; if (lastFetchInstance.getState().getName().equals(InstanceStateName.Terminated.toString())) return false; return true; }
/** * Gets the current state of the instance. * * <p> * Unlike {@link #describeInstance()}, this method always return the current status by calling EC2. */ public InstanceState getState() throws AmazonClientException, InterruptedException { ec2InstanceDescription=_describeInstance(); return InstanceState.find(ec2InstanceDescription.getState().getName()); }
private boolean instanceStarting(String instanceId) { DescribeInstancesResult result=ec2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId)); return result.getReservations().get(0).getInstances().get(0).getState().getName().equals(InstanceStateName.Pending.toString()); };
/** * Gets the current state of the instance. * * <p> * Unlike {@link #describeInstance()}, this method always return the current status by calling EC2. */ public InstanceState getState() throws AmazonClientException, InterruptedException { ec2InstanceDescription = CloudHelper.getInstanceWithRetry(getInstanceId(), getCloud()); return InstanceState.find(ec2InstanceDescription.getState().getName()); }