Merge pull request #1424 from pjain1/validate_rules

Check lower bound of replicant values for rules
This commit is contained in:
Himanshu 2015-06-04 14:16:50 -05:00
commit f44f7f07de
4 changed files with 11 additions and 0 deletions

View File

@ -36,6 +36,7 @@ public class ForeverLoadRule extends LoadRule
@JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants
)
{
validateTieredReplicants(tieredReplicants);
this.tieredReplicants = tieredReplicants;
}

View File

@ -41,6 +41,7 @@ public class IntervalLoadRule extends LoadRule
@JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants
)
{
validateTieredReplicants(tieredReplicants);
this.interval = interval;
this.tieredReplicants = tieredReplicants;
}

View File

@ -20,6 +20,7 @@ package io.druid.server.coordinator.rules;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.MinMaxPriorityQueue;
import com.metamx.common.IAE;
import com.metamx.emitter.EmittingLogger;
import io.druid.server.coordinator.BalancerStrategy;
import io.druid.server.coordinator.CoordinatorStats;
@ -240,6 +241,13 @@ public abstract class LoadRule implements Rule
return stats;
}
protected void validateTieredReplicants(Map<String, Integer> tieredReplicants){
for (Map.Entry<String, Integer> entry: tieredReplicants.entrySet()) {
if (entry.getValue() < 0)
throw new IAE("Replicant value [%d] is less than 0, which is not allowed", entry.getValue());
}
}
public abstract Map<String, Integer> getTieredReplicants();
public abstract int getNumReplicants(String tier);

View File

@ -42,6 +42,7 @@ public class PeriodLoadRule extends LoadRule
@JsonProperty("tieredReplicants") Map<String, Integer> tieredReplicants
)
{
validateTieredReplicants(tieredReplicants);
this.period = period;
this.tieredReplicants = tieredReplicants;
}