From 4b761c790a3fcabbac16fd94356e3f34a79d0375 Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Thu, 2 Jun 2011 12:08:00 +0200 Subject: [PATCH 1/8] Renamed Predicate protocol to Coercions --- compute/src/main/clojure/org/jclouds/predicate.clj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compute/src/main/clojure/org/jclouds/predicate.clj b/compute/src/main/clojure/org/jclouds/predicate.clj index 1a35f88ae4..ae295e5618 100644 --- a/compute/src/main/clojure/org/jclouds/predicate.clj +++ b/compute/src/main/clojure/org/jclouds/predicate.clj @@ -18,11 +18,12 @@ ; (ns org.jclouds.predicate) -(defprotocol Predicate - "Protocol for making a com.google.common.base.Predicate." +(defprotocol Coercions + "Protocol for coercing between predicate-like things, like + Clojure fns and com.google.common.base.Predicate." (to-predicate [p])) -(extend-protocol Predicate +(extend-protocol Coercions clojure.lang.IFn (to-predicate [p] (reify com.google.common.base.Predicate From e49e0254ce0f405ca2af0d07f795f14acb00e091 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 2 Jun 2011 11:08:58 -0700 Subject: [PATCH 2/8] Issue 591:Need to handle 2+ cookies from TE --- .../ParseLoginResponseFromHeaders.java | 61 ++++++++++-------- .../ParseLoginResponseFromHeadersTest.java | 63 +++++++++++++++---- 2 files changed, 86 insertions(+), 38 deletions(-) diff --git a/common/vcloud/src/main/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeaders.java b/common/vcloud/src/main/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeaders.java index 4453929364..6c71e10d4e 100755 --- a/common/vcloud/src/main/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeaders.java +++ b/common/vcloud/src/main/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeaders.java @@ -18,10 +18,10 @@ */ package org.jclouds.vcloud.functions; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.http.HttpUtils.releasePayload; import java.util.Map; +import java.util.NoSuchElementException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -41,6 +41,8 @@ import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.xml.OrgListHandler; import com.google.common.base.Function; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; /** * This parses {@link VCloudSession} from HTTP headers. @@ -49,7 +51,7 @@ import com.google.common.base.Function; */ @Singleton public class ParseLoginResponseFromHeaders implements Function { - static final Pattern pattern = Pattern.compile("(vcloud-token=)?([^;]+)(;.*)?"); + static final Pattern pattern = Pattern.compile("(vcloud-token)=?([^;]+)(;.*)?"); private final ParseSax.Factory factory; private final Provider orgHandlerProvider; @@ -61,38 +63,45 @@ public class ParseLoginResponseFromHeaders implements Function org = factory.create(orgHandlerProvider.get()).parse( + final String token = parseTokenFromHeaders(from); + final Map org = factory.create(orgHandlerProvider.get()).parse( from.getPayload().getInput()); - return new VCloudSession() { - @VCloudToken - public String getVCloudToken() { - return matcher.group(2); - } + return new VCloudSession() { + @VCloudToken + public String getVCloudToken() { + return token; + } - @Org - public Map getOrgs() { - return org; - } - }; - - } + @Org + public Map getOrgs() { + return org; + } + }; } finally { releasePayload(from); } - throw new HttpResponseException("x-vcloud-authorization not found ", null, from); + } + + public String parseTokenFromHeaders(HttpResponse from) { + String cookieHeader = from.getFirstHeaderOrNull("x-vcloud-authorization"); + if (cookieHeader != null) { + Matcher matcher = pattern.matcher(cookieHeader); + return matcher.find() ? matcher.group(2) : cookieHeader; + } else { + try { + cookieHeader = Iterables.find(from.getHeaders().get(HttpHeaders.SET_COOKIE), Predicates.contains(pattern)); + Matcher matcher = pattern.matcher(cookieHeader); + matcher.find(); + return matcher.group(2); + } catch (NoSuchElementException e) { + throw new HttpResponseException(String.format("Header %s or %s must be present", "x-vcloud-authorization", + HttpHeaders.SET_COOKIE), null, from); + } + } } } diff --git a/common/vcloud/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java b/common/vcloud/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java index d4945d37f0..fdfeadc1ea 100644 --- a/common/vcloud/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java +++ b/common/vcloud/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java @@ -23,6 +23,7 @@ import static org.testng.Assert.assertEquals; import java.net.URI; import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.io.Payloads; import org.jclouds.vcloud.VCloudMediaType; @@ -54,60 +55,98 @@ public class ParseLoginResponseFromHeadersTest extends BaseHandlerTest { @Test public void testApply() { HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", - "vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/")); + .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", + "vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/")); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); + VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } @Test public void testApplyBlueLock() { HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", - "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0=")); + .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", + "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0=")); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0="); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); + VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } @Test public void testApplyTerremark() { HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("Set-Cookie", - "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/")); + .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("Set-Cookie", + "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/")); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); + VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } + @Test + public void testApplyTerremarkMultipleCookies() { + HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() + .getResourceAsStream("/orglist.xml")), ImmutableMultimap. builder().put("Set-Cookie", + "NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly") + .put("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").build()); + response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); + response.getPayload().getContentMetadata().setContentLength(307l); + + VCloudSession reply = parser.apply(response); + assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d"); + assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", + VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); + + } + + @Test(expectedExceptions = HttpResponseException.class) + public void testUnmatchedCookieThrowsHttpResponseException() { + HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() + .getResourceAsStream("/orglist.xml")), ImmutableMultimap. builder().put("Set-Cookie", + "NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly") + .build()); + response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); + response.getPayload().getContentMetadata().setContentLength(307l); + + parser.apply(response); + } + + @Test(expectedExceptions = HttpResponseException.class) + public void testNoThrowsHttpResponseException() { + HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() + .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of()); + response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); + response.getPayload().getContentMetadata().setContentLength(307l); + + parser.apply(response); + } + @Test public void testApplyVirtacore() { HttpResponse response = new HttpResponse(200, "OK", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", - "vcloud-token=IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48=")); + .getResourceAsStream("/orglist.xml")), ImmutableMultimap. of("x-vcloud-authorization", + "vcloud-token=IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48=")); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48="); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); + VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } } From 34bbfa3797d68e83bec5962c86cc70f2fe8f9b4f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 2 Jun 2011 12:59:57 -0700 Subject: [PATCH 3/8] more detail on test failures in elasticstack --- .../org/jclouds/elasticstack/ElasticStackClientLiveTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java index 05993b1d4e..b6085157e0 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java @@ -159,8 +159,8 @@ public class ElasticStackClientLiveTest { @Test public void testGetDrive() throws Exception { for (String driveUUID : client.listDrives()) { - assert !"".equals(driveUUID); - assertNotNull(client.getDriveInfo(driveUUID)); + assert !"".equals(driveUUID) : driveUUID; + assert client.getDriveInfo(driveUUID) != null : driveUUID; } } From 11884540a65d9cccb36f9799a7a3d7f01296312a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 2 Jun 2011 13:00:18 -0700 Subject: [PATCH 4/8] test size comparison when testing templates --- .../compute/BaseTemplateBuilderLiveTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java index cc30beefcd..5ae857f58a 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java @@ -33,6 +33,7 @@ import java.util.concurrent.TimeoutException; import org.jclouds.Constants; import org.jclouds.compute.config.BaseComputeServiceContextModule; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; @@ -77,6 +78,29 @@ public abstract class BaseTemplateBuilderLiveTest { apiversion = System.getProperty("test." + provider + ".apiversion"); } + public void testCompareSizes() throws Exception { + Hardware defaultSize = context.getComputeService().templateBuilder().build().getHardware(); + + Hardware smallest = context.getComputeService().templateBuilder().smallest().build().getHardware(); + Hardware fastest = context.getComputeService().templateBuilder().fastest().build().getHardware(); + Hardware biggest = context.getComputeService().templateBuilder().biggest().build().getHardware(); + + System.out.printf("smallest %s%n", smallest); + System.out.printf("fastest %s%n", fastest); + System.out.printf("biggest %s%n", biggest); + + assertEquals(defaultSize, smallest); + + assert getCores(smallest) <= getCores(fastest) : String.format("%s ! <= %s", smallest, fastest); + assert getCores(biggest) <= getCores(fastest) : String.format("%s ! <= %s", biggest, fastest); + + assert biggest.getRam() >= fastest.getRam() : String.format("%s ! >= %s", biggest, fastest); + assert biggest.getRam() >= smallest.getRam() : String.format("%s ! >= %s", biggest, smallest); + + assert getCores(fastest) >= getCores(biggest) : String.format("%s ! >= %s", fastest, biggest); + assert getCores(fastest) >= getCores(smallest) : String.format("%s ! >= %s", fastest, smallest); + } + protected Properties setupProperties() { Properties overrides = new Properties(); overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); From 2360bd1afdb78148c7f05eaef667db8443de9a34 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 2 Jun 2011 13:19:39 -0700 Subject: [PATCH 5/8] bumped aws-ec2 to 11.04 ubuntu --- .../jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java index ed15d0962a..57126d25fe 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java @@ -84,7 +84,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { .osVersionMatches("1[10].[10][04]").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU).build(); assert (template.getImage().getProviderId().startsWith("ami-")) : template; - assertEquals(template.getImage().getOperatingSystem().getVersion(), "10.10"); + assertEquals(template.getImage().getOperatingSystem().getVersion(), "11.04"); assertEquals(template.getImage().getOperatingSystem().is64Bit(), false); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); From a0692e737ff9c83ecdfb38149b55b3b55b61a572 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 2 Jun 2011 13:20:17 -0700 Subject: [PATCH 6/8] refactored so that eucalyptus m1.small can use 64 bit image --- .../ec2/compute/domain/EC2HardwareBuilder.java | 14 ++++++++++++-- .../ec2/compute/suppliers/EC2HardwareSupplier.java | 3 +-- .../ec2/compute/EC2TemplateBuilderTest.java | 4 ++-- .../RunningInstanceToNodeMetadataTest.java | 10 +++++----- ...urityGroupsAsNeededAndReturnRunOptionsTest.java | 4 ++-- .../compute/suppliers/AWSEC2HardwareSupplier.java | 4 ++-- ...urityGroupsAsNeededAndReturnRunOptionsTest.java | 6 +++--- ...tnerCloudEucalyptusTemplateBuilderLiveTest.java | 11 ++++++++--- 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/domain/EC2HardwareBuilder.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/domain/EC2HardwareBuilder.java index 53cbe925d8..2e10e9f7cc 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/domain/EC2HardwareBuilder.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/domain/EC2HardwareBuilder.java @@ -209,13 +209,23 @@ public class EC2HardwareBuilder extends HardwareBuilder { /** * @see InstanceType#M1_SMALL */ - public static EC2HardwareBuilder m1_small() { + public static EC2HardwareBuilder m1_small32() { return new EC2HardwareBuilder(InstanceType.M1_SMALL).ram(1740).processors( ImmutableList.of(new Processor(1.0, 1.0))).volumes( ImmutableList. of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(150.0f, "/dev/sda2", false, false))).is64Bit(false); } - + + /** + * @see InstanceType#M1_SMALL + */ + public static EC2HardwareBuilder m1_small() { + return new EC2HardwareBuilder(InstanceType.M1_SMALL).ram(1740).processors( + ImmutableList.of(new Processor(1.0, 1.0))).volumes( + ImmutableList. of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(150.0f, + "/dev/sda2", false, false))); + } + /** * @see InstanceType#T1_MICRO */ diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/EC2HardwareSupplier.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/EC2HardwareSupplier.java index ee0185d107..bcc5d09fa2 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/EC2HardwareSupplier.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/EC2HardwareSupplier.java @@ -18,7 +18,6 @@ */ package org.jclouds.ec2.compute.suppliers; -import static org.jclouds.compute.predicates.ImagePredicates.any; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_medium; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_large; @@ -43,7 +42,7 @@ public class EC2HardwareSupplier implements Supplier> { @Override public Set get() { - return ImmutableSet. of(m1_small().supportsImage(any()).build(), c1_medium().build(), c1_xlarge() + return ImmutableSet. of(m1_small().build(), c1_medium().build(), c1_xlarge() .build(), m1_large().build(), m1_xlarge().build()); } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java index 92d0e9191f..d4bb385fc9 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java @@ -26,7 +26,7 @@ import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_medium; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.cc1_4xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_large; -import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_small; +import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_small32; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m2_2xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m2_4xlarge; @@ -161,7 +161,7 @@ public class EC2TemplateBuilderTest { .build())); Supplier> sizes = Suppliers.> ofInstance(ImmutableSet . of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large().build(), - m1_small().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), + m1_small32().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), m2_4xlarge().build(), CC1_4XLARGE)); return new TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(location), optionsProvider, 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 4eaca6bf6b..16683b37b8 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 @@ -18,7 +18,7 @@ */ package org.jclouds.ec2.compute.functions; -import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_small; +import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_small32; import static org.testng.Assert.assertEquals; import java.net.UnknownHostException; @@ -129,7 +129,7 @@ public class RunningInstanceToNodeMetadataTest { @Test public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationFound() throws UnknownHostException { - RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet + RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small32().build()), ImmutableSet .of(provider), EC2ImageParserTest.convertImages("/amzn_images.xml"), ImmutableMap . of()); @@ -137,7 +137,7 @@ public class RunningInstanceToNodeMetadataTest { 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_small().build()).operatingSystem( + "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()); @@ -158,7 +158,7 @@ public class RunningInstanceToNodeMetadataTest { }; Map instanceToImage = new MapMaker().makeComputingMap(nullReturningFunction); - RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet + RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small32().build()), ImmutableSet .of(provider), ImmutableMap. of(), EC2ComputeServiceDependenciesModule.instanceToNodeState, instanceToImage); @@ -167,7 +167,7 @@ public class RunningInstanceToNodeMetadataTest { 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_small().build()).location(provider).build()); + m1_small32().build()).location(provider).build()); } protected RunningInstance firstInstanceFromResource(String resource) { diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index 3cacd017a0..f54b6cca71 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -69,7 +69,7 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest { // setup constants String region = Region.AP_SOUTHEAST_1; String tag = "tag"; - Hardware size = EC2HardwareBuilder.m1_small().build(); + Hardware size = EC2HardwareBuilder.m1_small32().build(); String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String generatedGroup = "group"; Set generatedGroups = ImmutableSet.of(generatedGroup); @@ -124,7 +124,7 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest { // setup constants String region = Region.AP_SOUTHEAST_1; String tag = "tag"; - Hardware size = EC2HardwareBuilder.m1_small().build(); + Hardware size = EC2HardwareBuilder.m1_small32().build(); String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String generatedGroup = "group"; Set generatedGroups = ImmutableSet.of(generatedGroup); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2HardwareSupplier.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2HardwareSupplier.java index c51c9897da..e16ff71084 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2HardwareSupplier.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/suppliers/AWSEC2HardwareSupplier.java @@ -24,7 +24,7 @@ import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_medium; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.cc1_4xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_large; -import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_small; +import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_small32; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m1_xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m2_2xlarge; import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.m2_4xlarge; @@ -82,7 +82,7 @@ public class AWSEC2HardwareSupplier extends EC2HardwareSupplier { sizes.add(cc1_4xlarge().location(location).supportsImageIds(ccAmi).build()); } sizes.addAll(ImmutableSet. of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large() - .build(), m1_small().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), + .build(), m1_small32().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), m2_4xlarge().build())); return sizes.build(); } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index f61a77b8ef..b5388a6c71 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -73,7 +73,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT // setup constants String region = Region.AP_SOUTHEAST_1; String group = "group"; - Hardware size = EC2HardwareBuilder.m1_small().build(); + Hardware size = EC2HardwareBuilder.m1_small32().build(); String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String generatedGroup = "group"; Set generatedGroups = ImmutableSet.of(generatedGroup); @@ -262,7 +262,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT // setup constants String region = Region.AP_SOUTHEAST_1; String group = "group"; - Hardware size = EC2HardwareBuilder.m1_small().build(); + Hardware size = EC2HardwareBuilder.m1_small32().build(); String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; // create mocks @@ -320,7 +320,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT // setup constants String region = Region.AP_SOUTHEAST_1; String group = "group"; - Hardware size = EC2HardwareBuilder.m1_small().build(); + Hardware size = EC2HardwareBuilder.m1_small32().build(); String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String generatedGroup = "group"; Set generatedGroups = ImmutableSet.of(generatedGroup); diff --git a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest.java b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest.java index 03193f81d4..bdd38a5d46 100644 --- a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest.java +++ b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest.java @@ -24,10 +24,13 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; +import org.jclouds.aws.util.AWSUtils; import org.jclouds.compute.BaseTemplateBuilderLiveTest; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.Template; +import org.jclouds.domain.LocationScope; +import org.jclouds.ec2.compute.util.EC2ComputeUtils; import org.testng.annotations.Test; import com.google.common.base.Predicate; @@ -68,16 +71,18 @@ public class EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest extends Bas @Test public void testDefaultTemplateBuilder() throws IOException { - Template defaultTemplate = context.getComputeService().templateBuilder().build(); assert (defaultTemplate.getImage().getProviderId().startsWith("emi-")) : defaultTemplate; assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); + assertEquals(defaultTemplate.getHardware().getId(), "m1.small"); assertEquals(defaultTemplate.getLocation().getId(), "kvm-cluster"); - assertEquals(getCores(defaultTemplate.getHardware()), 2.0d); - + assertEquals(defaultTemplate.getLocation().getScope(), LocationScope.ZONE); + assertEquals(AWSUtils.getRegionFromLocationOrNull(defaultTemplate.getLocation()), "Eucalyptus"); + assertEquals(EC2ComputeUtils.getZoneFromLocationOrNull(defaultTemplate.getLocation()), "kvm-cluster"); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } @Override From ac56adc2e169f038eb9302a011c34e51f0d96015 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 2 Jun 2011 13:47:57 -0700 Subject: [PATCH 7/8] Issue 592:templateBuilder.fromTemplate loses location when more narrow than region --- .../org/jclouds/ec2/compute/options/EC2TemplateOptions.java | 2 +- .../compute/domain/internal/TemplateBuilderImpl.java | 1 + .../org/jclouds/compute/BaseTemplateBuilderLiveTest.java | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/options/EC2TemplateOptions.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/options/EC2TemplateOptions.java index 5f63ffbd10..1c44f71c93 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/options/EC2TemplateOptions.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/options/EC2TemplateOptions.java @@ -509,6 +509,6 @@ public class EC2TemplateOptions extends TemplateOptions implements Cloneable { @Override public String toString() { return "[groupIds=" + groupIds + ", keyPair=" + keyPair + ", noKeyPair=" + noKeyPair + ", userData=" - + Arrays.toString(userData) + ", blockDeviceMappings=" + blockDeviceMappings + "]"; + + Arrays.toString(userData) + ", blockDeviceMappings=" + blockDeviceMappings.build() + "]"; } } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java index c03791bbd0..4c9c44949a 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java @@ -416,6 +416,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { */ @Override public TemplateBuilder fromTemplate(Template template) { + location = template.getLocation(); fromHardware(template.getHardware()); fromImage(template.getImage()); options(template.getOptions()); diff --git a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java index 5ae857f58a..75d9800e4e 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java @@ -101,6 +101,12 @@ public abstract class BaseTemplateBuilderLiveTest { assert getCores(fastest) >= getCores(smallest) : String.format("%s ! >= %s", fastest, smallest); } + public void testFromTemplate() { + Template defaultTemplate = context.getComputeService().templateBuilder().build(); + assertEquals(context.getComputeService().templateBuilder().fromTemplate(defaultTemplate).build().toString(), + defaultTemplate.toString()); + } + protected Properties setupProperties() { Properties overrides = new Properties(); overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); From a68640351f7cfb9c2bbd5cf509586b7d52bf2c72 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 2 Jun 2011 13:51:49 -0700 Subject: [PATCH 8/8] better error when last-modified header not found --- .../functions/ParseSystemAndUserMetadataFromHeaders.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blobstore/src/main/java/org/jclouds/blobstore/functions/ParseSystemAndUserMetadataFromHeaders.java b/blobstore/src/main/java/org/jclouds/blobstore/functions/ParseSystemAndUserMetadataFromHeaders.java index 69c0f743d0..160881a2f9 100755 --- a/blobstore/src/main/java/org/jclouds/blobstore/functions/ParseSystemAndUserMetadataFromHeaders.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/functions/ParseSystemAndUserMetadataFromHeaders.java @@ -94,8 +94,7 @@ public class ParseSystemAndUserMetadataFromHeaders implements Function