/** * 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; }
@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; }
/** * 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 String getInstanceIp(String instanceId) { if (getInstanceState(instanceId).getCode() != 16) return null; try { return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { FOKLogger.log(getClass().getName(), Level.SEVERE, FOKLogger.DEFAULT_ERROR_TEXT, e); return null; } }
@Override public String getInstanceDns(String instanceId) { if (getInstanceState(instanceId).getCode() != 16) return ""; try { return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { FOKLogger.log(getClass().getName(), Level.SEVERE, FOKLogger.DEFAULT_ERROR_TEXT, e); return null; } }
/** * 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; }
public Integer getInstanceStatus(String instanceId) { DescribeInstancesRequest describeInstanceRequest = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult describeInstanceResult = ec2.describeInstances(describeInstanceRequest); InstanceState state = describeInstanceResult.getReservations().get(0).getInstances().get(0).getState(); return state.getCode(); }
public Integer getInstanceStatus(String instanceId) { DescribeInstancesRequest describeInstanceRequest = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult describeInstanceResult = ec2.describeInstances(describeInstanceRequest); InstanceState state = describeInstanceResult.getReservations().get(0).getInstances().get(0).getState(); return state.getCode(); }
public boolean checkEc2Instance(String instanceId) { boolean instanceTerminated = false; try { DescribeInstancesResult result = awsEc2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId)); List<com.amazonaws.services.ec2.model.Instance> instances = result.getReservations().stream() .flatMap(r -> r.getInstances().stream()) .filter(i -> i.getInstanceId().equals(instanceId)) .collect(Collectors.toList()); instanceTerminated = instances.isEmpty() || instances.stream() .map(com.amazonaws.services.ec2.model.Instance::getState) .anyMatch(s -> s.getCode().equals(48)); } catch (AmazonServiceException e) { log.info(e.toString(), e); if (e.getStatusCode() == 400) { instanceTerminated = true; } } if (instanceTerminated) { log.warn("Invalid instance " + instanceId + " in group " + activeConfiguration.getAutoScalingGroupId() + ". Detaching instance."); awsAsClient.detachInstances(new DetachInstancesRequest() .withAutoScalingGroupName(activeConfiguration.getAutoScalingGroupId()) .withInstanceIds(instanceId) .withShouldDecrementDesiredCapacity(false)); } return instanceTerminated; }
private static boolean allInstancesStarted(DescribeInstancesResult describeInstancesResult, int port) { for (Reservation reservation : describeInstancesResult.getReservations()) { for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) { if (instance.getState() == null || instance.getState().getCode() == null) { return false; } // is it running? int state = instance.getState().getCode(); if (state == STATE_PENDING || instance.getPublicDnsName() == null) { return false; } // can we talk to it yet? try { Resources.toByteArray(new URL(format("http://%s:%s/v1/slot", instance.getPublicDnsName(), port))); } catch (Exception e) { return false; } } } return true; }
private static boolean allInstancesStarted(DescribeInstancesResult describeInstancesResult, int port) { for (Reservation reservation : describeInstancesResult.getReservations()) { for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) { if (instance.getState() == null || instance.getState().getCode() == null) { return false; } // is it running? int state = instance.getState().getCode(); if (state == STATE_PENDING || instance.getPublicDnsName() == null) { return false; } // can we talk to it yet? try { Resources.toByteArray(new URL(format("http://%s:%s/v1/slot", instance.getPublicDnsName(), port))); } catch (Exception e) { return false; } } } return true; } }
private static boolean allInstancesStarted(DescribeInstancesResult describeInstancesResult, int port) { for (Reservation reservation : describeInstancesResult.getReservations()) { for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) { if (instance.getState() == null || instance.getState().getCode() == null) { return false; } // is it running? int state = instance.getState().getCode(); if (state == STATE_PENDING || instance.getPublicDnsName() == null) { return false; } // can we talk to it yet? try { Resources.toByteArray(new URL(format("http://%s:%s/v1/slot", instance.getPublicDnsName(), port))); } catch (Exception e) { return false; } } } return true; } }
private void logReconcileStats(Collection<Instance> ec2Instances, Collection<EsInstance> cmdbInstances) { int ec2RunningCount = 0; for (Instance inst : ec2Instances) { if (inst.getState().getCode() == 16) { //EC2 API may return some terminated instances. Only get the running count ec2RunningCount++; } } Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "ec2TotalRunningCount"), ec2RunningCount); Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "cmdbTotalRunningCount"), cmdbInstances.size()); Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "diffcount"), Math.abs(ec2RunningCount - cmdbInstances.size())); int serviceMappingMissingCount = 0; for (EsInstance instance : cmdbInstances) { /*if (instance.getServiceMappings() == null || instance.getServiceMappings().length == 0) { serviceMappingMissingCount++; }*/ } Stats.setGauge(StatsUtil.getStatsName("awsreconcile", "servicemappingmissingcount"), serviceMappingMissingCount); }