fixed default template for ec2 to use osVersion to match default image. improved error messages in templateBuilder

This commit is contained in:
Adrian Cole 2010-08-24 17:00:19 -07:00
parent 96fb5f42aa
commit 44c5fc714a
2 changed files with 93 additions and 1 deletions

View File

@ -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

View File

@ -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<Image> idPredicate = new Predicate<Image>() {
@ -154,6 +159,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "imageId(" + imageId + ")";
}
};
private final Predicate<OperatingSystem> osFamilyPredicate = new Predicate<OperatingSystem>() {
@ -180,6 +190,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "osName(" + osName + ")";
}
};
private final Predicate<OperatingSystem> osDescriptionPredicate = new Predicate<OperatingSystem>() {
@ -195,6 +210,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "osDescription(" + osDescription + ")";
}
};
private final Predicate<OperatingSystem> osVersionPredicate = new Predicate<OperatingSystem>() {
@ -209,6 +229,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "osVersion(" + osVersion + ")";
}
};
private final Predicate<OperatingSystem> os64BitPredicate = new Predicate<OperatingSystem>() {
@ -223,6 +248,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "os64Bit(" + os64Bit + ")";
}
};
private final Predicate<OperatingSystem> osArchPredicate = new Predicate<OperatingSystem>() {
@ -237,6 +267,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "osArch(" + osArch + ")";
}
};
private final Predicate<Image> imageVersionPredicate = new Predicate<Image>() {
@ -251,6 +286,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "imageVersion(" + imageVersion + ")";
}
};
private final Predicate<Image> imageNamePredicate = new Predicate<Image>() {
@ -265,6 +305,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "imageName(" + imageName + ")";
}
};
private final Predicate<Image> imageDescriptionPredicate = new Predicate<Image>() {
@Override
@ -280,6 +325,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "imageDescription(" + imageDescription + ")";
}
};
private final Predicate<Size> sizeIdPredicate = new Predicate<Size>() {
@Override
@ -294,6 +344,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
}
return returnVal;
}
@Override
public String toString() {
return "sizeId(" + sizeId + ")";
}
};
private final Predicate<Size> sizeCoresPredicate = new Predicate<Size>() {
@ -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<Size> sizeRamPredicate = new Predicate<Size>() {
@ -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<Size> 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<? extends Image> images = getImages();
Predicate<Image> imagePredicate = buildImagePredicate();
Iterable<? extends Image> 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<? extends Image> 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<Predicate<OperatingSystem>> 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);