mirror of https://github.com/apache/jclouds.git
Issue 613:Automatically parse cluster ami list
This commit is contained in:
parent
3c200645bc
commit
6e2cf793b2
|
@ -18,7 +18,9 @@
|
|||
*/
|
||||
package org.jclouds.ec2.compute.config;
|
||||
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -33,6 +35,7 @@ import org.jclouds.ec2.compute.domain.RegionAndName;
|
|||
import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
|
@ -67,4 +70,14 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
|
|||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named(PROPERTY_EC2_AMI_OWNERS)
|
||||
String[] amiOwners(@Named(PROPERTY_EC2_AMI_OWNERS) String amiOwners) {
|
||||
if (amiOwners.trim().equals(""))
|
||||
return new String[] {};
|
||||
return toArray(Splitter.on(',').split(amiOwners), String.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.ec2.compute.config;
|
||||
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
|
@ -56,7 +54,6 @@ import org.jclouds.rest.RestContext;
|
|||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.MapMaker;
|
||||
|
@ -137,16 +134,7 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule {
|
|||
// return new MapMaker().makeComputingMap(in);
|
||||
return newLinkedHashMap();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named(PROPERTY_EC2_AMI_OWNERS)
|
||||
String[] amiOwners(@Named(PROPERTY_EC2_AMI_OWNERS) String amiOwners) {
|
||||
if (amiOwners.trim().equals(""))
|
||||
return new String[] {};
|
||||
return toArray(Splitter.on(',').split(amiOwners), String.class);
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Map<RegionAndName, Image> provideImageMap(Function<RegionAndName, Image> regionAndIdToImage) {
|
||||
|
|
|
@ -18,14 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.ec2.compute.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static org.jclouds.compute.predicates.ImagePredicates.any;
|
||||
import static org.jclouds.compute.predicates.ImagePredicates.idIn;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -146,9 +144,8 @@ public class EC2HardwareBuilder extends HardwareBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder supportsImageIds(String... ids) {
|
||||
checkArgument(ids != null && ids.length > 0, "ids must be specified");
|
||||
this.imageIds = idIn(Arrays.asList(ids));
|
||||
public EC2HardwareBuilder supportsImageIds(Iterable<String> ids) {
|
||||
this.imageIds = idIn(ids);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ import com.google.common.base.Function;
|
|||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
/**
|
||||
|
@ -103,8 +104,8 @@ public class RegionAndNameToImageSupplier implements Supplier<Map<RegionAndName,
|
|||
Iterable<Entry<String, DescribeImagesOptions>> queries = getDescribeQueriesForOwnersInRegions(regions,
|
||||
amiOwners);
|
||||
|
||||
Iterable<? extends Image> parsedImages = filter(transform(describer.apply(queries), parser), Predicates
|
||||
.notNull());
|
||||
Iterable<? extends Image> parsedImages = ImmutableSet.copyOf(filter(transform(describer.apply(queries), parser), Predicates
|
||||
.notNull()));
|
||||
|
||||
images.putAll(uniqueIndex(parsedImages, new Function<Image, RegionAndName>() {
|
||||
|
||||
|
@ -129,8 +130,8 @@ public class RegionAndNameToImageSupplier implements Supplier<Map<RegionAndName,
|
|||
return builder.build().entrySet();
|
||||
}
|
||||
|
||||
public static DescribeImagesOptions getOptionsForOwners(String[] amiOwners) {
|
||||
final DescribeImagesOptions options;
|
||||
public DescribeImagesOptions getOptionsForOwners(String... amiOwners) {
|
||||
DescribeImagesOptions options;
|
||||
if (amiOwners.length == 1 && amiOwners[0].equals("*"))
|
||||
options = new DescribeImagesOptions();
|
||||
else
|
||||
|
|
|
@ -73,7 +73,7 @@ public class EC2TemplateBuilderTest {
|
|||
private static final Location location = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
|
||||
.description("us-east-1").build();
|
||||
|
||||
public static final Hardware CC1_4XLARGE = cc1_4xlarge().location(location).supportsImageIds("us-east-1/cc-image")
|
||||
public static final Hardware CC1_4XLARGE = cc1_4xlarge().supportsImageIds(ImmutableSet.of("us-east-1/cc-image"))
|
||||
.build();
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.compute.domain.Image;
|
|||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OperatingSystemBuilder;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
|
@ -122,7 +121,7 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
|
||||
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId(
|
||||
"us-east-1/ami-82e4b5c7").operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description(
|
||||
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description(
|
||||
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f")
|
||||
.providerId("i-0799056f").location(provider).build());
|
||||
}
|
||||
|
|
|
@ -19,11 +19,15 @@
|
|||
package org.jclouds.aws.ec2;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGIONS;
|
||||
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_SUSPENDED;
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jclouds.aws.domain.Region;
|
||||
|
||||
|
@ -43,14 +47,22 @@ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilde
|
|||
// auth fail sometimes happens in EC2, as the rc.local script that injects the
|
||||
// authorized key executes after ssh has started
|
||||
properties.setProperty("jclouds.ssh.max_retries", "7");
|
||||
properties.setProperty("jclouds.ssh.retryable_messages",
|
||||
"Auth fail,failed to send channel request,channel is not opened,invalid data,End of IO Stream Read,Connection reset,socket is not established,connection is closed by foreign host,socket is not established");
|
||||
properties
|
||||
.setProperty(
|
||||
"jclouds.ssh.retryable_messages",
|
||||
"Auth fail,failed to send channel request,channel is not opened,invalid data,End of IO Stream Read,Connection reset,socket is not established,connection is closed by foreign host,socket is not established");
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com");
|
||||
properties.putAll(Region.regionProperties());
|
||||
properties.remove(PROPERTY_EC2_AMI_OWNERS);
|
||||
// amazon, alestic, canonical, and rightscale
|
||||
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317");
|
||||
properties.setProperty(PROPERTY_EC2_AMI_QUERY,
|
||||
"owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine");
|
||||
// amis that work with the cluster instances
|
||||
properties.setProperty(PROPERTY_EC2_CC_AMIs, "us-east-1/ami-321eed5b,us-east-1/ami-7ea24a17");
|
||||
properties.setProperty(PROPERTY_EC2_CC_REGIONS, Region.US_EAST_1);
|
||||
properties
|
||||
.setProperty(
|
||||
PROPERTY_EC2_CC_AMI_QUERY,
|
||||
"virtualization-type=hvm;architecture=x86_64;owner-id=137112412989,099720109477;hypervisor=xen;state=available;image-type=machine;root-device-type=ebs");
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
@ -62,4 +74,38 @@ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilde
|
|||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties build() {
|
||||
Properties props = super.build();
|
||||
warnAndReplaceIfUsingOldImageKey(props);
|
||||
warnAndReplaceIfUsingOldCCImageKey(props);
|
||||
return props;
|
||||
}
|
||||
|
||||
protected void warnAndReplaceIfUsingOldImageKey(Properties props) {
|
||||
if (props.containsKey(PROPERTY_EC2_AMI_OWNERS)) {
|
||||
StringBuilder query = new StringBuilder();
|
||||
String owners = properties.remove(PROPERTY_EC2_AMI_OWNERS).toString();
|
||||
if (!"*".equals(owners) && !"".equals(owners))
|
||||
query.append("owner-id=").append(owners).append(';');
|
||||
if (!"".equals(owners))
|
||||
query.append("state=available;image-type=machine");
|
||||
props.setProperty(PROPERTY_EC2_AMI_QUERY, query.toString());
|
||||
Logger.getAnonymousLogger().warning(
|
||||
String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS,
|
||||
PROPERTY_EC2_AMI_QUERY, query.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
protected void warnAndReplaceIfUsingOldCCImageKey(Properties props) {
|
||||
if (props.containsKey(PROPERTY_EC2_CC_AMIs)) {
|
||||
String amis = properties.remove(PROPERTY_EC2_CC_AMIs).toString();
|
||||
String value = "image-id=" + amis.replace("us-east-1/", "");
|
||||
props.setProperty(PROPERTY_EC2_CC_AMI_QUERY, value);
|
||||
Logger.getAnonymousLogger().warning(
|
||||
String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_CC_AMIs,
|
||||
PROPERTY_EC2_CC_AMI_QUERY, value));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.compute.config;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.AWSEC2TemplateBuilderImpl;
|
||||
import org.jclouds.aws.ec2.compute.functions.AWSRunningInstanceToNodeMetadata;
|
||||
import org.jclouds.aws.ec2.compute.predicates.AWSEC2InstancePresent;
|
||||
|
@ -31,8 +37,12 @@ import org.jclouds.aws.ec2.compute.strategy.AWSEC2ReviseParsedImage;
|
|||
import org.jclouds.aws.ec2.compute.strategy.CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions;
|
||||
import org.jclouds.aws.ec2.compute.suppliers.AWSEC2HardwareSupplier;
|
||||
import org.jclouds.aws.ec2.compute.suppliers.AWSRegionAndNameToImageSupplier;
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule;
|
||||
import org.jclouds.ec2.compute.config.EC2BindComputeStrategiesByClass;
|
||||
import org.jclouds.ec2.compute.config.EC2BindComputeSuppliersByClass;
|
||||
import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
||||
import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
|
||||
import org.jclouds.ec2.compute.predicates.InstancePresent;
|
||||
|
@ -43,29 +53,27 @@ import org.jclouds.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
|
|||
import org.jclouds.ec2.compute.strategy.EC2ListNodesStrategy;
|
||||
import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
|
||||
import org.jclouds.ec2.compute.suppliers.EC2HardwareSupplier;
|
||||
import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class AWSEC2ComputeServiceContextModule extends EC2ComputeServiceContextModule {
|
||||
|
||||
@Override
|
||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||
return template.osFamily(AMZN_LINUX).os64Bit(true);
|
||||
}
|
||||
|
||||
public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContextModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
installDependencies();
|
||||
install(new EC2BindComputeStrategiesByClass());
|
||||
install(new EC2BindComputeSuppliersByClass());
|
||||
bind(ReviseParsedImage.class).to(AWSEC2ReviseParsedImage.class);
|
||||
bind(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class).to(
|
||||
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class);
|
||||
bind(EC2HardwareSupplier.class).to(AWSEC2HardwareSupplier.class);
|
||||
bind(RegionAndNameToImageSupplier.class).to(AWSRegionAndNameToImageSupplier.class);
|
||||
bind(EC2TemplateBuilderImpl.class).to(AWSEC2TemplateBuilderImpl.class);
|
||||
bind(EC2GetNodeMetadataStrategy.class).to(AWSEC2GetNodeMetadataStrategy.class);
|
||||
bind(EC2ListNodesStrategy.class).to(AWSEC2ListNodesStrategy.class);
|
||||
|
@ -75,9 +83,25 @@ public class AWSEC2ComputeServiceContextModule extends EC2ComputeServiceContextM
|
|||
bind(RunningInstanceToNodeMetadata.class).to(AWSRunningInstanceToNodeMetadata.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installDependencies() {
|
||||
install(new AWSEC2ComputeServiceDependenciesModule());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final AWSRegionAndNameToImageSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<RegionAndName, ? extends Image>>(
|
||||
authException, seconds, new Supplier<Map<RegionAndName, ? extends Image>>() {
|
||||
@Override
|
||||
public Map<RegionAndName, ? extends Image> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||
return template.osFamily(AMZN_LINUX).os64Bit(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,10 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.compute.config;
|
||||
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -32,6 +31,7 @@ import org.jclouds.aws.ec2.AWSEC2AsyncClient;
|
|||
import org.jclouds.aws.ec2.AWSEC2Client;
|
||||
import org.jclouds.aws.ec2.compute.AWSEC2ComputeService;
|
||||
import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions;
|
||||
import org.jclouds.aws.ec2.compute.suppliers.CallForImages;
|
||||
import org.jclouds.aws.ec2.domain.PlacementGroup;
|
||||
import org.jclouds.aws.ec2.domain.RegionNameAndPublicKeyMaterial;
|
||||
import org.jclouds.aws.ec2.functions.ImportOrReturnExistingKeypair;
|
||||
|
@ -62,10 +62,11 @@ import org.jclouds.rest.internal.RestContextImpl;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -95,6 +96,7 @@ public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDep
|
|||
bind(new TypeLiteral<RestContext<AWSEC2Client, AWSEC2AsyncClient>>() {
|
||||
}).to(new TypeLiteral<RestContextImpl<AWSEC2Client, AWSEC2AsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
install(new FactoryModuleBuilder().build(CallForImages.Factory.class));
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -121,11 +123,10 @@ public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDep
|
|||
}
|
||||
|
||||
@Provides
|
||||
@ClusterCompute
|
||||
@Singleton
|
||||
@Named(PROPERTY_EC2_CC_AMIs)
|
||||
protected String[] ccAmis(@Named(PROPERTY_EC2_CC_AMIs) String ccAmis) {
|
||||
if (ccAmis.trim().equals(""))
|
||||
return new String[] {};
|
||||
return toArray(Splitter.on(',').split(ccAmis), String.class);
|
||||
protected Set<String> provideClusterComputeIds() {
|
||||
return Sets.newLinkedHashSet();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package org.jclouds.aws.ec2.compute.config;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Related to a ClusterCompute resource.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface ClusterCompute {
|
||||
|
||||
}
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.compute.suppliers;
|
||||
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_medium;
|
||||
import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge;
|
||||
import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.cc1_4xlarge;
|
||||
|
@ -34,18 +32,12 @@ import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.t1_micro;
|
|||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.aws.ec2.compute.config.ClusterCompute;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.ec2.compute.suppliers.EC2HardwareSupplier;
|
||||
import org.jclouds.location.Provider;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
|
@ -56,31 +48,17 @@ import com.google.common.collect.ImmutableSet.Builder;
|
|||
@Singleton
|
||||
public class AWSEC2HardwareSupplier extends EC2HardwareSupplier {
|
||||
|
||||
private final Supplier<Set<? extends Location>> locations;
|
||||
private final String[] ccAmis;
|
||||
private final Set<String> ccAmis;
|
||||
|
||||
@Inject
|
||||
public AWSEC2HardwareSupplier(@Memoized Supplier<Set<? extends Location>> locations, @Provider String providerName,
|
||||
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) {
|
||||
this.locations = locations;
|
||||
public AWSEC2HardwareSupplier(@ClusterCompute Set<String> ccAmis) {
|
||||
this.ccAmis = ccAmis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Hardware> get() {
|
||||
Builder<Hardware> sizes = ImmutableSet.builder();
|
||||
for (String ccAmi : ccAmis) {
|
||||
final String region = ccAmi.split("/")[0];
|
||||
Location location = find(locations.get(), new Predicate<Location>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getScope() == LocationScope.REGION && input.getId().equals(region);
|
||||
}
|
||||
|
||||
});
|
||||
sizes.add(cc1_4xlarge().location(location).supportsImageIds(ccAmi).build());
|
||||
}
|
||||
sizes.add(cc1_4xlarge().supportsImageIds(ccAmis).build());
|
||||
sizes.addAll(ImmutableSet.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large()
|
||||
.build(), m1_small32().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(),
|
||||
m2_4xlarge().build()));
|
||||
|
|
|
@ -18,75 +18,138 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.compute.suppliers;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.imageIds;
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Maps.uniqueIndex;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGIONS;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.aws.ec2.compute.config.ClusterCompute;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.ec2.compute.functions.EC2ImageParser;
|
||||
import org.jclouds.ec2.compute.strategy.DescribeImagesParallel;
|
||||
import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier;
|
||||
import org.jclouds.ec2.options.DescribeImagesOptions;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class AWSRegionAndNameToImageSupplier extends RegionAndNameToImageSupplier {
|
||||
public class AWSRegionAndNameToImageSupplier implements Supplier<Map<RegionAndName, ? extends Image>> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final String[] ccAmis;
|
||||
private final Map<RegionAndName, Image> images;
|
||||
private final Set<String> clusterComputeIds;
|
||||
private final CallForImages.Factory factory;
|
||||
private final ExecutorService executor;
|
||||
|
||||
private final Iterable<String> regions;
|
||||
private final String amiQuery;
|
||||
private final Iterable<String> clusterRegions;
|
||||
private final String ccAmiQuery;
|
||||
|
||||
@Inject
|
||||
AWSRegionAndNameToImageSupplier(@Region Set<String> regions, DescribeImagesParallel describer,
|
||||
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis, @Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners,
|
||||
EC2ImageParser parser, Map<RegionAndName, Image> images) {
|
||||
super(regions, describer, amiOwners, parser, images);
|
||||
this.ccAmis = ccAmis;
|
||||
protected AWSRegionAndNameToImageSupplier(@Region Set<String> regions,
|
||||
@Named(PROPERTY_EC2_AMI_QUERY) String amiQuery, @Named(PROPERTY_EC2_CC_REGIONS) String clusterRegions,
|
||||
@Named(PROPERTY_EC2_CC_AMI_QUERY) String ccAmiQuery, Map<RegionAndName, Image> images,
|
||||
CallForImages.Factory factory, @ClusterCompute Set<String> clusterComputeIds,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
this.factory = factory;
|
||||
this.regions = regions;
|
||||
this.amiQuery = amiQuery;
|
||||
this.clusterRegions = Splitter.on(',').split(clusterRegions);
|
||||
this.ccAmiQuery = ccAmiQuery;
|
||||
this.images = images;
|
||||
this.clusterComputeIds = clusterComputeIds;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public Iterable<Entry<String, DescribeImagesOptions>> getDescribeQueriesForOwnersInRegions(Set<String> regions,
|
||||
String[] amiOwners) {
|
||||
return concat(super.getDescribeQueriesForOwnersInRegions(regions, amiOwners), ccAmisToDescribeQueries(ccAmis)
|
||||
.entrySet());
|
||||
}
|
||||
|
||||
static Map<String, DescribeImagesOptions> ccAmisToDescribeQueries(String[] ccAmis) {
|
||||
Map<String, DescribeImagesOptions> queries = newLinkedHashMap();
|
||||
for (String from : ccAmis) {
|
||||
queries.put(from.split("/")[0], imageIds(from.split("/")[1]));
|
||||
@Override
|
||||
public Map<RegionAndName, ? extends Image> get() {
|
||||
Future<Iterable<Image>> normalImages = images(regions, amiQuery, PROPERTY_EC2_AMI_QUERY);
|
||||
ImmutableSet<Image> clusterImages;
|
||||
try {
|
||||
clusterImages = ImmutableSet.copyOf(images(clusterRegions, ccAmiQuery, PROPERTY_EC2_CC_AMI_QUERY).get());
|
||||
} catch (Exception e) {
|
||||
logger.warn(e, "Error parsing images in query %s", ccAmiQuery);
|
||||
Throwables.propagate(e);
|
||||
return null;
|
||||
}
|
||||
return queries;
|
||||
Iterables.addAll(clusterComputeIds, transform(clusterImages, new Function<Image, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Image arg0) {
|
||||
return arg0.getId();
|
||||
}
|
||||
}));
|
||||
Iterable<? extends Image> parsedImages;
|
||||
try {
|
||||
parsedImages = ImmutableSet.copyOf(concat(clusterImages, normalImages.get()));
|
||||
} catch (Exception e) {
|
||||
logger.warn(e, "Error parsing images in query %s", amiQuery);
|
||||
Throwables.propagate(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
images.putAll(uniqueIndex(parsedImages, new Function<Image, RegionAndName>() {
|
||||
|
||||
@Override
|
||||
public RegionAndName apply(Image from) {
|
||||
return new RegionAndName(from.getLocation().getId(), from.getProviderId());
|
||||
}
|
||||
|
||||
}));
|
||||
return images;
|
||||
}
|
||||
|
||||
private Future<Iterable<Image>> images(Iterable<String> regions, String query, String tag) {
|
||||
if (query.equals("")) {
|
||||
logger.debug(">> no %s specified, skipping image parsing", tag);
|
||||
return Futures.<Iterable<Image>> immediateFuture(ImmutableSet.<Image> of());
|
||||
} else {
|
||||
return executor.submit(factory.parseImagesFromRegionsUsingFilter(regions, QueryStringToMultimap.INSTANCE
|
||||
.apply(query)));
|
||||
}
|
||||
}
|
||||
|
||||
public static enum QueryStringToMultimap implements Function<String, Multimap<String, String>> {
|
||||
INSTANCE;
|
||||
@Override
|
||||
public Multimap<String, String> apply(String arg0) {
|
||||
ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
|
||||
for (String pair : Splitter.on(';').split(arg0)) {
|
||||
String[] keyValue = pair.split("=");
|
||||
if (keyValue.length == 1)
|
||||
builder.putAll(keyValue[0], ImmutableSet.<String> of());
|
||||
else
|
||||
builder.putAll(keyValue[0], Splitter.on(',').split(keyValue[1]));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.aws.ec2.compute.suppliers;
|
||||
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.aws.ec2.options.AWSDescribeImagesOptions.Builder.filters;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.ec2.compute.functions.EC2ImageParser;
|
||||
import org.jclouds.ec2.compute.strategy.DescribeImagesParallel;
|
||||
import org.jclouds.ec2.options.DescribeImagesOptions;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class CallForImages implements Callable<Iterable<Image>> {
|
||||
public interface Factory {
|
||||
CallForImages parseImagesFromRegionsUsingFilter(Iterable<String> regions, Multimap<String, String> filter);
|
||||
}
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Iterable<String> regions;
|
||||
private final DescribeImagesParallel describer;
|
||||
private final EC2ImageParser parser;
|
||||
private final Multimap<String, String> filter;
|
||||
|
||||
@Inject
|
||||
protected CallForImages(DescribeImagesParallel describer, EC2ImageParser parser, @Assisted Iterable<String> regions,
|
||||
@Assisted Multimap<String, String> filter) {
|
||||
this.regions = regions;
|
||||
this.describer = describer;
|
||||
this.filter = filter;
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public Iterable<Image> call() {
|
||||
|
||||
logger.debug(">> providing images");
|
||||
|
||||
Builder<String, DescribeImagesOptions> builder = ImmutableMap.<String, DescribeImagesOptions> builder();
|
||||
for (String region : regions)
|
||||
builder.put(region, filters(filter));
|
||||
|
||||
Iterable<Entry<String, DescribeImagesOptions>> queries = builder.build().entrySet();
|
||||
|
||||
Iterable<Image> returnVal = filter(transform(describer.apply(queries), parser), Predicates.notNull());
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("<< images(%s)", Iterables.size(returnVal));
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("desribingImages(filter=%s,regions=%s)", filter, regions);
|
||||
}
|
||||
|
||||
}
|
|
@ -52,6 +52,18 @@ public interface AWSEC2Constants extends EC2Constants {
|
|||
*
|
||||
* @see InstanceType.CC1_4XLARGE
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String PROPERTY_EC2_CC_AMIs = "jclouds.ec2.cc-amis";
|
||||
/**
|
||||
* expression to find amis that work on the cluster instance type <br/>
|
||||
* ex. {@code
|
||||
* virtualization-type=hvm;architecture=x86_64;owner-id=137112412989,099720109477;hypervisor=xen;
|
||||
* state=available;image-type=machine;root-device-type=ebs}
|
||||
*
|
||||
* @see InstanceType.CC1_4XLARGE
|
||||
*/
|
||||
public static final String PROPERTY_EC2_CC_AMI_QUERY = "jclouds.ec2.cc-ami-query";
|
||||
public static final String PROPERTY_EC2_CC_REGIONS = "jclouds.ec2.cc-regions";
|
||||
public static final String PROPERTY_EC2_AMI_QUERY = "jclouds.ec2.ami-query";
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.aws.ec2;
|
||||
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "AWSEC2PropertiesBuilderTest")
|
||||
public class AWSEC2PropertiesBuilderTest {
|
||||
public void testConvertCCImageSyntax() {
|
||||
Properties input = new Properties();
|
||||
input.setProperty(PROPERTY_EC2_CC_AMIs, "us-east-1/ami-321eed5b,us-east-1/ami-7ea24a17");
|
||||
Properties props = new AWSEC2PropertiesBuilder(input).build();
|
||||
assertEquals(props.getProperty(PROPERTY_EC2_CC_AMIs), null);
|
||||
assertEquals(props.getProperty(PROPERTY_EC2_CC_AMI_QUERY), "image-id=ami-321eed5b,ami-7ea24a17");
|
||||
}
|
||||
|
||||
public void testConvertImageSyntax() {
|
||||
Properties input = new Properties();
|
||||
input.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317");
|
||||
Properties props = new AWSEC2PropertiesBuilder(input).build();
|
||||
assertEquals(props.getProperty(PROPERTY_EC2_AMI_OWNERS), null);
|
||||
assertEquals(props.getProperty(PROPERTY_EC2_AMI_QUERY),
|
||||
"owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine");
|
||||
}
|
||||
|
||||
public void testConvertImageSyntaxWhenStar() {
|
||||
Properties input = new Properties();
|
||||
input.setProperty(PROPERTY_EC2_AMI_OWNERS, "*");
|
||||
Properties props = new AWSEC2PropertiesBuilder(input).build();
|
||||
assertEquals(props.getProperty(PROPERTY_EC2_AMI_OWNERS), null);
|
||||
assertEquals(props.getProperty(PROPERTY_EC2_AMI_QUERY), "state=available;image-type=machine");
|
||||
}
|
||||
|
||||
public void testConvertImageSyntaxWhenBlank() {
|
||||
Properties input = new Properties();
|
||||
input.setProperty(PROPERTY_EC2_AMI_OWNERS, "");
|
||||
Properties props = new AWSEC2PropertiesBuilder(input).build();
|
||||
assertEquals(props.getProperty(PROPERTY_EC2_AMI_OWNERS), null);
|
||||
assertEquals(props.getProperty(PROPERTY_EC2_AMI_QUERY), "");
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ import java.util.Properties;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.aws.ec2.reference.AWSEC2Constants;
|
||||
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
|
@ -34,7 +35,6 @@ import org.jclouds.compute.domain.OsFamily;
|
|||
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.ec2.domain.InstanceType;
|
||||
import org.jclouds.ec2.reference.EC2Constants;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -81,7 +81,8 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
|||
public void testTemplateBuilderM1SMALLWithDescription() {
|
||||
|
||||
Template template = context.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL)
|
||||
.osVersionMatches("1[10].[10][04]").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU).build();
|
||||
.osVersionMatches("1[10].[10][04]").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU)
|
||||
.build();
|
||||
|
||||
assert (template.getImage().getProviderId().startsWith("ami-")) : template;
|
||||
assertEquals(template.getImage().getOperatingSystem().getVersion(), "11.10");
|
||||
|
@ -130,9 +131,10 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
|||
|
||||
@Test
|
||||
public void testFastestTemplateBuilder() throws IOException {
|
||||
|
||||
Template fastestTemplate = context.getComputeService().templateBuilder().fastest().build();
|
||||
Template fastestTemplate = context.getComputeService().templateBuilder().fastest().osFamily(OsFamily.AMZN_LINUX)
|
||||
.build();
|
||||
assert (fastestTemplate.getImage().getProviderId().startsWith("ami-")) : fastestTemplate;
|
||||
assertEquals(fastestTemplate.getHardware().getProviderId(), InstanceType.CC1_4XLARGE);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getVersion(), "2011.02.1-beta");
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
|
@ -140,6 +142,17 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
|||
assertEquals(fastestTemplate.getLocation().getId(), "us-east-1");
|
||||
assertEquals(getCores(fastestTemplate.getHardware()), 8.0d);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getArch(), "hvm");
|
||||
|
||||
fastestTemplate = context.getComputeService().templateBuilder().fastest().build();
|
||||
assert (fastestTemplate.getImage().getProviderId().startsWith("ami-")) : fastestTemplate;
|
||||
assertEquals(fastestTemplate.getHardware().getProviderId(), InstanceType.CC1_4XLARGE);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getVersion(), "11.10");
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(fastestTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
|
||||
assertEquals(fastestTemplate.getLocation().getId(), "us-east-1");
|
||||
assertEquals(getCores(fastestTemplate.getHardware()), 8.0d);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getArch(), "hvm");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -164,7 +177,8 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
|||
try {
|
||||
Properties overrides = setupProperties();
|
||||
// set owners to nothing
|
||||
overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "");
|
||||
overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, "");
|
||||
overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY, "");
|
||||
|
||||
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
|
||||
.<Module> of(new Log4JLoggingModule()), overrides);
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
package org.jclouds.aws.ec2.services;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.imageIds;
|
||||
import static org.jclouds.aws.ec2.options.AWSDescribeImagesOptions.Builder.filters;
|
||||
import static org.jclouds.aws.ec2.options.AWSDescribeImagesOptions.Builder.imageIds;
|
||||
import static org.jclouds.ec2.options.RegisterImageBackedByEbsOptions.Builder.addNewBlockDevice;
|
||||
import static org.jclouds.ec2.options.RegisterImageOptions.Builder.withDescription;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -30,12 +31,13 @@ import java.util.Properties;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.ec2.EC2AsyncClient;
|
||||
import org.jclouds.ec2.EC2Client;
|
||||
import org.jclouds.ec2.domain.Image;
|
||||
import org.jclouds.ec2.domain.Image.ImageType;
|
||||
import org.jclouds.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.ec2.domain.Image.ImageType;
|
||||
import org.jclouds.ec2.services.AMIClient;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
@ -45,6 +47,7 @@ import org.testng.annotations.BeforeGroups;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
@ -55,7 +58,7 @@ import com.google.inject.Module;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true)
|
||||
@Test(groups = "live", singleThreaded = true)
|
||||
public class AMIClientLiveTest {
|
||||
|
||||
private AMIClient client;
|
||||
|
@ -99,7 +102,7 @@ public class AMIClientLiveTest {
|
|||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
context = new ComputeServiceContextFactory().createContext(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
client = context.getApi().getAMIServices();
|
||||
}
|
||||
|
||||
|
@ -114,13 +117,13 @@ public class AMIClientLiveTest {
|
|||
|
||||
public void testDescribeImages() {
|
||||
for (String region : context.getApi().getAvailabilityZoneAndRegionServices().describeRegions().keySet()) {
|
||||
Set<Image> allResults = Sets.newLinkedHashSet(client.describeImagesInRegion(region));
|
||||
Set<? extends Image> allResults = client.describeImagesInRegion(region);
|
||||
assertNotNull(allResults);
|
||||
assert allResults.size() >= 2 : allResults.size();
|
||||
Iterator<Image> iterator = allResults.iterator();
|
||||
Iterator<? extends Image> iterator = allResults.iterator();
|
||||
String id1 = iterator.next().getId();
|
||||
String id2 = iterator.next().getId();
|
||||
Set<Image> twoResults = Sets.newLinkedHashSet(client.describeImagesInRegion(region, imageIds(id1, id2)));
|
||||
Set<? extends Image> twoResults = client.describeImagesInRegion(region, imageIds(id1, id2));
|
||||
assertNotNull(twoResults);
|
||||
assertEquals(twoResults.size(), 2);
|
||||
iterator = twoResults.iterator();
|
||||
|
@ -129,12 +132,27 @@ public class AMIClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void testDescribeImagesCC() {
|
||||
Set<? extends Image> twoResults = client.describeImagesInRegion(Region.US_EAST_1, filters(
|
||||
ImmutableMultimap.<String, String> builder()//
|
||||
.put("virtualization-type", "hvm")//
|
||||
.put("architecture", "x86_64")//
|
||||
.putAll("owner-id", ImmutableSet.<String> of("137112412989", "099720109477"))//
|
||||
.put("hypervisor", "xen")//
|
||||
.put("state", "available")//
|
||||
.put("image-type", "machine")//
|
||||
.put("root-device-type", "ebs")//
|
||||
.build()).ownedBy("137112412989", "099720109477"));
|
||||
assertNotNull(twoResults);
|
||||
assertEquals(twoResults.size(), 26);
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testRegisterImageFromManifest() {
|
||||
String imageRegisteredId = client.registerImageFromManifestInRegion(null, "jcloudstest1", DEFAULT_MANIFEST);
|
||||
imagesToDeregister.add(imageRegisteredId);
|
||||
Image imageRegisteredFromManifest = Iterables.getOnlyElement(client.describeImagesInRegion(null,
|
||||
imageIds(imageRegisteredId)));
|
||||
imageIds(imageRegisteredId)));
|
||||
assertEquals(imageRegisteredFromManifest.getName(), "jcloudstest1");
|
||||
assertEquals(imageRegisteredFromManifest.getImageLocation(), DEFAULT_MANIFEST);
|
||||
assertEquals(imageRegisteredFromManifest.getImageType(), ImageType.MACHINE);
|
||||
|
@ -145,10 +163,10 @@ public class AMIClientLiveTest {
|
|||
@Test(enabled = false)
|
||||
public void testRegisterImageFromManifestOptions() {
|
||||
String imageRegisteredWithOptionsId = client.registerImageFromManifestInRegion(null, "jcloudstest2",
|
||||
DEFAULT_MANIFEST, withDescription("adrian"));
|
||||
DEFAULT_MANIFEST, withDescription("adrian"));
|
||||
imagesToDeregister.add(imageRegisteredWithOptionsId);
|
||||
Image imageRegisteredFromManifestWithOptions = Iterables.getOnlyElement(client.describeImagesInRegion(null,
|
||||
imageIds(imageRegisteredWithOptionsId)));
|
||||
imageIds(imageRegisteredWithOptionsId)));
|
||||
assertEquals(imageRegisteredFromManifestWithOptions.getName(), "jcloudstest2");
|
||||
assertEquals(imageRegisteredFromManifestWithOptions.getImageLocation(), DEFAULT_MANIFEST);
|
||||
assertEquals(imageRegisteredFromManifestWithOptions.getImageType(), ImageType.MACHINE);
|
||||
|
@ -163,7 +181,7 @@ public class AMIClientLiveTest {
|
|||
String imageRegisteredId = client.registerUnixImageBackedByEbsInRegion(null, "jcloudstest1", DEFAULT_MANIFEST);
|
||||
imagesToDeregister.add(imageRegisteredId);
|
||||
Image imageRegistered = Iterables
|
||||
.getOnlyElement(client.describeImagesInRegion(null, imageIds(imageRegisteredId)));
|
||||
.getOnlyElement(client.describeImagesInRegion(null, imageIds(imageRegisteredId)));
|
||||
assertEquals(imageRegistered.getName(), "jcloudstest1");
|
||||
assertEquals(imageRegistered.getImageType(), ImageType.MACHINE);
|
||||
assertEquals(imageRegistered.getRootDeviceType(), RootDeviceType.EBS);
|
||||
|
@ -174,19 +192,18 @@ public class AMIClientLiveTest {
|
|||
// awaiting EBS functionality to be added to jclouds
|
||||
public void testRegisterImageBackedByEBSOptions() {
|
||||
String imageRegisteredWithOptionsId = client.registerUnixImageBackedByEbsInRegion(null, "jcloudstest2",
|
||||
DEFAULT_SNAPSHOT, addNewBlockDevice("/dev/sda2", "myvirtual", 1).withDescription("adrian"));
|
||||
DEFAULT_SNAPSHOT, addNewBlockDevice("/dev/sda2", "myvirtual", 1).withDescription("adrian"));
|
||||
imagesToDeregister.add(imageRegisteredWithOptionsId);
|
||||
Image imageRegisteredWithOptions = Iterables.getOnlyElement(client.describeImagesInRegion(null,
|
||||
imageIds(imageRegisteredWithOptionsId)));
|
||||
imageIds(imageRegisteredWithOptionsId)));
|
||||
assertEquals(imageRegisteredWithOptions.getName(), "jcloudstest2");
|
||||
assertEquals(imageRegisteredWithOptions.getImageType(), ImageType.MACHINE);
|
||||
assertEquals(imageRegisteredWithOptions.getRootDeviceType(), RootDeviceType.EBS);
|
||||
assertEquals(imageRegisteredWithOptions.getRootDeviceName(), "/dev/sda1");
|
||||
assertEquals(imageRegisteredWithOptions.getDescription(), "adrian");
|
||||
assertEquals(
|
||||
imageRegisteredWithOptions.getEbsBlockDevices().entrySet(),
|
||||
ImmutableMap.of("/dev/sda1", new Image.EbsBlockDevice("/dev/sda1", 30, true), "/dev/sda2",
|
||||
new Image.EbsBlockDevice("/dev/sda2", 1, true)).entrySet());
|
||||
assertEquals(imageRegisteredWithOptions.getEbsBlockDevices().entrySet(), ImmutableMap.of("/dev/sda1",
|
||||
new Image.EbsBlockDevice("/dev/sda1", 30, true), "/dev/sda2",
|
||||
new Image.EbsBlockDevice("/dev/sda2", 1, true)).entrySet());
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.services;
|
||||
|
||||
import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.executableBy;
|
||||
import static org.jclouds.aws.ec2.options.AWSDescribeImagesOptions.Builder.filters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
|
@ -41,6 +41,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
|
@ -115,16 +116,18 @@ public class AWSAMIAsyncClientTest extends BaseAWSEC2AsyncClientTest<AWSAMIAsync
|
|||
|
||||
public void testDescribeImagesOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AWSAMIAsyncClient.class.getMethod("describeImagesInRegion", String.class,
|
||||
Array.newInstance(DescribeImagesOptions.class, 0).getClass());
|
||||
HttpRequest request = processor.createRequest(method, null,
|
||||
executableBy("me").ownedBy("fred", "nancy").imageIds("1", "2"));
|
||||
DescribeImagesOptions[].class);
|
||||
|
||||
HttpRequest request = processor.createRequest(method, null, filters(
|
||||
ImmutableMap.of("state", "available", "image-type", "machine")).executableBy("me").ownedBy("fred",
|
||||
"nancy").imageIds("1", "2"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2010-11-15&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
request,
|
||||
"Version=2010-11-15&Action=DescribeImages&Filter.1.Name=state&Filter.1.Value.1=available&Filter.2.Name=image-type&Filter.2.Value.1=machine&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.jclouds.aws.ec2.services;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.imageIds;
|
||||
import static org.jclouds.aws.ec2.options.AWSDescribeImagesOptions.Builder.imageIds;
|
||||
import static org.jclouds.ec2.options.RegisterImageBackedByEbsOptions.Builder.addNewBlockDevice;
|
||||
import static org.jclouds.ec2.options.RegisterImageOptions.Builder.withDescription;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -34,8 +34,8 @@ import org.jclouds.aws.ec2.AWSEC2AsyncClient;
|
|||
import org.jclouds.aws.ec2.AWSEC2Client;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.ec2.domain.Image;
|
||||
import org.jclouds.ec2.domain.Image.ImageType;
|
||||
import org.jclouds.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.ec2.domain.Image.ImageType;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.aws.ec2.services;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static com.google.common.collect.Sets.newTreeSet;
|
||||
|
@ -46,8 +45,6 @@ import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted;
|
|||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.RunNodesException;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.predicates.NodePredicates;
|
||||
|
@ -60,7 +57,6 @@ import org.testng.annotations.BeforeClass;
|
|||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
@ -172,29 +168,12 @@ public class PlacementGroupClientLiveTest {
|
|||
|
||||
public void testStartCCInstance() throws Exception {
|
||||
|
||||
Set<? extends Hardware> sizes = context.getComputeService().listHardwareProfiles();
|
||||
assert any(sizes, new Predicate<Hardware>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Hardware arg0) {
|
||||
return arg0.getProviderId().equals(InstanceType.CC1_4XLARGE);
|
||||
}
|
||||
|
||||
}) : sizes;
|
||||
Set<? extends Image> images = context.getComputeService().listImages();
|
||||
assert any(images, new Predicate<Image>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Image arg0) {
|
||||
return arg0.getId().equals("us-east-1/ami-7ea24a17");
|
||||
}
|
||||
|
||||
}) : images;
|
||||
|
||||
Template template = context.getComputeService().templateBuilder().fastest().build();
|
||||
Template template = context.getComputeService().templateBuilder().fastest().osVersionMatches("11.04").build();
|
||||
assert template != null : "The returned template was null, but it should have a value.";
|
||||
assertEquals(template.getHardware().getProviderId(), InstanceType.CC1_4XLARGE);
|
||||
assertEquals(template.getImage().getId(), "us-east-1/ami-321eed5b");
|
||||
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
|
||||
assertEquals(template.getImage().getUserMetadata().get("virtualizationType"), "hvm");
|
||||
assertEquals(template.getImage().getUserMetadata().get("hypervisor"), "xen");
|
||||
|
||||
template.getOptions().overrideLoginCredentialWith(keyPair.get("private"))
|
||||
.authorizePublicKey(keyPair.get("public")).runScript(buildScript(template.getImage().getOperatingSystem()));
|
||||
|
|
Loading…
Reference in New Issue