gogrid related changes for Issue 826

This commit is contained in:
Adrian Cole 2012-02-02 07:42:27 -08:00
parent 6dfe726dfa
commit c32d72084e
4 changed files with 24 additions and 20 deletions

View File

@ -43,7 +43,6 @@ import org.jclouds.gogrid.compute.functions.ServerImageToImage;
import org.jclouds.gogrid.compute.functions.ServerToNodeMetadata;
import org.jclouds.gogrid.compute.options.GoGridTemplateOptions;
import org.jclouds.gogrid.compute.strategy.GoGridComputeServiceAdapter;
import org.jclouds.gogrid.compute.suppliers.GoGridDefaultLocationSupplier;
import org.jclouds.gogrid.domain.Option;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.domain.ServerImage;
@ -51,7 +50,6 @@ import org.jclouds.gogrid.domain.ServerState;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Provides;
@ -93,11 +91,10 @@ public class GoGridComputeServiceContextModule extends
bind(new TypeLiteral<Function<Hardware, Hardware>>() {
}).to((Class) IdentityFunction.class);
// there are no locations except the provider
bind(new TypeLiteral<Supplier<Location>>() {
}).to(GoGridDefaultLocationSupplier.class);
bind(TemplateOptions.class).to(GoGridTemplateOptions.class);
// to have the compute service adapter override default locations
install(new LocationsFromComputeServiceAdapterModule<Server, Hardware, ServerImage, Option>(){});
}
@VisibleForTesting

View File

@ -20,7 +20,6 @@ package org.jclouds.gogrid.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
@ -32,10 +31,10 @@ import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.gogrid.domain.Option;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.location.suppliers.all.JustProvider;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
@ -43,25 +42,24 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole
*/
@Singleton
public class OptionToLocation extends JustProvider implements Function<Option, Location> {
private final Map<String, Set<String>> isoCodesById;
public class OptionToLocation implements Function<Option, Location> {
private final Location provider;
private final Supplier<Map<String, Supplier<Set<String>>>> isoCodesByIdSupplier;
@Inject
OptionToLocation(@Iso3166 Set<String> isoCodes, @Provider String providerName, @Provider URI endpoint,
@Iso3166 Map<String, Set<String>> isoCodesById) {
super(providerName, endpoint, isoCodes);
this.provider = Iterables.getOnlyElement(super.get());
this.isoCodesById = checkNotNull(isoCodesById, "isoCodesById");
OptionToLocation(JustProvider justProvider,
@Iso3166 Supplier<Map<String, Supplier<Set<String>>>> isoCodesByIdSupplier) {
this.provider = Iterables.getOnlyElement(justProvider.get());
this.isoCodesByIdSupplier = checkNotNull(isoCodesByIdSupplier, "isoCodesByIdSupplier");
}
@Override
public Location apply(Option from) {
LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(from.getId() + "").description(
from.getDescription()).parent(provider);
Map<String, Supplier<Set<String>>> isoCodesById = isoCodesByIdSupplier.get();
if (isoCodesById.containsKey(from.getId() + ""))
builder.iso3166Codes(isoCodesById.get(from.getId() + ""));
builder.iso3166Codes(isoCodesById.get(from.getId() + "").get());
return builder.build();
}
}

View File

@ -29,6 +29,7 @@ import org.jclouds.date.TimeStamp;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.handlers.GoGridErrorHandler;
import org.jclouds.gogrid.location.GoGridDefaultLocationSupplier;
import org.jclouds.gogrid.services.GridImageAsyncClient;
import org.jclouds.gogrid.services.GridImageClient;
import org.jclouds.gogrid.services.GridIpAsyncClient;
@ -44,6 +45,7 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
@ -51,6 +53,7 @@ import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides;
import com.google.inject.Scopes;
/**
* Configures the GoGrid connection.
@ -105,4 +108,9 @@ public class GoGridRestClientModule extends RestClientModule<GoGridClient, GoGri
super.configure();
}
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(GoGridDefaultLocationSupplier.class).in(Scopes.SINGLETON);
}
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.gogrid.compute.suppliers;
package org.jclouds.gogrid.location;
import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC;
@ -28,6 +28,7 @@ import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
@ -38,7 +39,7 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole
*/
@Singleton
public class GoGridDefaultLocationSupplier implements Supplier<Location> {
public class GoGridDefaultLocationSupplier implements ImplicitLocationSupplier {
private final Supplier<Set<? extends Location>> locations;
private final String defaultDC;