@Test public void testGetLoginPortOrDefaultReturnsPortWhenLoginPortPve() { NodeMetadata mock = Mockito.mock(NodeMetadata.class); Mockito.when(mock.getLoginPort()).thenReturn(666); Assert.assertEquals(JcloudsLocation.getLoginPortOrDefault(mock,22), 666); } }
@Test public void testGetLoginPortOrDefaultReturnsDefaultWhenLoginPortNve() { NodeMetadata mock = Mockito.mock(NodeMetadata.class); Mockito.when(mock.getLoginPort()).thenReturn(-1); Assert.assertEquals(JcloudsLocation.getLoginPortOrDefault(mock,22), 22); }
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkNotNull(node.getCredentials().credential, "no credential found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkNotNull(node.getCredentials().credential, "no credential found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkArgument(node.getCredentials().credential != null || sshFactory.isAgentAvailable(), "no credential or ssh agent found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkArgument(node.getCredentials().credential != null || sshFactory.isAgentAvailable(), "no credential or ssh agent found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
public void testVirtualMachineToNodeMetadata() { NodeMetadata node = function.apply(container); assertEquals(node.getId(), "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9"); assertEquals(node.getGroup(), "hopeful_mclean"); assertEquals(node.getImageId(), "af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6"); assertEquals(node.getLoginPort(), 49199); assertEquals(node.getStatus(), NodeMetadata.Status.RUNNING); assertEquals(node.getImageId(), "af0f59f1c19eef9471c3b8c8d587c39b8f130560b54f3766931b37d76d5de4b6"); assertEquals(node.getPrivateAddresses(), ImmutableSet.of("172.17.0.2")); assertEquals(node.getPublicAddresses(), ImmutableSet.of("127.0.0.1")); }
String getPublicHostname(NodeMetadata node, ConfigBag setup) { String provider = (setup != null) ? setup.get(CLOUD_PROVIDER) : null; if (provider == null) provider= getProvider(); if ("aws-ec2".equals(provider)) { String vmIp = null; try { vmIp = JcloudsUtil.getFirstReachableAddress(this.getComputeService().getContext(), node); } catch (Exception e) { LOG.warn("Error reaching aws-ec2 instance "+node.getId()+"@"+node.getLocation()+" on port "+node.getLoginPort()+"; falling back to jclouds metadata for address", e); } if (vmIp != null) { try { return getPublicHostnameAws(vmIp, setup); } catch (Exception e) { LOG.warn("Error querying aws-ec2 instance instance "+node.getId()+"@"+node.getLocation()+" over ssh for its hostname; falling back to first reachable IP", e); return vmIp; } } } return getPublicHostnameGeneric(node, setup); }
IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), node.getLoginPort()); if (socketTester.apply(socket)) { System.out.printf("<< socket ready [%s] node(%s)%n", socket, node.getId());
private static void assertNodeEquals(NodeMetadata actual, NodeMetadata expected) { assertEquals(actual, expected); // NodeMetadata equals method does not use all fields in equals. It assumes that same ids in same locations // determine the equivalence assertEquals(actual.getStatus(), expected.getStatus()); assertEquals(actual.getBackendStatus(), expected.getBackendStatus()); assertEquals(actual.getLoginPort(), expected.getLoginPort()); assertEquals(actual.getPublicAddresses(), expected.getPublicAddresses()); assertEquals(actual.getPrivateAddresses(), expected.getPrivateAddresses()); assertEquals(actual.getCredentials(), expected.getCredentials()); assertEquals(actual.getGroup(), expected.getGroup()); assertEquals(actual.getImageId(), expected.getImageId()); assertEquals(actual.getHardware(), expected.getHardware()); assertEquals(actual.getOperatingSystem(), expected.getOperatingSystem()); assertEquals(actual.getHostname(), expected.getHostname()); }
@Override public NodeMetadata apply(@Nullable org.jclouds.compute.domain.NodeMetadata input) { if (input == null) { return null; } return NodeMetadata.builder().id(input.getId()).name(input.getName()).status(input.getStatus().name()) .hostname(input.getHostname()) .loginPort(input.getLoginPort()).group(input.getGroup()) .tags(input.getTags()).metadata(input.getUserMetadata()) .locationId(input.getLocation() != null ? input.getLocation().getId() : null) .imageId(input.getImageId()) .defaultCredentials(ToLoginCredentials.INSTANCE.apply(input.getCredentials())).build(); } }
assertEquals(node.getLoginPort(), 49199); assertEquals(node.getPrivateAddresses(), ImmutableSet.of("172.17.0.2", "172.19.0.2")); assertEquals(node.getPublicAddresses(), ImmutableSet.of("127.0.0.1"));
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }