static RunningInstance blockUntilInstanceRunning(EC2Client client, RunningInstance instance) throws TimeoutException { // create utilities that wait for the instance to finish RetryablePredicate<RunningInstance> runningTester = new RetryablePredicate<RunningInstance>( new InstanceStateRunning(client), 180, 5, TimeUnit.SECONDS); System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance.getId()); if (!runningTester.apply(instance)) throw new TimeoutException("timeout waiting for instance to run: " + instance.getId()); instance = findInstanceById(client, instance.getId()); RetryablePredicate<HostAndPort> socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS); System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); if (!socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 22))) throw new TimeoutException("timeout waiting for ssh to start: " + instance.getIpAddress()); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getIpAddress()); System.out.printf("%d: %s awaiting http service to start%n", System.currentTimeMillis(), instance.getIpAddress()); if (!socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 80))) throw new TimeoutException("timeout waiting for http to start: " + instance.getIpAddress()); System.out.printf("%d: %s http service started%n", System.currentTimeMillis(), instance.getIpAddress()); return instance; }
public boolean apply(RunningInstance instance) { logger.trace("looking for ipAddress on instance %s", instance); try { instance = refresh(instance); return instance.getIpAddress() != null; } catch (AWSResponseException e) { if (e.getError().getCode().equals("InvalidInstanceID.NotFound")) return false; throw e; } }
public boolean apply(RunningInstance instance) { logger.trace("looking for ipAddress on instance %s", instance); try { instance = refresh(instance); return instance.getIpAddress() != null; } catch (AWSResponseException e) { if (e.getError().getCode().equals("InvalidInstanceID.NotFound")) return false; throw e; } }
public boolean apply(RunningInstance instance) { logger.trace("looking for ipAddress on instance %s", instance); try { instance = refresh(instance); return instance.getIpAddress() != null; } catch (AWSResponseException e) { if (e.getError().getCode().equals("InvalidInstanceID.NotFound")) return false; throw e; } }
public boolean apply(RunningInstance instance) { logger.trace("looking for ipAddress on instance %s", instance); try { instance = refresh(instance); return instance.getIpAddress() != null; } catch (AWSResponseException e) { if (e.getError().getCode().equals("InvalidInstanceID.NotFound")) return false; throw e; } }
public boolean apply(RunningInstance instance) { logger.trace("looking for ipAddress on instance %s", instance); try { instance = refresh(instance); return instance.getIpAddress() != null; } catch (AWSResponseException e) { if (e.getError().getCode().equals("InvalidInstanceID.NotFound")) return false; throw e; } }
private void doCheckKey(RunningInstance newDetails) throws UnknownHostException { doCheckKey(newDetails.getIpAddress()); }
private void doCheckKey(RunningInstance newDetails) throws UnknownHostException { doCheckKey(newDetails.getIpAddress()); }
private void doCheckKey(RunningInstance newDetails) throws UnknownHostException { doCheckKey(newDetails.getIpAddress()); }
private void doCheckKey(RunningInstance newDetails) throws UnknownHostException { doCheckKey(newDetails.getIpAddress()); }
private RunningInstance blockUntilWeCanSshIntoInstance(RunningInstance instance) throws UnknownHostException { System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance.getId()); assert runningTester.apply(instance); instance = getInstance(instance.getId()); System.out .printf("%d: %s awaiting instance to have ip assigned %n", System.currentTimeMillis(), instance.getId()); assert hasIpTester.apply(instance); System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 22)); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName()); sshPing(instance); System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); System.out.printf("%d: %s awaiting http service to start%n", System.currentTimeMillis(), instance.getIpAddress()); assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 80)); System.out.printf("%d: %s http service started%n", System.currentTimeMillis(), instance.getDnsName()); return instance; }
System.out.printf("ip address: %s%n", instance.getIpAddress()); System.out.printf("dns name: %s%n", instance.getDnsName()); System.out.printf("login identity:%n%s%n", pair.getKeyMaterial());
private RunningInstance blockUntilWeCanSshIntoInstance(RunningInstance instance) throws UnknownHostException { System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance.getId()); assert runningTester.apply(instance); instance = getInstance(instance.getId()); System.out .printf("%d: %s awaiting instance to have ip assigned %n", System.currentTimeMillis(), instance.getId()); assert hasIpTester.apply(instance); System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 22)); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName()); sshPing(instance); System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); System.out.printf("%d: %s awaiting http service to start%n", System.currentTimeMillis(), instance.getIpAddress()); assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 80)); System.out.printf("%d: %s http service started%n", System.currentTimeMillis(), instance.getDnsName()); return instance; }
private RunningInstance blockUntilWeCanSshIntoInstance(RunningInstance instance) throws UnknownHostException { System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance.getId()); assert runningTester.apply(instance); // search my identity for the instance I just created Set<? extends Reservation<? extends RunningInstance>> reservations = client.getInstanceServices() .describeInstancesInRegion(instance.getRegion(), instance.getId()); // last // parameter // (ids) // narrows // the // search instance = Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 22)); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName()); sshPing(instance); System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); return instance; }
private RunningInstance blockUntilWeCanSshIntoInstance(RunningInstance instance) throws UnknownHostException { System.out.printf("%d: %s awaiting instance to run %n", System.currentTimeMillis(), instance.getId()); assert runningTester.apply(instance); // search my identity for the instance I just created Reservation<? extends RunningInstance> reservation = Iterables.getOnlyElement(client.getInstanceApi().get() .describeInstancesInRegion(instance.getRegion(), instance.getId())); // last // parameter // (ids) // narrows // the // search instance = Iterables.getOnlyElement(reservation); System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 22)); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName()); sshPing(instance); System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); return instance; }
@Test(enabled = false, dependsOnMethods = "testReboot") void testElasticIpAddress() throws InterruptedException, ExecutionException, TimeoutException, IOException { address = client.getElasticIPAddressApi().get().allocateAddressInRegion(null); assertNotNull(address); PublicIpInstanceIdPair compare = Iterables.getLast(client.getElasticIPAddressApi().get() .describeAddressesInRegion(null, address)); assertEquals(compare.getPublicIp(), address); assert compare.getInstanceId() == null; client.getElasticIPAddressApi().get().associateAddressInRegion(null, address, instanceId); compare = Iterables.getLast(client.getElasticIPAddressApi().get().describeAddressesInRegion(null, address)); assertEquals(compare.getPublicIp(), address); assertEquals(compare.getInstanceId(), instanceId); Reservation<? extends RunningInstance> reservation = Iterables.getOnlyElement(client.getInstanceApi().get() .describeInstancesInRegion(null, instanceId)); assertNotNull(Iterables.getOnlyElement(reservation).getIpAddress()); assertNotEquals(address, Iterables.getOnlyElement(reservation).getIpAddress()); doCheckKey(address); client.getElasticIPAddressApi().get().disassociateAddressInRegion(null, address); compare = Iterables.getLast(client.getElasticIPAddressApi().get().describeAddressesInRegion(null, address)); assertEquals(compare.getPublicIp(), address); assert compare.getInstanceId() == null; reservation = Iterables.getOnlyElement(client.getInstanceApi().get().describeInstancesInRegion(null, instanceId)); // assert reservation.getRunningInstances().last().getIpAddress() == null; // TODO }
@Test(enabled = false, dependsOnMethods = "testReboot") void testElasticIpAddress() throws InterruptedException, ExecutionException, TimeoutException, IOException { address = client.getElasticIPAddressServices().allocateAddressInRegion(null); assertNotNull(address); PublicIpInstanceIdPair compare = Iterables.getLast(client.getElasticIPAddressServices() .describeAddressesInRegion(null, address)); assertEquals(compare.getPublicIp(), address); assert compare.getInstanceId() == null; client.getElasticIPAddressServices().associateAddressInRegion(null, address, instanceId); compare = Iterables.getLast(client.getElasticIPAddressServices().describeAddressesInRegion(null, address)); assertEquals(compare.getPublicIp(), address); assertEquals(compare.getInstanceId(), instanceId); Reservation<? extends RunningInstance> reservation = Iterables.getOnlyElement(client.getInstanceServices() .describeInstancesInRegion(null, instanceId)); assertNotNull(Iterables.getOnlyElement(reservation).getIpAddress()); assertNotEquals(address, Iterables.getOnlyElement(reservation).getIpAddress()); doCheckKey(address); client.getElasticIPAddressServices().disassociateAddressInRegion(null, address); compare = Iterables.getLast(client.getElasticIPAddressServices().describeAddressesInRegion(null, address)); assertEquals(compare.getPublicIp(), address); assert compare.getInstanceId() == null; reservation = Iterables.getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null, instanceId)); // assert reservation.getRunningInstances().last().getIpAddress() == null; // TODO }
@Test(enabled = false, dependsOnMethods = "testCreateRunningInstance") void testReboot() throws InterruptedException, ExecutionException, TimeoutException, IOException { RunningInstance instance = getInstance(instanceId); System.out.printf("%d: %s rebooting instance %n", System.currentTimeMillis(), instanceId); client.getInstanceApi().get().rebootInstancesInRegion(null, instanceId); Thread.sleep(1000); instance = getInstance(instanceId); blockUntilWeCanSshIntoInstance(instance); SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse uptime = ssh.exec("uptime"); assert uptime.getOutput().indexOf("0 min") != -1 : "reboot didn't work: " + uptime; } finally { if (ssh != null) ssh.disconnect(); } }
@Test(enabled = false, dependsOnMethods = "testCreateRunningInstance") void testReboot() throws InterruptedException, ExecutionException, TimeoutException, IOException { RunningInstance instance = getInstance(instanceId); System.out.printf("%d: %s rebooting instance %n", System.currentTimeMillis(), instanceId); client.getInstanceServices().rebootInstancesInRegion(null, instanceId); Thread.sleep(1000); instance = getInstance(instanceId); blockUntilWeCanSshIntoInstance(instance); SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse uptime = ssh.exec("uptime"); assert uptime.getOutput().indexOf("0 min") != -1 : "reboot didn't work: " + uptime; } finally { if (ssh != null) ssh.disconnect(); } }
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume") void testBundleInstance() { SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try {