aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmclaugh...@apache.org
Subject aurora git commit: Allow custom OfferManager ordering to be injected via Guice modules
Date Fri, 02 Jun 2017 20:54:54 GMT
Repository: aurora
Updated Branches:
  refs/heads/master accd46aef -> 8a4140de5


Allow custom OfferManager ordering to be injected via Guice modules

Reviewed at https://reviews.apache.org/r/59698/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/8a4140de
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/8a4140de
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/8a4140de

Branch: refs/heads/master
Commit: 8a4140de53dbc220d5e9e5f9cb3e90755af50cc1
Parents: accd46a
Author: David McLaughlin <david@dmclaughlin.com>
Authored: Fri Jun 2 13:43:43 2017 -0700
Committer: David McLaughlin <david@dmclaughlin.com>
Committed: Fri Jun 2 13:43:43 2017 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/offers/OfferManager.java   |  6 +--
 .../aurora/scheduler/offers/OfferSettings.java  | 14 +++++-
 .../aurora/scheduler/offers/OffersModule.java   | 45 ++++++++++++++++----
 3 files changed, 51 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/8a4140de/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java b/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java
index 96acaf9..17e577b 100644
--- a/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java
@@ -13,7 +13,6 @@
  */
 package org.apache.aurora.scheduler.offers;
 
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentSkipListSet;
@@ -30,6 +29,7 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
+import com.google.common.collect.Ordering;
 import com.google.common.eventbus.Subscribe;
 
 import org.apache.aurora.common.inject.TimedInterceptor.Timed;
@@ -276,8 +276,8 @@ public interface OfferManager extends EventSubscriber {
       // scheduling attempts. See VetoGroup for more details on static ban.
       private final Multimap<OfferID, TaskGroupKey> staticallyBannedOffers = HashMultimap.create();
 
-      HostOffers(StatsProvider statsProvider, List<OfferOrder> offerOrder) {
-        offers = new ConcurrentSkipListSet<>(OfferOrderBuilder.create(offerOrder));
+      HostOffers(StatsProvider statsProvider, Ordering<HostOffer> offerOrder) {
+        offers = new ConcurrentSkipListSet<>(offerOrder);
         // Potential gotcha - since this is a ConcurrentSkipListSet, size() is more expensive.
         // Could track this separately if it turns out to pose problems.
         statsProvider.exportSize(OUTSTANDING_OFFERS, offers);

http://git-wip-us.apache.org/repos/asf/aurora/blob/8a4140de/src/main/java/org/apache/aurora/scheduler/offers/OfferSettings.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/offers/OfferSettings.java b/src/main/java/org/apache/aurora/scheduler/offers/OfferSettings.java
index ee80176..4c6fd54 100644
--- a/src/main/java/org/apache/aurora/scheduler/offers/OfferSettings.java
+++ b/src/main/java/org/apache/aurora/scheduler/offers/OfferSettings.java
@@ -16,9 +16,11 @@ package org.apache.aurora.scheduler.offers;
 import java.util.List;
 
 import com.google.common.base.Supplier;
+import com.google.common.collect.Ordering;
 
 import org.apache.aurora.common.quantity.Amount;
 import org.apache.aurora.common.quantity.Time;
+import org.apache.aurora.scheduler.HostOffer;
 
 import static java.util.Objects.requireNonNull;
 
@@ -29,13 +31,21 @@ public class OfferSettings {
 
   private final Amount<Long, Time> offerFilterDuration;
   private final Supplier<Amount<Long, Time>> returnDelaySupplier;
-  private final List<OfferOrder> offerOrder;
+  private final Ordering<HostOffer> offerOrder;
 
   public OfferSettings(
       Amount<Long, Time> offerFilterDuration,
       Supplier<Amount<Long, Time>> returnDelaySupplier,
       List<OfferOrder> offerOrder) {
 
+    this(offerFilterDuration, returnDelaySupplier, OfferOrderBuilder.create(offerOrder));
+  }
+
+  OfferSettings(
+      Amount<Long, Time> offerFilterDuration,
+      Supplier<Amount<Long, Time>> returnDelaySupplier,
+      Ordering<HostOffer> offerOrder) {
+
     this.offerFilterDuration = requireNonNull(offerFilterDuration);
     this.returnDelaySupplier = requireNonNull(returnDelaySupplier);
     this.offerOrder = requireNonNull(offerOrder);
@@ -59,7 +69,7 @@ public class OfferSettings {
   /**
    * The ordering to use when fetching offers from OfferManager.
    */
-  public List<OfferOrder> getOfferOrder() {
+  public Ordering<HostOffer> getOfferOrder() {
     return offerOrder;
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/8a4140de/src/main/java/org/apache/aurora/scheduler/offers/OffersModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/offers/OffersModule.java b/src/main/java/org/apache/aurora/scheduler/offers/OffersModule.java
index e999ac5..bbccb17 100644
--- a/src/main/java/org/apache/aurora/scheduler/offers/OffersModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/offers/OffersModule.java
@@ -16,12 +16,17 @@ package org.apache.aurora.scheduler.offers;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 import java.util.List;
+import java.util.Set;
 import javax.inject.Qualifier;
 import javax.inject.Singleton;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Ordering;
 import com.google.inject.AbstractModule;
+import com.google.inject.Module;
 import com.google.inject.PrivateModule;
+import com.google.inject.Provides;
 import com.google.inject.TypeLiteral;
 
 import org.apache.aurora.common.args.Arg;
@@ -30,6 +35,8 @@ import org.apache.aurora.common.args.constraints.NotNegative;
 import org.apache.aurora.common.quantity.Amount;
 import org.apache.aurora.common.quantity.Time;
 import org.apache.aurora.common.util.Random;
+import org.apache.aurora.scheduler.HostOffer;
+import org.apache.aurora.scheduler.app.MoreModules;
 import org.apache.aurora.scheduler.events.PubsubEventModule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -78,6 +85,19 @@ public class OffersModule extends AbstractModule {
   private static final Arg<List<OfferOrder>> OFFER_ORDER =
       Arg.create(ImmutableList.of(OfferOrder.RANDOM));
 
+  @CmdLine(name = "offer_order_modules",
+      help = "Custom Guice module to provide an offer ordering.")
+  private static final Arg<Set<Module>> OFFER_ORDER_MODULES = Arg.create(
+      ImmutableSet.of(MoreModules.lazilyInstantiated(OfferOrderModule.class)));
+
+  public static class OfferOrderModule extends AbstractModule {
+    @Override
+    protected void configure() {
+      bind(new TypeLiteral<Ordering<HostOffer>>() { })
+          .toInstance(OfferOrderBuilder.create(OFFER_ORDER.get()));
+    }
+  }
+
   /**
    * Binding annotation for the threshold to veto tasks with unavailability.
    */
@@ -98,6 +118,10 @@ public class OffersModule extends AbstractModule {
           OFFER_HOLD_JITTER_WINDOW.get());
     }
 
+    for (Module module: OFFER_ORDER_MODULES.get()) {
+      install(module);
+    }
+
     bind(new TypeLiteral<Amount<Long, Time>>() { })
         .annotatedWith(UnavailabilityThreshold.class)
         .toInstance(UNAVAILABILITY_THRESHOLD.get());
@@ -105,20 +129,23 @@ public class OffersModule extends AbstractModule {
     install(new PrivateModule() {
       @Override
       protected void configure() {
-        bind(OfferSettings.class).toInstance(
-            new OfferSettings(
-                OFFER_FILTER_DURATION.get(),
-                new RandomJitterReturnDelay(
-                    MIN_OFFER_HOLD_TIME.get().as(Time.MILLISECONDS),
-                    OFFER_HOLD_JITTER_WINDOW.get().as(Time.MILLISECONDS),
-                    Random.Util.newDefaultRandom()),
-                OFFER_ORDER.get()));
         bind(OfferManager.class).to(OfferManager.OfferManagerImpl.class);
         bind(OfferManager.OfferManagerImpl.class).in(Singleton.class);
         expose(OfferManager.class);
-        expose(OfferSettings.class);
       }
     });
     PubsubEventModule.bindSubscriber(binder(), OfferManager.class);
   }
+
+  @Provides
+  @Singleton
+  OfferSettings provideOfferSettings(Ordering<HostOffer> offerOrdering) {
+    return new OfferSettings(
+        OFFER_FILTER_DURATION.get(),
+        new RandomJitterReturnDelay(
+            MIN_OFFER_HOLD_TIME.get().as(Time.MILLISECONDS),
+            OFFER_HOLD_JITTER_WINDOW.get().as(Time.MILLISECONDS),
+            Random.Util.newDefaultRandom()),
+        offerOrdering);
+  }
 }


Mime
View raw message