mirror of https://github.com/apache/jclouds.git
created base Context class with ProviderMetadata and Identity
This commit is contained in:
parent
35bbd4b97a
commit
886d2cafb9
|
@ -26,9 +26,9 @@ import java.util.Set;
|
|||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
|
@ -73,14 +73,16 @@ public class ComputeTaskUtils {
|
|||
public ComputeServiceContext load(URI from) {
|
||||
Properties props = new Properties();
|
||||
props.putAll(projectProvider.get().getProperties());
|
||||
Set<Module> modules = ImmutableSet.<Module> of(new AntLoggingModule(projectProvider.get(),
|
||||
ComputeServiceConstants.COMPUTE_LOGGER), new JschSshClientModule());
|
||||
// adding the properties to the factory will allow us to pass
|
||||
// alternate endpoints
|
||||
String provider = from.getHost();
|
||||
Credentials creds = Credentials.parse(from);
|
||||
return new ComputeServiceContextFactory().createContext(provider, creds.identity, creds.credential,
|
||||
ImmutableSet.of((Module) new AntLoggingModule(projectProvider.get(),
|
||||
ComputeServiceConstants.COMPUTE_LOGGER), new JschSshClientModule()), props);
|
||||
|
||||
return ContextBuilder.newBuilder(provider)
|
||||
.credentials(creds.identity, creds.credential)
|
||||
.modules(modules)
|
||||
.overrides(props).buildAndWrapWith(ComputeServiceContext.class);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
package org.jclouds.atmos.filters;
|
||||
|
||||
import static org.jclouds.Constants.LOGGER_SIGNATURE;
|
||||
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
|
@ -37,6 +35,8 @@ import org.jclouds.http.HttpException;
|
|||
import org.jclouds.io.InputSuppliers;
|
||||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.annotations.Credential;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -66,7 +66,7 @@ public class ShareUrl implements Function<String, URI> {
|
|||
Logger signatureLog = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public ShareUrl(@Named(PROPERTY_IDENTITY) String uid, @Named(PROPERTY_CREDENTIAL) String encodedKey,
|
||||
public ShareUrl(@Identity String uid, @Credential String encodedKey,
|
||||
@Provider Supplier<URI> provider, @TimeStamp javax.inject.Provider<Long> timeStampProvider,
|
||||
javax.inject.Provider<UriBuilder> uriBuilders, Crypto crypto) {
|
||||
this.uid = uid;
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
package org.jclouds.atmos.filters;
|
||||
|
||||
import static org.jclouds.Constants.LOGGER_SIGNATURE;
|
||||
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
||||
import static org.jclouds.util.Patterns.TWO_SPACE_PATTERN;
|
||||
|
||||
|
@ -46,6 +44,8 @@ import org.jclouds.http.internal.SignatureWire;
|
|||
import org.jclouds.http.utils.ModifyRequest;
|
||||
import org.jclouds.io.InputSuppliers;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.annotations.Credential;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -79,8 +79,8 @@ public class SignRequest implements HttpRequestFilter {
|
|||
Logger signatureLog = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public SignRequest(SignatureWire signatureWire, @Named(PROPERTY_IDENTITY) String uid,
|
||||
@Named(PROPERTY_CREDENTIAL) String encodedKey, @TimeStamp Provider<String> timeStampProvider, Crypto crypto,
|
||||
public SignRequest(SignatureWire signatureWire, @Identity String uid,
|
||||
@Credential String encodedKey, @TimeStamp Provider<String> timeStampProvider, Crypto crypto,
|
||||
HttpUtils utils) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.uid = uid;
|
||||
|
|
|
@ -57,7 +57,7 @@ import com.google.common.collect.Sets;
|
|||
public class AtmosClientLiveTest extends BaseBlobStoreIntegrationTest {
|
||||
|
||||
public AtmosClient getApi() {
|
||||
return context.unwrap(AtmosApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
return wrapper.unwrap(AtmosApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
}
|
||||
|
||||
private static final class HeadMatches implements Runnable {
|
||||
|
|
|
@ -34,6 +34,6 @@ public class AtmosLiveTest extends BaseBlobLiveTest {
|
|||
}
|
||||
protected void checkMD5(String container, String name, byte[] md5) {
|
||||
// atmos does not support content-md5 yet
|
||||
assertEquals(context.getBlobStore().blobMetadata(container, name).getContentMetadata().getContentMD5(), null);
|
||||
assertEquals(wrapper.getBlobStore().blobMetadata(container, name).getContentMetadata().getContentMD5(), null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class CloudFilesClientLiveTest extends CommonSwiftClientLiveTest<CloudFil
|
|||
|
||||
@Override
|
||||
public CloudFilesClient getApi() {
|
||||
return context.unwrap(CloudFilesApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
return wrapper.unwrap(CloudFilesApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -77,6 +77,7 @@ public abstract class BaseCloudLoadBalancersAsyncClientTest<T> extends BaseAsync
|
|||
protected void configure() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Singleton
|
||||
GetAuth provideGetAuth() {
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.cloudloadbalancers.internal;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.apis.BaseContextLiveTest;
|
||||
import org.jclouds.apis.BaseWrapperLiveTest;
|
||||
import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient;
|
||||
import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient;
|
||||
import org.jclouds.cloudloadbalancers.domain.LoadBalancer;
|
||||
|
@ -42,7 +42,7 @@ import com.google.inject.Injector;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BaseCloudLoadBalancersClientLiveTest extends BaseContextLiveTest<LoadBalancerServiceContext> {
|
||||
public class BaseCloudLoadBalancersClientLiveTest extends BaseWrapperLiveTest<LoadBalancerServiceContext> {
|
||||
|
||||
public BaseCloudLoadBalancersClientLiveTest() {
|
||||
provider = "cloudloadbalancers";
|
||||
|
@ -61,7 +61,7 @@ public class BaseCloudLoadBalancersClientLiveTest extends BaseContextLiveTest<Lo
|
|||
@Override
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
lbContext = context.unwrap();
|
||||
lbContext = wrapper.unwrap();
|
||||
|
||||
client = lbContext.getApi();
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class BaseCloudLoadBalancersClientLiveTest extends BaseContextLiveTest<Lo
|
|||
}
|
||||
|
||||
@Override
|
||||
protected TypeToken<LoadBalancerServiceContext> contextType() {
|
||||
protected TypeToken<LoadBalancerServiceContext> wrapperType() {
|
||||
return TypeToken.of(LoadBalancerServiceContext.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
@Override
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
Injector injector = context.utils().injector();
|
||||
Injector injector = wrapper.utils().injector();
|
||||
client = injector.getInstance(CloudServersClient.class);
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||
|
|
|
@ -89,7 +89,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest
|
|||
@Override
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
cloudSigmaContext = context.unwrap();
|
||||
cloudSigmaContext = wrapper.unwrap();
|
||||
|
||||
client = cloudSigmaContext.getApi();
|
||||
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime,
|
||||
|
@ -98,7 +98,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest
|
|||
TimeUnit.SECONDS);
|
||||
|
||||
if (Strings.emptyToNull(imageId) == null) {
|
||||
imageId = context.getComputeService().templateBuilder().build().getImage().getId();
|
||||
imageId = wrapper.getComputeService().templateBuilder().build().getImage().getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ import org.jclouds.http.utils.ModifyRequest;
|
|||
import org.jclouds.io.InputSuppliers;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
import org.jclouds.rest.annotations.Credential;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -71,9 +73,8 @@ public class QuerySigner implements AuthenticationFilter, RequestSigner {
|
|||
private Logger signatureLog = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public QuerySigner(SignatureWire signatureWire, @Named(Constants.PROPERTY_IDENTITY) String accessKey,
|
||||
@Named(Constants.PROPERTY_CREDENTIAL) String secretKey, Crypto crypto, HttpUtils utils,
|
||||
Provider<UriBuilder> builder) {
|
||||
public QuerySigner(SignatureWire signatureWire, @Identity String accessKey, @Credential String secretKey,
|
||||
Crypto crypto, HttpUtils utils, Provider<UriBuilder> builder) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.accessKey = accessKey;
|
||||
this.secretKey = secretKey;
|
||||
|
|
|
@ -18,12 +18,10 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.internal;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.CloudStackContext;
|
||||
|
@ -34,7 +32,6 @@ import org.jclouds.cloudstack.CloudStackGlobalClient;
|
|||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.Utils;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
|
@ -49,11 +46,11 @@ public class CloudStackContextImpl extends ComputeServiceContextImpl implements
|
|||
private final RestContext<CloudStackGlobalClient, CloudStackGlobalAsyncClient> globalContext;
|
||||
|
||||
@Inject
|
||||
public CloudStackContextImpl(@Provider Closeable wrapped, @Provider TypeToken<? extends Closeable> wrappedType,
|
||||
ComputeService computeService, Map<String, Credentials> credentialStore, Utils utils,
|
||||
public CloudStackContextImpl(@Provider Context wrapped, @Provider TypeToken<? extends Context> wrappedType,
|
||||
ComputeService computeService, Utils utils,
|
||||
RestContext<CloudStackDomainClient, CloudStackDomainAsyncClient> domainContext,
|
||||
RestContext<CloudStackGlobalClient, CloudStackGlobalAsyncClient> globalContext) {
|
||||
super(wrapped, wrappedType, computeService, credentialStore, utils);
|
||||
super(wrapped, wrappedType, computeService, utils);
|
||||
this.domainContext = domainContext;
|
||||
this.globalContext = globalContext;
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
|
|||
public void testCreateNodeWithGroupEncodedIntoName() throws InterruptedException {
|
||||
String group = prefix + "-foo";
|
||||
String name = group + "-node-" + new Random().nextInt();
|
||||
Template template = context.getComputeService().templateBuilder().build();
|
||||
Template template = wrapper.getComputeService().templateBuilder().build();
|
||||
|
||||
if (!client
|
||||
.getTemplateClient()
|
||||
|
|
|
@ -90,9 +90,9 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
|
|||
Network network = null;
|
||||
Set<? extends NodeMetadata> nodes = null;
|
||||
try {
|
||||
assert context.getComputeService().listAssignableLocations().size() > 0;
|
||||
assert wrapper.getComputeService().listAssignableLocations().size() > 0;
|
||||
|
||||
Template template = context.getComputeService().templateBuilder().build();
|
||||
Template template = wrapper.getComputeService().templateBuilder().build();
|
||||
|
||||
// get the zone we are launching into
|
||||
long zoneId = Long.parseLong(template.getLocation().getId());
|
||||
|
@ -115,7 +115,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
|
|||
template.getOptions().as(CloudStackTemplateOptions.class).networkId(network.getId());
|
||||
|
||||
// launch the VM
|
||||
nodes = context.getComputeService().createNodesInGroup(group, 1, template);
|
||||
nodes = wrapper.getComputeService().createNodesInGroup(group, 1, template);
|
||||
|
||||
assert nodes.size() > 0;
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
|
|||
nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
|
||||
} finally {
|
||||
if (nodes != null)
|
||||
context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
|
||||
wrapper.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
|
||||
if (network != null)
|
||||
domainAdminContext.getApi().getNetworkClient().deleteNetwork(network.getId());
|
||||
}
|
||||
|
@ -143,14 +143,14 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
|
|||
SshKeyPair keyPair = client.getSSHKeyPairClient().createSSHKeyPair(keyPairName);
|
||||
|
||||
String group = prefix + "-windows-test";
|
||||
Template template = context.getComputeService().templateBuilder()
|
||||
Template template = wrapper.getComputeService().templateBuilder()
|
||||
.imageId("290").locationId("1")
|
||||
.options(new CloudStackTemplateOptions().setupStaticNat(false).keyPair(keyPairName))
|
||||
.build();
|
||||
|
||||
NodeMetadata node = null;
|
||||
try {
|
||||
node = getOnlyElement(context.getComputeService()
|
||||
node = getOnlyElement(wrapper.getComputeService()
|
||||
.createNodesInGroup(group, 1, template));
|
||||
|
||||
String encryptedPassword = client.getVirtualMachineClient()
|
||||
|
@ -165,7 +165,7 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
} finally {
|
||||
if (node != null) {
|
||||
context.getComputeService().destroyNode(node.getId());
|
||||
wrapper.getComputeService().destroyNode(node.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.jclouds.cloudstack.predicates.VirtualMachineRunning;
|
|||
import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
|
||||
import org.jclouds.compute.internal.BaseGenericComputeServiceContextLiveTest;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
|
@ -65,6 +65,7 @@ import com.google.common.base.Predicate;
|
|||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
|
@ -73,7 +74,7 @@ import com.google.inject.Module;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BaseCloudStackClientLiveTest extends BaseComputeServiceContextLiveTest {
|
||||
public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceContextLiveTest<CloudStackContext> {
|
||||
protected String domainAdminIdentity;
|
||||
protected String domainAdminCredential;
|
||||
protected String globalAdminIdentity;
|
||||
|
@ -83,6 +84,11 @@ public class BaseCloudStackClientLiveTest extends BaseComputeServiceContextLiveT
|
|||
provider = "cloudstack";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeToken<CloudStackContext> wrapperType() {
|
||||
return TypeToken.of(CloudStackContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = super.setupProperties();
|
||||
|
@ -193,14 +199,14 @@ public class BaseCloudStackClientLiveTest extends BaseComputeServiceContextLiveT
|
|||
@Override
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
computeClient = context.getComputeService();
|
||||
cloudStackContext = context.unwrap();
|
||||
computeClient = wrapper.getComputeService();
|
||||
cloudStackContext = wrapper.unwrap();
|
||||
client = cloudStackContext.getApi();
|
||||
user = verifyCurrentUserIsOfType(cloudStackContext, Account.Type.USER);
|
||||
|
||||
domainAdminEnabled = setupDomainAdminProperties() != null;
|
||||
if (domainAdminEnabled) {
|
||||
domainAdminComputeContext = createContext(setupDomainAdminProperties(), setupModules()).unwrap();
|
||||
domainAdminComputeContext = createWrapper(setupDomainAdminProperties(), setupModules());
|
||||
domainAdminContext = domainAdminComputeContext.getDomainContext();
|
||||
domainAdminClient = domainAdminContext.getApi();
|
||||
domainAdminUser = verifyCurrentUserIsOfType(domainAdminContext, Account.Type.DOMAIN_ADMIN);
|
||||
|
@ -209,7 +215,7 @@ public class BaseCloudStackClientLiveTest extends BaseComputeServiceContextLiveT
|
|||
|
||||
globalAdminEnabled = setupGlobalAdminProperties() != null;
|
||||
if (globalAdminEnabled) {
|
||||
globalAdminComputeContext = createContext(setupGlobalAdminProperties(), setupModules()).unwrap();
|
||||
globalAdminComputeContext = createWrapper(setupGlobalAdminProperties(), setupModules());
|
||||
globalAdminContext = globalAdminComputeContext.getGlobalContext();
|
||||
globalAdminClient = globalAdminContext.getApi();
|
||||
globalAdminUser = verifyCurrentUserIsOfType(globalAdminContext, Account.Type.ADMIN);
|
||||
|
|
|
@ -27,6 +27,7 @@ import static org.testng.Assert.assertNotNull;
|
|||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudstack.CloudStackApiMetadata;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.CloudStackGlobalClient;
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
|
@ -83,9 +84,9 @@ public class GlobalUserClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
}
|
||||
|
||||
private void checkAuthAsUser(ApiKeyPair keyPair) {
|
||||
ComputeServiceContext context = createContext(credentialsAsProperties(keyPair), setupModules());
|
||||
ComputeServiceContext context = createWrapper(credentialsAsProperties(keyPair), setupModules());
|
||||
|
||||
CloudStackClient client = CloudStackClient.class.cast(context.getProviderSpecificContext().getApi());
|
||||
CloudStackClient client = context.unwrap(CloudStackApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
Set<Account> accounts = client.getAccountClient().listAccounts();
|
||||
|
||||
assert accounts.size() > 0;
|
||||
|
|
|
@ -66,7 +66,8 @@ public class OfferingClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
} catch (NoSuchElementException e) {
|
||||
// This bug is present both in 2.2.8 and 2.2.12
|
||||
assertTrue(Predicates.in(ImmutableSet.of("2.2.8", "2.2.12")).apply(cloudStackContext.getApiVersion()));
|
||||
assertTrue(Predicates.in(ImmutableSet.of("2.2.8", "2.2.12")).apply(
|
||||
cloudStackContext.getProviderMetadata().getApiMetadata().getVersion()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class SessionClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testCreateContextUsingUserAndPasswordAuthentication() {
|
||||
String endpoint = cloudStackContext.getEndpoint().toASCIIString();
|
||||
String endpoint = cloudStackContext.getProviderMetadata().getEndpoint();
|
||||
assert globalAdminEnabled;
|
||||
|
||||
Account testAccount = null;
|
||||
|
@ -75,7 +75,7 @@ public class SessionClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testTryToGetApiKeypairWithWrongCredentials() {
|
||||
String endpoint = cloudStackContext.getEndpoint().toASCIIString();
|
||||
String endpoint = cloudStackContext.getProviderMetadata().getEndpoint();
|
||||
ApiKeyPairs.loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair(
|
||||
URI.create(endpoint), "dummy-missing-user", "with-a-wrong-password", "");
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class ReadOnlyDeltacloudClientLiveTest extends BaseComputeServiceContextL
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.unwrap(DeltacloudApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
client = wrapper.unwrap(DeltacloudApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
|
||||
stateChanges = ImmutableMap.<Instance.State, Predicate<Instance>> of(//
|
||||
Instance.State.RUNNING, new RetryablePredicate<Instance>(new InstanceRunning(client), 600, 1,
|
||||
|
|
|
@ -70,7 +70,7 @@ public class DeltacloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTe
|
|||
|
||||
@Test
|
||||
public void testTemplateBuilder() {
|
||||
Template defaultTemplate = this.context.getComputeService().templateBuilder().build();
|
||||
Template defaultTemplate = this.wrapper.getComputeService().templateBuilder().build();
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
|
|
|
@ -18,15 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.ec2.compute.internal;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.compute.Utils;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.ec2.compute.EC2ComputeService;
|
||||
import org.jclouds.ec2.compute.EC2ComputeServiceContext;
|
||||
import org.jclouds.location.Provider;
|
||||
|
@ -39,9 +36,9 @@ import com.google.common.reflect.TypeToken;
|
|||
@Singleton
|
||||
public class EC2ComputeServiceContextImpl extends ComputeServiceContextImpl implements EC2ComputeServiceContext {
|
||||
@Inject
|
||||
public EC2ComputeServiceContextImpl(@Provider Closeable wrapped, @Provider TypeToken<? extends Closeable> wrappedType,
|
||||
EC2ComputeService computeService, Map<String, Credentials> credentialStore, Utils utils){
|
||||
super(wrapped, wrappedType, computeService, credentialStore, utils);
|
||||
public EC2ComputeServiceContextImpl(@Provider Context wrapped, @Provider TypeToken<? extends Context> wrappedType,
|
||||
EC2ComputeService computeService, Utils utils) {
|
||||
super(wrapped, wrappedType, computeService, utils);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,11 +20,9 @@ package org.jclouds.ec2.options;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.ec2.options.internal.BaseEC2RequestOptions;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -52,7 +50,7 @@ import com.google.inject.Inject;
|
|||
public class BundleInstanceS3StorageOptions extends BaseEC2RequestOptions {
|
||||
|
||||
@Inject(optional = true)
|
||||
@Named(PROPERTY_IDENTITY)
|
||||
@Identity
|
||||
String currentAwsAccessKeyId;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -95,7 +95,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
Injector injector = context.utils().injector();
|
||||
Injector injector = wrapper.utils().injector();
|
||||
client = injector.getInstance(EC2Client.class);
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client), 180, 5,
|
||||
|
|
|
@ -126,7 +126,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
Injector injector = context.utils().injector();
|
||||
Injector injector = wrapper.utils().injector();
|
||||
client = injector.getInstance(EC2Client.class);
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||
|
|
|
@ -102,13 +102,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
|
||||
@Test(enabled = true, dependsOnMethods = "testCompareSizes")
|
||||
public void testExtendedOptionsAndLogin() throws Exception {
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
.getSecurityGroupServices();
|
||||
|
||||
KeyPairClient keyPairClient = EC2Client.class.cast(context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
KeyPairClient keyPairClient = EC2Client.class.cast(wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
.getKeyPairServices();
|
||||
|
||||
InstanceClient instanceClient = EC2Client.class.cast(context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
InstanceClient instanceClient = EC2Client.class.cast(wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
.getInstanceServices();
|
||||
|
||||
String group = this.group + "o";
|
||||
|
@ -181,7 +181,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
Properties overrides = setupProperties();
|
||||
overrides.setProperty(EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "true");
|
||||
|
||||
context = createContext(overrides, setupModules());
|
||||
context = createWrapper(overrides, setupModules());
|
||||
|
||||
// create a node
|
||||
Set<? extends NodeMetadata> nodes =
|
||||
|
@ -233,19 +233,19 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
@Test(enabled = true)
|
||||
public void testMapEBS() throws Exception {
|
||||
|
||||
InstanceClient instanceClient = EC2Client.class.cast(context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
InstanceClient instanceClient = EC2Client.class.cast(wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
.getInstanceServices();
|
||||
|
||||
ElasticBlockStoreClient ebsClient = EC2Client.class.cast(context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
ElasticBlockStoreClient ebsClient = EC2Client.class.cast(wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
|
||||
.getElasticBlockStoreServices();
|
||||
|
||||
String group = this.group + "e";
|
||||
int volumeSize = 8;
|
||||
|
||||
final Template template = context.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL)
|
||||
final Template template = wrapper.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL)
|
||||
.osFamily(OsFamily.UBUNTU).osVersionMatches("10.04").imageDescriptionMatches(".*ebs.*").build();
|
||||
|
||||
Location zone = Iterables.find(context.getComputeService().listAssignableLocations(), new Predicate<Location>() {
|
||||
Location zone = Iterables.find(wrapper.getComputeService().listAssignableLocations(), new Predicate<Location>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Location arg0) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLive
|
|||
|
||||
@Test
|
||||
public void testTemplateBuilderCanUseImageIdWithoutFetchingAllImages() throws Exception {
|
||||
Template defaultTemplate = context.getComputeService().templateBuilder().build();
|
||||
Template defaultTemplate = wrapper.getComputeService().templateBuilder().build();
|
||||
String defaultImageId = defaultTemplate.getImage().getId();
|
||||
String defaultImageProviderId = defaultTemplate.getImage().getProviderId();
|
||||
|
||||
|
@ -58,7 +58,7 @@ public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLive
|
|||
try {
|
||||
// Track http commands
|
||||
final List<HttpCommand> commandsInvoked = Lists.newArrayList();
|
||||
context = createContext(
|
||||
context = createWrapper(
|
||||
setupProperties(),
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule(),
|
||||
TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked)));
|
||||
|
|
|
@ -39,18 +39,18 @@ public class TestCanRecreateGroupLiveTest extends BaseComputeServiceContextLiveT
|
|||
public void testCanRecreateGroup() throws Exception {
|
||||
|
||||
String tag = PREFIX + "recreate";
|
||||
context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
|
||||
wrapper.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
|
||||
|
||||
try {
|
||||
Template template = context.getComputeService().templateBuilder().build();
|
||||
context.getComputeService().createNodesInGroup(tag, 1, template);
|
||||
context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
|
||||
context.getComputeService().createNodesInGroup(tag, 1, template);
|
||||
Template template = wrapper.getComputeService().templateBuilder().build();
|
||||
wrapper.getComputeService().createNodesInGroup(tag, 1, template);
|
||||
wrapper.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
|
||||
wrapper.getComputeService().createNodesInGroup(tag, 1, template);
|
||||
} catch (RunNodesException e) {
|
||||
System.err.println(e.getNodeErrors().keySet());
|
||||
Throwables.propagate(e);
|
||||
} finally {
|
||||
context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
|
||||
wrapper.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class AvailabilityZoneAndRegionClientLiveTest extends BaseComputeServiceC
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getAvailabilityZoneAndRegionServices();
|
||||
client = wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getAvailabilityZoneAndRegionServices();
|
||||
}
|
||||
|
||||
public void testDescribeAvailabilityZones() {
|
||||
|
|
|
@ -61,12 +61,12 @@ public class ElasticBlockStoreClientLiveTest extends BaseComputeServiceContextLi
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getElasticBlockStoreServices();
|
||||
client = wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getElasticBlockStoreServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDescribeVolumes() {
|
||||
for (String region : context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) {
|
||||
for (String region : wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) {
|
||||
SortedSet<Volume> allResults = Sets.newTreeSet(client.describeVolumesInRegion(region));
|
||||
assertNotNull(allResults);
|
||||
if (allResults.size() >= 1) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ElasticIPAddressClientLiveTest extends BaseComputeServiceContextLiv
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getElasticIPAddressServices();
|
||||
client = wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getElasticIPAddressServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -49,7 +49,7 @@ public class InstanceClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getInstanceServices();
|
||||
client = wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getInstanceServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -51,7 +51,7 @@ public class KeyPairClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getKeyPairServices();
|
||||
client = wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getKeyPairServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -60,7 +60,7 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getSecurityGroupServices();
|
||||
client = wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getSecurityGroupServices();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -281,6 +281,6 @@ public class SecurityGroupClientLiveTest extends BaseComputeServiceContextLiveTe
|
|||
|
||||
@AfterTest
|
||||
public void shutdown() {
|
||||
context.close();
|
||||
wrapper.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,8 +76,8 @@ public class WindowsClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getWindowsServices();
|
||||
computeService = context.getComputeService();
|
||||
client = wrapper.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getWindowsServices();
|
||||
computeService = wrapper.getComputeService();
|
||||
}
|
||||
|
||||
|
||||
|
@ -141,7 +141,7 @@ public class WindowsClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
node.getCredentials().getPrivateKey());
|
||||
|
||||
// And apply it to the decryption function
|
||||
WindowsLoginCredentialsFromEncryptedData f = context.getUtils().getInjector().getInstance(WindowsLoginCredentialsFromEncryptedData.class);
|
||||
WindowsLoginCredentialsFromEncryptedData f = wrapper.getUtils().getInjector().getInstance(WindowsLoginCredentialsFromEncryptedData.class);
|
||||
LoginCredentials credentials = f.apply(dataAndKey);
|
||||
|
||||
assertEquals(credentials.getUser(), "Administrator");
|
||||
|
|
|
@ -88,7 +88,7 @@ public class ElasticStackClientLiveTest
|
|||
@Override
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
cloudStackContext = context.unwrap();
|
||||
cloudStackContext = wrapper.unwrap();
|
||||
|
||||
client = cloudStackContext.getApi();
|
||||
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime,
|
||||
|
@ -97,7 +97,7 @@ public class ElasticStackClientLiveTest
|
|||
TimeUnit.SECONDS);
|
||||
|
||||
if (Strings.emptyToNull(imageId) == null) {
|
||||
imageId = context.getComputeService().templateBuilder().build().getImage().getId();
|
||||
imageId = wrapper.getComputeService().templateBuilder().build().getImage().getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ public class FilesystemAsyncBlobStoreTest {
|
|||
// no base directory declared in properties
|
||||
try {
|
||||
Properties props = new Properties();
|
||||
context = ContextBuilder.newBuilder(PROVIDER).overrides(props).build();
|
||||
context = ContextBuilder.newBuilder(PROVIDER).overrides(props).build(BlobStoreContext.class);
|
||||
fail("No error if base directory is not specified");
|
||||
} catch (CreationException e) {
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ public class FilesystemAsyncBlobStoreTest {
|
|||
try {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, null);
|
||||
context = ContextBuilder.newBuilder(PROVIDER).overrides(props).build();
|
||||
context = ContextBuilder.newBuilder(PROVIDER).overrides(props).build(BlobStoreContext.class);
|
||||
fail("No error if base directory is null in the option");
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
|
|
|
@ -62,14 +62,14 @@ public class FilesystemContainerIntegrationTestDisabled extends BaseContainerInt
|
|||
|
||||
// NOTE all metadata in jclouds comes out as lowercase, in an effort to normalize the
|
||||
// providers.
|
||||
Blob object = context.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||
Blob object = wrapper.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||
.payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).build();
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
addBlobToContainer(containerName, object);
|
||||
validateContent(containerName, key);
|
||||
|
||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName, maxResults(1));
|
||||
PageSet<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName, maxResults(1));
|
||||
|
||||
BlobMetadata metadata = (BlobMetadata) Iterables.getOnlyElement(container);
|
||||
// transient container should be lenient and not return metadata on undetailed listing.
|
||||
|
|
|
@ -78,7 +78,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
@Override
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
Injector injector = context.utils().injector();
|
||||
Injector injector = wrapper.utils().injector();
|
||||
client = injector.getInstance(NovaClient.class);
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||
|
|
|
@ -18,32 +18,22 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.extensions;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Ingress;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.IpProtocol;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.SimpleServerUsage;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.SimpleTenantUsage;
|
||||
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
|
||||
import org.jclouds.openstack.nova.v1_1.parse.ParseSecurityGroupListTest;
|
||||
import org.jclouds.openstack.nova.v1_1.parse.ParseSecurityGroupTest;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
|
|
|
@ -22,9 +22,7 @@ import static org.testng.Assert.assertNotNull;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.SimpleTenantUsage;
|
||||
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
|
||||
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -123,17 +123,25 @@ public class PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensio
|
|||
CacheLoader.from(Functions.forMap(ImmutableMap.of("expectedzone", extensions, "differentzone",
|
||||
ImmutableSet.<Extension> of()))));
|
||||
|
||||
PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet fn = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {}
|
||||
PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet fn = Guice.createInjector(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@Provides
|
||||
LoadingCache<String, Set<Extension>> getExtensions() { return extensionsForZone;}
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
LoadingCache<String, Set<Extension>> getExtensions() {
|
||||
return extensionsForZone;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("openstack.nova.extensions")
|
||||
Multimap<URI, URI> getAliases() { return aliases;}
|
||||
}).getInstance(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class);
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Named("openstack.nova.extensions")
|
||||
Multimap<URI, URI> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
}).getInstance(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class);
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class BaseNovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
@Override
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
novaContext = context.unwrap();
|
||||
novaContext = wrapper.unwrap();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Set;
|
|||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.json.BaseParserTest;
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.openstack.nova.v1_1.config.NovaParserModule;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.KeyPair;
|
||||
|
@ -41,7 +41,7 @@ import com.google.inject.Injector;
|
|||
* @author Michael Arnold
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseKeyPairListTest")
|
||||
public class ParseKeyPairListTest extends BaseParserTest {
|
||||
public class ParseKeyPairListTest extends BaseItemParserTest<Set<Map<String, KeyPair>>> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
|
|
|
@ -18,11 +18,10 @@
|
|||
*/
|
||||
package org.jclouds.s3.blobstore.internal;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.BlobMap;
|
||||
import org.jclouds.blobstore.BlobRequestSigner;
|
||||
|
@ -45,7 +44,7 @@ import com.google.common.reflect.TypeToken;
|
|||
public class S3BlobStoreContextImpl extends BlobStoreContextImpl implements S3BlobStoreContext {
|
||||
|
||||
@Inject
|
||||
public S3BlobStoreContextImpl(@Provider Closeable wrapped, @Provider TypeToken<? extends Closeable> wrappedType,
|
||||
public S3BlobStoreContextImpl(@Provider Context wrapped, @Provider TypeToken<? extends Context> wrappedType,
|
||||
BlobMap.Factory blobMapFactory, Utils utils, ConsistencyModel consistencyModel,
|
||||
InputStreamMap.Factory inputStreamMapFactory, AsyncBlobStore ablobStore, BlobStore blobStore,
|
||||
BlobRequestSigner blobRequestSigner) {
|
||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.s3.filters;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Iterables.get;
|
||||
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG;
|
||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
|
||||
import static org.jclouds.http.utils.ModifyRequest.parseQueryToMap;
|
||||
|
@ -35,8 +33,8 @@ import java.lang.annotation.Annotation;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -57,6 +55,8 @@ import org.jclouds.http.internal.SignatureWire;
|
|||
import org.jclouds.io.InputSuppliers;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
import org.jclouds.rest.annotations.Credential;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.s3.Bucket;
|
||||
|
||||
|
@ -114,7 +114,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
|||
public RequestAuthorizeSignature(SignatureWire signatureWire, @Named(PROPERTY_AUTH_TAG) String authTag,
|
||||
@Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle,
|
||||
@Named(PROPERTY_S3_SERVICE_PATH) String servicePath, @Named(PROPERTY_HEADER_TAG) String headerTag,
|
||||
@Named(PROPERTY_IDENTITY) String accessKey, @Named(PROPERTY_CREDENTIAL) String secretKey,
|
||||
@Identity String accessKey, @Credential String secretKey,
|
||||
@TimeStamp Provider<String> timeStampProvider, Crypto crypto, HttpUtils utils) {
|
||||
this.isVhostStyle = isVhostStyle;
|
||||
this.servicePath = servicePath;
|
||||
|
|
|
@ -68,7 +68,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
public S3Client getApi() {
|
||||
return context.unwrap(S3ApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
return wrapper.unwrap(S3ApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,7 +71,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
public S3Client getApi() {
|
||||
return (S3Client) context.unwrap(S3ApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
return (S3Client) wrapper.unwrap(S3ApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.jclouds.blobstore.ContainerNotFoundException;
|
|||
import org.jclouds.blobstore.domain.PageSet;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.openstack.swift.domain.AccountMetadata;
|
||||
import org.jclouds.openstack.swift.domain.ContainerMetadata;
|
||||
import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata;
|
||||
|
|
|
@ -56,7 +56,6 @@ import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetada
|
|||
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob;
|
||||
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata;
|
||||
import org.jclouds.openstack.swift.blobstore.strategy.internal.AsyncMultipartUploadStrategy;
|
||||
import org.jclouds.openstack.swift.blobstore.strategy.internal.MultipartUploadStrategy;
|
||||
import org.jclouds.openstack.swift.domain.ContainerMetadata;
|
||||
import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata;
|
||||
import org.jclouds.openstack.swift.domain.ObjectInfo;
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.jclouds.io.PayloadSlicer;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||
import org.jclouds.openstack.swift.SwiftApiMetadata;
|
||||
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
|
||||
import org.jclouds.openstack.swift.blobstore.functions.BlobToObject;
|
||||
import org.jclouds.util.Throwables2;
|
||||
|
@ -91,8 +92,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
|
|||
latch.countDown();
|
||||
return;
|
||||
}
|
||||
final CommonSwiftAsyncClient client = (CommonSwiftAsyncClient) ablobstore.getContext()
|
||||
.getProviderSpecificContext().getAsyncApi();
|
||||
final CommonSwiftAsyncClient client = ablobstore.getContext().unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getAsyncApi();
|
||||
Payload chunkedPart = slicer.slice(payload, offset, size);
|
||||
logger.debug(String.format("async uploading part %s of %s to container %s", part, key, container));
|
||||
final long start = System.currentTimeMillis();
|
||||
|
@ -146,8 +146,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
|
|||
long chunkSize = algorithm.getChunkSize();
|
||||
long remaining = algorithm.getRemaining();
|
||||
if (parts > 0) {
|
||||
CommonSwiftClient client = (CommonSwiftClient) ablobstore
|
||||
.getContext().getProviderSpecificContext().getApi();
|
||||
CommonSwiftClient client = ablobstore.getContext().unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
final Map<Integer, ListenableFuture<String>> futureParts =
|
||||
new ConcurrentHashMap<Integer, ListenableFuture<String>>();
|
||||
final Map<Integer, Exception> errorMap = Maps.newHashMap();
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package org.jclouds.openstack.swift.blobstore.strategy.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.blobstore.KeyNotFoundException;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.options.PutOptions;
|
||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||
|
@ -13,15 +12,12 @@ import org.jclouds.io.Payload;
|
|||
import org.jclouds.io.PayloadSlicer;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||
import org.jclouds.openstack.swift.SwiftClient;
|
||||
import org.jclouds.openstack.swift.SwiftApiMetadata;
|
||||
import org.jclouds.openstack.swift.blobstore.SwiftBlobStore;
|
||||
import org.jclouds.openstack.swift.blobstore.functions.BlobToObject;
|
||||
import org.jclouds.openstack.swift.domain.SwiftObject;
|
||||
import org.jclouds.util.Throwables2;
|
||||
|
||||
import java.util.SortedMap;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
|
||||
public class SequentialMultipartUploadStrategy implements MultipartUploadStrategy {
|
||||
|
@ -52,9 +48,7 @@ public class SequentialMultipartUploadStrategy implements MultipartUploadStrateg
|
|||
int parts = algorithm.getParts();
|
||||
long chunkSize = algorithm.getChunkSize();
|
||||
if (parts > 0) {
|
||||
CommonSwiftClient client = (CommonSwiftClient) ablobstore.getContext()
|
||||
.getProviderSpecificContext().getApi();
|
||||
|
||||
CommonSwiftClient client = ablobstore.getContext().unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
try {
|
||||
int part;
|
||||
while ((part = algorithm.getNextPart()) <= parts) {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class SwiftClientLiveTest extends CommonSwiftClientLiveTest<SwiftClient>
|
|||
|
||||
@Override
|
||||
public SwiftClient getApi() {
|
||||
return context.unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
return wrapper.unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -89,10 +89,10 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
|||
String containerName = getContainerName();
|
||||
|
||||
try {
|
||||
BlobStore blobStore = context.getBlobStore();
|
||||
BlobStore blobStore = wrapper.getBlobStore();
|
||||
blobStore.createContainerInLocation(null, containerName);
|
||||
Blob blob = blobStore.blobBuilder("const.txt")
|
||||
.payload(new File("target/const.txt")).build();
|
||||
.payload(new File("target/const.txt")).contentMD5(oneHundredOneConstitutionsMD5).build();
|
||||
blobStore.putBlob(containerName, blob, PutOptions.Builder.multipart());
|
||||
} finally {
|
||||
returnContainer(containerName);
|
||||
|
|
|
@ -27,12 +27,13 @@ import org.testng.annotations.Test;
|
|||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "live" })
|
||||
@Test(groups = "live", testName = "SwiftContainerLiveTest" )
|
||||
public class SwiftContainerLiveTest extends BaseContainerLiveTest {
|
||||
public SwiftContainerLiveTest() {
|
||||
provider = "swift";
|
||||
}
|
||||
@Test(expectedExceptions=UnsupportedOperationException.class)
|
||||
|
||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||
public void testPublicAccess() throws MalformedURLException, InterruptedException, IOException {
|
||||
super.testPublicAccess();
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import java.util.concurrent.ExecutorService;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.blobstore.TransientAsyncBlobStore;
|
||||
|
|
|
@ -22,7 +22,6 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.get;
|
||||
import static org.jclouds.Constants.PROPERTY_BUILD_VERSION;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
|
||||
|
@ -41,17 +40,18 @@ import org.jclouds.javax.annotation.Nullable;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.ovf.Network;
|
||||
import org.jclouds.predicates.validators.DnsNameValidator;
|
||||
import org.jclouds.rest.annotations.BuildVersion;
|
||||
import org.jclouds.vcloud.TaskStillRunningException;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
|
||||
import org.jclouds.vcloud.domain.GuestCustomizationSection;
|
||||
import org.jclouds.vcloud.domain.NetworkConnection;
|
||||
import org.jclouds.vcloud.domain.NetworkConnectionSection;
|
||||
import org.jclouds.vcloud.domain.NetworkConnectionSection.Builder;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.domain.Vm;
|
||||
import org.jclouds.vcloud.domain.NetworkConnectionSection.Builder;
|
||||
import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
|
||||
import org.jclouds.vcloud.domain.network.NetworkConfig;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
|
@ -79,7 +79,7 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
@Inject
|
||||
protected InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn(VCloudClient client,
|
||||
Predicate<URI> successTester, LoadingCache<URI, VAppTemplate> vAppTemplates,
|
||||
Supplier<NetworkConfig> defaultNetworkConfig, @Named(PROPERTY_BUILD_VERSION) String buildVersion) {
|
||||
Supplier<NetworkConfig> defaultNetworkConfig, @BuildVersion String buildVersion) {
|
||||
this.client = client;
|
||||
this.successTester = successTester;
|
||||
this.vAppTemplates = vAppTemplates;
|
||||
|
|
|
@ -18,17 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.config;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
|
||||
|
@ -58,7 +56,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@org.jclouds.vcloud.endpoints.Org
|
||||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultOrg(DefaultOrgForUser defaultOrgURIForUser,
|
||||
@Named(PROPERTY_IDENTITY) String user) {
|
||||
@Identity String user) {
|
||||
return defaultOrgURIForUser.apply(user);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,17 +27,16 @@ import static com.google.common.collect.Iterables.filter;
|
|||
import static com.google.common.collect.Iterables.getLast;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.util.Maps2.uniqueIndex;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
|
||||
import static org.jclouds.util.Maps2.uniqueIndex;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -56,6 +55,7 @@ import org.jclouds.ovf.Envelope;
|
|||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
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.vcloud.VCloudAsyncClient;
|
||||
|
@ -117,8 +117,8 @@ 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.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
|
@ -390,7 +390,7 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
@Singleton
|
||||
@org.jclouds.vcloud.endpoints.VCloudLogin
|
||||
protected Supplier<URI> provideAuthenticationURI(final VCloudVersionsClient versionService,
|
||||
@Named(PROPERTY_API_VERSION) final String version) {
|
||||
@ApiVersion final String version) {
|
||||
return new Supplier<URI>() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,7 +49,7 @@ public class CatalogClientLiveTest extends BaseVCloudClientLiveTest {
|
|||
public void testFindCatalogIsWriteableIfNotVersion1_5() throws Exception {
|
||||
// when we are in vCloud 1.0.0 public catalogs don't work, so our default
|
||||
// catalog is private
|
||||
if (!context.utils().injector().getInstance(Key.get(String.class, ApiVersion.class)).startsWith("1.5"))
|
||||
if (!wrapper.utils().injector().getInstance(Key.get(String.class, ApiVersion.class)).startsWith("1.5"))
|
||||
assertTrue(getVCloudApi().getCatalogClient().findCatalogInOrgNamed(null, null).isReadOnly());
|
||||
}
|
||||
}
|
|
@ -45,14 +45,14 @@ public abstract class BaseVCloudClientLiveTest extends BaseComputeServiceContext
|
|||
}
|
||||
|
||||
protected VCloudClient getVCloudApi() {
|
||||
return VCloudClient.class.cast(context.unwrap(VCloudApiMetadata.CONTEXT_TOKEN).getApi());
|
||||
return VCloudClient.class.cast(wrapper.unwrap(VCloudApiMetadata.CONTEXT_TOKEN).getApi());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
client = context.getComputeService();
|
||||
client = wrapper.getComputeService();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,11 +20,10 @@ package org.jclouds.blobstore.internal;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.BlobMap;
|
||||
import org.jclouds.blobstore.BlobRequestSigner;
|
||||
|
@ -55,7 +54,7 @@ public class BlobStoreContextImpl extends BaseWrapper implements BlobStoreContex
|
|||
private final BlobRequestSigner blobRequestSigner;
|
||||
|
||||
@Inject
|
||||
public BlobStoreContextImpl(@Provider Closeable wrapped, @Provider TypeToken<? extends Closeable> wrappedType,
|
||||
public BlobStoreContextImpl(@Provider Context wrapped, @Provider TypeToken<? extends Context> wrappedType,
|
||||
BlobMap.Factory blobMapFactory, Utils utils, ConsistencyModel consistencyModel,
|
||||
InputStreamMap.Factory inputStreamMapFactory, AsyncBlobStore ablobStore, BlobStore blobStore,
|
||||
BlobRequestSigner blobRequestSigner) {
|
||||
|
@ -122,26 +121,26 @@ public class BlobStoreContextImpl extends BaseWrapper implements BlobStoreContex
|
|||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <S, A> RestContext<S, A> getProviderSpecificContext() {
|
||||
return (RestContext<S, A>) getWrapped();
|
||||
return (RestContext<S, A>) delegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
Closeables.closeQuietly(getWrapped());
|
||||
Closeables.closeQuietly(delegate());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return getWrapped().hashCode();
|
||||
return delegate().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getWrapped().toString();
|
||||
return delegate().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return getWrapped().equals(obj);
|
||||
return delegate().equals(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class TransientContainerIntegrationTest extends BaseContainerIntegrationT
|
|||
String key = "hello";
|
||||
// NOTE all metadata in jclouds comes out as lowercase, in an effort to normalize the
|
||||
// providers.
|
||||
Blob blob = context.getBlobStore().blobBuilder("hello").userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder("hello").userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||
.payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).build();
|
||||
|
||||
String containerName = getContainerName();
|
||||
|
@ -61,7 +61,7 @@ public class TransientContainerIntegrationTest extends BaseContainerIntegrationT
|
|||
addBlobToContainer(containerName, blob);
|
||||
validateContent(containerName, key);
|
||||
|
||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName, maxResults(1));
|
||||
PageSet<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName, maxResults(1));
|
||||
|
||||
BlobMetadata metadata = (BlobMetadata) getOnlyElement(container);
|
||||
// transient container should be lenient and not return metadata on undetailed listing.
|
||||
|
@ -75,7 +75,7 @@ public class TransientContainerIntegrationTest extends BaseContainerIntegrationT
|
|||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testDuplicateCreateContainer() {
|
||||
BlobStore blobStore = context.getBlobStore();
|
||||
BlobStore blobStore = wrapper.getBlobStore();
|
||||
Location location = null;
|
||||
String container = "container";
|
||||
boolean created;
|
||||
|
|
|
@ -141,15 +141,15 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
@Override
|
||||
public Void call() throws Exception {
|
||||
String name = blobCount.incrementAndGet() + "";
|
||||
Blob blob = context.getBlobStore().blobBuilder(name).payload(testPayload).build();
|
||||
context.getBlobStore().putBlob(container, blob);
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder(name).payload(testPayload).build();
|
||||
wrapper.getBlobStore().putBlob(container, blob);
|
||||
assertConsistencyAwareBlobExists(container, name);
|
||||
blob = context.getBlobStore().getBlob(container, name);
|
||||
blob = wrapper.getBlobStore().getBlob(container, name);
|
||||
|
||||
assert Arrays.equals(CryptoStreams.md5(blob.getPayload()), md5) : String.format(
|
||||
"md5 didn't match on %s/%s", container, name);
|
||||
|
||||
context.getBlobStore().removeBlob(container, name);
|
||||
wrapper.getBlobStore().removeBlob(container, name);
|
||||
assertConsistencyAwareBlobDoesntExist(container, name);
|
||||
return null;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
Map<Integer, Future<?>> responses = Maps.newHashMap();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
responses.put(i, Futures.compose(context.getAsyncBlobStore().getBlob(container, name),
|
||||
responses.put(i, Futures.compose(wrapper.getAsyncBlobStore().getBlob(container, name),
|
||||
new Function<Blob, Void>() {
|
||||
|
||||
@Override
|
||||
|
@ -204,9 +204,9 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
private void uploadConstitution(String container, String name, String contentDisposition) throws IOException {
|
||||
context.getBlobStore().putBlob(
|
||||
wrapper.getBlobStore().putBlob(
|
||||
container,
|
||||
context.getBlobStore().blobBuilder(name).payload(oneHundredOneConstitutions.getInput()).contentType(
|
||||
wrapper.getBlobStore().blobBuilder(name).payload(oneHundredOneConstitutions.getInput()).contentType(
|
||||
"text/plain").contentMD5(oneHundredOneConstitutionsMD5).contentLength(
|
||||
oneHundredOneConstitutionsLength).contentDisposition(contentDisposition).build());
|
||||
}
|
||||
|
@ -224,11 +224,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
addObjectAndValidateContent(container, name);
|
||||
Date after = new Date(System.currentTimeMillis() + 1000);
|
||||
|
||||
context.getBlobStore().getBlob(container, name, ifModifiedSince(before));
|
||||
wrapper.getBlobStore().getBlob(container, name, ifModifiedSince(before));
|
||||
validateContent(container, name);
|
||||
|
||||
try {
|
||||
context.getBlobStore().getBlob(container, name, ifModifiedSince(after));
|
||||
wrapper.getBlobStore().getBlob(container, name, ifModifiedSince(after));
|
||||
validateContent(container, name);
|
||||
} catch (HttpResponseException ex) {
|
||||
assertEquals(ex.getResponse().getStatusCode(), 304);
|
||||
|
@ -250,11 +250,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
addObjectAndValidateContent(container, name);
|
||||
Date after = new Date(System.currentTimeMillis() + 1000);
|
||||
|
||||
context.getBlobStore().getBlob(container, name, ifUnmodifiedSince(after));
|
||||
wrapper.getBlobStore().getBlob(container, name, ifUnmodifiedSince(after));
|
||||
validateContent(container, name);
|
||||
|
||||
try {
|
||||
context.getBlobStore().getBlob(container, name, ifUnmodifiedSince(before));
|
||||
wrapper.getBlobStore().getBlob(container, name, ifUnmodifiedSince(before));
|
||||
validateContent(container, name);
|
||||
} catch (HttpResponseException ex) {
|
||||
assertEquals(ex.getResponse().getStatusCode(), 412);
|
||||
|
@ -273,11 +273,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
String goodETag = addObjectAndValidateContent(container, name);
|
||||
|
||||
context.getBlobStore().getBlob(container, name, ifETagMatches(goodETag));
|
||||
wrapper.getBlobStore().getBlob(container, name, ifETagMatches(goodETag));
|
||||
validateContent(container, name);
|
||||
|
||||
try {
|
||||
context.getBlobStore().getBlob(container, name, ifETagMatches("powerfrisbee"));
|
||||
wrapper.getBlobStore().getBlob(container, name, ifETagMatches("powerfrisbee"));
|
||||
validateContent(container, name);
|
||||
} catch (HttpResponseException ex) {
|
||||
assertEquals(ex.getResponse().getStatusCode(), 412);
|
||||
|
@ -296,11 +296,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
String goodETag = addObjectAndValidateContent(container, name);
|
||||
|
||||
context.getBlobStore().getBlob(container, name, ifETagDoesntMatch("powerfrisbee"));
|
||||
wrapper.getBlobStore().getBlob(container, name, ifETagDoesntMatch("powerfrisbee"));
|
||||
validateContent(container, name);
|
||||
|
||||
try {
|
||||
context.getBlobStore().getBlob(container, name, ifETagDoesntMatch(goodETag));
|
||||
wrapper.getBlobStore().getBlob(container, name, ifETagDoesntMatch(goodETag));
|
||||
} catch (HttpResponseException ex) {
|
||||
assertEquals(ex.getResponse().getStatusCode(), 304);
|
||||
}
|
||||
|
@ -317,11 +317,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String name = "apples";
|
||||
|
||||
addObjectAndValidateContent(container, name);
|
||||
Blob blob1 = context.getBlobStore().getBlob(container, name, range(0, 5));
|
||||
Blob blob1 = wrapper.getBlobStore().getBlob(container, name, range(0, 5));
|
||||
validateMetadata(blob1.getMetadata(), container, name);
|
||||
assertEquals(getContentAsStringOrNullAndClose(blob1), TEST_STRING.substring(0, 6));
|
||||
|
||||
Blob blob2 = context.getBlobStore().getBlob(container, name, range(6, TEST_STRING.length()));
|
||||
Blob blob2 = wrapper.getBlobStore().getBlob(container, name, range(6, TEST_STRING.length()));
|
||||
validateMetadata(blob2.getMetadata(), container, name);
|
||||
assertEquals(getContentAsStringOrNullAndClose(blob2), TEST_STRING.substring(6, TEST_STRING.length()));
|
||||
} finally {
|
||||
|
@ -337,7 +337,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String name = "apples";
|
||||
|
||||
addObjectAndValidateContent(container, name);
|
||||
Blob blob = context.getBlobStore().getBlob(container, name, range(0, 5).range(6, TEST_STRING.length()));
|
||||
Blob blob = wrapper.getBlobStore().getBlob(container, name, range(0, 5).range(6, TEST_STRING.length()));
|
||||
validateMetadata(blob.getMetadata(), container, name);
|
||||
assertEquals(getContentAsStringOrNullAndClose(blob), TEST_STRING);
|
||||
} finally {
|
||||
|
@ -401,7 +401,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String container = getContainerName();
|
||||
String name = "test";
|
||||
try {
|
||||
context.getBlobStore().removeBlob(container, name);
|
||||
wrapper.getBlobStore().removeBlob(container, name);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String container = getContainerName();
|
||||
String name = "test";
|
||||
try {
|
||||
assert !context.getBlobStore().blobExists(container, name);
|
||||
assert !wrapper.getBlobStore().blobExists(container, name);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
}
|
||||
|
@ -429,7 +429,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String container = getContainerName();
|
||||
try {
|
||||
addBlobToContainer(container, name, name, MediaType.TEXT_PLAIN);
|
||||
context.getBlobStore().removeBlob(container, name);
|
||||
wrapper.getBlobStore().removeBlob(container, name);
|
||||
assertContainerEmptyDeleting(container, name);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
|
@ -437,7 +437,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
private void assertContainerEmptyDeleting(String container, String name) {
|
||||
Iterable<? extends StorageMetadata> listing = Iterables.filter(context.getBlobStore().list(container),
|
||||
Iterable<? extends StorageMetadata> listing = Iterables.filter(wrapper.getBlobStore().list(container),
|
||||
new Predicate<StorageMetadata>() {
|
||||
|
||||
@Override
|
||||
|
@ -454,7 +454,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
@Test(groups = { "integration", "live" })
|
||||
public void deleteObjectNoContainer() {
|
||||
try {
|
||||
context.getBlobStore().removeBlob("donb", "test");
|
||||
wrapper.getBlobStore().removeBlob("donb", "test");
|
||||
} catch (HttpResponseException e) {
|
||||
assertEquals(e.getResponse().getStatusCode(), 404);
|
||||
} catch (ContainerNotFoundException e) {
|
||||
|
@ -475,7 +475,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
@Test(groups = { "integration", "live" }, dataProvider = "putTests")
|
||||
public void testPutObject(String name, String type, Object content, Object realObject) throws InterruptedException,
|
||||
IOException {
|
||||
PayloadBlobBuilder blobBuilder = context.getBlobStore().blobBuilder(name).payload(Payloads.newPayload(content))
|
||||
PayloadBlobBuilder blobBuilder = wrapper.getBlobStore().blobBuilder(name).payload(Payloads.newPayload(content))
|
||||
.contentType(type);
|
||||
addContentMetadata(blobBuilder);
|
||||
if (content instanceof InputStream) {
|
||||
|
@ -484,14 +484,14 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
Blob blob = blobBuilder.build();
|
||||
String container = getContainerName();
|
||||
try {
|
||||
assertNotNull(context.getBlobStore().putBlob(container, blob));
|
||||
blob = context.getBlobStore().getBlob(container, blob.getMetadata().getName());
|
||||
assertNotNull(wrapper.getBlobStore().putBlob(container, blob));
|
||||
blob = wrapper.getBlobStore().getBlob(container, blob.getMetadata().getName());
|
||||
validateMetadata(blob.getMetadata(), container, name);
|
||||
checkContentMetadata(blob);
|
||||
|
||||
String returnedString = getContentAsStringOrNullAndClose(blob);
|
||||
assertEquals(returnedString, realObject);
|
||||
PageSet<? extends StorageMetadata> set = context.getBlobStore().list(container);
|
||||
PageSet<? extends StorageMetadata> set = wrapper.getBlobStore().list(container);
|
||||
assert set.size() == 1 : set;
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
|
@ -500,7 +500,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException {
|
||||
PayloadBlobBuilder blobBuilder = context.getBlobStore().blobBuilder("streaming").payload(
|
||||
PayloadBlobBuilder blobBuilder = wrapper.getBlobStore().blobBuilder("streaming").payload(
|
||||
new StreamingPayload(new WriteTo() {
|
||||
@Override
|
||||
public void writeTo(OutputStream outstream) throws IOException {
|
||||
|
@ -514,14 +514,14 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String container = getContainerName();
|
||||
try {
|
||||
|
||||
assertNotNull(context.getBlobStore().putBlob(container, blob));
|
||||
assertNotNull(wrapper.getBlobStore().putBlob(container, blob));
|
||||
|
||||
blob = context.getBlobStore().getBlob(container, blob.getMetadata().getName());
|
||||
blob = wrapper.getBlobStore().getBlob(container, blob.getMetadata().getName());
|
||||
String returnedString = getContentAsStringOrNullAndClose(blob);
|
||||
assertEquals(returnedString, "foo");
|
||||
validateMetadata(blob.getMetadata(), container, blob.getMetadata().getName());
|
||||
checkContentMetadata(blob);
|
||||
PageSet<? extends StorageMetadata> set = context.getBlobStore().list(container);
|
||||
PageSet<? extends StorageMetadata> set = wrapper.getBlobStore().list(container);
|
||||
assert set.size() == 1 : set;
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
|
@ -588,11 +588,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
// NOTE all metadata in jclouds comes out as lowercase, in an effort to
|
||||
// normalize the
|
||||
// providers.
|
||||
Blob blob = context.getBlobStore().blobBuilder(name).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder(name).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||
.payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).calculateMD5().build();
|
||||
String container = getContainerName();
|
||||
try {
|
||||
assertNull(context.getBlobStore().blobMetadata(container, "powderpuff"));
|
||||
assertNull(wrapper.getBlobStore().blobMetadata(container, "powderpuff"));
|
||||
|
||||
addBlobToContainer(container, blob);
|
||||
Blob newObject = validateContent(container, name);
|
||||
|
@ -601,7 +601,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
validateMetadata(metadata);
|
||||
validateMetadata(metadata, container, name);
|
||||
validateMetadata(context.getBlobStore().blobMetadata(container, name));
|
||||
validateMetadata(wrapper.getBlobStore().blobMetadata(container, name));
|
||||
|
||||
// write 2 items with the same name to ensure that provider doesn't
|
||||
// accept dupes
|
||||
|
@ -609,7 +609,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
blob.getMetadata().getUserMetadata().put("Adrian", "powderpuff");
|
||||
|
||||
addBlobToContainer(container, blob);
|
||||
validateMetadata(context.getBlobStore().blobMetadata(container, name));
|
||||
validateMetadata(wrapper.getBlobStore().blobMetadata(container, name));
|
||||
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
|
|
|
@ -51,18 +51,18 @@ public class BaseBlobLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
httpStreamMD5 = checkNotNull(httpStreamMD5 != null ? httpStreamMD5 : sysHttpStreamMD5, "httpStreamMd5");
|
||||
|
||||
HttpResponse response = context.utils().http().invoke(
|
||||
HttpResponse response = wrapper.utils().http().invoke(
|
||||
HttpRequest.builder().method("GET").endpoint(URI.create(httpStreamUrl)).build());
|
||||
long length = response.getPayload().getContentMetadata().getContentLength();
|
||||
|
||||
String name = "hello";
|
||||
byte[] md5 = CryptoStreams.hex(httpStreamMD5);
|
||||
|
||||
Blob blob = context.getBlobStore().blobBuilder(name).payload(response.getPayload()).contentLength(length)
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder(name).payload(response.getPayload()).contentLength(length)
|
||||
.contentMD5(md5).build();
|
||||
String container = getContainerName();
|
||||
try {
|
||||
context.getBlobStore().putBlob(container, blob);
|
||||
wrapper.getBlobStore().putBlob(container, blob);
|
||||
checkMD5(container, name, md5);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
|
@ -70,7 +70,7 @@ public class BaseBlobLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
protected void checkMD5(String container, String name, byte[] md5) {
|
||||
assertEquals(context.getBlobStore().blobMetadata(container, name).getContentMetadata().getContentMD5(), md5);
|
||||
assertEquals(wrapper.getBlobStore().blobMetadata(container, name).getContentMetadata().getContentMD5(), md5);
|
||||
}
|
||||
|
||||
}
|
|
@ -73,7 +73,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
public void testValues() throws IOException, InterruptedException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
BlobMap map = createMap(context, bucketName);
|
||||
BlobMap map = createMap(wrapper, bucketName);
|
||||
|
||||
putFiveStrings(map);
|
||||
putFiveStringsUnderPath(map);
|
||||
|
@ -95,7 +95,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
public void testRemove() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
Map<String, Blob> map = createMap(context, bucketName);
|
||||
Map<String, Blob> map = createMap(wrapper, bucketName);
|
||||
putStringWithMD5(map, "one", "two");
|
||||
assertConsistencyAwareContentEquals(map, "one", "two");
|
||||
// TODO track how often this occurs and potentially update map implementation
|
||||
|
@ -126,7 +126,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
public void testEntrySet() throws IOException, InterruptedException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
final BlobMap map = createMap(context, bucketName);
|
||||
final BlobMap map = createMap(wrapper, bucketName);
|
||||
putFiveStrings(map);
|
||||
assertConsistencyAwareMapSize(map, 5);
|
||||
Set<Entry<String, Blob>> entries = map.entrySet();
|
||||
|
@ -159,9 +159,9 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
public void testContains() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
Map<String, Blob> map = createMap(context, bucketName);
|
||||
Map<String, Blob> map = createMap(wrapper, bucketName);
|
||||
putStringWithMD5(map, "one", "apple");
|
||||
Blob blob = context.getBlobStore().blobBuilder("one").payload("apple").calculateMD5().build();
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder("one").payload("apple").calculateMD5().build();
|
||||
assertConsistencyAwareContainsValue(map, blob);
|
||||
} finally {
|
||||
returnContainer(bucketName);
|
||||
|
@ -185,8 +185,8 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
public void testPut() throws IOException, InterruptedException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
Map<String, Blob> map = createMap(context, bucketName);
|
||||
Blob blob = context.getBlobStore().blobBuilder("one").payload(Strings2.toInputStream("apple")).calculateMD5()
|
||||
Map<String, Blob> map = createMap(wrapper, bucketName);
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder("one").payload(Strings2.toInputStream("apple")).calculateMD5()
|
||||
.build();
|
||||
Blob old = map.put(blob.getMetadata().getName(), blob);
|
||||
getOneReturnsAppleAndOldValueIsNull(map, old);
|
||||
|
@ -203,12 +203,12 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
public void testPutAll() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
Map<String, Blob> map = createMap(context, bucketName);
|
||||
Map<String, Blob> map = createMap(wrapper, bucketName);
|
||||
ImmutableMap.Builder<String, Blob> newMap = ImmutableMap.builder();
|
||||
for (String key : fiveInputs.keySet()) {
|
||||
newMap.put(
|
||||
key,
|
||||
context.getBlobStore().blobBuilder(key).payload(fiveInputs.get(key))
|
||||
wrapper.getBlobStore().blobBuilder(key).payload(fiveInputs.get(key))
|
||||
.contentLength((long) fiveBytes.get(key).length).build());
|
||||
}
|
||||
map.putAll(newMap.build());
|
||||
|
@ -226,7 +226,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
return;
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
BlobMap map = createMap(context, bucketName);
|
||||
BlobMap map = createMap(wrapper, bucketName);
|
||||
Builder<String> keySet = ImmutableSet.builder();
|
||||
for (int i = 0; i < maxResultsForTestListings() + 1; i++) {
|
||||
keySet.add(i + "");
|
||||
|
@ -250,7 +250,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
|
||||
@Override
|
||||
protected void putStringWithMD5(Map<String, Blob> map, String key, String text) throws IOException {
|
||||
map.put(key, context.getBlobStore().blobBuilder(key).payload(text).calculateMD5().build());
|
||||
map.put(key, wrapper.getBlobStore().blobBuilder(key).payload(text).calculateMD5().build());
|
||||
}
|
||||
|
||||
protected void putFiveStrings(BlobMap map) {
|
||||
|
@ -277,7 +277,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
|
||||
@Override
|
||||
protected void addTenObjectsUnderPrefix(String containerName, String prefix) throws InterruptedException {
|
||||
BlobMap blobMap = createMap(context, containerName, inDirectory(prefix));
|
||||
BlobMap blobMap = createMap(wrapper, containerName, inDirectory(prefix));
|
||||
for (int i = 0; i < 10; i++) {
|
||||
blobMap.put(i + "", blobMap.blobBuilder().payload(i + "content").build());
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
|||
|
||||
@Override
|
||||
protected void addTenObjectsUnderRoot(String containerName) throws InterruptedException {
|
||||
BlobMap blobMap = createMap(context, containerName, ListContainerOptions.NONE);
|
||||
BlobMap blobMap = createMap(wrapper, containerName, ListContainerOptions.NONE);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
blobMap.put(i + "", blobMap.blobBuilder().payload(i + "content").build());
|
||||
}
|
||||
|
|
|
@ -41,15 +41,15 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
String name = "hello";
|
||||
String text = "fooooooooooooooooooooooo";
|
||||
|
||||
Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||
String container = getContainerName();
|
||||
try {
|
||||
context.getBlobStore().putBlob(container, blob);
|
||||
wrapper.getBlobStore().putBlob(container, blob);
|
||||
assertConsistencyAwareContainerSize(container, 1);
|
||||
HttpRequest request = context.getSigner().signRemoveBlob(container, name);
|
||||
HttpRequest request = wrapper.getSigner().signRemoveBlob(container, name);
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
context.utils().http().invoke(request);
|
||||
assert !context.getBlobStore().blobExists(container, name);
|
||||
wrapper.utils().http().invoke(request);
|
||||
assert !wrapper.getBlobStore().blobExists(container, name);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
}
|
||||
|
@ -60,14 +60,14 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
String name = "hello";
|
||||
String text = "fooooooooooooooooooooooo";
|
||||
|
||||
Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||
String container = getContainerName();
|
||||
try {
|
||||
context.getBlobStore().putBlob(container, blob);
|
||||
wrapper.getBlobStore().putBlob(container, blob);
|
||||
assertConsistencyAwareContainerSize(container, 1);
|
||||
HttpRequest request = context.getSigner().signGetBlob(container, name);
|
||||
HttpRequest request = wrapper.getSigner().signGetBlob(container, name);
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
assertEquals(Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput()), text);
|
||||
assertEquals(Strings2.toStringAndClose(wrapper.utils().http().invoke(request).getPayload().getInput()), text);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
}
|
||||
|
@ -78,14 +78,14 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
String name = "hello";
|
||||
String text = "fooooooooooooooooooooooo";
|
||||
|
||||
Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||
String container = getContainerName();
|
||||
try {
|
||||
context.getBlobStore().putBlob(container, blob);
|
||||
wrapper.getBlobStore().putBlob(container, blob);
|
||||
assertConsistencyAwareContainerSize(container, 1);
|
||||
HttpRequest request = context.getSigner().signGetBlob(container, name, range(0, 1));
|
||||
HttpRequest request = wrapper.getSigner().signGetBlob(container, name, range(0, 1));
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
assertEquals(Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput()), "fo");
|
||||
assertEquals(Strings2.toStringAndClose(wrapper.utils().http().invoke(request).getPayload().getInput()), "fo");
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
}
|
||||
|
@ -96,12 +96,12 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
String name = "hello";
|
||||
String text = "fooooooooooooooooooooooo";
|
||||
|
||||
Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||
String container = getContainerName();
|
||||
try {
|
||||
HttpRequest request = context.getSigner().signPutBlob(container, blob);
|
||||
HttpRequest request = wrapper.getSigner().signPutBlob(container, blob);
|
||||
assertEquals(request.getFilters().size(), 0);
|
||||
Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput());
|
||||
Strings2.toStringAndClose(wrapper.utils().http().invoke(request).getPayload().getInput());
|
||||
assertConsistencyAwareContainerSize(container, 1);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
|
|
|
@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.apis.BaseContextLiveTest;
|
||||
import org.jclouds.apis.BaseWrapperLiveTest;
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
|
@ -59,7 +59,7 @@ import com.google.common.collect.Sets;
|
|||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Module;
|
||||
|
||||
public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreContext> {
|
||||
public class BaseBlobStoreIntegrationTest extends BaseWrapperLiveTest<BlobStoreContext> {
|
||||
protected static final String LOCAL_ENCODING = System.getProperty("file.encoding");
|
||||
protected static final String XML_STRING_FORMAT = "<apples><apple name=\"%s\"></apple> </apples>";
|
||||
protected static final String TEST_STRING = String.format(XML_STRING_FORMAT, "apple");
|
||||
|
@ -90,9 +90,9 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
@BeforeSuite
|
||||
public void setUpResourcesForAllThreads(ITestContext testContext) throws Exception {
|
||||
setupContext();
|
||||
createContainersSharedByAllThreads(context, testContext);
|
||||
context.close();
|
||||
context = null;
|
||||
createContainersSharedByAllThreads(wrapper, testContext);
|
||||
wrapper.close();
|
||||
wrapper = null;
|
||||
}
|
||||
|
||||
protected Iterable<Module> setupModules() {
|
||||
|
@ -119,7 +119,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
if (exec != null) {
|
||||
exec.shutdownNow();
|
||||
}
|
||||
context.close();
|
||||
wrapper.close();
|
||||
}
|
||||
|
||||
private static volatile boolean initialized = false;
|
||||
|
@ -224,7 +224,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
}
|
||||
|
||||
protected void assertConsistencyAware(Runnable assertion) throws InterruptedException {
|
||||
assertConsistencyAware(context, assertion);
|
||||
assertConsistencyAware(wrapper, assertion);
|
||||
}
|
||||
|
||||
protected static void createContainerAndEnsureEmpty(BlobStoreContext context, final String containerName)
|
||||
|
@ -236,7 +236,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
}
|
||||
|
||||
protected void createContainerAndEnsureEmpty(String containerName) throws InterruptedException {
|
||||
createContainerAndEnsureEmpty(context, containerName);
|
||||
createContainerAndEnsureEmpty(wrapper, containerName);
|
||||
}
|
||||
|
||||
protected String addBlobToContainer(String sourceContainer, String key) {
|
||||
|
@ -244,20 +244,20 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
}
|
||||
|
||||
protected String addBlobToContainer(String sourceContainer, String key, String payload, String contentType) {
|
||||
Blob sourceObject = context.getBlobStore().blobBuilder(key).payload(payload).contentType(contentType).build();
|
||||
Blob sourceObject = wrapper.getBlobStore().blobBuilder(key).payload(payload).contentType(contentType).build();
|
||||
return addBlobToContainer(sourceContainer, sourceObject);
|
||||
}
|
||||
|
||||
protected void add5BlobsUnderPathAnd5UnderRootToContainer(String sourceContainer) {
|
||||
for (Entry<String, String> entry : Iterables.concat(fiveStrings.entrySet(), fiveStringsUnderPath.entrySet())) {
|
||||
Blob sourceObject = context.getBlobStore().blobBuilder(entry.getKey()).payload(entry.getValue())
|
||||
Blob sourceObject = wrapper.getBlobStore().blobBuilder(entry.getKey()).payload(entry.getValue())
|
||||
.contentType("text/xml").build();
|
||||
addBlobToContainer(sourceContainer, sourceObject);
|
||||
}
|
||||
}
|
||||
|
||||
protected String addBlobToContainer(String sourceContainer, Blob object) {
|
||||
return context.getBlobStore().putBlob(sourceContainer, object);
|
||||
return wrapper.getBlobStore().putBlob(sourceContainer, object);
|
||||
}
|
||||
|
||||
protected <T extends BlobMetadata> T validateMetadata(T md, String container, String name) {
|
||||
|
@ -269,7 +269,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
|
||||
protected Blob validateContent(String container, String name) throws InterruptedException {
|
||||
assertConsistencyAwareContainerSize(container, 1);
|
||||
Blob newObject = context.getBlobStore().getBlob(container, name);
|
||||
Blob newObject = wrapper.getBlobStore().getBlob(container, name);
|
||||
assert newObject != null;
|
||||
validateMetadata(newObject.getMetadata(), container, name);
|
||||
try {
|
||||
|
@ -285,9 +285,9 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
assertConsistencyAware(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
assert context.getBlobStore().countBlobs(containerName) == count : String.format(
|
||||
assert wrapper.getBlobStore().countBlobs(containerName) == count : String.format(
|
||||
"expected only %d values in %s: %s", count, containerName, ImmutableSet.copyOf(Iterables
|
||||
.transform(context.getBlobStore().list(containerName),
|
||||
.transform(wrapper.getBlobStore().list(containerName),
|
||||
new Function<StorageMetadata, String>() {
|
||||
|
||||
public String apply(StorageMetadata from) {
|
||||
|
@ -307,9 +307,9 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
assertConsistencyAware(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
assert context.getBlobStore().blobExists(containerName, name) : String.format(
|
||||
assert wrapper.getBlobStore().blobExists(containerName, name) : String.format(
|
||||
"could not find %s in %s: %s", name, containerName, ImmutableSet.copyOf(Iterables.transform(
|
||||
context.getBlobStore().list(containerName), new Function<StorageMetadata, String>() {
|
||||
wrapper.getBlobStore().list(containerName), new Function<StorageMetadata, String>() {
|
||||
|
||||
public String apply(StorageMetadata from) {
|
||||
return from.getName();
|
||||
|
@ -328,7 +328,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
assertConsistencyAware(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
assert !context.getBlobStore().blobExists(containerName, name) : String.format("found %s in %s", name,
|
||||
assert !wrapper.getBlobStore().blobExists(containerName, name) : String.format("found %s in %s", name,
|
||||
containerName);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e);
|
||||
|
@ -367,7 +367,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
* *substantially* slow down tests on a real server over a network.
|
||||
*/
|
||||
if (SANITY_CHECK_RETURNED_BUCKET_NAME) {
|
||||
if (!Iterables.any(context.getBlobStore().list(), new Predicate<StorageMetadata>() {
|
||||
if (!Iterables.any(wrapper.getBlobStore().list(), new Predicate<StorageMetadata>() {
|
||||
public boolean apply(StorageMetadata md) {
|
||||
return containerName.equals(md.getName());
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
assertConsistencyAware(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
assert !context.getBlobStore().containerExists(containerName) : "container " + containerName
|
||||
assert !wrapper.getBlobStore().containerExists(containerName) : "container " + containerName
|
||||
+ " still exists";
|
||||
} catch (Exception e) {
|
||||
propagateIfPossible(e);
|
||||
|
@ -416,7 +416,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
private String allocateNewContainerName(final String container) {
|
||||
exec.submit(new Runnable() {
|
||||
public void run() {
|
||||
deleteContainerOrWarnIfUnable(context, container);
|
||||
deleteContainerOrWarnIfUnable(wrapper, container);
|
||||
}
|
||||
});
|
||||
String newScratchContainer = container + containerIndex.incrementAndGet();
|
||||
|
@ -429,7 +429,7 @@ public class BaseBlobStoreIntegrationTest extends BaseContextLiveTest<BlobStoreC
|
|||
}
|
||||
|
||||
@Override
|
||||
protected TypeToken<BlobStoreContext> contextType() {
|
||||
protected TypeToken<BlobStoreContext> wrapperType() {
|
||||
return TypeToken.of(BlobStoreContext.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,21 +49,21 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void containerDoesntExist() {
|
||||
assert !context.getBlobStore().containerExists("forgetaboutit");
|
||||
assert !context.getBlobStore().containerExists("cloudcachestorefunctionalintegrationtest-first");
|
||||
assert !wrapper.getBlobStore().containerExists("forgetaboutit");
|
||||
assert !wrapper.getBlobStore().containerExists("cloudcachestorefunctionalintegrationtest-first");
|
||||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testPutTwiceIsOkAndDoesntOverwrite() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
context.getBlobStore().createContainerInLocation(null, containerName);
|
||||
wrapper.getBlobStore().createContainerInLocation(null, containerName);
|
||||
|
||||
Blob blob = context.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build();
|
||||
context.getBlobStore().putBlob(containerName, blob);
|
||||
Blob blob = wrapper.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build();
|
||||
wrapper.getBlobStore().putBlob(containerName, blob);
|
||||
|
||||
context.getBlobStore().createContainerInLocation(null, containerName);
|
||||
assertEquals(context.getBlobStore().countBlobs(containerName), 1);
|
||||
wrapper.getBlobStore().createContainerInLocation(null, containerName);
|
||||
assertEquals(wrapper.getBlobStore().countBlobs(containerName), 1);
|
||||
} finally {
|
||||
returnContainer(containerName);
|
||||
}
|
||||
|
@ -77,11 +77,11 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
addBlobToContainer(containerName,
|
||||
// NOTE all metadata in jclouds comes out as lowercase, in an effort to
|
||||
// normalize the providers.
|
||||
context.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||
wrapper.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||
.payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).calculateMD5().build());
|
||||
validateContent(containerName, key);
|
||||
|
||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName,
|
||||
PageSet<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName,
|
||||
maxResults(1).withDetails());
|
||||
|
||||
BlobMetadata metadata = BlobMetadata.class.cast(get(container, 0));
|
||||
|
@ -105,7 +105,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String containerName = getContainerName();
|
||||
try {
|
||||
add5BlobsUnderPathAnd5UnderRootToContainer(containerName);
|
||||
context.getBlobStore().clearContainer(containerName);
|
||||
wrapper.getBlobStore().clearContainer(containerName);
|
||||
assertConsistencyAwareContainerSize(containerName, 0);
|
||||
} finally {
|
||||
returnContainer(containerName);
|
||||
|
@ -118,13 +118,13 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
try {
|
||||
addAlphabetUnderRoot(containerName);
|
||||
|
||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName, maxResults(1));
|
||||
PageSet<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName, maxResults(1));
|
||||
|
||||
assert container.getNextMarker() != null;
|
||||
assertEquals(container.size(), 1);
|
||||
String marker = container.getNextMarker();
|
||||
|
||||
container = context.getBlobStore().list(containerName, afterMarker(marker));
|
||||
container = wrapper.getBlobStore().list(containerName, afterMarker(marker));
|
||||
assertEquals(container.getNextMarker(), null);
|
||||
assert container.size() == 25 : String.format("size should have been 25, but was %d: %s", container.size(),
|
||||
container);
|
||||
|
@ -142,7 +142,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String prefix = "rootdelimeter";
|
||||
addTenObjectsUnderPrefix(containerName, prefix);
|
||||
add15UnderRoot(containerName);
|
||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName);
|
||||
PageSet<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName);
|
||||
assert container.getNextMarker() == null;
|
||||
assertEquals(container.size(), 16);
|
||||
} finally {
|
||||
|
@ -157,17 +157,17 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
try {
|
||||
String directory = "directory";
|
||||
|
||||
assert !context.getBlobStore().directoryExists(containerName, directory);
|
||||
assert !wrapper.getBlobStore().directoryExists(containerName, directory);
|
||||
|
||||
context.getBlobStore().createDirectory(containerName, directory);
|
||||
wrapper.getBlobStore().createDirectory(containerName, directory);
|
||||
|
||||
assert context.getBlobStore().directoryExists(containerName, directory);
|
||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName);
|
||||
assert wrapper.getBlobStore().directoryExists(containerName, directory);
|
||||
PageSet<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName);
|
||||
// we should have only the directory under root
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 1 : container;
|
||||
|
||||
container = context.getBlobStore().list(containerName, inDirectory(directory));
|
||||
container = wrapper.getBlobStore().list(containerName, inDirectory(directory));
|
||||
|
||||
// we should have nothing in the directory
|
||||
assert container.getNextMarker() == null;
|
||||
|
@ -175,50 +175,50 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
addTenObjectsUnderPrefix(containerName, directory);
|
||||
|
||||
container = context.getBlobStore().list(containerName);
|
||||
container = wrapper.getBlobStore().list(containerName);
|
||||
// we should still have only the directory under root
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 1 : container;
|
||||
|
||||
container = context.getBlobStore().list(containerName, inDirectory(directory));
|
||||
container = wrapper.getBlobStore().list(containerName, inDirectory(directory));
|
||||
// we should have only the 10 items under the directory
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 10 : container;
|
||||
|
||||
// try 2 level deep directory
|
||||
assert !context.getBlobStore().directoryExists(containerName, directory + "/" + directory);
|
||||
context.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
||||
assert context.getBlobStore().directoryExists(containerName, directory + "/" + directory);
|
||||
assert !wrapper.getBlobStore().directoryExists(containerName, directory + "/" + directory);
|
||||
wrapper.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
||||
assert wrapper.getBlobStore().directoryExists(containerName, directory + "/" + directory);
|
||||
|
||||
context.getBlobStore().clearContainer(containerName, inDirectory(directory));
|
||||
assert context.getBlobStore().directoryExists(containerName, directory);
|
||||
assert context.getBlobStore().directoryExists(containerName, directory + "/" + directory);
|
||||
wrapper.getBlobStore().clearContainer(containerName, inDirectory(directory));
|
||||
assert wrapper.getBlobStore().directoryExists(containerName, directory);
|
||||
assert wrapper.getBlobStore().directoryExists(containerName, directory + "/" + directory);
|
||||
|
||||
// should have only the 2 level-deep directory above
|
||||
container = context.getBlobStore().list(containerName, inDirectory(directory));
|
||||
container = wrapper.getBlobStore().list(containerName, inDirectory(directory));
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 1 : container;
|
||||
|
||||
context.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
||||
wrapper.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
||||
|
||||
container = context.getBlobStore().list(containerName, inDirectory(directory).recursive());
|
||||
container = wrapper.getBlobStore().list(containerName, inDirectory(directory).recursive());
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 1 : container;
|
||||
|
||||
context.getBlobStore().clearContainer(containerName, inDirectory(directory).recursive());
|
||||
wrapper.getBlobStore().clearContainer(containerName, inDirectory(directory).recursive());
|
||||
|
||||
// should no longer have the 2 level-deep directory above
|
||||
container = context.getBlobStore().list(containerName, inDirectory(directory));
|
||||
container = wrapper.getBlobStore().list(containerName, inDirectory(directory));
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 0 : container;
|
||||
|
||||
container = context.getBlobStore().list(containerName);
|
||||
container = wrapper.getBlobStore().list(containerName);
|
||||
// should only have the directory
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 1 : container;
|
||||
context.getBlobStore().deleteDirectory(containerName, directory);
|
||||
wrapper.getBlobStore().deleteDirectory(containerName, directory);
|
||||
|
||||
container = context.getBlobStore().list(containerName);
|
||||
container = wrapper.getBlobStore().list(containerName);
|
||||
// now should be completely empty
|
||||
assert container.getNextMarker() == null;
|
||||
assert container.size() == 0 : container;
|
||||
|
@ -236,7 +236,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
addTenObjectsUnderPrefix(containerName, prefix);
|
||||
add15UnderRoot(containerName);
|
||||
|
||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName, inDirectory(prefix));
|
||||
PageSet<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName, inDirectory(prefix));
|
||||
assert container.getNextMarker() == null;
|
||||
assertEquals(container.size(), 10);
|
||||
} finally {
|
||||
|
@ -251,7 +251,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
try {
|
||||
addAlphabetUnderRoot(containerName);
|
||||
|
||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName, maxResults(5));
|
||||
PageSet<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName, maxResults(5));
|
||||
assertEquals(container.size(), 5);
|
||||
assert container.getNextMarker() != null;
|
||||
} finally {
|
||||
|
@ -263,7 +263,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
public void containerExists() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
assert context.getBlobStore().containerExists(containerName);
|
||||
assert wrapper.getBlobStore().containerExists(containerName);
|
||||
} finally {
|
||||
returnContainer(containerName);
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String containerName = getContainerName();
|
||||
try {
|
||||
addBlobToContainer(containerName, "test");
|
||||
context.getBlobStore().deleteContainer(containerName);
|
||||
wrapper.getBlobStore().deleteContainer(containerName);
|
||||
assertNotExists(containerName);
|
||||
} finally {
|
||||
recycleContainer(containerName);
|
||||
|
@ -285,7 +285,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
public void deleteContainerIfEmpty() throws InterruptedException {
|
||||
final String containerName = getContainerName();
|
||||
try {
|
||||
context.getBlobStore().deleteContainer(containerName);
|
||||
wrapper.getBlobStore().deleteContainer(containerName);
|
||||
assertNotExists(containerName);
|
||||
} finally {
|
||||
// this container is now deleted, so we can't reuse it directly
|
||||
|
@ -298,7 +298,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
String containerName = getContainerName();
|
||||
try {
|
||||
add15UnderRoot(containerName);
|
||||
Set<? extends StorageMetadata> container = context.getBlobStore().list(containerName);
|
||||
Set<? extends StorageMetadata> container = wrapper.getBlobStore().list(containerName);
|
||||
assertEquals(container.size(), 15);
|
||||
} finally {
|
||||
returnContainer(containerName);
|
||||
|
@ -308,8 +308,8 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
protected void addAlphabetUnderRoot(String containerName) throws InterruptedException {
|
||||
for (char letter = 'a'; letter <= 'z'; letter++) {
|
||||
context.getBlobStore().putBlob(containerName,
|
||||
context.getBlobStore().blobBuilder(letter + "").payload(letter + "content").build());
|
||||
wrapper.getBlobStore().putBlob(containerName,
|
||||
wrapper.getBlobStore().blobBuilder(letter + "").payload(letter + "content").build());
|
||||
}
|
||||
assertContainerSize(containerName, 26);
|
||||
|
||||
|
@ -319,7 +319,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
assertConsistencyAware(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
assertEquals(context.getBlobStore().countBlobs(containerName), size);
|
||||
assertEquals(wrapper.getBlobStore().countBlobs(containerName), size);
|
||||
} catch (Exception e) {
|
||||
propagateIfPossible(e);
|
||||
}
|
||||
|
@ -329,15 +329,15 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
protected void add15UnderRoot(String containerName) throws InterruptedException {
|
||||
for (int i = 0; i < 15; i++) {
|
||||
context.getBlobStore().putBlob(containerName,
|
||||
context.getBlobStore().blobBuilder(i + "").payload(i + "content").build());
|
||||
wrapper.getBlobStore().putBlob(containerName,
|
||||
wrapper.getBlobStore().blobBuilder(i + "").payload(i + "content").build());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addTenObjectsUnderPrefix(String containerName, String prefix) throws InterruptedException {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
context.getBlobStore().putBlob(containerName,
|
||||
context.getBlobStore().blobBuilder(prefix + "/" + i).payload(i + "content").build());
|
||||
wrapper.getBlobStore().putBlob(containerName,
|
||||
wrapper.getBlobStore().blobBuilder(prefix + "/" + i).payload(i + "content").build());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,18 +38,18 @@ public class BaseContainerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
public void testPublicAccess() throws InterruptedException, MalformedURLException, IOException {
|
||||
final String containerName = getScratchContainerName();
|
||||
try {
|
||||
context.getBlobStore().createContainerInLocation(null, containerName, publicRead());
|
||||
wrapper.getBlobStore().createContainerInLocation(null, containerName, publicRead());
|
||||
assertConsistencyAwareContainerSize(containerName, 0);
|
||||
|
||||
context.getBlobStore().putBlob(containerName,
|
||||
context.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build());
|
||||
wrapper.getBlobStore().putBlob(containerName,
|
||||
wrapper.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build());
|
||||
assertConsistencyAwareContainerSize(containerName, 1);
|
||||
|
||||
BlobMetadata metadata = context.getBlobStore().blobMetadata(containerName, "hello");
|
||||
BlobMetadata metadata = wrapper.getBlobStore().blobMetadata(containerName, "hello");
|
||||
|
||||
assert metadata.getPublicUri() != null : metadata;
|
||||
|
||||
assertEquals(Strings2.toStringAndClose(context.utils().http().get(metadata.getPublicUri())), TEST_STRING);
|
||||
assertEquals(Strings2.toStringAndClose(wrapper.utils().http().get(metadata.getPublicUri())), TEST_STRING);
|
||||
|
||||
} finally {
|
||||
// this container is now public, so we can't reuse it directly
|
||||
|
|
|
@ -53,7 +53,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testValues() throws InterruptedException, IOException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
map.putAll(this.fiveInputs);
|
||||
// this will cause us to block until the bucket updates.
|
||||
assertConsistencyAwareMapSize(map, 5);
|
||||
|
@ -74,7 +74,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPutMoreThanSingleListing() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
InputStreamMap map = createMap(context, containerName);
|
||||
InputStreamMap map = createMap(wrapper, containerName);
|
||||
Set<String> keySet = Sets.newLinkedHashSet();
|
||||
for (int i = 0; i < maxResultsForTestListings() + 1; i++) {
|
||||
keySet.add(i + "");
|
||||
|
@ -100,7 +100,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testRemove() throws InterruptedException, IOException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
putStringWithMD5(map, "one", "two");
|
||||
InputStream old = map.remove("one");
|
||||
assertEquals(Strings2.toStringAndClose(old), "two");
|
||||
|
@ -120,7 +120,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testEntrySet() throws InterruptedException, IOException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
((InputStreamMap) map).putAllStrings(this.fiveStrings);
|
||||
// this will cause us to block until the bucket updates.
|
||||
assertConsistencyAwareKeySize(map, 5);
|
||||
|
@ -143,7 +143,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testContainsStringValue() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
((InputStreamMap) map).putString("one", String.format(XML_STRING_FORMAT, "apple"));
|
||||
assertConsistencyAwareContainsValue(map, fiveStrings.get("one"));
|
||||
} finally {
|
||||
|
@ -155,7 +155,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testContainsFileValue() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
((InputStreamMap) map).putString("one", String.format(XML_STRING_FORMAT, "apple"));
|
||||
assertConsistencyAwareContainsValue(map, fiveFiles.get("one"));
|
||||
} finally {
|
||||
|
@ -167,7 +167,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testContainsInputStreamValue() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
((InputStreamMap) map).putString("one", String.format(XML_STRING_FORMAT, "apple"));
|
||||
assertConsistencyAwareContainsValue(map, this.fiveInputs.get("one"));
|
||||
} finally {
|
||||
|
@ -179,7 +179,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testContainsBytesValue() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
((InputStreamMap) map).putString("one", String.format(XML_STRING_FORMAT, "apple"));
|
||||
assertConsistencyAwareContainsValue(map, this.fiveBytes.get("one"));
|
||||
} finally {
|
||||
|
@ -192,7 +192,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPutAll() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
map.putAll(this.fiveInputs);
|
||||
assertConsistencyAwareMapSize(map, 5);
|
||||
assertConsistencyAwareKeySetEquals(map, new TreeSet<String>(fiveInputs.keySet()));
|
||||
|
@ -206,7 +206,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPutAllBytes() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
|
||||
((InputStreamMap) map).putAllBytes(this.fiveBytes);
|
||||
assertConsistencyAwareMapSize(map, 5);
|
||||
|
@ -221,7 +221,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPutAllFiles() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
|
||||
((InputStreamMap) map).putAllFiles(this.fiveFiles);
|
||||
assertConsistencyAwareMapSize(map, 5);
|
||||
|
@ -236,7 +236,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPutAllStrings() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
|
||||
((InputStreamMap) map).putAllStrings(this.fiveStrings);
|
||||
assertConsistencyAwareMapSize(map, 5);
|
||||
|
@ -251,7 +251,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPutString() throws InterruptedException, IOException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
|
||||
InputStream old = ((InputStreamMap) map).putString("one", fiveStrings.get("one"));
|
||||
getOneReturnsAppleAndOldValueIsNull(map, old);
|
||||
|
@ -280,7 +280,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPutFile() throws IOException, InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
|
||||
InputStream old = ((InputStreamMap) map).putFile("one", fiveFiles.get("one"));
|
||||
getOneReturnsAppleAndOldValueIsNull(map, old);
|
||||
|
@ -295,7 +295,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPutBytes() throws InterruptedException, IOException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
|
||||
InputStream old = ((InputStreamMap) map).putBytes("one", fiveBytes.get("one"));
|
||||
getOneReturnsAppleAndOldValueIsNull(map, old);
|
||||
|
@ -310,7 +310,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
|||
public void testPut() throws InterruptedException, IOException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
Map<String, InputStream> map = createMap(context, containerName);
|
||||
Map<String, InputStream> map = createMap(wrapper, containerName);
|
||||
|
||||
InputStream old = map.put("one", fiveInputs.get("one"));
|
||||
getOneReturnsAppleAndOldValueIsNull(map, old);
|
||||
|
|
|
@ -106,7 +106,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
public void testClear() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
String containerNameName = getContainerName();
|
||||
try {
|
||||
Map<String, V> map = createMap(context, containerNameName);
|
||||
Map<String, V> map = createMap(wrapper, containerNameName);
|
||||
assertConsistencyAwareMapSize(map, 0);
|
||||
putStringWithMD5(map, "one", "apple");
|
||||
assertConsistencyAwareMapSize(map, 1);
|
||||
|
@ -124,7 +124,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
public void testKeySet() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
String containerNameName = getContainerName();
|
||||
try {
|
||||
Map<String, V> map = createMap(context, containerNameName);
|
||||
Map<String, V> map = createMap(wrapper, containerNameName);
|
||||
assertConsistencyAwareKeySize(map, 0);
|
||||
putStringWithMD5(map, "one", "two");
|
||||
assertConsistencyAwareKeySize(map, 1);
|
||||
|
@ -136,15 +136,15 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
|
||||
protected void addTenObjectsUnderPrefix(String containerName, String prefix) throws InterruptedException {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
context.getBlobStore().putBlob(containerName,
|
||||
context.getBlobStore().blobBuilder(prefix + "/" + i).payload(i + "content").build());
|
||||
wrapper.getBlobStore().putBlob(containerName,
|
||||
wrapper.getBlobStore().blobBuilder(prefix + "/" + i).payload(i + "content").build());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addTenObjectsUnderRoot(String containerName) throws InterruptedException {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
context.getBlobStore().putBlob(containerName,
|
||||
context.getBlobStore().blobBuilder(i + "").payload(i + "content").build());
|
||||
wrapper.getBlobStore().putBlob(containerName,
|
||||
wrapper.getBlobStore().blobBuilder(i + "").payload(i + "content").build());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,13 +152,13 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
public void testDirectory() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
String directory = "apps";
|
||||
Map<String, V> rootMap = createMap(context, containerName);
|
||||
Map<String, V> rootRecursiveMap = createMap(context, containerName, recursive());
|
||||
Map<String, V> inDirectoryMap = createMap(context, containerName, inDirectory(directory));
|
||||
Map<String, V> inDirectoryRecursiveMap = createMap(context, containerName, inDirectory(directory).recursive());
|
||||
Map<String, V> rootMap = createMap(wrapper, containerName);
|
||||
Map<String, V> rootRecursiveMap = createMap(wrapper, containerName, recursive());
|
||||
Map<String, V> inDirectoryMap = createMap(wrapper, containerName, inDirectory(directory));
|
||||
Map<String, V> inDirectoryRecursiveMap = createMap(wrapper, containerName, inDirectory(directory).recursive());
|
||||
try {
|
||||
|
||||
context.getBlobStore().createDirectory(containerName, directory);
|
||||
wrapper.getBlobStore().createDirectory(containerName, directory);
|
||||
addTenObjectsUnderRoot(containerName);
|
||||
assertEquals(rootMap.size(), 10);
|
||||
assertEquals(ImmutableSortedSet.copyOf(rootMap.keySet()),
|
||||
|
@ -184,7 +184,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
assertEquals(ImmutableSortedSet.copyOf(inDirectoryRecursiveMap.keySet()),
|
||||
ImmutableSortedSet.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
|
||||
|
||||
context.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
||||
wrapper.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
||||
assertEquals(rootMap.size(), 10);
|
||||
assertEquals(rootRecursiveMap.size(), 20);
|
||||
assertEquals(inDirectoryMap.size(), 10);
|
||||
|
@ -252,7 +252,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
public void testContainsKey() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
String containerNameName = getContainerName();
|
||||
try {
|
||||
Map<String, V> map = createMap(context, containerNameName);
|
||||
Map<String, V> map = createMap(wrapper, containerNameName);
|
||||
assertConsistencyAwareDoesntContainKey(map);
|
||||
putStringWithMD5(map, "one", "apple");
|
||||
assertConsistencyAwareContainsKey(map);
|
||||
|
@ -294,7 +294,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
public void testIsEmpty() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
String containerNameName = getContainerName();
|
||||
try {
|
||||
Map<String, V> map = createMap(context, containerNameName);
|
||||
Map<String, V> map = createMap(wrapper, containerNameName);
|
||||
assertConsistencyAwareEmpty(map);
|
||||
putStringWithMD5(map, "one", "apple");
|
||||
assertConsistencyAwareNotEmpty(map);
|
||||
|
@ -343,7 +343,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String containerNameName = getContainerName();
|
||||
try {
|
||||
ListableMap<?, ?> map = (ListableMap<?, ?>) createMap(context, containerNameName);
|
||||
ListableMap<?, ?> map = (ListableMap<?, ?>) createMap(wrapper, containerNameName);
|
||||
assertConsistencyAwareListContainer(map, containerNameName);
|
||||
} finally {
|
||||
returnContainer(containerNameName);
|
||||
|
|
|
@ -41,24 +41,24 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
@Test(groups = { "integration", "live" })
|
||||
void containerDoesntExist() {
|
||||
Set<? extends StorageMetadata> list = context.getBlobStore().list();
|
||||
Set<? extends StorageMetadata> list = wrapper.getBlobStore().list();
|
||||
assert !list.contains(new MutableStorageMetadataImpl());
|
||||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testAllLocations() throws InterruptedException {
|
||||
for (final Location location : context.getBlobStore().listAssignableLocations()) {
|
||||
for (final Location location : wrapper.getBlobStore().listAssignableLocations()) {
|
||||
final String containerName = getScratchContainerName();
|
||||
try {
|
||||
System.err.printf(" >> creating container in location %s%n", location);
|
||||
context.getBlobStore().createContainerInLocation(location, containerName);
|
||||
wrapper.getBlobStore().createContainerInLocation(location, containerName);
|
||||
System.err.printf(" << call complete.. checking%n");
|
||||
|
||||
assertConsistencyAware(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PageSet<? extends StorageMetadata> list = context.getBlobStore().list();
|
||||
PageSet<? extends StorageMetadata> list = wrapper.getBlobStore().list();
|
||||
assert Iterables.any(list, new Predicate<StorageMetadata>() {
|
||||
public boolean apply(StorageMetadata md) {
|
||||
return containerName.equals(md.getName()) && location.equals(md.getLocation());
|
||||
|
@ -79,9 +79,9 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testGetAssignableLocations() throws Exception {
|
||||
if (context.unwrap() instanceof Location)
|
||||
assertProvider(Location.class.cast(context.unwrap()));
|
||||
for (Location location : context.getBlobStore().listAssignableLocations()) {
|
||||
if (wrapper.unwrap() instanceof Location)
|
||||
assertProvider(Location.class.cast(wrapper.unwrap()));
|
||||
for (Location location : wrapper.getBlobStore().listAssignableLocations()) {
|
||||
System.err.printf("location %s%n", location);
|
||||
assert location.getId() != null : location;
|
||||
assert location != location.getParent() : location;
|
||||
|
|
|
@ -53,8 +53,7 @@ public class BaseBlobMapTest {
|
|||
public void testTypes() {
|
||||
TypeLiteral<Map<String, Map<String, Blob>>> type0 = new TypeLiteral<Map<String, Map<String, Blob>>>() {
|
||||
};
|
||||
@SuppressWarnings("rawtypes")
|
||||
TypeLiteral type1 = TypeLiteral.get(Types.newParameterizedType(Map.class, String.class,
|
||||
TypeLiteral<?> type1 = TypeLiteral.get(Types.newParameterizedType(Map.class, String.class,
|
||||
Types.newParameterizedType(Map.class, String.class, Blob.class)));
|
||||
assertEquals(type0, type1);
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ import org.jclouds.http.internal.SignatureWire;
|
|||
import org.jclouds.http.utils.ModifyRequest;
|
||||
import org.jclouds.io.InputSuppliers;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.annotations.Credential;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -75,8 +77,8 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
|||
Logger signatureLog = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public SharedKeyLiteAuthentication(SignatureWire signatureWire, @Named(Constants.PROPERTY_IDENTITY) String identity,
|
||||
@Named(Constants.PROPERTY_CREDENTIAL) String encodedKey, @TimeStamp Provider<String> timeStampProvider,
|
||||
public SharedKeyLiteAuthentication(SignatureWire signatureWire, @Identity String identity,
|
||||
@Credential String encodedKey, @TimeStamp Provider<String> timeStampProvider,
|
||||
Crypto crypto, HttpUtils utils) {
|
||||
this.crypto = crypto;
|
||||
this.utils = utils;
|
||||
|
|
|
@ -18,14 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.trmk.vcloud_0_8.config;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
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;
|
||||
|
||||
|
@ -55,7 +53,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
|
|||
@org.jclouds.trmk.vcloud_0_8.endpoints.Org
|
||||
@Singleton
|
||||
protected Supplier<ReferenceType> provideDefaultOrg(DefaultOrgForUser defaultOrgURIForUser,
|
||||
@Named(PROPERTY_IDENTITY) String user) {
|
||||
@Identity String user) {
|
||||
return defaultOrgURIForUser.apply(user);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import static com.google.common.collect.Iterables.getLast;
|
|||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static com.google.common.collect.Maps.uniqueIndex;
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
|
||||
|
@ -50,6 +49,7 @@ import org.jclouds.location.suppliers.ImplicitLocationSupplier;
|
|||
import org.jclouds.location.suppliers.LocationsSupplier;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
|
||||
|
@ -311,7 +311,7 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
@Singleton
|
||||
@VCloudLogin
|
||||
protected Supplier<URI> provideAuthenticationURI(final TerremarkVCloudVersionsClient versionService,
|
||||
@Named(PROPERTY_API_VERSION) final String version) {
|
||||
@ApiVersion final String version) {
|
||||
return new Supplier<URI>() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -482,7 +482,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
injector = context.utils().injector();
|
||||
injector = wrapper.utils().injector();
|
||||
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
socketTester = new RetryablePredicate<IPSocket>(injector.getInstance(SocketOpen.class), 300, 10, TimeUnit.SECONDS);// make
|
||||
|
@ -492,7 +492,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
|||
// default internet
|
||||
// service timeout
|
||||
successTester = new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), 650, 10, TimeUnit.SECONDS);
|
||||
connection = (S) RestContext.class.cast(context.unwrap()).getApi();
|
||||
connection = (S) RestContext.class.cast(wrapper.unwrap()).getApi();
|
||||
orgs = listOrgs();
|
||||
}
|
||||
|
||||
|
@ -514,7 +514,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
|||
for (Org org : orgs) {
|
||||
RestContext<S, A> newContext = null;
|
||||
try {
|
||||
newContext = createContext(
|
||||
newContext = createWrapper(
|
||||
overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName())),
|
||||
setupModules()).unwrap();
|
||||
assertEquals(newContext.getApi().findOrgNamed(null), org);
|
||||
|
@ -549,7 +549,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
|||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
RestContext<S, A> newContext = null;
|
||||
try {
|
||||
newContext = createContext(
|
||||
newContext = createWrapper(
|
||||
overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(),
|
||||
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG, cat.getName())), setupModules())
|
||||
.unwrap();
|
||||
|
@ -592,7 +592,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
|||
for (ReferenceType net : response.getAvailableNetworks().values()) {
|
||||
RestContext<S, A> newContext = null;
|
||||
try {
|
||||
newContext = createContext(
|
||||
newContext = createWrapper(
|
||||
overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(),
|
||||
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName(),
|
||||
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK, net.getName())), setupModules())
|
||||
|
@ -671,7 +671,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
|||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
RestContext<S, A> newContext = null;
|
||||
try {
|
||||
newContext = createContext(
|
||||
newContext = createWrapper(
|
||||
overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(),
|
||||
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName())), setupModules())
|
||||
.unwrap();
|
||||
|
@ -703,7 +703,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
|||
for (ReferenceType tasksList : org.getTasksLists().values()) {
|
||||
RestContext<S, A> newContext = null;
|
||||
try {
|
||||
newContext = createContext(
|
||||
newContext = createWrapper(
|
||||
overrideDefaults(ImmutableMap.of(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(),
|
||||
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_TASKSLIST, tasksList.getName())), setupModules())
|
||||
.unwrap();
|
||||
|
@ -737,7 +737,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
|
|||
|
||||
@AfterGroups(groups = { "live" })
|
||||
public void teardownClient() {
|
||||
context.close();
|
||||
wrapper.close();
|
||||
}
|
||||
|
||||
protected Iterable<Org> listOrgs() {
|
||||
|
|
|
@ -54,7 +54,7 @@ extends BaseComputeServiceContextLiveTest {
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
Injector injector = context.utils().injector();
|
||||
Injector injector = wrapper.utils().injector();
|
||||
|
||||
tmClient = injector.getInstance(TerremarkVCloudClient.class);
|
||||
allCatalogItemsInOrg = injector.getInstance(AllCatalogItemsInOrg.class);
|
||||
|
|
|
@ -60,10 +60,10 @@ public abstract class BaseTerremarkClientLiveTest<S extends TerremarkVCloudClien
|
|||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
Injector injector = context.utils().injector();
|
||||
Injector injector = wrapper.utils().injector();
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS);
|
||||
sshFactory = injector.getInstance(Factory.class);
|
||||
connection = (S) RestContext.class.cast(context.unwrap()).getApi();
|
||||
connection = (S) RestContext.class.cast(wrapper.unwrap()).getApi();
|
||||
}
|
||||
|
||||
protected Module getSshModule() {
|
||||
|
|
|
@ -42,27 +42,20 @@ public interface ComputeServiceContext extends Closeable, Wrapper {
|
|||
ComputeService getComputeService();
|
||||
|
||||
/**
|
||||
* retrieves a list of credentials for resources created within this context, keyed on {@code id}
|
||||
* of the resource with a namespace prefix (ex. {@code node#}. We are testing this approach for
|
||||
* resources such as compute nodes, where you could access this externally.
|
||||
* <p/>
|
||||
* <h4>accessing credentials for a node</h4>
|
||||
* <p/>
|
||||
* the key is in the form {@code node#id}.
|
||||
* <ul>
|
||||
* <li>if the node id is {@code 8}, then the key will be {@code node#8}</li>
|
||||
* <li>if the node id is {@code us-east-1/i-asdfdas}, then the key will be {@code
|
||||
* node#us-east-1/i-asdfdas}</li>
|
||||
* <li>if the node id is {@code http://cloud/instances/1}, then the key will be {@code
|
||||
* node#http://cloud/instances/1}</li>
|
||||
* </ul>
|
||||
* will be removed in jclouds 1.6
|
||||
*
|
||||
* @see Utils#getCredentialStore()
|
||||
*/
|
||||
@Deprecated
|
||||
@Beta
|
||||
Map<String, Credentials> getCredentialStore();
|
||||
|
||||
/**
|
||||
* @see ComputeServiceContext#getCredentialStore
|
||||
* will be removed in jclouds 1.6
|
||||
*
|
||||
* @see Utils#credentialStore()
|
||||
*/
|
||||
@Deprecated
|
||||
@Beta
|
||||
Map<String, Credentials> credentialStore();
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@ package org.jclouds.compute.internal;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.Utils;
|
||||
|
@ -34,7 +34,6 @@ import org.jclouds.internal.BaseWrapper;
|
|||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
|
@ -44,21 +43,31 @@ import com.google.common.reflect.TypeToken;
|
|||
public class ComputeServiceContextImpl extends BaseWrapper implements ComputeServiceContext {
|
||||
private final ComputeService computeService;
|
||||
private final Utils utils;
|
||||
private final Map<String, Credentials> credentialStore;
|
||||
|
||||
@Inject
|
||||
public ComputeServiceContextImpl(@Provider Closeable wrapped, @Provider TypeToken<? extends Closeable> wrappedType,
|
||||
ComputeService computeService, Map<String, Credentials> credentialStore, Utils utils) {
|
||||
public ComputeServiceContextImpl(@Provider Context wrapped, @Provider TypeToken<? extends Context> wrappedType,
|
||||
ComputeService computeService, Utils utils) {
|
||||
super(wrapped, wrappedType);
|
||||
this.credentialStore = credentialStore;
|
||||
this.utils = utils;
|
||||
this.computeService = checkNotNull(computeService, "computeService");
|
||||
this.utils = checkNotNull(utils, "utils");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeService getComputeService() {
|
||||
return computeService;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <S, A> RestContext<S, A> getProviderSpecificContext() {
|
||||
return (RestContext<S, A>) delegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
delegate().close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Utils getUtils() {
|
||||
return utils();
|
||||
|
@ -69,39 +78,14 @@ public class ComputeServiceContextImpl extends BaseWrapper implements ComputeSer
|
|||
return utils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Credentials> getCredentialStore() {
|
||||
return credentialStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Credentials> credentialStore() {
|
||||
return credentialStore;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <S, A> RestContext<S, A> getProviderSpecificContext() {
|
||||
return (RestContext<S, A>) getWrapped();
|
||||
return utils().credentialStore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
Closeables.closeQuietly(getWrapped());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return getWrapped().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getWrapped().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return getWrapped().equals(obj);
|
||||
public Map<String, Credentials> getCredentialStore() {
|
||||
return utils().credentialStore();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.compute.internal;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -28,6 +29,7 @@ import org.jclouds.compute.Utils;
|
|||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.rest.HttpAsyncClient;
|
||||
|
@ -53,11 +55,12 @@ public class UtilsImpl extends org.jclouds.rest.internal.UtilsImpl implements Ut
|
|||
|
||||
@Inject
|
||||
UtilsImpl(Injector injector, Json json, XMLParser xml, HttpClient simpleClient, HttpAsyncClient simpleAsyncClient,
|
||||
Crypto encryption, DateService date, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads,
|
||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioThreads, EventBus eventBus,
|
||||
LoggerFactory loggerFactory, Function<NodeMetadata, SshClient> sshForNode) {
|
||||
Crypto encryption, DateService date, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads,
|
||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioThreads, EventBus eventBus,
|
||||
Map<String, Credentials> credentialStore, LoggerFactory loggerFactory,
|
||||
Function<NodeMetadata, SshClient> sshForNode) {
|
||||
super(injector, json, xml, simpleClient, simpleAsyncClient, encryption, date, userThreads, ioThreads, eventBus,
|
||||
loggerFactory);
|
||||
credentialStore, loggerFactory);
|
||||
this.sshForNode = sshForNode;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,70 +18,18 @@
|
|||
*/
|
||||
package org.jclouds.compute.internal;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.jclouds.apis.BaseContextLiveTest;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.domain.LoginCredentials.Builder;
|
||||
import org.jclouds.io.CopyInputStreamInputSupplierMap;
|
||||
import org.jclouds.rest.config.CredentialStoreModule;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.InputSupplier;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.util.Modules;
|
||||
|
||||
/**
|
||||
* @author Jason King, Adrian Cole
|
||||
*/
|
||||
public abstract class BaseComputeServiceContextLiveTest extends BaseContextLiveTest<ComputeServiceContext> {
|
||||
|
||||
protected String imageId;
|
||||
protected String loginUser;
|
||||
protected String authenticateSudo;
|
||||
protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build();
|
||||
|
||||
// isolate tests from eachother, as default credentialStore is static
|
||||
protected Module credentialStoreModule = new CredentialStoreModule(new CopyInputStreamInputSupplierMap(
|
||||
new ConcurrentHashMap<String, InputSupplier<InputStream>>()));
|
||||
public abstract class BaseComputeServiceContextLiveTest extends BaseGenericComputeServiceContextLiveTest<ComputeServiceContext> {
|
||||
|
||||
@Override
|
||||
protected TypeToken<ComputeServiceContext> contextType() {
|
||||
protected TypeToken<ComputeServiceContext> wrapperType() {
|
||||
return TypeToken.of(ComputeServiceContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = super.setupProperties();
|
||||
imageId = setIfTestSystemPropertyPresent(overrides, provider + ".image-id");
|
||||
loginUser = setIfTestSystemPropertyPresent(overrides, provider + ".image.login-user");
|
||||
authenticateSudo = setIfTestSystemPropertyPresent(overrides, provider + ".image.authenticate-sudo");
|
||||
|
||||
if (loginUser != null) {
|
||||
Iterable<String> userPass = Splitter.on(':').split(loginUser);
|
||||
Builder loginCredentialsBuilder = LoginCredentials.builder();
|
||||
loginCredentialsBuilder.user(Iterables.get(userPass, 0));
|
||||
if (Iterables.size(userPass) == 2)
|
||||
loginCredentialsBuilder.password(Iterables.get(userPass, 1));
|
||||
if (authenticateSudo != null)
|
||||
loginCredentialsBuilder.authenticateSudo(Boolean.valueOf(authenticateSudo));
|
||||
loginCredentials = loginCredentialsBuilder.build();
|
||||
}
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<Module> setupModules() {
|
||||
return ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule, getSshModule());
|
||||
}
|
||||
|
||||
protected Module getSshModule() {
|
||||
return Modules.EMPTY_MODULE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
|
||||
|
||||
protected void buildSocketTester() {
|
||||
SocketOpen socketOpen = context.utils().injector().getInstance(SocketOpen.class);
|
||||
SocketOpen socketOpen = wrapper.utils().injector().getInstance(SocketOpen.class);
|
||||
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS);
|
||||
// wait a maximum of 60 seconds for port 8080 to open.
|
||||
long maxWait = TimeUnit.SECONDS.toMillis(60);
|
||||
|
@ -168,7 +168,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
@Override
|
||||
protected void initializeContext() {
|
||||
super.initializeContext();
|
||||
client = context.getComputeService();
|
||||
client = wrapper.getComputeService();
|
||||
}
|
||||
|
||||
// wait up to 5 seconds for an auth exception
|
||||
|
@ -326,7 +326,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
}
|
||||
|
||||
protected void checkHttpGet(NodeMetadata node) {
|
||||
ComputeTestUtils.checkHttpGet(context.utils().http(), node, 8080);
|
||||
ComputeTestUtils.checkHttpGet(wrapper.utils().http(), node, 8080);
|
||||
}
|
||||
|
||||
@Test(enabled = true, dependsOnMethods = "testCompareSizes")
|
||||
|
@ -422,7 +422,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
public void testCredentialsCache() throws Exception {
|
||||
initializeContext();
|
||||
for (NodeMetadata node : nodes)
|
||||
assert (context.getCredentialStore().get("node#" + node.getId()) != null) : "credentials for " + node.getId();
|
||||
assert (wrapper.utils().credentialStore().get("node#" + node.getId()) != null) : "credentials for " + node.getId();
|
||||
}
|
||||
|
||||
protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String group, OperatingSystem os,
|
||||
|
@ -437,7 +437,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
assertNotNull(node.getGroup());
|
||||
assertEquals(node.getGroup(), group);
|
||||
assertEquals(node.getState(), NodeState.RUNNING);
|
||||
Credentials fromStore = context.getCredentialStore().get("node#" + node.getId());
|
||||
Credentials fromStore = wrapper.utils().credentialStore().get("node#" + node.getId());
|
||||
assertEquals(fromStore, node.getCredentials());
|
||||
assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node;
|
||||
assertNotNull(node.getCredentials());
|
||||
|
@ -554,7 +554,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
assertEquals(toDestroy, destroyed.size());
|
||||
for (NodeMetadata node : filter(client.listNodesDetailsMatching(all()), inGroup(group))) {
|
||||
assert node.getState() == NodeState.TERMINATED : node;
|
||||
assert context.getCredentialStore().get("node#" + node.getId()) == null : "credential should have been null for "
|
||||
assert wrapper.utils().credentialStore().get("node#" + node.getId()) == null : "credential should have been null for "
|
||||
+ "node#" + node.getId();
|
||||
}
|
||||
}
|
||||
|
@ -697,7 +697,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
getLocationForIp(nodeIp)));
|
||||
}
|
||||
|
||||
trackAvailabilityOfProcessOnNode(context.utils().userExecutor().submit(new Callable<ExecResponse>() {
|
||||
trackAvailabilityOfProcessOnNode(wrapper.utils().userExecutor().submit(new Callable<ExecResponse>() {
|
||||
@Override
|
||||
public ExecResponse call() {
|
||||
return client.runScriptOnNode(nodeId, startJBoss(configuration), runAsRoot(false).blockOnComplete(false)
|
||||
|
@ -713,7 +713,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
|
||||
client.runScriptOnNode(nodeId, "/tmp/init-jboss stop", runAsRoot(false).wrapInInitScript(false));
|
||||
|
||||
trackAvailabilityOfProcessOnNode(context.utils().userExecutor().submit(new Callable<ExecResponse>() {
|
||||
trackAvailabilityOfProcessOnNode(wrapper.utils().userExecutor().submit(new Callable<ExecResponse>() {
|
||||
|
||||
@Override
|
||||
public ExecResponse call() {
|
||||
|
@ -734,10 +734,10 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
}
|
||||
|
||||
protected String getLocationForIp(String ip) throws IOException {
|
||||
InputStream json = context.utils().http().get(URI.create("http://freegeoip.appspot.com/" + ip));
|
||||
InputStream json = wrapper.utils().http().get(URI.create("http://freegeoip.appspot.com/" + ip));
|
||||
String text = null;
|
||||
if (json != null && (text = Strings2.toStringAndClose(json)).indexOf("}") != -1) {
|
||||
return context.utils().json().fromJson(text, FreeGeoIPLocation.class).toString();
|
||||
return wrapper.utils().json().fromJson(text, FreeGeoIPLocation.class).toString();
|
||||
} else {
|
||||
getAnonymousLogger().warning("could not get info on ip " + ip + "; check freegeoip");
|
||||
}
|
||||
|
@ -872,7 +872,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
}
|
||||
|
||||
protected void doCheckJavaIsInstalledViaSsh(NodeMetadata node, String taskName) throws IOException {
|
||||
SshClient ssh = context.utils().sshForNode().apply(node);
|
||||
SshClient ssh = wrapper.utils().sshForNode().apply(node);
|
||||
try {
|
||||
ssh.connect();
|
||||
ExecResponse hello = ssh.exec("echo hello");
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* 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.compute.internal;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.jclouds.apis.BaseWrapperLiveTest;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.domain.LoginCredentials.Builder;
|
||||
import org.jclouds.io.CopyInputStreamInputSupplierMap;
|
||||
import org.jclouds.rest.config.CredentialStoreModule;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.InputSupplier;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.util.Modules;
|
||||
|
||||
/**
|
||||
* @author Jason King, Adrian Cole
|
||||
*/
|
||||
public abstract class BaseGenericComputeServiceContextLiveTest<W extends ComputeServiceContext> extends BaseWrapperLiveTest<W> {
|
||||
|
||||
protected String imageId;
|
||||
protected String loginUser;
|
||||
protected String authenticateSudo;
|
||||
protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build();
|
||||
|
||||
// isolate tests from eachother, as default credentialStore is static
|
||||
protected Module credentialStoreModule = new CredentialStoreModule(new CopyInputStreamInputSupplierMap(
|
||||
new ConcurrentHashMap<String, InputSupplier<InputStream>>()));
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = super.setupProperties();
|
||||
imageId = setIfTestSystemPropertyPresent(overrides, provider + ".image-id");
|
||||
loginUser = setIfTestSystemPropertyPresent(overrides, provider + ".image.login-user");
|
||||
authenticateSudo = setIfTestSystemPropertyPresent(overrides, provider + ".image.authenticate-sudo");
|
||||
|
||||
if (loginUser != null) {
|
||||
Iterable<String> userPass = Splitter.on(':').split(loginUser);
|
||||
Builder loginCredentialsBuilder = LoginCredentials.builder();
|
||||
loginCredentialsBuilder.user(Iterables.get(userPass, 0));
|
||||
if (Iterables.size(userPass) == 2)
|
||||
loginCredentialsBuilder.password(Iterables.get(userPass, 1));
|
||||
if (authenticateSudo != null)
|
||||
loginCredentialsBuilder.authenticateSudo(Boolean.valueOf(authenticateSudo));
|
||||
loginCredentials = loginCredentialsBuilder.build();
|
||||
}
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<Module> setupModules() {
|
||||
return ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule, getSshModule());
|
||||
}
|
||||
|
||||
protected Module getSshModule() {
|
||||
return Modules.EMPTY_MODULE;
|
||||
}
|
||||
}
|
|
@ -53,13 +53,13 @@ public abstract class BaseImageExtensionLiveTest extends BaseComputeServiceConte
|
|||
* @return
|
||||
*/
|
||||
public Template getNodeTemplate() {
|
||||
return context.getComputeService().templateBuilder().any().build();
|
||||
return wrapper.getComputeService().templateBuilder().any().build();
|
||||
}
|
||||
|
||||
@Test(groups = { "integration", "live" }, singleThreaded = true)
|
||||
public void testCreateImage() throws RunNodesException, InterruptedException {
|
||||
|
||||
ComputeService computeService = context.getComputeService();
|
||||
ComputeService computeService = wrapper.getComputeService();
|
||||
|
||||
Optional<ImageExtension> imageExtension = computeService.getImageExtension();
|
||||
assertTrue("image extension was not present", imageExtension.isPresent());
|
||||
|
@ -87,20 +87,20 @@ public abstract class BaseImageExtensionLiveTest extends BaseComputeServiceConte
|
|||
@Test(groups = { "integration", "live" }, singleThreaded = true, dependsOnMethods = "testCreateImage")
|
||||
public void testSpawnNodeFromImage() throws RunNodesException {
|
||||
|
||||
ComputeService computeService = context.getComputeService();
|
||||
ComputeService computeService = wrapper.getComputeService();
|
||||
|
||||
Template template = computeService.templateBuilder().fromImage(getImage().get()).build();
|
||||
|
||||
NodeMetadata node = Iterables.getOnlyElement(computeService.createNodesInGroup("test-create-image", 1, template));
|
||||
|
||||
SshClient client = context.utils().sshForNode().apply(node);
|
||||
SshClient client = wrapper.utils().sshForNode().apply(node);
|
||||
client.connect();
|
||||
|
||||
ExecResponse hello = client.exec("echo hello");
|
||||
|
||||
assertEquals(hello.getOutput().trim(), "hello");
|
||||
|
||||
context.getComputeService().destroyNode(node.getId());
|
||||
wrapper.getComputeService().destroyNode(node.getId());
|
||||
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ public abstract class BaseImageExtensionLiveTest extends BaseComputeServiceConte
|
|||
"testSpawnNodeFromImage" })
|
||||
public void testDeleteImage() {
|
||||
|
||||
ComputeService computeService = context.getComputeService();
|
||||
ComputeService computeService = wrapper.getComputeService();
|
||||
|
||||
Optional<ImageExtension> imageExtension = computeService.getImageExtension();
|
||||
assertTrue("image extension was not present", imageExtension.isPresent());
|
||||
|
@ -123,7 +123,7 @@ public abstract class BaseImageExtensionLiveTest extends BaseComputeServiceConte
|
|||
}
|
||||
|
||||
private Optional<? extends Image> getImage() {
|
||||
return Iterables.tryFind(context.getComputeService().listImages(), new Predicate<Image>() {
|
||||
return Iterables.tryFind(wrapper.getComputeService().listImages(), new Predicate<Image>() {
|
||||
@Override
|
||||
public boolean apply(Image input) {
|
||||
return input.getId().contains("test-create-image");
|
||||
|
|
|
@ -63,15 +63,14 @@ import com.google.inject.Module;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "integration,live")
|
||||
public abstract class BaseTemplateBuilderLiveTest extends
|
||||
BaseComputeServiceContextLiveTest {
|
||||
public abstract class BaseTemplateBuilderLiveTest extends BaseComputeServiceContextLiveTest {
|
||||
|
||||
public void testCompareSizes() throws Exception {
|
||||
Hardware defaultSize = context.getComputeService().templateBuilder().build().getHardware();
|
||||
Hardware defaultSize = wrapper.getComputeService().templateBuilder().build().getHardware();
|
||||
|
||||
Hardware smallest = context.getComputeService().templateBuilder().smallest().build().getHardware();
|
||||
Hardware fastest = context.getComputeService().templateBuilder().fastest().build().getHardware();
|
||||
Hardware biggest = context.getComputeService().templateBuilder().biggest().build().getHardware();
|
||||
Hardware smallest = wrapper.getComputeService().templateBuilder().smallest().build().getHardware();
|
||||
Hardware fastest = wrapper.getComputeService().templateBuilder().fastest().build().getHardware();
|
||||
Hardware biggest = wrapper.getComputeService().templateBuilder().biggest().build().getHardware();
|
||||
|
||||
System.out.printf("smallest %s%n", smallest);
|
||||
System.out.printf("fastest %s%n", fastest);
|
||||
|
@ -90,8 +89,8 @@ public abstract class BaseTemplateBuilderLiveTest extends
|
|||
}
|
||||
|
||||
public void testFromTemplate() {
|
||||
Template defaultTemplate = context.getComputeService().templateBuilder().build();
|
||||
assertEquals(context.getComputeService().templateBuilder().fromTemplate(defaultTemplate).build().toString(),
|
||||
Template defaultTemplate = wrapper.getComputeService().templateBuilder().build();
|
||||
assertEquals(wrapper.getComputeService().templateBuilder().fromTemplate(defaultTemplate).build().toString(),
|
||||
defaultTemplate.toString());
|
||||
}
|
||||
|
||||
|
@ -135,7 +134,7 @@ public abstract class BaseTemplateBuilderLiveTest extends
|
|||
|
||||
@Test(dataProvider = "osSupported")
|
||||
public void testTemplateBuilderCanFind(OsFamilyVersion64Bit matrix) throws InterruptedException {
|
||||
TemplateBuilder builder = context.getComputeService().templateBuilder().osFamily(matrix.family)
|
||||
TemplateBuilder builder = wrapper.getComputeService().templateBuilder().osFamily(matrix.family)
|
||||
.os64Bit(matrix.is64Bit);
|
||||
if (!matrix.version.equals(""))
|
||||
builder.osVersionMatches("^" + matrix.version + "$");
|
||||
|
@ -148,7 +147,7 @@ public abstract class BaseTemplateBuilderLiveTest extends
|
|||
|
||||
@Test(dataProvider = "osNotSupported", expectedExceptions = NoSuchElementException.class)
|
||||
public void testTemplateBuilderCannotFind(OsFamilyVersion64Bit matrix) throws InterruptedException {
|
||||
TemplateBuilder builder = context.getComputeService().templateBuilder().osFamily(matrix.family)
|
||||
TemplateBuilder builder = wrapper.getComputeService().templateBuilder().osFamily(matrix.family)
|
||||
.os64Bit(matrix.is64Bit);
|
||||
if (!matrix.version.equals(""))
|
||||
builder.osVersionMatches("^" + matrix.version + "$");
|
||||
|
@ -157,18 +156,18 @@ public abstract class BaseTemplateBuilderLiveTest extends
|
|||
|
||||
@Test
|
||||
public void testTemplateBuilderCanUseImageId() throws Exception {
|
||||
Template defaultTemplate = context.getComputeService().templateBuilder().build();
|
||||
context.close();
|
||||
Template defaultTemplate = wrapper.getComputeService().templateBuilder().build();
|
||||
wrapper.close();
|
||||
setupContext();
|
||||
|
||||
Template template = context.getComputeService().templateBuilder().imageId(defaultTemplate.getImage().getId())
|
||||
Template template = wrapper.getComputeService().templateBuilder().imageId(defaultTemplate.getImage().getId())
|
||||
.locationId(defaultTemplate.getLocation().getId()).build();
|
||||
assertEquals(template.getImage(), defaultTemplate.getImage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultTemplateBuilder() throws IOException {
|
||||
Template defaultTemplate = context.getComputeService().templateBuilder().build();
|
||||
Template defaultTemplate = wrapper.getComputeService().templateBuilder().build();
|
||||
assert defaultTemplate.getImage().getOperatingSystem().getVersion().matches("1[012].[10][04]") : defaultTemplate
|
||||
.getImage().getOperatingSystem().getVersion();
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||
|
@ -180,9 +179,8 @@ public abstract class BaseTemplateBuilderLiveTest extends
|
|||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testGetAssignableLocations() throws Exception {
|
||||
if (context.unwrap() instanceof Location)
|
||||
assertProvider(Location.class.cast(context.unwrap()));
|
||||
for (Location location : context.getComputeService().listAssignableLocations()) {
|
||||
assertProvider(wrapper.unwrap());
|
||||
for (Location location : wrapper.getComputeService().listAssignableLocations()) {
|
||||
System.err.printf("location %s%n", location);
|
||||
assert location.getId() != null : location;
|
||||
assert location != location.getParent() : location;
|
||||
|
@ -220,14 +218,14 @@ public abstract class BaseTemplateBuilderLiveTest extends
|
|||
|
||||
@Test
|
||||
public void testTemplateBuilderWithImageIdSpecified() throws IOException {
|
||||
Template defaultTemplate = context.getComputeService().templateBuilder().build();
|
||||
Template defaultTemplate = wrapper.getComputeService().templateBuilder().build();
|
||||
|
||||
ComputeServiceContext context = null;
|
||||
try {
|
||||
Properties overrides = setupProperties();
|
||||
overrides.setProperty("jclouds.image-id", defaultTemplate.getImage().getId());
|
||||
|
||||
context = createContext(overrides, setupModules());
|
||||
context = createWrapper(overrides, setupModules());
|
||||
|
||||
assertEquals(context.getComputeService().templateBuilder().build().toString(), defaultTemplate.toString());
|
||||
} finally {
|
||||
|
@ -240,7 +238,7 @@ public abstract class BaseTemplateBuilderLiveTest extends
|
|||
Properties overrides = setupProperties();
|
||||
overrides.setProperty(provider + ".image-id", defaultTemplate.getImage().getId());
|
||||
|
||||
context = createContext(overrides, setupModules());
|
||||
context = createWrapper(overrides, setupModules());
|
||||
|
||||
assertEquals(context.getComputeService().templateBuilder().build().toString(), defaultTemplate.toString());
|
||||
} finally {
|
||||
|
@ -268,7 +266,7 @@ public abstract class BaseTemplateBuilderLiveTest extends
|
|||
boolean auth = authenticateSudo != null ? Boolean.valueOf(authenticateSudo) : true;
|
||||
overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + "");
|
||||
|
||||
context = createContext(overrides, ImmutableSet.<Module>of(credentialStoreModule));
|
||||
context = createWrapper(overrides, ImmutableSet.<Module>of(credentialStoreModule));
|
||||
|
||||
Iterable<String> userPass = Splitter.on(':').split(login);
|
||||
String user = Iterables.get(userPass, 0);
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.internal.ContextImpl;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.rest.Utils;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* Represents an authenticated context to the cloud.
|
||||
*
|
||||
* <h2>Note</h2> Please issue {@link #close()} when you are finished with this context in order to
|
||||
* release resources.
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@ImplementedBy(ContextImpl.class)
|
||||
public interface Context extends Location, Closeable {
|
||||
|
||||
/**
|
||||
* will be removed in jclouds 1.6
|
||||
*
|
||||
* @see Utils#getCredentialStore()
|
||||
*/
|
||||
@Deprecated
|
||||
@Beta
|
||||
Map<String, Credentials> getCredentialStore();
|
||||
|
||||
/**
|
||||
* will be removed in jclouds 1.6
|
||||
*
|
||||
* @see Utils#credentialStore()
|
||||
*/
|
||||
@Deprecated
|
||||
@Beta
|
||||
Map<String, Credentials> credentialStore();
|
||||
|
||||
/**
|
||||
* @return the providerMetadata used to create this context
|
||||
* @see ContextBuilder#newBuilder(org.jclouds.providers.ProviderMetadata)
|
||||
*/
|
||||
ProviderMetadata getProviderMetadata();
|
||||
|
||||
/**
|
||||
* @return the current login user, access key, email, or whatever the 'identity' field was building the context.
|
||||
* @see ApiMetadata#getDefaultIdentity
|
||||
*/
|
||||
String getIdentity();
|
||||
|
||||
/**
|
||||
* will be removed in jclouds 1.6
|
||||
* @see #getProviderMetadata()
|
||||
* @see ProviderMetadata#getEndpoint()
|
||||
*/
|
||||
@Deprecated
|
||||
URI getEndpoint();
|
||||
|
||||
/**
|
||||
* will be removed in jclouds 1.6
|
||||
* @see #getProviderMetadata()
|
||||
* @see ProviderMetadata#getApiMetadata()
|
||||
* @see ApiMetadata#getVersion()
|
||||
*/
|
||||
@Deprecated
|
||||
String getApiVersion();
|
||||
|
||||
/**
|
||||
* will be removed in jclouds 1.6
|
||||
* @see #getProviderMetadata()
|
||||
* @see ProviderMetadata#getApiMetadata()
|
||||
* @see ApiMetadata#getBuildVersion()
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
String getBuildVersion();
|
||||
|
||||
Utils getUtils();
|
||||
|
||||
/**
|
||||
* @see #getUtils
|
||||
*/
|
||||
Utils utils();
|
||||
|
||||
/**
|
||||
* Closes all connections, including executor service
|
||||
*/
|
||||
@Override
|
||||
void close();
|
||||
|
||||
}
|
|
@ -19,9 +19,17 @@
|
|||
package org.jclouds;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.containsPattern;
|
||||
import static com.google.common.base.Predicates.instanceOf;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static com.google.common.collect.Iterables.addAll;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static org.jclouds.Constants.PROPERTY_API;
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.Constants.PROPERTY_BUILD_VERSION;
|
||||
|
@ -32,14 +40,12 @@ import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
|
|||
import static org.jclouds.Constants.PROPERTY_PROVIDER;
|
||||
import static org.jclouds.util.Throwables2.propagateAuthorizationOrOriginalException;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.apis.Apis;
|
||||
|
@ -47,6 +53,9 @@ import org.jclouds.concurrent.MoreExecutors;
|
|||
import org.jclouds.concurrent.SingleThreaded;
|
||||
import org.jclouds.concurrent.config.ConfiguresExecutorService;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.config.BindPropertiesToExpandedValues;
|
||||
import org.jclouds.config.BindRestContextWithWildcardExtendsExplicitAndRawType;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.events.config.ConfiguresEventBus;
|
||||
import org.jclouds.events.config.EventBusModule;
|
||||
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
|
||||
|
@ -54,48 +63,40 @@ import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
|||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
import org.jclouds.lifecycle.config.LifeCycleModule;
|
||||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.logging.config.LoggingModule;
|
||||
import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
||||
import org.jclouds.providers.AnonymousProviderMetadata;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.providers.Providers;
|
||||
import org.jclouds.providers.config.BindProviderMetadataContextAndCredentials;
|
||||
import org.jclouds.providers.internal.UpdateProviderMetadataFromProperties;
|
||||
import org.jclouds.rest.ConfiguresCredentialStore;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestApiMetadata;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.config.BindPropertiesToAnnotations;
|
||||
import org.jclouds.rest.config.CredentialStoreModule;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.rest.config.RestModule;
|
||||
import org.jclouds.rest.internal.BaseRestApiMetadata;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.nnsoft.guice.rocoto.Rocoto;
|
||||
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.util.concurrent.ExecutionList;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Stage;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.util.Types;
|
||||
|
||||
/**
|
||||
* Creates {@link RestContext} or {@link Injector} instances based on the most commonly requested
|
||||
|
@ -110,54 +111,7 @@ import com.google.inject.util.Types;
|
|||
* @author Adrian Cole, Andrew Newdigate
|
||||
* @see RestContext
|
||||
*/
|
||||
public final class ContextBuilder {
|
||||
|
||||
static class ResolveRestContextModule extends AbstractModule {
|
||||
private final RestApiMetadata restApiMetadata;
|
||||
|
||||
ResolveRestContextModule(RestApiMetadata restApiMetadata) {
|
||||
this.restApiMetadata = restApiMetadata;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void configure() {
|
||||
if (restApiMetadata.getContext().getRawType().equals(RestContext.class)) {
|
||||
TypeToken concreteType = BaseRestApiMetadata.contextToken(TypeToken.of(restApiMetadata.getApi()), TypeToken
|
||||
.of(restApiMetadata.getAsyncApi()));
|
||||
// bind explicit type
|
||||
bind(TypeLiteral.get(concreteType.getType())).to(
|
||||
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata
|
||||
.getApi(), restApiMetadata.getAsyncApi())));
|
||||
// bind potentially wildcard type
|
||||
if (!concreteType.equals(restApiMetadata.getContext())) {
|
||||
bind(TypeLiteral.get(restApiMetadata.getContext().getType())).to(
|
||||
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata
|
||||
.getApi(), restApiMetadata.getAsyncApi())));
|
||||
}
|
||||
// bind w/o types
|
||||
bind(TypeLiteral.get(RestContext.class)).to(
|
||||
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata
|
||||
.getApi(), restApiMetadata.getAsyncApi())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class BindDefaultContextQualifiedToProvider extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<TypeToken<? extends Closeable>>() {
|
||||
}).annotatedWith(Provider.class).toInstance(apiMetadata.getContext());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Provider
|
||||
@Singleton
|
||||
protected Closeable wrapped(Injector i, @Provider TypeToken<? extends Closeable> wrappedType) {
|
||||
return (Closeable) i.getInstance(Key.get(TypeLiteral.get(wrappedType.getType())));
|
||||
}
|
||||
}
|
||||
public class ContextBuilder {
|
||||
|
||||
/**
|
||||
* looks up a provider or api with the given id
|
||||
|
@ -177,8 +131,8 @@ public final class ContextBuilder {
|
|||
}
|
||||
} catch (NoSuchElementException e) {
|
||||
Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
|
||||
builder.putAll("providers", Iterables.transform(Providers.all(), Providers.idFunction()));
|
||||
builder.putAll("apis", Iterables.transform(Apis.all(), Apis.idFunction()));
|
||||
builder.putAll("providers", transform(Providers.all(), Providers.idFunction()));
|
||||
builder.putAll("apis", transform(Apis.all(), Apis.idFunction()));
|
||||
throw new NoSuchElementException(String.format("key [%s] not in the list of providers or apis: %s",
|
||||
providerOrApi, builder.build()));
|
||||
}
|
||||
|
@ -200,14 +154,16 @@ public final class ContextBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
protected ProviderMetadata providerMetadata;
|
||||
protected String endpoint;
|
||||
protected String identity;
|
||||
protected Optional<ProviderMetadata> providerMetadata = Optional.absent();
|
||||
protected final String providerId;
|
||||
protected Optional<String> endpoint = Optional.absent();
|
||||
protected Optional<String> identity = Optional.absent();
|
||||
@Nullable
|
||||
protected String credential;
|
||||
protected ApiMetadata apiMetadata;
|
||||
protected String apiVersion;
|
||||
protected String buildVersion;
|
||||
protected Properties overrides = new Properties();;
|
||||
protected Optional<Properties> overrides = Optional.absent();
|
||||
protected List<Module> modules = new ArrayList<Module>(3);
|
||||
|
||||
@Override
|
||||
|
@ -217,36 +173,37 @@ public final class ContextBuilder {
|
|||
}
|
||||
|
||||
protected ContextBuilder(ProviderMetadata providerMetadata) {
|
||||
this(providerMetadata, providerMetadata.getApiMetadata());
|
||||
this(providerMetadata, checkNotNull(providerMetadata, "providerMetadata").getApiMetadata());
|
||||
}
|
||||
|
||||
protected ContextBuilder(@Nullable ProviderMetadata providerMetadata, ApiMetadata apiMetadata) {
|
||||
this.apiMetadata = checkNotNull(apiMetadata, "apiMetadata");
|
||||
this.providerMetadata = providerMetadata;
|
||||
if (providerMetadata != null)
|
||||
this.endpoint = providerMetadata.getEndpoint();
|
||||
if (apiMetadata.getDefaultIdentity().isPresent())
|
||||
identity = apiMetadata.getDefaultIdentity().get();
|
||||
if (apiMetadata.getDefaultCredential().isPresent())
|
||||
credential = apiMetadata.getDefaultCredential().get();
|
||||
if (providerMetadata != null) {
|
||||
this.providerMetadata = Optional.of(providerMetadata);
|
||||
this.endpoint = Optional.of(providerMetadata.getEndpoint());
|
||||
this.providerId = providerMetadata.getId();
|
||||
} else {
|
||||
this.endpoint = apiMetadata.getDefaultEndpoint();
|
||||
this.providerId = apiMetadata.getId();
|
||||
}
|
||||
this.identity = apiMetadata.getDefaultIdentity();
|
||||
this.credential = apiMetadata.getDefaultCredential().orNull();
|
||||
this.apiVersion = apiMetadata.getVersion();
|
||||
this.buildVersion = apiMetadata.getBuildVersion().or("");
|
||||
if (endpoint == null)
|
||||
endpoint = apiMetadata.getDefaultEndpoint().orNull();
|
||||
}
|
||||
|
||||
public ContextBuilder(ApiMetadata apiMetadata) {
|
||||
this(null, apiMetadata);
|
||||
}
|
||||
|
||||
public ContextBuilder credentials(String identity, String credential) {
|
||||
this.identity = identity;
|
||||
public ContextBuilder credentials(String identity, @Nullable String credential) {
|
||||
this.identity = Optional.of(checkNotNull(identity, "identity"));
|
||||
this.credential = credential;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContextBuilder endpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
this.endpoint = Optional.of(checkNotNull(endpoint, "endpoint"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -261,102 +218,136 @@ public final class ContextBuilder {
|
|||
}
|
||||
|
||||
public ContextBuilder modules(Iterable<? extends Module> modules) {
|
||||
addAll(this.modules, modules);
|
||||
addAll(this.modules, checkNotNull(modules, "modules"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContextBuilder overrides(Properties overrides) {
|
||||
this.overrides.putAll(overrides);
|
||||
this.overrides = Optional.of(checkNotNull(overrides, "overrides"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoSuchElementException
|
||||
*/
|
||||
public static String searchPropertiesForProviderScopedProperty(Properties overrides, String prov, String key,
|
||||
String defaultVal) {
|
||||
public static String searchPropertiesForProviderScopedProperty(Properties mutable, String prov, String key) throws NoSuchElementException {
|
||||
try {
|
||||
return Iterables.find(Lists.newArrayList(overrides.getProperty(prov + "." + key), overrides
|
||||
.getProperty("jclouds." + key), defaultVal), Predicates.notNull());
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new NoSuchElementException("no " + key + " configured for provider: " + prov);
|
||||
return find(newArrayList(mutable.getProperty(prov + "." + key), mutable.getProperty("jclouds." + key)),
|
||||
notNull());
|
||||
} finally {
|
||||
mutable.remove(prov + "." + key);
|
||||
mutable.remove("jclouds." + key);
|
||||
}
|
||||
}
|
||||
|
||||
public Injector buildInjector() {
|
||||
checkNotNull(modules, "modules");
|
||||
checkNotNull(overrides, "overrides");
|
||||
checkNotNull(apiMetadata, "api");
|
||||
|
||||
final Properties mutable = new Properties();
|
||||
mutable.putAll(apiMetadata.getDefaultProperties());
|
||||
String providerId;
|
||||
if (providerMetadata != null) {
|
||||
mutable.putAll(providerMetadata.getDefaultProperties());
|
||||
mutable.setProperty(PROPERTY_PROVIDER, providerId = providerMetadata.getId());
|
||||
mutable.setProperty(PROPERTY_ISO3166_CODES, Joiner.on(',').join(providerMetadata.getIso3166Codes()));
|
||||
} else {
|
||||
mutable.setProperty(PROPERTY_PROVIDER, providerId = apiMetadata.getId());
|
||||
}
|
||||
mutable.putAll(checkNotNull(overrides, "overrides"));
|
||||
mutable.putAll(propertiesPrefixedWithJcloudsApiOrProviderId(System.getProperties(), providerId));
|
||||
Properties unexpanded = currentStateToUnexpandedProperties();
|
||||
|
||||
mutable.setProperty(PROPERTY_ENDPOINT, searchPropertiesForProviderScopedProperty(mutable, providerId, "endpoint",
|
||||
endpoint));
|
||||
mutable.setProperty(PROPERTY_API, searchPropertiesForProviderScopedProperty(mutable, providerId, "api",
|
||||
apiMetadata.getName()));
|
||||
mutable.setProperty(PROPERTY_API_VERSION, searchPropertiesForProviderScopedProperty(mutable, providerId,
|
||||
"api-version", apiVersion));
|
||||
mutable.setProperty(PROPERTY_BUILD_VERSION, searchPropertiesForProviderScopedProperty(mutable, providerId,
|
||||
"build-version", buildVersion));
|
||||
mutable.setProperty(PROPERTY_IDENTITY, searchPropertiesForProviderScopedProperty(mutable, providerId, "identity",
|
||||
identity));
|
||||
ImmutableSet<String> keysToResolve = ImmutableSet.of(PROPERTY_ENDPOINT, PROPERTY_IDENTITY, PROPERTY_CREDENTIAL,
|
||||
PROPERTY_API, PROPERTY_API_VERSION, PROPERTY_BUILD_VERSION);
|
||||
|
||||
ImmutableSet<String> optionalKeys = apiMetadata.getCredentialName().isPresent() ? ImmutableSet.<String> of()
|
||||
: ImmutableSet.of(PROPERTY_CREDENTIAL);
|
||||
|
||||
Properties resolved = resolveProperties(unexpanded, providerId, keysToResolve, optionalKeys);
|
||||
|
||||
Properties expanded = expandProperties(resolved);
|
||||
|
||||
Credentials creds = new Credentials(getAndRemove(expanded, PROPERTY_IDENTITY), getAndRemove(expanded,
|
||||
PROPERTY_CREDENTIAL));
|
||||
|
||||
ProviderMetadata providerMetadata = new UpdateProviderMetadataFromProperties(apiMetadata, this.providerMetadata).apply(expanded);
|
||||
|
||||
return buildInjector(providerMetadata, creds, modules);
|
||||
}
|
||||
|
||||
private static String getAndRemove(Properties expanded, String key) {
|
||||
try {
|
||||
mutable.setProperty(PROPERTY_CREDENTIAL, searchPropertiesForProviderScopedProperty(mutable, providerId,
|
||||
"credential", credential));
|
||||
} catch (NoSuchElementException e) {
|
||||
if (apiMetadata.getCredentialName().isPresent())
|
||||
throw e;
|
||||
return expanded.getProperty(key);
|
||||
} finally {
|
||||
expanded.remove(key);
|
||||
}
|
||||
if (providerMetadata == null)
|
||||
providerMetadata = AnonymousProviderMetadata.forApiWithEndpoint(apiMetadata, mutable
|
||||
.getProperty(PROPERTY_ENDPOINT));
|
||||
}
|
||||
|
||||
modules.add(Rocoto.expandVariables(new ConfigurationModule() {
|
||||
private Properties currentStateToUnexpandedProperties() {
|
||||
Properties defaults = new Properties();
|
||||
defaults.putAll(apiMetadata.getDefaultProperties());
|
||||
defaults.setProperty(PROPERTY_PROVIDER,providerId);
|
||||
if (providerMetadata.isPresent()) {
|
||||
defaults.putAll(providerMetadata.get().getDefaultProperties());
|
||||
defaults.setProperty(PROPERTY_ISO3166_CODES, Joiner.on(',').join(providerMetadata.get().getIso3166Codes()));
|
||||
}
|
||||
if (endpoint.isPresent())
|
||||
defaults.setProperty(PROPERTY_ENDPOINT, endpoint.get());
|
||||
defaults.setProperty(PROPERTY_API, apiMetadata.getName());
|
||||
defaults.setProperty(PROPERTY_API_VERSION, apiVersion);
|
||||
defaults.setProperty(PROPERTY_BUILD_VERSION, buildVersion);
|
||||
if (identity.isPresent())
|
||||
defaults.setProperty(PROPERTY_IDENTITY, identity.get());
|
||||
if (credential != null)
|
||||
defaults.setProperty(PROPERTY_CREDENTIAL, credential);
|
||||
if (overrides.isPresent())
|
||||
defaults.putAll(checkNotNull(overrides.get(), "overrides"));
|
||||
defaults.putAll(propertiesPrefixedWithJcloudsApiOrProviderId(getSystemProperties(), apiMetadata.getId(), providerId));
|
||||
return defaults;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindConfigurations() {
|
||||
bindProperties(mutable);
|
||||
}
|
||||
@VisibleForTesting
|
||||
protected Properties getSystemProperties() {
|
||||
return System.getProperties();
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
boolean restModuleSpecifiedByUser = restClientModulePresent(modules);
|
||||
Iterable<Module> defaultModules = ifSpecifiedByUserDontIncludeDefaultRestModule(restModuleSpecifiedByUser);
|
||||
Iterables.addAll(modules, defaultModules);
|
||||
addClientModuleIfNotPresent(modules);
|
||||
addRestContextBinding();
|
||||
private Properties expandProperties(final Properties resolved) {
|
||||
return Guice.createInjector(new BindPropertiesToExpandedValues(resolved)).getInstance(Properties.class);
|
||||
}
|
||||
|
||||
public static Injector buildInjector(ProviderMetadata providerMetadata, Credentials creds, List<Module> inputModules) {
|
||||
List<Module> modules = newArrayList();
|
||||
modules.addAll(inputModules);
|
||||
boolean restModuleSpecifiedByUser = restClientModulePresent(inputModules);
|
||||
Iterable<Module> defaultModules = ifSpecifiedByUserDontIncludeDefaultRestModule(
|
||||
providerMetadata.getApiMetadata(), restModuleSpecifiedByUser);
|
||||
addAll(modules, defaultModules);
|
||||
addClientModuleIfNotPresent(providerMetadata.getApiMetadata(), modules);
|
||||
addRestContextBinding(providerMetadata.getApiMetadata(), modules);
|
||||
addLoggingModuleIfNotPresent(modules);
|
||||
addHttpModuleIfNeededAndNotPresent(modules);
|
||||
addExecutorServiceIfNotPresent(modules);
|
||||
addEventBusIfNotPresent(modules);
|
||||
addCredentialStoreIfNotPresent(modules);
|
||||
modules.add(new LifeCycleModule());
|
||||
modules.add(new BindPropertiesToAnnotations());
|
||||
modules.add(new BindDefaultContextQualifiedToProvider());
|
||||
modules.add(new BindProviderMetadataContextAndCredentials(providerMetadata, creds));
|
||||
Injector returnVal = Guice.createInjector(Stage.PRODUCTION, modules);
|
||||
returnVal.getInstance(ExecutionList.class).execute();
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
void addRestContextBinding() {
|
||||
static Properties resolveProperties(Properties mutable, String providerId, Set<String> keys, Set<String> optionalKeys) throws NoSuchElementException {
|
||||
for (String key : keys){
|
||||
try {
|
||||
String scopedProperty = ImmutableList.copyOf(Splitter.on('.').split(key)).get(1);
|
||||
mutable.setProperty(key, searchPropertiesForProviderScopedProperty(mutable, providerId,scopedProperty));
|
||||
} catch (NoSuchElementException e){
|
||||
if (!optionalKeys.contains(key))
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return mutable;
|
||||
}
|
||||
|
||||
static void addRestContextBinding(ApiMetadata apiMetadata, List<Module> modules) {
|
||||
if (apiMetadata instanceof RestApiMetadata) {
|
||||
modules.add(new ResolveRestContextModule(RestApiMetadata.class.cast(apiMetadata)));
|
||||
try {
|
||||
modules.add(new BindRestContextWithWildcardExtendsExplicitAndRawType(RestApiMetadata.class
|
||||
.cast(apiMetadata)));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Iterable<Module> ifSpecifiedByUserDontIncludeDefaultRestModule(boolean restModuleSpecifiedByUser) {
|
||||
Iterable<Module> defaultModules = Iterables.transform(apiMetadata.getDefaultModules(),
|
||||
static Iterable<Module> ifSpecifiedByUserDontIncludeDefaultRestModule(ApiMetadata apiMetadata,
|
||||
boolean restModuleSpecifiedByUser) {
|
||||
Iterable<Module> defaultModules = transform(apiMetadata.getDefaultModules(),
|
||||
new Function<Class<? extends Module>, Module>() {
|
||||
|
||||
@Override
|
||||
|
@ -364,37 +355,38 @@ public final class ContextBuilder {
|
|||
try {
|
||||
return arg0.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
throw Throwables.propagate(e);
|
||||
throw propagate(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw Throwables.propagate(e);
|
||||
throw propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
if (restModuleSpecifiedByUser)
|
||||
defaultModules = Iterables.filter(defaultModules, Predicates.not(configuresRest));
|
||||
defaultModules = filter(defaultModules, not(configuresRest));
|
||||
return defaultModules;
|
||||
}
|
||||
|
||||
@SuppressWarnings( { "unchecked" })
|
||||
Map<String, Object> propertiesPrefixedWithJcloudsApiOrProviderId(Properties properties, String providerId) {
|
||||
return Maps.filterKeys((Map) System.getProperties(), Predicates.containsPattern("^(jclouds|" + providerId + "|"
|
||||
+ apiMetadata.getId() + ").*"));
|
||||
static Map<String, Object> propertiesPrefixedWithJcloudsApiOrProviderId(Properties properties, String apiId,
|
||||
String providerId) {
|
||||
return Maps.filterKeys((Map) properties, containsPattern("^(jclouds|" + providerId + "|" + apiId
|
||||
+ ").*"));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void addLoggingModuleIfNotPresent(List<Module> modules) {
|
||||
static void addLoggingModuleIfNotPresent(List<Module> modules) {
|
||||
if (!any(modules, instanceOf(LoggingModule.class)))
|
||||
modules.add(new JDKLoggingModule());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addHttpModuleIfNeededAndNotPresent(List<Module> modules) {
|
||||
static void addHttpModuleIfNeededAndNotPresent(List<Module> modules) {
|
||||
if (nothingConfiguresAnHttpService(modules))
|
||||
modules.add(new JavaUrlHttpCommandExecutorServiceModule());
|
||||
}
|
||||
|
||||
private boolean nothingConfiguresAnHttpService(List<Module> modules) {
|
||||
static boolean nothingConfiguresAnHttpService(List<Module> modules) {
|
||||
return (!any(modules, new Predicate<Module>() {
|
||||
public boolean apply(Module input) {
|
||||
return input.getClass().isAnnotationPresent(ConfiguresHttpCommandExecutorService.class);
|
||||
|
@ -404,25 +396,25 @@ public final class ContextBuilder {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void addClientModuleIfNotPresent(List<Module> modules) {
|
||||
static void addClientModuleIfNotPresent(ApiMetadata apiMetadata, List<Module> modules) {
|
||||
if (!restClientModulePresent(modules)) {
|
||||
addClientModule(modules);
|
||||
addClientModule(apiMetadata, modules);
|
||||
}
|
||||
}
|
||||
|
||||
Predicate<Module> configuresRest = new Predicate<Module>() {
|
||||
static Predicate<Module> configuresRest = new Predicate<Module>() {
|
||||
public boolean apply(Module input) {
|
||||
return input.getClass().isAnnotationPresent(ConfiguresRestClient.class);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private boolean restClientModulePresent(List<Module> modules) {
|
||||
static boolean restClientModulePresent(List<Module> modules) {
|
||||
return any(modules, configuresRest);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
static void addClientModule(ApiMetadata apiMetadata, List<Module> modules) {
|
||||
// TODO: move this up
|
||||
if (apiMetadata instanceof RestApiMetadata) {
|
||||
RestApiMetadata rest = RestApiMetadata.class.cast(apiMetadata);
|
||||
|
@ -433,7 +425,7 @@ public final class ContextBuilder {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void addEventBusIfNotPresent(List<Module> modules) {
|
||||
static void addEventBusIfNotPresent(List<Module> modules) {
|
||||
if (!any(modules, new Predicate<Module>() {
|
||||
public boolean apply(Module input) {
|
||||
return input.getClass().isAnnotationPresent(ConfiguresEventBus.class);
|
||||
|
@ -446,7 +438,7 @@ public final class ContextBuilder {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void addExecutorServiceIfNotPresent(List<Module> modules) {
|
||||
static void addExecutorServiceIfNotPresent(List<Module> modules) {
|
||||
if (!any(modules, new Predicate<Module>() {
|
||||
public boolean apply(Module input) {
|
||||
return input.getClass().isAnnotationPresent(ConfiguresExecutorService.class);
|
||||
|
@ -468,7 +460,7 @@ public final class ContextBuilder {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void addCredentialStoreIfNotPresent(List<Module> modules) {
|
||||
static void addCredentialStoreIfNotPresent(List<Module> modules) {
|
||||
if (!any(modules, new Predicate<Module>() {
|
||||
public boolean apply(Module input) {
|
||||
return input.getClass().isAnnotationPresent(ConfiguresCredentialStore.class);
|
||||
|
@ -489,40 +481,55 @@ public final class ContextBuilder {
|
|||
* @see #build(TypeToken)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <C extends Closeable> C build() {
|
||||
public <C extends Context> C build() {
|
||||
return (C) build(apiMetadata.getContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #build(TypeToken)
|
||||
* @see #buildAndWrapWith(Class)
|
||||
*/
|
||||
public <C extends Closeable> C build(Class<C> contextType) {
|
||||
return build(TypeToken.of(checkNotNull(contextType, "contextType")));
|
||||
public <W extends Wrapper> W build(Class<W> wrapperType) {
|
||||
return buildAndWrapWith(checkNotNull(wrapperType, "wrapperType"));
|
||||
}
|
||||
|
||||
/**
|
||||
* this will build any context supported by the ApiMetadata. This includes the base
|
||||
* {@link ApiMetadata#getContext() context}, or any {@link ApiMetadata#getWrappers() wrapper} it
|
||||
* supports.
|
||||
* @see #buildAndWrapWith(TypeToken)
|
||||
*/
|
||||
public <W extends Wrapper> W buildAndWrapWith(Class<W> wrapperType) {
|
||||
return buildAndWrapWith(TypeToken.of(checkNotNull(wrapperType, "wrapperType")));
|
||||
}
|
||||
|
||||
/**
|
||||
* this will build any {@link ApiMetadata#getWrappers() wrapper} supported by the ApiMetadata.
|
||||
*
|
||||
* ex. {@code builder.build(BlobStoreContext.class) } will work, if {@code TypeToken<BlobStore>}
|
||||
* is a configured {@link ApiMetadata#getWrappers() wrapper} of this api.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <C extends Closeable> C build(final TypeToken<C> contextType) {
|
||||
public <W extends Wrapper> W buildAndWrapWith(TypeToken<W> wrapperType) {
|
||||
TypeToken<W> returnType;
|
||||
try {
|
||||
returnType = (TypeToken<W>) Apis.findWrapper(apiMetadata, checkNotNull(wrapperType, "wrapperType"));
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"api %s not wrappable as %s; context: %s, wrappers: %s", apiMetadata,
|
||||
wrapperType, apiMetadata.getContext(), apiMetadata.getWrappers()));
|
||||
}
|
||||
return (W) buildInjector().getInstance(Key.get(TypeLiteral.get(returnType.getType())));
|
||||
}
|
||||
|
||||
/**
|
||||
* this will build the {@link ApiMetadata#getContext() context} supported by the current ApiMetadata.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <C extends Context> C build(TypeToken<C> contextType) {
|
||||
TypeToken<C> returnType = null;
|
||||
if (contextType.isAssignableFrom(apiMetadata.getContext()))
|
||||
returnType = (TypeToken<C>) apiMetadata.getContext();
|
||||
else
|
||||
try {
|
||||
returnType = (TypeToken<C>) Apis.findWrapper(apiMetadata, contextType);
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"api %s not assignable from or transformable to %s; context: %s, wrappers: %s", apiMetadata,
|
||||
contextType, apiMetadata.getContext(), apiMetadata.getWrappers()));
|
||||
}
|
||||
throw new IllegalArgumentException(String.format("api %s not assignable from %s; context: %s", apiMetadata,
|
||||
contextType, apiMetadata.getContext()));
|
||||
return (C) buildInjector().getInstance(Key.get(TypeLiteral.get(returnType.getType())));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
|
@ -57,14 +55,14 @@ public interface Wrapper {
|
|||
* class.
|
||||
* @see #getWrappedType()
|
||||
*/
|
||||
<C extends Closeable> C unwrap(TypeToken<C> type) throws IllegalArgumentException;
|
||||
<C extends Context> C unwrap(TypeToken<C> type) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* shortcut for {@code unwrap(TypeToken.of(clazz))}
|
||||
*
|
||||
* @see #unwrap(TypeToken)
|
||||
*/
|
||||
<C extends Closeable> C unwrap(Class<C> clazz) throws IllegalArgumentException;
|
||||
<C extends Context> C unwrap(Class<C> clazz) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* shortcut for {@code unwrap(getWrappedType())}
|
||||
|
@ -73,6 +71,6 @@ public interface Wrapper {
|
|||
* if the user supplied {@code C} param is not assignableFrom
|
||||
* {@link #getWrappedType()}
|
||||
*/
|
||||
<C extends Closeable> C unwrap() throws ClassCastException;
|
||||
<C extends Context> C unwrap() throws ClassCastException;
|
||||
|
||||
}
|
|
@ -18,12 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.apis;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.Wrapper;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
|
@ -56,7 +56,7 @@ public interface ApiMetadata extends Serializable {
|
|||
/**
|
||||
* @see ApiMetadata#getContext()
|
||||
*/
|
||||
Builder context(TypeToken<? extends Closeable> context);
|
||||
Builder context(TypeToken<? extends Context> context);
|
||||
|
||||
/**
|
||||
* @see ApiMetadata#getWrappers()
|
||||
|
@ -262,7 +262,7 @@ public interface ApiMetadata extends Serializable {
|
|||
/**
|
||||
* @return the primary context of this api, for example {@code RestContext<EC2Client, EC2AsyncClient>}
|
||||
*/
|
||||
TypeToken<? extends Closeable> getContext();
|
||||
TypeToken<? extends Context> getContext();
|
||||
|
||||
/**
|
||||
* @return types of contexts this can be transformed into, for example {@code BlobStoreContext}
|
||||
|
|
|
@ -28,19 +28,18 @@ import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST;
|
|||
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTION_REUSE;
|
||||
import static org.jclouds.Constants.PROPERTY_MAX_SESSION_FAILURES;
|
||||
import static org.jclouds.Constants.PROPERTY_PRETTY_PRINT_PAYLOADS;
|
||||
import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
|
||||
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
|
||||
import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.Wrapper;
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Optional;
|
||||
|
@ -95,7 +94,7 @@ public abstract class BaseApiMetadata implements ApiMetadata {
|
|||
protected Properties defaultProperties = BaseApiMetadata.defaultProperties();
|
||||
protected URI documentation;
|
||||
//
|
||||
protected TypeToken<? extends Closeable> context = TypeToken.of(Closer.class);
|
||||
protected TypeToken<? extends Context> context = TypeToken.of(Context.class);
|
||||
protected Set<Class<? extends Module>> defaultModules = ImmutableSet.of();
|
||||
|
||||
/**
|
||||
|
@ -235,7 +234,7 @@ public abstract class BaseApiMetadata implements ApiMetadata {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder context(TypeToken<? extends Closeable> context) {
|
||||
public Builder context(TypeToken<? extends Context> context) {
|
||||
this.context = checkNotNull(context, "context");
|
||||
return this;
|
||||
}
|
||||
|
@ -289,7 +288,7 @@ public abstract class BaseApiMetadata implements ApiMetadata {
|
|||
protected final Optional<String> defaultCredential;
|
||||
protected final Properties defaultProperties;
|
||||
protected final URI documentation;
|
||||
protected final TypeToken<? extends Closeable> context;
|
||||
protected final TypeToken<? extends Context> context;
|
||||
protected final Set<Class<? extends Module>> defaultModules;
|
||||
|
||||
protected BaseApiMetadata(Builder builder) {
|
||||
|
@ -302,7 +301,7 @@ public abstract class BaseApiMetadata implements ApiMetadata {
|
|||
public BaseApiMetadata(String id, String name, Set<TypeToken<? extends Wrapper>> wrappers, String endpointName, String identityName,
|
||||
Optional<String> credentialName, String version, Optional<String> buildVersion,
|
||||
Optional<String> defaultEndpoint, Optional<String> defaultIdentity, Optional<String> defaultCredential,
|
||||
Properties defaultProperties, URI documentation, TypeToken<? extends Closeable> context,
|
||||
Properties defaultProperties, URI documentation, TypeToken<? extends Context> context,
|
||||
Set<Class<? extends Module>> defaultModules) {
|
||||
this.id = checkNotNull(id, "id");
|
||||
this.name = checkNotNull(name, "name");
|
||||
|
@ -458,7 +457,7 @@ public abstract class BaseApiMetadata implements ApiMetadata {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TypeToken<? extends Closeable> getContext() {
|
||||
public TypeToken<? extends Context> getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* 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.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.internal.FilterStringsBoundToInjectorByName;
|
||||
import org.nnsoft.guice.rocoto.Rocoto;
|
||||
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* expands properties.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BindPropertiesToExpandedValues extends AbstractModule {
|
||||
private final Properties resolved;
|
||||
|
||||
public BindPropertiesToExpandedValues(Properties resolved) {
|
||||
this.resolved = checkNotNull(resolved, "resolved");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(Rocoto.expandVariables(new ConfigurationModule() {
|
||||
|
||||
@Override
|
||||
protected void bindConfigurations() {
|
||||
bindProperties(resolved);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Properties expanded(FilterStringsBoundToInjectorByName filterStringsBoundByName) {
|
||||
Properties props = new Properties();
|
||||
props.putAll(filterStringsBoundByName.apply(Predicates.<String> alwaysTrue()));
|
||||
return props;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* 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.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.rest.RestApiMetadata;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.BaseRestApiMetadata;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.util.Types;
|
||||
|
||||
/**
|
||||
* Allows you to lookup the {@link RestApiMetadata#getContext()} as {@link RestContext}, {@code RestContext<Client, AsyncClient>}, and {@code
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BindRestContextWithWildcardExtendsExplicitAndRawType extends AbstractModule {
|
||||
private final RestApiMetadata restApiMetadata;
|
||||
|
||||
public BindRestContextWithWildcardExtendsExplicitAndRawType(RestApiMetadata restApiMetadata)
|
||||
throws IllegalArgumentException {
|
||||
this.restApiMetadata = checkNotNull(restApiMetadata, "restApiMetadata");
|
||||
checkArgument(restApiMetadata.getContext().getRawType().equals(RestContext.class),
|
||||
"this does not work as %s raw type is not RestContext", restApiMetadata.getContext());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void configure() {
|
||||
TypeToken concreteType = BaseRestApiMetadata.contextToken(TypeToken.of(restApiMetadata.getApi()), TypeToken
|
||||
.of(restApiMetadata.getAsyncApi()));
|
||||
// bind explicit type
|
||||
bind(TypeLiteral.get(concreteType.getType())).to(
|
||||
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class,
|
||||
restApiMetadata.getApi(), restApiMetadata.getAsyncApi())));
|
||||
// bind potentially wildcard type
|
||||
if (!concreteType.equals(restApiMetadata.getContext())) {
|
||||
bind(TypeLiteral.get(restApiMetadata.getContext().getType())).to(
|
||||
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata
|
||||
.getApi(), restApiMetadata.getAsyncApi())));
|
||||
}
|
||||
// bind w/o types
|
||||
bind(TypeLiteral.get(RestContext.class)).to(
|
||||
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class,
|
||||
restApiMetadata.getApi(), restApiMetadata.getAsyncApi())));
|
||||
}
|
||||
}
|
|
@ -19,13 +19,8 @@
|
|||
package org.jclouds.http.filters;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
|
@ -35,6 +30,8 @@ import org.jclouds.http.HttpException;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.utils.ModifyRequest;
|
||||
import org.jclouds.rest.annotations.Credential;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
|
||||
/**
|
||||
* Uses Basic Authentication to sign the request.
|
||||
|
@ -49,11 +46,10 @@ public class BasicAuthentication implements HttpRequestFilter {
|
|||
private final String header;
|
||||
|
||||
@Inject
|
||||
public BasicAuthentication(@Named(PROPERTY_IDENTITY) String user, @Named(PROPERTY_CREDENTIAL) String password,
|
||||
Crypto crypto) throws UnsupportedEncodingException {
|
||||
public BasicAuthentication(@Identity String user, @Credential String password, Crypto crypto) {
|
||||
this.header = "Basic "
|
||||
+ CryptoStreams.base64(String.format("%s:%s", checkNotNull(user, "user"),
|
||||
checkNotNull(password, "password")).getBytes("UTF-8"));
|
||||
+ CryptoStreams.base64(String.format("%s:%s", checkNotNull(user, "user"),
|
||||
checkNotNull(password, "password")).getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,56 +21,56 @@ import static com.google.common.base.Objects.equal;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.Wrapper;
|
||||
import org.jclouds.location.Provider;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.collect.ForwardingObject;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public abstract class BaseWrapper implements Wrapper {
|
||||
public abstract class BaseWrapper extends ForwardingObject implements Wrapper {
|
||||
|
||||
private final Closeable wrapped;
|
||||
private final TypeToken<? extends Closeable> wrappedType;
|
||||
private final Context wrapped;
|
||||
private final TypeToken<? extends Context> wrappedType;
|
||||
|
||||
|
||||
protected BaseWrapper(@Provider Closeable wrapped, @Provider TypeToken<? extends Closeable> wrappedType) {
|
||||
protected BaseWrapper(@Provider Context wrapped, @Provider TypeToken<? extends Context> wrappedType) {
|
||||
this.wrapped = checkNotNull(wrapped, "wrapped");
|
||||
this.wrappedType = checkNotNull(wrappedType, "wrappedType");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <C extends Closeable> C unwrap(TypeToken<C> type) {
|
||||
public <C extends Context> C unwrap(TypeToken<C> type) {
|
||||
checkArgument(checkNotNull(type, "type").isAssignableFrom(wrappedType), "wrapped type: %s not assignable from %s", wrappedType, type);
|
||||
return (C) wrapped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <C extends Closeable> C unwrap(Class<C> clazz) {
|
||||
public <C extends Context> C unwrap(Class<C> clazz) {
|
||||
return unwrap (TypeToken.of(checkNotNull(clazz, "clazz")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeToken<? extends Closeable> getWrappedType() {
|
||||
public TypeToken<? extends Context> getWrappedType() {
|
||||
return wrappedType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <C extends Closeable> C unwrap() throws ClassCastException {
|
||||
public <C extends Context> C unwrap() throws ClassCastException {
|
||||
return (C) unwrap(getWrappedType());
|
||||
}
|
||||
|
||||
public Closeable getWrapped() {
|
||||
@Override
|
||||
protected Context delegate() {
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
|
@ -81,12 +81,12 @@ public abstract class BaseWrapper implements Wrapper {
|
|||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
BaseWrapper that = BaseWrapper.class.cast(o);
|
||||
return equal(this.getWrapped(), that.getWrapped()) && equal(this.getWrappedType(), that.getWrappedType());
|
||||
return equal(this.delegate(), that.delegate()) && equal(this.getWrappedType(), that.getWrappedType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(getWrapped(), getWrappedType());
|
||||
return Objects.hashCode(delegate(), getWrappedType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,7 +95,7 @@ public abstract class BaseWrapper implements Wrapper {
|
|||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper("").add("wrapped", getWrapped()).add("wrappedType", getWrappedType());
|
||||
return Objects.toStringHelper("").add("wrapped", delegate()).add("wrappedType", getWrappedType());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,220 @@
|
|||
/**
|
||||
* 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.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.rest.Utils;
|
||||
import org.jclouds.rest.annotations.Identity;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ContextImpl implements Context {
|
||||
|
||||
private final ProviderMetadata providerMetadata;
|
||||
private final String identity;
|
||||
private final Utils utils;
|
||||
private final Closer closer;
|
||||
|
||||
@Inject
|
||||
protected ContextImpl(ProviderMetadata providerMetadata, @Identity String identity, Utils utils, Closer closer) {
|
||||
this.providerMetadata = checkNotNull(providerMetadata, "providerMetadata");
|
||||
this.identity = checkNotNull(identity, "identity");
|
||||
this.utils = checkNotNull(utils, "utils");
|
||||
this.closer = checkNotNull(closer, "closer");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
Closeables.closeQuietly(closer);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ProviderMetadata getProviderMetadata() {
|
||||
return providerMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public URI getEndpoint() {
|
||||
return URI.create(providerMetadata.getEndpoint());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Utils getUtils() {
|
||||
return utils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Utils utils() {
|
||||
return utils;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getApiVersion() {
|
||||
return providerMetadata.getApiMetadata().getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getBuildVersion() {
|
||||
return providerMetadata.getApiMetadata().getBuildVersion().orNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(providerMetadata, identity);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ContextImpl that = ContextImpl.class.cast(obj);
|
||||
return Objects.equal(this.providerMetadata, that.providerMetadata) && Objects.equal(this.identity, that.identity);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("").add("providerMetadata", providerMetadata).add("identity", identity).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return providerMetadata.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return providerMetadata.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getIso3166Codes() {
|
||||
return providerMetadata.getIso3166Codes();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getMetadata() {
|
||||
return ImmutableMap.<String, Object> of("endpoint", URI.create(providerMetadata.getEndpoint()), "apiVersion",
|
||||
providerMetadata.getApiMetadata().getVersion(), "buildVersion", providerMetadata.getApiMetadata()
|
||||
.getBuildVersion().or(""), "identity", identity);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public LocationScope getScope() {
|
||||
return LocationScope.PROVIDER;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Credentials> credentialStore() {
|
||||
return utils().credentialStore();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Credentials> getCredentialStore() {
|
||||
return utils().credentialStore();
|
||||
}
|
||||
|
||||
}
|
|
@ -20,12 +20,12 @@ package org.jclouds.location.suppliers;
|
|||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.location.suppliers.fromconfig.ProviderURIFromConfiguration;
|
||||
import org.jclouds.location.suppliers.fromconfig.ProviderURIFromProviderMetadata;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
@ImplementedBy(ProviderURIFromConfiguration.class)
|
||||
@ImplementedBy(ProviderURIFromProviderMetadata.class)
|
||||
public interface ProviderURISupplier extends Supplier<URI> {
|
||||
|
||||
}
|
|
@ -18,22 +18,19 @@
|
|||
*/
|
||||
package org.jclouds.location.suppliers.fromconfig;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.location.suppliers.ProviderURISupplier;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.rest.suppliers.URIFromStringSupplier;
|
||||
|
||||
@Singleton
|
||||
public class ProviderURIFromConfiguration extends URIFromStringSupplier implements
|
||||
public class ProviderURIFromProviderMetadata extends URIFromStringSupplier implements
|
||||
ProviderURISupplier {
|
||||
@Inject
|
||||
protected ProviderURIFromConfiguration(@Named(PROPERTY_ENDPOINT) String endpoint) {
|
||||
super(checkNotNull(endpoint, PROPERTY_ENDPOINT));
|
||||
protected ProviderURIFromProviderMetadata(ProviderMetadata in) {
|
||||
super(in.getEndpoint());
|
||||
}
|
||||
|
||||
}
|
|
@ -18,8 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.providers;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import org.jclouds.Context;
|
||||
import org.jclouds.Wrapper;
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.apis.ApiPredicates;
|
||||
|
@ -38,9 +37,9 @@ import com.google.common.reflect.TypeToken;
|
|||
public class ProviderPredicates {
|
||||
|
||||
public static class ContextAssignableFrom implements Predicate<ProviderMetadata> {
|
||||
private final TypeToken<? extends Closeable> type;
|
||||
private final TypeToken<? extends Context> type;
|
||||
|
||||
public ContextAssignableFrom(TypeToken<? extends Closeable> type) {
|
||||
public ContextAssignableFrom(TypeToken<? extends Context> type) {
|
||||
Preconditions.checkNotNull(type, "context must be defined");
|
||||
this.type = type;
|
||||
}
|
||||
|
@ -261,7 +260,7 @@ public class ProviderPredicates {
|
|||
*
|
||||
* @return the providers with an context assignable from the given type.
|
||||
*/
|
||||
public static Predicate<ProviderMetadata> contextAssignableFrom(final TypeToken<? extends Closeable> type) {
|
||||
public static Predicate<ProviderMetadata> contextAssignableFrom(final TypeToken<? extends Context> type) {
|
||||
return new ContextAssignableFrom(type);
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue