mirror of https://github.com/apache/jclouds.git
fixed default template for ec2 to use osVersion to match default image. improved error messages in templateBuilder
This commit is contained in:
parent
96fb5f42aa
commit
44c5fc714a
|
@ -170,7 +170,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
|
||||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||||
String region = injector.getInstance(Key.get(String.class, Region.class));
|
String region = injector.getInstance(Key.get(String.class, Region.class));
|
||||||
return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() : template.os64Bit(false).osFamily(
|
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
|
@Provides
|
||||||
|
|
|
@ -139,6 +139,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
&& location.getParent().equals(input.getLocation());
|
&& location.getParent().equals(input.getLocation());
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "location(" + location + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<Image> idPredicate = new Predicate<Image>() {
|
private final Predicate<Image> idPredicate = new Predicate<Image>() {
|
||||||
|
@ -154,6 +159,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "imageId(" + imageId + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<OperatingSystem> osFamilyPredicate = new Predicate<OperatingSystem>() {
|
private final Predicate<OperatingSystem> osFamilyPredicate = new Predicate<OperatingSystem>() {
|
||||||
|
@ -180,6 +190,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "osName(" + osName + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<OperatingSystem> osDescriptionPredicate = new Predicate<OperatingSystem>() {
|
private final Predicate<OperatingSystem> osDescriptionPredicate = new Predicate<OperatingSystem>() {
|
||||||
|
@ -195,6 +210,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "osDescription(" + osDescription + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<OperatingSystem> osVersionPredicate = new Predicate<OperatingSystem>() {
|
private final Predicate<OperatingSystem> osVersionPredicate = new Predicate<OperatingSystem>() {
|
||||||
|
@ -209,6 +229,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "osVersion(" + osVersion + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<OperatingSystem> os64BitPredicate = new Predicate<OperatingSystem>() {
|
private final Predicate<OperatingSystem> os64BitPredicate = new Predicate<OperatingSystem>() {
|
||||||
|
@ -223,6 +248,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "os64Bit(" + os64Bit + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<OperatingSystem> osArchPredicate = new Predicate<OperatingSystem>() {
|
private final Predicate<OperatingSystem> osArchPredicate = new Predicate<OperatingSystem>() {
|
||||||
|
@ -237,6 +267,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "osArch(" + osArch + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<Image> imageVersionPredicate = new Predicate<Image>() {
|
private final Predicate<Image> imageVersionPredicate = new Predicate<Image>() {
|
||||||
|
@ -251,6 +286,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "imageVersion(" + imageVersion + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<Image> imageNamePredicate = new Predicate<Image>() {
|
private final Predicate<Image> imageNamePredicate = new Predicate<Image>() {
|
||||||
|
@ -265,6 +305,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "imageName(" + imageName + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
private final Predicate<Image> imageDescriptionPredicate = new Predicate<Image>() {
|
private final Predicate<Image> imageDescriptionPredicate = new Predicate<Image>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -280,6 +325,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "imageDescription(" + imageDescription + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
private final Predicate<Size> sizeIdPredicate = new Predicate<Size>() {
|
private final Predicate<Size> sizeIdPredicate = new Predicate<Size>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -294,6 +344,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "sizeId(" + sizeId + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<Size> sizeCoresPredicate = new Predicate<Size>() {
|
private final Predicate<Size> sizeCoresPredicate = new Predicate<Size>() {
|
||||||
|
@ -301,6 +356,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
public boolean apply(Size input) {
|
public boolean apply(Size input) {
|
||||||
return input.getCores() >= TemplateBuilderImpl.this.minCores;
|
return input.getCores() >= TemplateBuilderImpl.this.minCores;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "minCores(" + minCores + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Predicate<Size> sizeRamPredicate = new Predicate<Size>() {
|
private final Predicate<Size> sizeRamPredicate = new Predicate<Size>() {
|
||||||
|
@ -308,6 +368,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
public boolean apply(Size input) {
|
public boolean apply(Size input) {
|
||||||
return input.getRam() >= TemplateBuilderImpl.this.minRam;
|
return input.getRam() >= TemplateBuilderImpl.this.minRam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "minRam(" + minRam + ")";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
private final Predicate<Size> sizePredicate = and(sizeIdPredicate, locationPredicate, sizeCoresPredicate,
|
private final Predicate<Size> sizePredicate = and(sizeIdPredicate, locationPredicate, sizeCoresPredicate,
|
||||||
sizeRamPredicate);
|
sizeRamPredicate);
|
||||||
|
@ -426,6 +491,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return input.getId().equals(locationId);
|
return input.getId().equals(locationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "locationId(" + locationId + ")";
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -456,7 +526,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
options = optionsProvider.get();
|
options = optionsProvider.get();
|
||||||
logger.debug(">> searching params(%s)", this);
|
logger.debug(">> searching params(%s)", this);
|
||||||
Set<? extends Image> images = getImages();
|
Set<? extends Image> images = getImages();
|
||||||
|
Predicate<Image> imagePredicate = buildImagePredicate();
|
||||||
Iterable<? extends Image> supportedImages = filter(images, 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);
|
Size size = resolveSize(sizeSorter(), supportedImages);
|
||||||
Image image = resolveImage(size, supportedImages);
|
Image image = resolveImage(size, supportedImages);
|
||||||
logger.debug("<< matched image(%s)", image);
|
logger.debug("<< matched image(%s)", image);
|
||||||
|
@ -478,6 +552,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return size.supportsImage(input);
|
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);
|
return size.supportsImage(arg0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "size(" + size + ").supportsImage()";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
Iterable<? extends Image> matchingImages = filter(supportedImages, imagePredicate);
|
Iterable<? extends Image> matchingImages = filter(supportedImages, imagePredicate);
|
||||||
|
@ -546,6 +629,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return locationPredicate.apply(input);
|
return locationPredicate.apply(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return locationPredicate.toString();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final List<Predicate<OperatingSystem>> osPredicates = newArrayList();
|
final List<Predicate<OperatingSystem>> osPredicates = newArrayList();
|
||||||
|
@ -568,6 +655,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return Predicates.and(osPredicates).apply(input.getOperatingSystem());
|
return Predicates.and(osPredicates).apply(input.getOperatingSystem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Predicates.and(osPredicates).toString();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
if (imageVersion != null)
|
if (imageVersion != null)
|
||||||
predicates.add(imageVersionPredicate);
|
predicates.add(imageVersionPredicate);
|
||||||
|
|
Loading…
Reference in New Issue