if (getPrivateDnsName() != null) sb.append("PrivateDnsName: ").append(getPrivateDnsName()).append(","); if (getPrivateIpAddress() != null) sb.append("PrivateIpAddress: ").append(getPrivateIpAddress()).append(","); if (getProductCodes() != null) sb.append("ProductCodes: ").append(getProductCodes()).append(",");
/** {@inheritDoc} */ @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException { initClients(); List<String> instanceIds = new ArrayList<>(); DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest().withLoadBalancerNames(loadBalancerName); List<LoadBalancerDescription> descs = amazonELBClient.describeLoadBalancers(req).getLoadBalancerDescriptions(); for (LoadBalancerDescription desc : descs) { for (Instance instance : desc.getInstances()) instanceIds.add(instance.getInstanceId()); } DescribeInstancesRequest instReq = new DescribeInstancesRequest().withInstanceIds(instanceIds); List<Reservation> reservations = amazonEC2Client.describeInstances(instReq).getReservations(); List<InetSocketAddress> addrs = new ArrayList<>(); for (Reservation reservation : reservations) { List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances(); for (com.amazonaws.services.ec2.model.Instance instance : instances) addrs.add(new InetSocketAddress(instance.getPrivateIpAddress(), 0)); } return addrs; }
for( int i = 0; i < boxes; i++ ) { pub[i] = instances.get(i).getPublicIpAddress(); prv[i] = instances.get(i).getPrivateIpAddress();
hashCode = prime * hashCode + ((getPlatform() == null) ? 0 : getPlatform().hashCode()); hashCode = prime * hashCode + ((getPrivateDnsName() == null) ? 0 : getPrivateDnsName().hashCode()); hashCode = prime * hashCode + ((getPrivateIpAddress() == null) ? 0 : getPrivateIpAddress().hashCode()); hashCode = prime * hashCode + ((getProductCodes() == null) ? 0 : getProductCodes().hashCode()); hashCode = prime * hashCode + ((getPublicDnsName() == null) ? 0 : getPublicDnsName().hashCode());
/** * 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; }
if (other.getPrivateDnsName() != null && other.getPrivateDnsName().equals(this.getPrivateDnsName()) == false) return false; if (other.getPrivateIpAddress() == null ^ this.getPrivateIpAddress() == null) return false; if (other.getPrivateIpAddress() != null && other.getPrivateIpAddress().equals(this.getPrivateIpAddress()) == false) return false; if (other.getProductCodes() == null ^ this.getProductCodes() == null)
if (getSubnetId() != null) sb.append("SubnetId: " + getSubnetId() + ","); if (getVpcId() != null) sb.append("VpcId: " + getVpcId() + ","); if (getPrivateIpAddress() != null) sb.append("PrivateIpAddress: " + getPrivateIpAddress() + ","); if (getPublicIpAddress() != null) sb.append("PublicIpAddress: " + getPublicIpAddress() + ","); if (getStateReason() != null) sb.append("StateReason: " + getStateReason() + ",");
hashCode = prime * hashCode + ((getSubnetId() == null) ? 0 : getSubnetId().hashCode()); hashCode = prime * hashCode + ((getVpcId() == null) ? 0 : getVpcId().hashCode()); hashCode = prime * hashCode + ((getPrivateIpAddress() == null) ? 0 : getPrivateIpAddress().hashCode()); hashCode = prime * hashCode + ((getPublicIpAddress() == null) ? 0 : getPublicIpAddress().hashCode()); hashCode = prime * hashCode + ((getStateReason() == null) ? 0 : getStateReason().hashCode());
@Override public String apply(Instance input) { return input.getPrivateIpAddress(); } }
private Predicate<Instance> accessible(boolean requirePrivateAccessible) { if (requirePrivateAccessible) { return i -> !Strings.isNullOrEmpty(i.getPrivateIpAddress()); } else { return i -> true; } }
if (other.getVpcId() == null ^ this.getVpcId() == null) return false; if (other.getVpcId() != null && other.getVpcId().equals(this.getVpcId()) == false) return false; if (other.getPrivateIpAddress() == null ^ this.getPrivateIpAddress() == null) return false; if (other.getPrivateIpAddress() != null && other.getPrivateIpAddress().equals(this.getPrivateIpAddress()) == false) return false; if (other.getPublicIpAddress() == null ^ this.getPublicIpAddress() == null) return false; if (other.getPublicIpAddress() != null && other.getPublicIpAddress().equals(this.getPublicIpAddress()) == false) return false;
private String getPreferredHostName(final Instance instance) { if (this.preferPrivateIpHostnames) { return instance.getPrivateIpAddress(); } return instance.getPublicDnsName(); } }
private OverloadResource.OverloadStatus loadOverloadStatus(com.amazonaws.services.ec2.model.Instance instance) { try { HttpURLConnection connection = (HttpURLConnection) getOverloadUrl(instance.getPrivateIpAddress()).openConnection(); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestMethod("GET"); return om.readValue(connection.getInputStream(), OverloadResource.OverloadStatus.class); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Returns map of instanceId:privateIp * * @param ec2Instances * @return */ public Map<String,String> getPrivateIPs(List<Instance> ec2Instances) { TreeMap<String,String> names = new TreeMap<String,String>(String.CASE_INSENSITIVE_ORDER); for (Instance i : ec2Instances) { names.put(i.getInstanceId(),i.getPrivateIpAddress()); } return names; }
/** * * @param instanceId * @param ec2Client * @return */ public String getPrivateIp(String instanceId, AmazonEC2 ec2Client) { String privateIp = null; Instance instance = this.getInstanceById(instanceId, ec2Client); if (instance != null) { privateIp = instance.getPrivateIpAddress(); } return privateIp; }
private String getEC2HostAddress(EC2Computer computer, Instance inst) { if (computer.getNode().usePrivateDnsName) { return inst.getPrivateDnsName(); } else { String host = inst.getPublicDnsName(); // If we fail to get a public DNS name, use the private IP. if (host == null || host.equals("")) { host = inst.getPrivateIpAddress(); } return host; } }
public String getMasterNodeIp(AmazonElasticMapReduceClient emr, String emrId) throws Exception { Cluster cluster = emr.describeCluster(new DescribeClusterRequest().withClusterId(emrId)); ListInstancesResult instances = emr.listInstances(new ListInstancesRequest().withClusterId(emrId)); String masterDnsName = cluster.getMasterPublicDnsName(); for (Instance instance : instances.getInstances()) { if (instance.getPublicDnsName().equals(masterDnsName)) { return instance.getPrivateIpAddress(); } } throw new Exception("Failed to find master node private ip."); }
DescribeInstancesRequest describeRequest = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult describeResult = ec2.describeInstances(describeRequest); Instance instance = describeResult.getReservations().get(0).getInstances().get(0); String publicIp = instance.getPublicIpAddress(); String privateIp = instance.getPrivateIpAddress();
private void addInstanceToAgentsFile(Instance instance) { String instanceId = instance.getInstanceId(); DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceId); DescribeInstancesResult result = ec2.describeInstances(describeInstancesRequest); for (Reservation reservation : result.getReservations()) { for (Instance reserved : reservation.getInstances()) { appendText(reserved.getPublicIpAddress() + ',' + reserved.getPrivateIpAddress() + NEW_LINE, agentsFile); componentRegistry.addAgent(reserved.getPublicIpAddress(), reserved.getPrivateIpAddress()); } } }
private Ec2Instance toEc2Instance(com.amazonaws.services.ec2.model.Instance instance) { return new Ec2Instance.Builder().withInstanceId(instance.getInstanceId()).withPrivateIp(instance.getPrivateIpAddress()).withPublicIp(instance.getPublicIpAddress()).build(); }