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 a134ec036e..8dd3315379 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 @@ -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 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 addresses = addressesBuilder.build(); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java index 56ef8201a5..c01805cd77 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java @@ -121,10 +121,7 @@ public abstract class BaseReservationHandler 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 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 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); } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeAvailabilityZonesResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeAvailabilityZonesResponseHandler.java index a931531c60..aeb8873bff 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeAvailabilityZonesResponseHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeAvailabilityZonesResponseHandler.java @@ -50,7 +50,8 @@ public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWi private Set 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 defaultRegion) { diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeImagesResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeImagesResponseHandler.java index ce75bde66a..8c7fa42813 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeImagesResponseHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeImagesResponseHandler.java @@ -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 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()); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index 75e5016c55..5c272da6e0 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -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. of(), ImmutableSet - . of(), ImmutableSet. of(), ImmutableMap. of()); - - assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").privateAddresses( - ImmutableSet. 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(); diff --git a/common/aws/src/main/java/org/jclouds/aws/util/AWSUtils.java b/common/aws/src/main/java/org/jclouds/aws/util/AWSUtils.java index 10fea27e53..2c80e22a51 100644 --- a/common/aws/src/main/java/org/jclouds/aws/util/AWSUtils.java +++ b/common/aws/src/main/java/org/jclouds/aws/util/AWSUtils.java @@ -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)); diff --git a/common/aws/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java b/common/aws/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java index 97f1610de1..fa9b565981 100644 --- a/common/aws/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java +++ b/common/aws/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java @@ -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() {