private static boolean canConnect(List<Instance> instances) { for( Instance instance : instances ) { try { String ssh = "ssh -q" + Host.SSH_OPTS + " " + instance.getPublicIpAddress(); Process p = Runtime.getRuntime().exec(ssh + " exit"); if( p.waitFor() != 0 ) return false; } catch( Exception e ) { return false; } finally { } } 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; }
private String getMasterPublicIp() { final long startTime = System.currentTimeMillis(); final long launchTimeout = TimeUnit.MINUTES.toMillis(10); boolean isMasterLaunched = false; List<Instance> instanceIds = Collections.emptyList(); while (!isMasterLaunched && (System.currentTimeMillis() - startTime) < launchTimeout) { try { Thread.sleep(5000); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while waiting for cluster master to boot up", e); } instanceIds = this.awsSdkClient.getInstancesForGroup(this.masterAutoScalingGroupName, "running"); isMasterLaunched = instanceIds.size() > 0; } if (!isMasterLaunched) { throw new RuntimeException("Timed out while waiting for cluster master. " + "Check for issue manually for ASG: " + this.masterAutoScalingGroupName); } // This will change if cluster master restarts, but that will be handled by Helix events // TODO: Add listener to Helix / Zookeeper for master restart and update master public ip // .. although we do not use master public ip for anything return instanceIds.get(0).getPublicIpAddress(); }
public RunnerInstance( Instance instance ) { this.instance = instance; this.hostname = instance.getPublicDnsName(); this.ipv4Address = instance.getPublicIpAddress(); this.url = "https://" + instance.getPublicDnsName() + ":" + Runner.DEFAULT_SERVER_PORT + "/"; }
@SuppressWarnings( "UnusedDeclaration" ) public RunnerInstance( Instance instance, int port ) { this.instance = instance; this.port = port; this.hostname = instance.getPublicDnsName(); this.ipv4Address = instance.getPublicIpAddress(); this.url = "https://" + instance.getPublicDnsName() + ":" + port + "/"; }
if (getPublicDnsName() != null) sb.append("PublicDnsName: ").append(getPublicDnsName()).append(","); if (getPublicIpAddress() != null) sb.append("PublicIpAddress: ").append(getPublicIpAddress()).append(","); if (getRamdiskId() != null) sb.append("RamdiskId: ").append(getRamdiskId()).append(",");
String[] prv = new String[boxes]; for( int i = 0; i < boxes; i++ ) { pub[i] = instances.get(i).getPublicIpAddress(); prv[i] = instances.get(i).getPrivateIpAddress();
hashCode = prime * hashCode + ((getProductCodes() == null) ? 0 : getProductCodes().hashCode()); hashCode = prime * hashCode + ((getPublicDnsName() == null) ? 0 : getPublicDnsName().hashCode()); hashCode = prime * hashCode + ((getPublicIpAddress() == null) ? 0 : getPublicIpAddress().hashCode()); hashCode = prime * hashCode + ((getRamdiskId() == null) ? 0 : getRamdiskId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().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.getPublicDnsName() != null && other.getPublicDnsName().equals(this.getPublicDnsName()) == false) return false; if (other.getPublicIpAddress() == null ^ this.getPublicIpAddress() == null) return false; if (other.getPublicIpAddress() != null && other.getPublicIpAddress().equals(this.getPublicIpAddress()) == false) return false; if (other.getRamdiskId() == null ^ this.getRamdiskId() == null)
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() + ","); if (getArchitecture() != null) sb.append("Architecture: " + getArchitecture() + ",");
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()); hashCode = prime * hashCode + ((getArchitecture() == null) ? 0 : getArchitecture().hashCode());
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; if (other.getStateReason() == null ^ this.getStateReason() == null) return false; if (other.getStateReason() != null && other.getStateReason().equals(this.getStateReason()) == false) return false;
public String getInstanceIp(String instanceId) { return getInstanceDescription(instanceId).getPublicIpAddress(); }
DescribeInstancesResult result= ec2.describeInstances(request); List <Reservation> list = result.getReservations(); for (Reservation res:list) { List <Instance> instanceList= res.getInstances(); for (Instance instance:instanceList){ System.out.println("Instance Public IP :" + instance.getPublicIpAddress()); } }
private String lookupIpOfInstance(String instanceId) throws Exception { DescribeInstancesResult r=ec2Client.describeInstances( new DescribeInstancesRequest().withInstanceIds(instanceId) ); List<Reservation> instances=r.getReservations(); if(instances.size() != 1) throw new Exception("Could not find instance ["+instanceId+"]"); return instances.get(0).getInstances().get(0).getPublicIpAddress(); }
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 String findIpAddress(String instanceId) { DescribeInstancesResult result=ec2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId)); return result.getReservations().get(0).getInstances().get(0).getPublicIpAddress(); };
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(); }