Issue 418: updated location object to include metadata and iso3166codes

This commit is contained in:
Adrian Cole 2011-01-31 01:00:20 -08:00
parent 3263d22bfc
commit 675563c96a
158 changed files with 2024 additions and 1505 deletions

View File

@ -19,10 +19,6 @@
package org.jclouds.atmos.blobstore.config;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.atmos.AtmosAsyncClient;
import org.jclouds.atmos.AtmosClient;
import org.jclouds.atmos.blobstore.AtmosAsyncBlobStore;
@ -37,17 +33,9 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Provider;
import org.jclouds.location.config.JustProviderLocationModule;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
@ -64,24 +52,10 @@ public class AtmosBlobStoreContextModule extends AbstractModule {
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
bind(AsyncBlobStore.class).to(AtmosAsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(AtmosBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class).to(
new TypeLiteral<BlobStoreContextImpl<AtmosClient, AtmosAsyncClient>>() {
bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<AtmosClient, AtmosAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
bind(BlobRequestSigner.class).to(AtmosBlobRequestSigner.class);
}
@Provides
@Singleton
@Memoized
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
}
@Provides
@Singleton
Supplier<Location> provideDefaultLocation(@Provider String providerName) {
return Suppliers
.<Location> ofInstance(new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null));
install(new JustProviderLocationModule());
}
}

View File

@ -1,47 +0,0 @@
/**
*
* 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.cloudfiles;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties;
import org.jclouds.openstack.swift.SwiftPropertiesBuilder;
/**
* Builds properties used in CloudFiles Connections
*
* @author Adrian Cole
*/
public class CloudFilesPropertiesBuilder extends SwiftPropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_REGIONS, "US");
properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com");
return properties;
}
public CloudFilesPropertiesBuilder(Properties properties) {
super(properties);
}
}

View File

@ -21,13 +21,13 @@ package org.jclouds.cloudservers.compute.config;
import java.util.Set;
import org.jclouds.cloudservers.compute.suppliers.CloudServersHardwareSupplier;
import org.jclouds.cloudservers.compute.suppliers.CloudServersImageSupplier;
import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.domain.Location;
import org.jclouds.cloudservers.compute.suppliers.CloudServersHardwareSupplier;
import org.jclouds.cloudservers.compute.suppliers.CloudServersImageSupplier;
import org.jclouds.location.suppliers.SupplyPredefinedRegions;
import org.jclouds.location.suppliers.JustProvider;
import com.google.common.base.Supplier;
@ -49,6 +49,6 @@ public class CloudServersBindComputeSuppliersByClass extends BindComputeSupplier
@Override
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return SupplyPredefinedRegions.class;
return JustProvider.class;
}
}

View File

@ -20,7 +20,6 @@
package org.jclouds.cloudservers.compute.config;
import java.util.Map;
import java.util.Set;
import javax.inject.Singleton;
@ -41,8 +40,6 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.location.Region;
import org.jclouds.location.config.ProvideRegionsViaProperties;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
@ -82,8 +79,6 @@ public class CloudServersComputeServiceDependenciesModule extends AbstractModule
bind(new TypeLiteral<RestContext<CloudServersClient, CloudServersAsyncClient>>() {
}).to(new TypeLiteral<RestContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<Set<String>>() {
}).annotatedWith(Region.class).toProvider(ProvideRegionsViaProperties.class).in(Scopes.SINGLETON);
}
@VisibleForTesting

View File

@ -31,6 +31,8 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.cloudservers.domain.Server;
import org.jclouds.cloudservers.domain.ServerStatus;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
@ -41,11 +43,9 @@ import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.logging.Logger;
import org.jclouds.cloudservers.domain.Server;
import org.jclouds.cloudservers.domain.ServerStatus;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
@ -109,7 +109,8 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getId() + "");
builder.name(from.getName());
builder.location(new LocationImpl(LocationScope.HOST, from.getHostId(), from.getHostId(), location.get()));
builder.location(new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()).description(
from.getHostId()).parent(location.get()).build());
builder.userMetadata(from.getMetadata());
builder.tag(parseTagFromName(from.getName()));
builder.imageId(from.getImageId() + "");

View File

@ -23,16 +23,16 @@ import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException;
import org.jclouds.cloudservers.domain.Flavor;
import org.jclouds.cloudservers.functions.ParseFlavorFromJsonResponseTest;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.VolumeBuilder;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.cloudservers.domain.Flavor;
import org.jclouds.cloudservers.functions.ParseFlavorFromJsonResponseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@ -42,20 +42,14 @@ import com.google.common.collect.ImmutableList;
*/
@Test(groups = "unit")
public class FlavorToHardwareTest {
Location provider = new LocationImpl(LocationScope.ZONE, "dallas", "description", null);
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
@Test
public void test() throws UnknownHostException {
assertEquals(
convertFlavor(),
new HardwareBuilder()
.ids("1")
.name("256 MB Server")
.processors(ImmutableList.of(new Processor(1.0, 1.0)))
.ram(256)
.volumes(
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true)
.bootDevice(true).build())).build());
assertEquals(convertFlavor(), new HardwareBuilder().ids("1").name("256 MB Server").processors(
ImmutableList.of(new Processor(1.0, 1.0))).ram(256).volumes(
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true).bootDevice(true)
.build())).build());
}
public static Hardware convertFlavor() {

View File

@ -25,6 +25,10 @@ import java.net.UnknownHostException;
import java.util.Map;
import java.util.Set;
import org.jclouds.cloudservers.compute.config.CloudServersComputeServiceDependenciesModule;
import org.jclouds.cloudservers.domain.Server;
import org.jclouds.cloudservers.domain.ServerStatus;
import org.jclouds.cloudservers.functions.ParseServerFromJsonResponseTest;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image;
@ -38,12 +42,8 @@ import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.VolumeBuilder;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.cloudservers.compute.config.CloudServersComputeServiceDependenciesModule;
import org.jclouds.cloudservers.domain.Server;
import org.jclouds.cloudservers.domain.ServerStatus;
import org.jclouds.cloudservers.functions.ParseServerFromJsonResponseTest;
import org.testng.annotations.Test;
import com.google.common.base.Suppliers;
@ -56,7 +56,7 @@ import com.google.common.collect.ImmutableSet;
*/
@Test(groups = "unit")
public class ServerToNodeMetadataTest {
Location provider = new LocationImpl(LocationScope.ZONE, "dallas", "description", null);
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
@Test
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws UnknownHostException {
@ -68,18 +68,16 @@ public class ServerToNodeMetadataTest {
Server server = ParseServerFromJsonResponseTest.parseServer();
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
.<String, Credentials> of("node#1234", creds), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
.<String, Credentials> of("node#1234", creds), Suppliers.<Set<? extends Image>> ofInstance(images),
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
NodeMetadata metadata = parser.apply(server);
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")).tag(
"NOTAG#sample-server").imageId("2").id("1234").providerId("1234").name("sample-server").credentials(
creds).location(
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
"description", null))).userMetadata(
creds).location( new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0").description(
"e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()).userMetadata(
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
}
@ -99,9 +97,8 @@ public class ServerToNodeMetadataTest {
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")).tag(
"NOTAG#sample-server").imageId("2").id("1234").providerId("1234").name("sample-server").location(
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
"description", null))).userMetadata(
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0").description(
"e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()).userMetadata(
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
}
@ -125,9 +122,8 @@ public class ServerToNodeMetadataTest {
"NOTAG#sample-server").imageId("2").operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2").is64Bit(
true).build()).id("1234").providerId("1234").name("sample-server").location(
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
"description", null))).userMetadata(
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0").description(
"e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()).userMetadata(
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
}
@ -154,9 +150,8 @@ public class ServerToNodeMetadataTest {
.bootDevice(true).build())).build()).operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2").is64Bit(
true).build()).id("1234").providerId("1234").name("sample-server").location(
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
"description", null))).userMetadata(
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0").description(
"e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build()).userMetadata(
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
}
}

View File

@ -40,8 +40,8 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.ec2.domain.Image.Architecture;
import org.jclouds.ec2.domain.Image.ImageType;
@ -116,8 +116,8 @@ public class EC2ImageParser implements Function<org.jclouds.ec2.domain.Image, Im
}));
} catch (NoSuchElementException e) {
System.err.printf("unknown region %s for image %s; not in %s", from.getRegion(), from.getId(), locations);
builder.location(new LocationImpl(LocationScope.REGION, from.getRegion(), from.getRegion(), defaultLocation
.get().getParent()));
builder.location(new LocationBuilder().scope(LocationScope.REGION).id(from.getRegion()).description(
from.getRegion()).parent(defaultLocation.get()).build());
}
builder.operatingSystem(osBuilder.build());
return builder.build();

View File

@ -19,8 +19,11 @@
package org.jclouds.ec2.config;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.inject.Inject;
@ -51,8 +54,16 @@ import org.jclouds.location.Region;
import org.jclouds.location.Zone;
import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.base.Predicates;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.ConfigurationException;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.name.Names;
/**
* Configures the EC2 connection.
@ -96,20 +107,31 @@ public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient>
@Singleton
public static class RegionIdsToURI implements javax.inject.Provider<Map<String, URI>> {
private final AvailabilityZoneAndRegionClient client;
private final Injector injector;
@Inject
public RegionIdsToURI(EC2Client client) {
public RegionIdsToURI(EC2Client client, Injector injector) {
this.client = client.getAvailabilityZoneAndRegionServices();
this.injector = injector;
}
@Singleton
@Region
@Override
public Map<String, URI> get() {
return client.describeRegions();
try {
String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS)));
Set<String> regions = ImmutableSet.copyOf(Splitter.on(',').split(regionString));
if (regions.size() > 0)
return Maps.filterKeys(client.describeRegions(), Predicates.in(regions));
} catch (ConfigurationException e) {
// this happens if regions property isn't set
// services not run by AWS may not have regions, so this is ok.
}
return client.describeRegions();
}
}
@Singleton
public static class RegionIdToZoneId implements javax.inject.Provider<Map<String, String>> {

View File

@ -51,8 +51,8 @@ import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.testng.annotations.Test;
import com.google.common.base.Function;
@ -71,7 +71,8 @@ import com.google.common.collect.ImmutableSet;
* @author Oleksiy Yarmula
*/
public class EC2TemplateBuilderTest {
private static final Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null);
private static final Location location = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
.description("us-east-1").build();
public static final Hardware CC1_4XLARGE = cc1_4xlarge().location(location).supportsImageIds("us-east-1/cc-image")
.build();

View File

@ -31,8 +31,8 @@ import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
import org.jclouds.ec2.domain.Image;
@ -74,7 +74,8 @@ public class EC2ImageParserTest {
ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
}
static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description(
"us-east-1").build();
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {

View File

@ -36,8 +36,8 @@ import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule;
import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.domain.InstanceState;
@ -67,7 +67,8 @@ public class RunningInstanceToNodeMetadataTest {
}
Location provider = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
static Location provider = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
.description("us-east-1").build();
@Test
public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationNotFoundButCredentialsFound()
@ -81,9 +82,9 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).publicAddresses(
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f")
.credentials(creds).imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f")
.providerId("i-0799056f").build());
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(
ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f").credentials(creds).imageId(
"us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").build());
}
@Test
@ -94,8 +95,9 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).publicAddresses(
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f")
.imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").build());
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(
ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").id(
"us-east-1/i-0799056f").providerId("i-0799056f").build());
}
@Test
@ -106,8 +108,9 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").id(
"us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build());
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag(
"NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f")
.providerId("i-0799056f").location(provider).build());
}
@Test
@ -118,11 +121,11 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7")
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual")
.description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id(
"us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build());
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag(
"NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description(
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f")
.providerId("i-0799056f").location(provider).build());
}
@Test
@ -134,8 +137,8 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag("NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").hardware(
m1_small().build()).operatingSystem(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).tag(
"NOTAG#i-0799056f").imageId("us-east-1/ami-82e4b5c7").hardware(m1_small().build()).operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description(
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f")
.providerId("i-0799056f").location(provider).build());

View File

@ -32,8 +32,6 @@ import java.util.concurrent.ConcurrentMap;
import javax.inject.Provider;
import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.compute.options.EC2TemplateOptions;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
@ -43,8 +41,10 @@ import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.domain.internal.TemplateBuilderImplTest;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.compute.options.EC2TemplateOptions;
import org.testng.annotations.Test;
import com.google.common.base.Function;
@ -89,7 +89,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
@SuppressWarnings("unchecked")
@Test
public void testParseOnDemand() {
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
Location location = new LocationBuilder().scope(LocationScope.REGION).id("region").description("region").build();
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location));
@ -142,7 +142,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
@SuppressWarnings("unchecked")
@Test
public void testParseOnDemandWithoutRegionEncodedIntoId() {
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
Location location = new LocationBuilder().scope(LocationScope.REGION).id("region").description("region").build();
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location));
@ -179,7 +179,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
@SuppressWarnings("unchecked")
@Test(expectedExceptions = NoSuchElementException.class)
public void testParseOnDemandNotFound() {
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
Location location = new LocationBuilder().scope(LocationScope.REGION).id("region").description("region").build();
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location));

View File

@ -39,8 +39,8 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.util.ComputeUtils;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
import org.jclouds.ec2.compute.options.EC2TemplateOptions;
@ -154,10 +154,12 @@ public class EC2RunNodesAndAddToSetStrategyTest {
verifyStrategy(strategy);
}
private static final Location REGION_AP_SOUTHEAST_1 = new LocationImpl(LocationScope.REGION, Region.AP_SOUTHEAST_1,
Region.AP_SOUTHEAST_1, new LocationImpl(LocationScope.PROVIDER, "ec2", "ec2", null));
private static final Location ZONE_AP_SOUTHEAST_1A = new LocationImpl(LocationScope.ZONE,
AvailabilityZone.AP_SOUTHEAST_1A, AvailabilityZone.AP_SOUTHEAST_1A, REGION_AP_SOUTHEAST_1);
private static final Location REGION_AP_SOUTHEAST_1 = new LocationBuilder().scope(LocationScope.REGION).id(
Region.AP_SOUTHEAST_1).description(Region.AP_SOUTHEAST_1).parent(
new LocationBuilder().scope(LocationScope.PROVIDER).id("ec2").description("ec2").build()).build();
private static final Location ZONE_AP_SOUTHEAST_1A = new LocationBuilder().scope(LocationScope.ZONE).id(
AvailabilityZone.AP_SOUTHEAST_1A).description(AvailabilityZone.AP_SOUTHEAST_1A).parent(
REGION_AP_SOUTHEAST_1).build();
// /////////////////////////////////////////////////////////////////////
@SuppressWarnings("unchecked")

View File

@ -6,7 +6,6 @@ import static com.google.common.collect.Iterables.filter;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import static org.jclouds.elasticstack.util.Servers.small;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@ -29,8 +28,6 @@ import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.elasticstack.ElasticStackAsyncClient;
import org.jclouds.elasticstack.ElasticStackClient;
import org.jclouds.elasticstack.domain.Device;
@ -42,7 +39,7 @@ import org.jclouds.elasticstack.domain.ServerInfo;
import org.jclouds.elasticstack.domain.ServerStatus;
import org.jclouds.elasticstack.domain.WellKnownImage;
import org.jclouds.elasticstack.reference.ElasticStackConstants;
import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
@ -64,8 +61,7 @@ public class ElasticStackComputeServiceAdapter implements
private final Predicate<DriveInfo> driveNotClaimed;
private final Map<String, WellKnownImage> preinstalledImages;
private final Map<String, DriveInfo> cache;
private final String providerName;
private final URI providerURI;
private final JustProvider locationSupplier;
private final String defaultVncPassword;
private final ExecutorService executor;
@ -75,15 +71,14 @@ public class ElasticStackComputeServiceAdapter implements
@Inject
public ElasticStackComputeServiceAdapter(ElasticStackClient client, ElasticStackAsyncClient aclient,
Predicate<DriveInfo> driveNotClaimed, @Provider String providerName, @Provider URI providerURI,
Predicate<DriveInfo> driveNotClaimed, JustProvider locationSupplier,
Map<String, WellKnownImage> preinstalledImages, Map<String, DriveInfo> cache,
@Named(ElasticStackConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.client = checkNotNull(client, "client");
this.aclient = checkNotNull(aclient, "aclient");
this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed");
this.providerName = checkNotNull(providerName, "providerName");
this.providerURI = checkNotNull(providerURI, "providerURI");
this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier");
this.preinstalledImages = checkNotNull(preinstalledImages, "preinstalledImages");
this.cache = checkNotNull(cache, "cache");
this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword");
@ -169,10 +164,10 @@ public class ElasticStackComputeServiceAdapter implements
return (Iterable<ServerInfo>) client.listServerInfo();
}
@SuppressWarnings("unchecked")
@Override
public Iterable<Location> listLocations() {
return ImmutableSet.<Location> of(new LocationImpl(LocationScope.PROVIDER, providerName, providerURI
.toASCIIString(), null));
return (Iterable<Location>) locationSupplier.get();
}
@Override

View File

@ -52,12 +52,14 @@ import org.jclouds.elasticstack.predicates.DriveClaimed;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.json.Json;
import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.util.Strings2;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.MapMaker;
import com.google.common.collect.Maps;
import com.google.inject.Provides;
@ -97,6 +99,8 @@ public class ElasticStackComputeServiceContextModule
}).to(FindImageForId.class);
bind(new TypeLiteral<Function<DriveInfo, Image>>() {
}).to(WellKnownImageToImage.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(OnlyLocationOrFirstZone.class);
}
@Provides

View File

@ -76,8 +76,6 @@ public class BindServerToPlainTextStringTest {
protected void configure() {
bind(new TypeLiteral<Function<Server, Map<String, String>>>() {
}).to(ServerToMap.class);
bind(new TypeLiteral<Function<Server, Map<String, String>>>() {
}).to(ServerToMap.class);
}
}).getInstance(BindServerToPlainTextString.class);

View File

@ -19,8 +19,6 @@
package org.jclouds.filesystem.config;
import java.util.Set;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
@ -29,10 +27,6 @@ import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.filesystem.FilesystemBlobStore;
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
@ -41,10 +35,8 @@ import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainer
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
import org.jclouds.filesystem.util.internal.FileSystemBlobUtilsImpl;
import org.jclouds.location.config.JustProviderLocationModule;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
@ -69,6 +61,7 @@ public class FilesystemBlobStoreContextModule extends AbstractModule {
bind(BlobUtils.class).to(FileSystemBlobUtilsImpl.class);
bind(FilesystemBlobKeyValidator.class).to(FilesystemBlobKeyValidatorImpl.class);
bind(FilesystemContainerNameValidator.class).to(FilesystemContainerNameValidatorImpl.class);
install(new JustProviderLocationModule());
}
@Provides
@ -77,18 +70,4 @@ public class FilesystemBlobStoreContextModule extends AbstractModule {
return in;
}
@Provides
@Singleton
@Memoized
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
}
@Provides
@Singleton
Supplier<Location> provideDefaultLocation() {
return Suppliers
.<Location> ofInstance(new LocationImpl(LocationScope.PROVIDER, "filesystem", "filesystem", null));
}
}

View File

@ -19,17 +19,6 @@
package org.jclouds.s3.blobstore.config;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.S3Client;
import org.jclouds.s3.blobstore.S3AsyncBlobStore;
import org.jclouds.s3.blobstore.S3BlobRequestSigner;
import org.jclouds.s3.blobstore.S3BlobStore;
import org.jclouds.s3.blobstore.functions.LocationFromBucketLocation;
import org.jclouds.s3.domain.BucketMetadata;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.BlobStore;
@ -37,20 +26,18 @@ import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Provider;
import org.jclouds.location.Region;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZoneOrRegionMatchingRegionId;
import org.jclouds.location.config.RegionsLocationModule;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.S3Client;
import org.jclouds.s3.blobstore.S3AsyncBlobStore;
import org.jclouds.s3.blobstore.S3BlobRequestSigner;
import org.jclouds.s3.blobstore.S3BlobStore;
import org.jclouds.s3.blobstore.functions.LocationFromBucketLocation;
import org.jclouds.s3.domain.BucketMetadata;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Sets;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
@ -64,9 +51,7 @@ public class S3BlobStoreContextModule extends AbstractModule {
@Override
protected void configure() {
install(new BlobStoreMapModule());
bind(new TypeLiteral<Supplier<Location>>() {
}).to(new TypeLiteral<OnlyLocationOrFirstZoneOrRegionMatchingRegionId>() {
});
install(new RegionsLocationModule());
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON);
@ -81,15 +66,5 @@ public class S3BlobStoreContextModule extends AbstractModule {
}).to(LocationFromBucketLocation.class);
}
@Provides
@Singleton
@Memoized
Supplier<Set<? extends Location>> provideLocations(@Region Set<String> regions, @Provider String providerName) {
Set<Location> locations = Sets.newHashSet();
Location s3 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
for (String zone : regions) {
locations.add(new LocationImpl(LocationScope.REGION, zone.toString(), zone.toString(), s3));
}
return Suppliers.<Set<? extends Location>> ofInstance(locations);
}
}

View File

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -49,7 +50,7 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
private final Set<String> regions;
@Inject
BindRegionToXmlPayload(@org.jclouds.location.Region String defaultRegion,
BindRegionToXmlPayload(@org.jclouds.location.Region @Nullable String defaultRegion,
@org.jclouds.location.Region Set<String> regions) {
this.defaultRegion = defaultRegion;
this.regions = regions;
@ -57,6 +58,8 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
if (defaultRegion == null)
return request;
input = input == null ? defaultRegion : input;
checkArgument(input instanceof String, "this binder is only valid for Region!");
String constraint = (String) input;
@ -70,8 +73,7 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
logger.warn("region %s not in %s ", constraint, regions);
value = constraint;
}
String payload = String
.format(
String payload = String.format(
"<CreateBucketConfiguration><LocationConstraint>%s</LocationConstraint></CreateBucketConfiguration>",
value);
request = super.bindToRequest(request, payload);

View File

@ -389,25 +389,6 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
checkFilters(request);
}
public void testPutBucketEu() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, String.class, Array.newInstance(
PutBucketOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "EU", "bucket");
assertRequestLineEquals(request, "PUT https://bucket." + url + "/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket." + url + "\n");
assertPayloadEquals(request,
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
"text/xml", false);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState.class);
checkFilters(request);
}
public void testPutObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {

View File

@ -37,6 +37,20 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.concurrent.Futures;
import org.jclouds.date.DateService;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.http.options.GetOptions;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.blobstore.S3AsyncBlobStore;
import org.jclouds.s3.blobstore.functions.BlobToObject;
@ -59,20 +73,6 @@ import org.jclouds.s3.options.CopyObjectOptions;
import org.jclouds.s3.options.ListBucketOptions;
import org.jclouds.s3.options.PutBucketOptions;
import org.jclouds.s3.options.PutObjectOptions;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.concurrent.Futures;
import org.jclouds.date.DateService;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.http.options.GetOptions;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
@ -140,7 +140,8 @@ public class StubS3AsyncClient implements S3AsyncClient {
region = region == null ? Region.US_STANDARD : region;
final PutBucketOptions options = (optionsList.length == 0) ? new PutBucketOptions() : optionsList[0];
keyToAcl.put(name, options.getAcl());
return blobStore.createContainerInLocation(new LocationImpl(LocationScope.REGION, region, region, null), name);
return blobStore.createContainerInLocation(new LocationBuilder().scope(LocationScope.REGION).id(region)
.description(region).build(), name);
}
public ListenableFuture<ListBucketResponse> listBucket(final String name, ListBucketOptions... optionsList) {

View File

@ -19,10 +19,6 @@
package org.jclouds.openstack.swift.blobstore.config;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.BlobStore;
@ -30,22 +26,14 @@ import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.location.Region;
import org.jclouds.location.config.ProvideRegionsViaProperties;
import org.jclouds.location.suppliers.SupplyPredefinedRegions;
import org.jclouds.location.config.JustProviderLocationModule;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
import org.jclouds.openstack.swift.blobstore.SwiftBlobRequestSigner;
import org.jclouds.openstack.swift.blobstore.SwiftBlobStore;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
@ -60,12 +48,7 @@ public class SwiftBlobStoreContextModule extends AbstractModule {
@Override
protected void configure() {
install(new BlobStoreMapModule());
bind(new TypeLiteral<Supplier<Set<? extends Location>>>() {
}).annotatedWith(Memoized.class).to(new TypeLiteral<SupplyPredefinedRegions>() {
});
bind(new TypeLiteral<Set<String>>() {
}).annotatedWith(Region.class).toProvider(ProvideRegionsViaProperties.class).in(Scopes.SINGLETON);
install(new JustProviderLocationModule());
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
bind(AsyncBlobStore.class).to(SwiftAsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(SwiftBlobStore.class).in(Scopes.SINGLETON);
@ -74,10 +57,5 @@ public class SwiftBlobStoreContextModule extends AbstractModule {
bind(BlobRequestSigner.class).to(SwiftBlobRequestSigner.class);
}
@Provides
@Singleton
protected Supplier<Location> getLocation(@Memoized Supplier<Set<? extends Location>> locations) {
return Suppliers.<Location> ofInstance(Iterables.get(locations.get(), 0));
}
}

View File

@ -19,7 +19,6 @@
package org.jclouds.blobstore.config;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@ -34,15 +33,9 @@ import org.jclouds.blobstore.TransientBlobRequestSigner;
import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Provider;
import org.jclouds.location.config.JustProviderLocationModule;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
@ -70,6 +63,7 @@ public class TransientBlobStoreContextModule extends AbstractModule {
}).toInstance(containerToLocation);
install(new BlobStoreObjectModule());
install(new BlobStoreMapModule());
install(new JustProviderLocationModule());
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
bind(BlobRequestSigner.class).to(TransientBlobRequestSigner.class);
}
@ -79,18 +73,4 @@ public class TransientBlobStoreContextModule extends AbstractModule {
BlobStore provide(TransientBlobStore in) {
return in;
}
@Provides
@Singleton
@Memoized
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
}
@Provides
@Singleton
Supplier<Location> provideDefaultLocation(@Provider String providerName) {
return Suppliers
.<Location> ofInstance(new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null));
}
}

View File

@ -31,6 +31,7 @@ import org.jclouds.domain.LocationScope;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
@ -61,11 +62,9 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
PageSet<? extends StorageMetadata> list = context.getBlobStore().list();
assert Iterables.any(list, new Predicate<StorageMetadata>() {
public boolean apply(StorageMetadata md) {
return containerName.equals(md.getName())
&& location.equals(md.getLocation());
return containerName.equals(md.getName()) && location.equals(md.getLocation());
}
}) : String.format("container %s/%s not found in list %s", location,
containerName, list);
}) : String.format("container %s/%s not found in list %s", location, containerName, list);
}
});
@ -75,10 +74,14 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
}
}
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of();
}
@Test(groups = { "integration", "live" })
public void testGetAssignableLocations() throws Exception {
for (Location location : context.getBlobStore()
.listAssignableLocations()) {
assertProvider(context.getProviderSpecificContext());
for (Location location : context.getBlobStore().listAssignableLocations()) {
System.err.printf("location %s%n", location);
assert location.getId() != null : location;
assert location != location.getParent() : location;
@ -89,6 +92,9 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
break;
case REGION:
assertProvider(location.getParent());
assert location.getIso3166Codes().size() == 0
|| location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location
+ " ||" + location.getParent();
break;
case ZONE:
Location provider = location.getParent().getParent();
@ -96,6 +102,9 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
if (provider == null)
provider = location.getParent();
assertProvider(provider);
assert location.getIso3166Codes().size() == 0
|| location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location
+ " ||" + location.getParent();
break;
case HOST:
Location provider2 = location.getParent().getParent().getParent();
@ -108,9 +117,10 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
}
}
public void assertProvider(Location provider) {
void assertProvider(Location provider) {
assertEquals(provider.getScope(), LocationScope.PROVIDER);
assertEquals(provider.getParent(), null);
assertEquals(provider.getIso3166Codes(), getIso3166Codes());
}
}

View File

@ -25,6 +25,7 @@ import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
@ -79,10 +80,11 @@ public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
@Provides
@Singleton
@Nullable
@Region
protected String getDefaultRegion(@Provider URI uri, @Region Map<String, URI> map, LoggerFactory logFactory) {
String region = ImmutableBiMap.copyOf(map).inverse().get(uri);
if (region == null) {
if (region == null && map.size() > 0) {
logFactory.getLogger(getClass().getName()).warn(
"failed to find region for current endpoint %s in %s; choosing first: %s", uri, map, region);
region = get(map.keySet(), 0);

View File

@ -51,7 +51,7 @@ import com.google.inject.name.Names;
public class FormSignerTest {
@SuppressWarnings("unchecked")
public static final RestContextSpec<Map, List> DUMMY_SPEC = new RestContextSpec<Map, List>("provider", "endpoint",
"apiVersion", "identity", "credential", Map.class, List.class, PropertiesBuilder.class,
"apiVersion", "", "identity", "credential", Map.class, List.class, PropertiesBuilder.class,
(Class) RestContextBuilder.class, ImmutableList.<Module> of(new MockModule(), new NullLoggingModule(),
new AbstractModule() {
@Override

View File

@ -139,8 +139,9 @@ public class SharedKeyLiteAuthenticationTest {
@SuppressWarnings("unchecked")
public static final RestContextSpec<Map, List> DUMMY_SPEC = new RestContextSpec<Map, List>("provider", "endpoint",
"apiVersion", "identity", "credential", Map.class, List.class, PropertiesBuilder.class,
"apiVersion", "", "identity", "credential", Map.class, List.class, PropertiesBuilder.class,
(Class) RestContextBuilder.class, ImmutableList.<Module> of(new MockModule(), new NullLoggingModule(),
new AzureStorageRestClientModule<Exception, RuntimeException>(Exception.class, RuntimeException.class)));
new AzureStorageRestClientModule<Exception, RuntimeException>(Exception.class,
RuntimeException.class)));
}

View File

@ -63,8 +63,8 @@ public class OpenStackAuthAsyncClientTest extends RestClientTest<OpenStackAuthAs
@Override
public RestContextSpec<OpenStackAuthClient, OpenStackAuthAsyncClient> createContextSpec() {
return contextSpec("test", "http://localhost:8080", "1.0", "identity", "credential", OpenStackAuthClient.class,
OpenStackAuthAsyncClient.class);
return contextSpec("test", "http://localhost:8080", "1.0", "", "identity", "credential",
OpenStackAuthClient.class, OpenStackAuthAsyncClient.class);
}
@Override

View File

@ -27,6 +27,7 @@ import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.BindComputeStrategiesByClass;
import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.location.config.LocationModule;
import org.jclouds.vcloud.domain.Status;
import com.google.common.annotations.VisibleForTesting;
@ -42,13 +43,13 @@ import com.google.inject.Provides;
public abstract class CommonVCloudComputeServiceContextModule extends BaseComputeServiceContextModule {
@VisibleForTesting
static final Map<Status, NodeState> vAppStatusToNodeState = ImmutableMap.<Status, NodeState> builder()
.put(Status.OFF, NodeState.SUSPENDED).put(Status.ON, NodeState.RUNNING)
.put(Status.RESOLVED, NodeState.PENDING).put(Status.ERROR, NodeState.ERROR)
.put(Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(Status.DEPLOYED, NodeState.PENDING)
.put(Status.INCONSISTENT, NodeState.PENDING).put(Status.UNKNOWN, NodeState.UNRECOGNIZED)
.put(Status.MIXED, NodeState.PENDING).put(Status.WAITING_FOR_INPUT, NodeState.PENDING)
.put(Status.SUSPENDED, NodeState.SUSPENDED).put(Status.UNRESOLVED, NodeState.PENDING).build();
static final Map<Status, NodeState> vAppStatusToNodeState = ImmutableMap.<Status, NodeState> builder().put(
Status.OFF, NodeState.SUSPENDED).put(Status.ON, NodeState.RUNNING).put(Status.RESOLVED, NodeState.PENDING)
.put(Status.ERROR, NodeState.ERROR).put(Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(Status.DEPLOYED,
NodeState.PENDING).put(Status.INCONSISTENT, NodeState.PENDING).put(Status.UNKNOWN,
NodeState.UNRECOGNIZED).put(Status.MIXED, NodeState.PENDING).put(Status.WAITING_FOR_INPUT,
NodeState.PENDING).put(Status.SUSPENDED, NodeState.SUSPENDED).put(Status.UNRESOLVED,
NodeState.PENDING).build();
@Singleton
@Provides

View File

@ -19,6 +19,9 @@
package org.jclouds.vcloud.compute.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
@ -26,43 +29,65 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.ImmutableSet.Builder;
/**
* @author Adrian Cole
*/
@Singleton
public class OrgAndVDCToLocationSupplier implements Supplier<Set<? extends Location>> {
private final String providerName;
public class OrgAndVDCToLocationSupplier extends JustProvider {
private final Supplier<Map<String, ReferenceType>> orgNameToResource;
private final Supplier<Map<String, ? extends Org>> orgNameToVDCResource;
private final Map<String, Set<String>> isoCodesById;
@Inject
OrgAndVDCToLocationSupplier(@org.jclouds.location.Provider String providerName,
OrgAndVDCToLocationSupplier(@Iso3166 Set<String> isoCodes, @Provider String providerName, @Provider URI endpoint,
@org.jclouds.vcloud.endpoints.Org Supplier<Map<String, ReferenceType>> orgNameToResource,
Supplier<Map<String, ? extends Org>> orgNameToVDCResource) {
this.providerName = providerName;
this.orgNameToResource = orgNameToResource;
this.orgNameToVDCResource = orgNameToVDCResource;
Supplier<Map<String, ? extends Org>> orgNameToVDCResource, @Iso3166 Map<String, Set<String>> isoCodesById) {
super(isoCodes, providerName, endpoint);
this.orgNameToResource = checkNotNull(orgNameToResource, "orgNameToResource");
this.orgNameToVDCResource = checkNotNull(orgNameToVDCResource, "orgNameToVDCResource");
this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById");
}
@Override
public Set<? extends Location> get() {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Set<Location> locations = Sets.newLinkedHashSet();
return buildJustProviderOrVDCs().build();
}
protected Builder<Location> buildJustProviderOrVDCs() {
Builder<Location> locations = ImmutableSet.builder();
Location provider = Iterables.getOnlyElement(super.get());
if (orgNameToResource.get().size() == 0)
return locations.add(provider);
else
for (ReferenceType org : orgNameToResource.get().values()) {
Location orgL = new LocationImpl(LocationScope.REGION, org.getHref().toASCIIString(), org.getName(), provider);
LocationBuilder builder = new LocationBuilder().scope(LocationScope.REGION).id(
org.getHref().toASCIIString()).description((org.getName())).parent(provider);
if (isoCodesById.containsKey(org.getHref().toASCIIString()))
builder.iso3166Codes(isoCodesById.get(org.getHref().toASCIIString()));
Location orgL = builder.build();
for (ReferenceType vdc : orgNameToVDCResource.get().get(org.getName()).getVDCs().values()) {
locations.add(new LocationImpl(LocationScope.ZONE, vdc.getHref().toASCIIString(), vdc.getName(), orgL));
builder = new LocationBuilder().scope(LocationScope.ZONE).id(vdc.getHref().toASCIIString()).description(
(vdc.getName())).parent(orgL);
if (isoCodesById.containsKey(vdc.getHref().toASCIIString()))
builder.iso3166Codes(isoCodesById.get(vdc.getHref().toASCIIString()));
locations.add(builder.build());
}
}
return locations;
}
}

View File

@ -60,8 +60,7 @@ public class VCloudLoginAsyncClientTest extends RestClientTest<VCloudLoginAsyncC
HttpRequest request = processor.createRequest(method);
assertEquals(request.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1");
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
+ ": application/vnd.vmware.vcloud.orgList+xml\n");
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": application/vnd.vmware.vcloud.orgList+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseLoginResponseFromHeaders.class);
@ -100,16 +99,16 @@ public class VCloudLoginAsyncClientTest extends RestClientTest<VCloudLoginAsyncC
};
}
@Timeout(duration = 10, timeUnit = TimeUnit.SECONDS)
public interface VCloudLoginClient {
VCloudSession login();
}
@Override
public RestContextSpec<VCloudLoginClient, VCloudLoginAsyncClient> createContextSpec() {
return contextSpec("test", "http://localhost:8080/login", "1", "identity", "credential", VCloudLoginClient.class,
VCloudLoginAsyncClient.class);
return contextSpec("test", "http://localhost:8080/login", "1", "", "identity", "credential",
VCloudLoginClient.class, VCloudLoginAsyncClient.class);
}
}

View File

@ -39,7 +39,6 @@ import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VCloudVersionsAsyncClient}
*
@ -83,8 +82,8 @@ public class VCloudVersionsAsyncClientTest extends RestClientTest<VCloudVersions
@Override
public RestContextSpec<VCloudVersionsClient, VCloudVersionsAsyncClient> createContextSpec() {
return contextSpec("test", "http://localhost:8080", "1", "identity", "credential", VCloudVersionsClient.class,
VCloudVersionsAsyncClient.class);
return contextSpec("test", "http://localhost:8080", "1", "", "identity", "credential",
VCloudVersionsClient.class, VCloudVersionsAsyncClient.class);
}
}

View File

@ -65,7 +65,7 @@
(.createContext (ComputeServiceContextFactory.) spec))
(^RestContextSpec defn context-spec [^StandaloneComputeServiceContextModule module]
(StandaloneComputeServiceContextSpec. "servermanager", "http://host", "1", "identity", "credential", module, (ImmutableSet/of)))
(StandaloneComputeServiceContextSpec. "servermanager", "http://host", "1", "", "identity", "credential", module, (ImmutableSet/of)))
(defrecord NodeListComputeService
[node-list]

View File

@ -29,25 +29,26 @@ import com.google.inject.Module;
* @author Adrian Cole
*/
public class StandaloneComputeServiceContextSpec<D, N, H, I, L> extends RestContextSpec<D, D> {
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String identity,
String credential, Class<D> driverClass,
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String iso3166Codes,
String identity, String credential, Class<D> driverClass,
Class<? extends StandaloneComputeServiceContextBuilder<D>> contextBuilderClass) {
this(provider, endpoint, apiVersion, identity, credential, driverClass, contextBuilderClass, ImmutableSet
.<Module> of());
this(provider, endpoint, apiVersion, iso3166Codes, identity, credential, driverClass, contextBuilderClass,
ImmutableSet.<Module> of());
}
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String identity,
String credential, Class<D> driverClass,
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String iso3166Codes,
String identity, String credential, Class<D> driverClass,
Class<? extends StandaloneComputeServiceContextBuilder<D>> contextBuilderClass, Iterable<Module> modules) {
this(provider, endpoint, apiVersion, identity, credential, driverClass, PropertiesBuilder.class,
this(provider, endpoint, apiVersion, iso3166Codes, identity, credential, driverClass, PropertiesBuilder.class,
contextBuilderClass, modules);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String identity,
String credential, Class<D> driverClass, Class<? extends PropertiesBuilder> propertiesBuilderClass,
@SuppressWarnings( { "unchecked", "rawtypes" })
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String iso3166Codes,
String identity, String credential, Class<D> driverClass,
Class<? extends PropertiesBuilder> propertiesBuilderClass,
Class<? extends StandaloneComputeServiceContextBuilder<D>> contextBuilderClass, Iterable<Module> modules) {
super(provider, endpoint, apiVersion, identity, credential, driverClass, driverClass,
super(provider, endpoint, apiVersion, iso3166Codes, identity, credential, driverClass, driverClass,
(Class) propertiesBuilderClass, (Class) contextBuilderClass, modules);
}
}

View File

@ -49,8 +49,8 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
import org.jclouds.domain.Location;
import org.jclouds.json.Json;
import org.jclouds.location.config.LocationModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.scriptbuilder.domain.Statement;
@ -76,6 +76,7 @@ import com.google.inject.name.Names;
public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Override
protected void configure() {
install(new LocationModule(authException));
install(new ComputeServiceTimeoutsModule());
bind(new TypeLiteral<Function<NodeMetadata, SshClient>>() {
}).to(CreateSshClientOncePortIsListeningOnNode.class);
@ -127,9 +128,9 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
checkNotNull(node, "node");
checkNotNull(runScript, "runScript");
checkNotNull(options, "options");
return !options.shouldWrapInInitScript() ? factory.exec(node, runScript, options)
: (options.shouldBlockOnComplete() ? factory.backgroundAndBlockOnComplete(node, runScript, options)
: factory.background(node, runScript, options));
return !options.shouldWrapInInitScript() ? factory.exec(node, runScript, options) : (options
.shouldBlockOnComplete() ? factory.backgroundAndBlockOnComplete(node, runScript, options) : factory
.background(node, runScript, options));
}
@Override
@ -206,41 +207,6 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
});
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Location>> provideLocationMap(
@Memoized Supplier<Set<? extends Location>> locations) {
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, ? extends Location>>() {
@Override
public Map<String, ? extends Location> apply(Set<? extends Location> from) {
return Maps.uniqueIndex(from, new Function<Location, String>() {
@Override
public String apply(Location from) {
return from.getId();
}
});
}
}, locations);
}
@Provides
@Singleton
@Memoized
protected Supplier<Set<? extends Location>> supplyLocationCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Location>> locationSupplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Location>>(authException, seconds,
new Supplier<Set<? extends Location>>() {
@Override
public Set<? extends Location> get() {
return locationSupplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(@Memoized Supplier<Set<? extends Hardware>> sizes) {

View File

@ -19,14 +19,11 @@
package org.jclouds.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Sets.newHashSet;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.collect.TransformingSetSupplier;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Hardware;
@ -41,7 +38,6 @@ import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.compute.strategy.impl.AdaptingComputeServiceStrategies;
import org.jclouds.domain.Location;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@ -64,30 +60,28 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
this.asyncClientType = asyncClientType;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings( { "unchecked", "rawtypes" })
@Override
protected void configure() {
super.configure();
bindDefaultLocation();
bind(new TypeLiteral<ComputeServiceContext>() {
}).to((TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class, syncClientType,
asyncClientType))).in(Scopes.SINGLETON);
}).to(
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class,
syncClientType, asyncClientType))).in(Scopes.SINGLETON);
}
public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>> {
private final Supplier<Iterable<F>> backingSupplier;
private final Function<F, T> converter;
public TransformingSetSupplier(Supplier<Iterable<F>> backingSupplier, Function<F, T> converter) {
this.backingSupplier = checkNotNull(backingSupplier, "backingSupplier");
this.converter = checkNotNull(converter, "converter");
}
@Provides
@Singleton
protected Supplier<Set<? extends Location>> provideLocations(final ComputeServiceAdapter<N, H, I, L> adapter,
Function<L, Location> transformer) {
return new TransformingSetSupplier<L, Location>(new Supplier<Iterable<L>>() {
@Override
public Set<? extends T> get() {
return newHashSet(transform(backingSupplier.get(), converter));
public Iterable<L> get() {
return adapter.listLocations();
}
}, transformer);
}
@Provides
@ -118,25 +112,6 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
}, transformer);
}
protected void bindDefaultLocation() {
bind(new TypeLiteral<Supplier<Location>>() {
}).to(OnlyLocationOrFirstZone.class);
}
@Provides
@Singleton
protected Supplier<Set<? extends Location>> provideLocations(final ComputeServiceAdapter<N, H, I, L> adapter,
Function<L, Location> transformer) {
return new TransformingSetSupplier<L, Location>(new Supplier<Iterable<L>>() {
@Override
public Iterable<L> get() {
return adapter.listLocations();
}
}, transformer);
}
@Provides
@Singleton
protected AddNodeWithTagStrategy defineAddNodeWithTagStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {

View File

@ -155,4 +155,5 @@ public interface TemplateBuilder {
* options such as inbound ports and run scripts.
*/
TemplateBuilder options(TemplateOptions options);
}

View File

@ -140,7 +140,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
boolean returnVal = true;
if (location != null && input.getLocation() != null)
returnVal = location.equals(input.getLocation()) || location.getParent() != null
&& location.getParent().equals(input.getLocation());
&& location.getParent().equals(input.getLocation()) || location.getParent().getParent() != null
&& location.getParent().getParent().equals(input.getLocation());
return returnVal;
}
@ -497,7 +498,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
*/
@Override
public TemplateBuilder locationId(final String locationId) {
this.location = Iterables.find(locations.get(), new Predicate<Location>() {
Set<? extends Location> locations = this.locations.get();
try {
this.location = Iterables.find(locations, new Predicate<Location>() {
@Override
public boolean apply(Location input) {
@ -510,6 +513,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
});
} catch (NoSuchElementException e) {
throw new NoSuchElementException(String.format("location id %s not found in: %s", locationId, locations));
}
return this;
}

View File

@ -20,8 +20,8 @@
package org.jclouds.compute.stub.config;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject;
@ -41,8 +41,7 @@ import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.rest.ResourceNotFoundException;
import com.google.common.base.Supplier;
@ -62,21 +61,21 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
private final String publicIpPrefix;
private final String privateIpPrefix;
private final String passwordPrefix;
private final String providerName;
private final Supplier<Set<? extends Location>> locationSupplier;
private final Map<OsFamily, Map<String, String>> osToVersionMap;
@Inject
public StubComputeServiceAdapter(ConcurrentMap<String, NodeMetadata> nodes, Supplier<Location> location,
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix,
@org.jclouds.location.Provider String providerName, Map<OsFamily, Map<String, String>> osToVersionMap) {
JustProvider locationSupplier, Map<OsFamily, Map<String, String>> osToVersionMap) {
this.nodes = nodes;
this.location = location;
this.idProvider = idProvider;
this.publicIpPrefix = publicIpPrefix;
this.privateIpPrefix = privateIpPrefix;
this.passwordPrefix = passwordPrefix;
this.providerName = providerName;
this.locationSupplier = locationSupplier;
this.osToVersionMap = osToVersionMap;
}
@ -105,23 +104,20 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
@Override
public Iterable<Hardware> listHardwareProfiles() {
return ImmutableSet.<Hardware> of(StubComputeServiceDependenciesModule.stub("small", 1, 1740, 160),
StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850),
StubComputeServiceDependenciesModule.stub("large", 8, 15360, 1690));
StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850), StubComputeServiceDependenciesModule
.stub("large", 8, 15360, 1690));
}
@Override
public Iterable<Image> listImages() {
Location zone = location.get().getParent();
String parentId = zone.getId();
Credentials defaultCredentials = new Credentials("root", null);
Set<Image> images = Sets.newLinkedHashSet();
int id = 1;
for (boolean is64Bit : new boolean[] { true, false })
for (Entry<OsFamily, Map<String, String>> osVersions : this.osToVersionMap.entrySet()) {
for (String version : Sets.newHashSet(osVersions.getValue().values())) {
for (String version : Sets.newLinkedHashSet(osVersions.getValue().values())) {
String desc = String.format("stub %s %s", osVersions.getKey(), is64Bit);
images.add(new ImageBuilder().providerId(id + "").name(osVersions.getKey().name())
.id(parentId + "/" + id++).location(zone)
images.add(new ImageBuilder().ids(id++ + "").name(osVersions.getKey().name()).location(location.get())
.operatingSystem(new OperatingSystem(osVersions.getKey(), desc, version, null, desc, is64Bit))
.description(desc).defaultCredentials(defaultCredentials).build());
}
@ -134,13 +130,10 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
return nodes.values();
}
@SuppressWarnings("unchecked")
@Override
public Iterable<Location> listLocations() {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region",
provider);
return ImmutableSet.<Location> of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName
+ "zone", region));
return (Iterable<Location>) locationSupplier.get();
}
@Override

View File

@ -26,8 +26,12 @@ import javax.inject.Singleton;
import org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.concurrent.SingleThreaded;
import org.jclouds.domain.Location;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
import com.google.common.base.Supplier;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
*
@ -51,6 +55,8 @@ public class StubComputeServiceContextModule extends
@Override
protected void configure() {
install(new StubComputeServiceDependenciesModule());
bind(new TypeLiteral<Supplier<Location>>() {
}).to(OnlyLocationOrFirstZone.class);
super.configure();
}
}

View File

@ -39,6 +39,8 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
@ -174,6 +176,53 @@ public abstract class BaseTemplateBuilderLiveTest {
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
protected abstract Set<String> getIso3166Codes();
@Test(groups = { "integration", "live" })
public void testGetAssignableLocations() throws Exception {
assertProvider(context.getProviderSpecificContext());
for (Location location : context.getComputeService().listAssignableLocations()) {
System.err.printf("location %s%n", location);
assert location.getId() != null : location;
assert location != location.getParent() : location;
assert location.getScope() != null : location;
switch (location.getScope()) {
case PROVIDER:
assertProvider(location);
break;
case REGION:
assertProvider(location.getParent());
assert location.getIso3166Codes().size() == 0
|| location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location
+ " ||" + location.getParent();
break;
case ZONE:
Location provider = location.getParent().getParent();
// zone can be a direct descendant of provider
if (provider == null)
provider = location.getParent();
assertProvider(provider);
assert location.getIso3166Codes().size() == 0
|| location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location
+ " ||" + location.getParent();
break;
case HOST:
Location provider2 = location.getParent().getParent().getParent();
// zone can be a direct descendant of provider
if (provider2 == null)
provider2 = location.getParent().getParent();
assertProvider(provider2);
break;
}
}
}
void assertProvider(Location provider) {
assertEquals(provider.getScope(), LocationScope.PROVIDER);
assertEquals(provider.getParent(), null);
assertEquals(provider.getIso3166Codes(), getIso3166Codes());
}
@AfterTest
protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
context.close();

View File

@ -44,7 +44,7 @@ public class ComputeServiceContextFactoryTest {
@SuppressWarnings("rawtypes")
ComputeServiceContext context = new ComputeServiceContextFactory()
.createContext(new StandaloneComputeServiceContextSpec<ConcurrentMap, NodeMetadata, Hardware, Image, Location>(
"stub", "stub", "1", "identity", "credential", ConcurrentMap.class,
"stub", "stub", "1", "", "identity", "credential", ConcurrentMap.class,
StubComputeServiceContextBuilder.class, ImmutableSet.<Module> of()));
context.getComputeService().listNodes();

View File

@ -19,8 +19,12 @@
package org.jclouds.compute;
import java.util.Set;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
*
*
@ -38,4 +42,9 @@ public class StubTemplateBuilderIntegrationTest extends BaseTemplateBuilderLiveT
identity = "stub";
credential = "stub";
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of();
}
}

View File

@ -19,6 +19,9 @@
package org.jclouds;
import org.jclouds.domain.Location;
import org.jclouds.location.reference.LocationConstants;
/**
* Constants used in jclouds services.
*
@ -194,6 +197,7 @@ public interface Constants {
* api.
*/
public static final String PROPERTY_ENDPOINT = "jclouds.endpoint";
/**
* String property.
* <p/>
@ -201,6 +205,15 @@ public interface Constants {
*/
public static final String PROPERTY_IDENTITY = "jclouds.identity";
/**
* String property. default("")
* <p/>
* comma-delimited iso 3166 codes; ex. US-CA,US
*
* @see Location#getIso3166Codes
*/
public static final String PROPERTY_ISO3166_CODES = "jclouds." + LocationConstants.ISO3166_CODES;
/**
* String property.
* <p/>

View File

@ -25,6 +25,7 @@ import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT;
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST;
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTION_REUSE;
@ -48,6 +49,7 @@ import java.util.Properties;
import javax.annotation.Nullable;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
/**
* Builds properties used in Http engines
@ -201,6 +203,7 @@ public class PropertiesBuilder {
protected Properties defaultProperties() {
Properties props = new Properties();
props.setProperty(PROPERTY_ISO3166_CODES, "");
props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + "");
props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + "");
props.setProperty(PROPERTY_SO_TIMEOUT, 60000 + "");
@ -228,6 +231,11 @@ public class PropertiesBuilder {
return this;
}
public PropertiesBuilder iso3166Codes(Iterable<String> codes) {
properties.setProperty(PROPERTY_ISO3166_CODES, Joiner.on(',').join(codes));
return this;
}
public PropertiesBuilder apiVersion(String apiVersion) {
properties.setProperty(PROPERTY_API_VERSION, apiVersion);
return this;

View File

@ -21,7 +21,7 @@ package org.jclouds.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Sets.newHashSet;
import static com.google.common.collect.Sets.newLinkedHashSet;
import java.util.Set;
@ -43,7 +43,7 @@ public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>>
@Override
public Set<? extends T> get() {
return newHashSet(transform(backingSupplier.get(), converter));
return newLinkedHashSet(transform(backingSupplier.get(), converter));
}
}

View File

@ -19,15 +19,18 @@
package org.jclouds.domain;
import java.util.Map;
import java.util.Set;
/**
* Running Operating system
* Description of where a resource is running. Note this can be physical or virtual.
*
* @author Adrian Cole
*/
public interface Location {
/**
* Scope of the location, ex. region, datacenter
* Scope of the location, ex. region, zone, host
*
*/
LocationScope getScope();
@ -48,4 +51,16 @@ public interface Location {
*/
Location getParent();
/**
* @return immutable set of metadata relating to this location
*/
Map<String, Object> getMetadata();
/**
* @return if known, the IS0 3166 or 3166-2 divisions where this service may run. ex. a set of
* strings like "US" or "US-CA"; otherwise returns an empty list.
* @see <a
* href="http://www.iso.org/iso/country_codes/background_on_iso_3166/what_is_iso_3166.htm">3166</a>
*/
Set<String> getIso3166Codes();
}

View File

@ -0,0 +1,77 @@
/**
*
* 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.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.Set;
import org.jclouds.domain.internal.LocationImpl;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class LocationBuilder {
protected LocationScope scope;
protected String id;
protected String description;
protected Location parent;
protected Set<String> iso3166Codes = ImmutableSet.of();
protected Map<String, Object> metadata = ImmutableMap.of();
public LocationBuilder scope(LocationScope scope) {
this.scope = scope;
return this;
}
public LocationBuilder id(String id) {
this.id = id;
return this;
}
public LocationBuilder description(String description) {
this.description = description;
return this;
}
public LocationBuilder parent(Location parent) {
this.parent = parent;
return this;
}
public LocationBuilder iso3166Codes(Iterable<String> iso3166Codes) {
this.iso3166Codes = ImmutableSet.copyOf(checkNotNull(iso3166Codes, "iso3166Codes"));
return this;
}
public LocationBuilder metadata(Map<String, Object> metadata) {
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return this;
}
public Location build() {
return new LocationImpl(scope, id, description, parent, iso3166Codes, metadata);
}
}

View File

@ -22,19 +22,22 @@ package org.jclouds.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* Idpayload of the object
*
* @author Adrian Cole
*/
public class LocationImpl implements Location, Serializable {
/** The serialVersionUID */
private static final long serialVersionUID = -280558162576368264L;
@ -42,36 +45,75 @@ public class LocationImpl implements Location, Serializable {
private final String id;
private final String description;
private final Location parent;
private final Set<String> iso3166Codes;
private final Map<String, Object> metadata;
public LocationImpl(LocationScope scope, String id, String description, @Nullable Location parent) {
public LocationImpl(LocationScope scope, String id, String description, @Nullable Location parent,
Iterable<String> iso3166Codes, Map<String, Object> metadata) {
this.scope = checkNotNull(scope, "scope");
this.id = checkNotNull(id, "id");
this.description = checkNotNull(description, "description");
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
this.iso3166Codes = ImmutableSet.copyOf(checkNotNull(iso3166Codes, "iso3166Codes"));
this.parent = parent;
}
/**
* {@inheritDoc}
*/
@Override
public LocationScope getScope() {
return scope;
}
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return id;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public Location getParent() {
return parent;
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getIso3166Codes() {
return iso3166Codes;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, Object> getMetadata() {
return metadata;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((iso3166Codes == null) ? 0 : iso3166Codes.hashCode());
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
result = prime * result + ((parent == null) ? 0 : parent.hashCode());
result = prime * result + ((scope == null) ? 0 : scope.hashCode());
return result;
@ -96,6 +138,16 @@ public class LocationImpl implements Location, Serializable {
return false;
} else if (!id.equals(other.id))
return false;
if (iso3166Codes == null) {
if (other.iso3166Codes != null)
return false;
} else if (!iso3166Codes.equals(other.iso3166Codes))
return false;
if (metadata == null) {
if (other.metadata != null)
return false;
} else if (!metadata.equals(other.metadata))
return false;
if (parent == null) {
if (other.parent != null)
return false;
@ -112,7 +164,8 @@ public class LocationImpl implements Location, Serializable {
@Override
public String toString() {
return "[id=" + id + ", scope=" + scope + ", description=" + description + ", parent="
+ ((parent == null) ? null : parent.getId()) + "]";
+ ((parent == null) ? null : parent.getId()) + ", iso3166Codes=" + iso3166Codes + ", metadata="
+ metadata + "]";
}
}

View File

@ -17,26 +17,24 @@
* ====================================================================
*/
package org.jclouds.libvirt.compute.functions;
package org.jclouds.location;
import javax.inject.Singleton;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.libvirt.Datacenter;
import com.google.common.base.Function;
import javax.inject.Qualifier;
/**
* Related to a Iso3166 code
*
* @author Adrian Cole
*
*/
@Singleton
public class DatacenterToLocation implements Function<Datacenter, Location> {
@Override
public Location apply(Datacenter from) {
return new LocationImpl(LocationScope.ZONE, from.id + "", from.name, null);
}
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Iso3166 {
}

View File

@ -17,26 +17,40 @@
* ====================================================================
*/
package org.jclouds.libvirt.compute.functions;
package org.jclouds.location.config;
import javax.inject.Singleton;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
import org.jclouds.rest.AuthorizationException;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class LibvirtNodeToLocation implements Function<Datacenter, Location> {
public class JustProviderLocationModule extends LocationModule {
public JustProviderLocationModule() {
super();
}
public JustProviderLocationModule(AtomicReference<AuthorizationException> authException) {
super(authException);
}
@Override
public Location apply(Datacenter from) {
return new LocationImpl(LocationScope.ZONE, from.id + "", from.name, null);
protected void configure() {
bind(new TypeLiteral<Supplier<Set<? extends Location>>>() {
}).to(JustProvider.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(OnlyLocationOrFirstZone.class);
super.configure();
}
}

View File

@ -0,0 +1,96 @@
/**
*
* 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.location.config;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
*
* @author Adrian Cole
*/
public class LocationModule extends AbstractModule {
protected final AtomicReference<AuthorizationException> authException;
public LocationModule() {
this(new AtomicReference<AuthorizationException>());
}
public LocationModule(AtomicReference<AuthorizationException> authException) {
this.authException = authException;
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Location>> provideLocationMap(
@Memoized Supplier<Set<? extends Location>> locations) {
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, ? extends Location>>() {
@Override
public Map<String, ? extends Location> apply(Set<? extends Location> from) {
return Maps.uniqueIndex(from, new Function<Location, String>() {
@Override
public String apply(Location from) {
return from.getId();
}
});
}
}, locations);
}
@Provides
@Singleton
@Memoized
protected Supplier<Set<? extends Location>> supplyLocationCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Location>> locationSupplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Location>>(authException, seconds,
new Supplier<Set<? extends Location>>() {
@Override
public Set<? extends Location> get() {
return locationSupplier.get();
}
});
}
@Override
protected void configure() {
}
}

View File

@ -0,0 +1,86 @@
/**
*
* 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.location.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.inject.name.Names.named;
import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_ZONE;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.location.Iso3166;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.ConfigurationException;
import com.google.inject.Injector;
import com.google.inject.Key;
/**
*
* looks for properties bound to the naming conventions jclouds.region.{@code regionId}
* .iso3166-codes and jclouds.zone.{@code zoneId}.iso3166-codes
*
* @author Adrian Cole
*/
@Singleton
public class ProvideIso3166CodesByLocationIdViaProperties implements javax.inject.Provider<Map<String, Set<String>>> {
private final Injector injector;
@Inject
ProvideIso3166CodesByLocationIdViaProperties(Injector injector) {
this.injector = checkNotNull(injector, "injector");
}
@Singleton
@Iso3166
@Override
public Map<String, Set<String>> get() {
Builder<String, Set<String>> codes = ImmutableMap.<String, Set<String>> builder();
for (String key : ImmutableSet.of(PROPERTY_REGION, PROPERTY_ZONE))
try {
String regionString = injector.getInstance(Key.get(String.class, named(key + "s")));
for (String region : Splitter.on(',').split(regionString)) {
try {
codes.put(region, ImmutableSet.copyOf(Splitter.on(',')
.split(
injector.getInstance(Key.get(String.class, named(key + "." + region + "."
+ ISO3166_CODES))))));
} catch (ConfigurationException e) {
// this happens if regions property isn't set
// services not run by AWS may not have regions, so this is ok.
}
}
} catch (ConfigurationException e) {
// this happens if regions property isn't set
// services not run by AWS may not have regions, so this is ok.
}
return codes.build();
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.location.config;
import static org.jclouds.location.reference.LocationConstants.ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
@ -28,7 +29,6 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.location.Provider;
import org.jclouds.location.Region;
import com.google.common.base.Splitter;
@ -41,7 +41,7 @@ import com.google.inject.name.Names;
/**
*
* looks for properties bound to the naming convention jclouds.location.region.{@code regionId}.endpoint
* looks for properties bound to the naming convention jclouds.region.{@code regionId}.endpoint
*
* @author Adrian Cole
*/
@ -63,17 +63,14 @@ public class ProvideRegionToURIViaProperties implements javax.inject.Provider<Ma
String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS)));
Builder<String, URI> regions = ImmutableMap.<String, URI> builder();
for (String region : Splitter.on(',').split(regionString)) {
regions.put(
region,
URI.create(injector.getInstance(Key.get(String.class,
Names.named(PROPERTY_REGION + "." + region + ".endpoint")))));
regions.put(region, URI.create(injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGION + "."
+ region + "." + ENDPOINT)))));
}
return regions.build();
} catch (ConfigurationException e) {
// this happens if regions property isn't set
// services not run by AWS may not have regions, so this is ok.
return ImmutableMap.of(injector.getInstance(Key.get(String.class, Provider.class)),
injector.getInstance(Key.get(URI.class, Provider.class)));
return ImmutableMap.of();
}
}

View File

@ -19,38 +19,29 @@
package org.jclouds.location.config;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZoneOrRegionMatchingRegionId;
import org.jclouds.location.suppliers.RegionToProviderOrJustProvider;
import org.jclouds.location.Region;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.base.Supplier;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class ProvideRegionsViaProperties implements javax.inject.Provider<Set<String>> {
public class RegionsLocationModule extends LocationModule {
private final Set<String> regions;
@Inject
ProvideRegionsViaProperties(@Named(PROPERTY_REGIONS) String regions) {
this.regions = ImmutableSet.copyOf(Splitter.on(',').split(regions));
}
@Singleton
@Region
@Override
public Set<String> get() {
return regions;
protected void configure() {
bind(new TypeLiteral<Supplier<Set<? extends Location>>>() {
}).to(RegionToProviderOrJustProvider.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(OnlyLocationOrFirstZoneOrRegionMatchingRegionId.class);
super.configure();
}
}

View File

@ -24,6 +24,10 @@ package org.jclouds.location.reference;
* @author Adrian Cole
*/
public interface LocationConstants {
public static final String PROPERTY_REGIONS = "jclouds.location.regions";
public static final String PROPERTY_REGION = "jclouds.location.region";
public static final String ENDPOINT = "endpoint";
public static final String ISO3166_CODES = "iso3166-codes";
public static final String PROPERTY_REGIONS = "jclouds.regions";
public static final String PROPERTY_REGION = "jclouds.region";
public static final String PROPERTY_ZONES = "jclouds.zones";
public static final String PROPERTY_ZONE = "jclouds.zone";
}

View File

@ -19,6 +19,8 @@
package org.jclouds.location.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
@ -26,39 +28,35 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.location.Region;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SupplyPredefinedRegions implements Supplier<Set<? extends Location>> {
private final Set<String> regions;
public class JustProvider implements Supplier<Set<? extends Location>> {
private final String providerName;
private final URI endpoint;
private final Set<String> isoCodes;
@Inject
SupplyPredefinedRegions(@Region Set<String> regions, @Provider String providerName, @Provider URI endpoint) {
this.regions = regions;
this.providerName = providerName;
this.endpoint = endpoint;
public JustProvider(@Iso3166 Set<String> isoCodes, @Provider String providerName, @Provider URI endpoint) {
this.providerName = checkNotNull(providerName, "providerName");
this.endpoint = checkNotNull(endpoint, "endpoint");
this.isoCodes = checkNotNull(isoCodes, "isoCodes");
}
@Override
public Set<? extends Location> get() {
Builder<Location> locations = ImmutableSet.builder();
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, endpoint.toASCIIString(), null);
for (String zone : regions) {
locations.add(new LocationImpl(LocationScope.REGION, zone.toString(), zone.toString(), provider));
}
return locations.build();
return ImmutableSet.of(new LocationBuilder().scope(LocationScope.PROVIDER).id(providerName).description(
endpoint.toASCIIString()).iso3166Codes(isoCodes).build());
}
}

View File

@ -36,6 +36,8 @@ import org.jclouds.location.Region;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.inject.Injector;
import com.google.inject.Key;
/**
* @author Adrian Cole
@ -70,13 +72,13 @@ public class OnlyLocationOrFirstZoneOrRegionMatchingRegionId implements Supplier
}
}
private final IsRegionAndIdEqualsOrIsZoneParentIdEquals matcher;
private final Injector injector;
private final Supplier<Set<? extends Location>> locationsSupplier;
@Inject
OnlyLocationOrFirstZoneOrRegionMatchingRegionId(IsRegionAndIdEqualsOrIsZoneParentIdEquals matcher,
OnlyLocationOrFirstZoneOrRegionMatchingRegionId(Injector injector,
@Memoized Supplier<Set<? extends Location>> locationsSupplier) {
this.matcher = checkNotNull(matcher, "matcher");
this.injector = checkNotNull(injector, "injector");
this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplier");
}
@ -86,7 +88,12 @@ public class OnlyLocationOrFirstZoneOrRegionMatchingRegionId implements Supplier
Set<? extends Location> locations = locationsSupplier.get();
if (locationsSupplier.get().size() == 1)
return getOnlyElement(locationsSupplier.get());
IsRegionAndIdEqualsOrIsZoneParentIdEquals matcher = null;
try {
String region = injector.getInstance(Key.get(String.class, Region.class));
if (region == null)
return Iterables.get(locationsSupplier.get(), 0);
matcher = injector.getInstance(IsRegionAndIdEqualsOrIsZoneParentIdEquals.class);
Location toReturn = Iterables.find(locations, matcher);
return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent();
} catch (NoSuchElementException e) {

View File

@ -21,50 +21,60 @@ package org.jclouds.location.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.location.Region;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.ImmutableSet.Builder;
/**
*
* @author Adrian Cole
*/
@Singleton
public class RegionToProviderOrJustProvider implements Supplier<Set<? extends Location>> {
public class RegionToProviderOrJustProvider extends JustProvider {
private final Set<String> regions;
private final String providerName;
private final Map<String, Set<String>> isoCodesById;
@Inject
RegionToProviderOrJustProvider(@Region Set<String> regions, @Provider String providerName) {
public RegionToProviderOrJustProvider(@Iso3166 Set<String> isoCodes, @Provider String providerName,
@Provider URI endpoint, @Region Set<String> regions, @Iso3166 Map<String, Set<String>> isoCodesById) {
super(isoCodes, providerName, endpoint);
this.regions = checkNotNull(regions, "regions");
this.providerName = checkNotNull(providerName, "providerName");
this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById");
}
@Override
public Set<? extends Location> get() {
final Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
if (regions.size() == 0)
return ImmutableSet.of(provider);
return ImmutableSet.<Location> copyOf(Iterables.transform(regions, new Function<String, Location>() {
@Override
public Location apply(String input) {
return new LocationImpl(LocationScope.REGION, input, input, provider);
return buildJustProviderOrRegions().build();
}
}));
protected Builder<Location> buildJustProviderOrRegions() {
Builder<Location> locations = ImmutableSet.builder();
Location provider = Iterables.getOnlyElement(super.get());
if (regions.size() == 0)
return locations.add(provider);
else
for (String region : regions) {
LocationBuilder builder = new LocationBuilder().scope(LocationScope.REGION).id(region).description(region)
.parent(provider);
if (isoCodesById.containsKey(region))
builder.iso3166Codes(isoCodesById.get(region));
locations.add(builder.build());
}
return locations;
}
}

View File

@ -21,8 +21,8 @@ package org.jclouds.location.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Maps.uniqueIndex;
import static com.google.common.collect.Sets.newLinkedHashSet;
import java.net.URI;
import java.util.Map;
import java.util.Set;
@ -30,50 +30,61 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.location.Zone;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ZoneToRegionToProviderOrJustProvider implements Supplier<Set<? extends Location>> {
public class ZoneToRegionToProviderOrJustProvider extends RegionToProviderOrJustProvider {
private final Map<String, String> zoneToRegion;
private final String providerName;
private Map<String, Set<String>> isoCodesById;
@Inject
ZoneToRegionToProviderOrJustProvider(@Zone Map<String, String> zoneToRegion, @Provider String providerName) {
this.zoneToRegion = checkNotNull(zoneToRegion, "zoneToRegion");
this.providerName = checkNotNull(providerName, "providerName");
ZoneToRegionToProviderOrJustProvider(@Iso3166 Set<String> isoCodes, @Provider String providerName,
@Provider URI endpoint, @Iso3166 Map<String, Set<String>> isoCodesById,
@Zone Map<String, String> zoneToRegion) {
super(isoCodes, providerName, endpoint, ImmutableSet.copyOf(checkNotNull(zoneToRegion, "zoneToRegion").values()),
isoCodesById);
this.zoneToRegion = zoneToRegion;
this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById");
}
@Override
public Set<? extends Location> get() {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
if (zoneToRegion.size() == 0)
return ImmutableSet.of(provider);
Set<Location> providers = newLinkedHashSet();
for (String region : newLinkedHashSet(zoneToRegion.values())) {
providers.add(new LocationImpl(LocationScope.REGION, region, region, provider));
}
ImmutableMap<String, Location> idToLocation = uniqueIndex(providers, new Function<Location, String>() {
Builder<Location> locations = buildJustProviderOrRegions();
ImmutableMap<String, Location> idToLocation = uniqueIndex(locations.build(), new Function<Location, String>() {
@Override
public String apply(Location from) {
return from.getId();
}
});
if (zoneToRegion.size() == 1)
return locations.build();
for (String zone : zoneToRegion.keySet()) {
providers.add(new LocationImpl(LocationScope.ZONE, zone, zone, idToLocation.get(zoneToRegion.get(zone))));
Location parent = idToLocation.get(zoneToRegion.get(zone));
LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(zone).description(zone).parent(
parent);
if (isoCodesById.containsKey(zone))
builder.iso3166Codes(isoCodesById.get(zone));
// be cautious.. only inherit iso codes if the parent is a region
// regions may be added dynamically, and we prefer to inherit an
// empty set of codes from a region, then a provider, whose code
// are likely hard-coded.
else if (parent.getScope() == LocationScope.REGION)
builder.iso3166Codes(parent.getIso3166Codes());
locations.add(builder.build());
}
return providers;
return locations.build();
}
}

View File

@ -24,6 +24,7 @@ import java.util.Map;
import java.util.concurrent.Future;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.common.annotations.Beta;
@ -40,7 +41,7 @@ import com.google.inject.ImplementedBy;
*
*/
@ImplementedBy(RestContextImpl.class)
public interface RestContext<S, A> {
public interface RestContext<S, A> extends Location {
/**
* low-level api to the cloud. Threadsafe implementations will return a singleton.
@ -59,6 +60,10 @@ public interface RestContext<S, A> {
URI getEndpoint();
String getApiVersion();
String getIdentity();
/**
* retrieves a list of credentials for resources created within this context, keyed on {@code id}
* of the resource. We are testing this approach for resources such as compute nodes, where you
@ -71,12 +76,6 @@ public interface RestContext<S, A> {
@Beta
Map<String, Credentials> credentialStore();
String getIdentity();
String getProvider();
String getApiVersion();
Utils getUtils();
/**

View File

@ -20,17 +20,30 @@
package org.jclouds.rest;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.not;
import static com.google.common.base.Splitter.on;
import static com.google.common.collect.Iterables.addAll;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.filter;
import static com.google.inject.Scopes.SINGLETON;
import static com.google.inject.name.Names.bindProperties;
import static com.google.inject.util.Types.newParameterizedType;
import static org.jclouds.Constants.PROPERTY_API;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.Constants.PROPERTY_PROVIDER;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.inject.Inject;
@ -41,7 +54,9 @@ import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.location.config.ProvideIso3166CodesByLocationIdViaProperties;
import org.jclouds.logging.config.LoggingModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.annotations.Api;
@ -55,17 +70,13 @@ import org.jclouds.rest.internal.RestContextImpl;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.google.inject.util.Types;
/**
* Creates {@link RestContext} or {@link Injector} instances based on the most commonly requested
@ -94,11 +105,18 @@ public class RestContextBuilder<S, A> {
Properties toBind = new Properties();
toBind.putAll(checkNotNull(properties, "properties"));
toBind.putAll(System.getProperties());
Names.bindProperties(binder(), toBind);
bindProperties(binder(), toBind);
bind(String.class).annotatedWith(Provider.class).toInstance(
checkNotNull(toBind.getProperty(PROPERTY_PROVIDER), PROPERTY_PROVIDER));
bind(URI.class).annotatedWith(Provider.class).toInstance(
URI.create(checkNotNull(toBind.getProperty(PROPERTY_ENDPOINT), PROPERTY_ENDPOINT)));
bind(new TypeLiteral<Set<String>>() {
}).annotatedWith(Iso3166.class).toInstance(
ImmutableSet.copyOf(filter(on(',').split(
checkNotNull(toBind.getProperty(PROPERTY_ISO3166_CODES), PROPERTY_ISO3166_CODES)),
not(equalTo("")))));
bind(new TypeLiteral<Map<String, Set<String>>>() {
}).annotatedWith(Iso3166.class).toProvider(ProvideIso3166CodesByLocationIdViaProperties.class);
if (toBind.containsKey(PROPERTY_API))
bind(String.class).annotatedWith(Api.class).toInstance(toBind.getProperty(PROPERTY_API));
if (toBind.containsKey(PROPERTY_API_VERSION))
@ -124,7 +142,7 @@ public class RestContextBuilder<S, A> {
}
public RestContextBuilder<S, A> withModules(Iterable<Module> modules) {
Iterables.addAll(this.modules, modules);
addAll(this.modules, modules);
return this;
}
@ -142,7 +160,7 @@ public class RestContextBuilder<S, A> {
@VisibleForTesting
protected void addLoggingModuleIfNotPresent(List<Module> modules) {
if (!Iterables.any(modules, Predicates.instanceOf(LoggingModule.class)))
if (!any(modules, instanceOf(LoggingModule.class)))
modules.add(new JDKLoggingModule());
}
@ -153,7 +171,7 @@ public class RestContextBuilder<S, A> {
}
private boolean nothingConfiguresAnHttpService(List<Module> modules) {
return (!Iterables.any(modules, new Predicate<Module>() {
return (!any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(ConfiguresHttpCommandExecutorService.class);
}
@ -163,7 +181,7 @@ public class RestContextBuilder<S, A> {
@VisibleForTesting
protected void addContextModuleIfNotPresent(List<Module> modules) {
if (!Iterables.any(modules, new Predicate<Module>() {
if (!any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(ConfiguresRestContext.class);
}
@ -177,20 +195,20 @@ public class RestContextBuilder<S, A> {
protected void addContextModule(List<Module> modules) {
modules.add(new AbstractModule() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings( { "unchecked", "rawtypes" })
@Override
protected void configure() {
bind(
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(RestContext.class, syncClientType,
(TypeLiteral) TypeLiteral.get(newParameterizedType(RestContext.class, syncClientType,
asyncClientType))).to(
TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, syncClientType, asyncClientType)))
.in(Scopes.SINGLETON);
TypeLiteral.get(newParameterizedType(RestContextImpl.class, syncClientType, asyncClientType))).in(
SINGLETON);
}
public String toString() {
return String.format("configure rest context %s->%s", syncClientType.getSimpleName(),
asyncClientType.getSimpleName());
return String.format("configure rest context %s->%s", syncClientType.getSimpleName(), asyncClientType
.getSimpleName());
}
});
@ -208,7 +226,7 @@ public class RestContextBuilder<S, A> {
}
private boolean atLeastOneModuleRequiresHttp(List<Module> modules) {
return Iterables.any(modules, new Predicate<Module>() {
return any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(RequiresHttp.class);
}
@ -223,7 +241,7 @@ public class RestContextBuilder<S, A> {
}
private boolean restClientModulePresent(List<Module> modules) {
return Iterables.any(modules, new Predicate<Module>() {
return any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(ConfiguresRestClient.class);
}
@ -237,14 +255,14 @@ public class RestContextBuilder<S, A> {
@VisibleForTesting
protected void addExecutorServiceIfNotPresent(List<Module> modules) {
if (!Iterables.any(modules, new Predicate<Module>() {
if (!any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(ConfiguresExecutorService.class);
}
}
)) {
if (Iterables.any(modules, new Predicate<Module>() {
if (any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(SingleThreaded.class);
}
@ -259,7 +277,7 @@ public class RestContextBuilder<S, A> {
@VisibleForTesting
protected void addCredentialStoreIfNotPresent(List<Module> modules) {
if (!Iterables.any(modules, new Predicate<Module>() {
if (!any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(ConfiguresCredentialStore.class);
}
@ -278,7 +296,7 @@ public class RestContextBuilder<S, A> {
@SuppressWarnings("unchecked")
public <T extends RestContext<S, A>> T buildContext() {
Injector injector = buildInjector();
return (T) injector.getInstance(Key.get(Types.newParameterizedType(RestContext.class, syncClientType,
asyncClientType)));
return (T) injector
.getInstance(Key.get(newParameterizedType(RestContext.class, syncClientType, asyncClientType)));
}
}

View File

@ -35,12 +35,14 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import org.jclouds.PropertiesBuilder;
import org.jclouds.location.reference.LocationConstants;
import org.jclouds.util.Modules2;
import org.jclouds.util.Strings2;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import com.google.inject.Module;
@ -70,22 +72,23 @@ import com.google.inject.Module;
public class RestContextFactory {
public static <S, A> RestContextSpec<S, A> contextSpec(String provider, String endpoint, String apiVersion,
String identity, String credential, Class<S> sync, Class<A> async,
String iso3166Codes, String identity, String credential, Class<S> sync, Class<A> async,
Class<PropertiesBuilder> propertiesBuilderClass, Class<RestContextBuilder<S, A>> contextBuilderClass,
Iterable<Module> modules) {
return new RestContextSpec<S, A>(provider, endpoint, apiVersion, identity, credential, sync, async,
return new RestContextSpec<S, A>(provider, endpoint, apiVersion, iso3166Codes, identity, credential, sync, async,
propertiesBuilderClass, contextBuilderClass, modules);
}
public static <S, A> RestContextSpec<S, A> contextSpec(String provider, String endpoint, String apiVersion,
String identity, String credential, Class<S> sync, Class<A> async) {
return new RestContextSpec<S, A>(provider, endpoint, apiVersion, identity, credential, sync, async);
String iso3166Codes, String identity, String credential, Class<S> sync, Class<A> async) {
return new RestContextSpec<S, A>(provider, endpoint, apiVersion, iso3166Codes, identity, credential, sync, async);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings( { "unchecked", "rawtypes" })
public static <S, A> RestContextSpec<S, A> contextSpec(String provider, String endpoint, String apiVersion,
String identity, String credential, Class<S> sync, Class<A> async, Iterable<Module> modules) {
return new RestContextSpec<S, A>(provider, endpoint, apiVersion, identity, credential, sync, async,
String iso3166Codes, String identity, String credential, Class<S> sync, Class<A> async,
Iterable<Module> modules) {
return new RestContextSpec<S, A>(provider, endpoint, apiVersion, iso3166Codes, identity, credential, sync, async,
PropertiesBuilder.class, (Class) RestContextBuilder.class, modules);
}
@ -177,9 +180,9 @@ public class RestContextFactory {
/**
*
* Identity will be found by searching {@code jclouds.identity} failing that
* {@code provider.identity} where provider corresponds to the parameter. Same pattern is used
* for credential ({@code jclouds.credential} failing that {@code provider.credential}).
* Identity will be found by searching {@code jclouds.identity} failing that {@code
* provider.identity} where provider corresponds to the parameter. Same pattern is used for
* credential ({@code jclouds.credential} failing that {@code provider.credential}).
*
* @param <S>
* Type of the provider specific client
@ -239,6 +242,7 @@ public class RestContextFactory {
props.setProperty(contextSpec.provider + ".endpoint", contextSpec.endpoint);
props.setProperty(contextSpec.provider + ".apiversion", contextSpec.apiVersion);
props.setProperty(contextSpec.provider + "." + LocationConstants.ISO3166_CODES, contextSpec.iso3166Codes);
props.setProperty(contextSpec.provider + ".identity", contextSpec.identity);
if (contextSpec.credential != null)
props.setProperty(contextSpec.provider + ".credential", contextSpec.credential);
@ -247,15 +251,15 @@ public class RestContextFactory {
props.setProperty(contextSpec.provider + ".async", checkNotNull(contextSpec.async, "contextSpec.async")
.getName());
} else {
props.setProperty(contextSpec.provider + ".contextbuilder",
checkNotNull(contextSpec.contextBuilderClass, "contextSpec.contextBuilderClass").getName());
props.setProperty(contextSpec.provider + ".contextbuilder", checkNotNull(contextSpec.contextBuilderClass,
"contextSpec.contextBuilderClass").getName());
props.setProperty(contextSpec.provider + ".propertiesbuilder",
checkNotNull(contextSpec.propertiesBuilderClass, "contextSpec.propertiesBuilderClass").getName());
props.setProperty(contextSpec.provider + ".propertiesbuilder", checkNotNull(
contextSpec.propertiesBuilderClass, "contextSpec.propertiesBuilderClass").getName());
}
if (size(contextSpec.modules) > 0) {
props.setProperty(contextSpec.provider + ".modules",
Joiner.on(',').join(transform(contextSpec.modules, new Function<Module, String>() {
props.setProperty(contextSpec.provider + ".modules", Joiner.on(',').join(
transform(contextSpec.modules, new Function<Module, String>() {
@Override
public String apply(Module from) {
@ -283,11 +287,12 @@ public class RestContextFactory {
props.putAll(this.properties);
props.putAll(_overrides);
String endpoint = props.getProperty(providerName + ".endpoint", null);
String endpoint = props.getProperty(providerName + "." + LocationConstants.ENDPOINT, null);
String iso3166Codes = props.getProperty(providerName + "." + LocationConstants.ISO3166_CODES, null);
String apiVersion = props.getProperty(providerName + ".apiversion", null);
identity = props.getProperty(providerName + ".identity", props.getProperty("jclouds.identity", identity));
credential = loadCredentialOrDefault(props, providerName + ".credential",
loadCredentialOrDefault(props, "jclouds.credential", credential));
credential = loadCredentialOrDefault(props, providerName + ".credential", loadCredentialOrDefault(props,
"jclouds.credential", credential));
String syncClassName = props.getProperty(providerName + ".sync", null);
String asyncClassName = props.getProperty(providerName + ".async", null);
Iterable<Module> modules = concat(Modules2.modulesForProviderInProperties(providerName, props), wiring);
@ -306,8 +311,8 @@ public class RestContextFactory {
assert false : "exception should have propogated " + e;
return null;
}
RestContextSpec<S, A> contextSpec = new RestContextSpec<S, A>(providerName, endpoint, apiVersion, identity,
credential, sync, async, propertiesBuilderClass, contextBuilderClass, modules);
RestContextSpec<S, A> contextSpec = new RestContextSpec<S, A>(providerName, endpoint, apiVersion, iso3166Codes,
identity, credential, sync, async, propertiesBuilderClass, contextBuilderClass, modules);
return contextSpec;
}
@ -316,8 +321,8 @@ public class RestContextFactory {
return properties.getProperty(property);
else if (properties.containsKey(property + ".resource"))
try {
return Strings2.toStringAndClose(RestContextFactory.class.getResourceAsStream(properties.getProperty(property
+ ".resource")));
return Strings2.toStringAndClose(RestContextFactory.class.getResourceAsStream(properties
.getProperty(property + ".resource")));
} catch (IOException e) {
throw new RuntimeException("error reading resource: " + properties.getProperty(property + ".resource"));
}
@ -355,6 +360,8 @@ public class RestContextFactory {
builder.provider(contextSpec.provider);
if (contextSpec.apiVersion != null)
builder.apiVersion(contextSpec.apiVersion);
if (contextSpec.iso3166Codes != null)
builder.iso3166Codes(Splitter.on('.').split(contextSpec.iso3166Codes));
if (contextSpec.identity != null)
builder.credentials(contextSpec.identity, contextSpec.credential);
if (contextSpec.endpoint != null)

View File

@ -36,6 +36,7 @@ public class RestContextSpec<S, A> {
protected final String provider;
protected final String endpoint;
protected final String apiVersion;
protected final String iso3166Codes;
protected final String identity;
protected final String credential;
protected final Class<S> sync;
@ -44,14 +45,15 @@ public class RestContextSpec<S, A> {
protected final Class<RestContextBuilder<S, A>> contextBuilderClass;
protected final Iterable<Module> modules;
public RestContextSpec(String provider, String endpoint, String apiVersion, String identity, String credential,
Class<S> sync, Class<A> async, Class<PropertiesBuilder> propertiesBuilderClass,
public RestContextSpec(String provider, String endpoint, String apiVersion, String iso3166Codes, String identity,
String credential, Class<S> sync, Class<A> async, Class<PropertiesBuilder> propertiesBuilderClass,
Class<RestContextBuilder<S, A>> contextBuilderClass, Iterable<Module> modules) {
this.provider = checkNotNull(provider, "provider");
this.endpoint = endpoint;
this.apiVersion = apiVersion;
this.identity = identity;
this.credential = credential;
this.iso3166Codes = iso3166Codes;
this.sync = sync;
this.async = async;
checkArgument(RestContextBuilder.class.isAssignableFrom(contextBuilderClass), contextBuilderClass.getName()
@ -63,10 +65,10 @@ public class RestContextSpec<S, A> {
this.modules = ImmutableList.copyOf(modules);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public RestContextSpec(String provider, String endpoint, String apiVersion, String identity, String credential,
Class<S> sync, Class<A> async) {
this(provider, endpoint, apiVersion, identity, credential, sync, async, PropertiesBuilder.class,
@SuppressWarnings( { "unchecked", "rawtypes" })
public RestContextSpec(String provider, String endpoint, String apiVersion, String iso3166Codes, String identity,
String credential, Class<S> sync, Class<A> async) {
this(provider, endpoint, apiVersion, iso3166Codes, identity, credential, sync, async, PropertiesBuilder.class,
(Class) RestContextBuilder.class, EMPTY_LIST);
}
@ -76,7 +78,7 @@ public class RestContextSpec<S, A> {
*/
@Override
public int hashCode() {
return Objects.hashCode(provider, endpoint, apiVersion, identity, credential, sync, async,
return Objects.hashCode(provider, endpoint, apiVersion, iso3166Codes, identity, credential, sync, async,
propertiesBuilderClass, contextBuilderClass, modules);
}
@ -97,10 +99,10 @@ public class RestContextSpec<S, A> {
*/
@Override
public String toString() {
return Objects.toStringHelper(this).add("provider", provider).add("endpoint", endpoint)
.add("apiVersion", apiVersion).add("identity", identity).add("sync", sync).add("async", async)
.add("propertiesBuilderClass", propertiesBuilderClass).add("contextBuilderClass", contextBuilderClass)
.add("modules", modules).toString();
return Objects.toStringHelper(this).add("provider", provider).add("endpoint", endpoint).add("apiVersion",
apiVersion).add("iso3166Codes", iso3166Codes).add("identity", identity).add("sync", sync).add("async",
async).add("propertiesBuilderClass", propertiesBuilderClass).add("contextBuilderClass",
contextBuilderClass).add("modules", modules).toString();
}
}

View File

@ -22,12 +22,16 @@ package org.jclouds.rest.internal;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.lifecycle.Closer;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RestContext;
@ -35,6 +39,7 @@ import org.jclouds.rest.Utils;
import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.annotations.Identity;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Singleton;
@ -57,11 +62,12 @@ public class RestContextImpl<S, A> implements RestContext<S, A> {
private final String apiVersion;
private final Utils utils;
private final Map<String, Credentials> credentialStore;
private final Set<String> iso3166Codes;
@Inject
protected RestContextImpl(Closer closer, Map<String, Credentials> credentialStore, Utils utils, Injector injector,
TypeLiteral<S> syncApi, TypeLiteral<A> asyncApi, @Provider URI endpoint, @Provider String provider,
@Identity String identity, @ApiVersion String apiVersion) {
@Identity String identity, @ApiVersion String apiVersion, @Iso3166 Set<String> iso3166Codes) {
this.credentialStore = credentialStore;
this.utils = utils;
this.asyncApi = injector.getInstance(Key.get(asyncApi));
@ -71,6 +77,7 @@ public class RestContextImpl<S, A> implements RestContext<S, A> {
this.identity = identity;
this.provider = provider;
this.apiVersion = apiVersion;
this.iso3166Codes = iso3166Codes;
}
/**
@ -122,11 +129,6 @@ public class RestContextImpl<S, A> implements RestContext<S, A> {
return apiVersion;
}
@Override
public String getProvider() {
return provider;
}
@Override
public int hashCode() {
final int prime = 31;
@ -172,8 +174,8 @@ public class RestContextImpl<S, A> implements RestContext<S, A> {
@Override
public String toString() {
return " [provider=" + provider + ", endpoint=" + endpoint + ", apiVersion=" + apiVersion + ", identity="
+ identity + "]";
return " [id=" + provider + ", endpoint=" + endpoint + ", apiVersion=" + apiVersion + ", identity=" + identity
+ ", iso3166Codes=" + iso3166Codes + "]";
}
@Override
@ -185,4 +187,34 @@ public class RestContextImpl<S, A> implements RestContext<S, A> {
public Map<String, Credentials> credentialStore() {
return credentialStore;
}
@Override
public String getDescription() {
return null;
}
@Override
public String getId() {
return provider;
}
@Override
public Set<String> getIso3166Codes() {
return iso3166Codes;
}
@Override
public Map<String, Object> getMetadata() {
return ImmutableMap.<String, Object> of("endpoint", endpoint, "apiVersion", apiVersion, "identity", identity);
}
@Override
public Location getParent() {
return null;
}
@Override
public LocationScope getScope() {
return LocationScope.PROVIDER;
}
}

View File

@ -166,7 +166,7 @@ swift.contextbuilder=org.jclouds.openstack.swift.SwiftContextBuilder
swift.propertiesbuilder=org.jclouds.openstack.swift.SwiftPropertiesBuilder
cloudfiles.contextbuilder=org.jclouds.cloudfiles.CloudFilesContextBuilder
cloudfiles.propertiesbuilder=org.jclouds.cloudfiles.CloudFilesPropertiesBuilder
cloudfiles.propertiesbuilder=org.jclouds.openstack.swift.SwiftPropertiesBuilder
cloudfiles-us.contextbuilder=org.jclouds.cloudfiles.CloudFilesContextBuilder
cloudfiles-us.propertiesbuilder=org.jclouds.rackspace.cloudfiles.CloudFilesUSPropertiesBuilder

View File

@ -266,7 +266,7 @@ public abstract class BaseJettyTest {
properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
properties.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec("test",
"http://localhost:" + testPort, "1", "identity", null, IntegrationTestClient.class,
"http://localhost:" + testPort, "1", "", "identity", null, IntegrationTestClient.class,
IntegrationTestAsyncClient.class, ImmutableSet.<Module> copyOf(connectionModules));
return createContextBuilder(contextSpec, properties);
}

View File

@ -142,7 +142,7 @@ public class InputParamValidatorTest {
void setupFactory() {
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec("test",
"http://localhost:9999", "1", "userFoo", null, IntegrationTestClient.class,
"http://localhost:9999", "1", "", "userFoo", null, IntegrationTestClient.class,
IntegrationTestAsyncClient.class);
injector = createContextBuilder(contextSpec).buildInjector();

View File

@ -54,19 +54,22 @@ public class RestContextFactoryTest {
public void testBuilder() {
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec(provider,
"http://localhost", "1", "dummy", null, IntegrationTestClient.class, IntegrationTestAsyncClient.class);
"http://localhost", "1", "", "dummy", null, IntegrationTestClient.class,
IntegrationTestAsyncClient.class);
createContextBuilder(contextSpec);
}
public void testBuilderProperties() {
public void testBuilderPropertiesWithIso3166() {
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec(provider,
"http://localhost", "1", "dummy", null, IntegrationTestClient.class, IntegrationTestAsyncClient.class);
"http://localhost", "1", "US-CA", "dummy", null, IntegrationTestClient.class,
IntegrationTestAsyncClient.class);
Properties props = RestContextFactory.toProperties(contextSpec);
assertEquals(props.getProperty("test.endpoint"), "http://localhost");
assertEquals(props.getProperty("test.apiversion"), "1");
assertEquals(props.getProperty("test.identity"), "dummy");
assertEquals(props.getProperty("test.iso3166-codes"), "US-CA");
assertEquals(props.getProperty("test.credential"), null);
assertEquals(props.getProperty("test.sync"), IntegrationTestClient.class.getName());
assertEquals(props.getProperty("test.async"), IntegrationTestAsyncClient.class.getName());
@ -79,7 +82,7 @@ public class RestContextFactoryTest {
public void testBuilderPropertiesWithCredential() {
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec(provider,
"http://localhost", "1", "dummy", "credential", IntegrationTestClient.class,
"http://localhost", "1", "", "dummy", "credential", IntegrationTestClient.class,
IntegrationTestAsyncClient.class);
Properties props = RestContextFactory.toProperties(contextSpec);
@ -100,7 +103,7 @@ public class RestContextFactoryTest {
public void testBuilderPropertiesWithContextBuilder() {
@SuppressWarnings("rawtypes")
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec(provider,
"http://localhost", "1", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class,
"http://localhost", "1", "", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class,
(Class) IntegrationTestContextBuilder.class, Collections.EMPTY_LIST);
Properties props = RestContextFactory.toProperties(contextSpec);
@ -121,7 +124,7 @@ public class RestContextFactoryTest {
public void testBuilderPropertiesWithModule() {
@SuppressWarnings("rawtypes")
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec(provider,
"http://localhost", "1", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class,
"http://localhost", "1", "", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class,
(Class) IntegrationTestContextBuilder.class, Collections.<Module> singleton(new A()));
Properties props = RestContextFactory.toProperties(contextSpec);
@ -142,7 +145,7 @@ public class RestContextFactoryTest {
public void testBuilderPropertiesWithModules() {
@SuppressWarnings("rawtypes")
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec(provider,
"http://localhost", "1", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class,
"http://localhost", "1", "", "dummy", null, (Class) null, (Class) null, PropertiesBuilder.class,
(Class) IntegrationTestContextBuilder.class, Arrays.<Module> asList(new A(), new B()));
Properties props = RestContextFactory.toProperties(contextSpec);
@ -164,6 +167,7 @@ public class RestContextFactoryTest {
Properties props = new Properties();
props.setProperty("test.endpoint", "http://localhost");
props.setProperty("test.apiversion", "1");
props.setProperty("test.iso3166-codes", "US");
props.setProperty("jclouds.identity", "foo");
props.setProperty("jclouds.credential", "bar");
@ -178,7 +182,9 @@ public class RestContextFactoryTest {
@Override
public <S, A> RestContextSpec<S, A> createContextSpec(String providerName, String identity, String credential,
Iterable<? extends Module> wiring, Properties _overrides) {
RestContextSpec<S, A> spec = super.createContextSpec(providerName, identity, credential, wiring, _overrides);
RestContextSpec<S, A> spec = super
.createContextSpec(providerName, identity, credential, wiring, _overrides);
assertEquals(spec.iso3166Codes, "US");
assertEquals(spec.identity, "foo");
assertEquals(spec.credential, "bar");
assertEquals(Iterables.size(spec.modules), 2);
@ -196,6 +202,7 @@ public class RestContextFactoryTest {
Properties props = new Properties();
props.setProperty("test.endpoint", "http://localhost");
props.setProperty("test.apiversion", "1");
props.setProperty("test.iso3166-codes", "US");
props.setProperty("test.identity", "foo");
props.setProperty("test.credential.file", file.getAbsolutePath());
@ -210,7 +217,9 @@ public class RestContextFactoryTest {
@Override
public <S, A> RestContextSpec<S, A> createContextSpec(String providerName, String identity, String credential,
Iterable<? extends Module> wiring, Properties _overrides) {
RestContextSpec<S, A> spec = super.createContextSpec(providerName, identity, credential, wiring, _overrides);
RestContextSpec<S, A> spec = super
.createContextSpec(providerName, identity, credential, wiring, _overrides);
assertEquals(spec.iso3166Codes, "US");
assertEquals(spec.identity, "foo");
assertEquals(spec.credential, "bar");
assertEquals(Iterables.size(spec.modules), 2);
@ -241,9 +250,9 @@ public class RestContextFactoryTest {
@SuppressWarnings("unchecked")
@Test(expectedExceptions = IllegalArgumentException.class)
public void testBuilderPropertiesWithWrongConfig() {
@SuppressWarnings({ "unused", "rawtypes" })
@SuppressWarnings( { "unused", "rawtypes" })
RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> contextSpec = contextSpec(provider,
"http://localhost", "1", "dummy", null, (Class) null, (Class) null,
"http://localhost", "1", "", "dummy", null, (Class) null, (Class) null,
(Class) IntegrationTestContextBuilder.class, (Class) PropertiesBuilder.class, Collections.EMPTY_LIST);
}

View File

@ -280,8 +280,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
private Injector injectorForClient() {
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo",
null, Caller.class, AsyncCaller.class, ImmutableSet.<Module> of(new MockModule(),
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "",
"userfoo", null, Caller.class, AsyncCaller.class, ImmutableSet.<Module> of(new MockModule(),
new NullLoggingModule(), new CallerCalleeModule()));
return createContextBuilder(contextSpec).buildInjector();
@ -2100,8 +2100,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@BeforeClass
void setupFactory() {
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
String.class, Integer.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
null, String.class, Integer.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
new AbstractModule() {
@Override

View File

@ -19,13 +19,16 @@
package org.jclouds.aws.ec2;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1;
import static org.jclouds.aws.domain.Region.EU_WEST_1;
import static org.jclouds.aws.domain.Region.US_EAST_1;
import static org.jclouds.aws.domain.Region.US_WEST_1;
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_SUSPENDED;
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties;
@ -40,11 +43,17 @@ import com.google.common.collect.ImmutableSet;
* @author Adrian Cole
*/
public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilder {
public static Set<String> DEFAULT_REGIONS = ImmutableSet.of(EU_WEST_1, US_EAST_1, US_WEST_1, AP_SOUTHEAST_1);
public static Set<String> DEFAULT_REGIONS = ImmutableSet.of(US_EAST_1, US_WEST_1, EU_WEST_1, AP_SOUTHEAST_1);
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-VA,US-CA,IE,SG");
properties.setProperty(PROPERTY_REGION + "." + US_EAST_1 + "." + ISO3166_CODES, "US-VA");
properties.setProperty(PROPERTY_REGION + "." + US_WEST_1 + "." + ISO3166_CODES, "US-CA");
properties.setProperty(PROPERTY_REGION + "." + EU_WEST_1 + "." + ISO3166_CODES, "IE");
properties.setProperty(PROPERTY_REGION + "." + AP_SOUTHEAST_1 + "." + ISO3166_CODES, "SG");
// sometimes, like in ec2, stop takes a very long time, perhaps
// due to volume management. one example spent 2 minutes moving
// from stopping->stopped state on an ec2 micro

View File

@ -20,11 +20,14 @@
package org.jclouds.aws.ec2.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
import org.jclouds.aws.domain.Region;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
@ -173,4 +176,40 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
}
}
@Test
public void testTemplateBuilderWithLessRegions() throws IOException {
ComputeServiceContext context = null;
try {
Properties overrides = setupProperties();
// set regions to only 1
overrides.setProperty(PROPERTY_REGIONS, Region.US_EAST_1);
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), overrides);
assert context.getComputeService().listImages().size() < this.context.getComputeService().listImages().size();
Template template = context.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").build();
System.out.println(template.getHardware());
assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(template.getImage().getVersion(), "4.4.10");
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 2.0d);
assertEquals(template.getHardware().getId(), "m1.large"); // because it is 64bit
} finally {
if (context != null)
context.close();
}
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-VA", "US-CA", "IE", "SG");
}
}

View File

@ -24,7 +24,6 @@ import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.Set;
import org.jclouds.aws.ec2.compute.strategy.AWSEC2ReviseParsedImage;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
@ -32,8 +31,8 @@ import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.ec2.compute.functions.EC2ImageParser;
import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.ec2.domain.Image;
@ -127,11 +126,11 @@ public class AWSEC2ImageParserTest {
assertEquals(
new Gson().toJson(Iterables.get(result, 1)),
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
assertEquals(
new Gson().toJson(Iterables.get(result, 2)),
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"providerId\":\"ami-710c2605\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"providerId\":\"ami-710c2605\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
}
public void testParseAmznImage() {
@ -154,7 +153,8 @@ public class AWSEC2ImageParserTest {
ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
}
static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description(
"us-east-1").build();
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {

View File

@ -20,10 +20,13 @@
package org.jclouds.aws.s3;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.aws.domain.Region.AP_SOUTHEAST_1;
import static org.jclouds.aws.domain.Region.EU_WEST_1;
import static org.jclouds.aws.domain.Region.US_EAST_1;
import static org.jclouds.aws.domain.Region.US_WEST_1;
import static org.jclouds.location.reference.LocationConstants.ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
@ -46,15 +49,20 @@ public class AWSS3PropertiesBuilder extends org.jclouds.s3.S3PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_REGIONS,
Joiner.on(',').join(Region.US_STANDARD, Region.US_WEST_1, "EU", Region.AP_SOUTHEAST_1));
properties.setProperty(PROPERTY_ISO3166_CODES, "US,US-CA,IE,SG");
properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(Region.US_STANDARD, Region.US_WEST_1, "EU",
Region.AP_SOUTHEAST_1));
properties.setProperty(PROPERTY_ENDPOINT, "https://s3.amazonaws.com");
properties.setProperty(PROPERTY_REGION + "." + Region.US_STANDARD + ".endpoint", "https://s3.amazonaws.com");
properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + ".endpoint",
properties.setProperty(PROPERTY_REGION + "." + Region.US_STANDARD + "." + ENDPOINT, "https://s3.amazonaws.com");
properties.setProperty(PROPERTY_REGION + "." + Region.US_STANDARD + "." + ISO3166_CODES, "US");
properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + "." + ENDPOINT,
"https://s3-us-west-1.amazonaws.com");
properties.setProperty(PROPERTY_REGION + "." + "EU" + ".endpoint", "https://s3-eu-west-1.amazonaws.com");
properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + ".endpoint",
properties.setProperty(PROPERTY_REGION + "." + Region.US_WEST_1 + "." + ISO3166_CODES, "US-CA");
properties.setProperty(PROPERTY_REGION + "." + "EU" + "." + ENDPOINT, "https://s3-eu-west-1.amazonaws.com");
properties.setProperty(PROPERTY_REGION + "." + "EU" + "." + ISO3166_CODES, "IE");
properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + "." + ENDPOINT,
"https://s3-ap-southeast-1.amazonaws.com");
properties.setProperty(PROPERTY_REGION + "." + Region.AP_SOUTHEAST_1 + "." + ISO3166_CODES, "SG");
return properties;
}

View File

@ -19,6 +19,15 @@
package org.jclouds.aws.s3;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState;
import org.jclouds.s3.options.PutBucketOptions;
import org.testng.annotations.Test;
/**
@ -32,4 +41,22 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest {
this.provider = "aws-s3";
}
public void testPutBucketEu() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("putBucketInRegion", String.class, String.class, Array.newInstance(
PutBucketOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "EU", "bucket");
assertRequestLineEquals(request, "PUT https://bucket." + url + "/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket." + url + "\n");
assertPayloadEquals(request,
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
"text/xml", false);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState.class);
checkFilters(request);
}
}

View File

@ -19,13 +19,21 @@
package org.jclouds.aws.s3.blobstore.integration;
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
import java.util.Set;
import org.jclouds.s3.blobstore.integration.S3ServiceIntegrationLiveTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
@Test(groups = "live", testName = "AWSS3ServiceIntegrationLiveTest")
public class AWSS3ServiceIntegrationLiveTest extends BaseServiceIntegrationTest {
public class AWSS3ServiceIntegrationLiveTest extends S3ServiceIntegrationLiveTest {
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US", "US-CA", "IE", "SG");
}
}

View File

@ -21,6 +21,7 @@ package org.jclouds.azureblob;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
import java.util.Properties;
@ -39,6 +40,7 @@ public class AzureBlobPropertiesBuilder extends AzureStoragePropertiesBuilder {
properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "x-ms-meta-");
properties.setProperty(PROPERTY_API_VERSION, "2009-09-19");
properties.setProperty(PROPERTY_ENDPOINT, "https://{identity}.blob.core.windows.net");
properties.setProperty(PROPERTY_ISO3166_CODES, "US-TX,US-IL,IE-D,SG,NL-NH,HK");
return properties;
}

View File

@ -19,10 +19,6 @@
package org.jclouds.azureblob.blobstore.config;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.azureblob.AzureBlobAsyncClient;
import org.jclouds.azureblob.AzureBlobClient;
import org.jclouds.azureblob.blobstore.AzureAsyncBlobStore;
@ -37,17 +33,9 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Provider;
import org.jclouds.location.config.JustProviderLocationModule;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
@ -61,6 +49,7 @@ public class AzureBlobStoreContextModule extends AbstractModule {
@Override
protected void configure() {
install(new BlobStoreMapModule());
install(new JustProviderLocationModule());
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
bind(AsyncBlobStore.class).to(AzureAsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(AzureBlobStore.class).in(Scopes.SINGLETON);
@ -70,18 +59,4 @@ public class AzureBlobStoreContextModule extends AbstractModule {
bind(BlobRequestSigner.class).to(AzureBlobRequestSigner.class);
}
@Provides
@Singleton
@Memoized
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
}
@Provides
@Singleton
Supplier<Location> provideDefaultLocation(@Provider String providerName) {
return Suppliers
.<Location> ofInstance(new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null));
}
}

View File

@ -19,13 +19,20 @@
package org.jclouds.azureblob.blobstore.integration;
import java.util.Set;
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
@Test(groups = "live")
public class AzureBlobServiceIntegrationLiveTest extends BaseServiceIntegrationTest {
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-TX", "US-IL", "IE-D", "SG", "NL-NH", "HK");
}
}

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud.bluelock;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import java.util.Properties;
@ -35,6 +36,7 @@ public class BlueLockVCloudDirectorPropertiesBuilder extends VCloudPropertiesBui
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN");
properties.setProperty(PROPERTY_ENDPOINT, "https://vcenterprise.bluelock.com/api");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01");
return properties;

View File

@ -4,6 +4,7 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Set;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.domain.OsFamily;
@ -12,6 +13,7 @@ import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
/**
*
@ -49,4 +51,9 @@ public class BlueLockVCloudDirectorTemplateBuilderLiveTest extends BaseTemplateB
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-IN");
}
}

View File

@ -20,6 +20,7 @@
package org.jclouds.rackspace.cloudfiles;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties;
@ -37,6 +38,7 @@ public class CloudFilesUKPropertiesBuilder extends SwiftPropertiesBuilder {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_REGIONS, "UK");
properties.setProperty(PROPERTY_ENDPOINT, "https://lon.auth.api.rackspacecloud.com");
properties.setProperty(PROPERTY_ISO3166_CODES, "GB-SLG");
return properties;
}

View File

@ -19,13 +19,20 @@
package org.jclouds.rackspace.cloudfiles.blobstore.integration;
import java.util.Set;
import org.jclouds.cloudfiles.blobstore.integration.CloudFilesServiceIntegrationLiveTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
@Test(groups = "live", testName = "CloudFilesUKServiceIntegrationLiveTest")
public class CloudFilesUKServiceIntegrationLiveTest extends CloudFilesServiceIntegrationLiveTest {
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("GB-SLG");
}
}

View File

@ -20,6 +20,7 @@
package org.jclouds.rackspace.cloudfiles;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties;
@ -37,6 +38,7 @@ public class CloudFilesUSPropertiesBuilder extends SwiftPropertiesBuilder {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_REGIONS, "US");
properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com");
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IL,US-TX");
return properties;
}

View File

@ -19,13 +19,20 @@
package org.jclouds.rackspace.cloudfiles.blobstore.integration;
import java.util.Set;
import org.jclouds.cloudfiles.blobstore.integration.CloudFilesServiceIntegrationLiveTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
@Test(groups = "live", testName = "CloudFilesUSServiceIntegrationLiveTest")
public class CloudFilesUSServiceIntegrationLiveTest extends CloudFilesServiceIntegrationLiveTest {
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-IL", "US-TX");
}
}

View File

@ -21,6 +21,7 @@ package org.jclouds.cloudonestorage;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import java.util.Properties;
@ -37,6 +38,7 @@ public class CloudOneStoragePropertiesBuilder extends PropertiesBuilder {
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://cloudonestorage.peer1.com");
properties.setProperty(PROPERTY_ISO3166_CODES, "US-GA,US-TX");
properties.setProperty(PROPERTY_API_VERSION, "1.3.0");
return properties;
}

View File

@ -19,13 +19,20 @@
package org.jclouds.cloudonestorage.blobstore.integration;
import java.util.Set;
import org.jclouds.atmos.blobstore.integration.AtmosServiceIntegrationLiveTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
@Test(groups = "live", testName = "CloudOneStorageServiceIntegrationLiveTest")
public class CloudOneStorageServiceIntegrationLiveTest extends AtmosServiceIntegrationLiveTest {
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-GA", "US-TX");
}
}

View File

@ -21,7 +21,7 @@ package org.jclouds.rackspace.cloudservers;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import java.util.Properties;
@ -37,7 +37,7 @@ public class CloudServersUKPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_REGIONS, "UK");
properties.setProperty(PROPERTY_ISO3166_CODES, "GB-SLG");
properties.setProperty(PROPERTY_ENDPOINT, "https://lon.auth.api.rackspacecloud.com");
properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION);
return properties;

View File

@ -22,6 +22,8 @@ package org.jclouds.rackspace.cloudservers.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
@ -29,6 +31,7 @@ import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
/**
*
@ -69,8 +72,12 @@ public class CloudServersUKTemplateBuilderLiveTest extends BaseTemplateBuilderLi
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "UK");
assertEquals(defaultTemplate.getLocation().getId(), provider);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("GB-SLG");
}
}

View File

@ -21,7 +21,7 @@ package org.jclouds.rackspace.cloudservers;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import java.util.Properties;
@ -37,7 +37,7 @@ public class CloudServersUSPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_REGIONS, "US");
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IL,US-TX");
properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com");
properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION);
return properties;

View File

@ -22,6 +22,8 @@ package org.jclouds.rackspace.cloudservers.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
@ -29,6 +31,7 @@ import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
/**
*
@ -69,7 +72,12 @@ public class CloudServersUSTemplateBuilderLiveTest extends BaseTemplateBuilderLi
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "US");
assertEquals(defaultTemplate.getLocation().getId(), provider);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-IL", "US-TX");
}
}

View File

@ -20,6 +20,7 @@
package org.jclouds.cloudsigma;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import java.util.Properties;
@ -32,6 +33,7 @@ public class CloudSigmaZurichPropertiesBuilder extends CloudSigmaPropertiesBuild
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "CH-ZH");
properties.setProperty(PROPERTY_ENDPOINT, "https://api.cloudsigma.com");
return properties;
}

View File

@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@ -56,9 +55,7 @@ import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
@ -88,8 +85,7 @@ public class CloudSigmaComputeServiceAdapter implements
private final CloudSigmaClient client;
private final CloudSigmaAsyncClient aclient;
private final Predicate<DriveInfo> driveNotClaimed;
private final String providerName;
private final URI providerURI;
private final JustProvider locationSupplier;
private final String defaultVncPassword;
private final Map<String, DriveInfo> cache;
private final ExecutorService executor;
@ -100,14 +96,13 @@ public class CloudSigmaComputeServiceAdapter implements
@Inject
public CloudSigmaComputeServiceAdapter(CloudSigmaClient client, CloudSigmaAsyncClient aclient,
Predicate<DriveInfo> driveNotClaimed, @Provider String providerName, @Provider URI providerURI,
Predicate<DriveInfo> driveNotClaimed, JustProvider locationSupplier,
@Named(CloudSigmaConstants.PROPERTY_VNC_PASSWORD) String defaultVncPassword, Map<String, DriveInfo> cache,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.client = checkNotNull(client, "client");
this.aclient = checkNotNull(aclient, "aclient");
this.driveNotClaimed = checkNotNull(driveNotClaimed, "driveNotClaimed");
this.providerName = checkNotNull(providerName, "providerName");
this.providerURI = checkNotNull(providerURI, "providerURI");
this.locationSupplier = checkNotNull(locationSupplier, "locationSupplier");
this.defaultVncPassword = checkNotNull(defaultVncPassword, "defaultVncPassword");
this.cache = checkNotNull(cache, "cache");
this.executor = checkNotNull(executor, "executor");
@ -159,8 +154,8 @@ public class CloudSigmaComputeServiceAdapter implements
return "sizeLessThanOrEqual(" + size + ")";
}
}).ids(id).ram(ram).processors(ImmutableList.of(new Processor(1, cpu)))
.volumes(ImmutableList.<Volume> of(new VolumeImpl(size, true, true))).build());
}).ids(id).ram(ram).processors(ImmutableList.of(new Processor(1, cpu))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(size, true, true))).build());
}
return hardware.build();
}
@ -191,10 +186,10 @@ public class CloudSigmaComputeServiceAdapter implements
return (Iterable<ServerInfo>) client.listServerInfo();
}
@SuppressWarnings("unchecked")
@Override
public Iterable<Location> listLocations() {
return ImmutableSet.<Location> of(new LocationImpl(LocationScope.PROVIDER, providerName, providerURI
.toASCIIString(), null));
return (Iterable<Location>) locationSupplier.get();
}
@Override

View File

@ -52,11 +52,13 @@ import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
import org.jclouds.predicates.RetryablePredicate;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.MapMaker;
import com.google.inject.Injector;
import com.google.inject.Provides;
@ -101,7 +103,8 @@ public class CloudSigmaComputeServiceContextModule
}).to(FindImageForId.class);
bind(new TypeLiteral<Function<String, OsFamilyVersion64Bit>>() {
}).to(ParseOsFamilyVersion64BitFromImageName.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(OnlyLocationOrFirstZone.class);
}
@Provides

View File

@ -23,6 +23,7 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Set;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.domain.OsFamily;
@ -31,6 +32,7 @@ import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
/**
*
@ -74,4 +76,9 @@ public class CloudSigmaTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTe
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("CH-ZH");
}
}

View File

@ -21,6 +21,7 @@ package org.jclouds.elastichosts;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import java.util.Properties;
@ -35,6 +36,7 @@ public class ElasticHostsBlueSquareLondonPropertiesBuilder extends ElasticStackP
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "GB-LND");
properties.setProperty(PROPERTY_ENDPOINT, "https://api.lon-p.elastichosts.com");
properties.setProperty(PROPERTY_API_VERSION, "1.0");
return properties;

View File

@ -22,6 +22,8 @@ package org.jclouds.elastichosts.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
@ -29,6 +31,7 @@ import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
/**
*
@ -75,4 +78,8 @@ public class ElasticHostsBlueSquareLondonTemplateBuilderLiveTest extends BaseTem
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("GB-LND");
}
}

View File

@ -21,6 +21,7 @@ package org.jclouds.elastichosts;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import java.util.Properties;
@ -35,6 +36,7 @@ public class ElasticHostsPeer1LondonPropertiesBuilder extends ElasticStackProper
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "GB-LND");
properties.setProperty(PROPERTY_ENDPOINT, "https://api.lon-p.elastichosts.com");
properties.setProperty(PROPERTY_API_VERSION, "1.0");
return properties;

View File

@ -22,6 +22,8 @@ package org.jclouds.elastichosts.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
@ -29,6 +31,7 @@ import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
/**
*
@ -75,4 +78,8 @@ public class ElasticHostsPeer1LondonTemplateBuilderLiveTest extends BaseTemplate
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("GB-LND");
}
}

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