@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getInstanceId() == null) ? 0 : getInstanceId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getReasonCode() == null) ? 0 : getReasonCode().hashCode()); hashCode = prime * hashCode + ((getDescription() == null) ? 0 : getDescription().hashCode()); return hashCode; }
setDescription(description); return this;
/** * <p> * The ID of the instance. * </p> * * @param instanceId * The ID of the instance. * @return Returns a reference to this object so that method calls can be chained together. */ public InstanceState withInstanceId(String instanceId) { setInstanceId(instanceId); return this; }
public InstanceState unmarshall(StaxUnmarshallerContext context) throws Exception { InstanceState instanceState = new InstanceState(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; instanceState.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instanceState.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instanceState.setReasonCode(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instanceState.setDescription(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue;
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; }
/** * <p> * The current state of the instance. * </p> * <p> * Valid values: <code>InService</code> | <code>OutOfService</code> | <code>Unknown</code> * </p> * * @param state * The current state of the instance.</p> * <p> * Valid values: <code>InService</code> | <code>OutOfService</code> | <code>Unknown</code> * @return Returns a reference to this object so that method calls can be chained together. */ public InstanceState withState(String state) { setState(state); return this; }
/** * <p> * Information about the cause of <code>OutOfService</code> instances. Specifically, whether the cause is Elastic * Load Balancing or the instance. * </p> * <p> * Valid values: <code>ELB</code> | <code>Instance</code> | <code>N/A</code> * </p> * * @param reasonCode * Information about the cause of <code>OutOfService</code> instances. Specifically, whether the cause is * Elastic Load Balancing or the instance.</p> * <p> * Valid values: <code>ELB</code> | <code>Instance</code> | <code>N/A</code> * @return Returns a reference to this object so that method calls can be chained together. */ public InstanceState withReasonCode(String reasonCode) { setReasonCode(reasonCode); return this; }
public InstanceState unmarshall(StaxUnmarshallerContext context) throws Exception { InstanceState instanceState = new InstanceState(); instanceState.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; .setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instanceState.setReasonCode(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue; instanceState.setDescription(StringStaxUnmarshaller.getInstance().unmarshall( context)); continue;
private void updateInstancesStateOnLoadBalancer(String loadBalancerName, List<Ec2Instance> instances) { DescribeInstanceHealthResult result = awsElbClient.describeInstanceHealth(new DescribeInstanceHealthRequest(loadBalancerName)); instances.forEach(i -> result.getInstanceStates().stream().filter(s -> s.getInstanceId().equals(i.getInstanceId())).findFirst().ifPresent(s -> i.updateState(AwsState.map(s.getState())))); }
/** * <p> * The current state of the instance. * </p> * <p> * Valid values: <code>InService</code> | <code>OutOfService</code> | <code>Unknown</code> * </p> * * @param state * The current state of the instance.</p> * <p> * Valid values: <code>InService</code> | <code>OutOfService</code> | <code>Unknown</code> * @return Returns a reference to this object so that method calls can be chained together. */ public InstanceState withState(String state) { setState(state); return this; }
/** * <p> * Information about the cause of <code>OutOfService</code> instances. Specifically, whether the cause is Elastic * Load Balancing or the instance. * </p> * <p> * Valid values: <code>ELB</code> | <code>Instance</code> | <code>N/A</code> * </p> * * @param reasonCode * Information about the cause of <code>OutOfService</code> instances. Specifically, whether the cause is * Elastic Load Balancing or the instance.</p> * <p> * Valid values: <code>ELB</code> | <code>Instance</code> | <code>N/A</code> * @return Returns a reference to this object so that method calls can be chained together. */ public InstanceState withReasonCode(String reasonCode) { setReasonCode(reasonCode); return this; }
@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.getInstanceId() == null ^ this.getInstanceId() == null) return false; if (other.getInstanceId() != null && other.getInstanceId().equals(this.getInstanceId()) == 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.getReasonCode() == null ^ this.getReasonCode() == null) return false; if (other.getReasonCode() != null && other.getReasonCode().equals(this.getReasonCode()) == false) return false; if (other.getDescription() == null ^ this.getDescription() == null) return false; if (other.getDescription() != null && other.getDescription().equals(this.getDescription()) == false) return false; return true; }
public InstanceState unmarshall(StaxUnmarshallerContext context) throws Exception { InstanceState instanceState = new InstanceState(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; instanceState.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instanceState.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instanceState.setReasonCode(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; instanceState.setDescription(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue;
public void updateInstanceState(Ec2Instance instance, List<String> loadBalancerNames) { for (String elb : loadBalancerNames) { DescribeInstanceHealthResult result = awsElbClient.describeInstanceHealth(new DescribeInstanceHealthRequest(elb)); Optional<InstanceState> state = result.getInstanceStates().stream().filter(s -> s.getInstanceId().equals(instance.getInstanceId())).findFirst(); if (!state.isPresent()) { instance.updateState(AwsState.UNKNOWN); } else { instance.updateState(AwsState.valueOf(state.get().getState().toUpperCase())); } } }
/** * <p> * The ID of the instance. * </p> * * @param instanceId * The ID of the instance. * @return Returns a reference to this object so that method calls can be chained together. */ public InstanceState withInstanceId(String instanceId) { setInstanceId(instanceId); return this; }
setDescription(description); return this;
/** * 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 (getState() != null) sb.append("State: ").append(getState()).append(","); if (getReasonCode() != null) sb.append("ReasonCode: ").append(getReasonCode()).append(","); if (getDescription() != null) sb.append("Description: ").append(getDescription()); sb.append("}"); return sb.toString(); }
public Observable<AwsState> pollForInstanceState(final String loadBalancer) { try { return Observable.from(elbAsyncClient.describeInstanceHealthAsync(new DescribeInstanceHealthRequest().withLoadBalancerName(loadBalancer).withInstances(new Instance().withInstanceId(instanceId)))) .flatMap(result -> { Optional<InstanceState> state = result.getInstanceStates().stream().filter(i -> i.getInstanceId().equals(instanceId)).findFirst(); return just(state.map(instanceState -> AwsState.map(instanceState.getState())).orElse(AwsState.UNKNOWN)); }); } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); throw new AwsException(e); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getInstanceId() == null) ? 0 : getInstanceId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getReasonCode() == null) ? 0 : getReasonCode().hashCode()); hashCode = prime * hashCode + ((getDescription() == null) ? 0 : getDescription().hashCode()); return hashCode; }
InstanceState other = (InstanceState) obj; if (other.getInstanceId() == null ^ this.getInstanceId() == null) return false; if (other.getInstanceId() != null && other.getInstanceId().equals(this.getInstanceId()) == 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.getReasonCode() == null ^ this.getReasonCode() == null) return false; if (other.getReasonCode() != null && other.getReasonCode().equals(this.getReasonCode()) == false) return false; if (other.getDescription() == null ^ this.getDescription() == null) return false; if (other.getDescription() != null && other.getDescription().equals(this.getDescription()) == false) return false; return true;