Skip to content

Apache Lucene open-source search software

SOLR-11285: Fix a bug in Policy modifier methods.

Andrzej Bialecki5c62fb56f7a7
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
index 12024e431ea..78961d6ba2d 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
@@ -113,29 +113,44 @@ public class Policy implements MapWriter {
}
- private Policy(Map<String, List<Clause>> policies, List<Clause> clusterPolicy, List<Preference> clusterPreferences,
- List<String> params) {
+ private Policy(Map<String, List<Clause>> policies, List<Clause> clusterPolicy, List<Preference> clusterPreferences) {
this.policies = policies != null ? Collections.unmodifiableMap(policies) : Collections.emptyMap();
this.clusterPolicy = clusterPolicy != null ? Collections.unmodifiableList(clusterPolicy) : Collections.emptyList();
this.clusterPreferences = clusterPreferences != null ? Collections.unmodifiableList(clusterPreferences) :
Collections.singletonList(DEFAULT_PREFERENCE);
- this.params = params != null ? Collections.unmodifiableList(params) : Collections.emptyList();
+ this.params = Collections.unmodifiableList(buildParams(this.clusterPreferences, this.clusterPolicy, this.policies));
+ }
+
+ private List<String> buildParams(List<Preference> preferences, List<Clause> policy, Map<String, List<Clause>> policies) {
+ final SortedSet<String> paramsOfInterest = new TreeSet<>();
+ preferences.forEach(p -> {
+ if (paramsOfInterest.contains(p.name.name())) {
+ throw new RuntimeException(p.name + " is repeated");
+ }
+ paramsOfInterest.add(p.name.toString());
+ });
+ List<String> newParams = new ArrayList<>(paramsOfInterest);
+ policy.forEach(c -> {
+ c.addTags(newParams);
+ });
+ policies.values().forEach(clauses -> clauses.forEach(c -> c.addTags(newParams)));
+ return newParams;
}
public Policy withPolicies(Map<String, List<Clause>> policies) {
- return new Policy(policies, clusterPolicy, clusterPreferences, params);
+ return new Policy(policies, clusterPolicy, clusterPreferences);
}
public Policy withClusterPreferences(List<Preference> clusterPreferences) {
- return new Policy(policies, clusterPolicy, clusterPreferences, params);
+ return new Policy(policies, clusterPolicy, clusterPreferences);
}
public Policy withClusterPolicy(List<Clause> clusterPolicy) {
- return new Policy(policies, clusterPolicy, clusterPreferences, params);
+ return new Policy(policies, clusterPolicy, clusterPreferences);
}
public Policy withParams(List<String> params) {
- return new Policy(policies, clusterPolicy, clusterPreferences, params);
+ return new Policy(policies, clusterPolicy, clusterPreferences);
}
public List<Clause> getClusterPolicy() {