mirror of https://github.com/apache/jclouds.git
cleanup of module binding, clarity in toStrings, reduced wrapper depth for memoized sets
This commit is contained in:
parent
07240f3e77
commit
fb98ce82f7
|
@ -48,10 +48,10 @@ import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
|
|||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -94,7 +94,7 @@ public class CloudLoadBalancersRestClientModule extends
|
|||
@Singleton
|
||||
@Named(RackspaceConstants.PROPERTY_ACCOUNT_ID)
|
||||
protected Supplier<String> accountID(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
|
||||
return Suppliers.compose(new Function<URI, String>() {
|
||||
return Suppliers2.compose(new Function<URI, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(URI arg0) {
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.compute.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -26,7 +25,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
@ -56,7 +54,6 @@ import org.jclouds.cloudstack.functions.GetFirewallRulesByVirtualMachine;
|
|||
import org.jclouds.cloudstack.functions.GetIPForwardingRulesByVirtualMachine;
|
||||
import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork;
|
||||
import org.jclouds.cloudstack.functions.ZoneIdToZone;
|
||||
import org.jclouds.cloudstack.options.ListFirewallRulesOptions;
|
||||
import org.jclouds.cloudstack.predicates.JobComplete;
|
||||
import org.jclouds.cloudstack.suppliers.GetCurrentUser;
|
||||
import org.jclouds.cloudstack.suppliers.NetworksForCurrentUser;
|
||||
|
@ -70,17 +67,16 @@ import org.jclouds.compute.options.TemplateOptions;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
@ -127,14 +123,18 @@ public class CloudStackComputeServiceContextModule extends
|
|||
@Memoized
|
||||
public Supplier<Map<String, String>> listOSCategories(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final CloudStackClient client) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException,
|
||||
seconds, new Supplier<Map<String, String>>() {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
new Supplier<Map<String, String>>() {
|
||||
@Override
|
||||
public Map<String, String> get() {
|
||||
GuestOSClient guestOSClient = client.getGuestOSClient();
|
||||
return guestOSClient.listOSCategories();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(client.getGuestOSClient()).add("method", "listOSCategories").toString();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -142,8 +142,8 @@ public class CloudStackComputeServiceContextModule extends
|
|||
@Memoized
|
||||
public Supplier<Map<String, OSType>> listOSTypes(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final CloudStackClient client) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, OSType>>(authException,
|
||||
seconds, new Supplier<Map<String, OSType>>() {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
new Supplier<Map<String, OSType>>() {
|
||||
@Override
|
||||
public Map<String, OSType> get() {
|
||||
GuestOSClient guestOSClient = client.getGuestOSClient();
|
||||
|
@ -155,7 +155,11 @@ public class CloudStackComputeServiceContextModule extends
|
|||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(client.getGuestOSClient()).add("method", "listOSTypes").toString();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -163,8 +167,8 @@ public class CloudStackComputeServiceContextModule extends
|
|||
@Memoized
|
||||
public Supplier<Map<String, Network>> listNetworks(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final NetworksForCurrentUser networksForCurrentUser) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Network>>(authException,
|
||||
seconds, networksForCurrentUser);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, networksForCurrentUser,
|
||||
seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -172,8 +176,8 @@ public class CloudStackComputeServiceContextModule extends
|
|||
@Memoized
|
||||
public Supplier<User> getCurrentUser(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final GetCurrentUser getCurrentUser) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<User>(authException, seconds,
|
||||
getCurrentUser);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, getCurrentUser,
|
||||
seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -23,6 +23,7 @@ import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
|||
import java.net.URI;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -47,11 +48,12 @@ import org.jclouds.rest.AuthorizationException;
|
|||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
|
@ -81,13 +83,17 @@ public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClien
|
|||
@Singleton
|
||||
protected Supplier<Set<? extends DeltacloudCollection>> provideCollections(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends DeltacloudCollection>>(
|
||||
authException, seconds, new Supplier<Set<? extends DeltacloudCollection>>() {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(
|
||||
authException, new Supplier<Set<? extends DeltacloudCollection>>() {
|
||||
@Override
|
||||
public Set<? extends DeltacloudCollection> get() {
|
||||
return client.getCollections();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(client).add("method", "getCollections").toString();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +103,7 @@ public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClien
|
|||
@Provides
|
||||
@Images
|
||||
protected Supplier<URI> provideImageCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("images"), collectionSupplier);
|
||||
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("images"), collectionSupplier);
|
||||
}
|
||||
|
||||
public static class FindCollectionWithRelAndReturnHref implements Function<Set<? extends DeltacloudCollection>, URI> {
|
||||
|
@ -128,24 +134,24 @@ public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClien
|
|||
@Provides
|
||||
@HardwareProfiles
|
||||
protected Supplier<URI> provideHardwareProfileCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("hardware_profiles"), collectionSupplier);
|
||||
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("hardware_profiles"), collectionSupplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Instances
|
||||
protected Supplier<URI> provideInstanceCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("instances"), collectionSupplier);
|
||||
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("instances"), collectionSupplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Realms
|
||||
protected Supplier<URI> provideRealmCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("realms"), collectionSupplier);
|
||||
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("realms"), collectionSupplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@InstanceStates
|
||||
protected Supplier<URI> provideInstanceStateCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
|
||||
return Suppliers.compose(new FindCollectionWithRelAndReturnHref("instance_states"), collectionSupplier);
|
||||
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("instance_states"), collectionSupplier);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,11 @@ import java.util.Properties;
|
|||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneParserModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule.KeystoneAdminURLModule;
|
||||
import org.jclouds.openstack.v2_0.ServiceType;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.BaseRestApiMetadata;
|
||||
|
@ -85,7 +88,11 @@ public class KeystoneApiMetadata extends BaseRestApiMetadata {
|
|||
.version("2.0")
|
||||
.defaultEndpoint("http://localhost:5000")
|
||||
.defaultProperties(KeystoneApiMetadata.defaultProperties())
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneRestClientModule.class));
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(KeystoneAuthenticationModule.class)
|
||||
.add(KeystoneAdminURLModule.class)
|
||||
.add(KeystoneParserModule.class)
|
||||
.add(KeystoneRestClientModule.class).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,12 +35,18 @@ import org.jclouds.domain.Credentials;
|
|||
import org.jclouds.http.HttpRetryHandler;
|
||||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
|
||||
import org.jclouds.location.suppliers.LocationsSupplier;
|
||||
import org.jclouds.location.suppliers.RegionIdToURISupplier;
|
||||
import org.jclouds.location.suppliers.RegionIdsSupplier;
|
||||
import org.jclouds.location.suppliers.ZoneIdToURISupplier;
|
||||
import org.jclouds.location.suppliers.ZoneIdsSupplier;
|
||||
import org.jclouds.location.suppliers.all.RegionToProvider;
|
||||
import org.jclouds.location.suppliers.all.ZoneToProvider;
|
||||
import org.jclouds.location.suppliers.derived.RegionIdsFromRegionIdToURIKeySet;
|
||||
import org.jclouds.location.suppliers.derived.ZoneIdsFromZoneIdToURIKeySet;
|
||||
import org.jclouds.location.suppliers.implicit.FirstRegion;
|
||||
import org.jclouds.location.suppliers.implicit.FirstZone;
|
||||
import org.jclouds.openstack.keystone.v2_0.AuthenticationAsyncClient;
|
||||
import org.jclouds.openstack.keystone.v2_0.AuthenticationClient;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
||||
|
@ -62,8 +68,8 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
|
||||
/**
|
||||
|
@ -71,25 +77,6 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class KeystoneAuthenticationModule extends AbstractModule {
|
||||
private final Module locationModule;
|
||||
|
||||
public KeystoneAuthenticationModule() {
|
||||
this(new RegionModule());
|
||||
}
|
||||
|
||||
protected KeystoneAuthenticationModule(Module locationModule) {
|
||||
this.locationModule = locationModule;
|
||||
}
|
||||
|
||||
public static class KeystoneAuthenticationModuleForRegions extends KeystoneAuthenticationModule {
|
||||
public KeystoneAuthenticationModuleForRegions() {
|
||||
super(new RegionModule());
|
||||
}
|
||||
}
|
||||
|
||||
public static Module forRegions() {
|
||||
return new KeystoneAuthenticationModuleForRegions();
|
||||
}
|
||||
|
||||
public static class RegionModule extends AbstractModule {
|
||||
@Override
|
||||
|
@ -100,6 +87,8 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
|||
RegionIdToAdminURIFromAccessForTypeAndVersion.class).build(RegionIdToAdminURISupplier.Factory.class));
|
||||
// dynamically build the region list as opposed to from properties
|
||||
bind(RegionIdsSupplier.class).to(RegionIdsFromRegionIdToURIKeySet.class);
|
||||
bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON);
|
||||
bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
// supply the region to id map from keystone, based on the servicetype and api version in
|
||||
|
@ -132,6 +121,8 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
|||
ZoneIdToURIFromAccessForTypeAndVersion.class).build(ZoneIdToURISupplier.Factory.class));
|
||||
// dynamically build the zone list as opposed to from properties
|
||||
bind(ZoneIdsSupplier.class).to(ZoneIdsFromZoneIdToURIKeySet.class);
|
||||
bind(ImplicitLocationSupplier.class).to(FirstZone.class).in(Scopes.SINGLETON);
|
||||
bind(LocationsSupplier.class).to(ZoneToProvider.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
// supply the zone to id map from keystone, based on the servicetype and api version in
|
||||
|
@ -146,21 +137,10 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
|||
|
||||
}
|
||||
|
||||
public static class KeystoneAuthenticationModuleForZones extends KeystoneAuthenticationModule {
|
||||
public KeystoneAuthenticationModuleForZones() {
|
||||
super(new ZoneModule());
|
||||
}
|
||||
}
|
||||
|
||||
public static Module forZones() {
|
||||
return new KeystoneAuthenticationModuleForZones();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
||||
bindAuthenticationClient();
|
||||
install(locationModule);
|
||||
}
|
||||
|
||||
protected void bindAuthenticationClient() {
|
||||
|
|
|
@ -61,6 +61,7 @@ public class KeystoneParserModule extends AbstractModule {
|
|||
* Treats [A,B,C] and {"values"=[A,B,C], "someotherstuff"=...} as the same Set
|
||||
*/
|
||||
public static class SetTypeAdapterFactory implements TypeAdapterFactory {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
|
||||
Type type = typeToken.getType();
|
||||
if (typeToken.getRawType() != Set.class || !(type instanceof ParameterizedType)) {
|
||||
|
@ -69,7 +70,7 @@ public class KeystoneParserModule extends AbstractModule {
|
|||
|
||||
Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
|
||||
TypeAdapter<?> elementAdapter = gson.getAdapter(TypeToken.get(elementType));
|
||||
return (TypeAdapter<T>) newSetAdapter(elementAdapter);
|
||||
return TypeAdapter.class.cast(newSetAdapter(elementAdapter));
|
||||
}
|
||||
|
||||
private <E> TypeAdapter<Set<E>> newSetAdapter(final TypeAdapter<E> elementAdapter) {
|
||||
|
|
|
@ -67,15 +67,13 @@ public class KeystoneRestClientModule<S extends KeystoneClient, A extends Keysto
|
|||
RestClientModule<S, A> {
|
||||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
|
||||
.put(ServiceClient.class, ServiceAsyncClient.class)
|
||||
.put(TokenClient.class, TokenAsyncClient.class)
|
||||
.put(UserClient.class, UserAsyncClient.class)
|
||||
.put(TenantClient.class, TenantAsyncClient.class).build();
|
||||
.put(ServiceClient.class, ServiceAsyncClient.class).put(TokenClient.class, TokenAsyncClient.class)
|
||||
.put(UserClient.class, UserAsyncClient.class).put(TenantClient.class, TenantAsyncClient.class).build();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public KeystoneRestClientModule() {
|
||||
super((TypeToken) TypeToken.of(KeystoneClient.class), (TypeToken) TypeToken.of(KeystoneAsyncClient.class),
|
||||
DELEGATE_MAP);
|
||||
super(TypeToken.class.cast(TypeToken.of(KeystoneClient.class)), TypeToken.class.cast(TypeToken
|
||||
.of(KeystoneAsyncClient.class)), DELEGATE_MAP);
|
||||
}
|
||||
|
||||
protected KeystoneRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
|
||||
|
@ -83,23 +81,11 @@ public class KeystoneRestClientModule<S extends KeystoneClient, A extends Keysto
|
|||
super(syncClientType, asyncClientType, sync2Async);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new KeystoneParserModule());
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installLocations() {
|
||||
install(new KeystoneAuthenticationModule(new KeystoneAdminURLModule()));
|
||||
super.installLocations();
|
||||
}
|
||||
|
||||
public static class KeystoneAdminURLModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ImplicitOptionalConverter.class).to(PresentWhenAdminURLExistsForIdentityService.class);
|
||||
bind(ImplicitOptionalConverter.class).to(PresentWhenAdminURLExistsForIdentityService.class);
|
||||
install(new FactoryModuleBuilder().implement(RegionIdToAdminURISupplier.class,
|
||||
RegionIdToAdminURIFromAccessForTypeAndVersion.class).build(RegionIdToAdminURISupplier.Factory.class));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ import java.util.Properties;
|
|||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForZones;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule;
|
||||
import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
|
||||
import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule;
|
||||
import org.jclouds.openstack.v2_0.ServiceType;
|
||||
|
@ -100,7 +101,11 @@ public class NovaApiMetadata extends BaseRestApiMetadata {
|
|||
.defaultEndpoint("http://localhost:5000")
|
||||
.defaultProperties(NovaApiMetadata.defaultProperties())
|
||||
.view(TypeToken.of(ComputeServiceContext.class))
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForZones.class, NovaRestClientModule.class, NovaComputeServiceContextModule.class));
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(KeystoneAuthenticationModule.class)
|
||||
.add(ZoneModule.class)
|
||||
.add(NovaRestClientModule.class)
|
||||
.add(NovaComputeServiceContextModule.class).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.openstack.nova.v2_0.compute;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue;
|
||||
|
@ -155,7 +156,9 @@ public class NovaComputeServiceAdapter implements
|
|||
@Override
|
||||
public Iterable<ImageInZone> listImages() {
|
||||
Builder<ImageInZone> builder = ImmutableSet.builder();
|
||||
for (final String zoneId : zoneIds.get()) {
|
||||
Set<String> zones = zoneIds.get();
|
||||
checkState(zones.size() > 0, "no zones found in supplier %s", zoneIds);
|
||||
for (final String zoneId : zones) {
|
||||
Set<Image> images = novaClient.getImageClientForZone(zoneId).listImagesInDetail();
|
||||
if (images.size() == 0) {
|
||||
logger.debug("no images found in zone %s", zoneId);
|
||||
|
|
|
@ -72,13 +72,13 @@ import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAn
|
|||
import org.jclouds.openstack.nova.v2_0.predicates.FindSecurityGroupWithNameAndReturnTrue;
|
||||
import org.jclouds.predicates.PredicateWithResult;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
@ -200,7 +200,7 @@ public class NovaComputeServiceContextModule extends
|
|||
@Singleton
|
||||
protected Supplier<Map<String, Location>> createLocationIndexedById(
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
return Suppliers2.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.openstack.nova.v2_0.domain.Image.Status;
|
|||
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ImageInZone;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
|
@ -63,4 +64,9 @@ public class ImageInZoneToImage implements Function<ImageInZone, Image> {
|
|||
.userMetadata(image.getMetadata()).operatingSystem(imageToOs.apply(image)).description(image.getName())
|
||||
.location(location).status(toPortableImageStatus.get(image.getStatus())).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,6 @@ import org.jclouds.http.HttpErrorHandler;
|
|||
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.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;
|
||||
|
@ -83,7 +79,6 @@ import com.google.common.cache.CacheLoader;
|
|||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
* Configures the Nova connection.
|
||||
|
@ -124,13 +119,6 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
|
|||
super.configure();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installLocations() {
|
||||
super.installLocations();
|
||||
bind(ImplicitLocationSupplier.class).to(FirstZone.class).in(Scopes.SINGLETON);
|
||||
bind(LocationsSupplier.class).to(ZoneToProvider.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public LoadingCache<String, Set<Extension>> provideExtensionsByZone(final Provider<NovaClient> novaClient) {
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
|||
import org.jclouds.location.suppliers.RegionIdToURISupplier;
|
||||
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
|
||||
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.reference.AuthHeaders;
|
||||
import org.jclouds.openstack.services.ServiceType;
|
||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||
|
@ -62,8 +62,8 @@ public class SwiftRestClientModule<S extends CommonSwiftClient, A extends Common
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SwiftRestClientModule() {
|
||||
this((TypeToken) TypeToken.of(SwiftClient.class), (TypeToken) TypeToken.of(SwiftAsyncClient.class), ImmutableMap
|
||||
.<Class<?>, Class<?>> of());
|
||||
this(TypeToken.class.cast(TypeToken.of(SwiftClient.class)), TypeToken.class.cast(TypeToken
|
||||
.of(SwiftAsyncClient.class)), ImmutableMap.<Class<?>, Class<?>> of());
|
||||
}
|
||||
|
||||
protected SwiftRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
|
||||
|
@ -80,7 +80,7 @@ public class SwiftRestClientModule<S extends CommonSwiftClient, A extends Common
|
|||
}
|
||||
}
|
||||
|
||||
public static class KeystoneStorageEndpointModule extends KeystoneAuthenticationModuleForRegions {
|
||||
public static class KeystoneStorageEndpointModule extends KeystoneAuthenticationModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jclouds.compute.domain.TemplateBuilder;
|
|||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.compute.functions.HardwareForVApp;
|
||||
import org.jclouds.vcloud.compute.functions.HardwareForVAppTemplate;
|
||||
import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate;
|
||||
|
@ -51,7 +52,6 @@ import org.jclouds.vcloud.functions.VAppTemplatesInOrg;
|
|||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -143,7 +143,7 @@ public class VCloudComputeServiceDependenciesModule extends AbstractModule {
|
|||
@Singleton
|
||||
public Supplier<NetworkConfig> networkConfig(@Network Supplier<ReferenceType> network,
|
||||
final FenceMode defaultFenceMode) {
|
||||
return Suppliers.compose(new Function<ReferenceType, NetworkConfig>() {
|
||||
return Suppliers2.compose(new Function<ReferenceType, NetworkConfig>() {
|
||||
|
||||
@Override
|
||||
public NetworkConfig apply(ReferenceType input) {
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.VCloudSession;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
|
@ -34,7 +35,6 @@ import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfig
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -57,7 +57,7 @@ public class DefaultOrgForUser implements Function<String, Supplier<ReferenceTyp
|
|||
|
||||
@Override
|
||||
public Supplier<ReferenceType> apply(final String user) {
|
||||
return Suppliers.compose(new Function<VCloudSession, ReferenceType>() {
|
||||
return Suppliers2.compose(new Function<VCloudSession, ReferenceType>() {
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(VCloudSession session) {
|
||||
|
|
|
@ -27,6 +27,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
|
||||
|
@ -72,7 +73,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
|
||||
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
return Suppliers2.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -80,7 +81,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
|
||||
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
return Suppliers2.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -146,7 +147,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
|
||||
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
return Suppliers2.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -161,7 +162,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
|
||||
@org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
|
||||
return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
return Suppliers2.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.vcloud.config;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.base.Suppliers.compose;
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.getLast;
|
||||
|
@ -35,8 +34,9 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEO
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -58,6 +58,7 @@ import org.jclouds.rest.ConfiguresRestClient;
|
|||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.VCloudToken;
|
||||
|
@ -110,15 +111,15 @@ import org.jclouds.vcloud.predicates.TaskSuccess;
|
|||
import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationSettingDataHandler;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
|
@ -151,15 +152,19 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, final VCloudLoginClient login) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
return login.login();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(login).add("method", "login").toString();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -219,7 +224,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(Supplier<Map<String, Org>> orgNameToOrgSuppier) {
|
||||
return compose(new Function<Map<String, Org>, Map<String, String>>() {
|
||||
return Suppliers2.compose(new Function<Map<String, Org>, Map<String, String>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(Map<String, Org> arg0) {
|
||||
|
@ -239,15 +244,15 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
protected Supplier<Map<String, Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, OrgMapSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Org>>(authException, seconds,
|
||||
supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@OrgList
|
||||
protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
return Suppliers.compose(new Function<VCloudSession, URI>() {
|
||||
return Suppliers2.compose(new Function<VCloudSession, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(VCloudSession arg0) {
|
||||
|
@ -318,7 +323,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Provides
|
||||
@Singleton
|
||||
Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return Suppliers.compose(new Function<VCloudSession, String>() {
|
||||
return Suppliers2.compose(new Function<VCloudSession, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(VCloudSession input) {
|
||||
|
@ -332,8 +337,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -341,8 +346,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
protected Supplier<Map<URI, VDC>> provideURIToVDC(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
URItoVDC supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, VDC>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -411,7 +416,6 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
|
||||
private final Supplier<VCloudSession> sessionSupplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Inject
|
||||
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
|
@ -428,7 +432,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
protected Supplier<Org> provideOrg(final Supplier<Map<String, Org>> orgSupplier,
|
||||
@org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(new Function<ReferenceType, Org>() {
|
||||
return Suppliers2.compose(new Function<ReferenceType, Org>() {
|
||||
|
||||
@Override
|
||||
public Org apply(ReferenceType input) {
|
||||
|
@ -450,8 +454,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
protected Supplier<Map<String, Map<String, Catalog>>> provideOrgCatalogItemMapSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Catalog>>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -459,8 +463,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
protected Supplier<Map<String, Map<String, VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgVDCSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, VDC>>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -533,8 +537,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
protected Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> provideOrgCatalogItemSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogItemSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, CatalogItem>>>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -30,11 +30,11 @@ import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
|||
import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
|
||||
import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -57,7 +57,7 @@ public class DefaultOrgForUser implements Function<String, Supplier<ReferenceTyp
|
|||
|
||||
@Override
|
||||
public Supplier<ReferenceType> apply(final String user) {
|
||||
return Suppliers.compose(new Function<VCloudSession, ReferenceType>() {
|
||||
return Suppliers2.compose(new Function<VCloudSession, ReferenceType>() {
|
||||
|
||||
@Override
|
||||
public ReferenceType apply(VCloudSession session) {
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
|
||||
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -69,7 +70,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
return Suppliers2.compose(defaultTasksListURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -84,7 +85,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
return Suppliers2.compose(defaultCatalogURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -121,7 +122,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
return Suppliers2.compose(defaultVDCURIForOrg, defaultOrg);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -136,7 +137,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
|
||||
return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
return Suppliers2.compose(defaultNetworkURIForVDC, defaultVDC);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -32,8 +32,9 @@ import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCL
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -81,14 +82,15 @@ import org.jclouds.trmk.vcloud_0_8.location.DefaultVDC;
|
|||
import org.jclouds.trmk.vcloud_0_8.location.OrgAndVDCToLocationSupplier;
|
||||
import org.jclouds.trmk.vcloud_0_8.predicates.TaskSuccess;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
|
@ -141,7 +143,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(
|
||||
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgNameToOrgSuppier) {
|
||||
return Suppliers.compose(
|
||||
return Suppliers2.compose(
|
||||
new Function<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>, Map<String, String>>() {
|
||||
|
||||
@Override
|
||||
|
@ -163,15 +165,15 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
protected Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> provideOrgMapCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgMapSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@OrgList
|
||||
protected Supplier<URI> provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
return Suppliers.compose(new Function<VCloudSession, URI>() {
|
||||
return Suppliers2.compose(new Function<VCloudSession, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(VCloudSession arg0) {
|
||||
|
@ -250,8 +252,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
@Singleton
|
||||
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -259,8 +261,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
protected Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> provideURIToVDC(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
URItoVDC supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -333,7 +335,6 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
private static class OrgNameToOrgSupplier implements Supplier<Map<String, ReferenceType>> {
|
||||
private final Supplier<VCloudSession> sessionSupplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Inject
|
||||
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
|
@ -351,7 +352,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
protected Supplier<org.jclouds.trmk.vcloud_0_8.domain.Org> provideOrg(
|
||||
final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
|
||||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
|
||||
return Suppliers.compose(new Function<ReferenceType, org.jclouds.trmk.vcloud_0_8.domain.Org>() {
|
||||
return Suppliers2.compose(new Function<ReferenceType, org.jclouds.trmk.vcloud_0_8.domain.Org>() {
|
||||
|
||||
@Override
|
||||
public org.jclouds.trmk.vcloud_0_8.domain.Org apply(ReferenceType input) {
|
||||
|
@ -373,8 +374,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Catalog>>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -382,8 +383,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgVDCSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -460,8 +461,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogItemSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.CatalogItem>>>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -479,15 +480,19 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
@Singleton
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
AtomicReference<AuthorizationException> authException, final TerremarkVCloudLoginClient login) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
return login.login();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(login).add("method", "login").toString();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -541,8 +546,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgNameToKeysListSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
|
||||
authException, seconds, supplier);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, supplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
|
|
@ -26,6 +26,7 @@ import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -61,11 +62,11 @@ import org.jclouds.rest.AuthorizationException;
|
|||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -209,7 +210,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Image>> provideImageMap(@Memoized Supplier<Set<? extends Image>> images) {
|
||||
return Suppliers.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() {
|
||||
return Suppliers2.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Image> apply(Set<? extends Image> from) {
|
||||
|
@ -244,13 +245,8 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
protected Supplier<Set<? extends Image>> supplyImageCache(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final Supplier<Set<? extends Image>> imageSupplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Image>>(authException,
|
||||
seconds, new Supplier<Set<? extends Image>>() {
|
||||
@Override
|
||||
public Set<? extends Image> get() {
|
||||
return imageSupplier.get();
|
||||
}
|
||||
});
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, imageSupplier, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -264,7 +260,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(@Memoized Supplier<Set<? extends Hardware>> sizes) {
|
||||
return Suppliers.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
|
||||
return Suppliers2.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Hardware> apply(Set<? extends Hardware> from) {
|
||||
|
@ -286,13 +282,8 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
@Memoized
|
||||
protected Supplier<Set<? extends Hardware>> supplySizeCache(AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final Supplier<Set<? extends Hardware>> hardwareSupplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Hardware>>(authException,
|
||||
seconds, new Supplier<Set<? extends Hardware>>() {
|
||||
@Override
|
||||
public Set<? extends Hardware> get() {
|
||||
return hardwareSupplier.get();
|
||||
}
|
||||
});
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, hardwareSupplier,
|
||||
seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.jclouds.domain.LoginCredentials;
|
|||
import org.jclouds.location.suppliers.LocationsSupplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -88,6 +89,11 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
|
|||
Iterable<L> locations = filter(adapter.listLocations(), notNull());
|
||||
return ImmutableSet.<Location> copyOf(transform(locations, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(adapter).add("method", "listLocations").toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +108,12 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
|
|||
public Iterable<H> get() {
|
||||
return adapter.listHardwareProfiles();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(adapter).add("method", "listHardwareProfiles").toString();
|
||||
}
|
||||
|
||||
}, transformer);
|
||||
}
|
||||
|
||||
|
@ -116,7 +127,12 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
|
|||
public Iterable<I> get() {
|
||||
return filter(adapter.listImages(), notNull());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(adapter).add("method", "listImages").toString();
|
||||
}
|
||||
|
||||
}, compose(addDefaultCredentialsToImage, transformer));
|
||||
}
|
||||
|
||||
|
@ -139,7 +155,7 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "addDefaultCredentialsToImage()";
|
||||
return Objects.toStringHelper(this).add("credsForImage", credsForImage).toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ import org.jclouds.domain.Credentials;
|
|||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -67,4 +69,9 @@ public class ReturnCredentialsBoundToImage implements PopulateDefaultLoginCreden
|
|||
return LoginCredentials.builder().user("root").build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,20 +20,23 @@ package org.jclouds.collect;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>> {
|
||||
public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>>, Serializable {
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = -8747953419394840218L;
|
||||
|
||||
private final Supplier<Iterable<F>> backingSupplier;
|
||||
private final Function<F, T> converter;
|
||||
|
||||
|
@ -44,7 +47,33 @@ public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>>
|
|||
|
||||
@Override
|
||||
public Set<? extends T> get() {
|
||||
return ImmutableSet.copyOf(filter(transform(filter(backingSupplier.get(), notNull()), converter), notNull()));
|
||||
Iterable<F> original = backingSupplier.get();
|
||||
return FluentIterable.from(original)
|
||||
.filter(notNull())
|
||||
.transform(converter)
|
||||
.filter(notNull())
|
||||
.toImmutableSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(backingSupplier, converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TransformingSetSupplier<?, ?> that = TransformingSetSupplier.class.cast(obj);
|
||||
return Objects.equal(backingSupplier, that.backingSupplier) && Objects.equal(converter, that.converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).add("backingSupplier", backingSupplier).add("converter", converter).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
|||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -51,12 +52,12 @@ import org.jclouds.location.suppliers.ZoneIdsSupplier;
|
|||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.functions.ImplicitOptionalConverter;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
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;
|
||||
|
@ -81,7 +82,8 @@ public class LocationModule extends AbstractModule {
|
|||
protected Supplier<Map<String, Supplier<Set<String>>>> isoCodesSupplier(
|
||||
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
LocationIdToIso3166CodesSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -89,14 +91,16 @@ public class LocationModule extends AbstractModule {
|
|||
@Provider
|
||||
protected Supplier<URI> provideProvider(AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, ProviderURISupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Location> implicitLocationSupplier(AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, ImplicitLocationSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -106,7 +110,8 @@ public class LocationModule extends AbstractModule {
|
|||
protected Supplier<Set<? extends Location>> memoizedLocationsSupplier(
|
||||
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
LocationsSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -114,8 +119,8 @@ public class LocationModule extends AbstractModule {
|
|||
@Region
|
||||
protected Supplier<Set<String>> regionIdsSupplier(AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, RegionIdFilter filter, RegionIdsSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds,
|
||||
Suppliers.compose(new FilterStrings(filter), uncached));
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
Suppliers2.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -124,8 +129,8 @@ public class LocationModule extends AbstractModule {
|
|||
protected Supplier<Set<String>> zoneIdsSupplier(
|
||||
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
ZoneIdFilter filter, ZoneIdsSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds,
|
||||
Suppliers.compose(new FilterStrings(filter), uncached));
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
Suppliers2.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
static class FilterStrings implements Function<Set<String>, Set<String>>{
|
||||
|
@ -149,7 +154,8 @@ public class LocationModule extends AbstractModule {
|
|||
protected Supplier<Map<String, Supplier<URI>>> regionIdToURISupplier(
|
||||
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
RegionIdToURISupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -157,7 +163,8 @@ public class LocationModule extends AbstractModule {
|
|||
@Region
|
||||
protected Supplier<String> implicitRegionIdSupplier(AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, ImplicitRegionIdSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,7 +174,8 @@ public class LocationModule extends AbstractModule {
|
|||
protected Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier(
|
||||
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
RegionIdToZoneIdsSupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -176,6 +184,7 @@ public class LocationModule extends AbstractModule {
|
|||
protected Supplier<Map<String, Supplier<URI>>> zoneIdToURISupplier(
|
||||
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
ZoneIdToURISupplier uncached) {
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, seconds, uncached);
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, uncached, seconds,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
|
@ -18,15 +18,24 @@
|
|||
*/
|
||||
package org.jclouds.rest.suppliers;
|
||||
|
||||
import static org.jclouds.util.Suppliers2.memoizeWithExpirationAfterWrite;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static org.jclouds.util.Throwables2.getFirstThrowableOfType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.jclouds.concurrent.RetryOnTimeOutExceptionSupplier;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ForwardingObject;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
|
||||
/**
|
||||
* This will retry the supplier if it encounters a timeout exception, but not if it encounters an
|
||||
|
@ -41,31 +50,110 @@ import com.google.common.base.Supplier;
|
|||
* it is called again for each provider method that depends on it. To short-circuit this, we
|
||||
* remember the last exception trusting that guice is single-threaded.
|
||||
*
|
||||
* Note this implementation is folded into the same class, vs being decorated as stacktraces are
|
||||
* exceptionally long and difficult to grok otherwise. We use {@link LoadingCache} to deal with
|
||||
* concurrency issues related to the supplier.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> implements Supplier<T> {
|
||||
public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> extends ForwardingObject implements
|
||||
Supplier<T>, Serializable {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 7626769175726919353L;
|
||||
|
||||
static class NullValueException extends RuntimeException {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 5064521423206078374L;
|
||||
|
||||
}
|
||||
|
||||
static class SetAndThrowAuthorizationExceptionSupplierBackedLoader<V> extends CacheLoader<String, V> implements
|
||||
Serializable {
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = -6129510622181946809L;
|
||||
|
||||
private final Supplier<V> delegate;
|
||||
private final AtomicReference<AuthorizationException> authException;
|
||||
|
||||
public SetAndThrowAuthorizationExceptionSupplierBackedLoader(Supplier<V> delegate,
|
||||
AtomicReference<AuthorizationException> authException) {
|
||||
this.delegate = checkNotNull(delegate, "delegate");
|
||||
this.authException = checkNotNull(authException, "authException");
|
||||
}
|
||||
|
||||
@Override
|
||||
public V load(String key) {
|
||||
if (authException.get() != null)
|
||||
throw authException.get();
|
||||
try {
|
||||
V value = delegate.get();
|
||||
if (value == null)
|
||||
throw new NullValueException();
|
||||
return value;
|
||||
} catch (Exception e) {
|
||||
AuthorizationException aex = getFirstThrowableOfType(e, AuthorizationException.class);
|
||||
if (aex != null) {
|
||||
authException.set(aex);
|
||||
throw aex;
|
||||
}
|
||||
throw propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).add("delegate", delegate).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Supplier<T> delegate;
|
||||
private final long seconds;
|
||||
private final long duration;
|
||||
private final TimeUnit unit;
|
||||
private final LoadingCache<String, T> cache;
|
||||
|
||||
public static <T> MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T> create(
|
||||
AtomicReference<AuthorizationException> authException, long seconds, Supplier<T> delegate) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T>(authException, seconds, delegate);
|
||||
AtomicReference<AuthorizationException> authException, Supplier<T> delegate, long duration, TimeUnit unit) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<T>(authException, delegate, duration,
|
||||
unit);
|
||||
}
|
||||
|
||||
public MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
|
||||
AtomicReference<AuthorizationException> authException, long seconds, Supplier<T> delegate) {
|
||||
this.delegate = memoizeWithExpirationAfterWrite(new RetryOnTimeOutExceptionSupplier<T>(
|
||||
new SetAndThrowAuthorizationExceptionSupplier<T>(delegate, authException)), seconds, TimeUnit.SECONDS);
|
||||
this.seconds = seconds;
|
||||
|
||||
MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(AtomicReference<AuthorizationException> authException,
|
||||
Supplier<T> delegate, long duration, TimeUnit unit) {
|
||||
this.delegate = delegate;
|
||||
this.duration = duration;
|
||||
this.unit = unit;
|
||||
this.cache = CacheBuilder.newBuilder().expireAfterWrite(duration, unit)
|
||||
.build(new SetAndThrowAuthorizationExceptionSupplierBackedLoader<T>(delegate, authException));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Supplier<T> delegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return delegate.get();
|
||||
try {
|
||||
T returnVal = cache.get("FOO");
|
||||
return returnVal;
|
||||
} catch (UncheckedExecutionException e) {
|
||||
NullValueException nullV = getFirstThrowableOfType(e, NullValueException.class);
|
||||
if (nullV != null) {
|
||||
return null;
|
||||
}
|
||||
throw propagate(e.getCause());
|
||||
} catch (ExecutionException e) {
|
||||
throw propagate(e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "memoizeWithExpiration(" + delegate + ", seconds=" + seconds + ")";
|
||||
return Objects.toStringHelper(this).add("delegate", delegate).add("duration", duration).add("unit", unit)
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -24,16 +24,12 @@ import java.io.IOException;
|
|||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ForwardingObject;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.OutputSupplier;
|
||||
|
||||
|
@ -44,7 +40,7 @@ import com.google.common.io.OutputSupplier;
|
|||
public class Suppliers2 {
|
||||
|
||||
public static <K, V> Supplier<V> getLastValueInMap(Supplier<Map<K, Supplier<V>>> input) {
|
||||
return Suppliers.compose(new Function<Map<K, Supplier<V>>, V>() {
|
||||
return Suppliers2.compose(new Function<Map<K, Supplier<V>>, V>() {
|
||||
|
||||
@Override
|
||||
public V apply(Map<K, Supplier<V>> input) {
|
||||
|
@ -86,63 +82,35 @@ public class Suppliers2 {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* same as {@link Supplier.memoizeWithExpiration} except that the expiration ticker starts after
|
||||
* write vs after call to {@code get}.
|
||||
*
|
||||
* @see Supplier.memoizeWithExpiration
|
||||
*/
|
||||
public static <T> Supplier<T> memoizeWithExpirationAfterWrite(Supplier<T> delegate, long duration, TimeUnit unit) {
|
||||
return new ExpireAfterWriteSupplier<T>(delegate, duration, unit);
|
||||
// only here until guava compose gives a toString!
|
||||
// http://code.google.com/p/guava-libraries/issues/detail?id=1052
|
||||
public static <F, T> Supplier<T> compose(Function<? super F, T> function, Supplier<F> supplier) {
|
||||
Preconditions.checkNotNull(function);
|
||||
Preconditions.checkNotNull(supplier);
|
||||
return new SupplierComposition<F, T>(function, supplier);
|
||||
}
|
||||
|
||||
static class ExpireAfterWriteSupplier<T> extends ForwardingObject implements Supplier<T>, Serializable {
|
||||
private final Supplier<T> delegate;
|
||||
private final long duration;
|
||||
private final TimeUnit unit;
|
||||
private final LoadingCache<Object, T> cache;
|
||||
private static class SupplierComposition<F, T> implements Supplier<T>, Serializable {
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 1023509665531743802L;
|
||||
|
||||
public ExpireAfterWriteSupplier(Supplier<T> delegate, long duration, TimeUnit unit) {
|
||||
this.delegate = delegate;
|
||||
this.duration = duration;
|
||||
this.unit = unit;
|
||||
cache = CacheBuilder.newBuilder().expireAfterWrite(duration, unit).build(CacheLoader.from(delegate));
|
||||
}
|
||||
final Function<? super F, T> function;
|
||||
final Supplier<F> supplier;
|
||||
|
||||
@Override
|
||||
protected Supplier<T> delegate() {
|
||||
return delegate;
|
||||
SupplierComposition(Function<? super F, T> function, Supplier<F> supplier) {
|
||||
this.function = function;
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
return cache.getUnchecked("FOO");
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(delegate, duration, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ExpireAfterWriteSupplier<?> that = ExpireAfterWriteSupplier.class.cast(obj);
|
||||
return Objects.equal(delegate, that.delegate) && Objects.equal(duration, that.duration);
|
||||
return function.apply(supplier.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).add("delegate", delegate).add("duration", duration).add("unit", unit)
|
||||
.toString();
|
||||
return Objects.toStringHelper(this).add("function", function).add("supplier", supplier).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,300 @@
|
|||
/**
|
||||
* 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.rest.suppliers;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertSame;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.SetAndThrowAuthorizationExceptionSupplierBackedLoader;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test(groups = "unit", testName = "MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest")
|
||||
public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest {
|
||||
@Test
|
||||
public void testLoaderNormal() {
|
||||
AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
|
||||
assertEquals(new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(Suppliers.ofInstance("foo"),
|
||||
authException).load("KEY"), "foo");
|
||||
assertEquals(authException.get(), null);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionType() {
|
||||
AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
|
||||
try {
|
||||
new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
throw new AuthorizationException();
|
||||
}
|
||||
}, authException).load("KEY");
|
||||
} finally {
|
||||
assertEquals(authException.get().getClass(), AuthorizationException.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenNested() {
|
||||
AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
|
||||
try {
|
||||
new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
throw new RuntimeException(new ExecutionException(new AuthorizationException()));
|
||||
}
|
||||
}, authException).load("KEY");
|
||||
} finally {
|
||||
assertEquals(authException.get().getClass(), AuthorizationException.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = RuntimeException.class)
|
||||
public void testLoaderThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() {
|
||||
AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
|
||||
try {
|
||||
new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
throw new RuntimeException(new IllegalArgumentException("foo"));
|
||||
}
|
||||
}, authException).load("KEY");
|
||||
} finally {
|
||||
assertEquals(authException.get().getClass(), RuntimeException.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemoizeKeepsValueForFullDurationWhenDelegateCallIsSlow() {
|
||||
final long SLEEP_TIME = 250;
|
||||
final long EXPIRATION_TIME = 200;
|
||||
|
||||
Supplier<Integer> slowSupplier = new CountingSupplier() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public Integer get() {
|
||||
try {
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
return super.get();
|
||||
}
|
||||
};
|
||||
|
||||
Supplier<Integer> memoizedSupplier = new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
|
||||
new AtomicReference<AuthorizationException>(), slowSupplier, EXPIRATION_TIME, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertEquals(memoizedSupplier.get(), (Integer) 10);
|
||||
assertEquals(memoizedSupplier.get(), (Integer) 10);
|
||||
}
|
||||
|
||||
// =================================
|
||||
//
|
||||
// TODO Everything below this point is taken from SuppliersTest, to test our version of the
|
||||
// Suppliers2.memoizeWithExpiration
|
||||
// It should be deleted when we can switch back to using the google
|
||||
// Supplier.memoizeWithExpiration.
|
||||
|
||||
private static class CountingSupplier implements Supplier<Integer>, Serializable {
|
||||
private static final long serialVersionUID = 0L;
|
||||
transient int calls = 0;
|
||||
|
||||
@Override
|
||||
public Integer get() {
|
||||
calls++;
|
||||
return calls * 10;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemoizeWithExpiration() throws InterruptedException {
|
||||
CountingSupplier countingSupplier = new CountingSupplier();
|
||||
|
||||
Supplier<Integer> memoizedSupplier = new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
|
||||
new AtomicReference<AuthorizationException>(), countingSupplier, 75, TimeUnit.MILLISECONDS);
|
||||
|
||||
checkExpiration(countingSupplier, memoizedSupplier);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemoizeWithExpirationSerialized() throws InterruptedException {
|
||||
CountingSupplier countingSupplier = new CountingSupplier();
|
||||
|
||||
Supplier<Integer> memoizedSupplier = new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
|
||||
new AtomicReference<AuthorizationException>(), countingSupplier, 75, TimeUnit.MILLISECONDS);
|
||||
// Calls to the original memoized supplier shouldn't affect its copy.
|
||||
memoizedSupplier.get();
|
||||
|
||||
Supplier<Integer> copy = reserialize(memoizedSupplier);
|
||||
memoizedSupplier.get();
|
||||
|
||||
CountingSupplier countingCopy = (CountingSupplier) ((MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier) copy)
|
||||
.delegate();
|
||||
checkExpiration(countingCopy, copy);
|
||||
}
|
||||
|
||||
private void checkExpiration(CountingSupplier countingSupplier, Supplier<Integer> memoizedSupplier)
|
||||
throws InterruptedException {
|
||||
// the underlying supplier hasn't executed yet
|
||||
assertEquals(0, countingSupplier.calls);
|
||||
|
||||
assertEquals(10, (int) memoizedSupplier.get());
|
||||
// now it has
|
||||
assertEquals(1, countingSupplier.calls);
|
||||
|
||||
assertEquals(10, (int) memoizedSupplier.get());
|
||||
// it still should only have executed once due to memoization
|
||||
assertEquals(1, countingSupplier.calls);
|
||||
|
||||
Thread.sleep(150);
|
||||
|
||||
assertEquals(20, (int) memoizedSupplier.get());
|
||||
// old value expired
|
||||
assertEquals(2, countingSupplier.calls);
|
||||
|
||||
assertEquals(20, (int) memoizedSupplier.get());
|
||||
// it still should only have executed twice due to memoization
|
||||
assertEquals(2, countingSupplier.calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpiringMemoizedSupplierThreadSafe() throws Throwable {
|
||||
Function<Supplier<Boolean>, Supplier<Boolean>> memoizer = new Function<Supplier<Boolean>, Supplier<Boolean>>() {
|
||||
@Override
|
||||
public Supplier<Boolean> apply(Supplier<Boolean> supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(
|
||||
new AtomicReference<AuthorizationException>(), supplier, Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||
}
|
||||
};
|
||||
supplierThreadSafe(memoizer);
|
||||
}
|
||||
|
||||
private void supplierThreadSafe(Function<Supplier<Boolean>, Supplier<Boolean>> memoizer) throws Throwable {
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final AtomicReference<Throwable> thrown = new AtomicReference<Throwable>(null);
|
||||
final int numThreads = 3;
|
||||
final Thread[] threads = new Thread[numThreads];
|
||||
final long timeout = TimeUnit.SECONDS.toNanos(60);
|
||||
|
||||
final Supplier<Boolean> supplier = new Supplier<Boolean>() {
|
||||
boolean isWaiting(Thread thread) {
|
||||
switch (thread.getState()) {
|
||||
case BLOCKED:
|
||||
case WAITING:
|
||||
case TIMED_WAITING:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int waitingThreads() {
|
||||
int waitingThreads = 0;
|
||||
for (Thread thread : threads) {
|
||||
if (isWaiting(thread)) {
|
||||
waitingThreads++;
|
||||
}
|
||||
}
|
||||
return waitingThreads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean get() {
|
||||
// Check that this method is called exactly once, by the first
|
||||
// thread to synchronize.
|
||||
long t0 = System.nanoTime();
|
||||
while (waitingThreads() != numThreads - 1) {
|
||||
if (System.nanoTime() - t0 > timeout) {
|
||||
thrown.set(new TimeoutException("timed out waiting for other threads to block"
|
||||
+ " synchronizing on supplier"));
|
||||
break;
|
||||
}
|
||||
Thread.yield();
|
||||
}
|
||||
count.getAndIncrement();
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
};
|
||||
|
||||
final Supplier<Boolean> memoizedSupplier = memoizer.apply(supplier);
|
||||
|
||||
for (int i = 0; i < numThreads; i++) {
|
||||
threads[i] = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertSame(Boolean.TRUE, memoizedSupplier.get());
|
||||
}
|
||||
};
|
||||
}
|
||||
for (Thread t : threads) {
|
||||
t.start();
|
||||
}
|
||||
for (Thread t : threads) {
|
||||
t.join();
|
||||
}
|
||||
|
||||
if (thrown.get() != null) {
|
||||
throw thrown.get();
|
||||
}
|
||||
assertEquals(1, count.get());
|
||||
}
|
||||
|
||||
// Taken from com.google.common.testing.SerializableTester
|
||||
private static <T> T reserialize(T object) {
|
||||
checkNotNull(object);
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
try {
|
||||
ObjectOutputStream out = new ObjectOutputStream(bytes);
|
||||
out.writeObject(object);
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
|
||||
return (T) in.readObject();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,11 +30,10 @@ import com.google.common.base.Supplier;
|
|||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SetAndThrowAuthorizationExceptionSupplier}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
@Test(groups = "unit", testName = "MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest")
|
||||
public class SetAndThrowAuthorizationExceptionSupplierTest {
|
||||
@Test
|
||||
public void testNormal() {
|
||||
|
|
|
@ -56,199 +56,4 @@ public class Suppliers2Test {
|
|||
assertEquals(Suppliers2.ofInstanceFunction().apply("foo").get(), "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemoizeKeepsValueForFullDurationWhenDelegateCallIsSlow() {
|
||||
final long SLEEP_TIME = 250;
|
||||
final long EXPIRATION_TIME = 200;
|
||||
|
||||
Supplier<Integer> slowSupplier = new CountingSupplier() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override public Integer get() {
|
||||
try {
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
return super.get();
|
||||
}
|
||||
};
|
||||
|
||||
Supplier<Integer> memoizedSupplier = Suppliers2.memoizeWithExpirationAfterWrite(
|
||||
slowSupplier, EXPIRATION_TIME, TimeUnit.MILLISECONDS);
|
||||
|
||||
assertEquals(memoizedSupplier.get(), (Integer)10);
|
||||
assertEquals(memoizedSupplier.get(), (Integer)10);
|
||||
}
|
||||
|
||||
// =================================
|
||||
//
|
||||
// TODO Everything below this point is taken from SuppliersTest, to test our version of the Suppliers2.memoizeWithExpiration
|
||||
// It should be deleted when we can switch back to using the google Supplier.memoizeWithExpiration.
|
||||
|
||||
private static class CountingSupplier implements Supplier<Integer>, Serializable {
|
||||
private static final long serialVersionUID = 0L;
|
||||
transient int calls = 0;
|
||||
@Override
|
||||
public Integer get() {
|
||||
calls++;
|
||||
return calls * 10;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemoizeWithExpiration() throws InterruptedException {
|
||||
CountingSupplier countingSupplier = new CountingSupplier();
|
||||
|
||||
Supplier<Integer> memoizedSupplier = Suppliers2.memoizeWithExpirationAfterWrite(
|
||||
countingSupplier, 75, TimeUnit.MILLISECONDS);
|
||||
|
||||
checkExpiration(countingSupplier, memoizedSupplier);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemoizeWithExpirationSerialized()
|
||||
throws InterruptedException {
|
||||
CountingSupplier countingSupplier = new CountingSupplier();
|
||||
|
||||
Supplier<Integer> memoizedSupplier = Suppliers2.memoizeWithExpirationAfterWrite(
|
||||
countingSupplier, 75, TimeUnit.MILLISECONDS);
|
||||
// Calls to the original memoized supplier shouldn't affect its copy.
|
||||
memoizedSupplier.get();
|
||||
|
||||
Supplier<Integer> copy = reserialize(memoizedSupplier);
|
||||
memoizedSupplier.get();
|
||||
|
||||
CountingSupplier countingCopy = (CountingSupplier)
|
||||
((Suppliers2.ExpireAfterWriteSupplier<Integer>) copy).delegate();
|
||||
checkExpiration(countingCopy, copy);
|
||||
}
|
||||
|
||||
private void checkExpiration(
|
||||
CountingSupplier countingSupplier, Supplier<Integer> memoizedSupplier)
|
||||
throws InterruptedException {
|
||||
// the underlying supplier hasn't executed yet
|
||||
assertEquals(0, countingSupplier.calls);
|
||||
|
||||
assertEquals(10, (int) memoizedSupplier.get());
|
||||
// now it has
|
||||
assertEquals(1, countingSupplier.calls);
|
||||
|
||||
assertEquals(10, (int) memoizedSupplier.get());
|
||||
// it still should only have executed once due to memoization
|
||||
assertEquals(1, countingSupplier.calls);
|
||||
|
||||
Thread.sleep(150);
|
||||
|
||||
assertEquals(20, (int) memoizedSupplier.get());
|
||||
// old value expired
|
||||
assertEquals(2, countingSupplier.calls);
|
||||
|
||||
assertEquals(20, (int) memoizedSupplier.get());
|
||||
// it still should only have executed twice due to memoization
|
||||
assertEquals(2, countingSupplier.calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpiringMemoizedSupplierThreadSafe() throws Throwable {
|
||||
Function<Supplier<Boolean>, Supplier<Boolean>> memoizer =
|
||||
new Function<Supplier<Boolean>, Supplier<Boolean>>() {
|
||||
@Override public Supplier<Boolean> apply(Supplier<Boolean> supplier) {
|
||||
return Suppliers2.memoizeWithExpirationAfterWrite(
|
||||
supplier, Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||
}
|
||||
};
|
||||
testSupplierThreadSafe(memoizer);
|
||||
}
|
||||
|
||||
public void testSupplierThreadSafe(
|
||||
Function<Supplier<Boolean>, Supplier<Boolean>> memoizer)
|
||||
throws Throwable {
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final AtomicReference<Throwable> thrown =
|
||||
new AtomicReference<Throwable>(null);
|
||||
final int numThreads = 3;
|
||||
final Thread[] threads = new Thread[numThreads];
|
||||
final long timeout = TimeUnit.SECONDS.toNanos(60);
|
||||
|
||||
final Supplier<Boolean> supplier = new Supplier<Boolean>() {
|
||||
boolean isWaiting(Thread thread) {
|
||||
switch (thread.getState()) {
|
||||
case BLOCKED:
|
||||
case WAITING:
|
||||
case TIMED_WAITING:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int waitingThreads() {
|
||||
int waitingThreads = 0;
|
||||
for (Thread thread : threads) {
|
||||
if (isWaiting(thread)) {
|
||||
waitingThreads++;
|
||||
}
|
||||
}
|
||||
return waitingThreads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean get() {
|
||||
// Check that this method is called exactly once, by the first
|
||||
// thread to synchronize.
|
||||
long t0 = System.nanoTime();
|
||||
while (waitingThreads() != numThreads - 1) {
|
||||
if (System.nanoTime() - t0 > timeout) {
|
||||
thrown.set(new TimeoutException(
|
||||
"timed out waiting for other threads to block" +
|
||||
" synchronizing on supplier"));
|
||||
break;
|
||||
}
|
||||
Thread.yield();
|
||||
}
|
||||
count.getAndIncrement();
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
};
|
||||
|
||||
final Supplier<Boolean> memoizedSupplier = memoizer.apply(supplier);
|
||||
|
||||
for (int i = 0; i < numThreads; i++) {
|
||||
threads[i] = new Thread() {
|
||||
@Override public void run() {
|
||||
assertSame(Boolean.TRUE, memoizedSupplier.get());
|
||||
}
|
||||
};
|
||||
}
|
||||
for (Thread t : threads) {
|
||||
t.start();
|
||||
}
|
||||
for (Thread t : threads) {
|
||||
t.join();
|
||||
}
|
||||
|
||||
if (thrown.get() != null) {
|
||||
throw thrown.get();
|
||||
}
|
||||
assertEquals(1, count.get());
|
||||
}
|
||||
|
||||
// Taken from com.google.common.testing.SerializableTester
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T reserialize(T object) {
|
||||
checkNotNull(object);
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
try {
|
||||
ObjectOutputStream out = new ObjectOutputStream(bytes);
|
||||
out.writeObject(object);
|
||||
ObjectInputStream in = new ObjectInputStream(
|
||||
new ByteArrayInputStream(bytes.toByteArray()));
|
||||
return (T) in.readObject();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,11 +56,11 @@ import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.DatasetInDatacenter;
|
|||
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.MachineInDatacenter;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.datacenterscoped.PackageInDatacenter;
|
||||
import org.jclouds.util.Iterables2;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
@ -134,7 +134,7 @@ public class SDCComputeServiceContextModule extends
|
|||
@Singleton
|
||||
protected Supplier<Map<String, Location>> createLocationIndexedById(
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
return Suppliers2.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, Location> apply(Set<? extends Location> arg0) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.jclouds.location.Provider;
|
|||
import org.jclouds.nodepool.Backend;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.rest.annotations.BuildVersion;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -117,7 +118,7 @@ public class BindBackendComputeService extends BindJcloudsModules {
|
|||
@Backend
|
||||
@Exposed
|
||||
protected Supplier<Template> makeBackendTemplate(@Backend Supplier<ComputeService> compute) {
|
||||
return Suppliers.memoize(Suppliers.compose(new Function<ComputeService, Template>() {
|
||||
return Suppliers.memoize(Suppliers2.compose(new Function<ComputeService, Template>() {
|
||||
|
||||
@Override
|
||||
public Template apply(ComputeService input) {
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.jclouds.blobstore.BlobStoreContext;
|
|||
import org.jclouds.filesystem.reference.FilesystemConstants;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
import org.jclouds.nodepool.Backend;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -51,7 +52,7 @@ public class BindInputStreamToFilesystemBlobStore extends BindJcloudsModules {
|
|||
@Exposed
|
||||
protected Supplier<Map<String, InputStream>> provideInputStreamMapFromBlobStore(Supplier<BlobStoreContext> in,
|
||||
@Named(NodePoolProperties.METADATA_CONTAINER) final String container) {
|
||||
return Suppliers.memoize(Suppliers.compose(new Function<BlobStoreContext, Map<String, InputStream>>() {
|
||||
return Suppliers.memoize(Suppliers2.compose(new Function<BlobStoreContext, Map<String, InputStream>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, InputStream> apply(BlobStoreContext input) {
|
||||
|
|
|
@ -27,8 +27,9 @@ import java.util.Properties;
|
|||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.openstack.glance.v1_0.config.GlanceRestClientModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
|
||||
import org.jclouds.openstack.v2_0.ServiceType;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.BaseRestApiMetadata;
|
||||
|
@ -86,7 +87,10 @@ public class GlanceApiMetadata extends BaseRestApiMetadata {
|
|||
.version("1.0")
|
||||
.defaultEndpoint("http://localhost:5000")
|
||||
.defaultProperties(GlanceApiMetadata.defaultProperties())
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForRegions.class, GlanceRestClientModule.class));
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(KeystoneAuthenticationModule.class)
|
||||
.add(RegionModule.class)
|
||||
.add(GlanceRestClientModule.class).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,10 +26,6 @@ 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;
|
||||
|
@ -39,7 +35,6 @@ 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.
|
||||
|
@ -63,13 +58,6 @@ public class GlanceRestClientModule extends RestClientModule<GlanceClient, Glanc
|
|||
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);
|
||||
|
|
|
@ -26,8 +26,9 @@ import java.util.Properties;
|
|||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
|
||||
import org.jclouds.openstack.quantum.v1_0.config.QuantumRestClientModule;
|
||||
import org.jclouds.openstack.v2_0.ServiceType;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
@ -85,7 +86,10 @@ public class QuantumApiMetadata extends BaseRestApiMetadata {
|
|||
.version("1.0")
|
||||
.defaultEndpoint("http://localhost:5000")
|
||||
.defaultProperties(QuantumApiMetadata.defaultProperties())
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForRegions.class, QuantumRestClientModule.class));
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(KeystoneAuthenticationModule.class)
|
||||
.add(RegionModule.class)
|
||||
.add(QuantumRestClientModule.class).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,10 +26,6 @@ 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;
|
||||
|
@ -41,7 +37,6 @@ 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.
|
||||
|
@ -66,13 +61,6 @@ public class QuantumRestClientModule extends RestClientModule<QuantumClient, Qua
|
|||
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);
|
||||
|
|
|
@ -26,8 +26,9 @@ import java.util.Properties;
|
|||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
|
||||
import org.jclouds.openstack.swift.v1.config.SwiftRestClientModule;
|
||||
import org.jclouds.openstack.v2_0.ServiceType;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
@ -86,7 +87,10 @@ public class SwiftApiMetadata extends BaseRestApiMetadata {
|
|||
.version("1.0")
|
||||
.defaultEndpoint("http://localhost:5000")
|
||||
.defaultProperties(SwiftApiMetadata.defaultProperties())
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForRegions.class, SwiftRestClientModule.class));
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(KeystoneAuthenticationModule.class)
|
||||
.add(RegionModule.class)
|
||||
.add(SwiftRestClientModule.class).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,10 +26,6 @@ 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;
|
||||
|
@ -43,7 +39,6 @@ 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.
|
||||
|
@ -68,13 +63,6 @@ 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() {
|
||||
|
|
|
@ -28,8 +28,11 @@ import org.jclouds.apis.ApiMetadata;
|
|||
import org.jclouds.openstack.keystone.v2_0.KeystoneApiMetadata;
|
||||
import org.jclouds.openstack.keystone.v2_0.KeystoneAsyncClient;
|
||||
import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneParserModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule.KeystoneAdminURLModule;
|
||||
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule;
|
||||
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes;
|
||||
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityRestClientModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -85,7 +88,11 @@ public class CloudIdentityApiMetadata extends KeystoneApiMetadata {
|
|||
.defaultProperties(CloudIdentityApiMetadata.defaultProperties())
|
||||
.context(CONTEXT_TOKEN)
|
||||
.documentation(URI.create("http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/"))
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(CloudIdentityRestClientModule.class));
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(CloudIdentityAuthenticationModule.class)
|
||||
.add(KeystoneAdminURLModule.class)
|
||||
.add(KeystoneParserModule.class)
|
||||
.add(KeystoneRestClientModule.class).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,7 +37,6 @@ import com.google.common.base.Function;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
|
@ -46,34 +45,6 @@ import com.google.inject.Scopes;
|
|||
*/
|
||||
public class CloudIdentityAuthenticationModule extends KeystoneAuthenticationModule {
|
||||
|
||||
public CloudIdentityAuthenticationModule() {
|
||||
this(new RegionModule());
|
||||
}
|
||||
|
||||
protected CloudIdentityAuthenticationModule(Module locationModule) {
|
||||
super(locationModule);
|
||||
}
|
||||
|
||||
public static class CloudIdentityAuthenticationModuleForRegions extends CloudIdentityAuthenticationModule {
|
||||
public CloudIdentityAuthenticationModuleForRegions() {
|
||||
super(new RegionModule());
|
||||
}
|
||||
}
|
||||
|
||||
public static Module forRegions() {
|
||||
return new CloudIdentityAuthenticationModuleForRegions();
|
||||
}
|
||||
|
||||
public static class CloudIdentityAuthenticationModuleForZones extends CloudIdentityAuthenticationModule {
|
||||
public CloudIdentityAuthenticationModuleForZones() {
|
||||
super(new ZoneModule());
|
||||
}
|
||||
}
|
||||
|
||||
public static Module forZones() {
|
||||
return new CloudIdentityAuthenticationModuleForZones();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindAuthenticationClient() {
|
||||
// AuthenticationClient is used directly for filters and retry handlers, so let's bind it
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package org.jclouds.rackspace.cloudidentity.v2_0.config;
|
||||
|
||||
import org.jclouds.location.config.LocationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.KeystoneAsyncClient;
|
||||
import org.jclouds.openstack.keystone.v2_0.KeystoneClient;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneRestClientModule;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
||||
/**
|
||||
* Configures the Keystone connection.
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@ConfiguresRestClient
|
||||
public class CloudIdentityRestClientModule extends KeystoneRestClientModule<KeystoneClient, KeystoneAsyncClient> {
|
||||
|
||||
@Override
|
||||
protected void installLocations() {
|
||||
// TODO: select this from KeystoneProperties.VERSION; note you select from
|
||||
// a guice provided property, so it will have to come from somewhere else, maybe we move
|
||||
// this to the the ContextBuilder
|
||||
install(CloudIdentityAuthenticationModule.forRegions());
|
||||
install(new LocationModule());
|
||||
}
|
||||
}
|
|
@ -23,11 +23,12 @@ import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CRED
|
|||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApiMetadata;
|
||||
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.CloudIdentityAuthenticationModule.CloudIdentityAuthenticationModuleForZones;
|
||||
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityAuthenticationModule;
|
||||
import org.jclouds.rackspace.cloudidentity.v2_0.config.CloudIdentityCredentialTypes;
|
||||
import org.jclouds.rackspace.cloudservers.us.config.CloudServersUSComputeServiceContextModule;
|
||||
|
||||
|
@ -77,7 +78,11 @@ 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, CloudServersUSComputeServiceContextModule.class))
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(CloudIdentityAuthenticationModule.class)
|
||||
.add(ZoneModule.class)
|
||||
.add(NovaRestClientModule.class)
|
||||
.add(CloudServersUSComputeServiceContextModule.class).build())
|
||||
.build())
|
||||
.homepage(URI.create("http://www.rackspace.com/cloud/nextgen"))
|
||||
.console(URI.create("https://mycloud.rackspace.com"))
|
||||
|
|
|
@ -27,6 +27,7 @@ import static org.jclouds.savvis.vpdc.reference.VPDCConstants.PROPERTY_VPDC_TIME
|
|||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -62,11 +63,12 @@ import org.jclouds.savvis.vpdc.internal.VCloudToken;
|
|||
import org.jclouds.savvis.vpdc.location.FirstNetwork;
|
||||
import org.jclouds.savvis.vpdc.predicates.TaskSuccess;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Injector;
|
||||
|
@ -91,7 +93,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
return Suppliers.compose(new Function<VCloudSession, String>() {
|
||||
return Suppliers2.compose(new Function<VCloudSession, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(VCloudSession input) {
|
||||
|
@ -106,7 +108,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
|
|||
@Singleton
|
||||
protected Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> provideOrgs(Supplier<VCloudSession> cache,
|
||||
@Identity final String user) {
|
||||
return Suppliers.compose(new Function<VCloudSession, Set<org.jclouds.savvis.vpdc.domain.Resource>>() {
|
||||
return Suppliers2.compose(new Function<VCloudSession, Set<org.jclouds.savvis.vpdc.domain.Resource>>() {
|
||||
|
||||
@Override
|
||||
public Set<org.jclouds.savvis.vpdc.domain.Resource> apply(VCloudSession input) {
|
||||
|
@ -122,7 +124,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
|
|||
@Singleton
|
||||
protected Supplier<String> provideDefaultOrgId(
|
||||
@org.jclouds.savvis.vpdc.internal.Org Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> orgs) {
|
||||
return Suppliers.compose(new Function<Set<org.jclouds.savvis.vpdc.domain.Resource>, String>() {
|
||||
return Suppliers2.compose(new Function<Set<org.jclouds.savvis.vpdc.domain.Resource>, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Set<org.jclouds.savvis.vpdc.domain.Resource> input) {
|
||||
|
@ -163,15 +165,18 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
|
|||
@Singleton
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final LoginClient login) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
return login.login();
|
||||
}
|
||||
|
||||
});
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(login).add("method", "login").toString();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.jclouds.rest.RestContext;
|
|||
import org.jclouds.rest.config.BinderUtils;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.jclouds.util.Suppliers2;
|
||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient;
|
||||
import org.jclouds.vcloud.director.v1_5.annotations.Login;
|
||||
|
@ -93,7 +94,6 @@ import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
@ -187,7 +187,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
|
|||
@Login
|
||||
protected Supplier<URI> loginUrl(@Provider Supplier<URI> provider) {
|
||||
// TODO: technically, we should implement version client, but this will work
|
||||
return Suppliers.compose(new Function<URI, URI>() {
|
||||
return Suppliers2.compose(new Function<URI, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(URI arg0) {
|
||||
|
@ -199,7 +199,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
|
|||
|
||||
@Provides
|
||||
protected Supplier<Session> currentSession(Supplier<SessionWithToken> in) {
|
||||
return Suppliers.compose(new Function<SessionWithToken, Session>() {
|
||||
return Suppliers2.compose(new Function<SessionWithToken, Session>() {
|
||||
|
||||
@Override
|
||||
public Session apply(SessionWithToken arg0) {
|
||||
|
@ -214,7 +214,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
|
|||
@Singleton
|
||||
@org.jclouds.vcloud.director.v1_5.annotations.Session
|
||||
protected Supplier<String> sessionToken(Supplier<SessionWithToken> in) {
|
||||
return Suppliers.compose(new Function<SessionWithToken, String>() {
|
||||
return Suppliers2.compose(new Function<SessionWithToken, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(SessionWithToken arg0) {
|
||||
|
|
|
@ -30,7 +30,8 @@ import java.net.URI;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.hpcloud.compute.config.HPCloudComputeServiceContextModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForZones;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule;
|
||||
import org.jclouds.openstack.nova.v2_0.NovaApiMetadata;
|
||||
import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
|
@ -87,7 +88,11 @@ public class HPCloudComputeProviderMetadata extends BaseProviderMetadata {
|
|||
.apiMetadata(new NovaApiMetadata().toBuilder()
|
||||
.identityName("yourTenantName:yourAccessKey")
|
||||
.credentialName("secretKey")
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForZones.class,NovaRestClientModule.class, HPCloudComputeServiceContextModule.class))
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(KeystoneAuthenticationModule.class)
|
||||
.add(ZoneModule.class)
|
||||
.add(NovaRestClientModule.class)
|
||||
.add(HPCloudComputeServiceContextModule.class).build())
|
||||
.build())
|
||||
.homepage(URI.create("http://hpcloud.com"))
|
||||
.console(URI.create("https://manage.hpcloud.com/compute"))
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.jclouds.apis.ApiMetadata;
|
|||
import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule;
|
||||
import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
||||
import org.jclouds.openstack.services.ServiceType;
|
||||
import org.jclouds.openstack.swift.SwiftApiMetadata;
|
||||
|
@ -89,7 +90,11 @@ public class HPCloudObjectStorageApiMetadata extends SwiftApiMetadata {
|
|||
.documentation(URI.create("https://build.hpcloud.com/object-storage/api"))
|
||||
.defaultProperties(HPCloudObjectStorageApiMetadata.defaultProperties())
|
||||
.context(CONTEXT_TOKEN)
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneStorageEndpointModule.class, HPCloudObjectStorageRestClientModule.class, HPCloudObjectStorageBlobStoreContextModule.class));
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
|
||||
.add(KeystoneStorageEndpointModule.class)
|
||||
.add(RegionModule.class)
|
||||
.add(HPCloudObjectStorageRestClientModule.class)
|
||||
.add(HPCloudObjectStorageBlobStoreContextModule.class).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,11 +31,7 @@ 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;
|
||||
|
@ -68,13 +64,6 @@ public class HPCloudObjectStorageRestClientModule extends
|
|||
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
|
||||
|
|
|
@ -25,6 +25,7 @@ import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named;
|
|||
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME;
|
||||
import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -54,6 +55,7 @@ import org.jclouds.softlayer.features.AccountClient;
|
|||
import org.jclouds.softlayer.features.ProductPackageClient;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
@ -95,7 +97,7 @@ public class SoftLayerComputeServiceContextModule extends
|
|||
public Supplier<ProductPackage> getProductPackage(AtomicReference<AuthorizationException> authException,
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final SoftLayerClient client,
|
||||
@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) final String virtualGuestPackageName) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<ProductPackage>(authException, seconds,
|
||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||
new Supplier<ProductPackage>() {
|
||||
@Override
|
||||
public ProductPackage get() {
|
||||
|
@ -104,7 +106,13 @@ public class SoftLayerComputeServiceContextModule extends
|
|||
ProductPackage p = find(accountClient.getActivePackages(), named(virtualGuestPackageName));
|
||||
return productPackageClient.getProductPackage(p.getId());
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(client).add("method", "accountClient.getActivePackages")
|
||||
.add("method", "productPackageClient.getProductPackage").toString();
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
// TODO: check the prices really do exist
|
||||
|
|
Loading…
Reference in New Issue