jordanly commented on a change in pull request #37: Staggered (Variable batch) 
Updates
URL: https://github.com/apache/aurora/pull/37#discussion_r221013032
 
 

 ##########
 File path: 
src/main/java/org/apache/aurora/scheduler/updater/strategy/VariableBatchStrategy.java
 ##########
 @@ -0,0 +1,152 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.updater.strategy;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Ordering;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A strategy that limits the number of instances selected by the subclass 
using variable steps.
+ *
+ * @param <T> Instance type.
+ */
+public class VariableBatchStrategy<T extends Comparable<T>> implements 
UpdateStrategy<T> {
+  private final Ordering<T> ordering;
+  protected final ImmutableList<Integer> maxActiveGroups;
+  private final boolean rollingForward;
+  private Optional<Integer> totalModInstanceCount;
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(VariableBatchStrategy.class);
+
+  /**
+   * Creates a variable active-limited strategy that applies an upper bound to 
all results.
+   *
+   * @param maxActiveGroups  List of Maximum group sizes. Each group size 
represents a step.
+   * {@link #getNextGroup(Set, Set)}.
+   */
+  public VariableBatchStrategy(Ordering<T> ordering,
+      List<Integer> maxActiveGroups,
+      boolean rollingForward) {
+
+    this.ordering = Objects.requireNonNull(ordering);
+    this.rollingForward = rollingForward;
+
+    maxActiveGroups.forEach(x -> Preconditions.checkArgument(x > 0));
+
+    this.maxActiveGroups = ImmutableList.copyOf(maxActiveGroups);
+    this.totalModInstanceCount = Optional.empty();
+  }
+
+  // Determine how far we're into the update based upon how many instances are 
waiting
+  // to be modified.
+  private int determineCurGroupSize(int remaining) {
+
+    // Calculate which groupIndex we are in by finding out how many instances 
we have left to update
+    int modified = totalModInstanceCount.get() - remaining;
+
+    int lastGroupSize = maxActiveGroups.get(maxActiveGroups.size() - 1);
+
+    LOG.debug("Variable Batch Update progress: {} instances have been 
modified, "
+            + "{} instances remain unmodified, and {} overall instances to be 
modified.",
+        modified,
+        remaining,
+        totalModInstanceCount.get());
+
+    if (rollingForward) {
+
 
 Review comment:
   nit: remove extra newline

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to