openstack-nova: allowing extension of the standard extensions by providers

This commit is contained in:
Adam Lowe 2012-08-10 11:06:49 +01:00 committed by Andrew Donald Kennedy
parent 9981eee038
commit 4fad770eaf
22 changed files with 63 additions and 55 deletions

View File

@ -100,98 +100,98 @@ public interface NovaApi {
* Provides synchronous access to Floating IP features.
*/
@Delegate
Optional<FloatingIPApi> getFloatingIPExtensionForZone(
Optional<? extends FloatingIPApi> getFloatingIPExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Security Group features.
*/
@Delegate
Optional<SecurityGroupApi> getSecurityGroupExtensionForZone(
Optional<? extends SecurityGroupApi> getSecurityGroupExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Key Pair features.
*/
@Delegate
Optional<KeyPairApi> getKeyPairExtensionForZone(
Optional<? extends KeyPairApi> getKeyPairExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Host Administration features.
*/
@Delegate
Optional<HostAdministrationApi> getHostAdministrationExtensionForZone(
Optional<? extends HostAdministrationApi> getHostAdministrationExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Simple Tenant Usage features.
*/
@Delegate
Optional<SimpleTenantUsageApi> getSimpleTenantUsageExtensionForZone(
Optional<? extends SimpleTenantUsageApi> getSimpleTenantUsageExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Volume features.
*/
@Delegate
Optional<VolumeApi> getVolumeExtensionForZone(
Optional<? extends VolumeApi> getVolumeExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Virtual Interface features.
*/
@Delegate
Optional<VirtualInterfaceApi> getVirtualInterfaceExtensionForZone(
Optional<? extends VirtualInterfaceApi> getVirtualInterfaceExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Server Extra Data features.
*/
@Delegate
Optional<ServerWithSecurityGroupsApi> getServerWithSecurityGroupsExtensionForZone(
Optional<? extends ServerWithSecurityGroupsApi> getServerWithSecurityGroupsExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Server Admin Actions features.
*/
@Delegate
Optional<AdminActionsApi> getAdminActionsExtensionForZone(
Optional<? extends AdminActionsApi> getAdminActionsExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Aggregate features.
*/
@Delegate
Optional<HostAggregateApi> getHostAggregateExtensionForZone(
Optional<? extends HostAggregateApi> getHostAggregateExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Flavor extra specs features.
*/
@Delegate
Optional<FlavorExtraSpecsApi> getFlavorExtraSpecsExtensionForZone(
Optional<? extends FlavorExtraSpecsApi> getFlavorExtraSpecsExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Quota features.
*/
@Delegate
Optional<QuotaApi> getQuotaExtensionForZone(
Optional<? extends QuotaApi> getQuotaExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Quota Classes features.
*/
@Delegate
Optional<QuotaClassApi> getQuotaClassExtensionForZone(
Optional<? extends QuotaClassApi> getQuotaClassExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Volume Type features.
*/
@Delegate
Optional<VolumeTypeApi> getVolumeTypeExtensionForZone(
Optional<? extends VolumeTypeApi> getVolumeTypeExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
}

View File

@ -98,49 +98,49 @@ public interface NovaAsyncApi {
* Provides asynchronous access to Floating IP features.
*/
@Delegate
Optional<FloatingIPAsyncApi> getFloatingIPExtensionForZone(
Optional<? extends FloatingIPAsyncApi> getFloatingIPExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Security Group features.
*/
@Delegate
Optional<SecurityGroupAsyncApi> getSecurityGroupExtensionForZone(
Optional<? extends SecurityGroupAsyncApi> getSecurityGroupExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Key Pair features.
*/
@Delegate
Optional<KeyPairAsyncApi> getKeyPairExtensionForZone(
Optional<? extends KeyPairAsyncApi> getKeyPairExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Host Administration features.
*/
@Delegate
Optional<HostAdministrationAsyncApi> getHostAdministrationExtensionForZone(
Optional<? extends HostAdministrationAsyncApi> getHostAdministrationExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Simple Tenant Usage features.
*/
@Delegate
Optional<SimpleTenantUsageAsyncApi> getSimpleTenantUsageExtensionForZone(
Optional<? extends SimpleTenantUsageAsyncApi> getSimpleTenantUsageExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Volume features.
*/
@Delegate
Optional<VolumeAsyncApi> getVolumeExtensionForZone(
Optional<? extends VolumeAsyncApi> getVolumeExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Virtual Interface features.
*/
@Delegate
Optional<VirtualInterfaceAsyncApi> getVirtualInterfaceExtensionForZone(
Optional<? extends VirtualInterfaceAsyncApi> getVirtualInterfaceExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
@ -148,49 +148,49 @@ public interface NovaAsyncApi {
* Provides asynchronous access to Server Extra Data features.
*/
@Delegate
Optional<ServerWithSecurityGroupsAsyncApi> getServerWithSecurityGroupsExtensionForZone(
Optional<? extends ServerWithSecurityGroupsAsyncApi> getServerWithSecurityGroupsExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Server Admin Actions features.
*/
@Delegate
Optional<AdminActionsAsyncApi> getAdminActionsExtensionForZone(
Optional<? extends AdminActionsAsyncApi> getAdminActionsExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to HostAggregate features.
*/
@Delegate
Optional<HostAggregateAsyncApi> getHostAggregateExtensionForZone(
Optional<? extends HostAggregateAsyncApi> getHostAggregateExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Flavor extra specs features.
*/
@Delegate
Optional<FlavorExtraSpecsAsyncApi> getFlavorExtraSpecsExtensionForZone(
Optional<? extends FlavorExtraSpecsAsyncApi> getFlavorExtraSpecsExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Quota features.
*/
@Delegate
Optional<QuotaAsyncApi> getQuotaExtensionForZone(
Optional<? extends QuotaAsyncApi> getQuotaExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Quota Classes features.
*/
@Delegate
Optional<QuotaClassAsyncApi> getQuotaClassExtensionForZone(
Optional<? extends QuotaClassAsyncApi> getQuotaClassExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Volume Type features.
*/
@Delegate
Optional<VolumeTypeAsyncApi> getVolumeTypeExtensionForZone(
Optional<? extends VolumeTypeAsyncApi> getVolumeTypeExtensionForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
}

View File

@ -135,7 +135,7 @@ public class NovaComputeService extends BaseComputeService {
}
private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) {
Optional<SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId);
Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId);
if (securityGroupApi.isPresent()) {
for (String group : groups) {
for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().listSecurityGroups(),
@ -152,7 +152,7 @@ public class NovaComputeService extends BaseComputeService {
}
private void cleanupOrphanedKeyPairsInZone(Set<String> groups, String zoneId) {
Optional<KeyPairApi> keyPairApi = novaApi.getKeyPairExtensionForZone(zoneId);
Optional<? extends KeyPairApi> keyPairApi = novaApi.getKeyPairExtensionForZone(zoneId);
if (keyPairApi.isPresent()) {
for (String group : groups) {
for (Map<String, KeyPair> view : keyPairApi.get().listKeyPairs()) {

View File

@ -62,7 +62,7 @@ public class CreateSecurityGroupIfNeeded implements Function<ZoneSecurityGroupNa
checkNotNull(zoneSecurityGroupNameAndPorts, "zoneSecurityGroupNameAndPorts");
String zoneId = zoneSecurityGroupNameAndPorts.getZone();
Optional<SecurityGroupApi> api = novaApi.getSecurityGroupExtensionForZone(zoneId);
Optional<? extends SecurityGroupApi> api = novaApi.getSecurityGroupExtensionForZone(zoneId);
checkArgument(api.isPresent(), "Security groups are required, but the extension is not availablein zone %s!", zoneId);
logger.debug(">> creating securityGroup %s", zoneSecurityGroupNameAndPorts);
try {

View File

@ -59,7 +59,7 @@ public class CreateUniqueKeyPair extends CacheLoader<ZoneAndName, KeyPair> {
String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone();
String prefix = zoneAndName.getName();
Optional<KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId);
Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId);
checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!",
zoneId);

View File

@ -51,7 +51,7 @@ public class LoadFloatingIpsForInstance extends CacheLoader<ZoneAndId, Iterable<
@Override
public Iterable<FloatingIP> load(final ZoneAndId key) throws Exception {
String zone = key.getZone();
Optional<FloatingIPApi> ipApiOptional = api.getFloatingIPExtensionForZone(zone);
Optional<? extends FloatingIPApi> ipApiOptional = api.getFloatingIPExtensionForZone(zone);
if (ipApiOptional.isPresent()) {
return Iterables.filter(ipApiOptional.get().listFloatingIPs(),
new Predicate<FloatingIP>() {

View File

@ -62,7 +62,7 @@ public class FindSecurityGroupWithNameAndReturnTrue implements Predicate<AtomicR
checkNotNull(securityGroupInZoneRef, "securityGroupRef");
final ZoneAndName securityGroupInZone = checkNotNull(securityGroupInZoneRef.get(), "securityGroupInZone");
Optional<SecurityGroupApi> api = novaApi.getSecurityGroupExtensionForZone(securityGroupInZone.getZone());
Optional<? extends SecurityGroupApi> api = novaApi.getSecurityGroupExtensionForZone(securityGroupInZone.getZone());
checkArgument(api.isPresent(), "Security groups are required, but the extension is not available!");
logger.trace("looking for security group %s", securityGroupInZone.slashEncode());

View File

@ -52,7 +52,9 @@ public class CreateUniqueKeyPairTest {
KeyPair pair = createMock(KeyPair.class);
expect(api.getKeyPairExtensionForZone("zone")).andReturn(Optional.of(keyApi)).atLeastOnce();
Optional optKeyApi = Optional.of(keyApi);
expect(api.getKeyPairExtensionForZone("zone")).andReturn(optKeyApi).atLeastOnce();
expect(keyApi.createKeyPair("group-1")).andReturn(pair);
@ -83,7 +85,7 @@ public class CreateUniqueKeyPairTest {
KeyPair pair = createMock(KeyPair.class);
expect(api.getKeyPairExtensionForZone("zone")).andReturn(Optional.of(keyApi)).atLeastOnce();
expect(api.getKeyPairExtensionForZone("zone")).andReturn((Optional) Optional.of(keyApi)).atLeastOnce();
expect(uniqueIdSupplier.get()).andReturn("1");
expect(keyApi.createKeyPair("group-1")).andThrow(new IllegalStateException());

View File

@ -46,7 +46,7 @@ public class LoadFloatingIpsForInstanceTest {
FloatingIPApi ipApi = createMock(FloatingIPApi.class);
FloatingIP testIp = FloatingIP.builder().id("1").ip("1.1.1.1").fixedIp("10.1.1.1").instanceId("i-blah").build();
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn(Optional.of(ipApi)).atLeastOnce();
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
expect(ipApi.listFloatingIPs()).andReturn(ImmutableSet.<FloatingIP>of(testIp)).atLeastOnce();
replay(api);
@ -65,7 +65,7 @@ public class LoadFloatingIpsForInstanceTest {
NovaApi api = createMock(NovaApi.class);
FloatingIPApi ipApi = createMock(FloatingIPApi.class);
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn(Optional.of(ipApi)).atLeastOnce();
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
expect(ipApi.listFloatingIPs()).andReturn(ImmutableSet.<FloatingIP>of()).atLeastOnce();
@ -86,7 +86,7 @@ public class LoadFloatingIpsForInstanceTest {
NovaApi api = createMock(NovaApi.class);
FloatingIPApi ipApi = createMock(FloatingIPApi.class);
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn(Optional.of(ipApi)).atLeastOnce();
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
expect(ipApi.listFloatingIPs()).andReturn(
ImmutableSet.<FloatingIP>of(FloatingIP.builder().id("1").ip("1.1.1.1").build()))

View File

@ -53,7 +53,7 @@ public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
private ImageApi imageApi;
private ServerApi serverApi;
private ExtensionApi extensionApi;
private Optional<AdminActionsApi> apiOption;
private Optional<? extends AdminActionsApi> apiOption;
private String zone;
private String testServerId;

View File

@ -44,7 +44,7 @@ import com.google.common.collect.Maps;
@Test(groups = "live", testName = "FlavorExtraSpecsApiLiveTest", singleThreaded = true)
public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest {
private FlavorApi flavorApi;
private Optional<FlavorExtraSpecsApi> apiOption;
private Optional<? extends FlavorExtraSpecsApi> apiOption;
private String zone;
private Resource testFlavor;

View File

@ -48,7 +48,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
@Test
public void testListFloatingIPs() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) {
Optional<FloatingIPApi> apiOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId);
Optional<? extends FloatingIPApi> apiOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId);
if (!apiOption.isPresent())
continue;
FloatingIPApi api = apiOption.get();
@ -70,7 +70,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
@Test
public void testAllocateAndDeallocateFloatingIPs() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) {
Optional<FloatingIPApi> apiOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId);
Optional<? extends FloatingIPApi> apiOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId);
if (!apiOption.isPresent())
continue;
FloatingIPApi api = apiOption.get();
@ -101,7 +101,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
@Test
public void testAddAndRemoveFloatingIp() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) {
Optional<FloatingIPApi> apiOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId);
Optional<? extends FloatingIPApi> apiOption = novaContext.getApi().getFloatingIPExtensionForZone(zoneId);
if (!apiOption.isPresent())
continue;
FloatingIPApi api = apiOption.get();

View File

@ -42,7 +42,7 @@ import com.google.common.collect.Iterables;
*/
@Test(groups = "live", testName = "HostAdministrationApiLiveTest", singleThreaded = true)
public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest {
private Optional<HostAdministrationApi> optApi = Optional.absent();
private Optional<? extends HostAdministrationApi> optApi = Optional.absent();
Predicate<Host> isComputeHost = new Predicate<Host>() {
@Override

View File

@ -44,8 +44,8 @@ import com.google.common.collect.Iterables;
*/
@Test(groups = "live", testName = "AggregateApiLiveTest", singleThreaded = true)
public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest {
private Optional<HostAggregateApi> apiOption;
private Optional<HostAdministrationApi> hostAdminOption;
private Optional<? extends HostAggregateApi> apiOption;
private Optional<? extends HostAdministrationApi> hostAdminOption;
private HostAggregate testAggregate;

View File

@ -36,7 +36,7 @@ import com.google.common.collect.Iterables;
*/
@Test(groups = "live", testName = "QuotaApiLiveTest", singleThreaded = true)
public class QuotaApiLiveTest extends BaseNovaApiLiveTest {
private Optional<QuotaApi> apiOption;
private Optional<? extends QuotaApi> apiOption;
private String tenant;
@BeforeClass(groups = {"integration", "live"})

View File

@ -36,7 +36,7 @@ import com.google.common.collect.Iterables;
*/
@Test(groups = "live", testName = "QuotaClassApiLiveTest", singleThreaded = true)
public class QuotaClassApiLiveTest extends BaseNovaApiLiveTest {
private Optional<QuotaClassApi> apiOption;
private Optional<? extends QuotaClassApi> apiOption;
private String zone;
@BeforeClass(groups = {"integration", "live"})

View File

@ -41,7 +41,7 @@ import com.google.common.collect.Iterables;
@Test(groups = "live", testName = "ServerWithSecurityGroupsApiLiveTest", singleThreaded = true)
public class ServerWithSecurityGroupsApiLiveTest extends BaseNovaApiLiveTest {
private ServerApi serverApi;
private Optional<ServerWithSecurityGroupsApi> apiOption;
private Optional<? extends ServerWithSecurityGroupsApi> apiOption;
private String zone;
@BeforeGroups(groups = {"integration", "live"})

View File

@ -38,7 +38,7 @@ public class SimpleTenantUsageApiLiveTest extends BaseNovaApiLiveTest {
public void testList() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) {
Optional<SimpleTenantUsageApi> optApi = novaContext.getApi().getSimpleTenantUsageExtensionForZone(zoneId);
Optional<? extends SimpleTenantUsageApi> optApi = novaContext.getApi().getSimpleTenantUsageExtensionForZone(zoneId);
if (optApi.isPresent() && identity.endsWith(":admin")) {
SimpleTenantUsageApi api = optApi.get();
Set<SimpleTenantUsage> usages = api.listTenantUsages();

View File

@ -38,7 +38,7 @@ import com.google.common.collect.Iterables;
*/
@Test(groups = "live", testName = "VirtualInterfaceApiLiveTest", singleThreaded = true)
public class VirtualInterfaceApiLiveTest extends BaseNovaApiLiveTest {
private Optional<VirtualInterfaceApi> apiOption;
private Optional<? extends VirtualInterfaceApi> apiOption;
private String zone;

View File

@ -48,7 +48,7 @@ import com.google.common.collect.Iterables;
@Test(groups = "live", testName = "VolumeApiLiveTest", singleThreaded = true)
public class VolumeApiLiveTest extends BaseNovaApiLiveTest {
private Optional<VolumeApi> volumeOption;
private Optional<? extends VolumeApi> volumeOption;
private String zone;
private Volume testVolume;

View File

@ -46,7 +46,7 @@ import com.google.common.collect.Iterables;
@Test(groups = "live", testName = "VolumeTypeApiLiveTest", singleThreaded = true)
public class VolumeTypeApiLiveTest extends BaseNovaApiLiveTest {
private Optional<VolumeTypeApi> volumeTypeOption;
private Optional<? extends VolumeTypeApi> volumeTypeOption;
private String zone;
private VolumeType testVolumeType;

View File

@ -20,6 +20,8 @@ package org.jclouds.util;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import com.google.common.base.Optional;
@ -35,7 +37,11 @@ public class Optionals2 {
if (optional) {
ParameterizedType futureType = ParameterizedType.class.cast(method.getGenericReturnType());
// TODO: error checking in case this is a type, not a class.
syncClass = Class.class.cast(futureType.getActualTypeArguments()[0]);
Type t = futureType.getActualTypeArguments()[0];
if (t instanceof WildcardType) {
t = ((WildcardType) t).getUpperBounds()[0];
}
syncClass = Class.class.cast(t);
} else {
syncClass = method.getReturnType();
}