From 6928082674cc81fb17de1cdddc5f9b95c4247cbb Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 22 Jul 2011 21:21:33 +1000 Subject: [PATCH] Issue 487:Add hostname property to nodemetadata --- .../byon/functions/NodeToNodeMetadata.java | 1 + .../functions/NodeToNodeMetadataTest.java | 17 ++-- .../functions/ServerToNodeMetadata.java | 1 + .../functions/ServerToNodeMetadataTest.java | 96 ++++++++++++++----- .../RunningInstanceToNodeMetadata.java | 3 + .../RunningInstanceToNodeMetadataTest.java | 73 ++++++++------ .../ElasticStackComputeServiceLiveTest.java | 9 ++ .../compute/functions/VAppToNodeMetadata.java | 3 + .../compute/util/VCloudComputeUtils.java | 16 +++- .../functions/VAppToNodeMetadataTest.java | 3 + .../VCloudExpressVAppToNodeMetadata.java | 2 + .../jclouds/compute/domain/NodeMetadata.java | 13 ++- .../compute/domain/NodeMetadataBuilder.java | 11 ++- .../domain/internal/NodeMetadataImpl.java | 6 ++ .../config/StubComputeServiceAdapter.java | 2 + .../compute/BaseComputeServiceLiveTest.java | 31 +++--- .../StubComputeServiceIntegrationTest.java | 4 +- .../functions/SliceToNodeMetadata.java | 1 + .../functions/SliceToNodeMetadataTest.java | 67 ++++++++----- 19 files changed, 258 insertions(+), 101 deletions(-) diff --git a/apis/byon/src/main/java/org/jclouds/byon/functions/NodeToNodeMetadata.java b/apis/byon/src/main/java/org/jclouds/byon/functions/NodeToNodeMetadata.java index 8479768062..a3a1982448 100644 --- a/apis/byon/src/main/java/org/jclouds/byon/functions/NodeToNodeMetadata.java +++ b/apis/byon/src/main/java/org/jclouds/byon/functions/NodeToNodeMetadata.java @@ -79,6 +79,7 @@ public class NodeToNodeMetadata implements Function { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId()); builder.name(from.getName()); + builder.hostname(from.getHostname()); builder.location(findLocationWithId(from.getLocationId())); builder.group(from.getGroup()); builder.tags(from.getTags()); diff --git a/apis/byon/src/test/java/org/jclouds/byon/functions/NodeToNodeMetadataTest.java b/apis/byon/src/test/java/org/jclouds/byon/functions/NodeToNodeMetadataTest.java index 3a59c24026..f9bb3b47fb 100644 --- a/apis/byon/src/test/java/org/jclouds/byon/functions/NodeToNodeMetadataTest.java +++ b/apis/byon/src/test/java/org/jclouds/byon/functions/NodeToNodeMetadataTest.java @@ -73,12 +73,17 @@ public class NodeToNodeMetadataTest { } public static NodeMetadata expectedNodeMetadataFromResource(int id, String resource, Location location) { - return new NodeMetadataBuilder().ids("cluster-" + id).group("hadoop").name("cluster-" + id).location(location) - .state(NodeState.RUNNING).operatingSystem( - OperatingSystem.builder().description("redhat").family(OsFamily.RHEL).arch("x86") - .version("5.3").build()).publicAddresses( - ImmutableSet.of("cluster-" + id + ".mydomain.com")).credentials( - new Credentials("myUser", NodesFromYamlTest.key)).adminPassword("happy bear").build(); + return new NodeMetadataBuilder() + .ids("cluster-" + id) + .group("hadoop") + .name("cluster-" + id) + .hostname("cluster-" + id + ".mydomain.com") + .location(location) + .state(NodeState.RUNNING) + .operatingSystem( + OperatingSystem.builder().description("redhat").family(OsFamily.RHEL).arch("x86").version("5.3") + .build()).publicAddresses(ImmutableSet.of("cluster-" + id + ".mydomain.com")) + .credentials(new Credentials("myUser", NodesFromYamlTest.key)).adminPassword("happy bear").build(); } @Test diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadata.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadata.java index 2e04c9a342..078e8cb58d 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadata.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadata.java @@ -108,6 +108,7 @@ public class ServerToNodeMetadata implements Function { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); + builder.hostname(from.getName()); builder.location(new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()).description( from.getHostId()).parent(location.get()).build()); builder.userMetadata(from.getMetadata()); diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java index b0ff294d83..5a4cb7ef72 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/compute/functions/ServerToNodeMetadataTest.java @@ -72,12 +72,22 @@ public class ServerToNodeMetadataTest { NodeMetadata metadata = parser.apply(server); - assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( - ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")) - .imageId("2").id("1234").providerId("1234").name("sample-server").credentials(creds).location( + assertEquals( + metadata, + new NodeMetadataBuilder() + .state(NodeState.PENDING) + .publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131")) + .privateAddresses(ImmutableSet.of("10.176.42.16")) + .imageId("2") + .id("1234") + .providerId("1234") + .name("sample-server") + .hostname("sample-server") + .credentials(creds) + .location( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0") - .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()) - .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } @Test @@ -93,12 +103,21 @@ public class ServerToNodeMetadataTest { NodeMetadata metadata = parser.apply(server); - assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( - ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")) - .imageId("2").id("1234").providerId("1234").name("sample-server").location( + assertEquals( + metadata, + new NodeMetadataBuilder() + .state(NodeState.PENDING) + .publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131")) + .privateAddresses(ImmutableSet.of("10.176.42.16")) + .imageId("2") + .id("1234") + .providerId("1234") + .name("sample-server") + .hostname("sample-server") + .location( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0") - .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()) - .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } @@ -116,14 +135,24 @@ public class ServerToNodeMetadataTest { NodeMetadata metadata = parser.apply(server); - assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( - ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")) - .imageId("2").operatingSystem( + assertEquals( + metadata, + new NodeMetadataBuilder() + .state(NodeState.PENDING) + .publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131")) + .privateAddresses(ImmutableSet.of("10.176.42.16")) + .imageId("2") + .operatingSystem( new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2") - .is64Bit(true).build()).id("1234").providerId("1234").name("sample-server").location( + .is64Bit(true).build()) + .id("1234") + .providerId("1234") + .name("sample-server") + .hostname("sample-server") + .location( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0") - .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()) - .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } @@ -140,17 +169,32 @@ public class ServerToNodeMetadataTest { NodeMetadata metadata = parser.apply(server); - assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( - ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")) - .imageId("2").hardware( - new HardwareBuilder().ids("1").name("256 MB Server").processors( - ImmutableList.of(new Processor(1.0, 1.0))).ram(256).volumes( - ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true) - .bootDevice(true).build())).build()).operatingSystem( + assertEquals( + metadata, + new NodeMetadataBuilder() + .state(NodeState.PENDING) + .publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131")) + .privateAddresses(ImmutableSet.of("10.176.42.16")) + .imageId("2") + .hardware( + new HardwareBuilder() + .ids("1") + .name("256 MB Server") + .processors(ImmutableList.of(new Processor(1.0, 1.0))) + .ram(256) + .volumes( + ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f) + .durable(true).bootDevice(true).build())).build()) + .operatingSystem( new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2") - .is64Bit(true).build()).id("1234").providerId("1234").name("sample-server").location( + .is64Bit(true).build()) + .id("1234") + .providerId("1234") + .name("sample-server") + .hostname("sample-server") + .location( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0") - .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()) - .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + .description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java index 9e3857b212..a9a85e3dd1 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -91,6 +91,9 @@ public class RunningInstanceToNodeMetadata implements Function of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses( - ImmutableSet.of("174.129.81.68")).credentials(creds).imageId("us-east-1/ami-82e4b5c7").id( - "us-east-1/i-0799056f").providerId("i-0799056f").build()); + assertEquals( + parser.apply(server), + new NodeMetadataBuilder().state(NodeState.RUNNING).hostname("ip-10-243-42-70") + .publicAddresses(ImmutableSet. of()).privateAddresses(ImmutableSet.of("10.243.42.70")) + .publicAddresses(ImmutableSet.of("174.129.81.68")).credentials(creds) + .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").build()); } @Test @@ -93,10 +95,11 @@ public class RunningInstanceToNodeMetadataTest { RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); - assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).publicAddresses( - ImmutableSet. of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses( - ImmutableSet.of("174.129.81.68")).imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f") - .providerId("i-0799056f").build()); + assertEquals(parser.apply(server), + new NodeMetadataBuilder().hostname("ip-10-243-42-70").state(NodeState.RUNNING) + .publicAddresses(ImmutableSet. of()).privateAddresses(ImmutableSet.of("10.243.42.70")) + .publicAddresses(ImmutableSet.of("174.129.81.68")).imageId("us-east-1/ami-82e4b5c7") + .id("us-east-1/i-0799056f").providerId("i-0799056f").build()); } @Test @@ -106,9 +109,10 @@ public class RunningInstanceToNodeMetadataTest { RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); - assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses( - ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId( - "us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build()); + assertEquals(parser.apply(server), new NodeMetadataBuilder().hostname("ip-10-243-42-70").state(NodeState.RUNNING) + .privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")) + .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider) + .build()); } @Test @@ -118,12 +122,18 @@ public class RunningInstanceToNodeMetadataTest { RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); - assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses( - ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId( - "us-east-1/ami-82e4b5c7").operatingSystem( - new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description( - "137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f") - .providerId("i-0799056f").location(provider).build()); + assertEquals( + parser.apply(server), + new NodeMetadataBuilder() + .state(NodeState.RUNNING) + .hostname("ip-10-243-42-70") + .privateAddresses(ImmutableSet.of("10.243.42.70")) + .publicAddresses(ImmutableSet.of("174.129.81.68")) + .imageId("us-east-1/ami-82e4b5c7") + .operatingSystem( + new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual") + .description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()) + .id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build()); } @Test @@ -134,12 +144,19 @@ public class RunningInstanceToNodeMetadataTest { RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); - assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses( - ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId( - "us-east-1/ami-82e4b5c7").hardware(m1_small32().build()).operatingSystem( - new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description( - "137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f") - .providerId("i-0799056f").location(provider).build()); + assertEquals( + parser.apply(server), + new NodeMetadataBuilder() + .hostname("ip-10-243-42-70") + .state(NodeState.RUNNING) + .privateAddresses(ImmutableSet.of("10.243.42.70")) + .publicAddresses(ImmutableSet.of("174.129.81.68")) + .imageId("us-east-1/ami-82e4b5c7") + .hardware(m1_small32().build()) + .operatingSystem( + new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual") + .description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()) + .id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build()); } @Test @@ -163,10 +180,12 @@ public class RunningInstanceToNodeMetadataTest { RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml"); - assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses( - ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId( - "us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").hardware( - m1_small32().build()).location(provider).build()); + assertEquals( + parser.apply(server), + new NodeMetadataBuilder().hostname("ip-10-243-42-70").state(NodeState.RUNNING) + .privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")) + .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f") + .hardware(m1_small32().build()).location(provider).build()); } protected RunningInstance firstInstanceFromResource(String resource) { diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java index e5dd95d09c..417dd1311f 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceLiveTest.java @@ -19,6 +19,8 @@ package org.jclouds.elasticstack.compute; import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.testng.annotations.Test; @@ -40,4 +42,11 @@ public class ElasticStackComputeServiceLiveTest extends BaseComputeServiceLiveTe public void testOptionToNotBlock() { // start call is blocking anyway. } + + protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { + assert execResponse.getOutput().trim().equals("ubuntu");// hostname is not + // predicatble + // based on node + // metadata + } } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java index ba998b2391..9cc7cccdc6 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java @@ -24,6 +24,7 @@ import static com.google.common.collect.Iterables.filter; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName; import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom; import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getIpsFromVApp; +import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getVirtualSystemIdentifierOfFirstVMIn; import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.toComputeOs; import java.util.Map; @@ -72,6 +73,8 @@ public class VAppToNodeMetadata implements Function { builder.ids(from.getHref().toASCIIString()); builder.uri(from.getHref()); builder.name(from.getName()); + // not guaranteed to be correct, but good chance + builder.hostname(getVirtualSystemIdentifierOfFirstVMIn(from)); builder.location(findLocationForResourceInVDC.apply(from.getVDC())); builder.group(parseGroupFromName(from.getName())); builder.operatingSystem(toComputeOs(from, null)); diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java index 18f606a2ef..cef45c8a3c 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java @@ -57,6 +57,16 @@ public class VCloudComputeUtils { return CIMOperatingSystem.toComputeOs(vm.getOperatingSystemSection()); } + public static String getVirtualSystemIdentifierOfFirstVMIn(VApp vApp) { + return vApp.getChildren().size() > 0 ? getVirtualSystemIdentifierOf(Iterables.get(vApp.getChildren(), 0)) : null; + } + + public static String getVirtualSystemIdentifierOf(Vm vm) { + if (vm.getVirtualHardwareSection() != null && vm.getVirtualHardwareSection().getSystem() != null) + return vm.getVirtualHardwareSection().getSystem().getVirtualSystemIdentifier(); + return null; + } + public static Credentials getCredentialsFrom(VApp vApp) { return vApp.getChildren().size() > 0 ? getCredentialsFrom(Iterables.get(vApp.getChildren(), 0)) : null; } @@ -83,8 +93,10 @@ public class VCloudComputeUtils { Builder ips = ImmutableSet. builder(); Vm vm = Iterables.get(vApp.getChildren(), 0); // TODO: figure out how to differentiate public from private ip addresses - // assumption is that we'll do this from the network object, which may have - // enough data to tell whether or not it is a public network without string + // assumption is that we'll do this from the network object, which may + // have + // enough data to tell whether or not it is a public network without + // string // parsing. At worst, we could have properties set per cloud provider to // declare the networks which are public, then check against these in // networkconnection.getNetwork diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java index d433e7f3af..0ca83622c3 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadataTest.java @@ -121,6 +121,7 @@ public class VAppToNodeMetadataTest { VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class); NodeMetadata node = converter.apply(result); assertEquals(node.getLocation(), location); + assertEquals(node.getHostname(), "my-app"); assertEquals(node.getPrivateAddresses(), ImmutableSet.of("172.16.7.230")); assertEquals(node.getPublicAddresses(), ImmutableSet.of()); } @@ -135,6 +136,7 @@ public class VAppToNodeMetadataTest { VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class); NodeMetadata node = converter.apply(result); assertEquals(node.getLocation(), location); + assertEquals(node.getHostname(), "Centos-5.5_x64"); assertEquals(node.getPrivateAddresses(), ImmutableSet.of()); assertEquals(node.getPublicAddresses(), ImmutableSet.of()); } @@ -149,6 +151,7 @@ public class VAppToNodeMetadataTest { VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is); VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class); NodeMetadata node = converter.apply(result); + assertEquals(node.getHostname(), ""); assertEquals(node.getLocation(), location); } } diff --git a/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/compute/functions/VCloudExpressVAppToNodeMetadata.java b/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/compute/functions/VCloudExpressVAppToNodeMetadata.java index 3da4e684cf..dbe06bdd11 100644 --- a/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/compute/functions/VCloudExpressVAppToNodeMetadata.java +++ b/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/compute/functions/VCloudExpressVAppToNodeMetadata.java @@ -76,6 +76,8 @@ public class VCloudExpressVAppToNodeMetadata implements Functionnote hostname is something that is set in the operating system + * image, so this value, if present, cannot be guaranteed on images not + * directly controlled by the cloud provider. + * + * @return hostname of the node, or null if unknown + * + */ + @Nullable + String getHostname(); + /** * Tag used for all resources that belong to the same logical group. run, destroy commands are * scoped to group. @@ -41,6 +51,7 @@ public interface NodeMetadata extends ComputeMetadata { * @return group for this node, or null, if not a part of a group * */ + @Nullable String getGroup(); /** diff --git a/compute/src/main/java/org/jclouds/compute/domain/NodeMetadataBuilder.java b/compute/src/main/java/org/jclouds/compute/domain/NodeMetadataBuilder.java index 17cf4507cb..d2873a2833 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/NodeMetadataBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/domain/NodeMetadataBuilder.java @@ -53,6 +53,8 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder { private Hardware hardware; @Nullable private OperatingSystem os; + @Nullable + private String hostname; public NodeMetadataBuilder() { super(ComputeType.NODE); @@ -108,6 +110,11 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder { return this; } + public NodeMetadataBuilder hostname(String hostname) { + this.hostname = hostname; + return this; + } + @Override public NodeMetadataBuilder id(String id) { return NodeMetadataBuilder.class.cast(super.id(id)); @@ -151,7 +158,7 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder { @Override public NodeMetadata build() { return new NodeMetadataImpl(providerId, name, id, location, uri, userMetadata, tags, group, hardware, imageId, - os, state, loginPort, publicAddresses, privateAddresses, adminPassword, credentials); + os, state, loginPort, publicAddresses, privateAddresses, adminPassword, credentials, hostname); } public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { @@ -160,7 +167,7 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder { node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).state(node.getState()).loginPort(node.getLoginPort()).publicAddresses( node.getPublicAddresses()).privateAddresses(node.getPrivateAddresses()).adminPassword( - node.getAdminPassword()).credentials(node.getCredentials()); + node.getAdminPassword()).credentials(node.getCredentials()).hostname(node.getHostname()); } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java index 20c532bf07..1d1f60a187 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java @@ -197,6 +197,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode()); result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode()); result = prime * result + ((group == null) ? 0 : group.hashCode()); + result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); result = prime * result + ((imageId == null) ? 0 : imageId.hashCode()); result = prime * result + ((hardware == null) ? 0 : hardware.hashCode()); result = prime * result + ((os == null) ? 0 : os.hashCode()); @@ -226,6 +227,11 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat return false; } else if (!publicAddresses.equals(other.publicAddresses)) return false; + if (hostname == null) { + if (other.hostname != null) + return false; + } else if (!hostname.equals(other.hostname)) + return false; if (group == null) { if (other.group != null) return false; diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java index cebdfa18f0..4dbd37dde9 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java @@ -89,6 +89,8 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda String id = idProvider.get() + ""; builder.ids(id); builder.name(name); + // using a predictable name so tests will pass + builder.hostname(group); builder.tags(template.getOptions().getTags()); builder.group(group); builder.location(location.get()); diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 6870b90e04..dda6b803d6 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -51,11 +51,11 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.Collection; import java.util.Map; +import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Properties; import java.util.Set; import java.util.SortedSet; -import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -243,11 +243,12 @@ public abstract class BaseComputeServiceLiveTest { TemplateOptions options = client.templateOptions().blockOnPort(22, 120); try { Set nodes = client.createNodesInGroup(group, 1, options); - Credentials good = nodes.iterator().next().getCredentials(); + NodeMetadata node = get(nodes, 0); + Credentials good = node.getCredentials(); assert good.identity != null : nodes; assert good.credential != null : nodes; - - OperatingSystem os = get(nodes, 0).getOperatingSystem(); + + OperatingSystem os = node.getOperatingSystem(); try { Map responses = runScriptWithCreds(group, os, new Credentials( good.identity, "romeo")); @@ -257,33 +258,37 @@ public abstract class BaseComputeServiceLiveTest { } for (Entry response : client.runScriptOnNodesMatching( - runningInGroup(group), Statements.exec("echo hello"), - overrideCredentialsWith(good).wrapInInitScript(false).runAsRoot(false)).entrySet()) - assert response.getValue().getOutput().trim().equals("hello") : response.getKey() + ": " - + response.getValue(); + runningInGroup(group), Statements.exec("hostname"), + overrideCredentialsWith(good).wrapInInitScript(false).runAsRoot(false)).entrySet()){ + checkResponseEqualsHostname(response.getValue(), response.getKey()); + } // test single-node execution - ExecResponse response = client.runScriptOnNode(get(nodes, 0).getId(), "echo hello", wrapInInitScript(false) + ExecResponse response = client.runScriptOnNode(node.getId(), "hostname", wrapInInitScript(false) .runAsRoot(false)); - assert response.getOutput().trim().equals("hello") : get(nodes, 0).getId() + ": " + response; + checkResponseEqualsHostname(response, node); runScriptWithCreds(group, os, good); checkNodes(nodes, group); // test adding AdminAccess later changes the default boot user, in this case to foo - response = client.runScriptOnNode(get(nodes, 0).getId(), AdminAccess.builder().adminUsername("foo").build(), nameTask("adminUpdate")); + response = client.runScriptOnNode(node.getId(), AdminAccess.builder().adminUsername("foo").build(), nameTask("adminUpdate")); - response = client.runScriptOnNode(get(nodes, 0).getId(), "echo $USER", wrapInInitScript(false) + response = client.runScriptOnNode(node.getId(), "echo $USER", wrapInInitScript(false) .runAsRoot(false)); - assert response.getOutput().trim().equals("foo") : get(nodes, 0).getId() + ": " + response; + assert response.getOutput().trim().equals("foo") : node.getId() + ": " + response; } finally { client.destroyNodesMatching(inGroup(group)); } } + protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { + assert execResponse.getOutput().trim().equals(node1.getHostname()) : node1 + ": " + execResponse; + } + @Test(enabled = true, dependsOnMethods = { "testImagesCache" }) public void testTemplateMatch() throws Exception { template = buildTemplate(client.templateBuilder()); diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index 12739b02c2..21273d7e78 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -158,12 +158,12 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes // run script without backgrounding (via predicate) client2.connect(); - expect(client2.exec("echo hello\n")).andReturn(new ExecResponse("hello\n", "", 0)); + expect(client2.exec("hostname\n")).andReturn(new ExecResponse("stub-r\n", "", 0)); client2.disconnect(); // run script without backgrounding (via id) client2.connect(); - expect(client2.exec("echo hello\n")).andReturn(new ExecResponse("hello\n", "", 0)); + expect(client2.exec("hostname\n")).andReturn(new ExecResponse("stub-r\n", "", 0)); client2.disconnect(); client2.connect(); diff --git a/providers/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadata.java b/providers/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadata.java index 3a2b1cceda..beff4d8c88 100644 --- a/providers/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadata.java +++ b/providers/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadata.java @@ -102,6 +102,7 @@ public class SliceToNodeMetadata implements Function { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); + builder.hostname(from.getName()); builder.location(location.get()); builder.group(parseGroupFromName(from.getName())); builder.imageId(from.getImageId() + ""); diff --git a/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadataTest.java b/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadataTest.java index be9f664484..cf5214f82b 100644 --- a/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadataTest.java +++ b/providers/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SliceToNodeMetadataTest.java @@ -70,10 +70,12 @@ public class SliceToNodeMetadataTest { NodeMetadata metadata = parser.apply(slice); - assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( - ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds") - .imageId("2").id("1").providerId("1").name("jclouds-foo").location(provider).credentials(creds) - .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + assertEquals( + metadata, + new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(ImmutableSet.of("174.143.212.229")) + .privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds").imageId("2").id("1") + .providerId("1").name("jclouds-foo").hostname("jclouds-foo").location(provider).credentials(creds) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } @Test @@ -89,10 +91,12 @@ public class SliceToNodeMetadataTest { NodeMetadata metadata = parser.apply(slice); - assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( - ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds") - .imageId("2").id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata( - ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + assertEquals( + metadata, + new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(ImmutableSet.of("174.143.212.229")) + .privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds").imageId("2").id("1") + .providerId("1").name("jclouds-foo").hostname("jclouds-foo").location(provider) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } @Test @@ -108,12 +112,19 @@ public class SliceToNodeMetadataTest { .ofInstance(provider), Suppliers.> ofInstance(hardwares)); NodeMetadata metadata = parser.apply(slice); - assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( - ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds") - .imageId("2").operatingSystem( + assertEquals( + metadata, + new NodeMetadataBuilder() + .state(NodeState.PENDING) + .publicAddresses(ImmutableSet.of("174.143.212.229")) + .privateAddresses(ImmutableSet.of("10.176.164.199")) + .group("jclouds") + .imageId("2") + .operatingSystem( new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2") - .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").location(provider) - .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo") + .hostname("jclouds-foo").location(provider) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } @Test @@ -128,15 +139,27 @@ public class SliceToNodeMetadataTest { .ofInstance(provider), Suppliers.> ofInstance(hardwares)); NodeMetadata metadata = parser.apply(slice); - assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses( - ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds") - .imageId("2").hardware( - new HardwareBuilder().ids("1").name("256 slice").processors( - ImmutableList.of(new Processor(0.25, 1.0))).ram(256).volumes( - ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f).durable(true) - .bootDevice(true).build())).build()).operatingSystem( + assertEquals( + metadata, + new NodeMetadataBuilder() + .state(NodeState.PENDING) + .publicAddresses(ImmutableSet.of("174.143.212.229")) + .privateAddresses(ImmutableSet.of("10.176.164.199")) + .group("jclouds") + .imageId("2") + .hardware( + new HardwareBuilder() + .ids("1") + .name("256 slice") + .processors(ImmutableList.of(new Processor(0.25, 1.0))) + .ram(256) + .volumes( + ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f) + .durable(true).bootDevice(true).build())).build()) + .operatingSystem( new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2") - .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").location(provider) - .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); + .is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo") + .hostname("jclouds-foo").location(provider) + .userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build()); } } \ No newline at end of file