You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wf...@apache.org on 2015/08/28 20:33:34 UTC
[16/21] aurora git commit: Remove unused classes from commons fork.
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/CounterMapWithTopKey.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/CounterMapWithTopKey.java b/commons/src/main/java/org/apache/aurora/common/stats/CounterMapWithTopKey.java
deleted file mode 100644
index 1e90e85..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/CounterMapWithTopKey.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * 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.common.stats;
-
-import java.util.Map;
-
-/**
- * Same as CounterMap<K>, but also keeps track of the item with the highest count.
- */
-public class CounterMapWithTopKey<K> extends CounterMap<K> {
-
- private K mostCommonKey = null;
-
- /**
- * Updates the most common key, if needed.
- *
- * @param key The key to check.
- * @param count The count for the key.
- * @return The count.
- */
- private int updateMostCommon(K key, int count) {
- if (count > get(mostCommonKey)) {
- mostCommonKey = key;
- }
- return count;
- }
-
- /**
- * Increments the counter value associated with {@code key}, and returns the new value.
- *
- * @param key The key to increment
- * @return The incremented value.
- */
- @Override
- public int incrementAndGet(K key) {
- return updateMostCommon(key, super.incrementAndGet(key));
- }
-
- /**
- * Assigns a value to a key.
- *
- * @param key The key to assign a value to.
- * @param newValue The value to assign.
- */
- @Override
- public void set(K key, int newValue) {
- super.set(key, updateMostCommon(key, newValue));
- }
-
- /**
- * Resets the value for {@code key}. This will simply set the stored value to 0.
- * The most common key is updated by scanning the entire map.
- *
- * @param key The key to reset.
- */
- @Override
- public void reset(K key) {
- super.reset(key);
- for (Map.Entry<K, Integer> entry : this) {
- updateMostCommon(entry.getKey(), entry.getValue());
- }
- }
-
- /**
- *
- * @return The key with the highest count in the map. If multiple keys have this count, return
- * an arbitrary one.
- */
- public K getMostCommonKey() {
- return mostCommonKey;
- }
-
- @Override
- public String toString() {
- return new StringBuilder(super.toString()).append(String.format("Most common key: %s\n",
- mostCommonKey.toString())).toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/Elapsed.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Elapsed.java b/commons/src/main/java/org/apache/aurora/common/stats/Elapsed.java
deleted file mode 100644
index 859ca7e..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/Elapsed.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * 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.common.stats;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Ticker;
-
-import org.apache.aurora.common.base.MorePreconditions;
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Time;
-
-/**
- * A stat that exports the amount of time since it was last reset.
- *
- * @author William Farner
- */
-public class Elapsed {
-
- private final Ticker ticker;
- private final AtomicLong lastEventNs = new AtomicLong();
-
- /**
- * Calls {@link #Elapsed(String, Time)} using a default granularity of nanoseconds.
- *
- * @param name Name of the stat to export.
- */
- public Elapsed(String name) {
- this(name, Time.NANOSECONDS);
- }
-
- /**
- * Equivalent to calling {@link #Elapsed(String, Time, Ticker)} passing {@code name},
- * {@code granularity} and {@link com.google.common.base.Ticker#systemTicker()}.
- * <br/>
- * @param name Name of the stat to export.
- * @param granularity Time unit granularity to export.
- */
- public Elapsed(String name, Time granularity) {
- this(name, granularity, Ticker.systemTicker());
- }
-
- /**
- * Creates and exports a new stat that maintains the difference between the tick time
- * and the time since it was last reset. Upon export, the counter will act as though it were just
- * reset.
- * <br/>
- * @param name Name of stat to export
- * @param granularity Time unit granularity to export.
- * @param ticker Ticker implementation
- */
- public Elapsed(String name, final Time granularity, final Ticker ticker) {
- MorePreconditions.checkNotBlank(name);
- Preconditions.checkNotNull(granularity);
- this.ticker = Preconditions.checkNotNull(ticker);
-
- reset();
-
- Stats.export(new StatImpl<Long>(name) {
- @Override public Long read() {
- return Amount.of(ticker.read() - lastEventNs.get(), Time.NANOSECONDS).as(granularity);
- }
- });
- }
-
- public void reset() {
- lastEventNs.set(ticker.read());
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/Entropy.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Entropy.java b/commons/src/main/java/org/apache/aurora/common/stats/Entropy.java
deleted file mode 100644
index 4e011c1..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/Entropy.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.common.stats;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Calculate the entropy of a discrete distribution of <T>.
- *
- * @author Gilad Mishne
- */
-public class Entropy<T> {
- private final CounterMap<T> counts = new CounterMap<T>();
- private int total = 0;
-
- private static double Log2(double n) {
- return Math.log(n) / Math.log(2);
- }
-
- public Entropy(Iterable<T> elements) {
- Preconditions.checkNotNull(elements);
- for (T element : elements) {
- counts.incrementAndGet(element);
- total++;
- }
- }
-
- public double entropy() {
- double entropy = 0;
- for (int count: counts.values()) {
- double prob = (double) count / total;
- entropy -= prob * Log2(prob);
- }
- return entropy;
- }
-
- public double perplexity() {
- return Math.pow(2, entropy());
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/Histogram.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Histogram.java b/commons/src/main/java/org/apache/aurora/common/stats/Histogram.java
deleted file mode 100644
index 53c976d..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/Histogram.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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.common.stats;
-
-/**
- * An interface for Histogram
- */
-public interface Histogram {
-
- /**
- * Add an entry into the histogram.
- * @param x the value to insert.
- */
- void add(long x);
-
- /**
- * Clear the histogram.
- */
- void clear();
-
- /**
- * Return the current quantile of the histogram.
- * @param quantile value to compute.
- */
- long getQuantile(double quantile);
-
- /**
- * Return the quantiles of the histogram.
- * @param quantiles array of values to compute.
- */
- long[] getQuantiles(double[] quantiles);
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/Histograms.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Histograms.java b/commons/src/main/java/org/apache/aurora/common/stats/Histograms.java
deleted file mode 100644
index 6818b05..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/Histograms.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.common.stats;
-
-/**
- * Helper class containing only static methods
- */
-public final class Histograms {
-
- private Histograms() {
- /* Disable */
- }
-
- /**
- * Helper method that return an array of quantiles
- * @param h the histogram to query
- * @param quantiles an array of double representing the quantiles
- * @return the array of computed quantiles
- */
- public static long[] extractQuantiles(Histogram h, double[] quantiles) {
- long[] results = new long[quantiles.length];
- for (int i = 0; i < results.length; i++) {
- double q = quantiles[i];
- results[i] = h.getQuantile(q);
- }
- return results;
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/MovingAverage.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/MovingAverage.java b/commons/src/main/java/org/apache/aurora/common/stats/MovingAverage.java
deleted file mode 100644
index 339737b..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/MovingAverage.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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.common.stats;
-
-import java.util.concurrent.LinkedBlockingDeque;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Function to compute the moving average of a time series.
- *
- * @author William Farner
- */
-public class MovingAverage<T extends Number> extends SampledStat<Double> {
-
- private static final int DEFAULT_WINDOW = 10;
- private final Stat<T> input;
-
- private final LinkedBlockingDeque<T> samples;
- private double sampleSum = 0;
-
- private MovingAverage(String name, Stat<T> input, int windowSize) {
- super(name, 0d);
- Preconditions.checkArgument(windowSize > 1);
-
- this.input = Preconditions.checkNotNull(input);
- this.samples = new LinkedBlockingDeque<T>(windowSize);
- Stats.export(input);
- }
-
- public static <T extends Number> MovingAverage<T> of(Stat<T> input) {
- return MovingAverage.of(input, DEFAULT_WINDOW);
- }
-
- public static <T extends Number> MovingAverage<T> of(Stat<T> input, int windowSize) {
- return MovingAverage.of(String.format("%s_avg", input.getName()), input, windowSize);
- }
-
- public static <T extends Number> MovingAverage<T> of(String name, Stat<T> input,
- int windowSize) {
- return new MovingAverage<T>(name, input, windowSize);
- }
-
- @Override
- public Double doSample() {
- T sample = input.read();
-
- if (samples.remainingCapacity() == 0) {
- sampleSum -= samples.removeLast().doubleValue();
- }
-
- samples.addFirst(sample);
- sampleSum += sample.doubleValue();
-
- return sampleSum / samples.size();
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/MovingWindowDelta.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/MovingWindowDelta.java b/commons/src/main/java/org/apache/aurora/common/stats/MovingWindowDelta.java
deleted file mode 100644
index a20eed0..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/MovingWindowDelta.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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.common.stats;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Supplier;
-
-import java.util.concurrent.LinkedBlockingDeque;
-
-import org.apache.aurora.common.base.MorePreconditions;
-
-
-/**
- * Delta over the most recent k sample periods.
- *
- * If you use this class with a counter, you can get the cumulation of counts in a sliding window.
- *
- * One sample period is the time in between doSample() calls.
- *
- * @author Feng Zhuge
- */
-public class MovingWindowDelta<T extends Number> extends SampledStat<Long> {
- private static final int DEFAULT_WINDOW_SIZE = 60;
- private final LinkedBlockingDeque<Long> deltaSeries;
- private final Supplier<T> inputAccessor;
- long sumDelta = 0l;
- long lastInput = 0l;
-
- private MovingWindowDelta(String name, Supplier<T> inputAccessor, int windowSize) {
- super(name, 0l);
-
- Preconditions.checkArgument(windowSize >= 1);
- Preconditions.checkNotNull(inputAccessor);
- MorePreconditions.checkNotBlank(name);
-
- deltaSeries = new LinkedBlockingDeque<Long>(windowSize);
- this.inputAccessor = inputAccessor;
-
- Stats.export(this);
- }
-
- /**
- * Create a new MovingWindowDelta instance.
- *
- * @param name The name of the value to be tracked.
- * @param inputAccessor The accessor of the value.
- * @param windowSize How many sample periods shall we use to calculate delta.
- * @param <T> The type of the value.
- * @return The created MovingWindowSum instance.
- */
- public static <T extends Number> MovingWindowDelta<T> of(
- String name, Supplier<T> inputAccessor, int windowSize) {
- return new MovingWindowDelta<T>(name, inputAccessor, windowSize);
- }
-
- /**
- * Create a new MovingWindowDelta instance using the default window size (currently 60).
- *
- * @param name The name of the value to be tracked.
- * @param inputAccessor The accessor of the value.
- * @param <T> The type of the value.
- * @return The created MovingWindowSum instance.
- */
- public static <T extends Number> MovingWindowDelta<T> of(String name, Supplier<T> inputAccessor) {
- return of(name, inputAccessor, DEFAULT_WINDOW_SIZE);
- }
-
- @Override
- public Long doSample() {
- long lastDelta = 0l;
- if (deltaSeries.remainingCapacity() == 0) {
- lastDelta = deltaSeries.removeFirst();
- }
-
- long newInput = inputAccessor.get().longValue();
- long newDelta = newInput - lastInput;
- lastInput = newInput;
-
- deltaSeries.addLast(newDelta);
-
- sumDelta += newDelta - lastDelta;
-
- return sumDelta;
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/NumericStatExporter.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/NumericStatExporter.java b/commons/src/main/java/org/apache/aurora/common/stats/NumericStatExporter.java
deleted file mode 100644
index 7345edc..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/NumericStatExporter.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
- * 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.common.stats;
-
-import java.util.Map;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Maps;
-
-import org.apache.aurora.common.application.ShutdownRegistry;
-import org.apache.aurora.common.base.Closure;
-import org.apache.aurora.common.base.Command;
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Time;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Stat exporter that extracts numeric {@link Stat}s from the {@link Stats} system, and exports them
- * via a caller-defined sink.
- *
- * @author William Farner
- */
-public class NumericStatExporter {
-
- private static final Logger LOG = Logger.getLogger(NumericStatExporter.class.getName());
-
- private final ScheduledExecutorService executor;
- private final Amount<Long, Time> exportInterval;
- private final Closure<Map<String, ? extends Number>> exportSink;
-
- private final Runnable exporter;
-
- /**
- * Creates a new numeric stat exporter that will export to the specified sink.
- *
- * @param exportSink Consumes stats.
- * @param executor Executor to handle export thread.
- * @param exportInterval Export period.
- */
- public NumericStatExporter(final Closure<Map<String, ? extends Number>> exportSink,
- ScheduledExecutorService executor, Amount<Long, Time> exportInterval) {
- checkNotNull(exportSink);
- this.executor = checkNotNull(executor);
- this.exportInterval = checkNotNull(exportInterval);
- this.exportSink = exportSink;
-
- exporter = new Runnable() {
- @Override public void run() {
- exportSink.execute(Maps.transformValues(
- Maps.uniqueIndex(Stats.getNumericVariables(), GET_NAME), READ_STAT));
- }
- };
- }
-
- /**
- * Starts the stat exporter.
- *
- * @param shutdownRegistry Shutdown hook registry to allow the exporter to cleanly halt.
- */
- public void start(ShutdownRegistry shutdownRegistry) {
- long intervalSecs = exportInterval.as(Time.SECONDS);
- executor.scheduleAtFixedRate(exporter, intervalSecs, intervalSecs, TimeUnit.SECONDS);
-
- shutdownRegistry.addAction(new Command() {
- @Override public void execute() {
- stop();
- exportSink.execute(Maps.transformValues(
- Maps.uniqueIndex(Stats.getNumericVariables(), GET_NAME), SAMPLE_AND_READ_STAT));
- }
- });
- }
-
- /**
- * Stops the stat exporter. Once stopped, it may be started again by calling
- * {@link #start(ShutdownRegistry)}.
- */
- public void stop() {
- try {
- if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
- executor.shutdownNow();
- if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
- LOG.severe("Failed to stop stat exporter.");
- }
- }
- } catch (InterruptedException e) {
- executor.shutdownNow();
- Thread.currentThread().interrupt();
- }
- }
-
- public static final Function<Stat<?>, String> GET_NAME = new Function<Stat<?>, String>() {
- @Override public String apply(Stat<?> stat) {
- return stat.getName();
- }
- };
-
- public static final Function<Stat<? extends Number>, Number> READ_STAT =
- new Function<Stat<? extends Number>, Number>() {
- @Override public Number apply(Stat<? extends Number> stat) {
- return stat.read();
- }
- };
-
- private static final Function<RecordingStat<? extends Number>, Number> SAMPLE_AND_READ_STAT =
- new Function<RecordingStat<? extends Number>, Number>() {
- @Override public Number apply(RecordingStat<? extends Number> stat) {
- return stat.sample();
- }
- };
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/PipelineStats.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/PipelineStats.java b/commons/src/main/java/org/apache/aurora/common/stats/PipelineStats.java
deleted file mode 100644
index 014a56a..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/PipelineStats.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * 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.common.stats;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import org.apache.aurora.common.base.MorePreconditions;
-import org.apache.aurora.common.collections.Pair;
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Time;
-import org.apache.aurora.common.util.Clock;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tracks the latency of different pipeline stages in a process.
- *
- * @author William Farner
- */
-public class PipelineStats {
- private static final String FULL_PIPELINE_NAME = "full";
-
- private final Time precision;
- private final Clock clock;
-
- private final Map<String, SlidingStats> stages;
-
- /**
- * Creates a new pipeline tracker with the given pipeline name and stages. The stage name "full"
- * is reserved to represent the duration of the entire pipeline.
- *
- * @param pipelineName Name of the pipeline.
- * @param stages Stage names.
- * @param precision Precision for time interval recording.
- */
- public PipelineStats(String pipelineName, Set<String> stages, Time precision) {
- this(pipelineName, stages, Clock.SYSTEM_CLOCK, precision);
- }
-
- @VisibleForTesting
- PipelineStats(String pipelineName, Set<String> stages, Clock clock, Time precision) {
- MorePreconditions.checkNotBlank(pipelineName);
- MorePreconditions.checkNotBlank(stages);
- Preconditions.checkArgument(!stages.contains(FULL_PIPELINE_NAME));
-
- this.clock = Preconditions.checkNotNull(clock);
- this.precision = Preconditions.checkNotNull(precision);
-
- this.stages = Maps.newHashMap();
- for (String stage : stages) {
- this.stages.put(stage, new SlidingStats(
- String.format("%s_%s", pipelineName, stage), precision.toString()));
- }
- this.stages.put(FULL_PIPELINE_NAME, new SlidingStats(
- String.format("%s_%s", pipelineName, FULL_PIPELINE_NAME), precision.toString()));
- }
-
- private void record(Snapshot snapshot) {
- for (Pair<String, Long> stage : snapshot.stages) {
- stages.get(stage.getFirst()).accumulate(stage.getSecond());
- }
- }
-
- public Snapshot newSnapshot() {
- return new Snapshot(this);
- }
-
- @VisibleForTesting
- public SlidingStats getStatsForStage(String stage) {
- return stages.get(stage);
- }
-
- public class Snapshot {
- private final List<Pair<String, Long>> stages = Lists.newLinkedList();
- private final PipelineStats parent;
-
- private String currentStage;
- private long startTime;
- private long ticker;
-
- private Snapshot(PipelineStats parent) {
- this.parent = parent;
- }
-
- /**
- * Records the duration for the current pipeline stage, and advances to the next stage. The
- * stage name must be one of the stages specified in the constructor.
- *
- * @param stageName Name of the stage to enter.
- */
- public void start(String stageName) {
- record(Preconditions.checkNotNull(stageName));
- }
-
- private void record(String stageName) {
- long now = Amount.of(clock.nowNanos(), Time.NANOSECONDS).as(precision);
- if (currentStage != null) {
- stages.add(Pair.of(currentStage, now - ticker));
- } else {
- startTime = now;
- }
-
- if (stageName == null) stages.add(Pair.of(FULL_PIPELINE_NAME, now - startTime));
-
- ticker = now;
- currentStage = stageName;
- }
-
- /**
- * Stops the pipeline, recording the interval for the last registered stage.
- * This is the same as calling {@link #start(String)} with {@code null};
- *
- */
- public void end() {
- record(null);
- parent.record(this);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/Precision.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Precision.java b/commons/src/main/java/org/apache/aurora/common/stats/Precision.java
deleted file mode 100644
index 7000e2f..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/Precision.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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.common.stats;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Precision expresses the maximum epsilon tolerated for a typical size of input
- * e.g.: Precision(0.01, 1000) express that we tolerate a error of 1% for 1000 entries
- * it means that max difference between the real quantile and the estimate one is
- * error = 0.01*1000 = 10
- * For an entry like (1 to 1000), q(0.5) will be [490 <= x <= 510] (real q(0.5) = 500)
- */
-public class Precision {
- private final double epsilon;
- private final int n;
-
- /**
- * Create a Precision instance representing a precision per number of entries
- *
- * @param epsilon is the maximum error tolerated
- * @param n size of the data set
- */
- public Precision(double epsilon, int n) {
- Preconditions.checkArgument(0.0 < epsilon, "Epsilon must be positive!");
- Preconditions.checkArgument(1 < n, "N (expected number of elements) must be greater than 1!");
-
- this.epsilon = epsilon;
- this.n = n;
- }
-
- public double getEpsilon() {
- return epsilon;
- }
-
- public int getN() {
- return n;
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/PrintableHistogram.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/PrintableHistogram.java b/commons/src/main/java/org/apache/aurora/common/stats/PrintableHistogram.java
deleted file mode 100644
index a587457..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/PrintableHistogram.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * 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.common.stats;
-
-import com.google.common.base.Preconditions;
-
-public class PrintableHistogram {
- private double[] bucketBoundaries;
- private int[] bucketCounts;
- private int totalCount = 0;
-
- /**
- * Creates a histogram with the given bucket boundaries. The boundaries
- * 0 and infinity are implicitly added.
- *
- * @param buckets Boundaries for histogram buckets.
- */
- public PrintableHistogram(double ... buckets) {
- Preconditions.checkState(buckets[0] != 0);
-
- bucketBoundaries = new double[buckets.length + 2];
- bucketBoundaries[0] = 0;
- bucketCounts = new int[buckets.length + 2];
- for (int i = 0; i < buckets.length; i++) {
- if (i > 0) {
- Preconditions.checkState(buckets[i] > buckets[i - 1],
- "Bucket %f must be greater than %f.", buckets[i], buckets[i - 1]);
- }
- bucketCounts[i] = 0;
- bucketBoundaries[i + 1] = buckets[i];
- }
-
- bucketBoundaries[bucketBoundaries.length - 1] = Integer.MAX_VALUE;
- }
-
- public void addValue(double value) {
- addValue(value, 1);
- }
-
- public void addValue(double value, int count) {
- Preconditions.checkState(value >= 0);
- Preconditions.checkState(count >= 0);
- Preconditions.checkState(bucketBoundaries.length > 1);
- int bucketId = -1;
- for (double boundary : bucketBoundaries) {
- if (value <= boundary) {
- break;
- }
- bucketId++;
- }
-
- bucketId = Math.max(0, bucketId);
- bucketId = Math.min(bucketCounts.length - 1, bucketId);
- bucketCounts[bucketId] += count;
- totalCount += count;
- }
-
- public double getBucketRatio(int bucketId) {
- Preconditions.checkState(bucketId >= 0);
- Preconditions.checkState(bucketId < bucketCounts.length);
- return (double) bucketCounts[bucketId] / totalCount;
- }
-
- public String toString() {
- StringBuilder display = new StringBuilder();
- display.append("Histogram: ");
- for (int bucketId = 0; bucketId < bucketCounts.length - 1; bucketId++) {
- display.append(String.format("\n(%g - %g]\n\t",
- bucketBoundaries[bucketId], bucketBoundaries[bucketId + 1]));
- for (int i = 0; i < getBucketRatio(bucketId) * 100; i++) {
- display.append('#');
- }
- display.append(
- String.format(" %.2g%% (%d)", getBucketRatio(bucketId) * 100, bucketCounts[bucketId]));
- }
-
- return display.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/ReservoirSampler.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/ReservoirSampler.java b/commons/src/main/java/org/apache/aurora/common/stats/ReservoirSampler.java
deleted file mode 100644
index 79e7e04..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/ReservoirSampler.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * 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.common.stats;
-
-import java.util.Vector;
-
-import com.google.common.base.Preconditions;
-
-import org.apache.aurora.common.util.Random;
-
-/**
- * An in memory implementation of Reservoir Sampling for sampling from
- * a population.
- * <p>Several optimizations can be done.
- * Especially, one can avoid rolling the dice as many times as the
- * size of the population with an involved trick.
- * See "Random Sampling with a Reservoir", Vitter, 1985</p>
- * <p>TODO (delip): Fix this when the problem arises</p>
- *
- * @param <T> Type of the sample
- * @author Delip Rao
- */
-public class ReservoirSampler<T> {
- private final Vector<T> reservoir = new Vector<T>();
- private final int numSamples;
-
- private final Random random;
- private int numItemsSeen = 0;
-
- /**
- * Create a new sampler with a certain reservoir size using
- * a supplied random number generator.
- *
- * @param numSamples Maximum number of samples to
- * retain in the reservoir. Must be non-negative.
- * @param random Instance of the random number generator
- * to use for sampling
- */
- public ReservoirSampler(int numSamples, Random random) {
- Preconditions.checkArgument(numSamples > 0,
- "numSamples should be positive");
- Preconditions.checkNotNull(random);
- this.numSamples = numSamples;
- this.random = random;
- }
-
- /**
- * Create a new sampler with a certain reservoir size using
- * the default random number generator.
- *
- * @param numSamples Maximum number of samples to
- * retain in the reservoir. Must be non-negative.
- */
- public ReservoirSampler(int numSamples) {
- this(numSamples, Random.Util.newDefaultRandom());
- }
-
- /**
- * Sample an item and store in the reservoir if needed.
- *
- * @param item The item to sample - may not be null.
- */
- public void sample(T item) {
- Preconditions.checkNotNull(item);
- if (reservoir.size() < numSamples) {
- // reservoir not yet full, just append
- reservoir.add(item);
- } else {
- // find a sample to replace
- int rIndex = random.nextInt(numItemsSeen + 1);
- if (rIndex < numSamples) {
- reservoir.set(rIndex, item);
- }
- }
- numItemsSeen++;
- }
-
- /**
- * Get samples collected in the reservoir.
- *
- * @return A sequence of the samples. No guarantee is provided on the order of the samples.
- */
- public Iterable<T> getSamples() {
- return reservoir;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/Significance.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Significance.java b/commons/src/main/java/org/apache/aurora/common/stats/Significance.java
deleted file mode 100644
index ff040e9..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/Significance.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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.common.stats;
-
-/**
- * Calculate significance scores between an observed amount and an expected amount.
- *
- * @author Gilad Mishne
- */
-public class Significance {
-
- /**
- * @param observed The observed amount.
- * @param expected The expected amount.
- * @return [(observed - expected) ** 2 / expected] * sign(observed - expected)
- */
- public static double chiSqrScore(double observed, double expected) {
- double score = Math.pow((observed - expected), 2) / expected;
- if (observed < expected) {
- score *= -1;
- }
- return score;
- }
-
- /**
- * @param observed The observed amount.
- * @param expected The expected amount.
- * @return -2 * expected * log(observed / expected) * sign(observed - expected)
- */
- public static double logLikelihood(double observed, double expected) {
- if (observed == 0) {
- return -expected;
- }
- if (expected == 0) {
- return observed;
- }
- double score = -2 * observed * Math.log(observed / expected);
- if (observed < expected) {
- score *= -1;
- }
- return score;
- }
-
- private Significance() {
- // prevent instantiation
- }
-
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/Statistics.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Statistics.java b/commons/src/main/java/org/apache/aurora/common/stats/Statistics.java
deleted file mode 100644
index 498abb0..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/Statistics.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * 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.common.stats;
-
-/**
- * A simple class to keep running statistics that require O(1) storage.
- *
- * @author William Farner
- */
-public class Statistics implements StatisticsInterface {
- private long populationSize;
- private long sum;
- private double accumulatedVariance;
- private double runningMean;
-
- private long minValue;
- private long maxValue;
-
- public Statistics() {
- clear();
- }
-
- public void accumulate(long value) {
- populationSize++;
- sum += value;
- double delta = value - runningMean;
- runningMean += delta / populationSize;
- accumulatedVariance += delta * (value - runningMean);
-
- // Update max/min.
- minValue = value < minValue ? value : minValue;
- maxValue = value > maxValue ? value : maxValue;
- }
-
- public void clear() {
- populationSize = 0;
- sum = 0;
- accumulatedVariance = 0;
- runningMean = 0;
- minValue = Long.MAX_VALUE;
- maxValue = Long.MIN_VALUE;
- }
-
- public double variance() {
- return accumulatedVariance / populationSize;
- }
-
- public double standardDeviation() {
- return Math.sqrt(variance());
- }
-
- public double mean() {
- return runningMean;
- }
-
- public long min() {
- return minValue;
- }
-
- public long max() {
- return maxValue;
- }
-
- public long range() {
- return maxValue - minValue;
- }
-
- public long sum() {
- return sum;
- }
-
- public long populationSize() {
- return populationSize;
- }
-
- @Override
- public String toString() {
- return String.format("Mean: %f, Min: %d, Max: %d, Range: %d, Stddev: %f, Variance: %f, " +
- "Population: %d, Sum: %d", mean(), min(), max(), range(), standardDeviation(),
- variance(), populationSize(), sum());
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/StatisticsInterface.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/StatisticsInterface.java b/commons/src/main/java/org/apache/aurora/common/stats/StatisticsInterface.java
deleted file mode 100644
index 893c069..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/StatisticsInterface.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.common.stats;
-
-/**
- * Interface representing statistics of a set of (long) elements.
- */
-public interface StatisticsInterface {
- /**
- * Add a value in the Statistics object.
- * @param value value that you want to accumulate.
- */
- void accumulate(long value);
-
- /**
- * Clear the Statistics instance (equivalent to recreate a new one).
- */
- void clear();
-
- /**
- * Return the variance of the inserted elements.
- */
- double variance();
-
- /**
- * Return the standard deviation of the inserted elements.
- */
- double standardDeviation();
-
- /**
- * Return the mean of the inserted elements.
- */
- double mean();
-
- /**
- * Return the min of the inserted elements.
- */
- long min();
-
- /**
- * Return the max of the inserted elements.
- */
- long max();
-
- /**
- * Return the range of the inserted elements.
- */
- long range();
-
- /**
- * Return the sum of the inserted elements.
- */
- long sum();
-
- /**
- * Return the number of the inserted elements.
- */
- long populationSize();
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/Windowed.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Windowed.java b/commons/src/main/java/org/apache/aurora/common/stats/Windowed.java
deleted file mode 100644
index 12ab468..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/Windowed.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * 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.common.stats;
-
-import java.lang.reflect.Array;
-
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Supplier;
-
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Time;
-import org.apache.aurora.common.util.Clock;
-
-/**
- * Windowed is an abstraction that let you span a class across a sliding window.
- * It creates a ring buffer of T and reuse the buffer after clearing it or use a new one (via
- * the {@code clearer} function).
- *
- * <pre>
- * tenured instances
- * ++++++++++++++++++++++++++++++++++
- * [----A-----][-----B----][-----C----][-----D----]
- * ++++++++++
- * current instance
- * </pre>
- *
- * The schema above represents the valid instances over time
- * (A,B,C) are the tenured ones
- * D is the current instance
- */
-public abstract class Windowed<T> {
- private Class<T> clazz;
- protected final T[] buffers;
- private final long sliceDuration;
- private final Clock clock;
- private long index = -1L;
- private Function<T, T> clearer;
-
- /**
- * @param clazz the type of the underlying element T
- * @param window the length of the window
- * @param slices the number of slices (the window will be divided into {@code slices} slices)
- * @param sliceProvider the supplier of element
- * @param clearer the function that clear (or re-create) an element
- * @param clock the clock used for to select the appropriate histogram
- */
- public Windowed(Class<T> clazz, Amount<Long, Time> window, int slices,
- Supplier<T> sliceProvider, Function<T, T> clearer, Clock clock) {
- Preconditions.checkNotNull(window);
- // Ensure that we have at least 1ms per slice
- Preconditions.checkArgument(window.as(Time.MILLISECONDS) > (slices + 1));
- Preconditions.checkArgument(window.as(Time.MILLISECONDS) > (slices + 1));
- Preconditions.checkArgument(0 < slices);
- Preconditions.checkNotNull(sliceProvider);
- Preconditions.checkNotNull(clock);
-
- this.clazz = clazz;
- this.sliceDuration = window.as(Time.MILLISECONDS) / slices;
- @SuppressWarnings("unchecked") // safe because we have the clazz proof of type H
- T[] bufs = (T[]) Array.newInstance(clazz, slices + 1);
- for (int i = 0; i < bufs.length; i++) {
- bufs[i] = sliceProvider.get();
- }
- this.buffers = bufs;
- this.clearer = clearer;
- this.clock = clock;
- }
-
- /**
- * Return the index of the latest Histogram.
- * You have to modulo it with buffer.length before accessing the array with this number.
- */
- protected int getCurrentIndex() {
- long now = clock.nowMillis();
- return (int) (now / sliceDuration);
- }
-
- /**
- * Check for expired elements and return the current one.
- */
- protected T getCurrent() {
- sync(getCurrentIndex());
- return buffers[(int) (index % buffers.length)];
- }
-
- /**
- * Check for expired elements and return all the tenured (old) ones.
- */
- protected T[] getTenured() {
- long currentIndex = getCurrentIndex();
- sync(currentIndex);
- @SuppressWarnings("unchecked") // safe because we have the clazz proof of type T
- T[] tmp = (T[]) Array.newInstance(clazz, buffers.length - 1);
- for (int i = 0; i < tmp.length; i++) {
- int idx = (int) ((currentIndex + 1 + i) % buffers.length);
- tmp[i] = buffers[idx];
- }
- return tmp;
- }
-
- /**
- * Clear all the elements.
- */
- public void clear() {
- for (int i = 0; i <= buffers.length; i++) {
- buffers[i] = clearer.apply(buffers[i]);
- }
- }
-
- /**
- * Synchronize elements with a point in time.
- * i.e. Check for expired ones and clear them, and update the index variable.
- */
- protected void sync(long currentIndex) {
- if (index < currentIndex) {
- long from = Math.max(index + 1, currentIndex - buffers.length + 1);
- for (long i = from; i <= currentIndex; i++) {
- int idx = (int) (i % buffers.length);
- buffers[idx] = clearer.apply(buffers[idx]);
- }
- index = currentIndex;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/WindowedApproxHistogram.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/WindowedApproxHistogram.java b/commons/src/main/java/org/apache/aurora/common/stats/WindowedApproxHistogram.java
deleted file mode 100644
index 6461a2e..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/WindowedApproxHistogram.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * 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.common.stats;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Supplier;
-
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Data;
-import org.apache.aurora.common.quantity.Time;
-import org.apache.aurora.common.util.Clock;
-
-/**
- * WindowedApproxHistogram is an implementation of WindowedHistogram with an
- * ApproximateHistogram as the underlying storing histogram.
- */
-public class WindowedApproxHistogram extends WindowedHistogram<ApproximateHistogram> {
- @VisibleForTesting public static final int DEFAULT_SLICES = 3;
- @VisibleForTesting public static final Amount<Long, Time> DEFAULT_WINDOW =
- Amount.of(1L, Time.MINUTES);
- @VisibleForTesting public static final Amount<Long, Data> DEFAULT_MAX_MEMORY = Amount.of(
- (DEFAULT_SLICES + 1) * ApproximateHistogram.DEFAULT_MAX_MEMORY.as(Data.BYTES), Data.BYTES);
-
- /**
- * Create a {@code WindowedApproxHistogram } with a window duration of {@code window} and
- * decomposed in {@code slices} Histograms. Those Histograms will individually take less than
- * {@code maxMemory / (slices + 1)}. The clock will be used to find the correct index in the
- * ring buffer.
- *
- * @param window duration of the window
- * @param slices number of slices in the window
- * @param maxMemory maximum memory used by the whole histogram
- */
- public WindowedApproxHistogram(Amount<Long, Time> window, final int slices,
- final Amount<Long, Data> maxMemory, Clock clock) {
- super(ApproximateHistogram.class, window, slices,
- new Supplier<ApproximateHistogram>() {
- private Amount<Long, Data> perHistogramMemory = Amount.of(
- maxMemory.as(Data.BYTES) / (slices + 1), Data.BYTES);
- @Override
- public ApproximateHistogram get() {
- return new ApproximateHistogram(perHistogramMemory);
- }
- },
- new Function<ApproximateHistogram[], Histogram>() {
- @Override
- public Histogram apply(ApproximateHistogram[] histograms) {
- return ApproximateHistogram.merge(histograms);
- }
- }, clock);
- }
-
- /**
- * Create a {@code WindowedApproxHistogram } with a window duration of {@code window} and
- * decomposed in {@code slices} Histograms. Those Histograms will individually have a
- * precision of {@code precision / (slices + 1)}. The ticker will be used to measure elapsed
- * time in the WindowedHistogram.
- *
- * @param window duration of the window
- * @param slices number of slices in the window
- * @param precision precision of the whole histogram
- */
- public WindowedApproxHistogram(Amount<Long, Time> window, final int slices,
- final Precision precision, Clock clock) {
- super(ApproximateHistogram.class, window, slices,
- new Supplier<ApproximateHistogram>() {
- private Precision perHistogramPrecision = new Precision(
- precision.getEpsilon(), precision.getN() / (slices + 1));
- @Override
- public ApproximateHistogram get() {
- return new ApproximateHistogram(perHistogramPrecision);
- }
- },
- new Function<ApproximateHistogram[], Histogram>() {
- @Override
- public Histogram apply(ApproximateHistogram[] histograms) {
- return ApproximateHistogram.merge(histograms);
- }
- }, clock);
- }
-
- /**
- * Equivalent to calling
- * {@link #WindowedApproxHistogram(Amount, int, Amount, Clock)}
- * with the System clock.
- */
- public WindowedApproxHistogram(Amount<Long, Time> window, int slices,
- Amount<Long, Data> maxMemory) {
- this(window, slices, maxMemory, Clock.SYSTEM_CLOCK);
- }
-
- /**
- * Equivalent to calling
- * {@link #WindowedApproxHistogram(Amount, int, Amount)}
- * with default window and slices.
- */
- public WindowedApproxHistogram(Amount<Long, Data> maxMemory) {
- this(DEFAULT_WINDOW, DEFAULT_SLICES, maxMemory);
- }
-
- /**
- * Equivalent to calling
- * {@link #WindowedApproxHistogram(Amount, int, Precision, Clock)}
- * with the System clock.
- */
- public WindowedApproxHistogram(Amount<Long, Time> window, int slices, Precision precision) {
- this(window, slices, precision, Clock.SYSTEM_CLOCK);
- }
-
- /**
- * Equivalent to calling
- * {@link #WindowedApproxHistogram(Amount, int, Precision)}
- * with default window and slices.
- */
- public WindowedApproxHistogram(Precision precision) {
- this(DEFAULT_WINDOW, DEFAULT_SLICES, precision);
- }
-
- /**
- * Equivalent to calling
- * {@link #WindowedApproxHistogram(Amount, int, Amount, Clock)}
- * with the default maxMemory parameter and System clock.
- */
- public WindowedApproxHistogram(Amount<Long, Time> window, int slices) {
- this(window, slices, DEFAULT_MAX_MEMORY, Clock.SYSTEM_CLOCK);
- }
-
- /**
- * WindowedApproxHistogram constructor with default values.
- */
- public WindowedApproxHistogram() {
- this(DEFAULT_WINDOW, DEFAULT_SLICES, DEFAULT_MAX_MEMORY, Clock.SYSTEM_CLOCK);
- }
-
- /**
- * WindowedApproxHistogram constructor with custom Clock (for testing purposes only).
- */
- @VisibleForTesting public WindowedApproxHistogram(Clock clock) {
- this(DEFAULT_WINDOW, DEFAULT_SLICES, DEFAULT_MAX_MEMORY, clock);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/WindowedHistogram.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/WindowedHistogram.java b/commons/src/main/java/org/apache/aurora/common/stats/WindowedHistogram.java
deleted file mode 100644
index 23e2f4f..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/WindowedHistogram.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * 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.common.stats;
-
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Supplier;
-
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Time;
-import org.apache.aurora.common.util.Clock;
-
-/**
- * Histogram windowed over time.
- * <p>
- * This histogram is composed of a series of ({@code slices} + 1) histograms representing a window
- * of {@code range} duration. We only update the latest one, and we query the oldest ones (i.e. all
- * histograms except the head).
- * </p>
- * <pre>
- * range
- * <------------->
- * [AAA][BBB][CCC][DDD] here slices = 3
- * --------------------->
- * t1 t2
- *
- * For t in [t1,t2) we:
- * insert elements in DDD
- * query quantile over [AAA][BBB][CCC]
- * </pre>
- * <p>
- * When {@code t} is in {@code [t1, t2)} we insert value into the latest histogram (DDD here),
- * when we query the histogram, we 'merge' all other histograms (all except the latest) and query
- * it. when {@code t > t2} the oldest histogram become the newest (like in a ring buffer) and
- * so on ...
- * </p>
- * <p>
- * Note: We use MergedHistogram class to represent a merged histogram without actually
- * merging the underlying histograms.
- * </p>
- */
-public class WindowedHistogram<H extends Histogram> extends Windowed<H> implements Histogram {
-
- private long mergedHistIndex = -1L;
- private Function<H[], Histogram> merger;
- private Histogram mergedHistogram = null;
-
- /**
- * Create a WindowedHistogram of {@code slices + 1} elements over a time {@code window}.
- * This code is independent from the implementation of Histogram, you just need to provide
- * a {@code Supplier<H>} to create the histograms and a {@code Function<H[], Histogram>} to
- * merge them.
- *
- * @param clazz the type of the underlying Histogram H
- * @param window the length of the window
- * @param slices the number of slices (the window will be divided into {@code slices} slices)
- * @param sliceProvider the supplier of histogram
- * @param merger the function that merge an array of histogram H[] into a single Histogram
- * @param clock the clock used for to select the appropriate histogram
- */
- public WindowedHistogram(Class<H> clazz, Amount<Long, Time> window, int slices,
- Supplier<H> sliceProvider, Function<H[], Histogram> merger, Clock clock) {
- super(clazz, window, slices, sliceProvider, new Function<H, H>() {
- @Override
- public H apply(H h) { h.clear(); return h; }
- }, clock);
- Preconditions.checkNotNull(merger);
-
- this.merger = merger;
- }
-
- @Override
- public synchronized void add(long x) {
- getCurrent().add(x);
- }
-
- @Override
- public synchronized void clear() {
- for (Histogram h: buffers) {
- h.clear();
- }
- }
-
- @Override
- public synchronized long getQuantile(double quantile) {
- long currentIndex = getCurrentIndex();
- if (mergedHistIndex < currentIndex) {
- H[] tmp = getTenured();
- mergedHistogram = merger.apply(tmp);
- mergedHistIndex = currentIndex;
- }
- return mergedHistogram.getQuantile(quantile);
- }
-
- @Override
- public synchronized long[] getQuantiles(double[] quantiles) {
- return Histograms.extractQuantiles(this, quantiles);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/WindowedStatistics.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/WindowedStatistics.java b/commons/src/main/java/org/apache/aurora/common/stats/WindowedStatistics.java
deleted file mode 100644
index ded3faf..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/WindowedStatistics.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/**
- * 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.common.stats;
-
-import com.google.common.base.Supplier;
-import com.google.common.base.Function;
-
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Time;
-import org.apache.aurora.common.util.Clock;
-
-/**
- * Keep track of statistics over a set of value in a sliding window.
- * WARNING: The computation of the statistics needs to be explicitly requested with
- * {@code refresh()} before reading any statistics.
- *
- * @see Windowed class for more details about how the window is parametrized.
- */
-public class WindowedStatistics extends Windowed<Statistics> implements StatisticsInterface {
- private int lastIndex = -1;
- private double variance = 0.0;
- private double mean = 0.0;
- private long sum = 0L;
- private long min = Long.MAX_VALUE;
- private long max = Long.MIN_VALUE;
- private long populationSize = 0L;
-
- public WindowedStatistics(Amount<Long, Time> window, int slices, Clock clock) {
- super(Statistics.class, window, slices,
- new Supplier<Statistics>() {
- @Override public Statistics get() { return new Statistics(); }
- },
- new Function<Statistics, Statistics>() {
- @Override public Statistics apply(Statistics s) { s.clear(); return s; }
- },
- clock);
- }
-
- /**
- * Construct a Statistics sliced over time in {@code slices + 1} windows.
- * The {@code window} parameter represents the total window, that will be sliced into
- * {@code slices + 1} parts.
- *
- * Ex: WindowedStatistics(Amount.of(1L, Time.MINUTES), 3) will be sliced like this:
- * <pre>
- * 20s 20s 20s 20s
- * [----A-----][-----B----][-----C----][-----D----]
- * </pre>
- * The current window is 'D' (the one you insert elements into) and the tenured windows
- * are 'A', 'B', 'C' (the ones you read elements from).
- */
- public WindowedStatistics(Amount<Long, Time> window, int slices) {
- this(window, slices, Clock.SYSTEM_CLOCK);
- }
-
- /**
- * Equivalent to calling {@link #WindowedStatistics(Amount, int)} with a 1 minute window
- * and 3 slices.
- */
- public WindowedStatistics() {
- this(Amount.of(1L, Time.MINUTES), 3, Clock.SYSTEM_CLOCK);
- }
-
- public void accumulate(long value) {
- getCurrent().accumulate(value);
- }
-
- /**
- * Compute all the statistics in one pass.
- */
- public void refresh() {
- int currentIndex = getCurrentIndex();
- if (lastIndex != currentIndex) {
- lastIndex = currentIndex;
- double x = 0.0;
- variance = 0.0;
- mean = 0.0;
- sum = 0L;
- populationSize = 0L;
- min = Long.MAX_VALUE;
- max = Long.MIN_VALUE;
- for (Statistics s : getTenured()) {
- if (s.populationSize() == 0) {
- continue;
- }
- x += s.populationSize() * (s.variance() + s.mean() * s.mean());
- sum += s.sum();
- populationSize += s.populationSize();
- min = Math.min(min, s.min());
- max = Math.max(max, s.max());
- }
- if (populationSize != 0) {
- mean = ((double) sum) / populationSize;
- variance = x / populationSize - mean * mean;
- }
- }
- }
-
- /**
- * WARNING: You need to call refresh() to recompute the variance
- * @return the variance of the aggregated windows
- */
- public double variance() {
- return variance;
- }
-
- /**
- * WARNING: You need to call refresh() to recompute the variance
- * @return the standard deviation of the aggregated windows
- */
- public double standardDeviation() {
- return Math.sqrt(variance());
- }
-
- /**
- * WARNING: You need to call refresh() to recompute the variance
- * @return the mean of the aggregated windows
- */
- public double mean() {
- return mean;
- }
-
- /**
- * WARNING: You need to call refresh() to recompute the variance
- * @return the sum of the aggregated windows
- */
- public long sum() {
- return sum;
- }
-
- /**
- * WARNING: You need to call refresh() to recompute the variance
- * @return the min of the aggregated windows
- */
- public long min() {
- return min;
- }
-
- /**
- * WARNING: You need to call refresh() to recompute the variance
- * @return the max of the aggregated windows
- */
- public long max() {
- return max;
- }
-
- /**
- * WARNING: You need to call refresh() to recompute the variance
- * @return the range of the aggregated windows
- */
- public long range() {
- return max - min;
- }
-
- /**
- * WARNING: You need to call refresh() to recompute the variance
- * @return the population size of the aggregated windows
- */
- public long populationSize() {
- return populationSize;
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/stats/testing/RealHistogram.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/testing/RealHistogram.java b/commons/src/main/java/org/apache/aurora/common/stats/testing/RealHistogram.java
deleted file mode 100644
index 36b1174..0000000
--- a/commons/src/main/java/org/apache/aurora/common/stats/testing/RealHistogram.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.common.stats.testing;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.aurora.common.stats.Histogram;
-import org.apache.aurora.common.stats.Histograms;
-
-public class RealHistogram implements Histogram {
- private final List<Long> buffer = new ArrayList<Long>();
-
- @Override public void add(long x) {
- buffer.add(x);
- }
-
- @Override public void clear() {
- buffer.clear();
- }
-
- @Override public long getQuantile(double quantile) {
- Collections.sort(buffer);
- return buffer.get((int) (quantile * buffer.size()));
- }
-
- @Override public long[] getQuantiles(double[] quantiles) {
- return Histograms.extractQuantiles(this, quantiles);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/testing/TearDownRegistry.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/testing/TearDownRegistry.java b/commons/src/main/java/org/apache/aurora/common/testing/TearDownRegistry.java
deleted file mode 100644
index 02db075..0000000
--- a/commons/src/main/java/org/apache/aurora/common/testing/TearDownRegistry.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.common.testing;
-
-import com.google.common.base.Preconditions;
-import com.google.common.testing.TearDown;
-import com.google.common.testing.TearDownAccepter;
-
-import org.apache.aurora.common.application.ShutdownRegistry;
-import org.apache.aurora.common.base.ExceptionalCommand;
-
-/**
- * An action registry suitable for use as a shutdownRegistry in tests that extend
- * {@link com.google.common.testing.junit4.TearDownTestCase}.
- *
- * @author John Sirois
- */
-public class TearDownRegistry implements ShutdownRegistry {
- private final TearDownAccepter tearDownAccepter;
-
- /**
- * Creates a new tear down registry that delegates execution of shutdown actions to a
- * {@code tearDownAccepter}.
- *
- * @param tearDownAccepter A tear down accepter that will be used to register shutdown actions
- * with.
- */
- public TearDownRegistry(TearDownAccepter tearDownAccepter) {
- this.tearDownAccepter = Preconditions.checkNotNull(tearDownAccepter);
- }
-
- @Override
- public <E extends Exception, T extends ExceptionalCommand<E>> void addAction(final T action) {
- tearDownAccepter.addTearDown(new TearDown() {
- @Override public void tearDown() throws Exception {
- action.execute();
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/testing/mockito/MockitoTest.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/testing/mockito/MockitoTest.java b/commons/src/main/java/org/apache/aurora/common/testing/mockito/MockitoTest.java
deleted file mode 100644
index cef57cc..0000000
--- a/commons/src/main/java/org/apache/aurora/common/testing/mockito/MockitoTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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.common.testing.mockito;
-
-import org.junit.Before;
-import org.mockito.MockitoAnnotations;
-
-/**
- * A base class for tests that use Mockito. Before each test, it initializes all the mocks
- * declared in the class.
- */
-public abstract class MockitoTest {
- /**
- * Initializes all fields annotated with {@link org.mockito.Mock}.
- */
- @Before
- public final void initMockito() {
- MockitoAnnotations.initMocks(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/thrift/Config.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/thrift/Config.java b/commons/src/main/java/org/apache/aurora/common/thrift/Config.java
deleted file mode 100644
index 7ab122b..0000000
--- a/commons/src/main/java/org/apache/aurora/common/thrift/Config.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/**
- * 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.common.thrift;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Time;
-import org.apache.aurora.common.stats.Stats;
-import org.apache.aurora.common.stats.StatsProvider;
-
-/**
- * Represents the configuration for a thrift call. Use {@link #builder()} to create a new one or
- * or {@link #builder(Config)} to create a new config based on another config.
- *
- * <p>If a deadline is specified, it acts as a global timeout for each thrift call made.
- * Obtaining connections, performing the remote call and executing retries are all expected to
- * complete within this deadline. When the specified deadline is not met, an
- * {@link TTimeoutException} will be thrown.
- *
- * <p>If max retries is specified as zero (never retry), then the list of retryable exceptions are
- * ignored. It is only when max retries is greater than zero that list of retryable exceptions is
- * used to determine if a particular failed call should be retried.
- *
- * @author John Sirois
- */
-public class Config {
-
- /**
- * Created a builder for a new {@link Config}. Default values are as follows:
- * <ul>
- * <li>{@link #getRequestTimeout()} 0
- * <li>{@link #getMaxRetries()} 0
- * <li>{@link #getRetryableExceptions()} []
- * <li>{@link #isDebug()} ()} false
- * </ul>
- */
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- *
- * @param config the builder configuration to use
- */
- public static Builder builder(Config config) {
- Preconditions.checkNotNull(config);
- return new Builder(config);
- }
-
- private static final Amount<Long,Time> DEADLINE_BLOCKING = Amount.of(0L, Time.MILLISECONDS);
-
- @VisibleForTesting
- static final Amount<Long,Time> DEFAULT_CONNECT_TIMEOUT = Amount.of(5L, Time.SECONDS);
-
- private Amount<Long, Time> requestTimeout = DEADLINE_BLOCKING;
- private Amount<Long, Time> connectTimeout = DEFAULT_CONNECT_TIMEOUT;
- private int maxRetries;
- private ImmutableSet<Class<? extends Exception>> retryableExceptions = ImmutableSet.of();
- private boolean debug = false;
- private boolean enableStats = true;
- private StatsProvider statsProvider = Stats.STATS_PROVIDER;
-
- private Config() {
- // defaults
- }
-
- private Config(Config copyFrom) {
- requestTimeout = copyFrom.requestTimeout;
- maxRetries = copyFrom.maxRetries;
- retryableExceptions = copyFrom.retryableExceptions;
- debug = copyFrom.debug;
- statsProvider = copyFrom.statsProvider;
- }
-
- /**
- * Returns the maximum time to wait for any thrift call to complete. A deadline of 0 means to
- * wait forever
- */
- public Amount<Long, Time> getRequestTimeout() {
- return requestTimeout;
- }
-
- /**
- * Returns the maximum time to wait for a connection to be established. A deadline of 0 means to
- * wait forever
- */
- public Amount<Long, Time> getConnectTimeout() {
- return connectTimeout;
- }
-
- /**
- * Returns the maximum number of retries to perform for each thrift call. A value of 0 means to
- * never retry and in this case {@link #getRetryableExceptions()} will be an empty set.
- */
- public int getMaxRetries() {
- return maxRetries;
- }
-
- /**
- * Returns the set of exceptions to retry calls for. The returned set will only be empty if
- * {@link #getMaxRetries()} is 0.
- */
- public ImmutableSet<Class<? extends Exception>> getRetryableExceptions() {
- return retryableExceptions;
- }
-
- /**
- * Returns {@code true} if the client should log extra debugging information. Currently this
- * includes method call arguments when RPCs fail with exceptions.
- */
- public boolean isDebug() {
- return debug;
- }
-
- /**
- * Returns {@code true} if the client should track request statistics.
- */
- public boolean enableStats() {
- return enableStats;
- }
-
- /**
- * Returns the stats provider to use to record Thrift client stats.
- */
- public StatsProvider getStatsProvider() {
- return statsProvider;
- }
-
- // This was made public because it seems to be causing problems for scala users when it is not
- // public.
- public static abstract class AbstractBuilder<T extends AbstractBuilder> {
- private final Config config;
-
- AbstractBuilder() {
- this.config = new Config();
- }
-
- AbstractBuilder(Config template) {
- Preconditions.checkNotNull(template);
- this.config = new Config(template);
- }
-
- protected abstract T getThis();
-
- // TODO(John Sirois): extra validation or design ... can currently do strange things like:
- // builder.blocking().withDeadline(1, TimeUnit.MILLISECONDS)
- // builder.noRetries().retryOn(TException.class)
-
- /**
- * Specifies that all calls be blocking calls with no inherent deadline. It may be the
- * case that underlying transports will eventually deadline, but {@link Thrift} will not
- * enforce a deadline.
- */
- public final T blocking() {
- config.requestTimeout = DEADLINE_BLOCKING;
- return getThis();
- }
-
- /**
- * Specifies that all calls be subject to a global timeout. This deadline includes all call
- * activities, including obtaining a free connection and any automatic retries.
- */
- public final T withRequestTimeout(Amount<Long, Time> timeout) {
- Preconditions.checkNotNull(timeout);
- Preconditions.checkArgument(timeout.getValue() >= 0,
- "A negative deadline is invalid: %s", timeout);
- config.requestTimeout = timeout;
- return getThis();
- }
-
- /**
- * Assigns the timeout for all connections established with the blocking client.
- * On an asynchronous client this timeout is only used for the connection pool lock
- * acquisition on initial calls (not retries, @see withRetries). The actual network
- * connection timeout for the asynchronous client is governed by socketTimeout.
- *
- * @param timeout Connection timeout.
- * @return A reference to the builder.
- */
- public final T withConnectTimeout(Amount<Long, Time> timeout) {
- Preconditions.checkNotNull(timeout);
- Preconditions.checkArgument(timeout.getValue() >= 0,
- "A negative deadline is invalid: %s", timeout);
- config.connectTimeout = timeout;
- return getThis();
- }
-
- /**
- * Specifies that no calls be automatically retried.
- */
- public final T noRetries() {
- config.maxRetries = 0;
- config.retryableExceptions = ImmutableSet.of();
- return getThis();
- }
-
- /**
- * Specifies that failing calls meeting {@link #retryOn retry} criteria be retried up to a
- * maximum of {@code retries} times before failing. On an asynchronous client, these retries
- * will be forced to be non-blocking, failing fast if they cannot immediately acquire the
- * connection pool locks, so they only provide a best-effort retry strategy there.
- */
- public final T withRetries(int retries) {
- Preconditions.checkArgument(retries >= 0, "A negative retry count is invalid: %d", retries);
- config.maxRetries = retries;
- return getThis();
- }
-
- /**
- * Specifies the set of exception classes that are to be considered retryable (if retries are
- * enabled). Any exceptions thrown by the underlying thrift call will be considered retryable
- * if they are an instance of any one of the specified exception classes. The set of exception
- * classes must contain at least exception class. To specify no retries either use
- * {@link #noRetries()} or pass zero to {@link #withRetries(int)}.
- */
- public final T retryOn(Iterable<? extends Class<? extends Exception>> retryableExceptions) {
- Preconditions.checkNotNull(retryableExceptions);
- ImmutableSet<Class<? extends Exception>> classes =
- ImmutableSet.copyOf(Iterables.filter(retryableExceptions, Predicates.notNull()));
- Preconditions.checkArgument(!classes.isEmpty(),
- "Must provide at least one retryable exception class");
- config.retryableExceptions = classes;
- return getThis();
- }
-
- /**
- * Specifies the set of exception classes that are to be considered retryable (if retries are
- * enabled). Any exceptions thrown by the underlying thrift call will be considered retryable
- * if they are an instance of any one of the specified exception classes. The set of exception
- * classes must contain at least exception class. To specify no retries either use
- * {@link #noRetries()} or pass zero to {@link #withRetries(int)}.
- */
- public final T retryOn(Class<? extends Exception> exception) {
- Preconditions.checkNotNull(exception);
- config.retryableExceptions =
- ImmutableSet.<Class<? extends Exception>>builder().add(exception).build();
- return getThis();
- }
-
- /**
- * When {@code debug == true}, specifies that extra debugging information should be logged.
- */
- public final T withDebug(boolean debug) {
- config.debug = debug;
- return getThis();
- }
-
- /**
- * Disables stats collection on the client (enabled by default).
- */
- public T disableStats() {
- config.enableStats = false;
- return getThis();
- }
-
- /**
- * Registers a custom stats provider to use to track various client stats.
- */
- public T withStatsProvider(StatsProvider statsProvider) {
- config.statsProvider = Preconditions.checkNotNull(statsProvider);
- return getThis();
- }
-
- protected final Config getConfig() {
- return config;
- }
- }
-
- public static final class Builder extends AbstractBuilder<Builder> {
- private Builder() {
- super();
- }
-
- private Builder(Config template) {
- super(template);
- }
-
- @Override
- protected Builder getThis() {
- return this;
- }
-
- public Config create() {
- return getConfig();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/thrift/TResourceExhaustedException.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/thrift/TResourceExhaustedException.java b/commons/src/main/java/org/apache/aurora/common/thrift/TResourceExhaustedException.java
deleted file mode 100644
index 54e2bd3..0000000
--- a/commons/src/main/java/org/apache/aurora/common/thrift/TResourceExhaustedException.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.common.thrift;
-
-import org.apache.thrift.TException;
-
-/**
- * @author Adam Samet
- *
- * This is exception is thrown when there are no available instances of a thrift backend
- * service to serve requests.
- */
-public class TResourceExhaustedException extends TException {
-
- private static final long serialVersionUID = 1L;
-
- public TResourceExhaustedException(String message) {
- super(message);
- }
-
- public TResourceExhaustedException(Throwable cause) {
- super(cause);
- }
-
- public TResourceExhaustedException(String message, Throwable cause) {
- super(message, cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/thrift/TTimeoutException.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/thrift/TTimeoutException.java b/commons/src/main/java/org/apache/aurora/common/thrift/TTimeoutException.java
deleted file mode 100644
index 068abea..0000000
--- a/commons/src/main/java/org/apache/aurora/common/thrift/TTimeoutException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.common.thrift;
-
-import org.apache.thrift.TException;
-
-/**
- * @author Adam Samet
- *
- * This is exception is thrown when accessing a thrift service resource times out.
- */
-public class TTimeoutException extends TException {
-
- private static final long serialVersionUID = 1L;
-
- public TTimeoutException(String message) {
- super(message);
- }
-
- public TTimeoutException(Throwable cause) {
- super(cause);
- }
-
- public TTimeoutException(String message, Throwable cause) {
- super(message, cause);
- }
-}