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