Issue 487:Add hostname property to nodemetadata

This commit is contained in:
Adrian Cole 2011-07-22 21:21:33 +10:00
parent acd4b4a628
commit 6928082674
19 changed files with 258 additions and 101 deletions

View File

@ -79,6 +79,7 @@ public class NodeToNodeMetadata implements Function<Node, NodeMetadata> {
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());

View File

@ -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

View File

@ -108,6 +108,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
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());

View File

@ -72,9 +72,19 @@ 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());
@ -93,9 +103,18 @@ 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());
@ -116,11 +135,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").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());
@ -140,15 +169,30 @@ 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());

View File

@ -91,6 +91,9 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
builder.id(instance.getRegion() + "/" + instance.getId());
String group = getGroupForInstance(instance);
builder.group(group);
// standard convention from aws-ec2, which might not be re-used outside.
if (instance.getPrivateDnsName() != null)
builder.hostname(instance.getPrivateDnsName().replaceAll("\\..*", ""));
addCredentialsForInstance(builder, instance);
builder.state(instanceToNodeState.get(instance.getInstanceState()));
builder.publicAddresses(NullSafeCollections.nullSafeSet(instance.getIpAddress()));

View File

@ -80,10 +80,12 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).publicAddresses(
ImmutableSet.<String> 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.<String> 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.<String> 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.<String> 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) {

View File

@ -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
}
}

View File

@ -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<VApp, NodeMetadata> {
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));

View File

@ -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<String> ips = ImmutableSet.<String> 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

View File

@ -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);
}
}

View File

@ -76,6 +76,8 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
builder.ids(from.getHref().toASCIIString());
builder.uri(from.getHref());
builder.name(from.getName());
//terremark
builder.hostname(from.getName());
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
builder.group(parseGroupFromName(from.getName()));
if (from.getOsType() != null && OSType.fromValue(from.getOsType()) != OSType.UNRECOGNIZED) {

View File

@ -33,6 +33,16 @@ import com.google.inject.ImplementedBy;
*/
@ImplementedBy(NodeMetadataImpl.class)
public interface NodeMetadata extends ComputeMetadata {
/**
* <h4>note</h4> 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
@ -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();
/**

View File

@ -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());
}
}

View File

@ -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;

View File

@ -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());

View File

@ -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<? extends NodeMetadata> 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<? extends NodeMetadata, ExecResponse> responses = runScriptWithCreds(group, os, new Credentials(
good.identity, "romeo"));
@ -257,33 +258,37 @@ public abstract class BaseComputeServiceLiveTest {
}
for (Entry<? extends NodeMetadata, ExecResponse> 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());

View File

@ -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();

View File

@ -102,6 +102,7 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
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() + "");

View File

@ -70,9 +70,11 @@ 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)
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());
}
@ -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,11 +112,18 @@ public class SliceToNodeMetadataTest {
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> 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)
.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());
}
@ -128,15 +139,27 @@ public class SliceToNodeMetadataTest {
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> 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)
.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());
}
}