mirror of https://github.com/apache/jclouds.git
Issue 803: changes needed when guice is in production mode
This commit is contained in:
parent
cc5aa5cee2
commit
f390f314ee
|
@ -18,17 +18,19 @@
|
|||
*/
|
||||
package org.jclouds.cloudloadbalancers.loadbalancer.functions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudloadbalancers.domain.LoadBalancer;
|
||||
import org.jclouds.cloudloadbalancers.domain.VirtualIP;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
|
||||
import org.jclouds.loadbalancer.domain.LoadBalancerType;
|
||||
import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl;
|
||||
import org.jclouds.location.predicates.LocationPredicates;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -41,20 +43,20 @@ import com.google.common.collect.Iterables;
|
|||
*/
|
||||
@Singleton
|
||||
public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer, LoadBalancerMetadata> {
|
||||
protected final Supplier<Map<String, ? extends Location>> locationMap;
|
||||
protected final Supplier<Set<? extends Location>> locations;
|
||||
protected final Supplier<Location> defaultLocationSupplier;
|
||||
|
||||
@Inject
|
||||
public LoadBalancerToLoadBalancerMetadata(Supplier<Location> defaultLocationSupplier,
|
||||
Supplier<Map<String, ? extends Location>> locationMap) {
|
||||
this.locationMap = locationMap;
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
this.locations = locations;
|
||||
this.defaultLocationSupplier = defaultLocationSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadBalancerMetadata apply(LoadBalancer input) {
|
||||
|
||||
Location location = locationMap.get().get(input.getRegion());
|
||||
Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(input.getRegion()));
|
||||
|
||||
String id = input.getRegion() + "/" + input.getId();
|
||||
// TODO Builder
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
package org.jclouds.cloudloadbalancers;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||
import static org.jclouds.cloudloadbalancers.reference.RackspaceConstants.PROPERTY_ACCOUNT_ID;
|
||||
import static org.jclouds.cloudloadbalancers.reference.Region.DFW;
|
||||
import static org.jclouds.location.reference.LocationConstants.ENDPOINT;
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -84,9 +89,12 @@ public class CloudLoadBalancersAsyncClientTest extends BaseCloudLoadBalancersAsy
|
|||
@Override
|
||||
protected Properties getProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(PROPERTY_REGIONS, "US");
|
||||
overrides.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com");
|
||||
overrides.setProperty(PROPERTY_API_VERSION, "1");
|
||||
overrides.setProperty(provider + ".endpoint", "https://auth");
|
||||
overrides.setProperty(PROPERTY_REGIONS, "DFW");
|
||||
overrides.setProperty(PROPERTY_REGION + "." + DFW + "." + ENDPOINT, String
|
||||
.format("https://dfw.loadbalancers.api.rackspacecloud.com/v{%s}/{%s}", PROPERTY_API_VERSION,
|
||||
PROPERTY_ACCOUNT_ID));
|
||||
overrides.setProperty(provider + ".contextbuilder", CloudLoadBalancersContextBuilder.class.getName());
|
||||
return overrides;
|
||||
}
|
||||
|
|
|
@ -28,22 +28,33 @@ import java.util.Properties;
|
|||
import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient;
|
||||
import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient;
|
||||
import org.jclouds.cloudloadbalancers.config.CloudLoadBalancersRestClientModule;
|
||||
import org.jclouds.cloudloadbalancers.functions.ConvertLB;
|
||||
import org.jclouds.cloudloadbalancers.reference.Region;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.internal.ClassMethodArgs;
|
||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
||||
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
|
||||
import org.jclouds.openstack.filters.AuthenticateRequest;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import com.google.inject.util.Types;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -58,11 +69,39 @@ public abstract class BaseCloudLoadBalancersAsyncClientTest<T> extends RestClien
|
|||
bindRegionsToProvider(Regions.class);
|
||||
}
|
||||
|
||||
//TODO: replace this with Expect test
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void configure() {
|
||||
// following from CloudLoadBalancersRestClientModule, except we are hard-coding the auth response
|
||||
install(new OpenStackAuthenticationModule() {
|
||||
@Override
|
||||
protected Supplier<AuthenticationResponse> provideAuthenticationResponseCache(
|
||||
final GetAuthenticationResponse getAuthenticationResponse) {
|
||||
return Suppliers.ofInstance(new AuthenticationResponse("token", ImmutableMap.<String, URI> of()));
|
||||
}
|
||||
});
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
bindRegionsToProvider();
|
||||
install(new FactoryModuleBuilder().build(ConvertLB.Factory.class));
|
||||
|
||||
// following from RestClientModule
|
||||
bind(new TypeLiteral<RestContext>() {
|
||||
}).to(
|
||||
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(
|
||||
RestContextImpl.class, syncClientType, asyncClientType))).in(
|
||||
Scopes.SINGLETON);
|
||||
bindAsyncClient();
|
||||
bindClient();
|
||||
bindErrorHandlers();
|
||||
bindRetryHandlers();
|
||||
}
|
||||
|
||||
static class Regions implements javax.inject.Provider<Map<String, URI>> {
|
||||
@Override
|
||||
public Map<String, URI> get() {
|
||||
return ImmutableMap.<String, URI> of("DFW",
|
||||
URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234"));
|
||||
return ImmutableMap.<String, URI> of("DFW", URI
|
||||
.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,8 +134,8 @@ public abstract class BaseCloudLoadBalancersAsyncClientTest<T> extends RestClien
|
|||
super.setupFactory();
|
||||
try {
|
||||
processor.setCaller(new ClassMethodArgs(CloudLoadBalancersAsyncClient.class,
|
||||
CloudLoadBalancersAsyncClient.class.getMethod("getLoadBalancerClient", String.class),
|
||||
new Object[] { Region.DFW }));
|
||||
CloudLoadBalancersAsyncClient.class.getMethod("getLoadBalancerClient", String.class),
|
||||
new Object[] { Region.DFW }));
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
|
|
|
@ -21,17 +21,17 @@ package org.jclouds.cloudstack.filters;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.IntegrationTestAsyncClient;
|
||||
import org.jclouds.http.IntegrationTestClient;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -48,8 +48,8 @@ import com.google.inject.Module;
|
|||
@Test(groups = "unit", testName = "QuerySignerTest")
|
||||
public class QuerySignerTest {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static final RestContextSpec<Map, List> DUMMY_SPEC = new RestContextSpec<Map, List>("cloudstack",
|
||||
"http://localhost:8080/client/api", "2.2", "", "", "apiKey", "secretKey", Map.class, List.class,
|
||||
public static final RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> DUMMY_SPEC = new RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient>("cloudstack",
|
||||
"http://localhost:8080/client/api", "2.2", "", "", "apiKey", "secretKey", IntegrationTestClient.class, IntegrationTestAsyncClient.class,
|
||||
PropertiesBuilder.class, (Class) RestContextBuilder.class, ImmutableList.<Module> of(new MockModule(),
|
||||
new NullLoggingModule(), new AbstractModule() {
|
||||
@Override
|
||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.blobstore.config;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.BlobRequestSigner;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
|
@ -36,7 +34,6 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.location.config.JustProviderLocationModule;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
|
@ -63,13 +60,9 @@ public class TransientBlobStoreContextModule extends AbstractModule {
|
|||
install(new BlobStoreObjectModule());
|
||||
install(new BlobStoreMapModule());
|
||||
install(new JustProviderLocationModule());
|
||||
bind(BlobStore.class).to(TransientBlobStore.class);
|
||||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||
bind(BlobRequestSigner.class).to(TransientBlobRequestSigner.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
BlobStore provide(TransientBlobStore in) {
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,15 +17,13 @@
|
|||
* under the License.
|
||||
*/
|
||||
package org.jclouds.aws.filters;
|
||||
|
||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.http.IntegrationTestAsyncClient;
|
||||
import org.jclouds.http.IntegrationTestClient;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
|
@ -49,8 +47,9 @@ import com.google.inject.name.Names;
|
|||
@Test(groups = "unit", testName = "FormSignerTest")
|
||||
public class FormSignerTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final RestContextSpec<Map, List> DUMMY_SPEC = new RestContextSpec<Map, List>("provider", "endpoint",
|
||||
"apiVersion", "buildVersion", "", "identity", "credential", Map.class, List.class, PropertiesBuilder.class,
|
||||
public static final RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> DUMMY_SPEC = new RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient>(
|
||||
"provider", "endpoint", "apiVersion", "buildVersion", "", "identity", "credential",
|
||||
IntegrationTestClient.class, IntegrationTestAsyncClient.class, PropertiesBuilder.class,
|
||||
(Class) RestContextBuilder.class, ImmutableList.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
|
|
|
@ -22,8 +22,6 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
@ -31,6 +29,8 @@ import javax.ws.rs.core.HttpHeaders;
|
|||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.azure.storage.config.AzureStorageRestClientModule;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.IntegrationTestAsyncClient;
|
||||
import org.jclouds.http.IntegrationTestClient;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
|
@ -137,10 +137,11 @@ public class SharedKeyLiteAuthenticationTest {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final RestContextSpec<Map, List> DUMMY_SPEC = new RestContextSpec<Map, List>("provider", "endpoint",
|
||||
"apiVersion", "buildVersion", "", "identity", "credential", Map.class, List.class, PropertiesBuilder.class,
|
||||
(Class) RestContextBuilder.class, ImmutableList.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||
new AzureStorageRestClientModule<Exception, RuntimeException>(Exception.class,
|
||||
RuntimeException.class)));
|
||||
public static final RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient> DUMMY_SPEC = new RestContextSpec<IntegrationTestClient, IntegrationTestAsyncClient>(
|
||||
"provider", "endpoint", "apiVersion", "buildVersion", "", "identity", "credential", IntegrationTestClient.class,
|
||||
IntegrationTestAsyncClient.class, PropertiesBuilder.class, (Class) RestContextBuilder.class, ImmutableList
|
||||
.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||
new AzureStorageRestClientModule<IntegrationTestClient, IntegrationTestAsyncClient>(IntegrationTestClient.class,
|
||||
IntegrationTestAsyncClient.class)));
|
||||
|
||||
}
|
|
@ -104,7 +104,7 @@ public class OpenStackAuthenticationModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
Supplier<AuthenticationResponse> provideAuthenticationResponseCache(
|
||||
protected Supplier<AuthenticationResponse> provideAuthenticationResponseCache(
|
||||
final GetAuthenticationResponse getAuthenticationResponse) {
|
||||
return Suppliers.memoizeWithExpiration(new RetryOnTimeOutExceptionSupplier<AuthenticationResponse>(
|
||||
getAuthenticationResponse), 23, TimeUnit.HOURS);
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
|
@ -109,8 +108,7 @@ public class BlockUntilInitScriptStatusIsZeroThenReturnOutput extends AbstractFu
|
|||
* Submits a thread that will either set the result of the future or the exception that took
|
||||
* place
|
||||
*/
|
||||
@PostConstruct
|
||||
BlockUntilInitScriptStatusIsZeroThenReturnOutput init() {
|
||||
public BlockUntilInitScriptStatusIsZeroThenReturnOutput init() {
|
||||
userThreads.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.compute.callables;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
||||
|
@ -61,7 +60,6 @@ public class SudoAwareInitManager {
|
|||
this.init = checkNotNull(init, "init");
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public SudoAwareInitManager init() {
|
||||
ssh = sshFactory.apply(node);
|
||||
return this;
|
||||
|
|
|
@ -81,7 +81,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new LocationModule(authException));
|
||||
configureLocationModule();
|
||||
install(new ComputeServiceTimeoutsModule());
|
||||
bind(new TypeLiteral<Function<NodeMetadata, SshClient>>() {
|
||||
}).to(CreateSshClientOncePortIsListeningOnNode.class);
|
||||
|
@ -115,6 +115,10 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
install(new FactoryModuleBuilder().build(BlockUntilInitScriptStatusIsZeroThenReturnOutput.Factory.class));
|
||||
}
|
||||
|
||||
protected void configureLocationModule() {
|
||||
install(new LocationModule(authException));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
static class RunScriptOnNodeFactoryImpl implements RunScriptOnNode.Factory {
|
||||
|
||||
|
|
|
@ -18,11 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.compute.config;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.collect.TransformingSetSupplier;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
|
@ -41,10 +45,13 @@ import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
|||
import org.jclouds.compute.strategy.impl.AdaptingComputeServiceStrategies;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
@ -64,33 +71,39 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
|
|||
this.asyncClientType = asyncClientType;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings( { "unchecked", "rawtypes" })
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||
}).to((TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class, syncClientType,
|
||||
asyncClientType))).in(Scopes.SINGLETON);
|
||||
}).to(
|
||||
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class,
|
||||
syncClientType, asyncClientType))).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureLocationModule() {
|
||||
// configuring below
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Location>> provideLocations(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<L, Location> transformer) {
|
||||
return new TransformingSetSupplier<L, Location>(new Supplier<Iterable<L>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<L> get() {
|
||||
return adapter.listLocations();
|
||||
}
|
||||
|
||||
}, transformer);
|
||||
@Memoized
|
||||
protected Supplier<Set<? extends Location>> supplyLocationCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final ComputeServiceAdapter<N, H, I, L> adapter, final Function<L, Location> transformer) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Location>>(authException,
|
||||
seconds, new Supplier<Set<? extends Location>>() {
|
||||
@Override
|
||||
public Set<? extends Location> get() {
|
||||
return ImmutableSet.<Location> copyOf(Iterables.transform(adapter.listLocations(), transformer));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Hardware>> provideHardware(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<H, Hardware> transformer) {
|
||||
Function<H, Hardware> transformer) {
|
||||
return new TransformingSetSupplier<H, Hardware>(new Supplier<Iterable<H>>() {
|
||||
|
||||
@Override
|
||||
|
@ -104,7 +117,7 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Image>> provideImages(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<I, Image> transformer, AddDefaultCredentialsToImage addDefaultCredentialsToImage) {
|
||||
Function<I, Image> transformer, AddDefaultCredentialsToImage addDefaultCredentialsToImage) {
|
||||
return new TransformingSetSupplier<I, Image>(new Supplier<Iterable<I>>() {
|
||||
|
||||
@Override
|
||||
|
@ -139,7 +152,7 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
|
|||
@Provides
|
||||
@Singleton
|
||||
protected CreateNodeWithGroupEncodedIntoName defineAddNodeWithTagStrategy(
|
||||
AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||
AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ import java.util.Set;
|
|||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -43,18 +43,18 @@ import com.google.inject.Inject;
|
|||
@Singleton
|
||||
public class NodePresentAndInIntendedState implements Predicate<NodeMetadata> {
|
||||
|
||||
private final ComputeService client;
|
||||
private final GetNodeMetadataStrategy client;
|
||||
private final NodeState intended;
|
||||
private final Set<NodeState> invalids;
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public NodePresentAndInIntendedState(NodeState intended, ComputeService client) {
|
||||
public NodePresentAndInIntendedState(NodeState intended, GetNodeMetadataStrategy client) {
|
||||
this(intended, ImmutableSet.of(NodeState.ERROR), client);
|
||||
}
|
||||
|
||||
public NodePresentAndInIntendedState(NodeState intended, Set<NodeState> invalids, ComputeService client) {
|
||||
public NodePresentAndInIntendedState(NodeState intended, Set<NodeState> invalids, GetNodeMetadataStrategy client) {
|
||||
this.intended = intended;
|
||||
this.client = client;
|
||||
this.invalids = invalids;
|
||||
|
@ -75,6 +75,6 @@ public class NodePresentAndInIntendedState implements Predicate<NodeMetadata> {
|
|||
private NodeMetadata refresh(NodeMetadata node) {
|
||||
if (node == null || node.getId() == null)
|
||||
return null;
|
||||
return client.getNodeMetadata(node.getId());
|
||||
return client.getNode(node.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ package org.jclouds.compute.predicates;
|
|||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -36,7 +36,7 @@ import com.google.inject.Inject;
|
|||
public class NodeRunning extends NodePresentAndInIntendedState {
|
||||
|
||||
@Inject
|
||||
public NodeRunning(ComputeService client) {
|
||||
public NodeRunning(GetNodeMetadataStrategy client) {
|
||||
super(NodeState.RUNNING, ImmutableSet.of(NodeState.ERROR, NodeState.TERMINATED), client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ package org.jclouds.compute.predicates;
|
|||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
|
@ -35,7 +35,7 @@ import com.google.inject.Inject;
|
|||
public class NodeSuspended extends NodePresentAndInIntendedState {
|
||||
|
||||
@Inject
|
||||
public NodeSuspended(ComputeService client) {
|
||||
public NodeSuspended(GetNodeMetadataStrategy client) {
|
||||
super(NodeState.SUSPENDED, client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -40,13 +40,13 @@ import com.google.inject.Inject;
|
|||
@Singleton
|
||||
public class NodeTerminated implements Predicate<NodeMetadata> {
|
||||
|
||||
private final ComputeService client;
|
||||
private final GetNodeMetadataStrategy client;
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public NodeTerminated(ComputeService client) {
|
||||
public NodeTerminated(GetNodeMetadataStrategy client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,6 @@ public class NodeTerminated implements Predicate<NodeMetadata> {
|
|||
}
|
||||
|
||||
private NodeMetadata refresh(NodeMetadata node) {
|
||||
return client.getNodeMetadata(node.getId());
|
||||
return client.getNode(node.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.ssh;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
|
@ -56,10 +53,8 @@ public interface SshClient {
|
|||
|
||||
ExecResponse exec(String command);
|
||||
|
||||
@PostConstruct
|
||||
void connect();
|
||||
|
||||
@PreDestroy
|
||||
void disconnect();
|
||||
|
||||
void put(String path, String contents);
|
||||
|
|
|
@ -22,9 +22,9 @@ import static org.easymock.EasyMock.expect;
|
|||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -38,15 +38,15 @@ import org.testng.annotations.Test;
|
|||
public class NodePredicatesTest {
|
||||
|
||||
private NodeMetadata node;
|
||||
private ComputeService computeService;
|
||||
private GetNodeMetadataStrategy computeService;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() throws Exception {
|
||||
node = createMock(NodeMetadata.class);
|
||||
computeService = createMock(ComputeService.class);
|
||||
computeService = createMock(GetNodeMetadataStrategy.class);
|
||||
|
||||
expect(node.getId()).andReturn("myid").anyTimes();
|
||||
expect(computeService.getNodeMetadata("myid")).andReturn(node).anyTimes();
|
||||
expect(computeService.getNode("myid")).andReturn(node).anyTimes();
|
||||
expect(node.getLocation()).andReturn(null).anyTimes();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ import org.jclouds.Constants;
|
|||
import org.jclouds.concurrent.MoreExecutors;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.util.concurrent.ExecutionList;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.Stage;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.spi.InjectionListener;
|
||||
|
@ -143,9 +143,9 @@ public class LifeCycleModule extends AbstractModule {
|
|||
method.invoke(injectee);
|
||||
} catch (InvocationTargetException ie) {
|
||||
Throwable e = ie.getTargetException();
|
||||
throw new ProvisionException(e.getMessage(), e);
|
||||
throw Throwables.propagate(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ProvisionException(e.getMessage(), e);
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}, MoreExecutors.sameThreadExecutor());
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.location.config;
|
|||
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -32,10 +31,7 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
|
@ -54,27 +50,6 @@ public class LocationModule extends AbstractModule {
|
|||
this.authException = authException;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Location>> provideLocationMap(
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, ? extends Location>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Location> apply(Set<? extends Location> from) {
|
||||
return Maps.uniqueIndex(from, new Function<Location, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Location from) {
|
||||
return from.getId();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}, locations);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
|
|
|
@ -68,6 +68,30 @@ public class LocationPredicates {
|
|||
}
|
||||
}
|
||||
|
||||
public static Predicate<Location> idEquals(String id) {
|
||||
return new IdEquals(id);
|
||||
}
|
||||
|
||||
static class IdEquals implements Predicate<Location> {
|
||||
|
||||
private final String id;
|
||||
|
||||
IdEquals(String id) {
|
||||
this.id = checkNotNull(id, "id");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
|
||||
return input.getId().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "idEquals(" + id + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public static Predicate<Location> isZoneOrRegionWhereRegionIdEquals(String region) {
|
||||
return new IsZoneOrRegionWhereRegionIdEquals(region);
|
||||
}
|
||||
|
|
|
@ -2426,8 +2426,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "", "userfoo",
|
||||
null, String.class, Integer.class,
|
||||
RestContextSpec<Callee, AsyncCallee> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "", "userfoo",
|
||||
null, Callee.class, AsyncCallee.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.io.InputStream;
|
|||
import java.net.ConnectException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
@ -224,7 +223,6 @@ public class JschSshClient implements SshClient {
|
|||
return null;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void connect() {
|
||||
acquire(sessionConnection);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import java.net.ConnectException;
|
|||
import java.net.SocketTimeoutException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
@ -248,7 +247,6 @@ public class SshjSshClient implements SshClient {
|
|||
return null;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void connect() {
|
||||
try {
|
||||
ssh = acquire(sshConnection);
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.loadbalancer.config;
|
|||
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -32,10 +31,7 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
|
@ -52,27 +48,6 @@ public abstract class BaseLoadBalancerServiceContextModule extends AbstractModul
|
|||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Location>> provideLocationMap(
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, ? extends Location>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Location> apply(Set<? extends Location> from) {
|
||||
return Maps.uniqueIndex(from, new Function<Location, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Location from) {
|
||||
return from.getId();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}, locations);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
|
||||
|
||||
|
@ -38,6 +37,7 @@ import org.jclouds.compute.domain.NodeState;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.ServerState;
|
||||
import org.jclouds.location.predicates.LocationPredicates;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -57,7 +57,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
private final Map<ServerState, NodeState> serverStateToNodeState;
|
||||
private final Supplier<Set<? extends Image>> images;
|
||||
private final Supplier<Set<? extends Hardware>> hardwares;
|
||||
private final Supplier<Map<String, ? extends Location>> locations;
|
||||
private final Supplier<Set<? extends Location>> locations;
|
||||
|
||||
static class FindImageForServer implements Predicate<Image> {
|
||||
private final Server instance;
|
||||
|
@ -92,7 +92,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
@Inject
|
||||
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState,
|
||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
|
||||
Supplier<Map<String, ? extends Location>> locations) {
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
||||
this.images = checkNotNull(images, "images");
|
||||
this.hardwares = checkNotNull(hardwares, "hardwares");
|
||||
|
@ -104,7 +104,8 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
builder.ids(from.getId() + "");
|
||||
builder.name(from.getName());
|
||||
builder.location(locations.get().get(from.getDatacenter().getId() + ""));
|
||||
Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + ""));
|
||||
builder.location(location);
|
||||
builder.group(parseGroupFromName(from.getName()));
|
||||
builder.hardware(parseHardware(from));
|
||||
builder.imageId(from.getImage().getId() + "");
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.jclouds.gogrid.domain.ServerState;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
|
@ -73,7 +72,7 @@ public class ServerToNodeMetadataTest {
|
|||
expect(serverStateToNodeState.get(ServerState.ON)).andReturn(NodeState.RUNNING);
|
||||
|
||||
Location location = new LocationBuilder().scope(LocationScope.ZONE).id("1").description("US-West-1").build();
|
||||
Map<String, ? extends Location> locations = ImmutableMap.<String, Location> of("1", location);
|
||||
Set< ? extends Location> locations = ImmutableSet.< Location> of( location);
|
||||
|
||||
expect(server.getIp()).andReturn(new Ip("127.0.0.1"));
|
||||
|
||||
|
@ -94,7 +93,7 @@ public class ServerToNodeMetadataTest {
|
|||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||
.<Set<? extends Hardware>> ofInstance(GoGridHardwareSupplier.H_ALL), Suppliers
|
||||
.<Map<String, ? extends Location>> ofInstance(locations));
|
||||
.<Set<? extends Location>> ofInstance(locations));
|
||||
|
||||
NodeMetadata metadata = parser.apply(server);
|
||||
assertEquals(metadata.getLocation(), location);
|
||||
|
|
Loading…
Reference in New Issue