Github user Graeme-Miller commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/128#discussion_r61403861
--- Diff:
locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynImageChooser.java
---
@@ -292,27 +325,63 @@ public int compare(Image left, Image right) {
};
}
- public static class ImageChooserFromOrdering implements
Function<Iterable<? extends Image>, Image>,
ComputeServiceAwareChooser<ImageChooserFromOrdering> {
- final Ordering<Image> ordering;
- public ImageChooserFromOrdering(final Ordering<Image> ordering) {
this.ordering = ordering; }
+ public static class ImageChooserFromOrdering implements
Function<Iterable<? extends Image>, Image>,
+ ComputeServiceAwareChooser<ImageChooserFromOrdering>,
ConfigAwareChooser<ImageChooserFromOrdering> {
+ final List<Ordering<? super Image>> orderings;
+
+ public ImageChooserFromOrdering(final Ordering<Image> ordering) {
+ this(ImmutableList.of(ordering));
+ }
+ public ImageChooserFromOrdering(Iterable<? extends Ordering<?
super Image>> orderings) {
+ this.orderings = ImmutableList.copyOf(checkNotNull(orderings,
"orderings"));
+ }
@Override
public Image apply(Iterable<? extends Image> input) {
- List<? extends Image> maxImages = multiMax(ordering, input);
+ List<? extends Image> maxImages =
multiMax(Ordering.compound(orderings), input);
return maxImages.get(maxImages.size() - 1);
}
@Override
public ImageChooserFromOrdering cloneFor(ComputeService service) {
- if (ordering instanceof ComputeServiceAwareChooser) {
- return new ImageChooserFromOrdering(
BrooklynImageChooser.cloneFor(ordering, service) );
+ if (Iterables.tryFind(orderings,
Predicates.instanceOf(ComputeServiceAwareChooser.class)).isPresent()) {
+ List<Ordering<? super Image>> clonedOrderings =
Lists.newArrayList();
+ for (Ordering<? super Image> ordering : orderings) {
+ if (ordering instanceof ComputeServiceAwareChooser) {
+
clonedOrderings.add(BrooklynImageChooser.cloneFor(ordering, service));
+ } else {
+ clonedOrderings.add(ordering);
+ }
+ }
+ return new ImageChooserFromOrdering(clonedOrderings);
+ } else {
+ return this;
+ }
+ }
+ @Override
+ public ImageChooserFromOrdering cloneFor(ConfigBag config) {
+ if (Iterables.tryFind(orderings,
Predicates.instanceOf(ConfigAwareChooser.class)).isPresent()) {
+ List<Ordering<? super Image>> clonedOrderings =
Lists.newArrayList();
+ for (Ordering<? super Image> ordering : orderings) {
+ if (ordering instanceof ConfigAwareChooser) {
--- End diff --
Slightly concerned about the use of instanceof here, but I can see we are
using the same approach as the ComputeServiceAwareChooser
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---