Issue 241:Add provider to the Location hierarchy and make getParent a Location object; also fixed compute services where broken and added ssh logging for runscript

This commit is contained in:
Adrian Cole 2010-05-03 01:04:48 -07:00
parent ae130eff83
commit a1c7ccfd3f
152 changed files with 770 additions and 540 deletions

View File

@ -47,15 +47,15 @@ import com.google.inject.TypeLiteral;
public class AtmosStorageContextBuilder extends
BlobStoreContextBuilder<AtmosStorageAsyncClient, AtmosStorageClient> {
public AtmosStorageContextBuilder(Properties props) {
super(new TypeLiteral<AtmosStorageAsyncClient>() {
public AtmosStorageContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<AtmosStorageAsyncClient>() {
}, new TypeLiteral<AtmosStorageClient>() {
}, props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new AtmosBlobStoreContextModule());
protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new AtmosBlobStoreContextModule(providerName));
}
@Override

View File

@ -41,18 +41,18 @@ import com.google.inject.Module;
*/
public class AtmosStorageContextFactory {
public static BlobStoreContext createContext(Properties properties, Module... modules) {
return new AtmosStorageContextBuilder(new AtmosStoragePropertiesBuilder(properties).build())
.withModules(modules).buildBlobStoreContext();
return new AtmosStorageContextBuilder("atmosstorage", new AtmosStoragePropertiesBuilder(
properties).build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(String uid, String key, Module... modules) {
return new AtmosStorageContextBuilder(new AtmosStoragePropertiesBuilder(uid, key).build())
.withModules(modules).buildBlobStoreContext();
return new AtmosStorageContextBuilder("atmosstorage", new AtmosStoragePropertiesBuilder(uid,
key).build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(URI endpoint, String uid, String key,
Module... modules) {
return new AtmosStorageContextBuilder(new AtmosStoragePropertiesBuilder(uid, key)
.withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
return new AtmosStorageContextBuilder("atmosstorage", new AtmosStoragePropertiesBuilder(uid,
key).withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
}
}

View File

@ -50,6 +50,11 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
*/
public class AtmosBlobStoreContextModule extends AtmosStorageContextModule {
private final String providerName;
public AtmosBlobStoreContextModule(String providerName) {
this.providerName = providerName;
}
@Override
protected void configure() {
@ -68,7 +73,7 @@ public class AtmosBlobStoreContextModule extends AtmosStorageContextModule {
@Provides
@Singleton
Location getLocation() {
return new LocationImpl(LocationScope.ZONE, "UNKNOWN", "TODO", null);
return new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
}
@Provides

View File

@ -35,6 +35,7 @@ import org.jclouds.atmosonline.saas.domain.FileType;
import org.jclouds.atmosonline.saas.domain.SystemMetadata;
import org.jclouds.atmosonline.saas.options.ListOptions;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.blobstore.KeyAlreadyExistsException;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
@ -49,6 +50,8 @@ import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Tests behavior of {@code AtmosStorageClient}
@ -109,12 +112,12 @@ public class AtmosStorageClientLiveTest {
URI container2;
@BeforeGroups(groups = { "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException {
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
String uid = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
BlobStoreContext blobStoreContext = new AtmosStorageContextBuilder(
new AtmosStoragePropertiesBuilder(uid, key).build()).withModules(
new Log4JLoggingModule()).buildBlobStoreContext();
BlobStoreContext blobStoreContext = new BlobStoreContextFactory().createContext(
"atmosstorage", uid, key, ImmutableSet.<Module> of(new Log4JLoggingModule()));
RestContext<AtmosStorageAsyncClient, AtmosStorageClient> context = blobStoreContext
.getProviderSpecificContext();
connection = context.getApi();

View File

@ -45,7 +45,7 @@ public class AtmosBlobStoreModuleTest {
Injector createInjector() {
return Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor(),
sameThreadExecutor()), new JDKLoggingModule(), new AtmosStorageStubClientModule(),
new AtmosBlobStoreContextModule() {
new AtmosBlobStoreContextModule("atmos") {
@Override
protected void configure() {
bindConstant().annotatedWith(

View File

@ -18,9 +18,6 @@
*/
package org.jclouds.aws.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
*

View File

@ -45,11 +45,10 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
* @see EC2ComputeServiceContext
*/
public class EC2ContextBuilder extends
ComputeServiceContextBuilder<EC2AsyncClient, EC2Client> {
public class EC2ContextBuilder extends ComputeServiceContextBuilder<EC2AsyncClient, EC2Client> {
public EC2ContextBuilder(Properties props) {
super(new TypeLiteral<EC2AsyncClient>() {
public EC2ContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<EC2AsyncClient>() {
}, new TypeLiteral<EC2Client>() {
}, props);
}
@ -60,8 +59,8 @@ public class EC2ContextBuilder extends
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new EC2ComputeServiceContextModule());
protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new EC2ComputeServiceContextModule(providerName));
}
@Override
@ -69,8 +68,8 @@ public class EC2ContextBuilder extends
modules.add(new EC2RestClientModule());
}
@Override
protected void addImageResolutionModule() {
modules.add(new EC2ResolveImagesModule());
}
@Override
protected void addImageResolutionModule() {
modules.add(new EC2ResolveImagesModule());
}
}

View File

@ -42,26 +42,26 @@ import com.google.inject.Module;
*/
public class EC2ContextFactory {
public static ComputeServiceContext createContext(Properties properties, Module... modules) {
return new EC2ContextBuilder(new EC2PropertiesBuilder(properties).build())
return new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(properties).build())
.withModules(modules).buildComputeServiceContext();
}
public static ComputeServiceContext createContext(String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId,
return new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).build()).withModules(modules).buildComputeServiceContext();
}
public static ComputeServiceContext createContext(Properties properties, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ContextBuilder(new EC2PropertiesBuilder(properties)
.withCredentials(awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules)
return new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules)
.buildComputeServiceContext();
}
public static ComputeServiceContext createContext(URI endpoint, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new EC2ContextBuilder(new EC2PropertiesBuilder(awsAccessKeyId,
return new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
.buildComputeServiceContext();
}

View File

@ -27,7 +27,6 @@ import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromNodeOrDefault;
import org.jclouds.aws.ec2.compute.domain.PortsRegionTag;

View File

@ -99,6 +99,12 @@ import com.google.inject.TypeLiteral;
*/
public class EC2ComputeServiceContextModule extends EC2ContextModule {
private final String providerName;
public EC2ComputeServiceContextModule(String providerName) {
this.providerName = providerName;
}
@Override
protected void configure() {
super.configure();
@ -146,8 +152,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
public static class GetRegionFromNodeOrDefault implements Function<ComputeMetadata, String> {
public String apply(ComputeMetadata node) {
Location location = node.getLocation();
String region = location.getScope() == LocationScope.REGION ? location
.getId() : location.getParent();
String region = location.getScope() == LocationScope.REGION ? location.getId() : location
.getParent().getId();
return region;
}
}
@ -257,14 +263,15 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides
@Singleton
Map<String, ? extends Location> provideLocations(Map<String, String> availabilityZoneToRegionMap) {
Location ec2 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Map<String, Location> locations = Maps.newLinkedHashMap();
for (String zone : availabilityZoneToRegionMap.keySet()) {
locations.put(zone, new LocationImpl(LocationScope.ZONE, zone, zone,
availabilityZoneToRegionMap.get(zone)));
}
for (String region : availabilityZoneToRegionMap.values()) {
locations.put(region, new LocationImpl(LocationScope.REGION, region,
region, null));
locations.put(region, new LocationImpl(LocationScope.REGION, region, region, ec2));
}
for (String zone : availabilityZoneToRegionMap.keySet()) {
locations.put(zone, new LocationImpl(LocationScope.ZONE, zone, zone, locations
.get(availabilityZoneToRegionMap.get(zone))));
}
return locations;
}

View File

@ -29,7 +29,6 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.RegionTag;
import org.jclouds.aws.ec2.domain.KeyPair;

View File

@ -8,7 +8,6 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.PortsRegionTag;
import org.jclouds.aws.ec2.domain.IpProtocol;

View File

@ -24,7 +24,6 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromNodeOrDefault;
import org.jclouds.aws.ec2.domain.RunningInstance;

View File

@ -125,7 +125,7 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
// if the location has a parent, it must be an availability zone.
String region = zone == null ? template.getLocation().getId() :
template.getLocation().getParent();
template.getLocation().getParent().getId();
// get or create incidental resources
// TODO race condition. we were using MapMaker, but it doesn't seem to refresh properly when

View File

@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import org.jclouds.aws.domain.Region;
/**
*
* @see <a href=

View File

@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import org.jclouds.aws.domain.Region;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

View File

@ -23,8 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.Set;
import org.jclouds.aws.domain.Region;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

View File

@ -20,8 +20,6 @@ package org.jclouds.aws.ec2.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.aws.domain.Region;
/**
*

View File

@ -20,8 +20,6 @@ package org.jclouds.aws.ec2.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.aws.domain.Region;
import com.google.inject.internal.Nullable;
/**

View File

@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.net.InetAddress;
import org.jclouds.aws.domain.Region;
import com.google.inject.internal.Nullable;
/**

View File

@ -23,8 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jclouds.aws.domain.Region;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.internal.Nullable;

View File

@ -25,7 +25,6 @@ import java.util.Date;
import java.util.Map;
import java.util.Set;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.Attachment.Status;
import com.google.common.collect.Maps;

View File

@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import org.jclouds.aws.domain.Region;
/**
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-SecurityGroupItemType.html"

View File

@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import org.jclouds.aws.domain.Region;
/**
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSnapshot.html"

View File

@ -25,8 +25,6 @@ import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.aws.domain.Region;
import com.google.common.base.CaseFormat;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

View File

@ -24,7 +24,6 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import com.google.common.base.Function;

View File

@ -29,7 +29,6 @@ import javax.annotation.Nullable;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;

View File

@ -25,7 +25,6 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.aws.ec2.options.DescribeAvailabilityZonesOptions;
import org.jclouds.aws.ec2.options.DescribeRegionsOptions;

View File

@ -29,7 +29,6 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.binders.BindInetAddressesToIndexedFormParams;
import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;

View File

@ -25,7 +25,6 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair;
import org.jclouds.concurrent.Timeout;

View File

@ -28,7 +28,6 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.binders.BindKeyNameToIndexedFormParams;
import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;

View File

@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.concurrent.Timeout;

View File

@ -28,7 +28,6 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams;
import org.jclouds.aws.ec2.domain.MonitoringState;
import org.jclouds.aws.ec2.functions.RegionToEndpoint;

View File

@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.MonitoringState;
import org.jclouds.concurrent.Timeout;

View File

@ -28,7 +28,6 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.binders.BindGroupNameToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindUserIdGroupPairToSourceSecurityGroupFormParams;
import org.jclouds.aws.ec2.domain.IpProtocol;

View File

@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.IpProtocol;
import org.jclouds.aws.ec2.domain.SecurityGroup;
import org.jclouds.aws.ec2.domain.UserIdGroupPair;

View File

@ -23,7 +23,6 @@ import java.util.Date;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.Attachment;
import org.jclouds.aws.ec2.util.EC2Utils;

View File

@ -25,7 +25,6 @@ import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair;
import org.jclouds.aws.ec2.util.EC2Utils;

View File

@ -24,7 +24,6 @@ import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.Image;
import org.jclouds.aws.ec2.domain.RootDeviceType;

View File

@ -22,7 +22,6 @@ import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.date.DateService;

View File

@ -22,7 +22,6 @@ import java.util.Set;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.util.EC2Utils;

View File

@ -23,7 +23,6 @@ import java.util.Map;
import javax.annotation.Resource;
import org.jclouds.aws.domain.Region;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;

View File

@ -22,7 +22,6 @@ import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.IpPermission;
import org.jclouds.aws.ec2.domain.IpProtocol;

View File

@ -22,7 +22,6 @@ import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.InstanceStateChange;

View File

@ -18,7 +18,6 @@
*/
package org.jclouds.aws.ec2.xml;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.http.functions.ParseSax;
/**

View File

@ -20,7 +20,6 @@ package org.jclouds.aws.ec2.xml;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.util.EC2Utils;

View File

@ -20,7 +20,6 @@ package org.jclouds.aws.ec2.xml;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.date.DateService;

View File

@ -22,7 +22,6 @@ import java.util.Date;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.Snapshot;
import org.jclouds.aws.ec2.domain.Snapshot.Status;

View File

@ -46,15 +46,15 @@ import com.google.inject.TypeLiteral;
*/
public class S3ContextBuilder extends BlobStoreContextBuilder<S3AsyncClient, S3Client> {
public S3ContextBuilder(Properties props) {
super(new TypeLiteral<S3AsyncClient>() {
public S3ContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<S3AsyncClient>() {
}, new TypeLiteral<S3Client>() {
}, props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new S3BlobStoreContextModule());
protected void addContextModule(String providerName,List<Module> modules) {
modules.add(new S3BlobStoreContextModule(providerName));
}
@Override

View File

@ -41,27 +41,27 @@ import com.google.inject.Module;
*/
public class S3ContextFactory {
public static BlobStoreContext createContext(Properties properties,
Module... modules) {
return new S3ContextBuilder(new S3PropertiesBuilder(properties).build()).withModules(modules)
public static BlobStoreContext createContext(Properties properties, Module... modules) {
return new S3ContextBuilder("s3", new S3PropertiesBuilder(properties).build()).withModules(
modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(Properties properties, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new S3ContextBuilder("s3", new S3PropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules)
.buildBlobStoreContext();
}
public static BlobStoreContext createContext(Properties properties,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new S3ContextBuilder(new S3PropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new S3ContextBuilder(new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey)
public static BlobStoreContext createContext(String awsAccessKeyId, String awsSecretAccessKey,
Module... modules) {
return new S3ContextBuilder("s3", new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey)
.build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(URI endpoint,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new S3ContextBuilder(new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey)
public static BlobStoreContext createContext(URI endpoint, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new S3ContextBuilder("s3", new S3PropertiesBuilder(awsAccessKeyId, awsSecretAccessKey)
.withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
}
}

View File

@ -23,7 +23,6 @@ import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.S3;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
@ -53,6 +52,11 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
*/
public class S3BlobStoreContextModule extends S3ContextModule {
private final String providerName;
public S3BlobStoreContextModule(String providerName) {
this.providerName = providerName;
}
@Override
protected void configure() {
@ -76,9 +80,10 @@ public class S3BlobStoreContextModule extends S3ContextModule {
@Singleton
Map<String, ? extends Location> provideLocations(@S3 Set<String> regions) {
Set<Location> locations = Sets.newHashSet();
Location s3 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
for (String zone : regions) {
locations
.add(new LocationImpl(LocationScope.ZONE, zone.toString(), zone.toString(), null));
.add(new LocationImpl(LocationScope.REGION, zone.toString(), zone.toString(), s3));
}
return Maps.uniqueIndex(locations, new Function<Location, String>() {
@Override

View File

@ -24,7 +24,6 @@ import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.domain.BucketMetadata;
import org.jclouds.blobstore.ContainerNotFoundException;

View File

@ -28,7 +28,6 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.aws.sqs.functions.QueueLocation;

View File

@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.aws.sqs.options.CreateQueueOptions;
import org.jclouds.aws.sqs.options.ListQueuesOptions;

View File

@ -46,15 +46,15 @@ import com.google.inject.TypeLiteral;
*/
public class SQSContextBuilder extends RestContextBuilder<SQSAsyncClient, SQSClient> {
public SQSContextBuilder(Properties props) {
super(new TypeLiteral<SQSAsyncClient>() {
public SQSContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<SQSAsyncClient>() {
}, new TypeLiteral<SQSClient>() {
}, props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new SQSContextModule());
protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new SQSContextModule(providerName));
}
@Override

View File

@ -43,25 +43,26 @@ public class SQSContextFactory {
public static RestContext<SQSAsyncClient, SQSClient> createContext(Properties properties,
Module... modules) {
return new SQSContextBuilder(new SQSPropertiesBuilder(properties).build()).withModules(
modules).buildContext();
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(properties).build())
.withModules(modules).buildContext();
}
public static RestContext<SQSAsyncClient, SQSClient> createContext(Properties properties, String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new SQSContextBuilder(new SQSPropertiesBuilder(properties).withCredentials(awsAccessKeyId, awsSecretAccessKey)
.build()).withModules(modules).buildContext();
public static RestContext<SQSAsyncClient, SQSClient> createContext(Properties properties,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(properties).withCredentials(
awsAccessKeyId, awsSecretAccessKey).build()).withModules(modules).buildContext();
}
public static RestContext<SQSAsyncClient, SQSClient> createContext(String awsAccessKeyId,
String awsSecretAccessKey, Module... modules) {
return new SQSContextBuilder(new SQSPropertiesBuilder(awsAccessKeyId, awsSecretAccessKey)
.build()).withModules(modules).buildContext();
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).build()).withModules(modules).buildContext();
}
public static RestContext<SQSAsyncClient, SQSClient> createContext(URI endpoint,
String awsAccessKeyId, String awsSecretAccessKey, Module... modules) {
return new SQSContextBuilder(new SQSPropertiesBuilder(awsAccessKeyId, awsSecretAccessKey)
.withEndpoint(endpoint).build()).withModules(modules).buildContext();
return new SQSContextBuilder("sqs", new SQSPropertiesBuilder(awsAccessKeyId,
awsSecretAccessKey).withEndpoint(endpoint).build()).withModules(modules)
.buildContext();
}
}

View File

@ -42,6 +42,9 @@ import com.google.inject.Provides;
* @author Adrian Cole
*/
public class SQSContextModule extends AbstractModule {
public SQSContextModule(String providerName) {
}
@Override
protected void configure() {
bind(DateAdapter.class).to(CDateAdapter.class);

View File

@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.aws.domain.Region;
/**
*
* @see <a href="http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryListQueues.html"

View File

@ -24,7 +24,6 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.sqs.SQS;
import com.google.common.base.Function;

View File

@ -25,7 +25,6 @@ import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.sqs.SQS;
import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.http.functions.ParseSax;

View File

@ -26,7 +26,6 @@ import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.sqs.SQS;
import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;

View File

@ -25,7 +25,6 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.sqs.SQS;
import org.jclouds.aws.sqs.domain.Queue;
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;

View File

@ -27,7 +27,6 @@ import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.sqs.domain.Queue;
import com.google.common.collect.ImmutableBiMap;

View File

@ -93,8 +93,9 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException {
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new EC2ContextBuilder(new EC2PropertiesBuilder(user, password).build())
.withModules(new Log4JLoggingModule(), new JschSshClientModule()).buildInjector();
Injector injector = new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(user, password)
.build()).withModules(new Log4JLoggingModule(), new JschSshClientModule())
.buildInjector();
client = injector.getInstance(EC2Client.class);
sshFactory = injector.getInstance(SshClient.Factory.class);
runningTester = new RetryablePredicate<RunningInstance>(new InstanceStateRunning(client
@ -111,13 +112,12 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
securityGroupName = instancePrefix + "ingress";
try {
client.getSecurityGroupServices().deleteSecurityGroupInRegion(null,
securityGroupName);
client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName);
} catch (Exception e) {
}
client.getSecurityGroupServices().createSecurityGroupInRegion(null,
securityGroupName, securityGroupName);
client.getSecurityGroupServices().createSecurityGroupInRegion(null, securityGroupName,
securityGroupName);
for (int port : new int[] { 80, 443, 22 }) {
client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null,
securityGroupName, IpProtocol.TCP, port, port, "0.0.0.0/0");
@ -154,8 +154,13 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
try {
System.out.printf("%d: running instance%n", System.currentTimeMillis());
Reservation reservation = client.getInstanceServices().runInstancesInRegion(
null, null, // allow ec2 to chose an availability zone
Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow
// ec2
// to
// chose
// an
// availability
// zone
"ami-ccf615a5", // alestic ami allows auto-invoke of user data scripts
1, // minimum instances
1, // maximum instances
@ -185,11 +190,11 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
}
private void verifyInstanceProperties(String script) {
assertEquals(script, client.getInstanceServices().getUserDataForInstanceInRegion(
null, instanceId));
assertEquals(script, client.getInstanceServices().getUserDataForInstanceInRegion(null,
instanceId));
assertEquals(null, client.getInstanceServices().getRootDeviceNameForInstanceInRegion(
null, instanceId));
assertEquals(null, client.getInstanceServices().getRootDeviceNameForInstanceInRegion(null,
instanceId));
assert client.getInstanceServices().getRamdiskForInstanceInRegion(null, instanceId)
.startsWith("ari-");
@ -211,12 +216,12 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
}
private void setApiTerminationDisabledForInstanceInRegion() {
client.getInstanceServices().setApiTerminationDisabledForInstanceInRegion(null,
instanceId, true);
client.getInstanceServices().setApiTerminationDisabledForInstanceInRegion(null, instanceId,
true);
assertEquals(true, client.getInstanceServices().isApiTerminationDisabledForInstanceInRegion(
null, instanceId));
client.getInstanceServices().setApiTerminationDisabledForInstanceInRegion(null,
instanceId, false);
client.getInstanceServices().setApiTerminationDisabledForInstanceInRegion(null, instanceId,
false);
assertEquals(false, client.getInstanceServices().isApiTerminationDisabledForInstanceInRegion(
null, instanceId));
}
@ -243,10 +248,9 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
private void setRamdiskForInstanceInRegion() {
try {
String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(
null, instanceId);
client.getInstanceServices().setRamdiskForInstanceInRegion(null, instanceId,
ramdisk);
String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(null,
instanceId);
client.getInstanceServices().setRamdiskForInstanceInRegion(null, instanceId, ramdisk);
assert false : "shouldn't be allowed, as instance needs to be stopped";
} catch (AWSResponseException e) {
assertEquals("IncorrectInstanceState", e.getError().getCode());
@ -255,10 +259,9 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
private void setKernelForInstanceInRegion() {
try {
String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(
null, instanceId);
client.getInstanceServices().setKernelForInstanceInRegion(null, instanceId,
oldKernel);
String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(null,
instanceId);
client.getInstanceServices().setKernelForInstanceInRegion(null, instanceId, oldKernel);
assert false : "shouldn't be allowed, as instance needs to be stopped";
} catch (AWSResponseException e) {
assertEquals("IncorrectInstanceState", e.getError().getCode());
@ -267,8 +270,8 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
private void setInstanceTypeForInstanceInRegion() {
try {
client.getInstanceServices().setInstanceTypeForInstanceInRegion(null,
instanceId, InstanceType.C1_MEDIUM);
client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, instanceId,
InstanceType.C1_MEDIUM);
assert false : "shouldn't be allowed, as instance needs to be stopped";
} catch (AWSResponseException e) {
assertEquals("IncorrectInstanceState", e.getError().getCode());
@ -278,8 +281,8 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
private void setBlockDeviceMappingForInstanceInRegion() {
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
try {
client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null,
instanceId, blockDeviceMapping);
client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null, instanceId,
blockDeviceMapping);
assert false : "shouldn't be allowed, as instance needs to be ebs based-ami";
} catch (AWSResponseException e) {
assertEquals("InvalidParameterCombination", e.getError().getCode());
@ -288,8 +291,8 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
private void setInstanceInitiatedShutdownBehaviorForInstanceInRegion() {
try {
client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(
null, instanceId, InstanceInitiatedShutdownBehavior.STOP);
client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null,
instanceId, InstanceInitiatedShutdownBehavior.STOP);
assert false : "shouldn't be allowed, as instance needs to be ebs based-ami";
} catch (AWSResponseException e) {
assertEquals("UnsupportedInstanceAttribute", e.getError().getCode());
@ -328,8 +331,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
assertEquals(compare.getPublicIp(), address);
assert compare.getInstanceId() == null;
client.getElasticIPAddressServices().associateAddressInRegion(null, address,
instanceId);
client.getElasticIPAddressServices().associateAddressInRegion(null, address, instanceId);
compare = Iterables.getLast(client.getElasticIPAddressServices().describeAddressesInRegion(
null, address));
@ -390,8 +392,8 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
private RunningInstance getInstance(String instanceId) {
// search my account for the instance I just created
Set<Reservation> reservations = client.getInstanceServices().describeInstancesInRegion(
null, instanceId); // last parameter (ids) narrows the search
Set<Reservation> reservations = client.getInstanceServices().describeInstancesInRegion(null,
instanceId); // last parameter (ids) narrows the search
return Iterables.getOnlyElement(Iterables.getOnlyElement(reservations));
}
@ -439,8 +441,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest {
if (keyPair != null)
client.getKeyPairServices().deleteKeyPairInRegion(null, keyPair.getKeyName());
if (securityGroupName != null)
client.getSecurityGroupServices().deleteSecurityGroupInRegion(null,
securityGroupName);
client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName);
}
}

View File

@ -120,8 +120,9 @@ public class EBSBootEC2ClientLiveTest {
public void setupClient() {
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new EC2ContextBuilder(new EC2PropertiesBuilder(user, password).build())
.withModules(new Log4JLoggingModule(), new JschSshClientModule()).buildInjector();
Injector injector = new EC2ContextBuilder("ec2", new EC2PropertiesBuilder(user, password)
.build()).withModules(new Log4JLoggingModule(), new JschSshClientModule())
.buildInjector();
client = injector.getInstance(EC2Client.class);
sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
@ -157,13 +158,12 @@ public class EBSBootEC2ClientLiveTest {
securityGroupName = INSTANCE_PREFIX + "ingress";
try {
client.getSecurityGroupServices().deleteSecurityGroupInRegion(null,
securityGroupName);
client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName);
} catch (Exception e) {
}
client.getSecurityGroupServices().createSecurityGroupInRegion(null,
securityGroupName, securityGroupName);
client.getSecurityGroupServices().createSecurityGroupInRegion(null, securityGroupName,
securityGroupName);
client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null,
securityGroupName, IpProtocol.TCP, 80, 80, "0.0.0.0/0");
client.getSecurityGroupServices().authorizeSecurityGroupIngressInRegion(null,
@ -199,8 +199,13 @@ public class EBSBootEC2ClientLiveTest {
while (instance == null) {
try {
System.out.printf("%d: running instance%n", System.currentTimeMillis());
Reservation reservation = client.getInstanceServices().runInstancesInRegion(
null, null, // allow ec2 to chose an availability zone
Reservation reservation = client.getInstanceServices().runInstancesInRegion(null, null, // allow
// ec2
// to
// chose
// an
// availability
// zone
imageId, 1, // minimum instances
1, // maximum instances
withKeyName(keyPair.getKeyName())// key I created above
@ -422,37 +427,37 @@ public class EBSBootEC2ClientLiveTest {
}
private void setUserDataForInstanceInRegion() {
client.getInstanceServices().setUserDataForInstanceInRegion(null,
ebsInstance.getId(), "test".getBytes());
assertEquals("test", client.getInstanceServices().getUserDataForInstanceInRegion(
null, ebsInstance.getId()));
client.getInstanceServices().setUserDataForInstanceInRegion(null, ebsInstance.getId(),
"test".getBytes());
assertEquals("test", client.getInstanceServices().getUserDataForInstanceInRegion(null,
ebsInstance.getId()));
}
private void setRamdiskForInstanceInRegion() {
String ramdisk = client.getInstanceServices().getRamdiskForInstanceInRegion(null,
ebsInstance.getId());
client.getInstanceServices().setRamdiskForInstanceInRegion(null,
ebsInstance.getId(), ramdisk);
assertEquals(ramdisk, client.getInstanceServices().getRamdiskForInstanceInRegion(
null, ebsInstance.getId()));
client.getInstanceServices()
.setRamdiskForInstanceInRegion(null, ebsInstance.getId(), ramdisk);
assertEquals(ramdisk, client.getInstanceServices().getRamdiskForInstanceInRegion(null,
ebsInstance.getId()));
}
private void setKernelForInstanceInRegion() {
String oldKernel = client.getInstanceServices().getKernelForInstanceInRegion(null,
ebsInstance.getId());
client.getInstanceServices().setKernelForInstanceInRegion(null,
ebsInstance.getId(), oldKernel);
assertEquals(oldKernel, client.getInstanceServices().getKernelForInstanceInRegion(
null, ebsInstance.getId()));
client.getInstanceServices().setKernelForInstanceInRegion(null, ebsInstance.getId(),
oldKernel);
assertEquals(oldKernel, client.getInstanceServices().getKernelForInstanceInRegion(null,
ebsInstance.getId()));
}
private void setInstanceTypeForInstanceInRegion() {
client.getInstanceServices().setInstanceTypeForInstanceInRegion(null,
ebsInstance.getId(), InstanceType.C1_MEDIUM);
client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(),
InstanceType.C1_MEDIUM);
assertEquals(InstanceType.C1_MEDIUM, client.getInstanceServices()
.getInstanceTypeForInstanceInRegion(null, ebsInstance.getId()));
client.getInstanceServices().setInstanceTypeForInstanceInRegion(null,
ebsInstance.getId(), InstanceType.M1_SMALL);
client.getInstanceServices().setInstanceTypeForInstanceInRegion(null, ebsInstance.getId(),
InstanceType.M1_SMALL);
assertEquals(InstanceType.M1_SMALL, client.getInstanceServices()
.getInstanceTypeForInstanceInRegion(null, ebsInstance.getId()));
}
@ -461,22 +466,21 @@ public class EBSBootEC2ClientLiveTest {
String volumeId = ebsInstance.getEbsBlockDevices().get("/dev/sda1").getVolumeId();
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
blockDeviceMapping.addEbsBlockDevice
("/dev/sda1", new RunningInstance.EbsBlockDevice(volumeId, false));
blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice(
volumeId, false));
try {
client.getInstanceServices().setBlockDeviceMappingForInstanceInRegion(null,
ebsInstance.getId(), blockDeviceMapping);
Map<String, RunningInstance.EbsBlockDevice> devices = client
.getInstanceServices().getBlockDeviceMappingForInstanceInRegion(null,
ebsInstance.getId());
assertEquals(devices.size(), 1);
String deviceName = Iterables.getOnlyElement(devices.keySet());
RunningInstance.EbsBlockDevice device = Iterables.getOnlyElement(devices.values());
Map<String, RunningInstance.EbsBlockDevice> devices = client.getInstanceServices()
.getBlockDeviceMappingForInstanceInRegion(null, ebsInstance.getId());
assertEquals(devices.size(), 1);
String deviceName = Iterables.getOnlyElement(devices.keySet());
RunningInstance.EbsBlockDevice device = Iterables.getOnlyElement(devices.values());
assertEquals(device.getVolumeId(), volumeId);
assertEquals(deviceName, "/dev/sda1");
assertEquals(device.isDeleteOnTermination(), false);
assertEquals(device.getVolumeId(), volumeId);
assertEquals(deviceName, "/dev/sda1");
assertEquals(device.isDeleteOnTermination(), false);
System.out.println("OK: setBlockDeviceMappingForInstanceInRegion");
} catch (Exception e) {
@ -489,14 +493,14 @@ public class EBSBootEC2ClientLiveTest {
private void setInstanceInitiatedShutdownBehaviorForInstanceInRegion() {
try {
client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(
null, ebsInstance.getId(), InstanceInitiatedShutdownBehavior.STOP);
client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null,
ebsInstance.getId(), InstanceInitiatedShutdownBehavior.STOP);
assertEquals(InstanceInitiatedShutdownBehavior.STOP, client.getInstanceServices()
.getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null,
ebsInstance.getId()));
client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(
null, ebsInstance.getId(), InstanceInitiatedShutdownBehavior.TERMINATE);
client.getInstanceServices().setInstanceInitiatedShutdownBehaviorForInstanceInRegion(null,
ebsInstance.getId(), InstanceInitiatedShutdownBehavior.TERMINATE);
assertEquals(InstanceInitiatedShutdownBehavior.TERMINATE, client.getInstanceServices()
.getInstanceInitiatedShutdownBehaviorForInstanceInRegion(null,
@ -628,8 +632,7 @@ public class EBSBootEC2ClientLiveTest {
}
if (securityGroupName != null) {
try {
client.getSecurityGroupServices().deleteSecurityGroupInRegion(null,
securityGroupName);
client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.xml.MonitoringStateHandler;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;

View File

@ -47,14 +47,14 @@ import com.google.inject.TypeLiteral;
public class AzureBlobContextBuilder extends
BlobStoreContextBuilder<AzureBlobAsyncClient, AzureBlobClient> {
public AzureBlobContextBuilder(Properties props) {
super(new TypeLiteral<AzureBlobAsyncClient>() {
public AzureBlobContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<AzureBlobAsyncClient>() {
}, new TypeLiteral<AzureBlobClient>() {
}, props);
}
@Override
protected void addContextModule(List<Module> modules) {
protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new AzureBlobStoreContextModule());
}

View File

@ -41,18 +41,19 @@ import com.google.inject.Module;
*/
public class AzureBlobContextFactory {
public static BlobStoreContext createContext(Properties properties, Module... modules) {
return new AzureBlobContextBuilder(new AzureBlobPropertiesBuilder(properties).build())
.withModules(modules).buildBlobStoreContext();
return new AzureBlobContextBuilder("azureblob", new AzureBlobPropertiesBuilder(properties)
.build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(String user, String encodedKey, Module... modules) {
return new AzureBlobContextBuilder(new AzureBlobPropertiesBuilder(user, encodedKey)
.build()).withModules(modules).buildBlobStoreContext();
return new AzureBlobContextBuilder("azureblob", new AzureBlobPropertiesBuilder(user,
encodedKey).build()).withModules(modules).buildBlobStoreContext();
}
public static BlobStoreContext createContext(URI endpoint, String user, String encodedKey,
Module... modules) {
return new AzureBlobContextBuilder(new AzureBlobPropertiesBuilder(user, encodedKey)
.withEndpoint(endpoint).build()).withModules(modules).buildBlobStoreContext();
return new AzureBlobContextBuilder("azureblob", new AzureBlobPropertiesBuilder(user,
encodedKey).withEndpoint(endpoint).build()).withModules(modules)
.buildBlobStoreContext();
}
}

View File

@ -67,7 +67,7 @@ public class AzureBlobStoreContextModule extends AzureBlobContextModule {
@Provides
@Singleton
Location getLocation() {
return new LocationImpl(LocationScope.ZONE, "UNKNOWN", "TODO", null);
return new LocationImpl(LocationScope.PROVIDER, "azureblob", "azureblob", null);
}
@Provides

View File

@ -47,15 +47,15 @@ import com.google.inject.TypeLiteral;
public class AzureQueueContextBuilder extends
RestContextBuilder<AzureQueueAsyncClient, AzureQueueClient> {
public AzureQueueContextBuilder(Properties properties) {
super(new TypeLiteral<AzureQueueAsyncClient>() {
public AzureQueueContextBuilder(String providerName, Properties properties) {
super(providerName, new TypeLiteral<AzureQueueAsyncClient>() {
}, new TypeLiteral<AzureQueueClient>() {
}, properties);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new AzureQueueContextModule());
protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new AzureQueueContextModule(providerName));
}
@Override

View File

@ -43,25 +43,25 @@ public class AzureQueueContextFactory {
public static RestContext<AzureQueueAsyncClient, AzureQueueClient> createContext(
Properties properties, Module... modules) {
return new AzureQueueContextBuilder(new AzureQueuePropertiesBuilder(properties).build())
.withModules(modules).buildContext();
return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(properties)
.build()).withModules(modules).buildContext();
}
public static RestContext<AzureQueueAsyncClient, AzureQueueClient> createContext(
Properties properties, String account, String encodedKey, Module... modules) {
return new AzureQueueContextBuilder(new AzureQueuePropertiesBuilder(properties)
return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(properties)
.withCredentials(account, encodedKey).build()).withModules(modules).buildContext();
}
public static RestContext<AzureQueueAsyncClient, AzureQueueClient> createContext(String account,
String encodedKey, Module... modules) {
return new AzureQueueContextBuilder(new AzureQueuePropertiesBuilder(account, encodedKey)
.build()).withModules(modules).buildContext();
return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(account,
encodedKey).build()).withModules(modules).buildContext();
}
public static RestContext<AzureQueueAsyncClient, AzureQueueClient> createContext(URI endpoint,
String account, String encodedKey, Module... modules) {
return new AzureQueueContextBuilder(new AzureQueuePropertiesBuilder(account, encodedKey)
.withEndpoint(endpoint).build()).withModules(modules).buildContext();
return new AzureQueueContextBuilder("azurequeue", new AzureQueuePropertiesBuilder(account,
encodedKey).withEndpoint(endpoint).build()).withModules(modules).buildContext();
}
}

View File

@ -38,6 +38,9 @@ import com.google.inject.Provides;
@RequiresHttp
public class AzureQueueContextModule extends AbstractModule {
public AzureQueueContextModule(String providerName) {
}
@Override
protected void configure() {
}

View File

@ -53,7 +53,7 @@ public class AzureQueueClientLiveTest {
public void setupClient() {
account = System.getProperty("jclouds.test.user");
String key = System.getProperty("jclouds.test.key");
Injector injector = new AzureQueueContextBuilder(
Injector injector = new AzureQueueContextBuilder("azurequeue",
new AzureQueuePropertiesBuilder(account, key).build()).withModules(
new Log4JLoggingModule()).buildInjector();
connection = injector.getInstance(AzureQueueClient.class);
@ -104,13 +104,13 @@ public class AzureQueueClientLiveTest {
assertEquals(privateQueue, response.getPrefix());
assertEquals(1, response.getMaxResults());
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateQueue" })
public void testPutMessage() throws Exception {
connection.putMessage(privateQueue,"holycow",PutMessageOptions.Builder.withTTL(4));
connection.putMessage(privateQueue, "holycow", PutMessageOptions.Builder.withTTL(4));
// TODO loop for up to 30 seconds checking if they are really gone
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testPutMessage" })
public void testDeleteQueue() throws Exception {
connection.clearMessages(privateQueue);

View File

@ -135,7 +135,7 @@ Options can also be specified for extension modules
"Retrieve the available container locations for the blobstore context."
([] (locations *blobstore*))
([#^BlobStore blobstore]
(seq-from-immutable-set (.getLocations blobstore))))
(seq-from-immutable-set (.getAssignableLocations blobstore))))
(defn create-container
"Create a container."

View File

@ -49,9 +49,9 @@ public interface AsyncBlobStore {
Blob newBlob(String name);
/**
* @see BlobStore#getLocations
* @see BlobStore#getAssignableLocations
*/
ListenableFuture<? extends Map<String, ? extends Location>> getLocations();
ListenableFuture<? extends Map<String, ? extends Location>> getAssignableLocations();
/**
* @see BlobStore#list

View File

@ -55,7 +55,7 @@ public interface BlobStore {
* similar to a datacenter. If a location has a parent, that implies it is within that location.
* For example a location can be a rack, whose parent is likely to be a zone.
*/
Map<String, ? extends Location> getLocations();
Map<String, ? extends Location> getAssignableLocations();
/**
* Lists all root-level resources available to the account.

View File

@ -35,13 +35,13 @@ public abstract class BlobStoreContextBuilder<A, S> extends RestContextBuilder<A
return (BlobStoreContextBuilder<A, S>) super.withModules(modules);
}
public BlobStoreContextBuilder(TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType) {
this(asyncClientType, syncClientType, new Properties());
public BlobStoreContextBuilder(String providerName,TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType) {
this(providerName, asyncClientType, syncClientType, new Properties());
}
public BlobStoreContextBuilder(TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType,
public BlobStoreContextBuilder(String providerName,TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType,
Properties properties) {
super(asyncClientType, syncClientType, properties);
super(providerName, asyncClientType, syncClientType, properties);
}

View File

@ -37,18 +37,18 @@ public class TransientBlobStoreContextBuilder extends
* This is only to have the same syntax.
*
*/
public TransientBlobStoreContextBuilder(Properties props) {
public TransientBlobStoreContextBuilder(String providerName, Properties props) {
this();
}
public TransientBlobStoreContextBuilder() {
super(new TypeLiteral<AsyncBlobStore>() {
super("transient", new TypeLiteral<AsyncBlobStore>() {
}, new TypeLiteral<BlobStore>() {
});
}
@Override
public void addContextModule(List<Module> modules) {
public void addContextModule(String providerName, List<Module> modules) {
modules.add(new TransientBlobStoreContextModule());
}

View File

@ -54,7 +54,7 @@ public class TransientBlobStoreContextModule extends AbstractModule {
@Provides
@Singleton
Location provideDefaultLocation() {
return new LocationImpl(LocationScope.ZONE, "default", "description", null);
return new LocationImpl(LocationScope.PROVIDER, "transient", "transient", null);
}
@Provides

View File

@ -271,7 +271,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
}
@Override
public ListenableFuture<? extends Map<String, ? extends Location>> getLocations() {
public ListenableFuture<? extends Map<String, ? extends Location>> getAssignableLocations() {
return immediateFuture(locations);
}

View File

@ -213,7 +213,7 @@ public abstract class BaseBlobStore implements BlobStore {
}
@Override
public Map<String, ? extends Location> getLocations() {
public Map<String, ? extends Location> getAssignableLocations() {
return locations;
}

View File

@ -18,12 +18,16 @@
*/
package org.jclouds.blobstore.integration.internal;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import java.util.Map.Entry;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
@ -43,11 +47,13 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
@Test(groups = { "integration", "live" })
public void testAllLocations() throws InterruptedException {
for (final Location location : context.getBlobStore().getLocations().values()) {
for (final Location location : context.getBlobStore().getAssignableLocations().values()) {
final String containerName = getScratchContainerName();
try {
System.err.printf(" >> creating container in location %s%n", location);
context.getBlobStore().createContainerInLocation(location, containerName);
System.err.printf(" << call complete.. checking%n");
assertConsistencyAware(new Runnable() {
@Override
@ -68,4 +74,44 @@ public class BaseServiceIntegrationTest extends BaseBlobStoreIntegrationTest {
}
}
}
@Test(groups = { "integration", "live" })
public void testGetAssignableLocations() throws Exception {
for (Entry<String, ? extends Location> location : context.getBlobStore()
.getAssignableLocations().entrySet()) {
System.err.printf("location %s%n", location.getValue());
assertEquals(location.getKey(), location.getValue().getId());
assert location.getValue().getId() != null : location;
assert location.getValue() != location.getValue().getParent() : location;
assert location.getValue().getScope() != null : location;
switch (location.getValue().getScope()) {
case PROVIDER:
assertProvider(location.getValue());
break;
case REGION:
assertProvider(location.getValue().getParent());
break;
case ZONE:
Location provider = location.getValue().getParent().getParent();
// zone can be a direct descendant of provider
if (provider == null)
provider = location.getValue().getParent();
assertProvider(provider);
break;
case HOST:
Location provider2 = location.getValue().getParent().getParent().getParent();
// zone can be a direct descendant of provider
if (provider2 == null)
provider2 = location.getValue().getParent().getParent();
assertProvider(provider2);
break;
}
}
}
public void assertProvider(Location provider) {
assertEquals(provider.getScope(), LocationScope.PROVIDER);
assertEquals(provider.getParent(), null);
}
}

View File

@ -117,7 +117,7 @@ See http://code.google.com/p/jclouds for details."
"Retrieve the available compute locations for the compute context."
([] (locations *compute*))
([#^ComputeService compute]
(seq-from-immutable-set (.getLocations compute))))
(seq-from-immutable-set (.getAssignableLocations compute))))
(defn nodes-with-tag
[#^String tag #^ComputeService compute]

View File

@ -90,7 +90,7 @@ public interface ComputeService {
* similar to a datacenter. If a location has a parent, that implies it is within that location.
* For example a location can be a rack, whose parent is likely to be a zone.
*/
Map<String, ? extends Location> getLocations();
Map<String, ? extends Location> getAssignableLocations();
/**
*

View File

@ -37,13 +37,14 @@ import com.google.inject.util.Types;
*/
public abstract class ComputeServiceContextBuilder<A, S> extends RestContextBuilder<A, S> {
public ComputeServiceContextBuilder(TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType) {
this(asyncClientType, syncClientType, new Properties());
public ComputeServiceContextBuilder(String providerName, TypeLiteral<A> asyncClientType,
TypeLiteral<S> syncClientType) {
this(providerName, asyncClientType, syncClientType, new Properties());
}
public ComputeServiceContextBuilder(TypeLiteral<A> asyncClientType,
public ComputeServiceContextBuilder(String providerName, TypeLiteral<A> asyncClientType,
TypeLiteral<S> syncClientType, Properties properties) {
super(asyncClientType, syncClientType, properties);
super(providerName, asyncClientType, syncClientType, properties);
}

View File

@ -33,7 +33,11 @@ import com.google.common.base.CaseFormat;
* @author Adrian Cole
*/
public enum OsFamily {
CENTOS, RHEL, FEDORA, DEBIAN, UBUNTU, TTYLINUX, ARCH, GENTOO, WINDOWS;
CENTOS,
/**
* Oracle Enterprise Linux
*/
OEL, RHEL, FEDORA, DEBIAN, UBUNTU, TTYLINUX, ARCH, GENTOO, WINDOWS;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
}

View File

@ -281,7 +281,7 @@ public class BaseComputeService implements ComputeService {
}
@Override
public Map<String, ? extends Location> getLocations() {
public Map<String, ? extends Location> getAssignableLocations() {
return locations.get();
}

View File

@ -0,0 +1,23 @@
package org.jclouds.compute.strategy.impl;
import java.util.regex.Pattern;
import javax.inject.Singleton;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
/**
* @author Adrian Cole
*/
@Singleton
public class ReturnNullCredentials implements PopulateDefaultLoginCredentialsForImageStrategy {
public static final Pattern USER_PASSWORD_PATTERN = Pattern
.compile(".*[Uu]sername: ([a-z]+) ?.*\n[Pp]assword: ([^ ]+) ?\n.*");
@Override
public Credentials execute(Object resourceToAuthenticate) {
return null;
}
}

View File

@ -288,6 +288,15 @@ public class ComputeUtils {
returnVal = runScriptAsDefaultUser();
runScriptNotRunning.apply(new CommandUsingClient("./" + scriptName + " status", ssh));
logger.debug("<< complete(%d)", returnVal.getExitCode());
if (logger.isDebugEnabled() || returnVal.getExitCode() != 0) {
logger.debug("<< stdout from %s as %s@%s\n%s", scriptName,
node.getCredentials().account, Iterables.get(node.getPublicAddresses(), 0)
.getHostAddress(), ssh.exec("./" + scriptName + " tail").getOutput());
logger.debug("<< stderr from %s as %s@%s\n%s", scriptName,
node.getCredentials().account, Iterables.get(node.getPublicAddresses(), 0)
.getHostAddress(), ssh.exec("./" + scriptName + " tailerr")
.getOutput());
}
return returnVal;
}

View File

@ -50,6 +50,7 @@ import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
@ -200,7 +201,7 @@ public abstract class BaseComputeServiceLiveTest {
void assertLocationSameOrChild(Location test, Location expected) {
if (!test.equals(expected)) {
assertEquals(test.getParent(), expected.getId());
assertEquals(test.getParent().getId(), expected.getId());
} else {
assertEquals(test, expected);
}
@ -248,11 +249,19 @@ public abstract class BaseComputeServiceLiveTest {
private Map<String, ExecResponse> runScriptWithCreds(String tag, OsFamily osFamily,
Credentials creds) {
return client.runScriptOnNodesWithTag(tag, buildScript(osFamily).getBytes(),
RunScriptOptions.Builder.overrideCredentialsWith(creds));
try {
return client.runScriptOnNodesWithTag(tag, buildScript(osFamily).getBytes(),
RunScriptOptions.Builder.overrideCredentialsWith(creds));
} catch (SshException e) {
if (Throwables.getRootCause(e).getMessage().contains("Auth fail")) {
System.err.printf("bad credentials: %s:%s for %s", creds.account, creds.key, client
.getNodesWithTag(tag));
}
throw e;
}
}
private void checkNodes(Iterable<? extends NodeMetadata> nodes, String tag) throws IOException {
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String tag) throws IOException {
for (NodeMetadata node : nodes) {
assertNotNull(node.getId());
assertNotNull(node.getTag());
@ -381,15 +390,44 @@ public abstract class BaseComputeServiceLiveTest {
}
}
public void testListLocations() throws Exception {
for (Entry<String, ? extends Location> image : client.getLocations().entrySet()) {
assertEquals(image.getKey(), image.getValue().getId());
assert image.getValue().getId() != null : image;
assert image.getValue().getId() != image.getValue().getParent() : image;
assert image.getValue().getScope() != null : image;
@Test(groups = { "integration", "live" })
public void testGetAssignableLocations() throws Exception {
for (Entry<String, ? extends Location> location : client.getAssignableLocations().entrySet()) {
System.err.printf("location %s%n", location.getValue());
assertEquals(location.getKey(), location.getValue().getId());
assert location.getValue().getId() != null : location;
assert location.getValue() != location.getValue().getParent() : location;
assert location.getValue().getScope() != null : location;
switch (location.getValue().getScope()) {
case PROVIDER:
assertProvider(location.getValue());
break;
case REGION:
assertProvider(location.getValue().getParent());
break;
case ZONE:
Location provider = location.getValue().getParent().getParent();
// zone can be a direct descendant of provider
if (provider == null)
provider = location.getValue().getParent();
assertProvider(provider);
break;
case HOST:
Location provider2 = location.getValue().getParent().getParent().getParent();
// zone can be a direct descendant of provider
if (provider2 == null)
provider2 = location.getValue().getParent().getParent();
assertProvider(provider2);
break;
}
}
}
private void assertProvider(Location provider) {
assertEquals(provider.getScope(), LocationScope.PROVIDER);
assertEquals(provider.getParent(), null);
}
public void testListSizes() throws Exception {
for (Entry<String, ? extends Size> size : client.getSizes().entrySet()) {
assertEquals(size.getKey(), size.getValue().getId());

View File

@ -48,8 +48,8 @@ public interface Location {
String getDescription();
/**
* The Id of the parent, or null, if top-level
* The parent, or null, if top-level
*/
String getParent();
Location getParent();
}

View File

@ -25,6 +25,6 @@ package org.jclouds.domain;
*/
public enum LocationScope {
REGION, ZONE, RACK, HOST;
PROVIDER, REGION, ZONE, RACK, HOST;
}

View File

@ -40,9 +40,9 @@ public class LocationImpl implements Location, Serializable {
private final LocationScope scope;
private final String id;
private final String description;
private final String parent;
private final Location parent;
public LocationImpl(LocationScope scope, String id, String description, @Nullable String parent) {
public LocationImpl(LocationScope scope, String id, String description, @Nullable Location parent) {
this.scope = checkNotNull(scope, "scope");
this.id = checkNotNull(id, "id");
this.description = checkNotNull(description, "description");
@ -61,7 +61,7 @@ public class LocationImpl implements Location, Serializable {
return description;
}
public String getParent() {
public Location getParent() {
return parent;
}
@ -111,7 +111,7 @@ public class LocationImpl implements Location, Serializable {
@Override
public String toString() {
return "[id=" + id + ", scope=" + scope + ", description=" + description + ", parent="
+ parent + "]";
+ ((parent == null) ? null : parent.getId()) + "]";
}
}

View File

@ -64,13 +64,15 @@ import com.google.inject.util.Types;
*/
public abstract class RestContextBuilder<A, S> {
protected final String providerName;
protected final Properties properties;
protected final List<Module> modules = new ArrayList<Module>(3);
protected final TypeLiteral<A> asyncClientType;
protected final TypeLiteral<S> syncClientType;
protected RestContextBuilder(TypeLiteral<A> asyncClientType, TypeLiteral<S> syncClientType,
Properties properties) {
protected RestContextBuilder(String providerName, TypeLiteral<A> asyncClientType,
TypeLiteral<S> syncClientType, Properties properties) {
this.providerName = providerName;
this.asyncClientType = asyncClientType;
this.syncClientType = syncClientType;
this.properties = properties;
@ -83,7 +85,7 @@ public abstract class RestContextBuilder<A, S> {
public Injector buildInjector() {
addContextModule(modules);
addContextModule(providerName, modules);
addClientModuleIfNotPresent(modules);
addLoggingModuleIfNotPresent(modules);
addHttpModuleIfNeededAndNotPresent(modules);
@ -124,7 +126,7 @@ public abstract class RestContextBuilder<A, S> {
}
@VisibleForTesting
protected abstract void addContextModule(List<Module> modules);
protected abstract void addContextModule(String providerName, List<Module> modules);
@VisibleForTesting
protected void ifHttpConfigureRestOtherwiseGuiceClientFactory(final List<Module> modules) {

View File

@ -98,46 +98,46 @@ public abstract class RestContextFactory<T, B extends RestContextBuilder<?, ?>>
this.properties = properties;
}
public T createContext(URI blobStore, Iterable<? extends Module> modules, Properties overrides) {
return createContext(blobStore, Credentials.parse(blobStore), modules, overrides);
public T createContext(URI contextUri, Iterable<? extends Module> modules, Properties overrides) {
return createContext(contextUri, Credentials.parse(contextUri), modules, overrides);
}
public T createContext(URI blobStore) {
return createContext(blobStore, ImmutableSet.<Module> of(), NO_PROPERTIES);
public T createContext(URI contextUri) {
return createContext(contextUri, ImmutableSet.<Module> of(), NO_PROPERTIES);
}
public T createContext(URI blobStore, Credentials creds, Iterable<? extends Module> modules,
public T createContext(URI contextUri, Credentials creds, Iterable<? extends Module> modules,
Properties overrides) {
return createContext(checkNotNull(blobStore.getHost(), "host"), checkNotNull(creds.account,
return createContext(checkNotNull(contextUri.getHost(), "host"), checkNotNull(creds.account,
"account"), checkNotNull(creds.key, "key"), checkNotNull(modules, "modules"),
checkNotNull(overrides, "overrides"));
}
public T createContext(URI blobStore, Credentials creds) {
return createContext(blobStore, creds, ImmutableSet.<Module> of(), NO_PROPERTIES);
public T createContext(URI contextUri, Credentials creds) {
return createContext(contextUri, creds, ImmutableSet.<Module> of(), NO_PROPERTIES);
}
public T createContext(String hint, String account, String key) {
return createContext(hint, account, key, ImmutableSet.<Module> of(), NO_PROPERTIES);
public T createContext(String provider, String account, String key) {
return createContext(provider, account, key, ImmutableSet.<Module> of(), NO_PROPERTIES);
}
public T createContext(String hint, Properties overrides) {
return createContext(hint, null, null, ImmutableSet.<Module> of(), overrides);
public T createContext(String provider, Properties overrides) {
return createContext(provider, null, null, ImmutableSet.<Module> of(), overrides);
}
public T createContext(String hint, Iterable<? extends Module> modules, Properties overrides) {
return createContext(hint, null, null, modules, overrides);
public T createContext(String provider, Iterable<? extends Module> modules, Properties overrides) {
return createContext(provider, null, null, modules, overrides);
}
public T createContext(String hint, @Nullable String account, @Nullable String key,
public T createContext(String provider, @Nullable String account, @Nullable String key,
Iterable<? extends Module> modules) {
return createContext(hint, account, key, modules, new Properties());
return createContext(provider, account, key, modules, new Properties());
}
/**
* Creates a new remote context.
*
* @param hint
* @param provider
* @param account
* nullable, if credentials are present in the overrides
* @param key
@ -150,20 +150,20 @@ public abstract class RestContextFactory<T, B extends RestContextBuilder<?, ?>>
* @return initialized context ready for use
*/
@SuppressWarnings("unchecked")
public T createContext(String hint, @Nullable String account, @Nullable String key,
public T createContext(String provider, @Nullable String account, @Nullable String key,
Iterable<? extends Module> modules, Properties overrides) {
checkNotNull(hint, "hint");
checkNotNull(provider, "provider");
checkNotNull(modules, "modules");
checkNotNull(overrides, "overrides");
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
String propertiesBuilderKey = String.format("%s.propertiesbuilder", provider);
String propertiesBuilderClassName = checkNotNull(
properties.getProperty(propertiesBuilderKey), hint + " service not supported");
properties.getProperty(propertiesBuilderKey), provider + " service not supported");
String contextBuilderKey = String.format("%s.contextbuilder", hint);
String contextBuilderKey = String.format("%s.contextbuilder", provider);
String contextBuilderClassName = checkNotNull(properties.getProperty(contextBuilderKey),
contextBuilderKey);
String endpointKey = String.format("%s.endpoint", hint);
String endpointKey = String.format("%s.endpoint", provider);
String endpoint = properties.getProperty(endpointKey);
try {
Class<PropertiesBuilder> propertiesBuilderClass = (Class<PropertiesBuilder>) Class
@ -175,8 +175,9 @@ public abstract class RestContextFactory<T, B extends RestContextBuilder<?, ?>>
builder.withCredentials(account, key);
if (endpoint != null)
builder.withEndpoint(URI.create(endpoint));
B contextBuilder = (B) contextBuilderClass.getConstructor(Properties.class).newInstance(
builder.build()).withModules(Iterables.toArray(modules, Module.class));
B contextBuilder = (B) contextBuilderClass.getConstructor(String.class, Properties.class)
.newInstance(provider, builder.build()).withModules(
Iterables.toArray(modules, Module.class));
return build(contextBuilder);
} catch (ProvisionException e) {
Throwable throwable = Utils.firstRootCauseOrOriginalException(e);

View File

@ -74,15 +74,15 @@ public abstract class BaseJettyTest {
RestContextBuilder<IntegrationTestAsyncClient, IntegrationTestClient> {
private final int testPort;
public IntegrationContextBuilder(Properties properties, int testPort) {
super(new TypeLiteral<IntegrationTestAsyncClient>() {
public IntegrationContextBuilder(String providerName, Properties properties, int testPort) {
super(providerName, new TypeLiteral<IntegrationTestAsyncClient>() {
}, new TypeLiteral<IntegrationTestClient>() {
}, properties);
this.testPort = testPort;
}
@Override
protected void addContextModule(List<Module> modules) {
protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new JettyContextModule(testPort));
}
@ -190,19 +190,20 @@ public abstract class BaseJettyTest {
if (failEveryTenRequests(request, response))
return;
if (request.getContentLength() > 0) {
if(request.getHeader("Content-MD5") != null) {
String expectedMd5 = request.getHeader("Content-MD5");
String realMd5FromRequest = Base64.encodeBytes(new JCEEncryptionService().md5(request.getInputStream()));
boolean matched = expectedMd5.equals(realMd5FromRequest);
if(matched) {
response.setContentType("text/xml");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("created");
}
if (request.getHeader("Content-MD5") != null) {
String expectedMd5 = request.getHeader("Content-MD5");
String realMd5FromRequest = Base64.encodeBytes(new JCEEncryptionService()
.md5(request.getInputStream()));
boolean matched = expectedMd5.equals(realMd5FromRequest);
if (matched) {
response.setContentType("text/xml");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("created");
}
} else {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(
Utils.toStringAndClose(request.getInputStream()) + "POST");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(
Utils.toStringAndClose(request.getInputStream()) + "POST");
}
} else {
handleAction(request, response);
@ -214,8 +215,9 @@ public abstract class BaseJettyTest {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("test");
} else if (request.getMethod().equals("HEAD")) {
/* NOTE: by HTML specification, HEAD response MUST NOT
include a body */
/*
* NOTE: by HTML specification, HEAD response MUST NOT include a body
*/
response.setContentType("text/xml");
response.setStatus(HttpServletResponse.SC_OK);
} else {
@ -245,26 +247,28 @@ public abstract class BaseJettyTest {
}
} else if (request.getMethod().equals("POST")) {
if (request.getContentLength() > 0) {
if(request.getHeader("Content-MD5") != null) {
String expectedMd5 = request.getHeader("Content-MD5");
String realMd5FromRequest = Base64.encodeBytes(new JCEEncryptionService().md5(request.getInputStream()));
boolean matched = expectedMd5.equals(realMd5FromRequest);
if(matched) {
response.setContentType("text/xml");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("created");
}
} else {
if (request.getHeader("Content-MD5") != null) {
String expectedMd5 = request.getHeader("Content-MD5");
String realMd5FromRequest = Base64.encodeBytes(new JCEEncryptionService()
.md5(request.getInputStream()));
boolean matched = expectedMd5.equals(realMd5FromRequest);
if (matched) {
response.setContentType("text/xml");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(
Utils.toStringAndClose(request.getInputStream()) + "POST");
response.getWriter().println("created");
}
} else {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(
Utils.toStringAndClose(request.getInputStream()) + "POST");
}
} else {
handleAction(request, response);
}
} else if (request.getMethod().equals("HEAD")) {
/* NOTE: by HTML specification, HEAD response MUST NOT
include a body */
/*
* NOTE: by HTML specification, HEAD response MUST NOT include a body
*/
response.setContentType("text/xml");
response.setStatus(HttpServletResponse.SC_OK);
} else {
@ -318,7 +322,8 @@ public abstract class BaseJettyTest {
public static RestContextBuilder<IntegrationTestAsyncClient, IntegrationTestClient> newBuilder(
final int testPort, final Properties properties, Module connectionModule) {
return new IntegrationContextBuilder(properties, testPort).withModules(connectionModule);
return new IntegrationContextBuilder("integration-test", properties, testPort)
.withModules(connectionModule);
}
@AfterTest

View File

@ -87,7 +87,7 @@ public class RestContextBuilderTest {
class TestRestContextBuilder extends RestContextBuilder<String, String> {
protected TestRestContextBuilder(Properties properties) {
super(new TypeLiteral<String>() {
super("test", new TypeLiteral<String>() {
}, new TypeLiteral<String>() {
}, properties);
}
@ -98,7 +98,7 @@ public class RestContextBuilderTest {
}
@Override
protected void addContextModule(List<Module> modules) {
protected void addContextModule(String providerName, List<Module> modules) {
// ignored as we add it directly above without use of injection
}

View File

@ -44,8 +44,8 @@ import com.google.inject.TypeLiteral;
public class GoGridContextBuilder extends
ComputeServiceContextBuilder<GoGridAsyncClient, GoGridClient> {
public GoGridContextBuilder(Properties props) {
super(new TypeLiteral<GoGridAsyncClient>() {
public GoGridContextBuilder(String providerName, Properties props) {
super(providerName, new TypeLiteral<GoGridAsyncClient>() {
}, new TypeLiteral<GoGridClient>() {
}, props);
}
@ -55,8 +55,8 @@ public class GoGridContextBuilder extends
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new GoGridComputeServiceContextModule());
protected void addContextModule(String providerName, List<Module> modules) {
modules.add(new GoGridComputeServiceContextModule(providerName));
}
@Override

View File

@ -52,14 +52,15 @@ import com.google.inject.Module;
*/
public class GoGridContextFactory {
public static RestContext<GoGridAsyncClient, GoGridClient> createContext(String user, String password,
Module... modules) {
return new GoGridContextBuilder(new GoGridPropertiesBuilder(user, password).build())
public static RestContext<GoGridAsyncClient, GoGridClient> createContext(String user,
String password, Module... modules) {
return new GoGridContextBuilder("gogrid", new GoGridPropertiesBuilder(user, password).build())
.withModules(modules).buildContext();
}
public static RestContext<GoGridAsyncClient, GoGridClient> createContext(Properties properties, Module... modules) {
return new GoGridContextBuilder(new GoGridPropertiesBuilder(properties).build())
public static RestContext<GoGridAsyncClient, GoGridClient> createContext(Properties properties,
Module... modules) {
return new GoGridContextBuilder("gogrid", new GoGridPropertiesBuilder(properties).build())
.withModules(modules).buildContext();
}

View File

@ -91,6 +91,11 @@ import com.google.inject.TypeLiteral;
* @author Oleksiy Yarmula
*/
public class GoGridComputeServiceContextModule extends GoGridContextModule {
private final String providerName;
public GoGridComputeServiceContextModule(String providerName) {
this.providerName = providerName;
}
@Override
protected void configure() {
@ -284,8 +289,9 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
Function<ComputeMetadata, String> indexer) {
final Set<Location> locations = Sets.newHashSet();
holder.logger.debug(">> providing locations");
locations
.add(new LocationImpl(LocationScope.ZONE, "SANFRANCISCO", "San Francisco, CA", null));
Location parent = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
locations.add(new LocationImpl(LocationScope.ZONE, "SANFRANCISCO", "San Francisco, CA",
parent));
holder.logger.debug("<< locations(%d)", locations.size());
return Maps.uniqueIndex(locations, new Function<Location, String>() {

Some files were not shown because too many files have changed in this diff Show More