You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2017/10/09 15:31:03 UTC
[11/19] lucene-solr:branch_7x: SOLR-11285: Fix a bug in Policy
modifier methods.
SOLR-11285: Fix a bug in Policy modifier methods.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/87f0b057
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/87f0b057
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/87f0b057
Branch: refs/heads/branch_7x
Commit: 87f0b0570c6c708d232f76f6cd09dd35ba47be9c
Parents: ccf1bf7
Author: Andrzej Bialecki <ab...@apache.org>
Authored: Wed Oct 4 18:53:32 2017 +0200
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Mon Oct 9 17:09:50 2017 +0530
----------------------------------------------------------------------
.../client/solrj/cloud/autoscaling/Policy.java | 29 +++++++++++++++-----
1 file changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/87f0b057/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
----------------------------------------------------------------------
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 12024e4..78961d6 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() {