diff --git a/archetypes/compute-service-archetype/src/main/resources/archetype-resources/src/test/java/config/__providerName__ContextModuleTest.java b/archetypes/compute-service-archetype/src/main/resources/archetype-resources/src/test/java/config/__providerName__ContextModuleTest.java index 633e65ab79..d1d5403b44 100644 --- a/archetypes/compute-service-archetype/src/main/resources/archetype-resources/src/test/java/config/__providerName__ContextModuleTest.java +++ b/archetypes/compute-service-archetype/src/main/resources/archetype-resources/src/test/java/config/__providerName__ContextModuleTest.java @@ -21,7 +21,7 @@ package ${package}.config; import static org.testng.Assert.assertEquals; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpRetryHandler; diff --git a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/config/__clientName__ContextModuleTest.java b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/config/__clientName__ContextModuleTest.java index f4010052a1..24012ae58e 100644 --- a/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/config/__clientName__ContextModuleTest.java +++ b/archetypes/json-client-archetype/src/main/resources/archetype-resources/src/test/java/config/__clientName__ContextModuleTest.java @@ -47,7 +47,7 @@ package ${package}.config; import static org.testng.Assert.assertEquals; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpRetryHandler; diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java similarity index 97% rename from atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientTest.java rename to atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java index 255cbef605..575cde5c4d 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClientTest.java @@ -18,12 +18,14 @@ */ package org.jclouds.atmosonline.saas; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; +import java.util.Properties; import javax.ws.rs.core.HttpHeaders; @@ -67,7 +69,7 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "emcsaas.AtmosStorageClientTest") -public class AtmosStorageClientTest extends RestClientTest { +public class AtmosStorageAsyncClientTest extends RestClientTest { private BlobToObject blobToObject; @@ -294,12 +296,11 @@ public class AtmosStorageClientTest extends RestClientTest() { })); install(new AtmosObjectModule()); + Jsr330.bindProperties(binder(), checkNotNull(new AtmosStoragePropertiesBuilder( + new Properties()).build(), "properties")); bind(URI.class).annotatedWith(AtmosStorage.class).toInstance( URI.create("http://accesspoint.emccis.com")); bind(String.class).annotatedWith(TimeStamp.class).toInstance("timestamp"); - bindConstant().annotatedWith( - Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_ENDPOINT)).to( - "http://accesspoint.emccis.com"); bindConstant().annotatedWith(Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID)) .to("uid"); bindConstant().annotatedWith(Jsr330.named(AtmosStorageConstants.PROPERTY_EMCSAAS_KEY)) diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/blobstore/config/AtmosBlobStoreModuleTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/blobstore/config/AtmosBlobStoreModuleTest.java index 8b4a653e32..e1e31ba5f1 100755 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/blobstore/config/AtmosBlobStoreModuleTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/blobstore/config/AtmosBlobStoreModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.atmosonline.saas.blobstore.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import org.jclouds.Constants; diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/config/AtmosStorageRestClientModuleTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/config/AtmosStorageRestClientModuleTest.java index 3b78fe4d74..264cc1ab6e 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/config/AtmosStorageRestClientModuleTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/config/AtmosStorageRestClientModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.atmosonline.saas.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/filters/SignRequestTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/filters/SignRequestTest.java index a8b8a6e63b..e2fff4dbaf 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/filters/SignRequestTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/filters/SignRequestTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.atmosonline.saas.filters; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import java.io.IOException; diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index 8177ef098a..215c0fcd24 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -138,15 +138,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule { @Singleton public static class GetRegionFromNodeOrDefault implements Function { - private final Map locations; - - @Inject - protected GetRegionFromNodeOrDefault(Map locations) { - this.locations = locations; - } - public Region apply(ComputeMetadata node) { - Location location = locations.get(node.getLocationId()); + Location location = node.getLocation(); Region region = location.getScope() == LocationScope.REGION ? Region.fromValue(location .getId()) : Region.fromValue(location.getParent()); return region; @@ -261,11 +254,11 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule { Set locations = Sets.newHashSet(); for (AvailabilityZone zone : map.keySet()) { locations.add(new LocationImpl(LocationScope.ZONE, zone.toString(), zone.toString(), map - .get(zone).toString(), true)); + .get(zone).toString())); } for (Region region : map.values()) { locations.add(new LocationImpl(LocationScope.REGION, region.toString(), region.toString(), - null, true)); + null)); } return Maps.uniqueIndex(locations, new Function() { @Override diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java index 020855c287..9ae8fd3c50 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java @@ -18,6 +18,8 @@ */ package org.jclouds.aws.ec2.compute.functions; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -35,6 +37,7 @@ import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; import org.jclouds.logging.Logger; import com.google.common.base.Function; @@ -58,10 +61,14 @@ public class ImageParser implements Function locations; @Inject - ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider) { - this.credentialProvider = credentialProvider; + ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, + Map locations) { + this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); + this.locations = checkNotNull(locations, "locations"); + } @Override @@ -98,7 +105,7 @@ public class ImageParser implements Function of("owner", from.getImageOwnerId()), description, diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java index 80afa80ab8..9e90c4c7cc 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -30,18 +30,19 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.aws.ec2.compute.domain.RegionTag; -import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.functions.InstanceTypeToStorageMappingUnix; import org.jclouds.aws.ec2.options.DescribeImagesOptions; import org.jclouds.aws.ec2.services.AMIClient; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; @@ -62,13 +63,18 @@ public class RunningInstanceToNodeMetadata implements Function credentialsMap; private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider; + private final Map images; + private final Map locations; @Inject RunningInstanceToNodeMetadata(AMIClient amiClient, Map credentialsMap, - PopulateDefaultLoginCredentialsForImageStrategy credentialProvider) { + PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, + Map images, Map locations) { this.amiClient = checkNotNull(amiClient, "amiClient"); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); + this.images = checkNotNull(images, "images"); + this.locations = checkNotNull(locations, "locations"); } @Override @@ -97,8 +103,9 @@ public class RunningInstanceToNodeMetadata implements Function extra = getExtra(instance); - return new NodeMetadataImpl(id, name, locationId, uri, userMetadata, tag, state, - publicAddresses, privateAddresses, extra, credentials); + return new NodeMetadataImpl(id, name, locations.get(locationId), uri, userMetadata, tag, + images.get(instance.getImageId()), state, publicAddresses, privateAddresses, extra, + credentials); } /** @@ -126,14 +133,14 @@ public class RunningInstanceToNodeMetadata implements Function newHashMap(), "description", "1.0", null, "ubuntu", Architecture.X86_64, new Credentials("root", null)); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java index 3e110b13d0..d908f75e17 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java @@ -31,6 +31,7 @@ import org.jclouds.aws.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsFo import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.domain.Location; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; @@ -51,14 +52,16 @@ public class ImageParserTest extends BaseHandlerTest { Set result = parseImages(is); assertEquals(result.size(), 6); - ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy()); + ImageParser parser = new ImageParser( + new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImmutableMap + . of()); org.jclouds.compute.domain.Image ubuntuHardy = parser.apply(Iterables.get(result, 0)); assertEquals(ubuntuHardy.getArchitecture(), org.jclouds.compute.domain.Architecture.X86_32); assertEquals(ubuntuHardy.getDescription(), "ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml"); assertEquals(ubuntuHardy.getId(), "ami-7e28ca17"); - assertEquals(ubuntuHardy.getLocationId(), "default"); + assertEquals(ubuntuHardy.getLocation(), null); assertEquals(ubuntuHardy.getName(), "8.04"); assertEquals(ubuntuHardy.getOsDescription(), "ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml"); @@ -73,7 +76,7 @@ public class ImageParserTest extends BaseHandlerTest { assertEquals(alesticKarmic.getDescription(), "alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml"); assertEquals(alesticKarmic.getId(), "ami-19a34270"); - assertEquals(alesticKarmic.getLocationId(), "default"); + assertEquals(alesticKarmic.getLocation(), null); assertEquals(alesticKarmic.getName(), "9.10"); assertEquals(alesticKarmic.getOsDescription(), "alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml"); @@ -88,7 +91,7 @@ public class ImageParserTest extends BaseHandlerTest { assertEquals(ubuntuKarmic.getDescription(), "ubuntu-images-us/ubuntu-karmic-9.10-i386-server-20100121.manifest.xml"); assertEquals(ubuntuKarmic.getId(), "ami-bb709dd2"); - assertEquals(ubuntuKarmic.getLocationId(), "default"); + assertEquals(ubuntuKarmic.getLocation(), null); assertEquals(ubuntuKarmic.getName(), "9.10"); assertEquals(ubuntuKarmic.getOsDescription(), "ubuntu-images-us/ubuntu-karmic-9.10-i386-server-20100121.manifest.xml"); @@ -106,7 +109,7 @@ public class ImageParserTest extends BaseHandlerTest { assertEquals(alesticHardy.getDescription(), "alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml"); assertEquals(alesticHardy.getId(), "ami-c0fa1ea9"); - assertEquals(alesticHardy.getLocationId(), "default"); + assertEquals(alesticHardy.getLocation(), null); assertEquals(alesticHardy.getName(), "8.04"); assertEquals(alesticHardy.getOsDescription(), "alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml"); @@ -124,7 +127,9 @@ public class ImageParserTest extends BaseHandlerTest { Set result = parseImages(is); - ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy()); + ImageParser parser = new ImageParser( + new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImmutableMap + . of()); org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0)); @@ -132,7 +137,7 @@ public class ImageParserTest extends BaseHandlerTest { assertEquals(image.getDescription(), "vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml"); assertEquals(image.getId(), "ami-870de2ee"); - assertEquals(image.getLocationId(), "default"); + assertEquals(image.getLocation(), null); assertEquals(image.getName(), ""); assertEquals(image.getOsDescription(), "vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml"); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index 0fa27778bc..7a1959f3f6 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -20,6 +20,7 @@ package org.jclouds.aws.ec2.compute.functions; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.verify; import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.imageIds; @@ -41,6 +42,9 @@ import org.jclouds.aws.ec2.services.AMIClient; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -57,12 +61,19 @@ public class RunningInstanceToNodeMetadataTest { throws UnknownHostException { AMIClient amiClient = createMock(AMIClient.class); Map credentialsMap = createMock(Map.class); + Map images = createMock(Map.class); + Map locations = createMock(Map.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); RunningInstance instance = createMock(RunningInstance.class); expect(instance.getId()).andReturn("id").atLeastOnce(); expect(instance.getKeyName()).andReturn(null).atLeastOnce(); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); + Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); + expect(locations.get("us-east-1a")).andReturn(location); + + org.jclouds.compute.domain.Image jcImage = createNiceMock(org.jclouds.compute.domain.Image.class); + expect(images.get("imageId")).andReturn(jcImage); expect(instance.getIpAddress()).andReturn( InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 })); @@ -71,18 +82,23 @@ public class RunningInstanceToNodeMetadataTest { expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); + expect(instance.getImageId()).andReturn("imageId").atLeastOnce(); + expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); replay(amiClient); replay(credentialsMap); replay(credentialProvider); replay(instance); + replay(images); + replay(locations); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, - credentialsMap, credentialProvider); + credentialsMap, credentialProvider, images, locations); NodeMetadata metadata = parser.apply(instance); - + assertEquals(metadata.getLocation(), location); + assertEquals(metadata.getImage(), jcImage); assertEquals(metadata.getTag(), "NOTAG-id"); assertEquals(metadata.getCredentials(), null); @@ -90,6 +106,8 @@ public class RunningInstanceToNodeMetadataTest { verify(credentialsMap); verify(credentialProvider); verify(instance); + verify(images); + verify(locations); } @SuppressWarnings("unchecked") @@ -98,6 +116,9 @@ public class RunningInstanceToNodeMetadataTest { throws UnknownHostException { AMIClient amiClient = createMock(AMIClient.class); Map credentialsMap = createMock(Map.class); + Map images = createMock(Map.class); + Map locations = createMock(Map.class); + PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); RunningInstance instance = createMock(RunningInstance.class); Image image = createMock(Image.class); @@ -106,6 +127,12 @@ public class RunningInstanceToNodeMetadataTest { expect(instance.getKeyName()).andReturn("keyName-100").atLeastOnce(); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); + Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); + expect(locations.get("us-east-1a")).andReturn(location); + + org.jclouds.compute.domain.Image jcImage = createNiceMock(org.jclouds.compute.domain.Image.class); + expect(images.get("imageId")).andReturn(jcImage); + expect(instance.getIpAddress()).andReturn( InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 })); expect(instance.getPrivateIpAddress()).andReturn( @@ -131,13 +158,17 @@ public class RunningInstanceToNodeMetadataTest { replay(credentialsMap); replay(credentialProvider); replay(instance); + replay(images); + replay(locations); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient, - credentialsMap, credentialProvider); + credentialsMap, credentialProvider, images, locations); NodeMetadata metadata = parser.apply(instance); assertEquals(metadata.getTag(), "keyName"); + assertEquals(metadata.getLocation(), location); + assertEquals(metadata.getImage(), jcImage); assertEquals(metadata.getCredentials(), new Credentials("user", "pass")); @@ -145,6 +176,8 @@ public class RunningInstanceToNodeMetadataTest { verify(credentialsMap); verify(credentialProvider); verify(instance); + verify(images); + verify(locations); } } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2ContextModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2ContextModuleTest.java index 9e23ba9e0a..293b1b0c76 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2ContextModuleTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2ContextModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.aws.ec2.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import org.jclouds.aws.ec2.EC2AsyncClient; @@ -62,7 +62,7 @@ public class EC2ContextModuleTest { void testM1SMALLIsSmallest() { // TODO } - + @Test void testContextImpl() { RestContext handler = createInjector().getInstance( diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2RestClientModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2RestClientModuleTest.java index 5fb35d1e0e..d091358443 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2RestClientModuleTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/config/EC2RestClientModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.aws.ec2.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import javax.ws.rs.core.UriBuilder; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java index 06d91db5b9..b4cde8132d 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AMIAsyncClientTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.ec2.services; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.executableBy; import static org.testng.Assert.assertEquals; @@ -26,11 +27,13 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; import java.util.Map; +import java.util.Properties; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; +import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.options.CreateImageOptions; import org.jclouds.aws.ec2.options.DescribeImagesOptions; import org.jclouds.aws.ec2.options.RegisterImageBackedByEbsOptions; @@ -43,8 +46,8 @@ import org.jclouds.aws.ec2.xml.ProductCodesHandler; import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.date.TimeStamp; -import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.CloseContentAndReturn; +import org.jclouds.http.functions.ParseSax; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest; @@ -453,6 +456,8 @@ public class AMIAsyncClientTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) + .build(), "properties")); bind(URI.class).annotatedWith(EC2.class).toInstance( URI.create("https://ec2.amazonaws.com")); bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java index c1efaccabd..367595abe4 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/AvailabilityZoneAndRegionAsyncClientTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.ec2.services; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions.Builder.availabilityZones; import static org.jclouds.aws.ec2.options.DescribeRegionsOptions.Builder.regions; import static org.testng.Assert.assertEquals; @@ -27,11 +28,13 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; import java.util.Map; +import java.util.Properties; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; +import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions; import org.jclouds.aws.ec2.options.DescribeRegionsOptions; @@ -163,6 +166,8 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) + .build(), "properties")); bind(URI.class).annotatedWith(EC2.class).toInstance( URI.create("https://ec2.amazonaws.com")); bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java index 8b976a1569..4687bd45bd 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticBlockStoreAsyncClientTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.ec2.services; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.ec2.options.DescribeSnapshotsOptions.Builder.ownedBy; import static org.jclouds.aws.ec2.options.DetachVolumeOptions.Builder.fromInstance; import static org.testng.Assert.assertEquals; @@ -27,11 +28,13 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; import java.util.Map; +import java.util.Properties; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; +import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.functions.ReturnVoidOnVolumeAvailable; import org.jclouds.aws.ec2.options.CreateSnapshotOptions; @@ -110,11 +113,11 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest httpMethod = processor.createRequest( method, AvailabilityZone.US_EAST_1A, 15, "snapshotId"); @@ -433,6 +436,8 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) + .build(), "properties")); bind(URI.class).annotatedWith(EC2.class).toInstance( URI.create("https://ec2.amazonaws.com")); bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java index fa22d259e7..b7e942ca47 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/KeyPairAsyncClientTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.ec2.services; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -25,11 +26,13 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; import java.util.Map; +import java.util.Properties; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; +import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler; import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; @@ -131,6 +134,8 @@ public class KeyPairAsyncClientTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new EC2PropertiesBuilder(new Properties()) + .build(), "properties")); bind(URI.class).annotatedWith(EC2.class).toInstance( URI.create("https://ec2.amazonaws.com")); bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java index d0a609e109..98a05c2e6b 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/MonitoringAsyncClientTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.ec2.services; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -25,11 +26,13 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; import java.util.Map; +import java.util.Properties; import javax.inject.Singleton; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2; +import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.ec2.xml.MonitoringStateHandler; import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.reference.AWSConstants; @@ -113,6 +116,8 @@ public class MonitoringAsyncClientTest extends RestClientTest { }, new TypeLiteral() { })); install(new S3ObjectModule()); + Jsr330.bindProperties(binder(), checkNotNull(new S3PropertiesBuilder(new Properties()) + .build(), "properties")); bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("http://stub:8080")); bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to( "user"); bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)) .to("key"); - bindConstant().annotatedWith( - Jsr330.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("prefix"); bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { public Logger getLogger(String category) { return Logger.NULL; diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreModuleTest.java index f80a31725f..be3aab49a1 100755 --- a/aws/core/src/test/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreModuleTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/blobstore/config/S3BlobStoreModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.aws.s3.blobstore.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import org.jclouds.Constants; diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/config/S3RestClientModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/config/S3RestClientModuleTest.java index d4929e7132..4981a8208d 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/config/S3RestClientModuleTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/config/S3RestClientModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.aws.s3.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java index c726067820..2eaa0f4bf3 100755 --- a/aws/core/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.aws.s3.filters; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import java.net.URI; diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java index 86953dd260..4753d219af 100644 --- a/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/SQSAsyncClientTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.sqs; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -25,6 +26,7 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; import java.util.Map; +import java.util.Properties; import javax.inject.Singleton; @@ -152,6 +154,8 @@ public class SQSAsyncClientTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new SQSPropertiesBuilder(new Properties()) + .build(), "properties")); bind(URI.class).annotatedWith(SQS.class).toInstance(URI.create("https://default")); bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to( "user"); diff --git a/aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java b/aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java index 89d151ed8c..ed22f932f1 100644 --- a/aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/sqs/config/SQSRestClientModuleTest.java @@ -19,7 +19,7 @@ package org.jclouds.aws.sqs.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import java.net.URI; diff --git a/azure/src/main/java/org/jclouds/azure/storage/blob/predicates/validators/ContainerNameValidator.java b/azure/src/main/java/org/jclouds/azure/storage/blob/predicates/validators/ContainerNameValidator.java index 0195129373..e1347a6beb 100644 --- a/azure/src/main/java/org/jclouds/azure/storage/blob/predicates/validators/ContainerNameValidator.java +++ b/azure/src/main/java/org/jclouds/azure/storage/blob/predicates/validators/ContainerNameValidator.java @@ -1,64 +1,65 @@ /** -* -* Copyright (C) 2010 Cloud Conscious, LLC. -* -* ==================================================================== -* 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. -* ==================================================================== -*/ + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.azure.storage.blob.predicates.validators; -import com.google.common.base.CharMatcher; -import org.jclouds.predicates.Validator; -import javax.annotation.Nullable; -import static com.google.common.base.CharMatcher.*; +import javax.inject.Inject; + +import org.jclouds.predicates.validators.DnsNameValidator; + +import com.google.inject.Singleton; /** -* Validates name for Azure container. -* The complete requirements are listed at: -* http://weblogs.asp.net/vblasberg/archive/2009/02/17/azure-details-and-limitations-blobs-tables-and-queues.aspx -* -* @see org.jclouds.rest.InputParamValidator -* @see org.jclouds.predicates.Validator -* -* @author Oleksiy Yarmula -*/ -public class ContainerNameValidator extends Validator { + * Validates name for Azure container. The complete requirements are listed at: + * http://weblogs.asp.net + * /vblasberg/archive/2009/02/17/azure-details-and-limitations-blobs-tables-and-queues.aspx + * + * @see org.jclouds.rest.InputParamValidator + * @see org.jclouds.predicates.Validator + * + * @author Oleksiy Yarmula + */ +@Singleton +public class ContainerNameValidator extends DnsNameValidator { - public void validate(@Nullable String containerName) { - - if(containerName == null || containerName.length() < 3 || containerName.length() > 63) throw exception(containerName, "Can't be null or empty. Length must be 3 to 63 symbols."); - if(CharMatcher.JAVA_LETTER_OR_DIGIT.indexIn(containerName) != 0) throw exception(containerName, "Should start with letter/number"); - if(!containerName.toLowerCase().equals(containerName)) throw exception(containerName, "Should be only lowercase"); - - /* The name must be a valid DNS name. From wikipedia: - "The characters allowed in a label are a subset of the ASCII character set, a - and includes the characters a through z, A through Z, digits 0 through 9". - From Azure: - Every Dash (-) Must Be Immediately Preceded and Followed by a Letter or Number. - */ - CharMatcher lettersNumbersOrDashes = inRange('a', 'z').or(inRange('0', '9').or(is('-'))); - if(! lettersNumbersOrDashes.matchesAllOf(containerName)) throw exception(containerName, "Should have lowercase ASCII letters, " + - "numbers, or dashes"); - if(containerName.contains("--")) throw exception(containerName, "Every dash must be followed by letter or number"); - if(containerName.endsWith("-")) throw exception(containerName, "Shouldn't end with a dash"); + @Inject + ContainerNameValidator() { + super(3,63); } - private IllegalArgumentException exception(String containerName, String reason) { - return new IllegalArgumentException(String.format("Object '%s' doesn't match Azure container naming convention. " + - "Reason: %s. For more info, please refer to http://weblogs.asp.net/vblasberg/archive/2009/02/17/" + - "azure-details-and-limitations-blobs-tables-and-queues.aspx.", containerName, reason)); - } + public void validate(String containerName) { + super.validate(containerName); + if (containerName.contains("--")) + throw exception(containerName, "Every dash must be followed by letter or number"); + if (containerName.endsWith("-")) + throw exception(containerName, "Shouldn't end with a dash"); + } + + @Override + protected IllegalArgumentException exception(String containerName, String reason) { + return new IllegalArgumentException( + String + .format( + "Object '%s' doesn't match Azure container naming convention. " + + "Reason: %s. For more info, please refer to http://weblogs.asp.net/vblasberg/archive/2009/02/17/" + + "azure-details-and-limitations-blobs-tables-and-queues.aspx.", + containerName, reason)); + } } \ No newline at end of file diff --git a/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobAsyncClientTest.java b/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobAsyncClientTest.java index 1324c3dedb..e7ee3fe213 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobAsyncClientTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/blob/AzureBlobAsyncClientTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.azure.storage.blob; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.azure.storage.blob.options.CreateContainerOptions.Builder.withPublicAcl; import static org.jclouds.azure.storage.options.ListOptions.Builder.maxResults; import static org.testng.Assert.assertEquals; diff --git a/azure/src/test/java/org/jclouds/azure/storage/blob/blobstore/config/AzureBlobStoreModuleTest.java b/azure/src/test/java/org/jclouds/azure/storage/blob/blobstore/config/AzureBlobStoreModuleTest.java index 1befd5a1d5..2b527458df 100755 --- a/azure/src/test/java/org/jclouds/azure/storage/blob/blobstore/config/AzureBlobStoreModuleTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/blob/blobstore/config/AzureBlobStoreModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.azure.storage.blob.blobstore.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties; diff --git a/azure/src/test/java/org/jclouds/azure/storage/blob/config/RestAzureBlobClientModuleTest.java b/azure/src/test/java/org/jclouds/azure/storage/blob/config/RestAzureBlobClientModuleTest.java index 29272bc359..85f3d8cca5 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/blob/config/RestAzureBlobClientModuleTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/blob/config/RestAzureBlobClientModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.azure.storage.blob.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import javax.ws.rs.core.UriBuilder; diff --git a/azure/src/test/java/org/jclouds/azure/storage/predicates/validators/ContainerNameValidatorTest.java b/azure/src/test/java/org/jclouds/azure/storage/blob/predicates/validators/ContainerNameValidatorTest.java similarity index 98% rename from azure/src/test/java/org/jclouds/azure/storage/predicates/validators/ContainerNameValidatorTest.java rename to azure/src/test/java/org/jclouds/azure/storage/blob/predicates/validators/ContainerNameValidatorTest.java index e8ea2ee743..adaba0fd65 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/predicates/validators/ContainerNameValidatorTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/blob/predicates/validators/ContainerNameValidatorTest.java @@ -17,7 +17,7 @@ * ==================================================================== */ -package org.jclouds.azure.storage.predicates.validators; +package org.jclouds.azure.storage.blob.predicates.validators; import org.testng.annotations.Test; import org.jclouds.azure.storage.blob.predicates.validators.ContainerNameValidator; diff --git a/azure/src/test/java/org/jclouds/azure/storage/config/AzureStorageRestClientModuleTest.java b/azure/src/test/java/org/jclouds/azure/storage/config/AzureStorageRestClientModuleTest.java index 9d92137deb..43234859c0 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/config/AzureStorageRestClientModuleTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/config/AzureStorageRestClientModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.azure.storage.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT; import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY; import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL; diff --git a/azure/src/test/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthenticationTest.java b/azure/src/test/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthenticationTest.java index 9e78f4f592..b14532b2fb 100755 --- a/azure/src/test/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthenticationTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/filters/SharedKeyLiteAuthenticationTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.azure.storage.filters; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL; import static org.testng.Assert.assertEquals; diff --git a/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueAsyncClientTest.java b/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueAsyncClientTest.java index f03c145ecf..5679c99ef4 100644 --- a/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueAsyncClientTest.java +++ b/azure/src/test/java/org/jclouds/azure/storage/queue/AzureQueueAsyncClientTest.java @@ -38,7 +38,6 @@ import org.jclouds.azure.storage.options.ListOptions; import org.jclouds.azure.storage.queue.options.PutMessageOptions; import org.jclouds.azure.storage.reference.AzureStorageConstants; import org.jclouds.date.TimeStamp; -import org.jclouds.encryption.internal.Base64; import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ReturnTrueIf2xx; @@ -249,11 +248,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest { @Override String getName(); - /** - * Physical location of the resource. - * - * ex. us-west-1 - * - */ - @Override - String getLocationId(); - /** * URI used to access this resource */ diff --git a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobMetadataImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobMetadataImpl.java index f246d5bc5e..3707d6a2f6 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobMetadataImpl.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/BlobMetadataImpl.java @@ -26,6 +26,7 @@ import java.util.Map; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.StorageType; +import org.jclouds.domain.Location; import com.google.inject.internal.Nullable; @@ -41,7 +42,7 @@ public class BlobMetadataImpl extends StorageMetadataImpl implements Serializabl private final String contentType; private final byte[] contentMD5; - public BlobMetadataImpl(String id, String name, @Nullable String location, URI uri, + public BlobMetadataImpl(String id, String name, @Nullable Location location, URI uri, String eTag, Long size, Date lastModified, Map userMetadata, String contentType, byte[] contentMD5) { super(StorageType.BLOB, id, name, location, uri, eTag, size, lastModified, userMetadata); diff --git a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/StorageMetadataImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/StorageMetadataImpl.java index e5f9e347d5..1858765bfc 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/StorageMetadataImpl.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/StorageMetadataImpl.java @@ -25,6 +25,7 @@ import java.util.Map; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageType; +import org.jclouds.domain.Location; import org.jclouds.domain.internal.ResourceMetadataImpl; import com.google.inject.internal.Nullable; @@ -48,7 +49,7 @@ public class StorageMetadataImpl extends ResourceMetadataImpl imple private final Date lastModified; public StorageMetadataImpl(StorageType type, @Nullable String id, @Nullable String name, - @Nullable String location, @Nullable URI uri, @Nullable String eTag, + @Nullable Location location, @Nullable URI uri, @Nullable String eTag, @Nullable Long size, @Nullable Date lastModified, Map userMetadata) { super(type, id, name, location, uri, userMetadata); this.eTag = eTag; diff --git a/blobstore/src/main/java/org/jclouds/blobstore/functions/ResourceMetadataToRelativePathResourceMetadata.java b/blobstore/src/main/java/org/jclouds/blobstore/functions/ResourceMetadataToRelativePathResourceMetadata.java index f6e3e0fbe5..404b9ee754 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/functions/ResourceMetadataToRelativePathResourceMetadata.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/functions/ResourceMetadataToRelativePathResourceMetadata.java @@ -38,7 +38,7 @@ public class ResourceMetadataToRelativePathResourceMetadata implements name = name.substring(0, name.length() - suffix.length()); } return new StorageMetadataImpl(StorageType.RELATIVE_PATH, md.getId(), name, md - .getLocationId(), md.getUri(), md.getETag(), md.getSize(), md.getLastModified(), md + .getLocation(), md.getUri(), md.getETag(), md.getSize(), md.getLastModified(), md .getUserMetadata()); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/FetchBlobMetadata.java b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/FetchBlobMetadata.java index c5117faed4..099cea2e3e 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/FetchBlobMetadata.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/FetchBlobMetadata.java @@ -19,6 +19,7 @@ package org.jclouds.blobstore.strategy.internal; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.concurrent.ConcurrentUtils.awaitCompletion; import java.util.Map; @@ -45,7 +46,6 @@ import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.common.util.concurrent.Executors; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; @@ -106,7 +106,7 @@ public class FetchBlobMetadata implements Throwables.propagate(e); } } - }, Executors.sameThreadExecutor()); + }, sameThreadExecutor()); responses.put(md, future); } else { metadata.add(md); diff --git a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/GetAllBlobsInListAndRetryOnFailure.java b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/GetAllBlobsInListAndRetryOnFailure.java index a1a458cec1..ff3ca2579a 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/GetAllBlobsInListAndRetryOnFailure.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/GetAllBlobsInListAndRetryOnFailure.java @@ -18,6 +18,7 @@ */ package org.jclouds.blobstore.strategy.internal; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.concurrent.ConcurrentUtils.awaitCompletion; import java.util.Map; @@ -44,7 +45,6 @@ import org.jclouds.logging.Logger; import com.google.common.base.Throwables; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.common.util.concurrent.Executors; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; @@ -102,7 +102,7 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg Throwables.propagate(e); } } - }, Executors.sameThreadExecutor()); + }, sameThreadExecutor()); responses.put(md, future); } exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, String.format( diff --git a/blobstore/src/main/java/org/jclouds/blobstore/util/internal/BlobStoreUtilsImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/util/internal/BlobStoreUtilsImpl.java index c276c58039..ebf1681b12 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/util/internal/BlobStoreUtilsImpl.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/util/internal/BlobStoreUtilsImpl.java @@ -111,7 +111,7 @@ public class BlobStoreUtilsImpl implements BlobStoreUtils { blob.getMetadata().setETag(blobMeta.getETag()); blob.getMetadata().setId(blobMeta.getId()); blob.getMetadata().setLastModified(blobMeta.getLastModified()); - blob.getMetadata().setLocationId(blobMeta.getLocationId()); + blob.getMetadata().setLocation(blobMeta.getLocation()); blob.getMetadata().setUri(blobMeta.getUri()); blob.getMetadata().setUserMetadata(blobMeta.getUserMetadata()); return blob; diff --git a/codegen/core/pom.xml b/codegen/core/pom.xml index cd4427b1f2..1de2e5ea60 100644 --- a/codegen/core/pom.xml +++ b/codegen/core/pom.xml @@ -65,10 +65,16 @@ 2.3.14 - com.google.common - google-guava - 1.0-r11 + com.google.guava + guava + r03 + + com.google.code.findbugs + jsr305 + 1.3.9 + + diff --git a/compute/src/main/java/org/jclouds/compute/domain/NodeMetadata.java b/compute/src/main/java/org/jclouds/compute/domain/NodeMetadata.java index c8b56eb3c3..f9998d3bdd 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/NodeMetadata.java +++ b/compute/src/main/java/org/jclouds/compute/domain/NodeMetadata.java @@ -22,6 +22,8 @@ import java.net.InetAddress; import java.util.Map; import java.util.Set; +import javax.annotation.Nullable; + import org.jclouds.domain.Credentials; /** @@ -39,6 +41,12 @@ public interface NodeMetadata extends ComputeMetadata { */ String getTag(); + /** + * The image this node was created from, if possible to correlate. + */ + @Nullable + Image getImage(); + /** * Current State of the node */ diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/ComputeMetadataImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/ComputeMetadataImpl.java index bed6011f63..298fd2b887 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/ComputeMetadataImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/ComputeMetadataImpl.java @@ -23,6 +23,7 @@ import java.util.Map; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeType; +import org.jclouds.domain.Location; import org.jclouds.domain.internal.ResourceMetadataImpl; /** @@ -35,9 +36,9 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl imple /** The serialVersionUID */ private static final long serialVersionUID = 7374704415964898694L; - public ComputeMetadataImpl(ComputeType type, String id, String name, String locationId, URI uri, + public ComputeMetadataImpl(ComputeType type, String id, String name, Location location, URI uri, Map userMetadata) { - super(type, id, name, locationId, uri, userMetadata); + super(type, id, name, location, uri, userMetadata); } } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java index 1c2965d8dd..5cb3e034af 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java @@ -35,6 +35,7 @@ import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OsFamily; import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; /** * @author Adrian Cole @@ -52,11 +53,11 @@ public class ImageImpl extends ComputeMetadataImpl implements Image { private final Credentials defaultCredentials; - public ImageImpl(String id, String name, String locationId, URI uri, + public ImageImpl(String id, String name, Location location, URI uri, Map userMetadata, String description, String version, @Nullable OsFamily osFamily, String osDescription, Architecture architecture, Credentials defaultCredentials) { - super(ComputeType.IMAGE, id, name, locationId, uri, userMetadata); + super(ComputeType.IMAGE, id, name, location, uri, userMetadata); this.version = checkNotNull(version, "version"); this.osFamily = osFamily; this.description = checkNotNull(description, "description"); @@ -115,7 +116,7 @@ public class ImageImpl extends ComputeMetadataImpl implements Image { @Override public String toString() { - return "[id=" + getId() + ", name=" + getName() + ", locationId=" + getLocationId() + return "[id=" + getId() + ", name=" + getName() + ", locationId=" + getLocation() + ", architecture=" + architecture + ", osDescription=" + osDescription + ", osFamily=" + osFamily + ", version=" + version + "]"; } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java index 2c8fb34712..4a9d5eabb9 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java @@ -28,9 +28,11 @@ import java.util.Set; import javax.annotation.Nullable; import org.jclouds.compute.domain.ComputeType; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; @@ -50,13 +52,16 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat private final Map extra = Maps.newLinkedHashMap(); private final Credentials credentials; private final String tag; + private final Image image; - public NodeMetadataImpl(String id, String name, String locationId, URI uri, - Map userMetadata, @Nullable String tag, NodeState state, - Iterable publicAddresses, Iterable privateAddresses, - Map extra, @Nullable Credentials credentials) { - super(ComputeType.NODE, id, name, locationId, uri, userMetadata); + public NodeMetadataImpl(String id, String name, Location location, URI uri, + Map userMetadata, @Nullable String tag, @Nullable Image image, + NodeState state, Iterable publicAddresses, + Iterable privateAddresses, Map extra, + @Nullable Credentials credentials) { + super(ComputeType.NODE, id, name, location, uri, userMetadata); this.tag = tag; + this.image = image; this.state = checkNotNull(state, "state"); Iterables.addAll(this.publicAddresses, checkNotNull(publicAddresses, "publicAddresses")); Iterables.addAll(this.privateAddresses, checkNotNull(privateAddresses, "privateAddresses")); @@ -80,6 +85,15 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat return credentials; } + /** + * {@inheritDoc} + */ + @Override + @Nullable + public Image getImage() { + return image; + } + /** * {@inheritDoc} */ @@ -115,7 +129,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat @Override public String toString() { return "[id=" + getId() + ", tag=" + getTag() + ", name=" + getName() + ", location=" - + getLocationId() + ", uri=" + getUri() + ", userMetadata=" + getUserMetadata() + + getLocation() + ", uri=" + getUri() + ", userMetadata=" + getUserMetadata() + ", state=" + getState() + ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses + "]"; } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java index 94cee4d1ec..8384d4fe1e 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java @@ -29,6 +29,7 @@ import javax.annotation.Nullable; import org.jclouds.compute.domain.Architecture; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.Size; +import org.jclouds.domain.Location; import org.jclouds.domain.ResourceMetadata; import com.google.common.collect.ComparisonChain; @@ -47,7 +48,7 @@ public class SizeImpl extends ComputeMetadataImpl implements Size { private final Set supportedArchitectures = Sets.newHashSet(); - public SizeImpl(String id, String name, @Nullable String location, URI uri, + public SizeImpl(String id, String name, @Nullable Location location, URI uri, Map userMetadata, double cores, int ram, int disk, Iterable supportedArchitectures) { super(ComputeType.SIZE, id, name, location, uri, userMetadata); diff --git a/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java index e8c0e2669f..bc6ab7aec1 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java @@ -110,8 +110,8 @@ public class TemplateBuilderImpl implements TemplateBuilder { @Override public boolean apply(ComputeMetadata input) { boolean returnVal = true; - if (locationId != null && input.getLocationId() != null) - returnVal = locationId.equals(input.getLocationId()); + if (locationId != null && input.getLocation() != null) + returnVal = locationId.equals(input.getLocation().getId()); return returnVal; } }; @@ -302,8 +302,8 @@ public class TemplateBuilderImpl implements TemplateBuilder { */ @Override public TemplateBuilder fromSize(Size size) { - if (size.getLocationId() != null) - this.locationId = size.getLocationId(); + if (size.getLocation() != null) + this.locationId = size.getLocation().getId(); this.minCores = size.getCores(); this.minRam = size.getRam(); return this; @@ -314,8 +314,8 @@ public class TemplateBuilderImpl implements TemplateBuilder { */ @Override public TemplateBuilder fromImage(Image image) { - if (image.getLocationId() != null) - this.locationId = image.getLocationId(); + if (image.getLocation() != null) + this.locationId = image.getLocation().getId(); if (image.getOsFamily() != null) this.os = image.getOsFamily(); if (image.getName() != null) diff --git a/compute/src/main/java/org/jclouds/compute/strategy/RunNodesAndAddToSetStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/RunNodesAndAddToSetStrategy.java index d170ec0cc8..032962e4b3 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/RunNodesAndAddToSetStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/RunNodesAndAddToSetStrategy.java @@ -24,7 +24,7 @@ import java.util.Set; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; -import org.jclouds.compute.strategy.impl.OneByOneRunNodesAndAddToSetStrategy; +import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.ImplementedBy; @@ -34,7 +34,7 @@ import com.google.inject.ImplementedBy; * * @author Adrian Cole */ -@ImplementedBy(OneByOneRunNodesAndAddToSetStrategy.class) +@ImplementedBy(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class) public interface RunNodesAndAddToSetStrategy { Map> execute(String tag, int count, Template template, diff --git a/compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/impl/EncodeTagIntoNameRunNodesAndAddToSetStrategy.java similarity index 76% rename from compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java rename to compute/src/main/java/org/jclouds/compute/strategy/impl/EncodeTagIntoNameRunNodesAndAddToSetStrategy.java index de01f86e72..5c68b685ff 100755 --- a/compute/src/main/java/org/jclouds/compute/strategy/impl/OneByOneRunNodesAndAddToSetStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/impl/EncodeTagIntoNameRunNodesAndAddToSetStrategy.java @@ -55,7 +55,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adrian Cole */ @Singleton -public class OneByOneRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrategy { +public class EncodeTagIntoNameRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrategy { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @@ -66,7 +66,7 @@ public class OneByOneRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetS protected final ExecutorService executor; @Inject - protected OneByOneRunNodesAndAddToSetStrategy(AddNodeWithTagStrategy addNodeWithTagStrategy, + protected EncodeTagIntoNameRunNodesAndAddToSetStrategy(AddNodeWithTagStrategy addNodeWithTagStrategy, ListNodesStrategy listNodesStrategy, @Named("NAMING_CONVENTION") String nodeNamingConvention, ComputeUtils utils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @@ -77,11 +77,15 @@ public class OneByOneRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetS this.executor = executor; } + /** + * This implementation gets a list of acceptable node names to encode the tag into, then it + * simultaneously runs the nodes and applies options to them. + */ @Override public Map> execute(final String tag, final int count, final Template template, final Set nodes) { Map> responses = Maps.newHashMap(); - for (final String name : getNextNames(tag, count)) { + for (final String name : getNextNames(tag, template, count)) { responses.put(name, makeListenable(executor.submit(new Callable() { @Override public Void call() throws Exception { @@ -104,13 +108,22 @@ public class OneByOneRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetS return responses; } - protected Set getNextNames(final String tag, int count) { + /** + * Find the next node names that can be used. These will be derived from the tag and the + * template. We will pre-allocate a specified quantity, and attempt to verify that there is no + * name conflict with the current service. + * + * @param tag + * @param count + * @param template + * @return + */ + protected Set getNextNames(final String tag, final Template template, int count) { Set names = Sets.newHashSet(); - int nodeIndex = new SecureRandom().nextInt(8096); Map currentNodes = Maps.uniqueIndex(listNodesStrategy .execute(GetNodesOptions.NONE), BaseComputeService.METADATA_TO_NAME); while (names.size() < count) { - String name = String.format(nodeNamingConvention, tag, nodeIndex++); + String name = getNextName(tag, template); if (!currentNodes.containsKey(name)) { names.add(name); } @@ -118,4 +131,16 @@ public class OneByOneRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetS return names; } + /** + * Get a name using a random mechanism that still ties all nodes in a tag together. + * + * This implementation will pass the tag and a hex formatted random number to the configured + * naming convention. + * + */ + protected String getNextName(final String tag, final Template template) { + return String.format(nodeNamingConvention, tag, Integer.toHexString(new SecureRandom() + .nextInt(4095))); + } + } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java index 7055a528d4..931ef1730e 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java @@ -387,8 +387,8 @@ public class ComputeUtils { * returns a new instance of {@link NodeMetadata} that has new credentials */ public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) { - return new NodeMetadataImpl(node.getId(), node.getName(), node.getLocationId(), - node.getUri(), node.getUserMetadata(), node.getTag(), node.getState(), node + return new NodeMetadataImpl(node.getId(), node.getName(), node.getLocation(), node.getUri(), + node.getUserMetadata(), node.getTag(), node.getImage(), node.getState(), node .getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), newCredentials); } diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 105258775f..c3266c12be 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -77,7 +78,7 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@Test(groups = "live", enabled = true, sequential = true, testName = "compute.ComputeServiceLiveTest") +@Test(groups = "live", sequential = true, testName = "compute.ComputeServiceLiveTest") public abstract class BaseComputeServiceLiveTest { @BeforeClass abstract public void setServiceDefaults(); @@ -149,7 +150,7 @@ public abstract class BaseComputeServiceLiveTest { assertEquals(toMatch, template); } - @Test(dependsOnMethods = "testTemplateMatch") + @Test(enabled = true, dependsOnMethods = "testTemplateMatch") public void testCreateTwoNodesWithRunScript() throws Exception { try { client.destroyNodesWithTag(tag); @@ -170,20 +171,39 @@ public abstract class BaseComputeServiceLiveTest { NodeMetadata node2 = nodes.last(); // credentials aren't always the same // assertEquals(node1.getCredentials(), node2.getCredentials()); - assert !node1.getId().equals(node2.getId()); + + assertLocationSameOrChild(node1.getLocation(), template.getLocation()); + assertLocationSameOrChild(node2.getLocation(), template.getLocation()); + + assertEquals(node1.getImage(), template.getImage()); + assertEquals(node2.getImage(), template.getImage()); } - @Test(dependsOnMethods = "testCreateTwoNodesWithRunScript") + void assertLocationSameOrChild(Location test, Location expected) { + if (!test.equals(expected)) { + assertEquals(test.getParent(), expected.getId()); + } else { + assertEquals(test, expected); + } + } + + @Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript") public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { initializeContextAndClient(); + TreeSet nodes = Sets.newTreeSet(client.runNodesWithTag(tag, 1, template) + .values()); + checkNodes(nodes, tag); + NodeMetadata node = nodes.first(); - checkNodes(client.runNodesWithTag(tag, 1, template).values(), tag); + assertEquals(nodes.size(), 1); + assertLocationSameOrChild(node.getLocation(), template.getLocation()); + assertEquals(node.getImage(), template.getImage()); } @Test public void testScriptExecutionAfterBootWithBasicTemplate() throws Exception { - String tag = this.tag + "script"; + String tag = this.tag + "run"; Template simpleTemplate = buildTemplate(client.templateBuilder()); simpleTemplate.getOptions().blockOnPort(22, 60); try { @@ -192,9 +212,9 @@ public abstract class BaseComputeServiceLiveTest { assert good.account != null; try { - runScriptWithCreds(tag, simpleTemplate.getImage().getOsFamily(), new Credentials( - good.account, "romeo")); - assert false : "shouldn't pass with a bad password"; + Map responses = runScriptWithCreds(tag, simpleTemplate.getImage() + .getOsFamily(), new Credentials(good.account, "romeo")); + assert false : "shouldn't pass with a bad password\n" + responses; } catch (SshException e) { assert Throwables.getRootCause(e).getMessage().contains("Auth fail") : e; } @@ -274,7 +294,9 @@ public abstract class BaseComputeServiceLiveTest { metadataSet.remove(node); NodeMetadata metadata = client.getNodeMetadata(node); assertEquals(metadata.getId(), node.getId()); - assertEquals(metadata.getName(), node.getName()); + assertEquals(metadata.getTag(), node.getTag()); + assertEquals(metadata.getLocation(), template.getLocation()); + assertEquals(metadata.getImage(), template.getImage()); assertEquals(metadata.getState(), NodeState.RUNNING); assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses()); assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses()); @@ -298,7 +320,7 @@ public abstract class BaseComputeServiceLiveTest { for (Entry node : client.getNodes().entrySet()) { assertEquals(node.getKey(), node.getValue().getId()); assert node.getValue().getId() != null; - assert node.getValue().getLocationId() != null; + assert node.getValue().getLocation() != null; assertEquals(node.getValue().getType(), ComputeType.NODE); } } @@ -308,17 +330,19 @@ public abstract class BaseComputeServiceLiveTest { new GetNodesOptions().withDetails()).entrySet()) { assertEquals(node.getKey(), node.getValue().getId()); assert node.getValue().getId() != null : node; - assert node.getValue().getLocationId() != null : node; + assert node.getValue().getLocation() != null : node; assertEquals(node.getValue().getType(), ComputeType.NODE); assert node.getValue() instanceof NodeMetadata; NodeMetadata nodeMetadata = (NodeMetadata) node.getValue(); assert nodeMetadata.getId() != null : nodeMetadata; + assert nodeMetadata.getImage() != null : node; // user specified name is not always supported // assert nodeMetadata.getName() != null : nodeMetadata; - assert nodeMetadata.getPublicAddresses() != null : nodeMetadata; - - assert nodeMetadata.getPublicAddresses().size() > 1 : nodeMetadata; - assertNotNull(nodeMetadata.getPrivateAddresses()); + if (nodeMetadata.getState() != NodeState.TERMINATED) { + assert nodeMetadata.getPublicAddresses() != null : nodeMetadata; + assert nodeMetadata.getPublicAddresses().size() > 0 : nodeMetadata; + assertNotNull(nodeMetadata.getPrivateAddresses()); + } } } diff --git a/compute/src/test/java/org/jclouds/compute/internal/TemplateBuilderImplTest.java b/compute/src/test/java/org/jclouds/compute/internal/TemplateBuilderImplTest.java index 9ab1740177..6e8a1482b3 100644 --- a/compute/src/test/java/org/jclouds/compute/internal/TemplateBuilderImplTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/TemplateBuilderImplTest.java @@ -42,7 +42,7 @@ public class TemplateBuilderImplTest { public void testImageIdNullsEverythingElse() { TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableMap. of(), ImmutableMap. of(), ImmutableMap. of(), - new LocationImpl(LocationScope.REGION, " id", "description", null, true)); + new LocationImpl(LocationScope.REGION, " id", "description", null)); template.architecture(Architecture.X86_32); template.imageDescriptionMatches("imageDescriptionMatches"); template.imageNameMatches("imageNameMatches"); diff --git a/core/pom.xml b/core/pom.xml index ada8f26405..f2edc9fa90 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -84,9 +84,14 @@ 1.4 - com.google.common - google-guava - 1.0-r11 + com.google.guava + guava + r03 + + + com.google.code.findbugs + jsr305 + 1.3.9 diff --git a/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java b/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java index d0ecedd7b5..7c8c3237f7 100644 --- a/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java +++ b/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java @@ -18,17 +18,12 @@ */ package org.jclouds.concurrent.internal; -/** - * Generates RESTful clients from appropriately annotated interfaces. - * - * @author Adrian Cole - */ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Arrays; -import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; @@ -39,10 +34,15 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.logging.Logger; import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.util.concurrent.ListenableFuture; +/** + * Generates RESTful clients from appropriately annotated interfaces. + * + * @author Adrian Cole + */ @Singleton public class SyncProxy implements InvocationHandler { @@ -60,7 +60,7 @@ public class SyncProxy implements InvocationHandler { private final Map methodMap; private final Map syncMethodMap; private final Map timeoutMap; - private static final List objectMethods = ImmutableList.of(Object.class.getMethods()); + private static final Set objectMethods = ImmutableSet.copyOf(Object.class.getMethods()); @Inject public SyncProxy(Class declaring, Object delegate) throws SecurityException, diff --git a/core/src/main/java/org/jclouds/domain/Location.java b/core/src/main/java/org/jclouds/domain/Location.java index ce516b9959..bf69c0c056 100644 --- a/core/src/main/java/org/jclouds/domain/Location.java +++ b/core/src/main/java/org/jclouds/domain/Location.java @@ -23,7 +23,6 @@ */ package org.jclouds.domain; - /** * Running Operating system * @@ -53,10 +52,4 @@ public interface Location { */ String getParent(); - /** - * Whether nodes can be assigned to this location. It is possible that a location is a container - * type that cannot be assigned to, or that a location is full. - */ - boolean isAssignable(); - } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/domain/MutableResourceMetadata.java b/core/src/main/java/org/jclouds/domain/MutableResourceMetadata.java index 0359944a14..94e1884eab 100644 --- a/core/src/main/java/org/jclouds/domain/MutableResourceMetadata.java +++ b/core/src/main/java/org/jclouds/domain/MutableResourceMetadata.java @@ -49,9 +49,9 @@ public interface MutableResourceMetadata> extends ResourceMeta void setName(String name); /** - * @see #getLocationId + * @see #getLocation */ - void setLocationId(String location); + void setLocation(Location location); /** * @see #getUri @@ -63,5 +63,4 @@ public interface MutableResourceMetadata> extends ResourceMeta */ void setUserMetadata(Map userMetadata); - } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/domain/ResourceMetadata.java b/core/src/main/java/org/jclouds/domain/ResourceMetadata.java index 2de0eb0003..ae398c9efe 100644 --- a/core/src/main/java/org/jclouds/domain/ResourceMetadata.java +++ b/core/src/main/java/org/jclouds/domain/ResourceMetadata.java @@ -21,6 +21,8 @@ package org.jclouds.domain; import java.net.URI; import java.util.Map; +import org.jclouds.domain.internal.ResourceMetadataImpl; + import com.google.inject.ImplementedBy; /** @@ -28,7 +30,7 @@ import com.google.inject.ImplementedBy; * * @author Adrian Cole */ -@ImplementedBy(ResourceMetadata.class) +@ImplementedBy(ResourceMetadataImpl.class) public interface ResourceMetadata> extends Comparable> { /** @@ -57,7 +59,7 @@ public interface ResourceMetadata> extends Comparable> implements MutableRe private T type; private String id; private String name; - private String location; + private Location location; private URI uri; private Map userMetadata; @@ -53,7 +54,7 @@ public class MutableResourceMetadataImpl> implements MutableRe this.type = from.getType(); this.id = from.getId(); this.name = from.getName(); - this.location = from.getLocationId(); + this.location = from.getLocation(); this.uri = from.getUri(); this.userMetadata = from.getUserMetadata(); } @@ -152,7 +153,7 @@ public class MutableResourceMetadataImpl> implements MutableRe * {@inheritDoc} */ @Override - public void setLocationId(String location) { + public void setLocation(Location location) { this.location = location; } @@ -160,7 +161,7 @@ public class MutableResourceMetadataImpl> implements MutableRe * {@inheritDoc} */ @Override - public String getLocationId() { + public Location getLocation() { return location; } diff --git a/core/src/main/java/org/jclouds/domain/internal/ResourceMetadataImpl.java b/core/src/main/java/org/jclouds/domain/internal/ResourceMetadataImpl.java index 89b78a8eec..6987c384bf 100644 --- a/core/src/main/java/org/jclouds/domain/internal/ResourceMetadataImpl.java +++ b/core/src/main/java/org/jclouds/domain/internal/ResourceMetadataImpl.java @@ -24,6 +24,7 @@ import java.io.Serializable; import java.net.URI; import java.util.Map; +import org.jclouds.domain.Location; import org.jclouds.domain.ResourceMetadata; import com.google.common.collect.Maps; @@ -45,17 +46,17 @@ public class ResourceMetadataImpl> implements ResourceMetadata @Nullable private final String name; @Nullable - private final String locationId; + private final Location location; @Nullable private final URI uri; private final Map userMetadata = Maps.newLinkedHashMap(); public ResourceMetadataImpl(T type, @Nullable String id, @Nullable String name, - @Nullable String locationId, @Nullable URI uri, Map userMetadata) { + @Nullable Location location, @Nullable URI uri, Map userMetadata) { this.type = checkNotNull(type, "type"); this.id = id; this.name = name; - this.locationId = locationId; + this.location = location; this.uri = uri; this.userMetadata.putAll(checkNotNull(userMetadata, "userMetadata")); } @@ -98,8 +99,8 @@ public class ResourceMetadataImpl> implements ResourceMetadata * {@inheritDoc} */ @Override - public String getLocationId() { - return locationId; + public Location getLocation() { + return location; } /** @@ -120,7 +121,7 @@ public class ResourceMetadataImpl> implements ResourceMetadata @Override public String toString() { - return "[type=" + type + ", id=" + id + ", name=" + name + ", location=" + locationId + return "[type=" + type + ", id=" + id + ", name=" + name + ", location=" + location + ", uri=" + uri + ", userMetadata=" + userMetadata + "]"; } @@ -129,7 +130,7 @@ public class ResourceMetadataImpl> implements ResourceMetadata final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((locationId == null) ? 0 : locationId.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); result = prime * result + ((uri == null) ? 0 : uri.hashCode()); @@ -150,10 +151,10 @@ public class ResourceMetadataImpl> implements ResourceMetadata return false; } else if (!id.equals(other.id)) return false; - if (locationId == null) { - if (other.locationId != null) + if (location == null) { + if (other.location != null) return false; - } else if (!locationId.equals(other.locationId)) + } else if (!location.equals(other.location)) return false; if (name == null) { if (other.name != null) @@ -173,5 +174,4 @@ public class ResourceMetadataImpl> implements ResourceMetadata return true; } - } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/http/TransformingHttpCommandExecutorServiceImpl.java b/core/src/main/java/org/jclouds/http/TransformingHttpCommandExecutorServiceImpl.java index 8b7a34a3b0..8e723bc6db 100644 --- a/core/src/main/java/org/jclouds/http/TransformingHttpCommandExecutorServiceImpl.java +++ b/core/src/main/java/org/jclouds/http/TransformingHttpCommandExecutorServiceImpl.java @@ -19,11 +19,11 @@ package org.jclouds.http; import static com.google.common.util.concurrent.Futures.compose; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import javax.inject.Inject; import com.google.common.base.Function; -import com.google.common.util.concurrent.Executors; import com.google.common.util.concurrent.ListenableFuture; /** @@ -46,7 +46,7 @@ public class TransformingHttpCommandExecutorServiceImpl implements */ public ListenableFuture submit(HttpCommand command, Function responseTransformer) { - return compose(client.submit(command), responseTransformer, Executors.sameThreadExecutor()); + return compose(client.submit(command), responseTransformer, sameThreadExecutor()); } } diff --git a/core/src/main/java/org/jclouds/predicates/validators/DnsNameValidator.java b/core/src/main/java/org/jclouds/predicates/validators/DnsNameValidator.java new file mode 100644 index 0000000000..f0873e3cec --- /dev/null +++ b/core/src/main/java/org/jclouds/predicates/validators/DnsNameValidator.java @@ -0,0 +1,79 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.predicates.validators; + +import static com.google.common.base.CharMatcher.inRange; +import static com.google.common.base.CharMatcher.is; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.jclouds.predicates.Validator; + +import com.google.common.base.CharMatcher; +import com.google.inject.Singleton; + +/** + * Validates name for dns-style names + * + * @see org.jclouds.rest.InputParamValidator + * @see org.jclouds.predicates.Validator + * + * @author Adrian Cole + */ +@Singleton +public class DnsNameValidator extends Validator { + private int min; + private int max; + + @Inject + protected DnsNameValidator(@Named("jclouds.dns_name_length_min") int min, + @Named("jclouds.dns_name_length_max") int max) { + this.min = min; + this.max = max; + } + + public void validate(String name) { + + if (name == null || name.length() < min || name.length() > max) + throw exception(name, "Can't be null or empty. Length must be " + min + " to " + max + + " symbols."); + if (CharMatcher.JAVA_LETTER_OR_DIGIT.indexIn(name) != 0) + throw exception(name, "Should start with letter/number"); + if (!name.toLowerCase().equals(name)) + throw exception(name, "Should be only lowercase"); + + /* + * The name must be a valid DNS name. From wikipedia: "The characters allowed in a label are a + * subset of the ASCII character set, a and includes the characters a through z, A through Z, + * digits 0 through 9". From Azure: Every Dash (-) Must Be Immediately Preceded and Followed + * by a Letter or Number. + */ + CharMatcher lettersNumbersOrDashes = inRange('a', 'z').or(inRange('0', '9').or(is('-'))); + if (!lettersNumbersOrDashes.matchesAllOf(name)) + throw exception(name, "Should have lowercase ASCII letters, " + "numbers, or dashes"); + } + + protected IllegalArgumentException exception(String vAppName, String reason) { + return new IllegalArgumentException(String.format( + "Object '%s' doesn't match dns naming constraints. " + "Reason: %s.", vAppName, + reason)); + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/RestContextBuilder.java b/core/src/main/java/org/jclouds/rest/RestContextBuilder.java index 0e078a5545..b926dfae3b 100755 --- a/core/src/main/java/org/jclouds/rest/RestContextBuilder.java +++ b/core/src/main/java/org/jclouds/rest/RestContextBuilder.java @@ -19,7 +19,7 @@ package org.jclouds.rest; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import java.util.ArrayList; import java.util.Arrays; diff --git a/core/src/test/java/org/jclouds/concurrent/FutureExceptionParserTest.java b/core/src/test/java/org/jclouds/concurrent/FutureExceptionParserTest.java index a81ad69e14..b8df87660a 100755 --- a/core/src/test/java/org/jclouds/concurrent/FutureExceptionParserTest.java +++ b/core/src/test/java/org/jclouds/concurrent/FutureExceptionParserTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.concurrent; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.concurrent.ConcurrentUtils.makeListenable; import static org.jclouds.util.Utils.propagateOrNull; import static org.testng.Assert.assertEquals; @@ -33,7 +34,6 @@ import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.Iterables; -import com.google.common.util.concurrent.Executors; import com.google.common.util.concurrent.ListenableFuture; /** @@ -43,7 +43,7 @@ import com.google.common.util.concurrent.ListenableFuture; */ @Test(groups = "unit", testName = "concurrent.ListenableFutureExceptionParserTest") public class FutureExceptionParserTest { - ExecutorService executorService = Executors.sameThreadExecutor(); + ExecutorService executorService = sameThreadExecutor(); @Test public void testGet() throws InterruptedException, ExecutionException { diff --git a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java index 929e3a3a7c..a03907aa6a 100644 --- a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java +++ b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.rest; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import java.lang.reflect.Method; import java.net.URI; diff --git a/core/src/test/java/org/jclouds/rest/RestClientTest.java b/core/src/test/java/org/jclouds/rest/RestClientTest.java index a9ef09f853..90b6ceb869 100644 --- a/core/src/test/java/org/jclouds/rest/RestClientTest.java +++ b/core/src/test/java/org/jclouds/rest/RestClientTest.java @@ -18,15 +18,13 @@ */ package org.jclouds.rest; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import java.io.IOException; import java.lang.reflect.Method; -import java.net.URI; -import org.jclouds.PropertiesBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.HttpUtils; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; @@ -34,11 +32,9 @@ import org.jclouds.rest.config.RestModule; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; import org.testng.annotations.BeforeClass; -import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Key; @@ -47,7 +43,25 @@ import com.google.inject.TypeLiteral; import com.google.inject.internal.Nullable; public abstract class RestClientTest { - +// , new AbstractModule() { +// +// @Override +// protected void configure() { +// Jsr330.bindProperties(binder(), new PropertiesBuilder() { +// +// @Override +// public PropertiesBuilder withCredentials(String account, String key) { +// return null; +// } +// +// @Override +// public PropertiesBuilder withEndpoint(URI endpoint) { +// return null; +// } +// }.build()); +// } +// +// } protected RestAnnotationProcessor processor; protected Injector injector; @@ -60,25 +74,8 @@ public abstract class RestClientTest { @BeforeClass protected void setupFactory() { - injector = Guice.createInjector(createModule(), new AbstractModule() { - - @Override - protected void configure() { - Jsr330.bindProperties(binder(), new PropertiesBuilder() { - - @Override - public PropertiesBuilder withCredentials(String account, String key) { - return null; - } - - @Override - public PropertiesBuilder withEndpoint(URI endpoint) { - return null; - } - }.build()); - } - - }, new RestModule(), new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()), + injector = Guice.createInjector(createModule(), new RestModule(), new ExecutorServiceModule( + sameThreadExecutor(), sameThreadExecutor()), new JavaUrlHttpCommandExecutorServiceModule()); processor = injector.getInstance(Key.get(createTypeLiteral())); diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index 45c226b345..4662001766 100755 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -19,7 +19,7 @@ package org.jclouds.rest.internal; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; diff --git a/extensions/gae/src/main/java/org/jclouds/gae/AsyncGaeHttpCommandExecutorService.java b/extensions/gae/src/main/java/org/jclouds/gae/AsyncGaeHttpCommandExecutorService.java index 58841b6652..fc57dfbf3d 100644 --- a/extensions/gae/src/main/java/org/jclouds/gae/AsyncGaeHttpCommandExecutorService.java +++ b/extensions/gae/src/main/java/org/jclouds/gae/AsyncGaeHttpCommandExecutorService.java @@ -19,6 +19,7 @@ package org.jclouds.gae; import static com.google.appengine.api.urlfetch.FetchOptions.Builder.disallowTruncate; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -53,7 +54,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.io.ByteStreams; import com.google.common.io.Closeables; -import com.google.common.util.concurrent.Executors; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -84,8 +84,8 @@ public class AsyncGaeHttpCommandExecutorService implements HttpCommandExecutorSe public ListenableFuture submit(HttpCommand command) { // TODO: this needs to handle retrying and filtering return Futures.compose(ConcurrentUtils.makeListenable(urlFetchService - .fetchAsync(convertToGaeRequest.apply(command.getRequest())), Executors - .sameThreadExecutor()), convertToJcloudsResponse); + .fetchAsync(convertToGaeRequest.apply(command.getRequest())), sameThreadExecutor()), + convertToJcloudsResponse); } @Singleton diff --git a/extensions/gae/src/main/java/org/jclouds/gae/config/GoogleAppEngineConfigurationModule.java b/extensions/gae/src/main/java/org/jclouds/gae/config/GoogleAppEngineConfigurationModule.java index 96541bd21c..a463e5326b 100644 --- a/extensions/gae/src/main/java/org/jclouds/gae/config/GoogleAppEngineConfigurationModule.java +++ b/extensions/gae/src/main/java/org/jclouds/gae/config/GoogleAppEngineConfigurationModule.java @@ -18,6 +18,8 @@ */ package org.jclouds.gae.config; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; + import org.jclouds.concurrent.SingleThreaded; import org.jclouds.concurrent.config.ConfiguresExecutorService; import org.jclouds.concurrent.config.ExecutorServiceModule; @@ -30,7 +32,6 @@ import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; import com.google.appengine.api.urlfetch.URLFetchService; import com.google.appengine.api.urlfetch.URLFetchServiceFactory; -import com.google.common.util.concurrent.Executors; import com.google.inject.Provides; /** @@ -44,7 +45,7 @@ import com.google.inject.Provides; public class GoogleAppEngineConfigurationModule extends ExecutorServiceModule { public GoogleAppEngineConfigurationModule() { - super(Executors.sameThreadExecutor(), Executors.sameThreadExecutor()); + super(sameThreadExecutor(), sameThreadExecutor()); } @Override diff --git a/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java index 45868b9d4b..3bb5659915 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java @@ -29,7 +29,7 @@ import java.util.Properties; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; -import org.jclouds.gogrid.config.GoGridComputeServiceContextModule; +import org.jclouds.gogrid.compute.config.GoGridComputeServiceContextModule; import org.jclouds.gogrid.config.GoGridRestClientModule; import org.jclouds.gogrid.config.internal.GoGridResolveImagesModule; diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindRealIpPortPairsToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindRealIpPortPairsToQueryParams.java index a2d48784a8..2ff0b94ff4 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindRealIpPortPairsToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindRealIpPortPairsToQueryParams.java @@ -32,36 +32,36 @@ import static org.jclouds.gogrid.reference.GoGridQueryParams.REAL_IP_LIST_KEY; /** * Binds a list of real IPs to the request. - * - * The {@link IpPortPair pairs} must have a {@link IpPortPair#ip} set with a valid - * IP address. - * + * + * The {@link IpPortPair pairs} must have a {@link IpPortPair#ip} set with a valid IP address. + * * @author Oleksiy Yarmula */ public class BindRealIpPortPairsToQueryParams implements Binder { - @SuppressWarnings({"unchecked"}) - @Override - public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - checkArgument(checkNotNull(input, "input is null") instanceof List, - "this binder is only valid for a List argument"); + @SuppressWarnings( { "unchecked" }) + @Override + public void bindToRequest(HttpRequest request, Object input) { + checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, + "this binder is only valid for GeneratedHttpRequests!"); + checkArgument(checkNotNull(input, "input is null") instanceof List, + "this binder is only valid for a List argument"); - List ipPortPairs = (List) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; + List ipPortPairs = (List) input; + GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - int i= 0; - for(IpPortPair ipPortPair : ipPortPairs) { - checkNotNull(ipPortPair.getIp(), "There must be an IP address defined"); - checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object"); - checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); + int i = 0; + for (IpPortPair ipPortPair : ipPortPairs) { + checkNotNull(ipPortPair.getIp(), "There must be an IP address defined"); + checkNotNull(ipPortPair.getIp().getIp(), + "There must be an IP address defined in Ip object"); + checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); - generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".ip", - ipPortPair.getIp().getIp()); - generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".port", - String.valueOf(ipPortPair.getPort())); - i++; - } - } + generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp() + .getHostAddress()); + generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".port", String.valueOf(ipPortPair + .getPort())); + i++; + } + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java index c3a0e86fde..425a383f75 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java @@ -51,7 +51,8 @@ public class BindVirtualIpPortPairToQueryParams implements Binder { checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object"); checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); - generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp()); + generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp() + .getHostAddress()); generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort())); } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java similarity index 89% rename from gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java rename to gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java index b4545d0c2b..e275655bf1 100755 --- a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridComputeServiceContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java @@ -16,9 +16,9 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.gogrid.config; +package org.jclouds.gogrid.compute.config; -import static com.google.common.base.Preconditions.*; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.domain.OsFamily.CENTOS; import java.net.InetAddress; @@ -48,20 +48,26 @@ import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.internal.ImageImpl; -import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.predicates.RunScriptRunning; import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.compute.strategy.*; +import org.jclouds.compute.strategy.AddNodeWithTagStrategy; +import org.jclouds.compute.strategy.DestroyNodeStrategy; +import org.jclouds.compute.strategy.GetNodeMetadataStrategy; +import org.jclouds.compute.strategy.ListNodesStrategy; +import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.internal.LocationImpl; import org.jclouds.gogrid.GoGridAsyncClient; import org.jclouds.gogrid.GoGridClient; +import org.jclouds.gogrid.compute.functions.ServerToNodeMetadata; +import org.jclouds.gogrid.config.GoGridContextModule; import org.jclouds.gogrid.domain.Ip; import org.jclouds.gogrid.domain.IpType; import org.jclouds.gogrid.domain.PowerCommand; @@ -75,12 +81,10 @@ import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.jclouds.ssh.SshClient; -import com.google.common.base.CharMatcher; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -115,7 +119,7 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule { @Named("NAMING_CONVENTION") @Singleton String provideNamingConvention() { - return "%s-%d"; + return "%s-%s"; } @Singleton @@ -315,36 +319,6 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule { }; } - @Singleton - private static class ServerToNodeMetadata implements Function { - private final Map serverStateToNodeState; - private final Function stringIpToInetAddress; - private final GoGridClient client; - - @SuppressWarnings("unused") - @Inject - ServerToNodeMetadata(Map serverStateToNodeState, - Function stringIpToInetAddress, GoGridClient client) { - this.serverStateToNodeState = serverStateToNodeState; - this.stringIpToInetAddress = stringIpToInetAddress; - this.client = client; - } - - @Override - public NodeMetadata apply(Server from) { - String locationId = "Unavailable"; - String tag = CharMatcher.JAVA_LETTER.retainFrom(from.getName()); - Set ipSet = ImmutableSet - .of(stringIpToInetAddress.apply(from.getIp().getIp())); - NodeState state = serverStateToNodeState.get(from.getState().getName()); - Credentials creds = client.getServerServices().getServerCredentialsList().get( - from.getName()); - return new NodeMetadataImpl(from.getId() + "", from.getName(), locationId, null, - ImmutableMap. of(), tag, state, ipSet, ImmutableList - . of(), ImmutableMap. of(), creds); - } - } - @Provides @Singleton ComputeServiceContext provideContext(ComputeService computeService, @@ -372,8 +346,8 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule { Function indexer) { final Set locations = Sets.newHashSet(); holder.logger.debug(">> providing locations"); - locations.add(new LocationImpl(LocationScope.ZONE, "SANFRANCISCO", "San Francisco, CA", null, - true)); + locations + .add(new LocationImpl(LocationScope.ZONE, "SANFRANCISCO", "San Francisco, CA", null)); holder.logger.debug("<< locations(%d)", locations.size()); return Maps.uniqueIndex(locations, new Function() { @@ -452,8 +426,8 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule { holder.logger.debug("<< didn't match os(%s)", matchedOs); } Credentials defaultCredentials = authenticator.execute(from); - images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), location.getId(), - null, ImmutableMap. of(), from.getDescription(), version, os, + images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), location, null, + ImmutableMap. of(), from.getDescription(), version, os, osDescription, arch, defaultCredentials)); } holder.logger.debug("<< images(%d)", images.size()); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java new file mode 100644 index 0000000000..75550c6aea --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java @@ -0,0 +1,74 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.gogrid.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.InetAddress; +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.internal.NodeMetadataImpl; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.gogrid.domain.Server; +import org.jclouds.gogrid.services.GridServerClient; + +import com.google.common.base.CharMatcher; +import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * @author Oleksiy Yarmula + */ +@Singleton +public class ServerToNodeMetadata implements Function { + private final Map serverStateToNodeState; + private final GridServerClient client; + private final Location location; + private final Map images; + + @Inject + ServerToNodeMetadata(Map serverStateToNodeState, GridServerClient client, + Map images, Location location) { + this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState"); + this.client = checkNotNull(client, "client"); + this.images = checkNotNull(images, "images"); + this.location = checkNotNull(location, "location"); + } + + @Override + public NodeMetadata apply(Server from) { + String tag = CharMatcher.JAVA_LETTER.retainFrom(from.getName()); + Set ipSet = ImmutableSet.of(from.getIp().getIp()); + NodeState state = serverStateToNodeState.get(from.getState().getName()); + Credentials creds = client.getServerCredentialsList().get(from.getName()); + return new NodeMetadataImpl(from.getId() + "", from.getName(), location, null, ImmutableMap + . of(), tag, images.get(from.getImage().getId() + ""), state, ipSet, + ImmutableList. of(), ImmutableMap. of(), creds); + } +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/Ip.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/Ip.java index 9f4f0d4616..284bd154f3 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/domain/Ip.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/Ip.java @@ -23,6 +23,8 @@ */ package org.jclouds.gogrid.domain; +import java.net.InetAddress; + import com.google.common.primitives.Longs; import com.google.gson.annotations.SerializedName; @@ -31,97 +33,99 @@ import com.google.gson.annotations.SerializedName; */ public class Ip implements Comparable { - private long id; + private long id; - private String ip; - private String subnet; - @SerializedName("public") - private boolean isPublic; - private IpState state; + private InetAddress ip; + private String subnet; + @SerializedName("public") + private boolean isPublic; + private IpState state; - /** - * A no-args constructor is required for deserialization - */ - public Ip() { - } + /** + * A no-args constructor is required for deserialization + */ + public Ip() { + } - /** - * Constructs a generic IP address - * without any additional options. - * - * @param ip ip address - */ - public Ip(String ip) { - this.ip = ip; - } + /** + * Constructs a generic IP address without any additional options. + * + * @param ip + * ip address + */ + public Ip(InetAddress ip) { + this.ip = ip; + } - public Ip(long id, String ip, String subnet, boolean isPublic, IpState state) { - this.id = id; - this.ip = ip; - this.subnet = subnet; - this.isPublic = isPublic; - this.state = state; - } + public Ip(long id, InetAddress ip, String subnet, boolean isPublic, IpState state) { + this.id = id; + this.ip = ip; + this.subnet = subnet; + this.isPublic = isPublic; + this.state = state; + } - public long getId() { - return id; - } + public long getId() { + return id; + } - public String getIp() { - return ip; - } + public InetAddress getIp() { + return ip; + } - public String getSubnet() { - return subnet; - } + public String getSubnet() { + return subnet; + } - public boolean isPublic() { - return isPublic; - } + public boolean isPublic() { + return isPublic; + } - public IpState getState() { - return state; - } + public IpState getState() { + return state; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; - Ip ip1 = (Ip) o; + Ip ip1 = (Ip) o; - if (id != ip1.id) return false; - if (isPublic != ip1.isPublic) return false; - if (!ip.equals(ip1.ip)) return false; - if (state != null ? !state.equals(ip1.state) : ip1.state != null) return false; - if (subnet != null ? !subnet.equals(ip1.subnet) : ip1.subnet != null) return false; + if (id != ip1.id) + return false; + if (isPublic != ip1.isPublic) + return false; + if (!ip.equals(ip1.ip)) + return false; + if (state != null ? !state.equals(ip1.state) : ip1.state != null) + return false; + if (subnet != null ? !subnet.equals(ip1.subnet) : ip1.subnet != null) + return false; - return true; - } + return true; + } - @Override - public int hashCode() { - int result = (int) (id ^ (id >>> 32)); - result = 31 * result + ip.hashCode(); - result = 31 * result + (subnet != null ? subnet.hashCode() : 0); - result = 31 * result + (isPublic ? 1 : 0); - result = 31 * result + (state != null ? state.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + ip.hashCode(); + result = 31 * result + (subnet != null ? subnet.hashCode() : 0); + result = 31 * result + (isPublic ? 1 : 0); + result = 31 * result + (state != null ? state.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "Ip{" + - "id=" + id + - ", ip='" + ip + '\'' + - ", subnet='" + subnet + '\'' + - ", isPublic=" + isPublic + - ", state=" + state + - '}'; - } + @Override + public String toString() { + return "Ip{" + "id=" + id + ", ip='" + ip + '\'' + ", subnet='" + subnet + '\'' + + ", isPublic=" + isPublic + ", state=" + state + '}'; + } - @Override - public int compareTo(Ip o) { - return Longs.compare(id, o.getId()); - } + @Override + public int compareTo(Ip o) { + return Longs.compare(id, o.getId()); + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerAsyncClient.java b/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerAsyncClient.java index 4a6cfe1335..0a9eecda40 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerAsyncClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerAsyncClient.java @@ -23,8 +23,21 @@ */ package org.jclouds.gogrid.services; -import com.google.common.util.concurrent.ListenableFuture; +import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION; +import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY; +import static org.jclouds.gogrid.reference.GoGridQueryParams.IMAGE_KEY; +import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_KEY; +import static org.jclouds.gogrid.reference.GoGridQueryParams.LOOKUP_LIST_KEY; +import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY; +import static org.jclouds.gogrid.reference.GoGridQueryParams.POWER_KEY; +import static org.jclouds.gogrid.reference.GoGridQueryParams.SERVER_ID_OR_NAME_KEY; +import static org.jclouds.gogrid.reference.GoGridQueryParams.SERVER_RAM_KEY; +import java.net.InetAddress; +import java.util.Map; +import java.util.Set; + +import javax.inject.Singleton; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; @@ -43,18 +56,20 @@ import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse; import org.jclouds.gogrid.functions.ParseServerNameToCredentialsMapFromJsonResponse; import org.jclouds.gogrid.options.AddServerOptions; import org.jclouds.gogrid.options.GetServerListOptions; -import org.jclouds.rest.annotations.*; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; -import java.util.Map; -import java.util.Set; - -import static org.jclouds.gogrid.reference.GoGridQueryParams.*; -import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION; +import com.google.common.base.Function; +import com.google.common.util.concurrent.ListenableFuture; /** * Provides asynchronous access to GoGrid via their REST API. *

- * + * * @see GridServerClient * @see * @author Adrian Cole @@ -65,81 +80,92 @@ import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION; @QueryParams(keys = VERSION, values = "1.3") public interface GridServerAsyncClient { - /** + /** * @see GridServerClient#getServerList(org.jclouds.gogrid.options.GetServerListOptions...) */ - @GET - @ResponseParser(ParseServerListFromJsonResponse.class) - @Path("/grid/server/list") - ListenableFuture> getServerList(GetServerListOptions... getServerListOptions); + @GET + @ResponseParser(ParseServerListFromJsonResponse.class) + @Path("/grid/server/list") + ListenableFuture> getServerList(GetServerListOptions... getServerListOptions); - /** + /** * @see GridServerClient#getServersByName(String...) */ - @GET - @ResponseParser(ParseServerListFromJsonResponse.class) - @Path("/grid/server/get") - ListenableFuture> getServersByName(@BinderParam(BindNamesToQueryParams.class) String... names); + @GET + @ResponseParser(ParseServerListFromJsonResponse.class) + @Path("/grid/server/get") + ListenableFuture> getServersByName( + @BinderParam(BindNamesToQueryParams.class) String... names); - /** + /** * @see GridServerClient#getServersById(Long...) */ - @GET - @ResponseParser(ParseServerListFromJsonResponse.class) - @Path("/grid/server/get") - ListenableFuture> getServersById(@BinderParam(BindIdsToQueryParams.class) Long... ids); + @GET + @ResponseParser(ParseServerListFromJsonResponse.class) + @Path("/grid/server/get") + ListenableFuture> getServersById( + @BinderParam(BindIdsToQueryParams.class) Long... ids); - /** + /** * @see GridServerClient#getServerCredentialsList */ - @GET - @ResponseParser(ParseServerNameToCredentialsMapFromJsonResponse.class) - @Path("/support/password/list") - ListenableFuture> getServerCredentialsList(); + @GET + @ResponseParser(ParseServerNameToCredentialsMapFromJsonResponse.class) + @Path("/support/password/list") + ListenableFuture> getServerCredentialsList(); - /** - * @see GridServerClient#addServer(String, String, String, String, org.jclouds.gogrid.options.AddServerOptions...) + /** + * @see GridServerClient#addServer(String, String, String, String, + * org.jclouds.gogrid.options.AddServerOptions...) */ - @GET - @ResponseParser(ParseServerFromJsonResponse.class) - @Path("/grid/server/add") - ListenableFuture addServer(@QueryParam(NAME_KEY) String name, - @QueryParam(IMAGE_KEY) String image, - @QueryParam(SERVER_RAM_KEY) String ram, - @QueryParam(IP_KEY) String ip, - AddServerOptions... addServerOptions); + @GET + @ResponseParser(ParseServerFromJsonResponse.class) + @Path("/grid/server/add") + ListenableFuture addServer(@QueryParam(NAME_KEY) String name, + @QueryParam(IMAGE_KEY) String image, @QueryParam(SERVER_RAM_KEY) String ram, + @QueryParam(IP_KEY) @ParamParser(InetAddressHostName.class) InetAddress ip, + AddServerOptions... addServerOptions); - /** + @Singleton + public static class InetAddressHostName implements Function { + + public String apply(Object from) { + return ((InetAddress) from).getHostAddress(); + } + + } + + /** * @see GridServerClient#power(String, org.jclouds.gogrid.domain.PowerCommand) */ - @GET - @ResponseParser(ParseServerFromJsonResponse.class) - @Path("/grid/server/power") - ListenableFuture power(@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName, - @QueryParam(POWER_KEY) PowerCommand power); + @GET + @ResponseParser(ParseServerFromJsonResponse.class) + @Path("/grid/server/power") + ListenableFuture power(@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName, + @QueryParam(POWER_KEY) PowerCommand power); - /** + /** * @see GridServerClient#deleteById(Long) */ - @GET - @ResponseParser(ParseServerFromJsonResponse.class) - @Path("/grid/server/delete") - ListenableFuture deleteById(@QueryParam(ID_KEY) Long id); + @GET + @ResponseParser(ParseServerFromJsonResponse.class) + @Path("/grid/server/delete") + ListenableFuture deleteById(@QueryParam(ID_KEY) Long id); - /** - * @see GridServerClient#deleteByName(String) + /** + * @see GridServerClient#deleteByName(String) */ - @GET - @ResponseParser(ParseServerFromJsonResponse.class) - @Path("/grid/server/delete") - ListenableFuture deleteByName(@QueryParam(NAME_KEY) String name); + @GET + @ResponseParser(ParseServerFromJsonResponse.class) + @Path("/grid/server/delete") + ListenableFuture deleteByName(@QueryParam(NAME_KEY) String name); - /** - * @see GridServerClient#getRamSizes - */ - @GET - @ResponseParser(ParseOptionsFromJsonResponse.class) - @Path("/common/lookup/list") - @QueryParams(keys = LOOKUP_LIST_KEY, values = "server.ram") - ListenableFuture> getRamSizes(); + /** + * @see GridServerClient#getRamSizes + */ + @GET + @ResponseParser(ParseOptionsFromJsonResponse.class) + @Path("/common/lookup/list") + @QueryParams(keys = LOOKUP_LIST_KEY, values = "server.ram") + ListenableFuture> getRamSizes(); } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerClient.java b/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerClient.java index fee891dcf0..cf382f2e69 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/services/GridServerClient.java @@ -23,6 +23,7 @@ */ package org.jclouds.gogrid.services; +import java.net.InetAddress; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -101,7 +102,7 @@ public interface GridServerClient { Server addServer(String name, String image, String ram, - String ip, + InetAddress ip, AddServerOptions... addServerOptions); @@ -145,7 +146,7 @@ public interface GridServerClient { * most cases, id or name will be used for {@link #addServer}. * * To see how RAM maps to CPU and disk space (as of March 2010), - * see {@link org.jclouds.gogrid.config.GoGridComputeServiceContextModule#provideSizeToRam}. + * see {@link org.jclouds.gogrid.compute.config.GoGridComputeServiceContextModule#provideSizeToRam}. * * @return supported ram sizes */ diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTest.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTest.java index 739525be32..dfcf6acf0a 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTest.java @@ -25,7 +25,6 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Arrays; @@ -345,8 +344,7 @@ public class GoGridLiveTest { Credentials instanceCredentials = credsMap.get(createdServer.getName()); assertNotNull(instanceCredentials); - InetSocketAddress socket = new InetSocketAddress(InetAddress.getByName(createdServer.getIp() - .getIp()), 22); + InetSocketAddress socket = new InetSocketAddress(createdServer.getIp().getIp(), 22); Predicate socketOpen = new RetryablePredicate( new SocketOpen(), 180, 5, TimeUnit.SECONDS); diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java new file mode 100644 index 0000000000..2ee01da79b --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java @@ -0,0 +1,87 @@ +package org.jclouds.gogrid.compute.functions; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Map; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.gogrid.domain.Ip; +import org.jclouds.gogrid.domain.Option; +import org.jclouds.gogrid.domain.Server; +import org.jclouds.gogrid.domain.ServerImage; +import org.jclouds.gogrid.services.GridServerClient; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "gogrid.ServerToNodeMetadataTest") +public class ServerToNodeMetadataTest { + + @SuppressWarnings("unchecked") + @Test + public void testApplySetsTagFromNameAndCredentialsFromName() throws UnknownHostException { + GridServerClient client = createMock(GridServerClient.class); + Map serverStateToNodeState = createMock(Map.class); + Map images = createMock(Map.class); + Server server = createMock(Server.class); + + expect(server.getId()).andReturn(1000l).atLeastOnce(); + expect(server.getName()).andReturn("tag").atLeastOnce(); + expect(server.getState()).andReturn(new Option("RUNNING")).atLeastOnce(); + + expect(serverStateToNodeState.get("RUNNING")).andReturn(NodeState.RUNNING); + Location location = new LocationImpl(LocationScope.ZONE, "sanfran", "description", null); + + Map credentialsMap = createMock(Map.class); + expect(client.getServerCredentialsList()).andReturn(credentialsMap); + expect(credentialsMap.get("tag")).andReturn(new Credentials("user", "pass")); + + expect(server.getIp()).andReturn( + new Ip(InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }))); + + ServerImage image = createMock(ServerImage.class); + expect(server.getImage()).andReturn(image).atLeastOnce(); + expect(image.getId()).andReturn(2000l).atLeastOnce(); + + + org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); + expect(images.get("2000")).andReturn(jcImage); + + + replay(client); + replay(serverStateToNodeState); + replay(server); + replay(image); + replay(credentialsMap); + replay(images); + + ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, client, + images, location); + + NodeMetadata metadata = parser.apply(server); + assertEquals(metadata.getLocation(), location); + assertEquals(metadata.getImage(), jcImage); + assertEquals(metadata.getTag(), "tag"); + assertEquals(metadata.getCredentials(), new Credentials("user", "pass")); + + verify(client); + verify(serverStateToNodeState); + verify(image); + verify(credentialsMap); + verify(server); + verify(images); + } + +} diff --git a/gogrid/src/test/java/org/jclouds/gogrid/config/GoGridContextModuleTest.java b/gogrid/src/test/java/org/jclouds/gogrid/config/GoGridContextModuleTest.java index 296423a67f..373c38b445 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/config/GoGridContextModuleTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/config/GoGridContextModuleTest.java @@ -18,14 +18,16 @@ */ package org.jclouds.gogrid.config; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; import javax.ws.rs.core.UriBuilder; import org.jboss.resteasy.specimpl.UriBuilderImpl; +import org.jclouds.Constants; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.gogrid.handlers.GoGridErrorHandler; +import org.jclouds.gogrid.reference.GoGridConstants; import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.functions.config.ParserModule; @@ -35,9 +37,7 @@ import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.gogrid.reference.GoGridConstants; import org.jclouds.util.Jsr330; -import org.jclouds.Constants; import org.testng.annotations.Test; import com.google.inject.Guice; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java index aa041cad6d..6a88e1c3ab 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java @@ -21,6 +21,7 @@ package org.jclouds.gogrid.functions; import static org.testng.Assert.assertEquals; import java.io.InputStream; +import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Map; import java.util.SortedSet; @@ -63,14 +64,14 @@ public class ParseLoadBalancersFromJsonResponseTest { .getInstance(Gson.class)); SortedSet response = parser.apply(is); - LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null, new IpPortPair( - new Ip(1313082L, "204.51.240.181", "204.51.240.176/255.255.255.240", true, - IpState.ASSIGNED), 80), ImmutableSortedSet.of(new IpPortPair( - new Ip(1313086L, "204.51.240.185", "204.51.240.176/255.255.255.240", true, - IpState.ASSIGNED), 80), new IpPortPair(new Ip(1313089L, "204.51.240.188", - "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED), 80)), - LoadBalancerType.ROUND_ROBIN, LoadBalancerPersistenceType.NONE, LoadBalancerOs.F5, - LoadBalancerState.ON); + LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null, new IpPortPair(new Ip( + 1313082L, InetAddress.getByName("204.51.240.181"), "204.51.240.176/255.255.255.240", + true, IpState.ASSIGNED), 80), ImmutableSortedSet.of(new IpPortPair(new Ip(1313086L, + InetAddress.getByName("204.51.240.185"), "204.51.240.176/255.255.255.240", true, + IpState.ASSIGNED), 80), new IpPortPair(new Ip(1313089L, InetAddress + .getByName("204.51.240.188"), "204.51.240.176/255.255.255.240", true, + IpState.ASSIGNED), 80)), LoadBalancerType.ROUND_ROBIN, + LoadBalancerPersistenceType.NONE, LoadBalancerOs.F5, LoadBalancerState.ON); assertEquals(Iterables.getOnlyElement(response), loadBalancer); } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java index e0b3587e36..ab9e7934f3 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java @@ -26,6 +26,7 @@ package org.jclouds.gogrid.functions; import static org.testng.Assert.assertEquals; import java.io.InputStream; +import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Date; import java.util.Map; @@ -77,13 +78,14 @@ public class ParseServersFromJsonResponseTest { Server server = new Server(75245L, false, "PowerServer", "server to test the api. created by Alex", new Option(1L, "On", "Server is in active state."), webServer, new Option(1L, "512MB", - "Server with 512MB RAM"), centOs, new Ip(1313079L, "204.51.240.178", - "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED), new ServerImage( - 1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", - "BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery", centOs, - null, ServerImageType.WEB_APPLICATION_SERVER, ServerImageState.AVAILABLE, - 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true, - new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of( + "Server with 512MB RAM"), centOs, new Ip(1313079L, InetAddress + .getByName("204.51.240.178"), "204.51.240.176/255.255.255.240", true, + IpState.ASSIGNED), new ServerImage(1946L, + "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0", + "http://bitnami.org/stack/gallery", centOs, null, + ServerImageType.WEB_APPLICATION_SERVER, ServerImageState.AVAILABLE, 0.0, + "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true, new Date( + 1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of( new BillingToken(38L, "CentOS 5.2 32bit", 0.0), new BillingToken( 56L, "BitNami: Gallery", 0.0)), new Customer(24732L, "BitRock"))); diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java index 5a41b0cb75..bb0fce2e89 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java @@ -18,17 +18,20 @@ */ package org.jclouds.gogrid.services; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.net.URI; +import java.util.Properties; import javax.inject.Singleton; import org.jclouds.encryption.EncryptionService; import org.jclouds.gogrid.GoGrid; +import org.jclouds.gogrid.GoGridPropertiesBuilder; import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; @@ -39,6 +42,7 @@ import org.jclouds.logging.Logger; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -173,6 +177,8 @@ public class GridImageAsyncClientTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new GoGridPropertiesBuilder( + new Properties()).build(), "properties")); bind(URI.class).annotatedWith(GoGrid.class).toInstance( URI.create("https://api.gogrid.com/api")); bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java index e5fdf5deea..778adcf52e 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.gogrid.services; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -25,11 +26,13 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.net.URI; import java.util.Date; +import java.util.Properties; import javax.inject.Singleton; import org.jclouds.encryption.EncryptionService; import org.jclouds.gogrid.GoGrid; +import org.jclouds.gogrid.GoGridPropertiesBuilder; import org.jclouds.gogrid.domain.JobState; import org.jclouds.gogrid.domain.ObjectType; import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; @@ -39,6 +42,7 @@ import org.jclouds.logging.Logger; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -159,6 +163,8 @@ public class GridJobAsyncClientTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new GoGridPropertiesBuilder( + new Properties()).build(), "properties")); bind(URI.class).annotatedWith(GoGrid.class).toInstance( URI.create("https://api.gogrid.com/api")); bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java index 2d8fe134b8..59a68a0d8e 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java @@ -18,19 +18,23 @@ */ package org.jclouds.gogrid.services; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; +import java.net.InetAddress; import java.net.URI; import java.util.Arrays; import java.util.List; +import java.util.Properties; import javax.inject.Singleton; import org.jclouds.encryption.EncryptionService; import org.jclouds.gogrid.GoGrid; +import org.jclouds.gogrid.GoGridPropertiesBuilder; import org.jclouds.gogrid.domain.Ip; import org.jclouds.gogrid.domain.IpPortPair; import org.jclouds.gogrid.domain.LoadBalancerPersistenceType; @@ -43,6 +47,7 @@ import org.jclouds.logging.Logger; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; import org.testng.annotations.Test; import com.google.common.collect.Iterables; @@ -87,10 +92,11 @@ public class GridLoadBalancerAsyncClientTest extends RestClientTest httpRequest = processor.createRequest( - method, "BalanceIt", new IpPortPair(new Ip("127.0.0.1"), 80), Arrays.asList( - new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(new Ip( - "127.0.0.1"), 9090)), new AddLoadBalancerOptions.Builder().create( - LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SSL_STICKY)); + method, "BalanceIt", new IpPortPair(new Ip(InetAddress.getByName("127.0.0.1")), 80), + Arrays.asList(new IpPortPair(new Ip(InetAddress.getByName("127.0.0.1")), 8080), + new IpPortPair(new Ip(InetAddress.getByName("127.0.0.1")), 9090)), + new AddLoadBalancerOptions.Builder().create(LoadBalancerType.LEAST_CONNECTED, + LoadBalancerPersistenceType.SSL_STICKY)); assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + "add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" @@ -122,8 +128,9 @@ public class GridLoadBalancerAsyncClientTest extends RestClientTest httpRequest = processor.createRequest( - method, "BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), - new IpPortPair(new Ip("127.0.0.1"), 9090))); + method, "BalanceIt", Arrays.asList(new IpPortPair(new Ip(InetAddress + .getByName("127.0.0.1")), 8080), new IpPortPair(new Ip(InetAddress + .getByName("127.0.0.1")), 9090))); assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" @@ -215,6 +222,8 @@ public class GridLoadBalancerAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - "serverName", "img55", "memory", "127.0.0.1"); + "serverName", "img55", "memory", InetAddress.getByName("127.0.0.1")); assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?v=1.3&" + "name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 " + "HTTP/1.1"); @@ -209,10 +214,10 @@ public class GridServerAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, - "serverName", "img55", "memory", "127.0.0.1", new AddServerOptions() - .asSandboxType().withDescription("fooy")); + "serverName", "img55", "memory", InetAddress.getByName("127.0.0.1"), + new AddServerOptions().asSandboxType().withDescription("fooy")); assertRequestLineEquals( httpRequest, @@ -330,6 +335,8 @@ public class GridServerAsyncClientTest extends RestClientTest { +public class PCSAsyncClientTest extends RestClientTest { public void testList() throws SecurityException, NoSuchMethodException, IOException { Method method = PCSAsyncClient.class.getMethod("list"); @@ -298,6 +301,8 @@ public class PCSClientTest extends RestClientTest { new TypeLiteral() { }, new TypeLiteral() { })); + Jsr330.bindProperties(binder(), checkNotNull(new PCSPropertiesBuilder( + new Properties()).build(), "properties")); bind(URI.class).annotatedWith(PCS.class) .toInstance(URI.create("http://localhost:8080")); bind(URI.class).annotatedWith(RootContainer.class).toInstance( diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudLiveTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudLiveTest.java index d1100aa5a7..f4bb593547 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudLiveTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudLiveTest.java @@ -19,7 +19,7 @@ package org.jclouds.mezeo.pcs2; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertNotNull; import java.io.UnsupportedEncodingException; diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java index 657020ce6c..81bbb9e94f 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/PCSCloudTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.mezeo.pcs2; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import java.io.UnsupportedEncodingException; diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/config/PCSContextModuleTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/config/PCSContextModuleTest.java index 3aafdcd67b..d62a9ae3b3 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/config/PCSContextModuleTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/config/PCSContextModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.mezeo.pcs2.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import java.net.URI; diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNClientTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAsyncClientTest.java similarity index 94% rename from nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNClientTest.java rename to nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAsyncClientTest.java index 58f1f57c00..9690aaa7ef 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNClientTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAsyncClientTest.java @@ -36,7 +36,6 @@ import org.jclouds.nirvanix.sdn.filters.AddSessionTokenToRequest; import org.jclouds.nirvanix.sdn.filters.InsertUserContextIntoPath; import org.jclouds.nirvanix.sdn.functions.ParseMetadataFromJsonResponse; import org.jclouds.nirvanix.sdn.functions.ParseUploadInfoFromJsonResponse; -import org.jclouds.nirvanix.sdn.reference.SDNConstants; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; @@ -55,7 +54,7 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "sdn.SDNClient") -public class SDNClientTest extends RestClientTest { +public class SDNAsyncClientTest extends RestClientTest { public void testGetStorageNode() throws SecurityException, NoSuchMethodException, IOException { Method method = SDNAsyncClient.class.getMethod("getStorageNode", String.class, long.class); @@ -186,6 +185,8 @@ public class SDNClientTest extends RestClientTest { new TypeLiteral() { }, new TypeLiteral() { })); + Jsr330.bindProperties(this.binder(), new SDNPropertiesBuilder("appKey", "appname", + "username", "password").build()); bind(URI.class).annotatedWith(SDN.class).toInstance(URI.create("http://stub:8080")); bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken"); bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { @@ -193,12 +194,6 @@ public class SDNClientTest extends RestClientTest { return Logger.NULL; } }); - bindConstant().annotatedWith(Jsr330.named(SDNConstants.PROPERTY_SDN_APPKEY)).to( - "appKey"); - bindConstant().annotatedWith(Jsr330.named(SDNConstants.PROPERTY_SDN_APPNAME)).to( - "appname"); - bindConstant().annotatedWith(Jsr330.named(SDNConstants.PROPERTY_SDN_USERNAME)).to( - "username"); } }; diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationLiveTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationLiveTest.java index 722bdd411d..d47c17c12b 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationLiveTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationLiveTest.java @@ -19,7 +19,7 @@ package org.jclouds.nirvanix.sdn; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertNotNull; import java.net.URI; diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java index 0554b553dd..6d7ad00966 100755 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.nirvanix.sdn; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import java.lang.reflect.Method; diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequestTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequestTest.java index 112c4c5342..63481c988a 100755 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequestTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequestTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.nirvanix.sdn.filters; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import java.lang.reflect.Method; diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/filters/InsertUserContextIntoPathTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/filters/InsertUserContextIntoPathTest.java index 115c1452f4..6e60bba296 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/filters/InsertUserContextIntoPathTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/filters/InsertUserContextIntoPathTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.nirvanix.sdn.filters; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceList.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceList.java index fcf2b77b3e..9742baa43c 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceList.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/blobstore/functions/ContainerToResourceList.java @@ -51,7 +51,7 @@ public class ContainerToResourceList implements public StorageMetadata apply(BlobMetadata input) { if (input.getContentType().equals("application/directory")) { return new StorageMetadataImpl(StorageType.RELATIVE_PATH, input.getId(), input - .getName(), input.getLocationId(), input.getUri(), input.getETag(), input + .getName(), input.getLocation(), input.getUri(), input.getETag(), input .getSize(), input.getLastModified(), input.getUserMetadata()); } return input; diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index 11ad843233..7d596268e9 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -18,6 +18,7 @@ */ package org.jclouds.rackspace.cloudservers.compute.config; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.domain.OsFamily.UBUNTU; import java.util.Map; @@ -68,6 +69,7 @@ import org.jclouds.logging.Logger; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient; import org.jclouds.rackspace.cloudservers.CloudServersClient; +import org.jclouds.rackspace.cloudservers.compute.functions.ServerToNodeMetadata; import org.jclouds.rackspace.cloudservers.config.CloudServersContextModule; import org.jclouds.rackspace.cloudservers.domain.Flavor; import org.jclouds.rackspace.cloudservers.domain.RebootType; @@ -118,7 +120,7 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext @Named("NAMING_CONVENTION") @Singleton String provideNamingConvention(@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) { - return account + "-%s-%d"; + return account + "-%s-%s"; } @Singleton @@ -176,8 +178,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext @Inject protected CloudServersAddNodeWithTagStrategy(CloudServersClient client, @Named("ACTIVE") Predicate serverActive) { - this.client = client; - this.serverActive = serverActive; + this.client = checkNotNull(client, "client"); + this.serverActive = checkNotNull(serverActive, "serverActive"); } @Override @@ -185,10 +187,10 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext Server server = client.createServer(name, Integer.parseInt(template.getImage().getId()), Integer.parseInt(template.getSize().getId())); serverActive.apply(server); - return new NodeMetadataImpl(server.getId() + "", name, template.getLocation().getId(), - null, server.getMetadata(), tag, NodeState.RUNNING, server.getAddresses() - .getPublicAddresses(), server.getAddresses().getPrivateAddresses(), - ImmutableMap. of(), + return new NodeMetadataImpl(server.getId() + "", name, template.getLocation(), null, + server.getMetadata(), tag, template.getImage(), NodeState.RUNNING, server + .getAddresses().getPublicAddresses(), server.getAddresses() + .getPrivateAddresses(), ImmutableMap. of(), new Credentials("root", server.getAdminPass())); } @@ -264,28 +266,6 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext .put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build(); } - protected static class ServerToNodeMetadata implements Function { - public static final Pattern TAG_PATTERN = Pattern.compile("[^-]+-([^-]+)-[0-9]+"); - private final Location location; - private final Map serverToNodeState; - - @Inject - ServerToNodeMetadata(Location location, Map serverToNodeState) { - this.location = location; - this.serverToNodeState = serverToNodeState; - } - - @Override - public NodeMetadata apply(Server from) { - Matcher matcher = TAG_PATTERN.matcher(from.getName()); - final String tag = matcher.find() ? matcher.group(1) : null; - return new NodeMetadataImpl(from.getId() + "", from.getName(), location.getId(), null, - from.getMetadata(), tag, serverToNodeState.get(from.getStatus()), from - .getAddresses().getPublicAddresses(), from.getAddresses() - .getPrivateAddresses(), ImmutableMap. of(), null); - } - } - @Provides @Singleton ComputeServiceContext provideContext(ComputeService computeService, @@ -305,7 +285,7 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext @Provides @Singleton Location getRegion() { - return new LocationImpl(LocationScope.ZONE, "DALLAS", "Dallas, TX", null, true); + return new LocationImpl(LocationScope.ZONE, "DALLAS", "Dallas, TX", null); } @Provides @@ -335,10 +315,9 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext final Set sizes = Sets.newHashSet(); holder.logger.debug(">> providing sizes"); for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) { - sizes.add(new SizeImpl(from.getId() + "", from.getName(), location.getId(), null, - ImmutableMap. of(), from.getDisk() / 10, from.getRam(), from - .getDisk(), ImmutableSet. of(Architecture.X86_32, - Architecture.X86_64))); + sizes.add(new SizeImpl(from.getId() + "", from.getName(), location, null, ImmutableMap + . of(), from.getDisk() / 10, from.getRam(), from.getDisk(), + ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); } holder.logger.debug("<< sizes(%d)", sizes.size()); return Maps.uniqueIndex(sizes, indexer); @@ -376,9 +355,9 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext holder.logger.debug("<< didn't match os(%s)", matcher.group(2)); } } - images.add(new ImageImpl(from.getId() + "", from.getName(), location.getId(), null, - ImmutableMap. of(), from.getName(), version, os, osDescription, - arch, new Credentials("root", null))); + images.add(new ImageImpl(from.getId() + "", from.getName(), location, null, ImmutableMap + . of(), from.getName(), version, os, osDescription, arch, + new Credentials("root", null))); } holder.logger.debug("<< images(%d)", images.size()); return Maps.uniqueIndex(images, indexer); diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java new file mode 100644 index 0000000000..99a8726944 --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.rackspace.cloudservers.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Inject; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.internal.NodeMetadataImpl; +import org.jclouds.domain.Location; +import org.jclouds.rackspace.cloudservers.domain.Server; +import org.jclouds.rackspace.cloudservers.domain.ServerStatus; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +public class ServerToNodeMetadata implements Function { + public static final Pattern TAG_PATTERN = Pattern.compile("[^-]+-([^-]+)-[0-9]+"); + private final Location location; + private final Map serverToNodeState; + private final Map images; + + @Inject + ServerToNodeMetadata(Map serverStateToNodeState, + Map images, Location location) { + this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState"); + this.images = checkNotNull(images, "images"); + this.location = checkNotNull(location, "location"); + } + + @Override + public NodeMetadata apply(Server from) { + Matcher matcher = TAG_PATTERN.matcher(from.getName()); + final String tag = matcher.find() ? matcher.group(1) : null; + return new NodeMetadataImpl(from.getId() + "", from.getName(), location, null, from + .getMetadata(), tag, images.get(from.getImageId().toString()), serverToNodeState + .get(from.getStatus()), from.getAddresses().getPublicAddresses(), from + .getAddresses().getPrivateAddresses(), ImmutableMap. of(), null); + } +} \ No newline at end of file diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/domain/Addresses.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/domain/Addresses.java index 4dfa7ff5b0..5a13af9287 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/domain/Addresses.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/domain/Addresses.java @@ -19,48 +19,43 @@ package org.jclouds.rackspace.cloudservers.domain; import java.net.InetAddress; -import java.util.Comparator; -import java.util.SortedSet; +import java.util.Set; import com.google.common.collect.Sets; import com.google.gson.annotations.SerializedName; +/** + * + * @author Adrian Cole + */ public class Addresses { - private static final Comparator ADDRESS_COMPARATOR = new Comparator() { - - @Override - public int compare(InetAddress o1, InetAddress o2) { - return (o1 == o2) ? 0 : o1.getHostAddress().compareTo(o2.getHostAddress()); - } - - }; @SerializedName("public") - private SortedSet publicAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR); + private Set publicAddresses = Sets.newLinkedHashSet(); @SerializedName("private") - private SortedSet privateAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR); + private Set privateAddresses = Sets.newLinkedHashSet(); public Addresses() { } - public Addresses(SortedSet publicAddresses, SortedSet privateAddresses) { + public Addresses(Set publicAddresses, Set privateAddresses) { this.publicAddresses = publicAddresses; this.privateAddresses = privateAddresses; } - public void setPublicAddresses(SortedSet publicAddresses) { + public void setPublicAddresses(Set publicAddresses) { this.publicAddresses = publicAddresses; } - public SortedSet getPublicAddresses() { + public Set getPublicAddresses() { return publicAddresses; } - public void setPrivateAddresses(SortedSet privateAddresses) { + public void setPrivateAddresses(Set privateAddresses) { this.privateAddresses = privateAddresses; } - public SortedSet getPrivateAddresses() { + public Set getPrivateAddresses() { return privateAddresses; } diff --git a/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthenticationLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthenticationLiveTest.java index 2fd446b9a7..8ca9652816 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthenticationLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthenticationLiveTest.java @@ -19,7 +19,7 @@ package org.jclouds.rackspace; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertNotNull; import java.net.URI; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthenticationTest.java b/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthenticationTest.java index 1eebc40c43..ab22adc430 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthenticationTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/RackspaceAuthenticationTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.rackspace; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import java.lang.reflect.Method; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/config/CloudFilesBlobStoreModuleTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/config/CloudFilesBlobStoreModuleTest.java index fa59cbdf4e..f11543b474 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/config/CloudFilesBlobStoreModuleTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudfiles/blobstore/config/CloudFilesBlobStoreModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.rackspace.cloudfiles.blobstore.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import org.jclouds.blobstore.BlobStoreContext; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java index 3eb967b632..d791c473de 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientLiveTest.java @@ -62,6 +62,7 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; import com.google.inject.Injector; /** @@ -372,8 +373,8 @@ public class CloudServersClientLiveTest { } private void doCheckPass(Server newDetails, String pass) throws IOException { - InetSocketAddress socket = new InetSocketAddress(newDetails.getAddresses() - .getPublicAddresses().first(), 22); + InetSocketAddress socket = new InetSocketAddress(Iterables.get(newDetails.getAddresses() + .getPublicAddresses(), 0), 22); socketTester.apply(socket); SshClient client = sshFactory.create(socket, "root", pass); @@ -389,8 +390,8 @@ public class CloudServersClientLiveTest { } private ExecResponse exec(Server details, String pass, String command) throws IOException { - InetSocketAddress socket = new InetSocketAddress(details.getAddresses().getPublicAddresses() - .first(), 22); + InetSocketAddress socket = new InetSocketAddress(Iterables.get(details.getAddresses() + .getPublicAddresses(), 0), 22); socketTester.apply(socket); SshClient client = sshFactory.create(socket, "root", pass); try { diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java index a100d76f62..4a1fd41d7a 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.rackspace.cloudservers; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withFile; import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withMetadata; import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withSharedIpGroup; @@ -82,7 +83,6 @@ import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.Executors; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -1036,8 +1036,8 @@ public class CloudServersClientTest { } }; } - }, new RestModule(), new ExecutorServiceModule(Executors.sameThreadExecutor(), Executors - .sameThreadExecutor()), new JavaUrlHttpCommandExecutorServiceModule()); + }, new RestModule(), new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()), + new JavaUrlHttpCommandExecutorServiceModule()); processor = injector.getInstance(Key .get(new TypeLiteral>() { })); diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java new file mode 100644 index 0000000000..fc48502c1d --- /dev/null +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadataTest.java @@ -0,0 +1,89 @@ +package org.jclouds.rackspace.cloudservers.compute.functions; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Map; +import java.util.Set; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.rackspace.cloudservers.domain.Addresses; +import org.jclouds.rackspace.cloudservers.domain.Server; +import org.jclouds.rackspace.cloudservers.domain.ServerStatus; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "cloudservers.ServerToNodeMetadataTest") +public class ServerToNodeMetadataTest { + + @SuppressWarnings("unchecked") + @Test + public void testApplySetsTagFromNameAndSetsMetadata() throws UnknownHostException { + Map serverStateToNodeState = createMock(Map.class); + Map images = createMock(Map.class); + Server server = createMock(Server.class); + + expect(server.getId()).andReturn(10000).atLeastOnce(); + expect(server.getName()).andReturn("adrian-tag-100").atLeastOnce(); + expect(server.getMetadata()).andReturn(ImmutableMap. of()).atLeastOnce(); + + expect(server.getStatus()).andReturn(ServerStatus.ACTIVE).atLeastOnce(); + + expect(serverStateToNodeState.get(ServerStatus.ACTIVE)).andReturn(NodeState.RUNNING); + Location location = new LocationImpl(LocationScope.ZONE, "dallas", "description", null); + + Addresses addresses = createMock(Addresses.class); + expect(server.getAddresses()).andReturn(addresses).atLeastOnce(); + + Set publicAddresses = ImmutableSet.of(InetAddress.getByAddress(new byte[] { 12, + 10, 10, 1 })); + Set privateAddresses = ImmutableSet.of(InetAddress.getByAddress(new byte[] { 10, + 10, 10, 1 })); + + expect(addresses.getPublicAddresses()).andReturn(publicAddresses); + expect(addresses.getPrivateAddresses()).andReturn(privateAddresses); + + expect(server.getImageId()).andReturn(2000).atLeastOnce(); + + org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); + expect(images.get("2000")).andReturn(jcImage); + + replay(addresses); + replay(serverStateToNodeState); + replay(server); + replay(images); + + ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, images, + location); + + NodeMetadata metadata = parser.apply(server); + assertEquals(metadata.getLocation(), location); + assertEquals(metadata.getImage(), jcImage); + assert metadata.getUserMetadata() != null; + assertEquals(metadata.getTag(), "tag"); + assertEquals(metadata.getCredentials(), null); + + assertEquals(metadata.getPrivateAddresses(), privateAddresses); + assertEquals(metadata.getPublicAddresses(), publicAddresses); + + verify(addresses); + verify(serverStateToNodeState); + verify(server); + verify(images); + } + +} diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index 83f7aeebb9..d3a2a88e50 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -121,7 +121,7 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo @Named("NAMING_CONVENTION") @Singleton String provideNamingConvention() { - return "%s-%d"; + return "%s-%s"; } @Singleton @@ -191,11 +191,11 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo // we have to lookup the new details in order to retrieve the currently assigned ip // address. NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, template - .getLocation().getId(), null, ImmutableMap. of(), tag, - runningStateToNodeState.get(server.getState()), getPublicAddresses.apply(server), - ImmutableList. of(), ImmutableMap. of(), - new Credentials("root", serverResponse.getNewInstanceRequest().getCreateOptions() - .getPassword())); + .getLocation(), null, ImmutableMap. of(), tag, template + .getImage(), runningStateToNodeState.get(server.getState()), getPublicAddresses + .apply(server), ImmutableList. of(), ImmutableMap + . of(), new Credentials("root", serverResponse + .getNewInstanceRequest().getCreateOptions().getPassword())); return node; } @@ -256,24 +256,32 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo private static class ServerToNodeMetadata implements Function { private final Function> getPublicAddresses; private final Map runningStateToNodeState; + private final Map images; + @SuppressWarnings("unused") + private final Map locations; @SuppressWarnings("unused") @Inject ServerToNodeMetadata(Function> getPublicAddresses, - Map runningStateToNodeState) { - this.getPublicAddresses = getPublicAddresses; - this.runningStateToNodeState = runningStateToNodeState; + Map runningStateToNodeState, + Map images, Map locations) { + this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState"); + this.runningStateToNodeState = checkNotNull(runningStateToNodeState, + "serverStateToNodeState"); + this.images = checkNotNull(images, "images"); + this.locations = checkNotNull(locations, "locations"); } @Override public NodeMetadata apply(Server from) { - String locationId = "//TODO"; + Location location = new LocationImpl(LocationScope.ZONE, "//TODO", null, null); String tag = from.getName().replaceAll("-[0-9]+", ""); Credentials creds = null; NodeState state = runningStateToNodeState.get(from.getState()); - return new NodeMetadataImpl(from.getId() + "", from.getName(), locationId, null, - ImmutableMap. of(), tag, state, getPublicAddresses.apply(from), - ImmutableList. of(), ImmutableMap. of(), creds); + return new NodeMetadataImpl(from.getId() + "", from.getName(), location, null, + ImmutableMap. of(), tag, images.get(from.getImageId()), state, + getPublicAddresses.apply(from), ImmutableList. of(), ImmutableMap + . of(), creds); } } @@ -331,7 +339,7 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo for (final PricingPlan from : sync.getPricingPlanList()) { try { locations.add(new LocationImpl(LocationScope.ZONE, from.getDataCenter().getId(), from - .getDataCenter().getName(), null, true)); + .getDataCenter().getName(), null)); } catch (NullPointerException e) { holder.logger.warn("datacenter not present in " + from.getId()); } @@ -360,18 +368,18 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo @Provides @Singleton protected Map provideSizes(RimuHostingClient sync, - Map images, LogHolder holder, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, + Map images, Map locations, + LogHolder holder, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, Function indexer) throws InterruptedException, TimeoutException, ExecutionException { final Set sizes = Sets.newHashSet(); holder.logger.debug(">> providing sizes"); for (final PricingPlan from : sync.getPricingPlanList()) { try { - sizes.add(new SizeImpl(from.getId(), from.getId(), from.getDataCenter().getId(), null, - ImmutableMap. of(), from.getDiskSize(), from.getRam(), from - .getDiskSize(), ImmutableSet. of(Architecture.X86_32, - Architecture.X86_64))); + sizes.add(new SizeImpl(from.getId(), from.getId(), locations.get(from.getDataCenter() + .getId()), null, ImmutableMap. of(), from.getDiskSize(), from + .getRam(), from.getDiskSize(), ImmutableSet. of( + Architecture.X86_32, Architecture.X86_64))); } catch (NullPointerException e) { holder.logger.warn("datacenter not present in " + from.getId()); } diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java index 2c5b00dbbc..27ccbff6d9 100644 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java @@ -18,11 +18,13 @@ */ package org.jclouds.rimuhosting.miro; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URI; +import java.util.Properties; import javax.inject.Singleton; @@ -33,6 +35,7 @@ import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; import org.testng.annotations.Test; import com.google.inject.AbstractModule; @@ -81,6 +84,8 @@ public class RimuHostingAsyncClientTest extends RestClientTest - com.google.common - google-guava - 1.0-r11 + com.google.guava + guava + r03 + + + com.google.code.findbugs + jsr305 + 1.3.9 diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java index 0b9038d494..7594ff5d60 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java @@ -152,9 +152,9 @@ public class ComputeTask extends Task { log(String .format( " image location=%s, id=%s, name=%s, version=%s, arch=%s, osfam=%s, osdesc=%s, desc=%s", - image.getLocationId(), image.getId(), image.getName(), image - .getVersion(), image.getArchitecture(), image.getOsFamily(), - image.getOsDescription(), image.getDescription())); + image.getLocation(), image.getId(), image.getName(), image.getVersion(), + image.getArchitecture(), image.getOsFamily(), image.getOsDescription(), + image.getDescription())); } } @@ -169,17 +169,16 @@ public class ComputeTask extends Task { private void listLocations(ComputeService computeService) { log("list locations"); for (Location location : computeService.getLocations().values()) {// TODO - log(String.format(" location id=%s, scope=%s, description=%s, parent=%s, assignable=%s", - location.getId(), location.getScope(), location.getDescription(), location - .getParent(), location.isAssignable())); + log(String.format(" location id=%s, scope=%s, description=%s, parent=%s", location + .getId(), location.getScope(), location.getDescription(), location.getParent())); } } private void list(ComputeService computeService) { log("list"); for (ComputeMetadata node : computeService.getNodes().values()) { - log(String.format(" location=%s, id=%s, tag=%s", node.getLocationId(), node.getId(), - node.getName())); + log(String.format(" location=%s, id=%s, tag=%s", node.getLocation(), node.getId(), node + .getName())); } } @@ -231,7 +230,7 @@ public class ComputeTask extends Task { .format( " node id=%s, name=%s, tag=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, extra=%s", metadata.getId(), metadata.getName(), metadata.getTag(), metadata - .getLocationId(), metadata.getState(), ComputeTaskUtils + .getLocation(), metadata.getState(), ComputeTaskUtils .ipOrEmptyString(metadata.getPublicAddresses()), ipOrEmptyString(metadata.getPrivateAddresses()), metadata.getExtra())); } diff --git a/twitter/src/test/java/org/jclouds/twitter/TwitterClientTest.java b/twitter/src/test/java/org/jclouds/twitter/TwitterAsyncClientTest.java similarity index 93% rename from twitter/src/test/java/org/jclouds/twitter/TwitterClientTest.java rename to twitter/src/test/java/org/jclouds/twitter/TwitterAsyncClientTest.java index 41797f2731..e63bd99a3e 100644 --- a/twitter/src/test/java/org/jclouds/twitter/TwitterClientTest.java +++ b/twitter/src/test/java/org/jclouds/twitter/TwitterAsyncClientTest.java @@ -35,6 +35,7 @@ import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.twitter.functions.ParseStatusesFromJsonResponse; +import org.jclouds.util.Jsr330; import org.testng.annotations.Test; import com.google.inject.AbstractModule; @@ -48,7 +49,7 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "twitter.TwitterClientTest") -public class TwitterClientTest extends RestClientTest { +public class TwitterAsyncClientTest extends RestClientTest { public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException { Method method = TwitterAsyncClient.class.getMethod("getMyMentions"); @@ -82,6 +83,9 @@ public class TwitterClientTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { + Jsr330 + .bindProperties(this.binder(), new TwitterPropertiesBuilder("foo", "bar") + .build()); bind(URI.class).annotatedWith(Twitter.class).toInstance( URI.create("http://twitter.com")); bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { diff --git a/twitter/src/test/java/org/jclouds/twitter/config/TwitterContextModuleTest.java b/twitter/src/test/java/org/jclouds/twitter/config/TwitterContextModuleTest.java index bcac4cda44..b38f3f3872 100644 --- a/twitter/src/test/java/org/jclouds/twitter/config/TwitterContextModuleTest.java +++ b/twitter/src/test/java/org/jclouds/twitter/config/TwitterContextModuleTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.twitter.config; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.testng.Assert.assertEquals; import javax.ws.rs.core.UriBuilder; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index e379f3d335..c361c1d772 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -36,11 +36,13 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import org.jclouds.predicates.validators.DnsNameValidator; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.MapPayloadParam; import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.ParamValidators; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -263,7 +265,7 @@ public interface VCloudAsyncClient { @XMLResponseParser(VAppHandler.class) @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) ListenableFuture instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId, - @MapPayloadParam("name") String appName, + @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, @MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, InstantiateVAppTemplateOptions... options); @@ -276,5 +278,6 @@ public interface VCloudAsyncClient { @MapBinder(BindCloneVAppParamsToXmlPayload.class) ListenableFuture cloneVAppInVDC(@PathParam("vDCId") String vDCId, @MapPayloadParam("vApp") @ParamParser(VAppIdToUri.class) String vAppIdToClone, - @MapPayloadParam("newName") String newName, CloneVAppOptions... options); + @MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, + CloneVAppOptions... options); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java index d6dd95f4ae..567e13060b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java @@ -51,6 +51,8 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder { "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); properties.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false"); properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString()); + properties.setProperty("jclouds.dns_name_length_min", "1"); + properties.setProperty("jclouds.dns_name_length_max", "80"); return properties; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index b8754bffe4..e8acca81c3 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -23,10 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.domain.OsFamily.UBUNTU; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; -import java.net.InetAddress; import java.util.Map; import java.util.Set; -import java.util.Map.Entry; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -65,6 +63,7 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.concurrent.ConcurrentUtils; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; @@ -79,10 +78,11 @@ import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.compute.BaseVCloudComputeClient; import org.jclouds.vcloud.compute.VCloudComputeClient; +import org.jclouds.vcloud.compute.functions.GetExtra; +import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata; +import org.jclouds.vcloud.compute.strategy.EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.vcloud.config.VCloudContextModule; import org.jclouds.vcloud.domain.NamedResource; -import org.jclouds.vcloud.domain.ResourceAllocation; -import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; @@ -128,6 +128,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { protected void configure() { super.configure(); bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class); + bind(RunNodesAndAddToSetStrategy.class).to( + EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.class); bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class); bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class); bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class); @@ -138,7 +140,7 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Named("NAMING_CONVENTION") @Singleton String provideNamingConvention() { - return "%s-%d"; + return "%s-%s%s"; } @Singleton @@ -206,8 +208,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map metaMap, VApp vApp) { - return new NodeMetadataImpl(vApp.getId(), vApp.getName(), template.getLocation().getId(), - vApp.getLocation(), ImmutableMap. of(), tag, + return new NodeMetadataImpl(vApp.getId(), vApp.getName(), template.getLocation(), vApp + .getLocation(), ImmutableMap. of(), tag, template.getImage(), vAppStatusToNodeState.get(vApp.getStatus()), computeClient .getPublicAddresses(vApp.getId()), computeClient .getPrivateAddresses(vApp.getId()), ImmutableMap. of(), @@ -224,8 +226,9 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Inject protected VCloudListNodesStrategy(VCloudClient client, VCloudComputeClient computeClient, - Map vAppStatusToNodeState) { - super(client, computeClient, vAppStatusToNodeState); + Map vAppStatusToNodeState, GetExtra getExtra, + Map locations, Map images) { + super(client, computeClient, vAppStatusToNodeState, getExtra, locations, images); } @Override @@ -264,64 +267,22 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Inject protected VCloudGetNodeMetadataStrategy(VCloudClient client, - VCloudComputeClient computeClient, Map vAppStatusToNodeState) { - super(client, computeClient, vAppStatusToNodeState); + VCloudComputeClient computeClient, Map vAppStatusToNodeState, + GetExtra getExtra, Map locations, + Map images) { + super(client, computeClient, vAppStatusToNodeState, getExtra, locations, images); } @Override public NodeMetadata execute(ComputeMetadata node) { checkArgument(node.getType() == ComputeType.NODE, "this is only valid for nodes, not " + node.getType()); - return getNodeMetadataByIdInVDC(checkNotNull(node.getLocationId(), "location"), + return getNodeMetadataByIdInVDC(checkNotNull(node.getLocation(), "location").getId(), checkNotNull(node.getId(), "node.id")); } } - @Singleton - public static class VCloudGetNodeMetadata { - - protected final VCloudClient client; - protected final VCloudComputeClient computeClient; - - protected final Map vAppStatusToNodeState; - - @Inject - protected VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient, - Map vAppStatusToNodeState) { - this.client = client; - this.computeClient = computeClient; - this.vAppStatusToNodeState = vAppStatusToNodeState; - } - - protected NodeMetadata getNodeMetadataByIdInVDC(String vDCId, String id) { - VApp vApp = client.getVApp(id); - String tag = vApp.getName().replaceAll("-[0-9]+", ""); - return new NodeMetadataImpl(vApp.getId(), vApp.getName(), vDCId, vApp.getLocation(), - ImmutableMap. of(), tag, vAppStatusToNodeState.get(vApp - .getStatus()), computeClient.getPublicAddresses(id), computeClient - .getPrivateAddresses(id), getExtra(vApp), null); - } - } - - private static Map getExtra(VApp vApp) { - Map extra = Maps.newHashMap(); - extra.put("memory/mb", Iterables.getOnlyElement( - vApp.getResourceAllocationByType().get(ResourceType.MEMORY)).getVirtualQuantity() - + ""); - extra.put("processor/count", Iterables.getOnlyElement( - vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)).getVirtualQuantity() - + ""); - for (ResourceAllocation disk : vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)) { - extra.put(String.format("disk_drive/%s/kb", disk.getId()), disk.getVirtualQuantity() + ""); - } - - for (Entry net : vApp.getNetworkToAddresses().entries()) { - extra.put(String.format("network/%s/ip", net.getKey()), net.getValue().getHostAddress()); - } - return extra; - } - @Provides @Singleton @Named("NOT_RUNNING") @@ -347,7 +308,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Singleton protected Map provideImages(final VCloudClient client, final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, - LogHolder holder, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, + final Map locations, LogHolder holder, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Function indexer) throws InterruptedException, ExecutionException, TimeoutException { final Set images = Sets.newHashSet(); @@ -372,10 +334,11 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { Architecture arch = resource.getName().indexOf("64") == -1 ? Architecture.X86_32 : Architecture.X86_64; VAppTemplate template = client.getVAppTemplate(resource.getId()); - images.add(new ImageImpl(resource.getId(), template.getName(), vDC - .getId(), template.getLocation(), ImmutableMap - . of(), template.getDescription(), "", myOs, - template.getName(), arch, new Credentials("root", null))); + images.add(new ImageImpl(resource.getId(), template.getName(), + locations.get(vDC.getId()), template.getLocation(), + ImmutableMap. of(), template + .getDescription(), "", myOs, template.getName(), + arch, new Credentials("root", null))); return null; } }), executor)); @@ -408,7 +371,7 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Override public Location apply(NamedResource from) { VDC vdc = client.getVDC(from.getId()); - return new LocationImpl(LocationScope.ZONE, vdc.getId(), vdc.getName(), null, true); + return new LocationImpl(LocationScope.ZONE, vdc.getId(), vdc.getName(), null); } }), new Function() { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/GetExtra.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/GetExtra.java new file mode 100644 index 0000000000..b7b13e3f53 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/GetExtra.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.compute.functions; + +import java.net.InetAddress; +import java.util.Map; +import java.util.Map.Entry; + +import javax.inject.Singleton; + +import org.jclouds.vcloud.compute.BaseVCloudComputeClient; +import org.jclouds.vcloud.domain.ResourceAllocation; +import org.jclouds.vcloud.domain.ResourceType; +import org.jclouds.vcloud.domain.VApp; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; + +/** + * Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient} + * bound. + * + * @author Adrian Cole + */ +@Singleton +public class GetExtra implements Function> { + public Map apply(VApp vApp) { + Map extra = Maps.newHashMap(); + extra.put("memory/mb", Iterables.getOnlyElement( + vApp.getResourceAllocationByType().get(ResourceType.MEMORY)).getVirtualQuantity() + + ""); + extra.put("processor/count", Iterables.getOnlyElement( + vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)) + .getVirtualQuantity() + + ""); + for (ResourceAllocation disk : vApp.getResourceAllocationByType().get( + ResourceType.PROCESSOR)) { + extra.put(String.format("disk_drive/%s/kb", disk.getId()), disk.getVirtualQuantity() + + ""); + } + + for (Entry net : vApp.getNetworkToAddresses().entries()) { + extra + .put(String.format("network/%s/ip", net.getKey()), net.getValue() + .getHostAddress()); + } + return extra; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java new file mode 100644 index 0000000000..8a40b9f38f --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java @@ -0,0 +1,101 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.internal.NodeMetadataImpl; +import org.jclouds.domain.Location; +import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.compute.BaseVCloudComputeClient; +import org.jclouds.vcloud.compute.VCloudComputeClient; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppStatus; + +import com.google.common.collect.ImmutableMap; + +/** + * Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient} + * bound. + * + * @author Adrian Cole + */ +@Singleton +public class VCloudGetNodeMetadata { + + protected final VCloudClient client; + protected final VCloudComputeClient computeClient; + protected final Map images; + protected final Map locations; + protected final GetExtra getExtra; + protected final Map vAppStatusToNodeState; + + // hex [][][] are templateId, last two are instanceId + public static final Pattern TAG_PATTERN_WITH_TEMPLATE = Pattern + .compile("([^-]+)-([0-9a-f][0-9a-f][0-9a-f])[0-9a-f]+"); + + public static final Pattern TAG_PATTERN_WITHOUT_TEMPLATE = Pattern.compile("([^-]+)-[0-9]+"); + + @Inject + protected VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient, + Map vAppStatusToNodeState, GetExtra getExtra, + Map locations, Map images) { + this.client = checkNotNull(client, "client"); + this.images = checkNotNull(images, "images"); + this.getExtra = checkNotNull(getExtra, "getExtra"); + this.locations = checkNotNull(locations, "locations"); + this.computeClient = checkNotNull(computeClient, "computeClient"); + this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState"); + } + + protected NodeMetadata getNodeMetadataByIdInVDC(String vDCId, String id) { + VApp vApp = client.getVApp(id); + + String tag = null; + Image image = null; + Matcher matcher = TAG_PATTERN_WITH_TEMPLATE.matcher(vApp.getName()); + if (matcher.find()) { + tag = matcher.group(1); + String templateIdInHexWithoutLeadingZeros = matcher.group(2).replaceAll("^[0]+", ""); + String templateId = Integer.parseInt(templateIdInHexWithoutLeadingZeros, 16) + ""; + image = images.get(templateId); + } else { + matcher = TAG_PATTERN_WITHOUT_TEMPLATE.matcher(vApp.getName()); + if (matcher.find()) { + tag = matcher.group(1); + } else { + tag = "NOTAG-" + vApp.getName(); + } + } + return new NodeMetadataImpl(vApp.getId(), vApp.getName(), locations.get(vDCId), vApp + .getLocation(), ImmutableMap. of(), tag, image, + vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(id), + computeClient.getPrivateAddresses(id), getExtra.apply(vApp), null); + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java new file mode 100644 index 0000000000..5cd6395317 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.compute.strategy; + +import java.security.SecureRandom; +import java.util.concurrent.ExecutorService; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.strategy.AddNodeWithTagStrategy; +import org.jclouds.compute.strategy.ListNodesStrategy; +import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; +import org.jclouds.compute.util.ComputeUtils; + +import com.google.common.base.Strings; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy extends + EncodeTagIntoNameRunNodesAndAddToSetStrategy { + + @Inject + protected EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy( + AddNodeWithTagStrategy addNodeWithTagStrategy, ListNodesStrategy listNodesStrategy, + @Named("NAMING_CONVENTION") String nodeNamingConvention, ComputeUtils utils, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor); + } + + /** + * Get a name corresponding to the tag-hex*5 where the first 3 hex correspond to the template id + * and the last a random number + * + */ + @Override + protected String getNextName(final String tag, final Template template) { + return String.format(nodeNamingConvention, tag, Strings.padStart(Integer.toHexString(Integer + .parseInt(template.getImage().getId())), 3, '0'), Strings.padStart(Integer + .toHexString(new SecureRandom().nextInt(255)), 2, '0')); + } +} \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index 6ac5acb614..b8f29210bf 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -18,12 +18,8 @@ */ package org.jclouds.vcloud; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -45,7 +41,6 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; -import org.jclouds.vcloud.domain.FenceMode; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.TasksList; @@ -57,6 +52,7 @@ import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.jclouds.vcloud.reference.VCloudConstants; import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogItemHandler; import org.jclouds.vcloud.xml.NetworkHandler; @@ -86,13 +82,13 @@ public class VCloudAsyncClientTest extends RestClientTest { String.class, String.class, String.class, Array.newInstance( InstantiateVAppTemplateOptions.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", - "CentOS 01", 3 + ""); + "my-vapp", 3 + ""); assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertHeadersEqual( httpMethod, - "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 638\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); + "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 634\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( "/newvapp-hosting.xml"))); @@ -109,14 +105,14 @@ public class VCloudAsyncClientTest extends RestClientTest { String.class, String.class, String.class, Array.newInstance( InstantiateVAppTemplateOptions.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", - "CentOS 01", 3 + "", processorCount(1).memory(512).disk(1024).inNetwork( + "my-vapp", 3 + "", processorCount(1).memory(512).disk(1024).inNetwork( URI.create("https://vcloud.safesecureweb.com/network/1990"))); assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertHeadersEqual( httpMethod, - "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 2022\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); + "Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 2018\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( "/newvapp-hostingcpumemdisk.xml"))); @@ -127,16 +123,26 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(httpMethod); } + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInstantiateVAppTemplateOptionsIllegalName() throws SecurityException, + NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", + String.class, String.class, String.class, Array.newInstance( + InstantiateVAppTemplateOptions.class, 0).getClass()); + processor.createRequest(method, "1", "CentOS 01", 3 + "", processorCount(1).memory(512).disk( + 1024).inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); + } + public void testCloneVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", - "4181", "New Name"); + "4181", "my-vapp"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/action/cloneVApp HTTP/1.1"); assertHeadersEqual( httpMethod, - "Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 398\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n"); + "Accept: application/vnd.vmware.vcloud.task+xml\nContent-Length: 397\nContent-Type: application/vnd.vmware.vcloud.cloneVAppParams+xml\n"); assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( "/cloneVApp-default.xml"))); @@ -151,7 +157,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); GeneratedHttpRequest httpMethod = processor.createRequest(method, "1", - "201", "New Linux Server", new CloneVAppOptions().deploy().powerOn() + "201", "new-linux-server", new CloneVAppOptions().deploy().powerOn() .withDescription("The description of the new vApp")); assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/action/cloneVApp HTTP/1.1"); @@ -168,6 +174,15 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(httpMethod); } + @Test(expectedExceptions = IllegalArgumentException.class) + public void testCloneVAppOptionsIllegalName() throws SecurityException, NoSuchMethodException, + IOException { + Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", String.class, + String.class, String.class, Array.newInstance(CloneVAppOptions.class, 0).getClass()); + processor.createRequest(method, "1", "201", "New Linux Server", new CloneVAppOptions() + .deploy().powerOn().withDescription("The description of the new vApp")); + } + public void testDefaultOrganization() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization"); @@ -520,14 +535,10 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override protected void configure() { Properties props = new Properties(); - props.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false"); - props.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString()); - props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK, + props.put(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK, "https://vcloud.safesecureweb.com/network/1990"); - props.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v0.8"); - props.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, - "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); - Jsr330.bindProperties(binder(), props); + Jsr330.bindProperties(binder(), checkNotNull( + new VCloudPropertiesBuilder(props).build(), "properties")); bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org")); bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog")); bind(String.class).annotatedWith(CatalogItemRoot.class) diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java index 5a5f0ddb56..db0dcbf285 100755 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java index 1166045b63..1265305604 100755 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginTest.java @@ -18,12 +18,14 @@ */ package org.jclouds.vcloud; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.net.URI; +import java.util.Properties; import javax.ws.rs.core.HttpHeaders; @@ -34,6 +36,7 @@ import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; import org.testng.annotations.Test; @@ -83,6 +86,8 @@ public class VCloudLoginTest extends RestClientTest { return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull( + new VCloudPropertiesBuilder(new Properties()).build(), "properties")); bind(URI.class).annotatedWith(org.jclouds.vcloud.endpoints.VCloudLogin.class) .toInstance(URI.create("http://localhost:8080/login")); try { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsLiveTest.java index 4537c92016..05100afa77 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsLiveTest.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; import static org.testng.Assert.assertNotNull; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java index 5fa7a3cc09..26b1053210 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudVersionsTest.java @@ -18,11 +18,13 @@ */ package org.jclouds.vcloud; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; +import java.util.Properties; import javax.ws.rs.core.HttpHeaders; @@ -32,6 +34,7 @@ import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; import org.jclouds.vcloud.xml.SupportedVersionsHandler; @@ -54,7 +57,8 @@ public class VCloudVersionsTest extends RestClientTest httpMethod = processor.createRequest(method); assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1"); - assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": application/vnd.vmware.vcloud.vcloud+xml\n"); + assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + + ": application/vnd.vmware.vcloud.vcloud+xml\n"); assertPayloadEquals(httpMethod, null); assertResponseParserClassEquals(method, httpMethod, ParseSax.class); @@ -80,6 +84,8 @@ public class VCloudVersionsTest extends RestClientTest map = Maps.newHashMap(); - map.put("newName", "New Linux Server"); + map.put("newName", "new-linux-server"); map.put("vApp", "https://services.vcloudexpress.terremark.com/api/vapp/201"); binder.bindToRequest(request, map); verify(request); @@ -103,7 +103,7 @@ public class BindCloneVAppParamsToXmlPayloadTest { .getInstance(BindCloneVAppParamsToXmlPayload.class); Map map = Maps.newHashMap(); - map.put("newName", "New Name"); + map.put("newName", "my-vapp"); map.put("vApp", "https://services.vcloudexpress.terremark.com/api/vapp/4181"); binder.bindToRequest(request, map); verify(request); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index 27b23cb66f..00e3efc628 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -83,7 +83,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); - map.put("name", "CentOS 01"); + map.put("name", "my-vapp"); map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); binder.bindToRequest(request, map); verify(request); @@ -107,7 +107,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); - map.put("name", "CentOS 01"); + map.put("name", "my-vapp"); map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); map.put("network", "https://vcloud.safesecureweb.com/network/1990"); @@ -137,7 +137,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); - map.put("name", "CentOS 01"); + map.put("name", "my-vapp"); map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); map.put("network", "https://vcloud.safesecureweb.com/network/1990"); map.put("networkName", "aloha"); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java index 42936fb731..14f9110b1a 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java @@ -49,7 +49,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { for (Entry node : client.getNodes().entrySet()) { assertEquals(node.getKey(), node.getValue().getId()); assert node.getValue().getId() != null; - assert node.getValue().getLocationId() != null; + assert node.getValue().getLocation() != null; assertEquals(node.getValue().getType(), ComputeType.NODE); NodeMetadata allData = client.getNodeMetadata(node.getValue()); assert allData.getExtra().get("processor/count") != null; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModuleTest.java index 055848ff98..c5afaa5940 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModuleTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModuleTest.java @@ -34,10 +34,13 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeState; +import org.jclouds.domain.Location; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.VCloudComputeClient; import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule.VCloudListNodesStrategy; +import org.jclouds.vcloud.compute.functions.GetExtra; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceType; @@ -49,6 +52,7 @@ import org.jclouds.vcloud.domain.internal.VAppImpl; import org.testng.annotations.Test; import com.google.common.collect.ImmutableListMultimap; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ListMultimap; import com.google.common.collect.Maps; @@ -93,6 +97,8 @@ public class VCloudComputeServiceContextModuleTest { public void testRetryOnVAppNotFoundForGetVAppEvenWhenPresentInAvailableResources() throws ExecutionException, InterruptedException, TimeoutException, IOException { VCloudClient client = createMock(VCloudClient.class); + GetExtra getExtra = new GetExtra(); + VCloudComputeClient computeClient = createMock(VCloudComputeClient.class); Map vAppStatusToNodeState = Maps.newHashMap(); VApp vApp = newVApp(); @@ -102,18 +108,23 @@ public class VCloudComputeServiceContextModuleTest { expect(computeClient.getPublicAddresses("10")).andReturn(Sets. newHashSet()); expect(computeClient.getPrivateAddresses("10")).andReturn( Sets.newHashSet(InetAddress.getLocalHost())); + + replay(getExtra); replay(client); replay(computeClient); - + + Map locations = ImmutableMap.of(); + Map images= ImmutableMap.of(); VCloudListNodesStrategy strategy = new VCloudListNodesStrategy(client, computeClient, - vAppStatusToNodeState); + vAppStatusToNodeState, getExtra, locations, images); Set nodes = Sets.newHashSet(); NamedResource vdc = new NamedResourceImpl("1", null, null, null); NamedResource resource = new NamedResourceImpl("10", null, null, null); strategy.addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource); - + + verify(getExtra); verify(client); verify(computeClient); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest.java new file mode 100644 index 0000000000..d56ef2c968 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/strategy/EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.vcloud.compute.strategy; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; +import static org.testng.Assert.assertEquals; + +import java.util.concurrent.ExecutorService; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.strategy.AddNodeWithTagStrategy; +import org.jclouds.compute.strategy.ListNodesStrategy; +import org.jclouds.compute.util.ComputeUtils; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest") +public class EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategyTest { + + @Test + public void testGetNextName() { + EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy strategy = new EncodeTemplateIdIntoNameRunNodesAndAddToSetStrategy( + createNiceMock(AddNodeWithTagStrategy.class), + createNiceMock(ListNodesStrategy.class), "%s-%s%s", + createNiceMock(ComputeUtils.class), createNiceMock(ExecutorService.class)); + + String oldName = null; + for (int i = 0; i < 5; i++) { + Template template = createMock(Template.class); + Image image = createMock(Image.class); + expect(template.getImage()).andReturn(image); + expect(image.getId()).andReturn("233"); + replay(template); + replay(image); + + String name = strategy.getNextName("test", template); + if (oldName != null) { + assert !oldName.equals(name); + oldName = name; + } + + assertEquals(name.length(), 10); + assertEquals(name.substring(0, 4), "test"); + System.out.println(name); + assertEquals(name.substring(5, 8), "0e9"); + assert name.substring(8, 9).matches("[0-9a-f]+"); + verify(template); + verify(image); + + } + } +} diff --git a/vcloud/core/src/test/resources/cloneVApp-default.xml b/vcloud/core/src/test/resources/cloneVApp-default.xml index fdd50cb91d..9d14e56666 100644 --- a/vcloud/core/src/test/resources/cloneVApp-default.xml +++ b/vcloud/core/src/test/resources/cloneVApp-default.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/cloneVApp.xml b/vcloud/core/src/test/resources/cloneVApp.xml index 366a84f43c..ec97219ad7 100644 --- a/vcloud/core/src/test/resources/cloneVApp.xml +++ b/vcloud/core/src/test/resources/cloneVApp.xml @@ -1 +1 @@ -The description of the new vApp \ No newline at end of file +The description of the new vApp \ No newline at end of file diff --git a/vcloud/core/src/test/resources/newvapp-hosting.xml b/vcloud/core/src/test/resources/newvapp-hosting.xml index 0ae6d0cfb5..8fb4dbbad8 100644 --- a/vcloud/core/src/test/resources/newvapp-hosting.xml +++ b/vcloud/core/src/test/resources/newvapp-hosting.xml @@ -1 +1 @@ -allowInOutfalse \ No newline at end of file +allowInOutfalse \ No newline at end of file diff --git a/vcloud/core/src/test/resources/newvapp-hostingcpumemdisk.xml b/vcloud/core/src/test/resources/newvapp-hostingcpumemdisk.xml index 0941335da3..87c8da34fa 100644 --- a/vcloud/core/src/test/resources/newvapp-hostingcpumemdisk.xml +++ b/vcloud/core/src/test/resources/newvapp-hostingcpumemdisk.xml @@ -1 +1 @@ -131245129171024allowInOutfalse \ No newline at end of file +131245129171024allowInOutfalse \ No newline at end of file diff --git a/vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml b/vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml index 9abdad4c40..c2f471ac42 100644 --- a/vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml +++ b/vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml @@ -1 +1 @@ -bridgedtrue \ No newline at end of file +bridgedtrue \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java index 1a15e5b183..99fe9f981a 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java @@ -18,11 +18,13 @@ */ package org.jclouds.vcloud.hostingdotcom; +import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; +import java.util.Properties; import javax.inject.Named; import javax.inject.Provider; @@ -34,7 +36,9 @@ import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; +import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.VCloudApi; @@ -93,6 +97,8 @@ public class HostingDotComVCloudAsyncClientTest extends return new AbstractModule() { @Override protected void configure() { + Jsr330.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder( + new Properties()).build(), "properties")); bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog")); bind(String.class).annotatedWith(CatalogItemRoot.class) .toInstance("http://catalogItem"); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java index deeb3b586a..2785f02459 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java @@ -35,12 +35,14 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import org.jclouds.predicates.validators.DnsNameValidator; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.MapPayloadParam; import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.ParamValidators; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.XMLResponseParser; @@ -143,7 +145,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class) @Override ListenableFuture instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId, - @MapPayloadParam("name") String appName, + @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, @MapPayloadParam("template") @ParamParser(CatalogIdToUri.class) String templateId, InstantiateVAppTemplateOptions... options); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java index 8b961b6ced..575815e6c5 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java @@ -40,6 +40,8 @@ public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder { properties.setProperty(PROPERTY_VCLOUD_DEFAULT_MEMORY, "512"); properties.setProperty(PROPERTY_VCLOUD_ENDPOINT, "https://services.vcloudexpress.terremark.com/api"); + properties.setProperty("jclouds.dns_name_length_min", "1"); + properties.setProperty("jclouds.dns_name_length_max", "15"); return properties; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java index 9757eb2f6e..643f9a8e75 100755 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -41,6 +41,7 @@ import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.concurrent.ConcurrentUtils; +import org.jclouds.domain.Location; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.compute.VCloudComputeClient; @@ -110,7 +111,8 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer @Override protected Map provideImages(final VCloudClient client, final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, - LogHolder holder, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, + final Map locations, LogHolder holder, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Function indexer) throws InterruptedException, ExecutionException, TimeoutException { final Set images = Sets.newHashSet(); @@ -139,11 +141,11 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer : Architecture.X86_64; VAppTemplate template = client.getVAppTemplate(item.getEntity() .getId()); - images.add(new ImageImpl(resource.getId(), template.getName(), vDC - .getId(), template.getLocation(), ImmutableMap - . of(), template.getDescription(), "", myOs, - template.getName(), arch, credentialsProvider - .execute(template))); + images.add(new ImageImpl(resource.getId(), template.getName(), + locations.get(vDC.getId()), template.getLocation(), + ImmutableMap. of(), template + .getDescription(), "", myOs, template.getName(), + arch, credentialsProvider.execute(template))); return null; } }), executor)); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java index b9525b092d..3b006b7283 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java @@ -18,13 +18,8 @@ */ package org.jclouds.vcloud.terremark; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled; import static org.testng.Assert.assertEquals; @@ -50,7 +45,6 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; -import org.jclouds.vcloud.domain.FenceMode; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.VCloudApi; @@ -564,16 +558,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest