Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Various changes from IntelliJ inspection

  • Loading branch information...
commit 59193f9f6e689b7011f42cc684903bbf34d88256 1 parent 7243680
@srowen srowen authored jwills committed
Showing with 149 additions and 127 deletions.
  1. +6 −4 avro/src/main/java/com/cloudera/gertrude/space/AvroExperimentSpaceDeserializer.java
  2. +4 −3 avro/src/test/java/com/cloudera/gertrude/space/AvroExperimentSpaceDeserializerTest.java
  3. +14 −8 core/src/main/java/com/cloudera/gertrude/DiversionCriterion.java
  4. +10 −8 core/src/main/java/com/cloudera/gertrude/ExperimentFlag.java
  5. +9 −7 core/src/main/java/com/cloudera/gertrude/ExperimentFlagSettings.java
  6. +3 −9 core/src/main/java/com/cloudera/gertrude/FlagValue.java
  7. +10 −8 core/src/main/java/com/cloudera/gertrude/calculate/BasicModifier.java
  8. +2 −8 core/src/main/java/com/cloudera/gertrude/calculate/FlagValueCalculatorImpl.java
  9. +3 −4 core/src/main/java/com/cloudera/gertrude/calculate/FlagValueOverride.java
  10. +7 −8 core/src/main/java/com/cloudera/gertrude/space/ExperimentSpaceBuilder.java
  11. +11 −2 core/src/main/java/com/cloudera/gertrude/space/FlagValueData.java
  12. +2 −3 core/src/main/java/com/cloudera/gertrude/space/LayerBuilder.java
  13. +3 −0  core/src/test/java/com/cloudera/gertrude/TestExperiments.java
  14. +4 −4 deploy/src/main/java/com/cloudera/gertrude/deploy/ArityValidatingCondition.java
  15. +29 −27 deploy/src/main/java/com/cloudera/gertrude/deploy/AvroSupport.java
  16. +5 −3 deploy/src/main/java/com/cloudera/gertrude/deploy/ConditionFactorySupport.java
  17. +0 −1  deploy/src/main/java/com/cloudera/gertrude/deploy/CuratorSupport.java
  18. +7 −3 deploy/src/main/java/com/cloudera/gertrude/deploy/Cyclone.java
  19. +5 −2 deploy/src/main/java/com/cloudera/gertrude/deploy/ExperimentFlagSupport.java
  20. +2 −3 file/src/main/java/com/cloudera/gertrude/file/FileExperimentSpaceLoader.java
  21. +4 −3 server/src/main/java/com/cloudera/gertrude/server/ExampleServlet.java
  22. +6 −5 server/src/main/java/com/cloudera/gertrude/server/GertrudeFilter.java
  23. +2 −2 server/src/main/java/com/cloudera/gertrude/server/HttpServletExperimentStateImpl.java
  24. +1 −2  server/src/main/java/com/cloudera/gertrude/server/condition/IntHeaderCondition.java
View
10 avro/src/main/java/com/cloudera/gertrude/space/AvroExperimentSpaceDeserializer.java
@@ -388,22 +388,24 @@ public String apply(Object in) {
try {
c.initialize(args);
} catch (Exception e) {
- throw new ValidationException("Exception initializing condition \"" + definition.getName() + "\"", e);
+ throw new ValidationException("Exception initializing condition \"" + definition.getName() + '"', e);
}
if (definition.getNegate() != null && definition.getNegate()) {
c = BooleanConditions.not(c);
}
conditions.add(c);
} else {
- throw new ValidationException("Unknown condition function name \"" + definition.getName() + "\"");
+ throw new ValidationException("Unknown condition function name \"" + definition.getName() + '"');
}
}
// May want to cache the c + args mappings to the instances...
if (conditions.size() == 1) {
return conditions.get(0);
- } else if (operator == null || operator == ConditionOperator.AND) {
+ }
+ if (operator == null || operator == ConditionOperator.AND) {
return BooleanConditions.and(conditions);
- } else if (operator == ConditionOperator.OR) {
+ }
+ if (operator == ConditionOperator.OR) {
return BooleanConditions.or(conditions);
}
throw new ValidationException("Unknown condition operator: " + operator);
View
7 avro/src/test/java/com/cloudera/gertrude/space/AvroExperimentSpaceDeserializerTest.java
@@ -39,8 +39,8 @@
import java.util.SortedSet;
import static com.cloudera.gertrude.space.AvroDataUtils.*;
-import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
public final class AvroExperimentSpaceDeserializerTest {
@@ -306,8 +306,8 @@ public void testTwoLayersWithIllegalOverrides() throws Exception {
@Test
public void testTwoLayersWithValidOverrides() throws Exception {
- int numBuckets = 100;
- SortedSet<Integer> one = Sets.newTreeSet(), two = Sets.newTreeSet();
+ SortedSet<Integer> one = Sets.newTreeSet();
+ SortedSet<Integer> two = Sets.newTreeSet();
for (int i = 0; i < 100; i++) {
if (i % 2 == 0) {
one.add(i);
@@ -326,6 +326,7 @@ public void testTwoLayersWithValidOverrides() throws Exception {
SegmentInfo s2 = new SegmentInfo(200, 3, 0, ImmutableSortedSet.of(77));
OverrideDefinition o2 = prependDef("foo", mod("2", ModifierOperator.MULTIPLY));
+ int numBuckets = 100;
ExperimentDeployment deployment = ExperimentDeployment.newBuilder()
.setDiversions(ImmutableList.of(divDef(0, numBuckets, false)))
.setFlagDefinitions(flagDefs)
View
22 core/src/main/java/com/cloudera/gertrude/DiversionCriterion.java
@@ -80,21 +80,27 @@ public boolean isRandom() {
@Override
public int compareTo(DiversionCriterion other) {
- return id - other.id;
+ if (id < other.id) {
+ return -1;
+ }
+ if (id > other.id) {
+ return 1;
+ }
+ return 0;
}
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
DiversionCriterion that = (DiversionCriterion) o;
- if (id != that.id) return false;
- if (numBuckets != that.numBuckets) return false;
- if (random != that.random) return false;
-
- return true;
+ return id == that.id && numBuckets == that.numBuckets && random == that.random;
}
@Override
View
18 core/src/main/java/com/cloudera/gertrude/ExperimentFlag.java
@@ -83,16 +83,18 @@ public T getDefaultValue() {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
ExperimentFlag<?> that = (ExperimentFlag<?>) o;
- if (!defaultValue.equals(that.defaultValue)) return false;
- if (!flagTypeParser.equals(that.flagTypeParser)) return false;
- if (!name.equals(that.name)) return false;
-
- return true;
+ return defaultValue.equals(that.defaultValue) &&
+ flagTypeParser.equals(that.flagTypeParser) &&
+ name.equals(that.name);
}
@Override
@@ -106,7 +108,7 @@ public int hashCode() {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(flagTypeParser.toString()).append(" ").append(name).append(" = ").append(defaultValue);
+ sb.append(flagTypeParser.toString()).append(' ').append(name).append(" = ").append(defaultValue);
return sb.toString();
}
}
View
16 core/src/main/java/com/cloudera/gertrude/ExperimentFlagSettings.java
@@ -53,7 +53,7 @@
FlagValueCalculator<T> calc = (FlagValueCalculator<T>) entries.get(flag.getName());
if (calc == null) {
if (delegate == null) {
- log.warn("No calculator defined for experiment flag: " + flag);
+ log.warn("No calculator defined for experiment flag: {}", flag);
return FlagValue.of(flag.getDefaultValue(), Condition.CacheLevel.RELOAD);
} else {
return delegate.getValue(flag, state);
@@ -72,15 +72,17 @@ ExperimentFlagSettings withOverrides(Map<String, ? extends FlagValueCalculator<O
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
ExperimentFlagSettings that = (ExperimentFlagSettings) o;
- if (delegate != null ? !delegate.equals(that.delegate) : that.delegate != null) return false;
- if (!entries.equals(that.entries)) return false;
-
- return true;
+ return (delegate == null ? that.delegate == null : delegate.equals(that.delegate)) &&
+ entries.equals(that.entries);
}
@Override
View
12 core/src/main/java/com/cloudera/gertrude/FlagValue.java
@@ -62,14 +62,8 @@ public boolean equals(Object o) {
FlagValue<T> that = (FlagValue<T>) o;
- if (cacheLevel != that.cacheLevel) {
- return false;
- }
- if (value != null ? !value.equals(that.value) : that.value != null) {
- return false;
- }
-
- return true;
+ return cacheLevel == that.cacheLevel &&
+ (value == null ? that.value == null : value.equals(that.value));
}
@Override
@@ -81,6 +75,6 @@ public int hashCode() {
@Override
public String toString() {
- return new StringBuilder(value.toString()).append("(").append(cacheLevel).append(")").toString();
+ return new StringBuilder(value.toString()).append('(').append(cacheLevel).append(')').toString();
}
}
View
18 core/src/main/java/com/cloudera/gertrude/calculate/BasicModifier.java
@@ -64,17 +64,19 @@ public void apply(FlagValue<T> baseValue, ExperimentState state) {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
BasicModifier<?> that = (BasicModifier<?>) o;
- if (!condition.equals(that.condition)) return false;
- if (!modifiers.equals(that.modifiers)) return false;
- if (!operator.equals(that.operator)) return false;
- if (!value.equals(that.value)) return false;
-
- return true;
+ return condition.equals(that.condition) &&
+ modifiers.equals(that.modifiers) &&
+ operator.equals(that.operator) &&
+ value.equals(that.value);
}
@Override
View
10 core/src/main/java/com/cloudera/gertrude/calculate/FlagValueCalculatorImpl.java
@@ -53,14 +53,8 @@ public boolean equals(Object o) {
FlagValueCalculatorImpl<T> that = (FlagValueCalculatorImpl<T>) o;
- if (baseValue != null ? !baseValue.equals(that.baseValue) : that.baseValue != null) {
- return false;
- }
- if (modifiers != null ? !modifiers.equals(that.modifiers) : that.modifiers != null) {
- return false;
- }
-
- return true;
+ return (baseValue == null ? that.baseValue == null : baseValue.equals(that.baseValue)) &&
+ (modifiers == null ? that.modifiers == null : modifiers.equals(that.modifiers));
}
@Override
View
7 core/src/main/java/com/cloudera/gertrude/calculate/FlagValueOverride.java
@@ -17,7 +17,6 @@
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
-import javax.annotation.Nullable;
import java.util.List;
public abstract class FlagValueOverride<T> implements Function<FlagValueCalculatorImpl<T>, FlagValueCalculatorImpl<T>> {
@@ -25,7 +24,7 @@
public static <T> FlagValueOverride<T> createReplace(final T baseValue, final List<Modifier<T>> modifiers) {
return new FlagValueOverride<T>() {
@Override
- public FlagValueCalculatorImpl<T> apply(@Nullable FlagValueCalculatorImpl<T> input) {
+ public FlagValueCalculatorImpl<T> apply(FlagValueCalculatorImpl<T> input) {
return new FlagValueCalculatorImpl<T>(baseValue, modifiers);
}
};
@@ -34,7 +33,7 @@
public static <S> FlagValueOverride<S> createAppend(final List<Modifier<S>> newModifiers) {
return new FlagValueOverride<S>() {
@Override
- public FlagValueCalculatorImpl<S> apply(@Nullable FlagValueCalculatorImpl<S> input) {
+ public FlagValueCalculatorImpl<S> apply(FlagValueCalculatorImpl<S> input) {
return new FlagValueCalculatorImpl<S>(input.getBaseValue(),
ImmutableList.<Modifier<S>>builder()
.addAll(input.getModifiers())
@@ -47,7 +46,7 @@
public static <S> FlagValueOverride<S> createPrepend(final List<Modifier<S>> newModifiers) {
return new FlagValueOverride<S>() {
@Override
- public FlagValueCalculatorImpl<S> apply(@Nullable FlagValueCalculatorImpl<S> input) {
+ public FlagValueCalculatorImpl<S> apply(FlagValueCalculatorImpl<S> input) {
return new FlagValueCalculatorImpl<S>(input.getBaseValue(),
ImmutableList.<Modifier<S>>builder()
.addAll(newModifiers)
View
15 core/src/main/java/com/cloudera/gertrude/space/ExperimentSpaceBuilder.java
@@ -61,11 +61,11 @@
void addFlagDefinition(String name, Object baseValue, List<Modifier<Object>> mods) throws ValidationException {
// Ensure that this flag hasn't been defined yet.
if (flagDefinitions.containsKey(name)) {
- throw new ValidationException("Cannot re-define experiment flag \"" + name + "\"");
- } else {
- flagDefinitions.put(name, new FlagValueCalculatorImpl<Object>(baseValue, mods));
+ throw new ValidationException("Cannot re-define experiment flag \"" + name + '"');
}
+ flagDefinitions.put(name, new FlagValueCalculatorImpl<Object>(baseValue, mods));
+
// Second, check compiled flag definition if it exists.
ExperimentFlag<?> compiledDef = experimentFlags.get(name);
if (compiledDef != null) {
@@ -112,10 +112,10 @@ void addExperimentInfo(SegmentInfo info, boolean domain, Map<String, FlagValueOv
} else {
FlagValueData flagValueData = layerBuilder.checkOverrides(info.getId(), overrides);
ExperimentInfo experimentInfo = new ExperimentInfo(info,
- flagValueData.baseOverrides,
- flagValueData.launchOverrides);
+ flagValueData.getBaseOverrides(),
+ flagValueData.getLaunchOverrides());
layerBuilder.addExperiment(experimentInfo);
- baseOverridesBySegment.put(info.getId(), flagValueData.baseOverrides);
+ baseOverridesBySegment.put(info.getId(), flagValueData.getBaseOverrides());
}
}
@@ -194,8 +194,7 @@ Domain getDomain(SegmentInfo info, Map<Integer, Segment> finalSegments) {
for (LayerBuilder lb : layersByDomain.get(info.getId())) {
layers.add(lb.build(finalSegments));
}
- Domain domain = new Domain(info, layers);
- return domain;
+ return new Domain(info, layers);
}
FlagValueCalculatorImpl<Object> getFlagFromExperiment(int id, String name) {
View
13 core/src/main/java/com/cloudera/gertrude/space/FlagValueData.java
@@ -20,12 +20,21 @@
final class FlagValueData {
- final Map<String, FlagValueCalculatorImpl<Object>> baseOverrides;
- final Map<Integer, Map<String, FlagValueCalculatorImpl<Object>>> launchOverrides;
+ private final Map<String, FlagValueCalculatorImpl<Object>> baseOverrides;
+ private final Map<Integer, Map<String, FlagValueCalculatorImpl<Object>>> launchOverrides;
FlagValueData(Map<String, FlagValueCalculatorImpl<Object>> baseOverrides,
Map<Integer, Map<String, FlagValueCalculatorImpl<Object>>> launchOverrides) {
this.baseOverrides = baseOverrides;
this.launchOverrides = launchOverrides;
}
+
+ Map<String, FlagValueCalculatorImpl<Object>> getBaseOverrides() {
+ return baseOverrides;
+ }
+
+ Map<Integer, Map<String, FlagValueCalculatorImpl<Object>>> getLaunchOverrides() {
+ return launchOverrides;
+ }
+
}
View
5 core/src/main/java/com/cloudera/gertrude/space/LayerBuilder.java
@@ -28,7 +28,6 @@
import com.google.common.collect.Sets;
import com.google.common.hash.Hashing;
-import javax.annotation.Nullable;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Set;
@@ -115,7 +114,7 @@ void allocateBuckets(int segmentId, DiversionCriterion criteria, SortedSet<Integ
for (Integer bucket : conflict) {
conflictSegments.add(allocatedBuckets.get(bucket));
}
- sb.append(conflictSegments).append(" (Buckets: ").append(conflict).append(")");
+ sb.append(conflictSegments).append(" (Buckets: ").append(conflict).append(')');
throw new ValidationException(sb.toString());
}
for (Integer bucket : buckets) {
@@ -126,7 +125,7 @@ void allocateBuckets(int segmentId, DiversionCriterion criteria, SortedSet<Integ
private Iterable<ExperimentInfo> findExperimentsThatOverride(String name) {
return Iterables.transform(flagOverridesByExperiment.get(name), new Function<Integer, ExperimentInfo>() {
@Override
- public ExperimentInfo apply(@Nullable Integer experimentId) {
+ public ExperimentInfo apply(Integer experimentId) {
return experiments.get(experimentId);
}
});
View
3  core/src/test/java/com/cloudera/gertrude/TestExperiments.java
@@ -24,6 +24,9 @@
private static ConditionFactory conditionFactory = new TestConditionFactory();
private static MetricRegistry metrics = new MetricRegistry();
+ private TestExperiments() {
+ }
+
public static void setLoader(ExperimentSpaceLoader l) {
loader = l;
}
View
8 deploy/src/main/java/com/cloudera/gertrude/deploy/ArityValidatingCondition.java
@@ -21,11 +21,11 @@
class ArityValidatingCondition implements Condition<ExperimentState> {
- private String name;
- private int minArgs;
- private int maxArgs;
+ private final String name;
+ private final int minArgs;
+ private final int maxArgs;
- public ArityValidatingCondition(String name, int minArgs, int maxArgs) {
+ ArityValidatingCondition(String name, int minArgs, int maxArgs) {
this.name = name;
this.minArgs = minArgs;
this.maxArgs = maxArgs;
View
56 deploy/src/main/java/com/cloudera/gertrude/deploy/AvroSupport.java
@@ -42,11 +42,12 @@
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
-import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
+import java.util.Collection;
import java.util.List;
+import java.util.Locale;
public class AvroSupport {
@@ -77,7 +78,7 @@ public AvroSupport(
DateTimeZone.setDefault(DateTimeZone.forID(timeZoneId));
}
- public byte[] toBytes(ExperimentDeployment deployment) throws Exception {
+ public byte[] toBytes(ExperimentDeployment deployment) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(baos, null);
writer.write(deployment, encoder);
@@ -85,14 +86,14 @@ public AvroSupport(
return baos.toByteArray();
}
- public void deploy(ExperimentDeployment deployment, String outputFile) throws Exception {
+ public void deploy(ExperimentDeployment deployment, String outputFile) throws IOException {
DataFileWriter<ExperimentDeployment> dfw = new DataFileWriter<ExperimentDeployment>(writer)
.create(ExperimentDeployment.getClassSchema(), new File(outputFile));
dfw.append(deployment);
dfw.close();
}
- private List<? extends Config> getConfigList(Config base, String path, boolean required) {
+ private static List<? extends Config> getConfigList(Config base, String path, boolean required) {
if (!base.hasPath(path)) {
if (required) {
throw new IllegalArgumentException(String.format("Config %s does not have required path: %s",
@@ -118,7 +119,7 @@ public ExperimentDeployment createDeployment(Config base) throws IOException {
return deployment;
}
- private ExperimentDeployment toExperimentDeployment(Config base) {
+ private static ExperimentDeployment toExperimentDeployment(Config base) {
List<ExperimentDefinition> experimentDefinitions = Lists.newArrayList();
experimentDefinitions.addAll(getExperiments(getConfigList(base, "EXPERIMENTS", false), false));
if (base.hasPath("DOMAINS")) {
@@ -133,10 +134,10 @@ private ExperimentDeployment toExperimentDeployment(Config base) {
.build();
}
- private List<ExperimentFlagDefinition> getFlags(List<? extends Config> flagConfig) {
+ private static List<ExperimentFlagDefinition> getFlags(List<? extends Config> flagConfig) {
return Lists.transform(flagConfig, new Function<Config, ExperimentFlagDefinition>() {
@Override
- public ExperimentFlagDefinition apply(@Nullable Config input) {
+ public ExperimentFlagDefinition apply(Config input) {
String flagName = input.getString("name");
if (flagName == null) {
throw new IllegalArgumentException("Invalid flag config, no name: " + input.resolve().toString());
@@ -145,39 +146,39 @@ public ExperimentFlagDefinition apply(@Nullable Config input) {
.setName(flagName)
.setBaseValue(input.getString("base-value"))
.setDescription(input.getString("description"))
- .setFlagType(FlagType.valueOf(input.getString("flag-type").toUpperCase()))
+ .setFlagType(FlagType.valueOf(input.getString("flag-type").toUpperCase(Locale.ENGLISH)))
.setModifiers(getModifiers(getConfigList(input, "modifiers", false)))
.build();
}
});
}
- private List<ModifierDefinition> getModifiers(List<? extends Config> modifierList) {
+ private static List<ModifierDefinition> getModifiers(List<? extends Config> modifierList) {
return Lists.transform(modifierList, new Function<Config, ModifierDefinition>() {
@Override
- public ModifierDefinition apply(@Nullable Config input) {
+ public ModifierDefinition apply(Config input) {
return ModifierDefinition.newBuilder()
.setValue(input.getString("value"))
.setConditions(getConditions(getConfigList(input, "conditions", false)))
.setModifiers(getModifiers(getConfigList(input, "modifiers", false)))
- .setOperator(ModifierOperator.valueOf(input.getString("operator").toUpperCase()))
+ .setOperator(ModifierOperator.valueOf(input.getString("operator").toUpperCase(Locale.ENGLISH)))
.setConditionMergeOperator(getConditionOperator(input))
.build();
}
});
}
- private ConditionOperator getConditionOperator(Config input) {
+ private static ConditionOperator getConditionOperator(Config input) {
if (input.hasPath("condition-merge-operator")) {
- return ConditionOperator.valueOf(input.getString("condition-merge-operator").toUpperCase());
+ return ConditionOperator.valueOf(input.getString("condition-merge-operator").toUpperCase(Locale.ENGLISH));
}
return null;
}
- private List<ConditionDefinition> getConditions(List<? extends Config> conditionConfig) {
+ private static List<ConditionDefinition> getConditions(List<? extends Config> conditionConfig) {
return Lists.transform(conditionConfig, new Function<Config, ConditionDefinition>() {
@Override
- public ConditionDefinition apply(@Nullable Config input) {
+ public ConditionDefinition apply(Config input) {
List<CharSequence> args = Lists.newArrayList();
if (input.hasPath("args")) {
args.addAll(input.getStringList("args"));
@@ -192,10 +193,11 @@ public ConditionDefinition apply(@Nullable Config input) {
});
}
- private List<ExperimentDefinition> getExperiments(List<? extends Config> experimentConfig, final boolean isDomain) {
+ private static Collection<ExperimentDefinition> getExperiments(List<? extends Config> experimentConfig,
+ final boolean isDomain) {
return Lists.transform(experimentConfig, new Function<Config, ExperimentDefinition>() {
@Override
- public ExperimentDefinition apply(@Nullable Config input) {
+ public ExperimentDefinition apply(Config input) {
return ExperimentDefinition.newBuilder()
.setName(input.getString("name"))
.setDescription(input.getString("description"))
@@ -219,7 +221,7 @@ public ExperimentDefinition apply(@Nullable Config input) {
});
}
- private Long getTime(Config config, String path) {
+ private static Long getTime(Config config, String path) {
if (!config.hasPath(path)) {
return null;
} else {
@@ -227,10 +229,10 @@ private Long getTime(Config config, String path) {
}
}
- private List<BucketRange> getBucketRanges(List<? extends Config> bucketRangeConfig) {
+ private static List<BucketRange> getBucketRanges(List<? extends Config> bucketRangeConfig) {
return Lists.transform(bucketRangeConfig, new Function<Config, BucketRange>() {
@Override
- public BucketRange apply(@Nullable Config input) {
+ public BucketRange apply(Config input) {
return BucketRange.newBuilder()
.setStart(input.getInt("start"))
.setEnd(input.getInt("end"))
@@ -239,24 +241,24 @@ public BucketRange apply(@Nullable Config input) {
});
}
- private List<OverrideDefinition> getOverrides(List<? extends Config> overrideConfig) {
+ private static List<OverrideDefinition> getOverrides(List<? extends Config> overrideConfig) {
return Lists.transform(overrideConfig, new Function<Config, OverrideDefinition>() {
@Override
- public OverrideDefinition apply(@Nullable Config input) {
+ public OverrideDefinition apply(Config input) {
return OverrideDefinition.newBuilder()
.setName(input.getString("name"))
.setBaseValue(input.hasPath("base-value") ? input.getString("base-value") : "")
.setModifiers(getModifiers(getConfigList(input, "modifiers", false)))
- .setOperator(OverrideOperator.valueOf(input.getString("operator").toUpperCase()))
+ .setOperator(OverrideOperator.valueOf(input.getString("operator").toUpperCase(Locale.ENGLISH)))
.build();
}
});
}
- private List<LayerDefinition> getLayers(List<? extends Config> layerConfig) {
+ private static List<LayerDefinition> getLayers(List<? extends Config> layerConfig) {
return Lists.transform(layerConfig, new Function<Config, LayerDefinition>() {
@Override
- public LayerDefinition apply(@Nullable Config input) {
+ public LayerDefinition apply(Config input) {
return LayerDefinition.newBuilder()
.setName(input.getString("name"))
.setId(input.getInt("id"))
@@ -270,10 +272,10 @@ public LayerDefinition apply(@Nullable Config input) {
});
}
- private List<DiversionDefinition> getDiversions(List<? extends Config> divConfig) {
+ private static List<DiversionDefinition> getDiversions(List<? extends Config> divConfig) {
return Lists.transform(divConfig, new Function<Config, DiversionDefinition>() {
@Override
- public DiversionDefinition apply(@Nullable Config input) {
+ public DiversionDefinition apply(Config input) {
return DiversionDefinition.newBuilder()
.setId(input.getInt("id"))
.setName(input.getString("name"))
View
8 deploy/src/main/java/com/cloudera/gertrude/deploy/ConditionFactorySupport.java
@@ -28,10 +28,12 @@
import java.io.IOException;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
public class ConditionFactorySupport {
private static final Logger log = LoggerFactory.getLogger(ConditionFactorySupport.class);
+ private static final Pattern COMMA = Pattern.compile(",");
@Parameter(names = "--conditions-file",
description = "A file containing the names of valid conditions, one per line, used for validation.")
@@ -49,7 +51,7 @@ public ConditionFactory getConditionFactory() throws IOException {
}
Map<String, Condition<ExperimentState>> conditions = Maps.newHashMap();
for (String line : Files.readLines(new File(conditionsFile), Charsets.UTF_8)) {
- String[] pieces = line.split(",");
+ String[] pieces = COMMA.split(line);
if (pieces.length == 0) {
// Ignore
} else if (pieces.length == 1) {
@@ -75,11 +77,11 @@ public ConditionFactory getConditionFactory() throws IOException {
private final Map<String, Condition<ExperimentState>> conditions;
private final boolean strict;
- public DeployConditionFactory() {
+ private DeployConditionFactory() {
this(Maps.<String, Condition<ExperimentState>>newHashMap());
}
- public DeployConditionFactory(Map<String, Condition<ExperimentState>> conditions) {
+ private DeployConditionFactory(Map<String, Condition<ExperimentState>> conditions) {
this.conditions = conditions;
this.strict = !conditions.isEmpty();
}
View
1  deploy/src/main/java/com/cloudera/gertrude/deploy/CuratorSupport.java
@@ -15,7 +15,6 @@
package com.cloudera.gertrude.deploy;
import com.beust.jcommander.Parameter;
-import com.cloudera.gertrude.experiments.avro.ExperimentDeployment;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
View
10 deploy/src/main/java/com/cloudera/gertrude/deploy/Cyclone.java
@@ -21,11 +21,15 @@
import com.cloudera.gertrude.experiments.avro.ExperimentDeployment;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
public class Cyclone {
+ private static final Logger log = LoggerFactory.getLogger(Cyclone.class);
+
@Parameter(names = "--input", description="The input config file to parse, in either JSON or HOCON format.",
required=true)
private String inputFile;
@@ -58,7 +62,7 @@ private int run(String[] args) throws Exception {
try {
jc.parse(args);
} catch (ParameterException e) {
- System.err.println(e.getLocalizedMessage());
+ log.error(e.getLocalizedMessage());
jc.usage();
return 1;
}
@@ -71,7 +75,7 @@ private int run(String[] args) throws Exception {
Config config = ConfigFactory.parseFileAnySyntax(new File(inputFile));
ExperimentDeployment deployment = avroSupport.createDeployment(config);
if (deployment == null) {
- System.err.println("Could not create valid experiment deployment, exiting...");
+ log.error("Could not create valid experiment deployment, exiting...");
return 1;
}
if (curatorSupport.isEnabled()) {
@@ -83,6 +87,6 @@ private int run(String[] args) throws Exception {
}
public static void main(String[] args) throws Exception {
- System.exit(new Cyclone().run(args));
+ new Cyclone().run(args);
}
}
View
7 deploy/src/main/java/com/cloudera/gertrude/deploy/ExperimentFlagSupport.java
@@ -25,11 +25,14 @@
import java.io.File;
import java.io.IOException;
+import java.util.Locale;
import java.util.Map;
+import java.util.regex.Pattern;
public class ExperimentFlagSupport {
private static final Logger log = LoggerFactory.getLogger(ExperimentFlagSupport.class);
+ private static final Pattern COMMA = Pattern.compile(",");
@Parameter(names = "--flags-file",
description = "A CSV file of 'flag_name,flag_type' pairs used for validation.")
@@ -47,10 +50,10 @@ public ExperimentFlagSupport(String experimentFlagFile) {
}
ImmutableMap.Builder<String, ExperimentFlag<?>> b = ImmutableMap.builder();
for (String line : Files.readLines(new File(experimentFlagFile), Charsets.UTF_8)) {
- String[] pieces = line.split(",");
+ String[] pieces = COMMA.split(line);
if (pieces.length == 2) {
String flagName = pieces[0];
- String flagType = pieces[1].toLowerCase();
+ String flagType = pieces[1].toLowerCase(Locale.ENGLISH);
if (flagType.startsWith("bool")) {
b.put(flagName, Experiments.declare(flagName, false));
} else if (flagType.startsWith("int") || "long".equals(flagType)) {
View
5 file/src/main/java/com/cloudera/gertrude/file/FileExperimentSpaceLoader.java
@@ -30,7 +30,6 @@
private static final long DEFAULT_POLL_INTERVAL_MILLIS = 5 * 1000L;
private final File dataFile;
- private final FileAlterationMonitor monitor;
public FileExperimentSpaceLoader(File dataFile) throws Exception {
this(dataFile, DEFAULT_POLL_INTERVAL_MILLIS);
@@ -39,8 +38,8 @@ public FileExperimentSpaceLoader(File dataFile) throws Exception {
public FileExperimentSpaceLoader(File dataFile, long pollIntervalMillis) throws Exception {
Preconditions.checkArgument(!dataFile.isDirectory(), "Data file cannot be a directory");
this.dataFile = dataFile;
- this.monitor = getMonitor(pollIntervalMillis);
- this.monitor.start();
+ FileAlterationMonitor monitor = getMonitor(pollIntervalMillis);
+ monitor.start();
}
private FileAlterationMonitor getMonitor(long pollIntervalMillis) {
View
7 server/src/main/java/com/cloudera/gertrude/server/ExampleServlet.java
@@ -27,9 +27,10 @@
* An example of using experiment flags to control response behavior in a servlet.
*/
public class ExampleServlet extends HttpServlet {
- static ExperimentFlag<Long> MAX_RESPONSE_LENGTH = Experiments.declare("max_response_length", -1L);
- static ExperimentFlag<Boolean> SKIP_RESPONSE = Experiments.declare("skip_response", false);
- static ExperimentFlag<String> RESPONSE_TEXT = Experiments.declare("response_text", "Hello World!");
+
+ private static ExperimentFlag<Long> MAX_RESPONSE_LENGTH = Experiments.declare("max_response_length", -1L);
+ private static ExperimentFlag<Boolean> SKIP_RESPONSE = Experiments.declare("skip_response", false);
+ private static ExperimentFlag<String> RESPONSE_TEXT = Experiments.declare("response_text", "Hello World!");
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
View
11 server/src/main/java/com/cloudera/gertrude/server/GertrudeFilter.java
@@ -27,16 +27,17 @@
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
+import java.util.regex.Pattern;
/**
- * A simple servlet {@link Filter} for intercepting the current request, creating an associated
+ * A simple servlet {@link javax.servlet.Filter} for intercepting the current request, creating an associated
* {@link HttpServletExperimentStateImpl}, and diverting the request into one or more experiments using
- * a pre-configured {@link ExperimentHandler}.
+ * a pre-configured {@link com.cloudera.gertrude.ExperimentHandler}.
*/
public class GertrudeFilter implements Filter {
private static final String DIVERSION_COOKIES_PARAM = "gertrude-diversion-cookies";
- private static final String DIVERSION_COOKIES_SEP = ",";
+ private static final Pattern DIVERSION_COOKIES_SEP = Pattern.compile(",");
private ExperimentHandler handler;
private List<String> diversionCookies;
@@ -44,10 +45,10 @@
@Override
public void init(FilterConfig filterConfig) throws ServletException {
String divCookiesStr = filterConfig.getInitParameter(DIVERSION_COOKIES_PARAM);
- if (divCookiesStr == null | divCookiesStr.isEmpty()) {
+ if (divCookiesStr == null || divCookiesStr.isEmpty()) {
diversionCookies = ImmutableList.of();
} else {
- diversionCookies = ImmutableList.copyOf(divCookiesStr.split(DIVERSION_COOKIES_SEP));
+ diversionCookies = ImmutableList.copyOf(DIVERSION_COOKIES_SEP.split(divCookiesStr));
}
filterConfig.getServletContext().log("Gertrude diversion cookies: " + diversionCookies);
View
4 server/src/main/java/com/cloudera/gertrude/server/HttpServletExperimentStateImpl.java
@@ -19,7 +19,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
-import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@@ -34,7 +33,7 @@
private final HttpServletRequest request;
private final Map<Integer, String> diversionCookies;
- public HttpServletExperimentStateImpl(HttpServletRequest request, List<String> diversionCookies) {
+ HttpServletExperimentStateImpl(HttpServletRequest request, List<String> diversionCookies) {
this.request = Preconditions.checkNotNull(request);
this.diversionCookies = indexDiversionCookies(diversionCookies, request.getCookies());
}
@@ -58,6 +57,7 @@ public HttpServletExperimentStateImpl(HttpServletRequest request, List<String> d
return Optional.fromNullable(diversionCookies.get(diversionId));
}
+ @Override
public HttpServletRequest getRequest() {
return request;
}
View
3  server/src/main/java/com/cloudera/gertrude/server/condition/IntHeaderCondition.java
@@ -20,7 +20,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
-import javax.annotation.Nullable;
import java.util.List;
import java.util.Set;
@@ -43,7 +42,7 @@
// the second
return ImmutableSet.copyOf(Lists.transform(args.subList(1, args.size()), new Function<String, Integer>() {
@Override
- public Integer apply(@Nullable String input) {
+ public Integer apply(String input) {
return Integer.valueOf(input);
}
}));
Please sign in to comment.
Something went wrong with that request. Please try again.