switched keystone-backed providers and apis to strictly return a single scope of location

This commit is contained in:
Adrian Cole 2012-07-02 15:23:52 -07:00
parent ef9a69e7c3
commit 17fce87661
10 changed files with 133 additions and 20 deletions

View File

@ -55,6 +55,7 @@ import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
import org.jclouds.openstack.nova.v2_0.predicates.ImagePredicates;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.cache.LoadingCache;
@ -155,8 +156,26 @@ public class NovaComputeServiceAdapter implements
public Iterable<ImageInZone> listImages() {
Builder<ImageInZone> builder = ImmutableSet.builder();
for (final String zoneId : zoneIds.get()) {
builder.addAll(transform(filter(novaClient.getImageClientForZone(zoneId).listImagesInDetail(), ImagePredicates
.statusEquals(Image.Status.ACTIVE)), new Function<Image, ImageInZone>() {
Set<Image> images = novaClient.getImageClientForZone(zoneId).listImagesInDetail();
if (images.size() == 0) {
logger.debug("no images found in zone %s", zoneId);
continue;
}
Iterable<Image> active = filter(images, ImagePredicates.statusEquals(Image.Status.ACTIVE));
if (images.size() == 0) {
logger.debug("no images with status active in zone %s; non-active: %s", zoneId,
transform(active, new Function<Image, String>() {
@Override
public String apply(Image input) {
return Objects.toStringHelper("").add("id", input.getId()).add("status", input.getStatus())
.toString();
}
}));
continue;
}
builder.addAll(transform(active, new Function<Image, ImageInZone>() {
@Override
public ImageInZone apply(Image arg0) {

View File

@ -124,7 +124,7 @@ public class NovaComputeServiceContextModule extends
// we aren't converting location from a provider-specific type
bind(new TypeLiteral<Function<Location, Location>>() {
}).to((Class) IdentityFunction.class);
}).to(Class.class.cast(IdentityFunction.class));
bind(TemplateOptions.class).to(NovaTemplateOptions.class);

View File

@ -30,7 +30,9 @@ 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.location.suppliers.implicit.OnlyLocationOrFirstZone;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.all.ZoneToProvider;
import org.jclouds.location.suppliers.implicit.FirstZone;
import org.jclouds.openstack.nova.v2_0.NovaAsyncClient;
import org.jclouds.openstack.nova.v2_0.NovaClient;
import org.jclouds.openstack.nova.v2_0.domain.Extension;
@ -125,7 +127,8 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON);
bind(ImplicitLocationSupplier.class).to(FirstZone.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(ZoneToProvider.class).in(Scopes.SINGLETON);
}
@Provides

View File

@ -26,6 +26,10 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.openstack.glance.v1_0.GlanceAsyncClient;
import org.jclouds.openstack.glance.v1_0.GlanceClient;
import org.jclouds.openstack.glance.v1_0.features.ImageAsyncClient;
@ -35,6 +39,7 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
/**
* Configures the Glance connection.
@ -57,7 +62,14 @@ public class GlanceRestClientModule extends RestClientModule<GlanceClient, Glanc
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(GlanceErrorHandler.class);

View File

@ -26,6 +26,10 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.openstack.quantum.v1_0.QuantumAsyncClient;
import org.jclouds.openstack.quantum.v1_0.QuantumClient;
import org.jclouds.openstack.quantum.v1_0.features.NetworkAsyncClient;
@ -37,6 +41,7 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
/**
* Configures the Quantum connection.
@ -60,7 +65,14 @@ public class QuantumRestClientModule extends RestClientModule<QuantumClient, Qua
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(QuantumErrorHandler.class);

View File

@ -26,6 +26,10 @@ import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.openstack.swift.v1.SwiftAsyncClient;
import org.jclouds.openstack.swift.v1.SwiftClient;
import org.jclouds.openstack.swift.v1.features.AccountAsyncClient;
@ -39,6 +43,7 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
/**
* Configures the Swift connection.
@ -63,6 +68,13 @@ public class SwiftRestClientModule extends RestClientModule<SwiftClient, SwiftAs
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
}
@Override
protected void bindErrorHandlers() {

View File

@ -18,19 +18,18 @@
*/
package org.jclouds.rackspace.cloudservers.us;
import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
import java.net.URI;
import java.util.Properties;
import org.jclouds.openstack.nova.v2_0.NovaApiMetadata;
import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.internal.BaseProviderMetadata;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule.CloudIdentityAuthenticationModuleForZones;
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes;
import org.jclouds.rackspace.cloudservers.us.config.CloudServersUSComputeServiceContextModule;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
@ -65,8 +64,6 @@ public class CloudServersUSProviderMetadata extends BaseProviderMetadata {
public static Properties defaultProperties() {
Properties properties = new Properties();
properties.setProperty(CREDENTIAL_TYPE, CloudIdentityCredentialTypes.API_KEY_CREDENTIALS);
properties.setProperty(TEMPLATE, "imageId=DFW/3afe97b2-26dc-49c5-a2cc-a2fc8d80c001,loginUser=root");
return properties;
}
@ -80,7 +77,7 @@ public class CloudServersUSProviderMetadata extends BaseProviderMetadata {
.credentialName("API Key")
.version("2")
.documentation(URI.create("http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_preface.html#webhelp-currentid"))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(CloudIdentityAuthenticationModuleForZones.class, NovaRestClientModule.class, NovaComputeServiceContextModule.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(CloudIdentityAuthenticationModuleForZones.class, NovaRestClientModule.class, CloudServersUSComputeServiceContextModule.class))
.build())
.homepage(URI.create("http://www.rackspace.com/cloud/nextgen"))
.console(URI.create("https://mycloud.rackspace.com"))

View File

@ -0,0 +1,45 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.rackspace.cloudservers.us.config;
import java.util.Map;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
/**
*
* @author Adrian Cole
*/
public class CloudServersUSComputeServiceContextModule extends NovaComputeServiceContextModule {
/**
* CloudServers images are accessible via the root user, not ubuntu
*/
@Override
protected Map<OsFamily, LoginCredentials> osFamilyToCredentials(Injector injector) {
return ImmutableMap.of(OsFamily.WINDOWS, LoginCredentials.builder().user("Administrator").build(),
OsFamily.UBUNTU, LoginCredentials.builder().user("root").build());
}
}

View File

@ -53,14 +53,16 @@ public class CloudServersUSTemplateBuilderLiveTest extends BaseTemplateBuilderLi
public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) {
case UBUNTU:
return (input.version.equals("") || (input.version.matches("^1[01].*") && !input.version
return (input.version.equals("") || (input.version.matches("^1[012].*") && !input.version
.equals("10.10")))
&& input.is64Bit;
case DEBIAN:
return input.is64Bit && !input.version.equals("5.0");
case CENTOS:
return (input.version.equals("") || input.version.equals("5.6") || input.version.equals("6.0"))
return (input.version.equals("") || input.version.equals("5.0")|| input.version.equals("5.6") || input.version.equals("6.0"))
&& input.is64Bit;
case WINDOWS:
return input.is64Bit && input.version.equals("");
default:
return false;
}
@ -73,15 +75,15 @@ public class CloudServersUSTemplateBuilderLiveTest extends BaseTemplateBuilderLi
public void testTemplateBuilder() {
Template defaultTemplate = this.view.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "11.10");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "12.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getImage().getName(), "Ubuntu 11.10");
assertEquals(defaultTemplate.getImage().getName(), "Ubuntu 12.04 LTS");
assertEquals(defaultTemplate.getImage().getDefaultCredentials().getUser(), "root");
assertEquals(defaultTemplate.getLocation().getId(), "DFW");
assertEquals(defaultTemplate.getImage().getLocation().getId(), "DFW");
assertEquals(defaultTemplate.getHardware().getLocation().getId(), "DFW");
assertEquals(defaultTemplate.getOptions().as(NovaTemplateOptions.class).shouldAutoAssignFloatingIp(), true);
assertEquals(getCores(defaultTemplate.getHardware()), 4.0d);
assertEquals(defaultTemplate.getOptions().as(NovaTemplateOptions.class).shouldAutoAssignFloatingIp(), false);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override

View File

@ -31,7 +31,11 @@ import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNAsyncClient;
import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient;
import org.jclouds.hpcloud.services.HPExtensionCDN;
import org.jclouds.hpcloud.services.HPExtensionServiceType;
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
import org.jclouds.location.suppliers.LocationsSupplier;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.location.suppliers.all.RegionToProvider;
import org.jclouds.location.suppliers.implicit.FirstRegion;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.config.SwiftRestClientModule;
@ -63,7 +67,14 @@ public class HPCloudObjectStorageRestClientModule extends
bind(CommonSwiftClient.class).to(HPCloudObjectStorageClient.class).in(Scopes.SINGLETON);
bind(CommonSwiftAsyncClient.class).to(HPCloudObjectStorageAsyncClient.class).in(Scopes.SINGLETON);
}
@Override
protected void installLocations() {
super.installLocations();
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
}
@Provides
@Singleton
@HPExtensionCDN