fixed ec2 templatebuilder

This commit is contained in:
Adrian Cole 2010-08-24 21:08:21 -07:00
parent 44c5fc714a
commit 53db05540b
7 changed files with 21 additions and 18 deletions

View File

@ -92,8 +92,8 @@ import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.MapMaker;
import com.google.common.collect.Sets;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
@ -244,7 +244,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
return Suppliers.compose(new Function<Map<RegionAndName, ? extends Image>, Set<? extends Image>>() {
@Override
public Set<? extends Image> apply(Map<RegionAndName, ? extends Image> from) {
return ImmutableSet.copyOf(from.values());
return Sets.newLinkedHashSet(from.values());
}
}, map);
}

View File

@ -19,7 +19,7 @@
package org.jclouds.aws.ec2.compute.domain;
import static org.jclouds.compute.predicates.ImagePredicates.any;
import static com.google.common.base.Predicates.not;
import static org.jclouds.compute.predicates.ImagePredicates.idIn;
import static org.jclouds.compute.predicates.ImagePredicates.is64Bit;
@ -42,7 +42,7 @@ public class EC2Size extends SizeImpl {
EC2Size(String instanceType, Double cores, Integer ram, Integer disk, boolean is64Bit) {
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), cores, ram, disk,
is64Bit ? is64Bit() : any());
is64Bit ? is64Bit() : not(is64Bit()));
this.instanceType = instanceType;
}

View File

@ -39,7 +39,6 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
/**
*
@ -115,13 +114,15 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
}
}
@SuppressWarnings("unchecked")
@Override
protected Set<? extends Image> getImages() {
Set<? extends Image> images = this.images.get();
Set<Image> images = (Set<Image>) this.images.get();
if (images.size() == 0) {
Image toReturn = lazyImageProvider.get();
if (toReturn != null)
return ImmutableSet.of(lazyImageProvider.get());
if (toReturn != null) {
images.add(toReturn);
}
}
return images;
}

View File

@ -68,17 +68,17 @@ public class EC2TemplateBuilderLiveTest {
Template defaultTemplate = newContext.getComputeService().templateBuilder().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
assertEquals(defaultTemplate.getImage().getName(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
newContext.getComputeService().templateBuilder().imageId(
Iterables.get(newContext.getComputeService().listImages(), 0).getProviderId()).build();
Iterables.get(newContext.getComputeService().listImages(), 0).getId()).build();
newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false).imageId(
"ami-7e28ca17").build();
"us-east-1/ami-7e28ca17").build();
newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false).imageId(
"ami-bb709dd2").build();
"us-east-1/ami-bb709dd2").build();
} finally {
if (newContext != null)
newContext.close();
@ -98,15 +98,16 @@ public class EC2TemplateBuilderLiveTest {
assertEquals(newContext.getComputeService().listImages().size(), 0);
Template template = newContext.getComputeService().templateBuilder().imageId("ami-ccb35ea5").build();
Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").build();
System.out.println(template.getImage());
assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getName(), "5.4");
assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(template.getImage().getVersion(), "4.4.10");
assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(template.getSize().getCores(), 4.0d); // because it is 64bit
assertEquals(template.getSize().getId(), "m1.large"); // because it is 64bit
// ensure we cache the new image for next time
assertEquals(newContext.getComputeService().listImages().size(), 1);

View File

@ -53,6 +53,7 @@ import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.MapMaker;
import com.google.common.collect.Sets;
/**
*
@ -93,7 +94,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(Sets.<Image> newLinkedHashSet());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet
.<Size> of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(), 1, 1,
1, ImagePredicates.any())));

View File

@ -669,7 +669,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
predicates.add(imageDescriptionPredicate);
}
Predicate<Image> imagePredicate = and(predicates);
Predicate<Image> imagePredicate = predicates.size() == 1 ? Iterables.get(predicates, 0) : and(predicates);
return imagePredicate;
}