Issue 497:revise template options on a per-provider basis

This commit is contained in:
Adrian Cole 2011-03-05 17:03:54 -05:00
parent e3e0ad3e84
commit 59c0dbb6cd
5 changed files with 65 additions and 64 deletions

View File

@ -52,9 +52,9 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
@Inject @Inject
protected EC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations, protected EC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider, Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Map<RegionAndName, Image> imageMap) { @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Map<RegionAndName, Image> imageMap) {
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider); super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
this.imageMap = imageMap; this.imageMap = imageMap;
} }
@ -85,8 +85,7 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
if (imageId != null) { if (imageId != null) {
String[] regionName = imageId.split("/"); String[] regionName = imageId.split("/");
checkArgument(regionName.length == 2, checkArgument(regionName.length == 2,
"amazon image ids must include the region ( ex. us-east-1/ami-7ea24a17 ) you specified: " "amazon image ids must include the region ( ex. us-east-1/ami-7ea24a17 ) you specified: " + imageId);
+ imageId);
RegionAndName key = new RegionAndName(regionName[0], regionName[1]); RegionAndName key = new RegionAndName(regionName[0], regionName[1]);
try { try {
return imageMap.get(key); return imageMap.get(key);

View File

@ -44,9 +44,9 @@ public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
@Inject @Inject
protected VCloudTemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations, protected VCloudTemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider, Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) { @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider); super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
} }
@ -58,6 +58,8 @@ public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
VCloudTemplateOptions eTo = VCloudTemplateOptions.class.cast(to); VCloudTemplateOptions eTo = VCloudTemplateOptions.class.cast(to);
if (eFrom.getCustomizationScript() != null) if (eFrom.getCustomizationScript() != null)
eTo.customizationScript(eFrom.getCustomizationScript()); eTo.customizationScript(eFrom.getCustomizationScript());
if (eFrom.getIpAddressAllocationMode() != null)
eTo.ipAddressAllocationMode(eFrom.getIpAddressAllocationMode());
} }
} }

View File

@ -43,7 +43,8 @@ public class GuestCustomizationSectionHandlerTest extends BaseHandlerTest {
public void testDefault() throws UnknownHostException { public void testDefault() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/guestCustomization.xml"); InputStream is = getClass().getResourceAsStream("/guestCustomization.xml");
GuestCustomizationSection result = factory.create(injector.getInstance(GuestCustomizationSectionHandler.class)).parse(is); GuestCustomizationSection result = factory.create(injector.getInstance(GuestCustomizationSectionHandler.class))
.parse(is);
checkGuestCustomization(result); checkGuestCustomization(result);
@ -52,8 +53,8 @@ public class GuestCustomizationSectionHandlerTest extends BaseHandlerTest {
@Test(enabled = false) @Test(enabled = false)
public static void checkGuestCustomization(GuestCustomizationSection result) { public static void checkGuestCustomization(GuestCustomizationSection result) {
assertEquals(result.getType(), VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML); assertEquals(result.getType(), VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML);
assertEquals(result.getHref(), URI assertEquals(result.getHref(),
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/guestCustomizationSection/")); URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/guestCustomizationSection/"));
assertEquals(result.getInfo(), "Specifies Guest OS Customization Settings"); assertEquals(result.getInfo(), "Specifies Guest OS Customization Settings");
assertEquals(result.isEnabled(), new Boolean(true)); assertEquals(result.isEnabled(), new Boolean(true));
assertEquals(result.shouldChangeSid(), new Boolean(false)); assertEquals(result.shouldChangeSid(), new Boolean(false));
@ -67,11 +68,11 @@ public class GuestCustomizationSectionHandlerTest extends BaseHandlerTest {
assertEquals(result.isAdminPasswordAuto(), new Boolean(true)); assertEquals(result.isAdminPasswordAuto(), new Boolean(true));
assertEquals(result.getAdminPassword(), null); assertEquals(result.getAdminPassword(), null);
assertEquals(result.isResetPasswordRequired(), new Boolean(false)); assertEquals(result.isResetPasswordRequired(), new Boolean(false));
assertEquals( assertEquals(result.getCustomizationScript(), "cat > /root/foo.txt<<EOF\nI '\"love\"' {asc|!}*&\nEOF\n");
result.getCustomizationScript(),
"#!/bin/bash if [[ $1 == \"postcustomization\" ]]; then echo \"post customization\" touch /root/.postcustomization ping www.redhat.com -c 1 sleep 30 # register with RHN /usr/sbin/rhnreg_ks --profilename vic_`hostname`_`dmidecode -s system-uuid` --activationkey=XXXXXXXXXXXX --force echo \"rhn registered\" # make hostname fully qualified to speed up sendmail start perl -i -pe \"s/`hostname`/`hostname`.victory.blk/g\" /etc/sysconfig/network rm /etc/ssh/*_key* service sshd restart echo \"completed\" fi");
assertEquals(result.getComputerName(), "RHEL5"); assertEquals(result.getComputerName(), "RHEL5");
assertEquals(result.getEdit(), new ReferenceTypeImpl(null, VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML, URI assertEquals(
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/guestCustomizationSection/"))); result.getEdit(),
new ReferenceTypeImpl(null, VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/guestCustomizationSection/")));
} }
} }

View File

@ -116,9 +116,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Inject @Inject
protected TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations, protected TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
Supplier<Location> defaultLocation2, Provider<TemplateOptions> optionsProvider, Supplier<Location> defaultLocation2, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) { @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
this.locations = locations; this.locations = locations;
this.images = images; this.images = images;
this.hardwares = hardwares; this.hardwares = hardwares;
@ -140,8 +140,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
boolean returnVal = true; boolean returnVal = true;
if (location != null && input.getLocation() != null) if (location != null && input.getLocation() != null)
returnVal = location.equals(input.getLocation()) || location.getParent() != null returnVal = location.equals(input.getLocation()) || location.getParent() != null
&& location.getParent().equals(input.getLocation()) || location.getParent().getParent() != null && location.getParent().equals(input.getLocation()) || location.getParent().getParent() != null
&& location.getParent().getParent().equals(input.getLocation()); && location.getParent().getParent().equals(input.getLocation());
return returnVal; return returnVal;
} }
@ -215,7 +215,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
returnVal = false; returnVal = false;
else else
returnVal = input.getDescription().contains(osDescription) returnVal = input.getDescription().contains(osDescription)
|| input.getDescription().matches(osDescription); || input.getDescription().matches(osDescription);
} }
return returnVal; return returnVal;
} }
@ -329,8 +329,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
returnVal = false; returnVal = false;
else else
returnVal = input.getDescription().equals(imageDescription) returnVal = input.getDescription().equals(imageDescription)
|| input.getDescription().contains(imageDescription) || input.getDescription().contains(imageDescription)
|| input.getDescription().matches(imageDescription); || input.getDescription().matches(imageDescription);
} }
return returnVal; return returnVal;
} }
@ -385,12 +385,12 @@ public class TemplateBuilderImpl implements TemplateBuilder {
} }
}; };
private final Predicate<Hardware> hardwarePredicate = and(hardwareIdPredicate, locationPredicate, private final Predicate<Hardware> hardwarePredicate = and(hardwareIdPredicate, locationPredicate,
hardwareCoresPredicate, hardwareRamPredicate); hardwareCoresPredicate, hardwareRamPredicate);
static final Ordering<Hardware> DEFAULT_SIZE_ORDERING = new Ordering<Hardware>() { static final Ordering<Hardware> DEFAULT_SIZE_ORDERING = new Ordering<Hardware>() {
public int compare(Hardware left, Hardware right) { public int compare(Hardware left, Hardware right) {
return ComparisonChain.start().compare(getCores(left), getCores(right)).compare(left.getRam(), right.getRam()) return ComparisonChain.start().compare(getCores(left), getCores(right)).compare(left.getRam(), right.getRam())
.compare(getSpace(left), getSpace(right)).result(); .compare(getSpace(left), getSpace(right)).result();
} }
}; };
static final Ordering<Hardware> BY_CORES_ORDERING = new Ordering<Hardware>() { static final Ordering<Hardware> BY_CORES_ORDERING = new Ordering<Hardware>() {
@ -400,16 +400,16 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}; };
static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() { static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() {
public int compare(Image left, Image right) { public int compare(Image left, Image right) {
return ComparisonChain.start().compare(left.getName(), right.getName(), return ComparisonChain.start()
Ordering.<String> natural().nullsLast()).compare(left.getVersion(), right.getVersion(), .compare(left.getName(), right.getName(), Ordering.<String> natural().nullsLast())
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getName(), .compare(left.getVersion(), right.getVersion(), Ordering.<String> natural().nullsLast())
right.getOperatingSystem().getName(),// .compare(left.getOperatingSystem().getName(), right.getOperatingSystem().getName(),//
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getVersion(), Ordering.<String> natural().nullsLast())
right.getOperatingSystem().getVersion(),// .compare(left.getOperatingSystem().getVersion(), right.getOperatingSystem().getVersion(),//
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getDescription(), Ordering.<String> natural().nullsLast())
right.getOperatingSystem().getDescription(),// .compare(left.getOperatingSystem().getDescription(), right.getOperatingSystem().getDescription(),//
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getArch(), Ordering.<String> natural().nullsLast())
right.getOperatingSystem().getArch()).result(); .compare(left.getOperatingSystem().getArch(), right.getOperatingSystem().getArch()).result();
} }
}; };
@ -549,7 +549,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
Iterable<? extends Image> supportedImages = filter(images, buildImagePredicate()); Iterable<? extends Image> supportedImages = filter(images, buildImagePredicate());
if (Iterables.size(supportedImages) == 0) if (Iterables.size(supportedImages) == 0)
throw new NoSuchElementException(String.format( throw new NoSuchElementException(String.format(
"no image matched predicate %s images that didn't match below:\n%s", imagePredicate, images)); "no image matched predicate %s images that didn't match below:\n%s", imagePredicate, images));
Hardware hardware = resolveSize(hardwareSorter(), supportedImages); Hardware hardware = resolveSize(hardwareSorter(), supportedImages);
Image image = resolveImage(hardware, supportedImages); Image image = resolveImage(hardware, supportedImages);
logger.debug("<< matched image(%s)", image); logger.debug("<< matched image(%s)", image);
@ -562,29 +562,29 @@ public class TemplateBuilderImpl implements TemplateBuilder {
Hardware hardware; Hardware hardware;
try { try {
Iterable<? extends Hardware> hardwaresThatAreCompatibleWithOurImages = filter(hardwaresl, Iterable<? extends Hardware> hardwaresThatAreCompatibleWithOurImages = filter(hardwaresl,
new Predicate<Hardware>() { new Predicate<Hardware>() {
@Override @Override
public boolean apply(final Hardware hardware) { public boolean apply(final Hardware hardware) {
return Iterables.any(images, new Predicate<Image>() { return Iterables.any(images, new Predicate<Image>() {
@Override @Override
public boolean apply(Image input) { public boolean apply(Image input) {
return hardware.supportsImage().apply(input); return hardware.supportsImage().apply(input);
} }
@Override @Override
public String toString() { public String toString() {
return "hardware(" + hardware + ").supportsImage()"; return "hardware(" + hardware + ").supportsImage()";
} }
}); });
} }
}); });
hardware = hardwareOrdering.max(filter(hardwaresThatAreCompatibleWithOurImages, hardwarePredicate)); hardware = hardwareOrdering.max(filter(hardwaresThatAreCompatibleWithOurImages, hardwarePredicate));
} catch (NoSuchElementException exception) { } catch (NoSuchElementException exception) {
throw new NoSuchElementException("hardwares don't support any images: " + toString() + "\n" + hardwaresl throw new NoSuchElementException("hardwares don't support any images: " + toString() + "\n" + hardwaresl
+ "\n" + images); + "\n" + images);
} }
logger.debug("<< matched hardware(%s)", hardware); logger.debug("<< matched hardware(%s)", hardware);
return hardware; return hardware;
@ -692,7 +692,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
// looks verbose, but explicit <Image> type needed for this to compile // looks verbose, but explicit <Image> type needed for this to compile
// properly // properly
Predicate<Image> imagePredicate = predicates.size() == 1 ? Iterables.<Predicate<Image>> get(predicates, 0) Predicate<Image> imagePredicate = predicates.size() == 1 ? Iterables.<Predicate<Image>> get(predicates, 0)
: Predicates.<Image> and(predicates); : Predicates.<Image> and(predicates);
return imagePredicate; return imagePredicate;
} }
@ -840,9 +840,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@VisibleForTesting @VisibleForTesting
boolean nothingChangedExceptOptions() { boolean nothingChangedExceptOptions() {
return osFamily == null && location == null && imageId == null && hardwareId == null && osName == null return osFamily == null && location == null && imageId == null && hardwareId == null && osName == null
&& osDescription == null && imageVersion == null && osVersion == null && osArch == null && osDescription == null && imageVersion == null && osVersion == null && osArch == null && os64Bit == null
&& os64Bit == null && imageName == null && imageDescription == null && minCores == 0 && minRam == 0 && imageName == null && imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest;
&& !biggest && !fastest;
} }
/** /**
@ -856,10 +855,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override @Override
public String toString() { public String toString() {
return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription=" return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription="
+ imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location=" + imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location=" + location
+ location + ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + osName
+ osName + ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", os64Bit="
+ ", os64Bit=" + os64Bit + ", hardwareId=" + hardwareId + "]"; + os64Bit + ", hardwareId=" + hardwareId + "]";
} }
@Override @Override

View File

@ -45,9 +45,9 @@ public class AWSEC2TemplateBuilderImpl extends EC2TemplateBuilderImpl {
@Inject @Inject
protected AWSEC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations, protected AWSEC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider, Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Map<RegionAndName, Image> imageMap) { @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Map<RegionAndName, Image> imageMap) {
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, imageMap); super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, imageMap);
} }