From 44c5fc714a40d60f74d7978a8a4e23e54fc8c196 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 24 Aug 2010 17:00:19 -0700 Subject: [PATCH] fixed default template for ec2 to use osVersion to match default image. improved error messages in templateBuilder --- .../EC2ComputeServiceContextModule.java | 2 +- .../domain/internal/TemplateBuilderImpl.java | 92 +++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index b54486f673..f57ec8e4b7 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -170,7 +170,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { String region = injector.getInstance(Key.get(String.class, Region.class)); return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() : template.os64Bit(false).osFamily( - UBUNTU).imageNameMatches(".*10\\.?04.*").osDescriptionMatches("^ubuntu-images.*"); + UBUNTU).osVersionMatches(".*10\\.?04.*").osDescriptionMatches("^ubuntu-images.*"); } @Provides diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java index e7439066ce..0fe1a46fcb 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java @@ -139,6 +139,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { && location.getParent().equals(input.getLocation()); return returnVal; } + + @Override + public String toString() { + return "location(" + location + ")"; + } }; private final Predicate idPredicate = new Predicate() { @@ -154,6 +159,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "imageId(" + imageId + ")"; + } }; private final Predicate osFamilyPredicate = new Predicate() { @@ -180,6 +190,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "osName(" + osName + ")"; + } }; private final Predicate osDescriptionPredicate = new Predicate() { @@ -195,6 +210,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "osDescription(" + osDescription + ")"; + } }; private final Predicate osVersionPredicate = new Predicate() { @@ -209,6 +229,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "osVersion(" + osVersion + ")"; + } }; private final Predicate os64BitPredicate = new Predicate() { @@ -223,6 +248,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "os64Bit(" + os64Bit + ")"; + } }; private final Predicate osArchPredicate = new Predicate() { @@ -237,6 +267,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "osArch(" + osArch + ")"; + } }; private final Predicate imageVersionPredicate = new Predicate() { @@ -251,6 +286,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "imageVersion(" + imageVersion + ")"; + } }; private final Predicate imageNamePredicate = new Predicate() { @@ -265,6 +305,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "imageName(" + imageName + ")"; + } }; private final Predicate imageDescriptionPredicate = new Predicate() { @Override @@ -280,6 +325,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "imageDescription(" + imageDescription + ")"; + } }; private final Predicate sizeIdPredicate = new Predicate() { @Override @@ -294,6 +344,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { } return returnVal; } + + @Override + public String toString() { + return "sizeId(" + sizeId + ")"; + } }; private final Predicate sizeCoresPredicate = new Predicate() { @@ -301,6 +356,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { public boolean apply(Size input) { return input.getCores() >= TemplateBuilderImpl.this.minCores; } + + @Override + public String toString() { + return "minCores(" + minCores + ")"; + } }; private final Predicate sizeRamPredicate = new Predicate() { @@ -308,6 +368,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { public boolean apply(Size input) { return input.getRam() >= TemplateBuilderImpl.this.minRam; } + + @Override + public String toString() { + return "minRam(" + minRam + ")"; + } }; private final Predicate sizePredicate = and(sizeIdPredicate, locationPredicate, sizeCoresPredicate, sizeRamPredicate); @@ -426,6 +491,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { return input.getId().equals(locationId); } + @Override + public String toString() { + return "locationId(" + locationId + ")"; + } + }); return this; } @@ -456,7 +526,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { options = optionsProvider.get(); logger.debug(">> searching params(%s)", this); Set images = getImages(); + Predicate imagePredicate = buildImagePredicate(); Iterable supportedImages = filter(images, buildImagePredicate()); + if (Iterables.size(supportedImages) == 0) + throw new NoSuchElementException(String.format( + "no image matched predicate %s images that didn't match below:\n%s", imagePredicate, images)); Size size = resolveSize(sizeSorter(), supportedImages); Image image = resolveImage(size, supportedImages); logger.debug("<< matched image(%s)", image); @@ -478,6 +552,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { return size.supportsImage(input); } + @Override + public String toString() { + return "size(" + size + ").supportsImage()"; + } + }); } @@ -515,6 +594,10 @@ public class TemplateBuilderImpl implements TemplateBuilder { return size.supportsImage(arg0); } + @Override + public String toString() { + return "size(" + size + ").supportsImage()"; + } }; try { Iterable matchingImages = filter(supportedImages, imagePredicate); @@ -546,6 +629,10 @@ public class TemplateBuilderImpl implements TemplateBuilder { return locationPredicate.apply(input); } + @Override + public String toString() { + return locationPredicate.toString(); + } }); final List> osPredicates = newArrayList(); @@ -568,6 +655,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { return Predicates.and(osPredicates).apply(input.getOperatingSystem()); } + @Override + public String toString() { + return Predicates.and(osPredicates).toString(); + } + }); if (imageVersion != null) predicates.add(imageVersionPredicate);