Issues 203 234 235, add visibility to image from nodemetadata, update to stable version of guava, harden tests, normalize location

This commit is contained in:
Adrian Cole 2010-04-25 00:46:54 -07:00
parent 82bb9e98f7
commit 10af8cdae8
144 changed files with 1647 additions and 759 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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<AtmosStorageAsyncClient> {
public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyncClient> {
private BlobToObject blobToObject;
@ -294,12 +296,11 @@ public class AtmosStorageClientTest extends RestClientTest<AtmosStorageAsyncClie
}, new TypeLiteral<AtmosStorageClient>() {
}));
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))

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -138,15 +138,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Singleton
public static class GetRegionFromNodeOrDefault implements Function<ComputeMetadata, Region> {
private final Map<String, ? extends Location> locations;
@Inject
protected GetRegionFromNodeOrDefault(Map<String, ? extends Location> 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<Location> 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<Location, String>() {
@Override

View File

@ -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<org.jclouds.aws.ec2.domain.Image, I
.build();
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
private final Map<String, ? extends Location> locations;
@Inject
ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider) {
this.credentialProvider = credentialProvider;
ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
Map<String, ? extends Location> locations) {
this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
this.locations = checkNotNull(locations, "locations");
}
@Override
@ -98,7 +105,7 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
return new ImageImpl(
from.getId(),
name,
from.getRegion().toString(),
locations.get(from.getRegion().toString()),
null,
ImmutableMap.<String, String> of("owner", from.getImageOwnerId()),
description,

View File

@ -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<RunningInstance,
private final AMIClient amiClient;
private final Map<RegionTag, KeyPair> credentialsMap;
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
private final Map<String, ? extends Image> images;
private final Map<String, ? extends Location> locations;
@Inject
RunningInstanceToNodeMetadata(AMIClient amiClient, Map<RegionTag, KeyPair> credentialsMap,
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider) {
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
Map<String, ? extends Image> images, Map<String, ? extends Location> 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<RunningInstance,
Map<String, String> 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<RunningInstance,
String getPrivateKeyOrNull(RunningInstance instance, String tag) {
KeyPair keyPair = credentialsMap.get(new RegionTag(instance.getRegion(), instance
.getKeyName()));
String privateKey = keyPair != null ? keyPair.getKeyMaterial() : null;
return privateKey;
return keyPair != null ? keyPair.getKeyMaterial() : null;
}
@VisibleForTesting
String getLoginAccountFor(RunningInstance from) {
Image image = Iterables.getOnlyElement(amiClient.describeImagesInRegion(from.getRegion(),
DescribeImagesOptions.Builder.imageIds(from.getImageId())));
org.jclouds.aws.ec2.domain.Image image = Iterables.getOnlyElement(amiClient
.describeImagesInRegion(from.getRegion(), DescribeImagesOptions.Builder
.imageIds(from.getImageId())));
return checkNotNull(credentialProvider.execute(image), "login from image: "
+ from.getImageId()).account;
}

View File

@ -111,8 +111,8 @@ public class EC2ComputeServiceTest {
}
private TemplateBuilder newTemplateBuilder() {
Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null, true);
Image image = new ImageImpl("ami-image", "image", "us-east-1", null, Maps
Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null);
Image image = new ImageImpl("ami-image", "image", location, null, Maps
.<String, String> newHashMap(), "description", "1.0", null, "ubuntu",
Architecture.X86_64, new Credentials("root", null));

View File

@ -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<Image> result = parseImages(is);
assertEquals(result.size(), 6);
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy());
ImageParser parser = new ImageParser(
new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImmutableMap
.<String, Location> 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<Image> result = parseImages(is);
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy());
ImageParser parser = new ImageParser(
new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImmutableMap
.<String, Location> 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");

View File

@ -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<RegionTag, KeyPair> credentialsMap = createMock(Map.class);
Map<String, org.jclouds.compute.domain.Image> images = createMock(Map.class);
Map<String, Location> 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<RegionTag, KeyPair> credentialsMap = createMock(Map.class);
Map<String, org.jclouds.compute.domain.Image> images = createMock(Map.class);
Map<String, Location> 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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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<AMIAsyncClient> {
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(

View File

@ -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(

View File

@ -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<ElasticBloc
checkFilters(httpMethod);
}
public void testCreateVolumeFromSnapShotWithSize() throws SecurityException, NoSuchMethodException,
IOException {
public void testCreateVolumeFromSnapShotWithSize() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"createVolumeFromSnapshotInAvailabilityZone", AvailabilityZone.class,
int.class, String.class);
"createVolumeFromSnapshotInAvailabilityZone", AvailabilityZone.class, int.class,
String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest(
method, AvailabilityZone.US_EAST_1A, 15, "snapshotId");
@ -433,6 +436,8 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
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(

View File

@ -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;
@ -26,11 +27,13 @@ import java.lang.reflect.Method;
import java.net.InetAddress;
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.AllocateAddressResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler;
import org.jclouds.aws.filters.FormSigner;
@ -171,6 +174,8 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest<ElasticIPAdd
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(

View File

@ -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.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.BlockDeviceMapping;
import org.jclouds.aws.ec2.domain.InstanceType;
@ -578,6 +581,8 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
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(

View File

@ -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<KeyPairAsyncClient> {
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(

View File

@ -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<MonitoringAsyncCli
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(

View File

@ -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.domain.IpProtocol;
import org.jclouds.aws.ec2.domain.UserIdGroupPair;
import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound;
@ -245,6 +248,8 @@ public class SecurityGroupAsyncClientTest extends RestClientTest<SecurityGroupAs
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(

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.aws.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.util.Date;
@ -36,7 +36,6 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.util.concurrent.Executors;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -65,8 +64,8 @@ public class FormSignerTest {
*/
@BeforeClass
protected void createFilter() {
injector = Guice.createInjector(new ParserModule(), new ExecutorServiceModule(Executors
.sameThreadExecutor(), sameThreadExecutor()), new AbstractModule() {
injector = Guice.createInjector(new ParserModule(), new ExecutorServiceModule(
sameThreadExecutor(), sameThreadExecutor()), new AbstractModule() {
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(AWSConstants.PROPERTY_AWS_ACCESSKEYID)).to(

View File

@ -18,12 +18,14 @@
*/
package org.jclouds.aws.s3;
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 org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.blobstore.functions.BlobToObject;
@ -60,7 +62,6 @@ import org.jclouds.blobstore.functions.ReturnFalseOnKeyNotFound;
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseETagHeader;
@ -545,13 +546,13 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
}, new TypeLiteral<S3Client>() {
}));
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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<SQSAsyncClient> {
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");

View File

@ -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;

View File

@ -19,46 +19,47 @@
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
* 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<String> {
@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));
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<AzureQueueAsyncCli
protected void configure() {
bind(URI.class).annotatedWith(AzureQueue.class).toInstance(
URI.create("http://localhost:8080"));
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT)).to("user");
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
Base64.encodeBytes("key".getBytes()));
Jsr330.bindProperties(this.binder(), new AzureQueuePropertiesBuilder("user", "key")
.build());
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;

View File

@ -59,15 +59,6 @@ public interface StorageMetadata extends ResourceMetadata<StorageType> {
@Override
String getName();
/**
* Physical location of the resource.
*
* ex. us-west-1
*
*/
@Override
String getLocationId();
/**
* URI used to access this resource
*/

View File

@ -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<String, String> userMetadata,
String contentType, byte[] contentMD5) {
super(StorageType.BLOB, id, name, location, uri, eTag, size, lastModified, userMetadata);

View File

@ -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<StorageType> 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<String, String> userMetadata) {
super(type, id, name, location, uri, userMetadata);
this.eTag = eTag;

View File

@ -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());
}

View File

@ -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);

View File

@ -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(

View File

@ -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;

View File

@ -65,10 +65,16 @@
<version>2.3.14</version>
</dependency>
<dependency>
<groupId>com.google.common</groupId>
<artifactId>google-guava</artifactId>
<version>1.0-r11</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r03</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
</dependency>
</dependencies>
<build>

View File

@ -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
*/

View File

@ -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<ComputeType> 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<String, String> userMetadata) {
super(type, id, name, locationId, uri, userMetadata);
super(type, id, name, location, uri, userMetadata);
}
}

View File

@ -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<String, String> 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 + "]";
}

View File

@ -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<String, String> 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<String, String> userMetadata, @Nullable String tag, NodeState state,
Iterable<InetAddress> publicAddresses, Iterable<InetAddress> privateAddresses,
Map<String, String> extra, @Nullable Credentials credentials) {
super(ComputeType.NODE, id, name, locationId, uri, userMetadata);
public NodeMetadataImpl(String id, String name, Location location, URI uri,
Map<String, String> userMetadata, @Nullable String tag, @Nullable Image image,
NodeState state, Iterable<InetAddress> publicAddresses,
Iterable<InetAddress> privateAddresses, Map<String, String> 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 + "]";
}

View File

@ -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<Architecture> 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<String, String> userMetadata, double cores, int ram, int disk,
Iterable<Architecture> supportedArchitectures) {
super(ComputeType.SIZE, id, name, location, uri, userMetadata);

View File

@ -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)

View File

@ -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<?, ListenableFuture<Void>> execute(String tag, int count, Template template,

View File

@ -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<?, ListenableFuture<Void>> execute(final String tag, final int count,
final Template template, final Set<NodeMetadata> nodes) {
Map<String, ListenableFuture<Void>> 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<Void>() {
@Override
public Void call() throws Exception {
@ -104,13 +108,22 @@ public class OneByOneRunNodesAndAddToSetStrategy implements RunNodesAndAddToSetS
return responses;
}
protected Set<String> 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<String> getNextNames(final String tag, final Template template, int count) {
Set<String> names = Sets.newHashSet();
int nodeIndex = new SecureRandom().nextInt(8096);
Map<String, ? extends ComputeMetadata> 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)));
}
}

View File

@ -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);
}

View File

@ -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<NodeMetadata> 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<String, ExecResponse> 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<String, ? extends ComputeMetadata> 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,19 +330,21 @@ 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;
if (nodeMetadata.getState() != NodeState.TERMINATED) {
assert nodeMetadata.getPublicAddresses() != null : nodeMetadata;
assert nodeMetadata.getPublicAddresses().size() > 1 : nodeMetadata;
assert nodeMetadata.getPublicAddresses().size() > 0 : nodeMetadata;
assertNotNull(nodeMetadata.getPrivateAddresses());
}
}
}
public void testListImages() throws Exception {
for (Entry<String, ? extends Image> image : client.getImages().entrySet()) {

View File

@ -42,7 +42,7 @@ public class TemplateBuilderImplTest {
public void testImageIdNullsEverythingElse() {
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableMap.<String, Location> of(),
ImmutableMap.<String, Image> of(), ImmutableMap.<String, Size> 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");

View File

@ -84,9 +84,14 @@
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.google.common</groupId>
<artifactId>google-guava</artifactId>
<version>1.0-r11</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r03</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
</dependency>
</dependencies>

View File

@ -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<Method, Method> methodMap;
private final Map<Method, Method> syncMethodMap;
private final Map<Method, Long> timeoutMap;
private static final List<Method> objectMethods = ImmutableList.of(Object.class.getMethods());
private static final Set<Method> objectMethods = ImmutableSet.copyOf(Object.class.getMethods());
@Inject
public SyncProxy(Class<?> declaring, Object delegate) throws SecurityException,

View File

@ -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();
}

View File

@ -49,9 +49,9 @@ public interface MutableResourceMetadata<T extends Enum<T>> 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<T extends Enum<T>> extends ResourceMeta
*/
void setUserMetadata(Map<String, String> userMetadata);
}

View File

@ -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<T extends Enum<T>> extends Comparable<ResourceMetadata<T>> {
/**
@ -57,7 +59,7 @@ public interface ResourceMetadata<T extends Enum<T>> extends Comparable<Resource
* ex. us-west-1
*
*/
String getLocationId();
Location getLocation();
/**
* URI used to access this resource

View File

@ -41,15 +41,12 @@ public class LocationImpl implements Location, Serializable {
private final String id;
private final String description;
private final String parent;
private final boolean assignable;
public LocationImpl(LocationScope scope, String id, String description, @Nullable String parent,
boolean assignable) {
public LocationImpl(LocationScope scope, String id, String description, @Nullable String parent) {
this.scope = checkNotNull(scope, "scope");
this.id = checkNotNull(id, "id");
this.description = checkNotNull(description, "description");
this.parent = parent;
this.assignable = checkNotNull(assignable, "assignable");
}
public LocationScope getScope() {
@ -68,15 +65,10 @@ public class LocationImpl implements Location, Serializable {
return parent;
}
public boolean isAssignable() {
return assignable;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (assignable ? 1231 : 1237);
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((parent == null) ? 0 : parent.hashCode());
@ -93,8 +85,6 @@ public class LocationImpl implements Location, Serializable {
if (getClass() != obj.getClass())
return false;
LocationImpl other = (LocationImpl) obj;
if (assignable != other.assignable)
return false;
if (description == null) {
if (other.description != null)
return false;
@ -121,7 +111,7 @@ public class LocationImpl implements Location, Serializable {
@Override
public String toString() {
return "[id=" + id + ", scope=" + scope + ", description=" + description + ", parent="
+ parent + ", assignable=" + assignable + "]";
+ parent + "]";
}
}

View File

@ -22,6 +22,7 @@ import java.io.Serializable;
import java.net.URI;
import java.util.Map;
import org.jclouds.domain.Location;
import org.jclouds.domain.MutableResourceMetadata;
import org.jclouds.domain.ResourceMetadata;
@ -41,7 +42,7 @@ public class MutableResourceMetadataImpl<T extends Enum<T>> implements MutableRe
private T type;
private String id;
private String name;
private String location;
private Location location;
private URI uri;
private Map<String, String> userMetadata;
@ -53,7 +54,7 @@ public class MutableResourceMetadataImpl<T extends Enum<T>> 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<T extends Enum<T>> implements MutableRe
* {@inheritDoc}
*/
@Override
public void setLocationId(String location) {
public void setLocation(Location location) {
this.location = location;
}
@ -160,7 +161,7 @@ public class MutableResourceMetadataImpl<T extends Enum<T>> implements MutableRe
* {@inheritDoc}
*/
@Override
public String getLocationId() {
public Location getLocation() {
return location;
}

View File

@ -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<T extends Enum<T>> implements ResourceMetadata
@Nullable
private final String name;
@Nullable
private final String locationId;
private final Location location;
@Nullable
private final URI uri;
private final Map<String, String> userMetadata = Maps.newLinkedHashMap();
public ResourceMetadataImpl(T type, @Nullable String id, @Nullable String name,
@Nullable String locationId, @Nullable URI uri, Map<String, String> userMetadata) {
@Nullable Location location, @Nullable URI uri, Map<String, String> 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<T extends Enum<T>> implements ResourceMetadata
* {@inheritDoc}
*/
@Override
public String getLocationId() {
return locationId;
public Location getLocation() {
return location;
}
/**
@ -120,7 +121,7 @@ public class ResourceMetadataImpl<T extends Enum<T>> 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<T extends Enum<T>> 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<T extends Enum<T>> 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<T extends Enum<T>> implements ResourceMetadata
return true;
}
}

View File

@ -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 <T> ListenableFuture<T> submit(HttpCommand command,
Function<HttpResponse, T> responseTransformer) {
return compose(client.submit(command), responseTransformer, Executors.sameThreadExecutor());
return compose(client.submit(command), responseTransformer, sameThreadExecutor());
}
}

View File

@ -0,0 +1,79 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<String> {
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));
}
}

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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<T> {
// , 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<T> processor;
protected Injector injector;
@ -60,25 +74,8 @@ public abstract class RestClientTest<T> {
@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()));

View File

@ -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;

View File

@ -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<HttpResponse> 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

View File

@ -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

View File

@ -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;

View File

@ -33,8 +33,7 @@ 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
*/
@ -54,13 +53,14 @@ public class BindRealIpPortPairsToQueryParams implements Binder {
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");
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()));
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++;
}
}

View File

@ -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()));
}
}

View File

@ -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<Server, NodeMetadata> {
private final Map<String, NodeState> serverStateToNodeState;
private final Function<String, InetAddress> stringIpToInetAddress;
private final GoGridClient client;
@SuppressWarnings("unused")
@Inject
ServerToNodeMetadata(Map<String, NodeState> serverStateToNodeState,
Function<String, InetAddress> 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<InetAddress> 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.<String, String> of(), tag, state, ipSet, ImmutableList
.<InetAddress> of(), ImmutableMap.<String, String> of(), creds);
}
}
@Provides
@Singleton
ComputeServiceContext provideContext(ComputeService computeService,
@ -372,8 +346,8 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
Function<ComputeMetadata, String> indexer) {
final Set<Location> 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<Location, String>() {
@ -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.<String, String> of(), from.getDescription(), version, os,
images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), location, null,
ImmutableMap.<String, String> of(), from.getDescription(), version, os,
osDescription, arch, defaultCredentials));
}
holder.logger.debug("<< images(%d)", images.size());

View File

@ -0,0 +1,74 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<Server, NodeMetadata> {
private final Map<String, NodeState> serverStateToNodeState;
private final GridServerClient client;
private final Location location;
private final Map<String, ? extends Image> images;
@Inject
ServerToNodeMetadata(Map<String, NodeState> serverStateToNodeState, GridServerClient client,
Map<String, ? extends Image> 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<InetAddress> 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
.<String, String> of(), tag, images.get(from.getImage().getId() + ""), state, ipSet,
ImmutableList.<InetAddress> of(), ImmutableMap.<String, String> of(), creds);
}
}

View File

@ -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;
@ -33,7 +35,7 @@ public class Ip implements Comparable<Ip> {
private long id;
private String ip;
private InetAddress ip;
private String subnet;
@SerializedName("public")
private boolean isPublic;
@ -46,16 +48,16 @@ public class Ip implements Comparable<Ip> {
}
/**
* Constructs a generic IP address
* without any additional options.
* Constructs a generic IP address without any additional options.
*
* @param ip ip address
* @param ip
* ip address
*/
public Ip(String ip) {
public Ip(InetAddress ip) {
this.ip = ip;
}
public Ip(long id, String ip, String subnet, boolean isPublic, IpState state) {
public Ip(long id, InetAddress ip, String subnet, boolean isPublic, IpState state) {
this.id = id;
this.ip = ip;
this.subnet = subnet;
@ -67,7 +69,7 @@ public class Ip implements Comparable<Ip> {
return id;
}
public String getIp() {
public InetAddress getIp() {
return ip;
}
@ -85,16 +87,23 @@ public class Ip implements Comparable<Ip> {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
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;
}
@ -111,13 +120,8 @@ public class Ip implements Comparable<Ip> {
@Override
public String toString() {
return "Ip{" +
"id=" + id +
", ip='" + ip + '\'' +
", subnet='" + subnet + '\'' +
", isPublic=" + isPublic +
", state=" + state +
'}';
return "Ip{" + "id=" + id + ", ip='" + ip + '\'' + ", subnet='" + subnet + '\''
+ ", isPublic=" + isPublic + ", state=" + state + '}';
}
@Override

View File

@ -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,13 +56,15 @@ 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.
@ -79,7 +94,8 @@ public interface GridServerAsyncClient {
@GET
@ResponseParser(ParseServerListFromJsonResponse.class)
@Path("/grid/server/get")
ListenableFuture<Set<Server>> getServersByName(@BinderParam(BindNamesToQueryParams.class) String... names);
ListenableFuture<Set<Server>> getServersByName(
@BinderParam(BindNamesToQueryParams.class) String... names);
/**
* @see GridServerClient#getServersById(Long...)
@ -87,7 +103,8 @@ public interface GridServerAsyncClient {
@GET
@ResponseParser(ParseServerListFromJsonResponse.class)
@Path("/grid/server/get")
ListenableFuture<Set<Server>> getServersById(@BinderParam(BindIdsToQueryParams.class) Long... ids);
ListenableFuture<Set<Server>> getServersById(
@BinderParam(BindIdsToQueryParams.class) Long... ids);
/**
* @see GridServerClient#getServerCredentialsList
@ -98,17 +115,26 @@ public interface GridServerAsyncClient {
ListenableFuture<Map<String, Credentials>> 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<Server> addServer(@QueryParam(NAME_KEY) String name,
@QueryParam(IMAGE_KEY) String image,
@QueryParam(SERVER_RAM_KEY) String ram,
@QueryParam(IP_KEY) String ip,
@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<Object, String> {
public String apply(Object from) {
return ((InetAddress) from).getHostAddress();
}
}
/**
* @see GridServerClient#power(String, org.jclouds.gogrid.domain.PowerCommand)
*/

View File

@ -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
*/

View File

@ -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<InetSocketAddress> socketOpen = new RetryablePredicate<InetSocketAddress>(
new SocketOpen(), 180, 5, TimeUnit.SECONDS);

View File

@ -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<String, NodeState> serverStateToNodeState = createMock(Map.class);
Map<String, org.jclouds.compute.domain.Image> 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<String, Credentials> 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);
}
}

View File

@ -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;

View File

@ -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<LoadBalancer> 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);
}

View File

@ -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")));

View File

@ -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<GridImageAsyncClien
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() {

View File

@ -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.IpType;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse;
@ -37,6 +40,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;
@ -118,6 +122,8 @@ public class GridIpAsyncClientTest extends RestClientTest<GridIpAsyncClient> {
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() {

View File

@ -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<GridJobAsyncClient> {
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() {

View File

@ -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<GridLoadBala
Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer", String.class,
IpPortPair.class, List.class, AddLoadBalancerOptions[].class);
GeneratedHttpRequest<GridLoadBalancerAsyncClient> 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<GridLoadBala
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", String.class,
List.class);
GeneratedHttpRequest<GridLoadBalancerAsyncClient> 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<GridLoadBala
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() {

View File

@ -41,17 +41,21 @@
*/
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.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.PowerCommand;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
@ -64,6 +68,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.common.collect.Iterables;
@ -183,9 +188,9 @@ public class GridServerAsyncClientTest extends RestClientTest<GridServerAsyncCli
@Test
public void testAddServerNoOptions() throws NoSuchMethodException, IOException {
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class,
String.class, String.class, String.class, AddServerOptions[].class);
String.class, String.class, InetAddress.class, AddServerOptions[].class);
GeneratedHttpRequest<GridServerAsyncClient> 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<GridServerAsyncCli
@Test
public void testAddServerOptions() throws NoSuchMethodException, IOException {
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class,
String.class, String.class, String.class, AddServerOptions[].class);
String.class, String.class, InetAddress.class, AddServerOptions[].class);
GeneratedHttpRequest<GridServerAsyncClient> 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<GridServerAsyncCli
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 LoggerFactory() {

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.mezeo.pcs2;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
@ -27,6 +28,7 @@ import java.lang.reflect.Method;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import javax.inject.Singleton;
import javax.ws.rs.HttpMethod;
@ -56,6 +58,7 @@ import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -71,7 +74,7 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "pcs2.PCSClientTest")
public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
public void testList() throws SecurityException, NoSuchMethodException, IOException {
Method method = PCSAsyncClient.class.getMethod("list");
@ -298,6 +301,8 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
new TypeLiteral<PCSAsyncClient>() {
}, new TypeLiteral<PCSClient>() {
}));
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(

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<SDNAsyncClient> {
public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
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<SDNAsyncClient> {
new TypeLiteral<SDNAsyncClient>() {
}, new TypeLiteral<SDNClient>() {
}));
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<SDNAsyncClient> {
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");
}
};

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

Some files were not shown because too many files have changed in this diff Show More