Skip to content

Commit

Permalink
Issue 418: updated location object to include metadata and iso3166codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Jan 31, 2011
1 parent 3263d22 commit 675563c
Show file tree
Hide file tree
Showing 158 changed files with 2,045 additions and 1,526 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,17 +33,9 @@
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;

Expand All @@ -64,24 +52,10 @@ protected void configure() {
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>>() {
}).in(Scopes.SINGLETON);
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());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

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;

Expand All @@ -49,6 +49,6 @@ protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier()

@Override
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return SupplyPredefinedRegions.class;
return JustProvider.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.jclouds.cloudservers.compute.config;

import java.util.Map;
import java.util.Set;

import javax.inject.Singleton;

Expand All @@ -41,8 +40,6 @@
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;

Expand Down Expand Up @@ -82,8 +79,6 @@ protected void configure() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
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;
Expand All @@ -41,11 +43,9 @@
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;
Expand All @@ -60,7 +60,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;

protected final Supplier<Location> location;
protected final Map<String, Credentials> credentialStore;
protected final Map<ServerStatus, NodeState> serverToNodeState;
Expand Down Expand Up @@ -109,7 +109,8 @@ public NodeMetadata apply(Server from) {
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() + "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@

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;
Expand All @@ -42,20 +42,14 @@
*/
@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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
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;
Expand All @@ -38,12 +42,8 @@
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;
Expand All @@ -56,7 +56,7 @@
*/
@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 {
Expand All @@ -68,18 +68,16 @@ public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws U
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());
}

Expand All @@ -99,9 +97,8 @@ public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException
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());

}
Expand All @@ -125,9 +122,8 @@ public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostExce
"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());

}
Expand All @@ -154,9 +150,8 @@ public void testApplyWhereImageAndHardwareFound() throws UnknownHostException {
.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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
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;
Expand Down Expand Up @@ -116,8 +116,8 @@ public boolean apply(Location input) {
}));
} 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();
Expand Down
Loading

0 comments on commit 675563c

Please sign in to comment.