Apache Solr open-source search software
SOLR-10278: renamed RuleSorted to Policy
Noble Paul83541fa96860
diff --git a/solr/solrj/src/java/org/apache/solr/recipe/AddReplicaSuggester.java b/solr/solrj/src/java/org/apache/solr/recipe/AddReplicaSuggester.javaindex ace808ddc01..31cfc1931e4 100644--- a/solr/solrj/src/java/org/apache/solr/recipe/AddReplicaSuggester.java+++ b/solr/solrj/src/java/org/apache/solr/recipe/AddReplicaSuggester.java@@ -20,8 +20,8 @@ package org.apache.solr.recipe;import java.util.Map;import org.apache.solr.common.util.Utils;-import org.apache.solr.recipe.RuleSorter.BaseSuggester;-import org.apache.solr.recipe.RuleSorter.Session;+import org.apache.solr.recipe.Policy.BaseSuggester;+import org.apache.solr.recipe.Policy.Session;import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;diff --git a/solr/solrj/src/java/org/apache/solr/recipe/Clause.java b/solr/solrj/src/java/org/apache/solr/recipe/Clause.javaindex 33858362a9c..203ab58d9a4 100644--- a/solr/solrj/src/java/org/apache/solr/recipe/Clause.java+++ b/solr/solrj/src/java/org/apache/solr/recipe/Clause.java@@ -27,7 +27,7 @@ import java.util.concurrent.atomic.AtomicReference;import org.apache.solr.common.MapWriter;import org.apache.solr.common.util.Utils;-import org.apache.solr.recipe.RuleSorter.ReplicaStat;+import org.apache.solr.recipe.Policy.ReplicaStat;import static java.util.Collections.singletonMap;import static org.apache.solr.common.params.CoreAdminParams.COLLECTION;@@ -41,8 +41,8 @@ import static org.apache.solr.recipe.Operand.GREATER_THAN;import static org.apache.solr.recipe.Operand.LESS_THAN;import static org.apache.solr.recipe.Operand.NOT_EQUAL;import static org.apache.solr.recipe.Operand.WILDCARD;-import static org.apache.solr.recipe.RuleSorter.ANY;-import static org.apache.solr.recipe.RuleSorter.EACH;+import static org.apache.solr.recipe.Policy.ANY;+import static org.apache.solr.recipe.Policy.EACH;// a set of conditions in a policypublic class Clause implements MapWriter {diff --git a/solr/solrj/src/java/org/apache/solr/recipe/MoveReplicaSuggester.java b/solr/solrj/src/java/org/apache/solr/recipe/MoveReplicaSuggester.javaindex 89273454832..2466ede8fb8 100644--- a/solr/solrj/src/java/org/apache/solr/recipe/MoveReplicaSuggester.java+++ b/solr/solrj/src/java/org/apache/solr/recipe/MoveReplicaSuggester.java@@ -21,8 +21,8 @@ import java.util.Map;import org.apache.solr.common.util.Pair;import org.apache.solr.common.util.Utils;-import org.apache.solr.recipe.RuleSorter.BaseSuggester;-import org.apache.solr.recipe.RuleSorter.Session;+import org.apache.solr.recipe.Policy.BaseSuggester;+import org.apache.solr.recipe.Policy.Session;import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;@@ -46,7 +46,7 @@ public class MoveReplicaSuggester extends BaseSuggester{//iterate through elements and identify the least loadedfor (int i = 0; i < matrix.size(); i++) {Row fromRow = matrix.get(i);- Pair<Row, RuleSorter.ReplicaStat> pair = fromRow.removeReplica(coll, shard);+ Pair<Row, Policy.ReplicaStat> pair = fromRow.removeReplica(coll, shard);fromRow = pair.first();if(fromRow == null){//no such replica availablediff --git a/solr/solrj/src/java/org/apache/solr/recipe/Operand.java b/solr/solrj/src/java/org/apache/solr/recipe/Operand.javaindex 796f06fd3d3..0d457c7f343 100644--- a/solr/solrj/src/java/org/apache/solr/recipe/Operand.java+++ b/solr/solrj/src/java/org/apache/solr/recipe/Operand.java@@ -21,7 +21,7 @@ import java.util.Objects;import org.apache.solr.recipe.Clause.TestStatus;import static org.apache.solr.recipe.Clause.TestStatus.*;-import static org.apache.solr.recipe.RuleSorter.ANY;+import static org.apache.solr.recipe.Policy.ANY;public enum Operand {@@ -34,7 +34,7 @@ public enum Operand {@Overridepublic Object parse(String val) {if(val == null) return ANY;- return ANY.equals(val) || RuleSorter.EACH.equals(val) ? val : null;+ return ANY.equals(val) || Policy.EACH.equals(val) ? val : null;}},EQUAL(""),diff --git a/solr/solrj/src/java/org/apache/solr/recipe/RuleSorter.java b/solr/solrj/src/java/org/apache/solr/recipe/Policy.javasimilarity index 96%rename from solr/solrj/src/java/org/apache/solr/recipe/RuleSorter.javarename to solr/solrj/src/java/org/apache/solr/recipe/Policy.javaindex 72246f74d09..222f756b64d 100644--- a/solr/solrj/src/java/org/apache/solr/recipe/RuleSorter.java+++ b/solr/solrj/src/java/org/apache/solr/recipe/Policy.java@@ -37,7 +37,7 @@ import org.apache.solr.common.util.Utils;import static java.util.Collections.singletonList;import static java.util.stream.Collectors.toList;-public class RuleSorter {+public class Policy {public static final String EACH = "#EACH";public static final String ANY = "#ANY";List<Clause> clauses = new ArrayList<>();@@ -45,7 +45,7 @@ public class RuleSorter {List<String> params= new ArrayList<>();- public RuleSorter(Map<String, Object> jsonMap) {+ public Policy(Map<String, Object> jsonMap) {List<Map<String, Object>> l = getListOfMap("conditions", jsonMap);clauses = l.stream().map(Clause::new).collect(toList());l = getListOfMap("preferences", jsonMap);@@ -86,8 +86,8 @@ public class RuleSorter {.collect(Collectors.toList());}- RuleSorter getRuleSorter() {- return RuleSorter.this;+ Policy getRuleSorter() {+ return Policy.this;}@@ -226,10 +226,10 @@ public class RuleSorter {static class BaseSuggester {final String coll;final String shard;- final RuleSorter.Session session;+ final Policy.Session session;List<Row> matrix;- BaseSuggester(String coll, String shard, RuleSorter.Session session) {+ BaseSuggester(String coll, String shard, Policy.Session session) {this.coll = coll;this.shard = shard;this.session = session;diff --git a/solr/solrj/src/java/org/apache/solr/recipe/Preference.java b/solr/solrj/src/java/org/apache/solr/recipe/Preference.javaindex 770f1762d85..56f387a635e 100644--- a/solr/solrj/src/java/org/apache/solr/recipe/Preference.java+++ b/solr/solrj/src/java/org/apache/solr/recipe/Preference.java@@ -21,15 +21,15 @@ import java.util.List;import java.util.Map;class Preference {- final RuleSorter.SortParam name;+ final Policy.SortParam name;Integer precision;- final RuleSorter.Sort sort;+ final Policy.Sort sort;Preference next;public int idx;Preference(Map<String, Object> m) {- sort = RuleSorter.Sort.get(m);- name = RuleSorter.SortParam.get(m.get(sort.name()).toString());+ sort = Policy.Sort.get(m);+ name = Policy.SortParam.get(m.get(sort.name()).toString());Object p = m.getOrDefault("precision", 0);precision = p instanceof Number ? ((Number) p).intValue() : Integer.parseInt(p.toString());diff --git a/solr/solrj/src/java/org/apache/solr/recipe/Row.java b/solr/solrj/src/java/org/apache/solr/recipe/Row.javaindex 216a3914a2a..a98a3a15803 100644--- a/solr/solrj/src/java/org/apache/solr/recipe/Row.java+++ b/solr/solrj/src/java/org/apache/solr/recipe/Row.java@@ -28,6 +28,7 @@ import org.apache.solr.common.IteratorWriter;import org.apache.solr.common.MapWriter;import org.apache.solr.common.util.Pair;import org.apache.solr.common.util.Utils;+import org.apache.solr.recipe.Policy.ReplicaStat;import static org.apache.solr.common.params.CoreAdminParams.NODE;@@ -35,11 +36,11 @@ import static org.apache.solr.common.params.CoreAdminParams.NODE;class Row implements MapWriter {public final String node;final Cell[] cells;- Map<String, Map<String, List<RuleSorter.ReplicaStat>>> replicaInfo;+ Map<String, Map<String, List<ReplicaStat>>> replicaInfo;List<Clause> violations = new ArrayList<>();boolean anyValueMissing = false;- Row(String node, List<String> params, RuleSorter.NodeValueProvider snitch) {+ Row(String node, List<String> params, Policy.NodeValueProvider snitch) {replicaInfo = snitch.getReplicaCounts(node, params);if (replicaInfo == null) replicaInfo = Collections.emptyMap();this.node = node;@@ -53,7 +54,7 @@ class Row implements MapWriter {}}- Row(String node, Cell[] cells, boolean anyValueMissing, Map<String, Map<String, List<RuleSorter.ReplicaStat>>> replicaInfo, List<Clause> violations) {+ Row(String node, Cell[] cells, boolean anyValueMissing, Map<String, Map<String, List<ReplicaStat>>> replicaInfo, List<Clause> violations) {this.node = node;this.cells = new Cell[cells.length];for (int i = 0; i < this.cells.length; i++) {@@ -89,20 +90,20 @@ class Row implements MapWriter {Row addReplica(String coll, String shard) {Row row = copy();- Map<String, List<RuleSorter.ReplicaStat>> c = row.replicaInfo.get(coll);+ Map<String, List<ReplicaStat>> c = row.replicaInfo.get(coll);if (c == null) row.replicaInfo.put(coll, c = new HashMap<>());- List<RuleSorter.ReplicaStat> s = c.get(shard);+ List<ReplicaStat> s = c.get(shard);if (s == null) c.put(shard, s = new ArrayList<>());return row;}- Pair<Row, RuleSorter.ReplicaStat> removeReplica(String coll, String shard) {+ Pair<Row, ReplicaStat> removeReplica(String coll, String shard) {Row row = copy();- Map<String, List<RuleSorter.ReplicaStat>> c = row.replicaInfo.get(coll);+ Map<String, List<ReplicaStat>> c = row.replicaInfo.get(coll);if(c == null) return null;- List<RuleSorter.ReplicaStat> s = c.get(shard);+ List<ReplicaStat> s = c.get(shard);if (s == null || s.isEmpty()) return null;return new Pair(row,s.remove(0));diff --git a/solr/solrj/src/test/org/apache/solr/recipe/TestRuleSorter.java b/solr/solrj/src/test/org/apache/solr/recipe/TestPolicy.javasimilarity index 88%rename from solr/solrj/src/test/org/apache/solr/recipe/TestRuleSorter.javarename to solr/solrj/src/test/org/apache/solr/recipe/TestPolicy.javaindex e69ad99e18b..c9ea01149b1 100644--- a/solr/solrj/src/test/org/apache/solr/recipe/TestRuleSorter.java+++ b/solr/solrj/src/test/org/apache/solr/recipe/TestPolicy.java@@ -31,7 +31,7 @@ import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.util.Utils;import org.apache.solr.common.util.ValidatingJsonMap;-public class TestRuleSorter extends SolrTestCaseJ4 {+public class TestPolicy extends SolrTestCaseJ4 {public void testOperands() {Clause c = new Clause((Map<String, Object>) Utils.fromJSONString("{replica:'<2', node:'#ANY'}"));@@ -113,9 +113,9 @@ public class TestRuleSorter extends SolrTestCaseJ4 {.getDeepCopy((Map) Utils.fromJSONString(clusterState), 6, true);- RuleSorter ruleSorter = new RuleSorter((Map<String, Object>) Utils.fromJSONString(rules));- RuleSorter.Session session;- RuleSorter.NodeValueProvider snitch = new RuleSorter.NodeValueProvider() {+ Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(rules));+ Policy.Session session;+ Policy.NodeValueProvider snitch = new Policy.NodeValueProvider() {@Overridepublic Map<String,Object> getValues(String node, Collection<String> keys) {Map<String,Object> result = new LinkedHashMap<>();@@ -124,8 +124,8 @@ public class TestRuleSorter extends SolrTestCaseJ4 {}@Override- public Map<String, Map<String, List<RuleSorter.ReplicaStat>>> getReplicaCounts(String node, Collection<String> keys) {- Map<String, Map<String, List<RuleSorter.ReplicaStat>>> result = new LinkedHashMap<>();+ public Map<String, Map<String, List<Policy.ReplicaStat>>> getReplicaCounts(String node, Collection<String> keys) {+ Map<String, Map<String, List<Policy.ReplicaStat>>> result = new LinkedHashMap<>();m.forEach((collName, o) -> {ValidatingJsonMap coll = (ValidatingJsonMap) o;@@ -135,11 +135,11 @@ public class TestRuleSorter extends SolrTestCaseJ4 {ValidatingJsonMap r = (ValidatingJsonMap) o2;String node_name = (String) r.get("node_name");if (!node_name.equals(node)) return;- Map<String, List<RuleSorter.ReplicaStat>> shardVsReplicaStats = result.get(collName);+ Map<String, List<Policy.ReplicaStat>> shardVsReplicaStats = result.get(collName);if (shardVsReplicaStats == null) result.put(collName, shardVsReplicaStats = new HashMap<>());- List<RuleSorter.ReplicaStat> replicaStats = shardVsReplicaStats.get(shard);+ List<Policy.ReplicaStat> replicaStats = shardVsReplicaStats.get(shard);if (replicaStats == null) shardVsReplicaStats.put(shard, replicaStats = new ArrayList<>());- replicaStats.add(new RuleSorter.ReplicaStat(replicaName, new HashMap<>()));+ replicaStats.add(new Policy.ReplicaStat(replicaName, new HashMap<>()));});});});@@ -150,7 +150,7 @@ public class TestRuleSorter extends SolrTestCaseJ4 {};- session = ruleSorter.createSession(Arrays.asList("node1", "node2", "node3", "node4"), snitch);+ session = policy.createSession(Arrays.asList("node1", "node2", "node3", "node4"), snitch);session.applyRules();List<Row> l = session.getSorted();