issue #1108: remove special casing of eucalyptus

This commit is contained in:
Adrian Cole 2012-12-29 11:54:19 -08:00
parent 7132683cf6
commit 38152a5cc3
7 changed files with 30 additions and 53 deletions

View File

@ -20,6 +20,7 @@ package org.jclouds.ec2.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.not;
import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.collect.Iterables.filter;
import java.util.List;
@ -55,7 +56,6 @@ import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
@ -120,13 +120,9 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
// collect all ip addresses into one bundle in case the api mistakenly put a private address
// into the public address field
Builder<String> addressesBuilder = ImmutableSet.builder();
if (Strings.emptyToNull(instance.getIpAddress()) != null)
if (emptyToNull(instance.getIpAddress()) != null)
addressesBuilder.add(instance.getIpAddress());
//Add dnsName (if available) to addresses, when the IPAddress is null
// happens on Eucalyptus sometimes.
else if(Strings.emptyToNull(instance.getDnsName()) != null)
addressesBuilder.add(instance.getDnsName());
if (Strings.emptyToNull(instance.getPrivateIpAddress()) != null)
if (emptyToNull(instance.getPrivateIpAddress()) != null)
addressesBuilder.add(instance.getPrivateIpAddress());
Set<String> addresses = addressesBuilder.build();

View File

@ -121,10 +121,7 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
} else if (equalsOrSuffix(qName, "amiLaunchIndex")) {
builder.amiLaunchIndex(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "dnsName")) {
String dnsName = currentOrNull(currentText);
// Eucalyptus
if (!"0.0.0.0".equals(dnsName))
builder.dnsName(dnsName);
builder.dnsName(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "imageId")) {
builder.imageId(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "instanceId")) {
@ -152,10 +149,7 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
} else if (equalsOrSuffix(qName, "platform")) {
builder.platform(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "privateDnsName")) {
String privateDnsName = currentOrNull(currentText);
// Eucalyptus
if (!"0.0.0.0".equals(privateDnsName))
builder.privateDnsName(privateDnsName);
builder.privateDnsName(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "privateIpAddress")) {
builder.privateIpAddress(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "ramdiskId")) {
@ -197,18 +191,6 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
protected void refineBuilderBeforeAddingInstance() {
String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
// Eucalyptus
if (builder.getIpAddress() == null && builder.getDnsName() != null && builder.getDnsName().matches(".*[0-9]$")) {
builder.ipAddress(builder.getDnsName());
builder.dnsName(null);
}
if (builder.getPrivateIpAddress() == null && builder.getPrivateDnsName() != null
&& builder.getPrivateDnsName().matches(".*[0-9]$")) {
builder.privateIpAddress(builder.getPrivateDnsName());
builder.privateDnsName(null);
}
builder.region((region == null) ? defaultRegion.get() : region);
builder.groupNames(groupNames);
}

View File

@ -50,7 +50,8 @@ public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWi
private Set<String> messages = Sets.newHashSet();
/**
* Eucalyptus 1.6 doesn't return region in the XML output
* clones like {@code openstack-nova-ec2}, which don't support multiple regions don't return region in the XML
* output.
*/
@Inject
DescribeAvailabilityZonesResponseHandler(@Region Supplier<String> defaultRegion) {

View File

@ -83,9 +83,6 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
private String ramdiskId;
private boolean inProductCodes;
private boolean inBlockDeviceMapping;
/**
* Eucalyptus 1.6 doesn't set rootDeviceType
*/
private RootDeviceType rootDeviceType = RootDeviceType.INSTANCE_STORE;
private Map<String, EbsBlockDevice> ebsBlockDevices = Maps.newHashMap();
private String deviceName;
@ -129,8 +126,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
} else if (qName.equals("imageState")) {
rawState = currentOrNull(currentText);
imageState = ImageState.fromValue(rawState);
// eucalyptus
} else if (qName.equals("imageType") || qName.equals("type")) {
} else if (qName.equals("imageType")) {
imageType = ImageType.fromValue(currentText.toString().trim());
} else if (qName.equals("isPublic")) {
isPublic = Boolean.parseBoolean(currentText.toString().trim());

View File

@ -99,21 +99,6 @@ public class RunningInstanceToNodeMetadataTest {
"us-east-1/image").providerId("id").build().toString());
}
@Test
public void testIPAddressIsSetToDnsNameWhenIPAddressIsNull() {
RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
.instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").dnsName("jclouds-1-1-1-1.jclouds.org").build();
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").privateAddresses(
ImmutableSet.<String> of()).publicAddresses(ImmutableSet.of("jclouds-1-1-1-1.jclouds.org")).id("us-east-1/id").imageId(
"us-east-1/image").providerId("id").build().toString());
}
static Location provider = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
.description("us-east-1").build();

View File

@ -85,15 +85,12 @@ public class AWSUtils {
}
public AWSError parseAWSErrorFromContent(HttpRequest request, HttpResponse response) {
// HEAD has no content
if (response.getPayload() == null)
return null;
// Eucalyptus and Walrus occasionally return text/plain
if (response.getPayload().getContentMetadata().getContentType() != null
&& response.getPayload().getContentMetadata().getContentType().indexOf("text/plain") != -1)
if ("text/plain".equals(response.getPayload().getContentMetadata().getContentType()))
return null;
try {
AWSError error = (AWSError) factory.create(errorHandlerProvider.get()).setContext(request).apply(response);
AWSError error = factory.create(errorHandlerProvider.get()).setContext(request).apply(response);
if (error.getRequestId() == null)
error.setRequestId(response.getFirstHeaderOrNull(requestId));
error.setRequestToken(response.getFirstHeaderOrNull(requestToken));

View File

@ -22,6 +22,7 @@ import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
@ -69,6 +70,25 @@ public class AWSUtilsTest {
response.getPayload().getContentMetadata().setContentType("text/xml");
return response;
}
/**
* HEAD requests don't have a payload
*/
@Test
public void testNoExceptionWhenNoPayload() {
HttpResponse response = HttpResponse.builder().statusCode(400).build();
assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response));
}
/**
* clones or proxies can mess up the error message.
*/
@Test
public void testNoExceptionParsingTextPlain() {
HttpResponse response = HttpResponse.builder().statusCode(400).payload("foo bar").build();
response.getPayload().getContentMetadata().setContentType("text/plain");
assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response));
}
@Test
public void testParseAWSErrorFromContentHttpCommandHttpResponseInputStream() {