Issue 660:null group on nodes from aws-ec2 provider

This commit is contained in:
Adrian Cole 2011-08-16 09:26:25 -07:00
parent 802f813663
commit ccb3d84133
5 changed files with 279 additions and 25 deletions

View File

@ -29,6 +29,7 @@ import javax.annotation.Nullable;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
@ -108,11 +109,12 @@ public class RunningInstanceToNodeMetadataTest {
ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
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());
NodeMetadata expected = 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();
assertEquals(parser.apply(server), expected);
}
@Test

View File

@ -120,10 +120,10 @@ public abstract class BaseAWSReservationHandler<T> extends HandlerForGeneratedRe
} else if (equalsOrSuffix(qName, "groupName")) {
switch (itemDepth) {
case 2:
builder.securityGroupIdToName(groupId, currentOrNull(currentText));
reservationGroupIdToNames.put(groupId, currentOrNull(currentText));
break;
case 3:
reservationGroupIdToNames.put(groupId, currentOrNull(currentText));
builder.securityGroupIdToName(groupId, currentOrNull(currentText));
break;
}
groupId = null;

View File

@ -0,0 +1,157 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.compute.functions;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.Set;
import org.jclouds.aws.ec2.domain.AWSRunningInstance;
import org.jclouds.aws.ec2.domain.MonitoringState;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.date.DateService;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule;
import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.domain.Attachment;
import org.jclouds.ec2.domain.BlockDevice;
import org.jclouds.ec2.domain.InstanceState;
import org.jclouds.ec2.domain.RootDeviceType;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class AWSRunningInstanceToNodeMetadataTest {
private static final String defaultRegion = "us-east-1";
static Location provider = new LocationBuilder().scope(LocationScope.REGION).id(defaultRegion).description(
defaultRegion).build();
private DateService dateService;
@BeforeTest
protected void setUpInjector() {
dateService = Guice.createInjector().getInstance(DateService.class);
assert dateService != null;
}
@Test
public void test2Nodes() {
AWSRunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
ImmutableSet<AWSRunningInstance> contents = ImmutableSet.of(new AWSRunningInstance.Builder()
.region(defaultRegion).instanceId("i-911444f0").imageId("ami-63be790a").instanceState(
InstanceState.RUNNING).privateDnsName("ip-10-212-81-7.ec2.internal").dnsName(
"ec2-174-129-173-155.compute-1.amazonaws.com").keyName("jclouds#zkclustertest#us-east-1#23")
.amiLaunchIndex("0").instanceType("t1.micro").launchTime(
dateService.iso8601DateParse("2011-08-16T13:40:50.000Z")).availabilityZone("us-east-1c")
.kernelId("aki-427d952b").monitoringState(MonitoringState.DISABLED).privateIpAddress("10.212.81.7")
.ipAddress("174.129.173.155").securityGroupIdToNames(
ImmutableMap.<String, String> of("sg-ef052b86", "jclouds#zkclustertest#us-east-1"))
.rootDeviceType(RootDeviceType.EBS).rootDeviceName("/dev/sda1").device(
"/dev/sda1",
new BlockDevice("vol-5829fc32", Attachment.Status.ATTACHED, dateService
.iso8601DateParse("2011-08-16T13:41:19.000Z"), true))
.virtualizationType("paravirtual").build(),//
new AWSRunningInstance.Builder().region(defaultRegion).instanceId("i-931444f2").imageId("ami-63be790a")
.instanceState(InstanceState.RUNNING).privateDnsName("ip-10-212-185-8.ec2.internal").dnsName(
"ec2-50-19-207-248.compute-1.amazonaws.com").keyName(
"jclouds#zkclustertest#us-east-1#23").amiLaunchIndex("0").instanceType("t1.micro")
.launchTime(dateService.iso8601DateParse("2011-08-16T13:40:50.000Z")).availabilityZone(
"us-east-1c").kernelId("aki-427d952b").monitoringState(MonitoringState.DISABLED)
.privateIpAddress("10.212.185.8").ipAddress("50.19.207.248").securityGroupIdToNames(
ImmutableMap.<String, String> of("sg-ef052b86", "jclouds#zkclustertest#us-east-1"))
.rootDeviceType(RootDeviceType.EBS).rootDeviceName("/dev/sda1").device(
"/dev/sda1",
new BlockDevice("vol-5029fc3a", Attachment.Status.ATTACHED, dateService
.iso8601DateParse("2011-08-16T13:41:19.000Z"), true)).virtualizationType(
"paravirtual").build());
assertEquals(parser.apply(Iterables.get(contents, 0)), new NodeMetadataBuilder().state(NodeState.RUNNING).group(
"zkclustertest").hostname("ip-10-212-81-7").privateAddresses(ImmutableSet.of("10.212.81.7"))
.publicAddresses(ImmutableSet.of("174.129.173.155")).imageId("us-east-1/ami-63be790a").id(
"us-east-1/i-911444f0").providerId("i-911444f0").build());
assertEquals(parser.apply(Iterables.get(contents, 1)), new NodeMetadataBuilder().state(NodeState.RUNNING).group(
"zkclustertest").hostname("ip-10-212-185-8").privateAddresses(ImmutableSet.of("10.212.185.8"))
.publicAddresses(ImmutableSet.of("50.19.207.248")).imageId("us-east-1/ami-63be790a").id(
"us-east-1/i-931444f2").providerId("i-931444f2").build());
}
protected AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
final ImmutableSet<Location> locations, Set<org.jclouds.compute.domain.Image> images,
Map<String, Credentials> credentialStore) {
Map<InstanceState, NodeState> instanceToNodeState = EC2ComputeServiceDependenciesModule.instanceToNodeState;
Map<RegionAndName, Image> instanceToImage = Maps.uniqueIndex(images, new Function<Image, RegionAndName>() {
@Override
public RegionAndName apply(Image from) {
return new RegionAndName(from.getLocation().getId(), from.getProviderId());
}
});
return createNodeParser(hardware, locations, credentialStore, instanceToNodeState, instanceToImage);
}
private AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
final ImmutableSet<Location> locations, Map<String, Credentials> credentialStore,
Map<InstanceState, NodeState> instanceToNodeState, Map<RegionAndName, Image> instanceToImage) {
Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() {
@Override
public Set<? extends Location> get() {
return locations;
}
};
Supplier<Set<? extends Hardware>> hardwareSupplier = new Supplier<Set<? extends Hardware>>() {
@Override
public Set<? extends Hardware> get() {
return hardware;
}
};
AWSRunningInstanceToNodeMetadata parser = new AWSRunningInstanceToNodeMetadata(instanceToNodeState,
credentialStore, instanceToImage, locationSupplier, hardwareSupplier);
return parser;
}
}

View File

@ -41,6 +41,7 @@ import org.jclouds.location.Region;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
@ -84,6 +85,49 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
assertEquals(result.toString(), contents.toString());
}
public void testWhenRunningLatest() throws UnknownHostException {
Set<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(new Reservation<AWSRunningInstance>(
defaultRegion, ImmutableSet.of("jclouds#ec2-s#us-east-1"), ImmutableSet.of(
new AWSRunningInstance.Builder().region(defaultRegion).instanceId("i-911444f0").imageId(
"ami-63be790a").instanceState(InstanceState.RUNNING).privateDnsName(
"ip-10-212-81-7.ec2.internal").dnsName("ec2-174-129-173-155.compute-1.amazonaws.com")
.keyName("jclouds#zkclustertest#us-east-1#23").amiLaunchIndex("0").instanceType(
"t1.micro").launchTime(
dateService.iso8601DateParse("2011-08-16T13:40:50.000Z")).availabilityZone(
"us-east-1c").kernelId("aki-427d952b").monitoringState(
MonitoringState.DISABLED).privateIpAddress("10.212.81.7").ipAddress(
"174.129.173.155").securityGroupIdToNames(
ImmutableMap.<String, String> of("sg-ef052b86",
"jclouds#zkclustertest#us-east-1")).rootDeviceType(
RootDeviceType.EBS).rootDeviceName("/dev/sda1").device(
"/dev/sda1",
new BlockDevice("vol-5829fc32", Attachment.Status.ATTACHED, dateService
.iso8601DateParse("2011-08-16T13:41:19.000Z"), true))
.virtualizationType("paravirtual").build(),//
new AWSRunningInstance.Builder().region(defaultRegion).instanceId("i-931444f2").imageId(
"ami-63be790a").instanceState(InstanceState.RUNNING).privateDnsName(
"ip-10-212-185-8.ec2.internal").dnsName("ec2-50-19-207-248.compute-1.amazonaws.com")
.keyName("jclouds#zkclustertest#us-east-1#23").amiLaunchIndex("0").instanceType(
"t1.micro").launchTime(
dateService.iso8601DateParse("2011-08-16T13:40:50.000Z")).availabilityZone(
"us-east-1c").kernelId("aki-427d952b").monitoringState(
MonitoringState.DISABLED).privateIpAddress("10.212.185.8").ipAddress(
"50.19.207.248").securityGroupIdToNames(
ImmutableMap.<String, String> of("sg-ef052b86",
"jclouds#zkclustertest#us-east-1")).rootDeviceType(
RootDeviceType.EBS).rootDeviceName("/dev/sda1").device(
"/dev/sda1",
new BlockDevice("vol-5029fc3a", Attachment.Status.ATTACHED, dateService
.iso8601DateParse("2011-08-16T13:41:19.000Z"), true))
.virtualizationType("paravirtual").build()), defaultRegion, defaultRegion,
defaultRegion));
Set<Reservation<? extends RunningInstance>> result = parseAWSRunningInstances("/describe_instances_latest.xml");
assertEquals(result.toString(), contents.toString());
}
public void testParseNoNPE() {
parseAWSRunningInstances("/describe_instances_1.xml");

View File

@ -1,33 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>e32bb361-415e-484b-8651-5fd0c0a85fab</requestId>
<requestId>a03c1896-0543-485f-a732-ebc83873a3ca</requestId>
<reservationSet>
<item>
<reservationId>r-6d62c002</reservationId>
<reservationId>r-0f4c2160</reservationId>
<ownerId>993194456877</ownerId>
<groupSet>
<item>
<groupId>sg-1f1c3976</groupId>
<groupName>jclouds#ec2-s#us-east-1</groupName>
<groupId>sg-ef052b86</groupId>
<groupName>jclouds#zkclustertest#us-east-1</groupName>
</item>
</groupSet>
<instancesSet>
<item>
<instanceId>i-5f833d3e</instanceId>
<imageId>ami-8e1fece7</imageId>
<instanceId>i-911444f0</instanceId>
<imageId>ami-63be790a</imageId>
<instanceState>
<code>16</code>
<name>running</name>
</instanceState>
<privateDnsName>domU-12-31-38-04-25-D8.compute-1.internal</privateDnsName>
<dnsName>ec2-50-16-149-221.compute-1.amazonaws.com</dnsName>
<privateDnsName>ip-10-212-81-7.ec2.internal</privateDnsName>
<dnsName>ec2-174-129-173-155.compute-1.amazonaws.com</dnsName>
<reason/>
<keyName>jclouds#ec2-s#us-east-1#38</keyName>
<keyName>jclouds#zkclustertest#us-east-1#23</keyName>
<amiLaunchIndex>0</amiLaunchIndex>
<productCodes/>
<instanceType>t1.micro</instanceType>
<launchTime>2011-07-29T04:08:19.000Z</launchTime>
<launchTime>2011-08-16T13:40:50.000Z</launchTime>
<placement>
<availabilityZone>us-east-1d</availabilityZone>
<availabilityZone>us-east-1c</availabilityZone>
<groupName/>
<tenancy>default</tenancy>
</placement>
@ -35,12 +36,12 @@
<monitoring>
<state>disabled</state>
</monitoring>
<privateIpAddress>10.220.38.38</privateIpAddress>
<ipAddress>50.16.149.221</ipAddress>
<privateIpAddress>10.212.81.7</privateIpAddress>
<ipAddress>174.129.173.155</ipAddress>
<groupSet>
<item>
<groupId>sg-1f1c3976</groupId>
<groupName>jclouds#ec2-s#us-east-1</groupName>
<groupId>sg-ef052b86</groupId>
<groupName>jclouds#zkclustertest#us-east-1</groupName>
</item>
</groupSet>
<architecture>x86_64</architecture>
@ -50,9 +51,59 @@
<item>
<deviceName>/dev/sda1</deviceName>
<ebs>
<volumeId>vol-4bc3da20</volumeId>
<volumeId>vol-5829fc32</volumeId>
<status>attached</status>
<attachTime>2011-07-29T04:08:40.000Z</attachTime>
<attachTime>2011-08-16T13:41:19.000Z</attachTime>
<deleteOnTermination>true</deleteOnTermination>
</ebs>
</item>
</blockDeviceMapping>
<virtualizationType>paravirtual</virtualizationType>
<clientToken/>
<hypervisor>xen</hypervisor>
</item>
<item>
<instanceId>i-931444f2</instanceId>
<imageId>ami-63be790a</imageId>
<instanceState>
<code>16</code>
<name>running</name>
</instanceState>
<privateDnsName>ip-10-212-185-8.ec2.internal</privateDnsName>
<dnsName>ec2-50-19-207-248.compute-1.amazonaws.com</dnsName>
<reason/>
<keyName>jclouds#zkclustertest#us-east-1#23</keyName>
<amiLaunchIndex>1</amiLaunchIndex>
<productCodes/>
<instanceType>t1.micro</instanceType>
<launchTime>2011-08-16T13:40:50.000Z</launchTime>
<placement>
<availabilityZone>us-east-1c</availabilityZone>
<groupName/>
<tenancy>default</tenancy>
</placement>
<kernelId>aki-427d952b</kernelId>
<monitoring>
<state>disabled</state>
</monitoring>
<privateIpAddress>10.212.185.8</privateIpAddress>
<ipAddress>50.19.207.248</ipAddress>
<groupSet>
<item>
<groupId>sg-ef052b86</groupId>
<groupName>jclouds#zkclustertest#us-east-1</groupName>
</item>
</groupSet>
<architecture>x86_64</architecture>
<rootDeviceType>ebs</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<blockDeviceMapping>
<item>
<deviceName>/dev/sda1</deviceName>
<ebs>
<volumeId>vol-5029fc3a</volumeId>
<status>attached</status>
<attachTime>2011-08-16T13:41:19.000Z</attachTime>
<deleteOnTermination>true</deleteOnTermination>
</ebs>
</item>
@ -64,4 +115,4 @@
</instancesSet>
</item>
</reservationSet>
</DescribeInstancesResponse>
</DescribeInstancesResponse>