/** * 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 (getCode() != null) sb.append("Code: ").append(getCode()).append(","); if (getName() != null) sb.append("Name: ").append(getName()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof InstanceState == false) return false; InstanceState other = (InstanceState) obj; if (other.getCode() == null ^ this.getCode() == null) return false; if (other.getCode() != null && other.getCode().equals(this.getCode()) == false) return false; if (other.getName() == null ^ this.getName() == null) return false; if (other.getName() != null && other.getName().equals(this.getName()) == false) return false; return true; }
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; }
instance.getImageId(), instance.getInstanceType(), instance.getState().getName(), instance.getMonitoring().getState());
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof InstanceState == false) return false; InstanceState other = (InstanceState)obj; if (other.getCode() == null ^ this.getCode() == null) return false; if (other.getCode() != null && other.getCode().equals(this.getCode()) == false) return false; if (other.getName() == null ^ this.getName() == null) return false; if (other.getName() != null && other.getName().equals(this.getName()) == false) return false; return true; }
/** * 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 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 (getCode() != null) sb.append("Code: " + getCode() + ","); if (getName() != null) sb.append("Name: " + getName() ); sb.append("}"); return sb.toString(); }
@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; }
@Override public boolean isTrue() { Instance instance = service.getInstance(instanceId); InstanceState instanceState = instance.getState(); String stateName = instanceState.getName(); return targetState.getValue().equals(stateName); }
/** * 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()); }
/** * 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()); }