mirror of https://github.com/apache/jclouds.git
Issue 27: workaround for when availabilityZone is null in eucalyptus
This commit is contained in:
parent
c3e44cb7af
commit
d2b145b470
|
@ -121,7 +121,7 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
hardware = ComputeServiceUtils.replacesVolumes(hardware, addEBS(instance, hardware.getVolumes()));
|
||||
}
|
||||
|
||||
Location location = getLocationForAvailabilityZone(instance);
|
||||
Location location = getLocationForAvailabilityZoneOrRegion(instance);
|
||||
|
||||
Image image = resolveImageForInstanceInLocation(instance, location);
|
||||
|
||||
|
@ -206,8 +206,14 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
}
|
||||
}
|
||||
|
||||
private Location getLocationForAvailabilityZone(final RunningInstance instance) {
|
||||
final String locationId = instance.getAvailabilityZone();
|
||||
private Location getLocationForAvailabilityZoneOrRegion(final RunningInstance instance) {
|
||||
Location location = findLocationWithId(instance.getAvailabilityZone());
|
||||
if (location == null)
|
||||
location = findLocationWithId(instance.getRegion());
|
||||
return location;
|
||||
}
|
||||
|
||||
private Location findLocationWithId(final String locationId) {
|
||||
try {
|
||||
Location location = Iterables.find(locations.get(), new Predicate<Location>() {
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
this.keyName = keyName;
|
||||
this.launchTime = checkNotNull(launchTime, "launchTime");
|
||||
this.monitoringState = monitoringState;
|
||||
this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone");
|
||||
this.availabilityZone = availabilityZone; // nullable on Eucalyptus.
|
||||
this.placementGroup = placementGroup;
|
||||
this.virtualizationType = virtualizationType;
|
||||
this.platform = platform;
|
||||
|
|
|
@ -65,6 +65,7 @@ import com.google.common.base.Suppliers;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -174,6 +175,90 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings( { "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testApplyForEucalyptusWhereNullAvailabilityZoneIpAddressNoGroups() throws UnknownHostException {
|
||||
EC2Client client = createMock(EC2Client.class);
|
||||
AMIClient amiClient = createMock(AMIClient.class);
|
||||
expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
.<Hardware> of(EC2Hardware.M1_SMALL));
|
||||
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
RunningInstance instance = createMock(RunningInstance.class);
|
||||
Image image = createMock(Image.class);
|
||||
|
||||
expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
|
||||
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
.<Location> of(region));
|
||||
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(null);
|
||||
expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
|
||||
|
||||
expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
|
||||
expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
|
||||
expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
|
||||
expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
|
||||
|
||||
expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
|
||||
(Set) ImmutableSet.<Image> of(image));
|
||||
|
||||
expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
|
||||
|
||||
expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce();
|
||||
|
||||
expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
|
||||
expect(instance.getEbsBlockDevices()).andReturn(Maps.<String, EbsBlockDevice> newHashMap());
|
||||
expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
|
||||
|
||||
replay(imageMap);
|
||||
replay(client);
|
||||
replay(amiClient);
|
||||
replay(credentialsMap);
|
||||
replay(credentialProvider);
|
||||
replay(instance);
|
||||
replay(jcImage);
|
||||
|
||||
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
|
||||
credentialProvider, imageMap, locations, hardwares);
|
||||
|
||||
NodeMetadata metadata = parser.apply(instance);
|
||||
|
||||
assertEquals(metadata.getTag(), "NOTAG-i-3d640055");
|
||||
assertEquals(metadata.getLocation(), region);
|
||||
assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
|
||||
assertEquals(metadata.getHardware().getId(), "m1.small");
|
||||
assertEquals(metadata.getHardware().getName(), "m1.small");
|
||||
assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
||||
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
||||
assertEquals(metadata.getHardware().getRam(), 1740);
|
||||
assertEquals(metadata.getHardware().getVolumes(), ImmutableList.<Volume> of(new VolumeImpl(null,
|
||||
Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
||||
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
|
||||
|
||||
assertEquals(metadata.getCredentials(), new Credentials("user", null));
|
||||
|
||||
verify(imageMap);
|
||||
verify(jcImage);
|
||||
verify(client);
|
||||
verify(amiClient);
|
||||
verify(credentialsMap);
|
||||
verify(credentialProvider);
|
||||
verify(instance);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testImageNotFoundAndLazyReturnsNull() throws UnknownHostException {
|
||||
|
|
|
@ -96,14 +96,15 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
InstanceType.M1_LARGE, (String) null, "aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), MonitoringState.DISABLED,
|
||||
AvailabilityZone.US_EAST_1B, null, "paravirtual", null, "10-251-50-132.ec2.internal", null,
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null, null, RootDeviceType.INSTANCE_STORE,
|
||||
null, ImmutableMap.<String, EbsBlockDevice> of()), new RunningInstance(defaultRegion,
|
||||
ImmutableSet.of("default"), "23", "ec2-72-44-33-6.compute-1.amazonaws.com", "ami-6ea54007",
|
||||
"i-28a64435", InstanceState.RUNNING, InstanceType.M1_LARGE, (String) null, "aki-ba3adfd3",
|
||||
"example-key-name", dateService.iso8601DateParse("2007-08-07T11:54:42.000Z"),
|
||||
MonitoringState.DISABLED, AvailabilityZone.US_EAST_1B, null, "paravirtual", null,
|
||||
"10-251-50-134.ec2.internal", null, ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null,
|
||||
null, null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of())),
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of()),
|
||||
new RunningInstance(defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-6.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64435", InstanceState.RUNNING,
|
||||
InstanceType.M1_LARGE, (String) null, "aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), MonitoringState.DISABLED,
|
||||
AvailabilityZone.US_EAST_1B, null, "paravirtual", null, "10-251-50-134.ec2.internal", null,
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of())),
|
||||
"UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", null, "r-44a5402d"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = getReservations(is);
|
||||
|
@ -123,8 +124,25 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
"i-3FFA0762", InstanceState.SHUTTING_DOWN, InstanceType.M1_LARGE, null, "eki-6CBD12F2",
|
||||
"jclouds#euc-17", dateService.iso8601DateParse("2010-06-16T03:06:19.000Z"),
|
||||
MonitoringState.DISABLED, "open", null, "paravirtual", null, "10.7.0.179", null, ImmutableSet
|
||||
.<String> of(), "eri-A97113E4", null, null, null, null, RootDeviceType.INSTANCE_STORE, null,
|
||||
ImmutableMap.<String, EbsBlockDevice> of())), "jclouds", null, "r-4D2A08AD"));
|
||||
.<String> of(), "eri-A97113E4", null, null, null, null, RootDeviceType.INSTANCE_STORE,
|
||||
null, ImmutableMap.<String, EbsBlockDevice> of())), "jclouds", null, "r-4D2A08AD"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = getReservations(is);
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
||||
public void testApplyInputStreamEucNoAvailabilityZone() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_instances_euc1.xml");
|
||||
Set<Reservation<? extends RunningInstance>> contents = Sets.newLinkedHashSet();
|
||||
|
||||
contents.add(new Reservation<RunningInstance>(defaultRegion, ImmutableSet.of("default"), ImmutableSet
|
||||
.of(new RunningInstance(defaultRegion, ImmutableSet.<String> of(), "0", null, "ami-h30p5im0",
|
||||
"i-9slweygo", InstanceState.RUNNING, InstanceType.M1_SMALL, null, null, "nebulatanimislam",
|
||||
dateService.iso8601SecondsDateParse("2010-09-09T18:09:42Z"), null, null, null, "paravirtual",
|
||||
null, null, "10.128.207.5", ImmutableSet.<String> of("None"), null, null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of())), "tislam1",
|
||||
null, "r-opqeylmj"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = getReservations(is);
|
||||
|
||||
|
@ -143,7 +161,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
"adriancole.ec2ebs1", dateService.iso8601DateParse("2009-12-30T04:06:23.000Z"),
|
||||
MonitoringState.DISABLED, AvailabilityZone.US_EAST_1B, "placement", "hvm", null,
|
||||
"domU-12-31-39-09-CE-53.compute-1.internal", "10.210.209.157", ImmutableSet.<String> of(),
|
||||
"ari-a51cf9cc", null, null, null, null, RootDeviceType.EBS, "/dev/sda1", ImmutableMap
|
||||
"ari-a51cf9cc", null, null, null, null, RootDeviceType.EBS, "/dev/sda1", ImmutableMap
|
||||
.<String, EbsBlockDevice> of("/dev/sda1", new EbsBlockDevice("vol-dc6ca8b5",
|
||||
Attachment.Status.ATTACHED, dateService
|
||||
.iso8601DateParse("2009-12-30T04:06:29.000Z"), true)))),
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" ?>
|
||||
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
|
||||
<requestId>G7PDD1DNVLO7DZS6AFZH</requestId>
|
||||
<reservationSet>
|
||||
<item>
|
||||
<instancesSet>
|
||||
<item>
|
||||
<privateDnsName>10.128.207.5</privateDnsName>
|
||||
<amiLaunchIndex>0</amiLaunchIndex>
|
||||
<instanceType>m1.small</instanceType>
|
||||
<dnsName />
|
||||
<launchTime>2010-09-09T18:09:42Z</launchTime>
|
||||
<instanceId>i-9slweygo</instanceId>
|
||||
<imageId>ami-h30p5im0</imageId>
|
||||
<instanceState>
|
||||
<code>1</code>
|
||||
<name>running</name>
|
||||
</instanceState>
|
||||
<keyName>nebulatanimislam</keyName>
|
||||
<publicDnsName>10.128.207.5</publicDnsName>
|
||||
<productCodesSet>
|
||||
<item>
|
||||
<productCode>None</productCode>
|
||||
</item>
|
||||
</productCodesSet>
|
||||
</item>
|
||||
</instancesSet>
|
||||
<reservationId>r-opqeylmj</reservationId>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>default</groupId>
|
||||
</item>
|
||||
</groupSet>
|
||||
<ownerId>tislam1</ownerId>
|
||||
</item>
|
||||
</reservationSet>
|
||||
</DescribeInstancesResponse>
|
Loading…
Reference in New Issue