You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2017/10/04 17:28:10 UTC

[1/2] lucene-solr:jira/solr-11285: SOLR-11285: Fix AutoScalingConfig modifier methods. Use ReplicaInfo properties instead of constructor args to allow for modifications.

Repository: lucene-solr
Updated Branches:
  refs/heads/jira/solr-11285 06d89bb1c -> e625512c5


SOLR-11285: Fix AutoScalingConfig modifier methods. Use ReplicaInfo properties instead of
constructor args to allow for modifications.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/25ef8af9
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/25ef8af9
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/25ef8af9

Branch: refs/heads/jira/solr-11285
Commit: 25ef8af96729ad5acb7a14dbbc6818bb38441581
Parents: 06d89bb
Author: Andrzej Bialecki <ab...@apache.org>
Authored: Wed Oct 4 16:40:51 2017 +0200
Committer: Andrzej Bialecki <ab...@apache.org>
Committed: Wed Oct 4 17:16:24 2017 +0200

----------------------------------------------------------------------
 .../cloud/autoscaling/AutoScalingConfig.java    |  8 ++-
 .../DelegatingClusterStateProvider.java         | 51 ++++++++++++---
 .../cloud/autoscaling/DistribStateManager.java  |  7 +-
 .../cloud/autoscaling/MoveReplicaSuggester.java |  8 +--
 .../client/solrj/cloud/autoscaling/Policy.java  | 20 +++++-
 .../solrj/cloud/autoscaling/ReplicaCount.java   |  2 +-
 .../solrj/cloud/autoscaling/ReplicaInfo.java    | 69 ++++++++++++++++----
 .../client/solrj/cloud/autoscaling/Row.java     |  6 +-
 .../solrj/impl/SolrClientNodeStateProvider.java |  2 +-
 .../solrj/cloud/autoscaling/TestPolicy.java     |  8 +--
 10 files changed, 144 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java
index 51e8f42..5312c29 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java
@@ -495,6 +495,10 @@ public class AutoScalingConfig implements MapWriter {
     ew.put("listeners", getTriggerListenerConfigs());
   }
 
+  public String toString() {
+    return Utils.toJSONString(this);
+  }
+
   @Override
   public boolean equals(Object o) {
     if (this == o) return true;
@@ -503,8 +507,8 @@ public class AutoScalingConfig implements MapWriter {
     AutoScalingConfig that = (AutoScalingConfig) o;
 
     if (!getPolicy().equals(that.getPolicy())) return false;
-    if (!triggers.equals(that.triggers)) return false;
-    return listeners.equals(that.listeners);
+    if (!getTriggerConfigs().equals(that.getTriggerConfigs())) return false;
+    return getTriggerListenerConfigs().equals(that.getTriggerListenerConfigs());
   }
 
   private static List<Object> getList(String key, Map<String, Object> properties) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DelegatingClusterStateProvider.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DelegatingClusterStateProvider.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DelegatingClusterStateProvider.java
index 9119271..10f18e3 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DelegatingClusterStateProvider.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DelegatingClusterStateProvider.java
@@ -18,6 +18,7 @@ package org.apache.solr.client.solrj.cloud.autoscaling;
 
 import java.io.IOException;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -37,46 +38,78 @@ public class DelegatingClusterStateProvider implements ClusterStateProvider {
 
   @Override
   public ClusterState.CollectionRef getState(String collection) {
-    return delegate.getState(collection);
+    if (delegate != null) {
+      return delegate.getState(collection);
+    } else {
+      return null;
+    }
   }
 
   @Override
   public Set<String> getLiveNodes() {
-    return delegate.getLiveNodes();
+    if (delegate != null) {
+      return delegate.getLiveNodes();
+    } else {
+      return Collections.emptySet();
+    }
   }
 
   @Override
   public String getAlias(String alias) {
-    return delegate.getAlias(alias);
+    if (delegate != null) {
+      return delegate.getAlias(alias);
+    } else {
+      return null;
+    }
   }
 
   @Override
   public String getCollectionName(String name) {
-    return delegate.getCollectionName(name);
+    if (delegate != null) {
+      return delegate.getCollectionName(name);
+    } else {
+      return null;
+    }
   }
 
   @Override
   public ClusterState getClusterState() throws IOException {
-    return delegate.getClusterState();
+    if (delegate != null) {
+      return delegate.getClusterState();
+    } else {
+      return null;
+    }
   }
 
   @Override
   public Map<String, Object> getClusterProperties() {
-    return delegate.getClusterProperties();
+    if (delegate != null) {
+      return delegate.getClusterProperties();
+    } else {
+      return Collections.emptyMap();
+    }
   }
 
   @Override
   public String getPolicyNameByCollection(String coll) {
-    return delegate.getPolicyNameByCollection(coll);
+    if (delegate != null) {
+      return delegate.getPolicyNameByCollection(coll);
+    } else {
+      return null;
+    }
   }
 
   @Override
   public void connect() {
-    delegate.connect();
+    if (delegate != null) {
+      delegate.connect();
+    }
   }
 
   @Override
   public void close() throws IOException {
-    delegate.close();
+    if (delegate != null) {
+      delegate.close();
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DistribStateManager.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DistribStateManager.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DistribStateManager.java
index 084c5b2..b5839d6 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DistribStateManager.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/DistribStateManager.java
@@ -16,6 +16,7 @@
  */
 package org.apache.solr.client.solrj.cloud.autoscaling;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.util.List;
 import java.util.NoSuchElementException;
@@ -29,7 +30,7 @@ import org.apache.zookeeper.Watcher;
 /**
  * Represents a distributed state repository.
  */
-public interface DistribStateManager {
+public interface DistribStateManager extends Closeable {
 
   // state accessors
 
@@ -61,4 +62,8 @@ public interface DistribStateManager {
     return getAutoScalingConfig(null);
   }
 
+  @Override
+  default void close() throws IOException {
+
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/MoveReplicaSuggester.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/MoveReplicaSuggester.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/MoveReplicaSuggester.java
index b32fc98..7e819cd 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/MoveReplicaSuggester.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/MoveReplicaSuggester.java
@@ -45,7 +45,7 @@ public class MoveReplicaSuggester extends Suggester {
       ReplicaInfo replicaInfo = fromReplica.first();
       String coll = replicaInfo.collection;
       String shard = replicaInfo.shard;
-      Pair<Row, ReplicaInfo> pair = fromRow.removeReplica(coll, shard, replicaInfo.type);
+      Pair<Row, ReplicaInfo> pair = fromRow.removeReplica(coll, shard, replicaInfo.getType());
       Row srcTmpRow = pair.first();
       if (srcTmpRow == null) {
         //no such replica available
@@ -57,7 +57,7 @@ public class MoveReplicaSuggester extends Suggester {
         Row targetRow = getMatrix().get(j);
         if(!targetRow.isLive) continue;
         if (!isAllowed(targetRow.node, Hint.TARGET_NODE)) continue;
-        targetRow = targetRow.addReplica(coll, shard, replicaInfo.type);
+        targetRow = targetRow.addReplica(coll, shard, replicaInfo.getType());
         List<Violation> errs = testChangedMatrix(strict, getModifiedMatrix(getModifiedMatrix(getMatrix(), srcTmpRow, i), targetRow, j));
         if (!containsNewErrors(errs) && isLessSerious(errs, leastSeriousViolation) &&
             Policy.compareRows(srcTmpRow, targetRow, session.getPolicy()) < 1) {
@@ -69,8 +69,8 @@ public class MoveReplicaSuggester extends Suggester {
       }
     }
     if (targetNodeIndex != null && sourceNodeIndex != null) {
-      getMatrix().set(sourceNodeIndex, getMatrix().get(sourceNodeIndex).removeReplica(sourceReplicaInfo.collection, sourceReplicaInfo.shard, sourceReplicaInfo.type).first());
-      getMatrix().set(targetNodeIndex, getMatrix().get(targetNodeIndex).addReplica(sourceReplicaInfo.collection, sourceReplicaInfo.shard, sourceReplicaInfo.type));
+      getMatrix().set(sourceNodeIndex, getMatrix().get(sourceNodeIndex).removeReplica(sourceReplicaInfo.collection, sourceReplicaInfo.shard, sourceReplicaInfo.getType()).first());
+      getMatrix().set(targetNodeIndex, getMatrix().get(targetNodeIndex).addReplica(sourceReplicaInfo.collection, sourceReplicaInfo.shard, sourceReplicaInfo.getType()));
       return new CollectionAdminRequest.MoveReplica(
           sourceReplicaInfo.collection,
           sourceReplicaInfo.name,

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/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 040739d..ba5339a 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
@@ -129,11 +129,27 @@ public class Policy implements MapWriter {
   }
 
   public Policy withClusterPreferences(List<Preference> clusterPreferences) {
-    return new Policy(policies, clusterPolicy, clusterPreferences, params);
+    // modify existing params
+    List<String> newParams = new ArrayList<>(params);
+    this.clusterPreferences.forEach(p -> newParams.remove(p.name.toString()));
+    clusterPreferences.forEach(p -> {
+      if (!newParams.contains(p.name.toString())) {
+        newParams.add(p.name.toString());
+      }
+    });
+    return new Policy(policies, clusterPolicy, clusterPreferences, newParams);
   }
 
   public Policy withClusterPolicy(List<Clause> clusterPolicy) {
-    return new Policy(policies, clusterPolicy, clusterPreferences, params);
+    // modify existing params
+    Set<String> paramsToRemove = new HashSet<>();
+    this.clusterPolicy.forEach(c -> {
+      c.addTags(paramsToRemove);
+    });
+    List<String> newParams = new ArrayList<>(params);
+    newParams.removeAll(paramsToRemove);
+    clusterPolicy.forEach(c -> c.addTags(newParams));
+    return new Policy(policies, clusterPolicy, clusterPreferences, newParams);
   }
 
   public Policy withParams(List<String> params) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaCount.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaCount.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaCount.java
index 56a0205..acb8c68 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaCount.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaCount.java
@@ -74,7 +74,7 @@ class ReplicaCount extends Number implements MapWriter {
   public void increment(List<ReplicaInfo> infos) {
     if (infos == null) return;
     for (ReplicaInfo info : infos) {
-      switch (info.type) {
+      switch (info.getType()) {
         case NRT:
           nrt++;
           break;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
index f6b9db1..9970625 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/ReplicaInfo.java
@@ -18,38 +18,43 @@
 package org.apache.solr.client.solrj.cloud.autoscaling;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 
 import org.apache.solr.common.MapWriter;
 import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.cloud.ZkStateReader;
 
 
 public class ReplicaInfo implements MapWriter {
   final String name;
-  String core, collection, shard;
-  Replica.Type type;
-  Map<String, Object> variables;
+  final String core, collection, shard;
+  final Map<String, Object> variables = new HashMap<>();
 
-  public ReplicaInfo(String name, String coll, String shard, Replica.Type type, Map<String, Object> vals) {
+  public ReplicaInfo(String name, String coll, String shard, Map<String, Object> vals) {
     this.name = name;
-    this.variables = vals;
+    if (vals != null) {
+      this.variables.putAll(vals);
+    }
     this.collection = coll;
     this.shard = shard;
-    this.type = type;
+    this.core = (String)vals.get("core");
   }
 
   @Override
   public void writeMap(EntryWriter ew) throws IOException {
     ew.put(name, (MapWriter) ew1 -> {
-      if (variables != null) {
-        for (Map.Entry<String, Object> e : variables.entrySet()) {
-          ew1.put(e.getKey(), e.getValue());
-        }
+      for (Map.Entry<String, Object> e : variables.entrySet()) {
+        ew1.put(e.getKey(), e.getValue());
       }
-      if (type != null) ew1.put("type", type.toString());
     });
   }
 
+  public String getName() {
+    return name;
+  }
+
   public String getCore() {
     return core;
   }
@@ -61,4 +66,46 @@ public class ReplicaInfo implements MapWriter {
   public String getShard() {
     return shard;
   }
+
+  public Replica.Type getType() {
+    Object o = variables.get(ZkStateReader.REPLICA_TYPE);
+    if (o == null) {
+      variables.put(ZkStateReader.REPLICA_TYPE, Replica.Type.NRT);
+      return Replica.Type.NRT;
+    } else if (o instanceof Replica.Type) {
+      return (Replica.Type)o;
+    } else {
+      Replica.Type type = Replica.Type.get(String.valueOf(o).toUpperCase(Locale.ROOT));
+      variables.put(ZkStateReader.REPLICA_TYPE, type);
+      return type;
+    }
+  }
+
+  public Replica.State getState() {
+    if (variables.get(ZkStateReader.STATE_PROP) != null) {
+      return Replica.State.getState((String) variables.get(ZkStateReader.STATE_PROP));
+    } else {
+      // default to ACTIVE
+      variables.put(ZkStateReader.STATE_PROP, Replica.State.ACTIVE.toString());
+      return Replica.State.ACTIVE;
+    }
+  }
+
+  public Map<String, Object> getVariables() {
+    return variables;
+  }
+
+  public Object getVariable(String name) {
+    return variables.get(name);
+  }
+
+  @Override
+  public String toString() {
+    return "ReplicaInfo{" +
+        "name='" + name + '\'' +
+        ", collection='" + collection + '\'' +
+        ", shard='" + shard + '\'' +
+        ", variables=" + variables +
+        '}';
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java
index 063cffb..d69b3ab 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Row.java
@@ -28,6 +28,7 @@ import java.util.Random;
 import org.apache.solr.common.IteratorWriter;
 import org.apache.solr.common.MapWriter;
 import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.util.Pair;
 import org.apache.solr.common.util.Utils;
 
@@ -97,7 +98,8 @@ public class Row implements MapWriter {
     Row row = copy();
     Map<String, List<ReplicaInfo>> c = row.collectionVsShardVsReplicas.computeIfAbsent(coll, k -> new HashMap<>());
     List<ReplicaInfo> replicas = c.computeIfAbsent(shard, k -> new ArrayList<>());
-    replicas.add(new ReplicaInfo("" + new Random().nextInt(1000) + 1000, coll, shard, type, new HashMap<>()));
+    replicas.add(new ReplicaInfo("" + new Random().nextInt(1000) + 1000, coll, shard,
+        Collections.singletonMap(ZkStateReader.REPLICA_TYPE, type != null ? type.toString() : Replica.Type.NRT.toString())));
     for (Cell cell : row.cells) {
       if (cell.name.equals("cores")) {
         cell.val = cell.val == null ? 0 : ((Number) cell.val).longValue() + 1;
@@ -116,7 +118,7 @@ public class Row implements MapWriter {
     int idx = -1;
     for (int i = 0; i < r.size(); i++) {
       ReplicaInfo info = r.get(i);
-      if (type == null || info.type == type) {
+      if (type == null || info.getType() == type) {
         idx = i;
         break;
       }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java
index c5b3d43..d7be7fe 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java
@@ -82,7 +82,7 @@ public class SolrClientNodeStateProvider implements NodeStateProvider {
         Map<String, Map<String, List<ReplicaInfo>>> nodeData = data.computeIfAbsent(replica.getNodeName(), k -> new HashMap<>());
         Map<String, List<ReplicaInfo>> collData = nodeData.computeIfAbsent(collName, k -> new HashMap<>());
         List<ReplicaInfo> replicas = collData.computeIfAbsent(shard, k -> new ArrayList<>());
-        replicas.add(new ReplicaInfo(replica.getName(), collName, shard, replica.getType(), new HashMap<>()));
+        replicas.add(new ReplicaInfo(replica.getName(), collName, shard, replica.getProperties()));
       });
     });
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/25ef8af9/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java b/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
index 08b8e7c..1957afc 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
@@ -114,7 +114,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
           if (!node_name.equals(node)) return;
           Map<String, List<ReplicaInfo>> shardVsReplicaStats = result.computeIfAbsent(collName, k -> new HashMap<>());
           List<ReplicaInfo> replicaInfos = shardVsReplicaStats.computeIfAbsent(shard, k -> new ArrayList<>());
-          replicaInfos.add(new ReplicaInfo(replicaName, collName, shard, Replica.Type.get((String) r.get(ZkStateReader.REPLICA_TYPE)), new HashMap<>()));
+          replicaInfos.add(new ReplicaInfo(replicaName, collName, shard, r));
         });
       });
     });
@@ -424,7 +424,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
             Object o = l3.get(i);
             Map m3 = (Map) o;
             l3.set(i, new ReplicaInfo(m3.keySet().iterator().next().toString()
-                ,coll.toString(), shard.toString(), Replica.Type.get((String)m3.get("type")), new HashMap<>()));
+                ,coll.toString(), shard.toString(), m3));
           }
         });
 
@@ -1005,8 +1005,8 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "      {'core_node2':{}}]}}}");
     Map m = (Map) Utils.getObjectByPath(replicaInfoMap, false, "127.0.0.1:60089_solr/compute_plan_action_test");
     m.put("shard1", Arrays.asList(
-        new ReplicaInfo("core_node1", "compute_plan_action_test", "shard1", Replica.Type.NRT, Collections.emptyMap()),
-        new ReplicaInfo("core_node2", "compute_plan_action_test", "shard1", Replica.Type.NRT, Collections.emptyMap())
+        new ReplicaInfo("core_node1", "compute_plan_action_test", "shard1", Collections.singletonMap(ZkStateReader.REPLICA_TYPE, Replica.Type.NRT)),
+        new ReplicaInfo("core_node2", "compute_plan_action_test", "shard1", Collections.singletonMap(ZkStateReader.REPLICA_TYPE, Replica.Type.NRT))
     ));
 
     Map<String, Map<String, Object>> tagsMap = (Map) Utils.fromJSONString("{" +


[2/2] lucene-solr:jira/solr-11285: SOLR-11285: Fix a bug in Policy modifier methods.

Posted by ab...@apache.org.
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/e625512c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e625512c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e625512c

Branch: refs/heads/jira/solr-11285
Commit: e625512c5cc6e2b43a24070b2fe13cd9595331a1
Parents: 25ef8af
Author: Andrzej Bialecki <ab...@apache.org>
Authored: Wed Oct 4 18:53:32 2017 +0200
Committer: Andrzej Bialecki <ab...@apache.org>
Committed: Wed Oct 4 18:53:32 2017 +0200

----------------------------------------------------------------------
 .../client/solrj/cloud/autoscaling/Policy.java  | 45 ++++++++++----------
 1 file changed, 22 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e625512c/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 ba5339a..67d65fb 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
@@ -115,45 +115,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) {
-    // modify existing params
-    List<String> newParams = new ArrayList<>(params);
-    this.clusterPreferences.forEach(p -> newParams.remove(p.name.toString()));
-    clusterPreferences.forEach(p -> {
-      if (!newParams.contains(p.name.toString())) {
-        newParams.add(p.name.toString());
-      }
-    });
-    return new Policy(policies, clusterPolicy, clusterPreferences, newParams);
+    return new Policy(policies, clusterPolicy, clusterPreferences);
   }
 
   public Policy withClusterPolicy(List<Clause> clusterPolicy) {
-    // modify existing params
-    Set<String> paramsToRemove = new HashSet<>();
-    this.clusterPolicy.forEach(c -> {
-      c.addTags(paramsToRemove);
-    });
-    List<String> newParams = new ArrayList<>(params);
-    newParams.removeAll(paramsToRemove);
-    clusterPolicy.forEach(c -> c.addTags(newParams));
-    return new Policy(policies, clusterPolicy, clusterPreferences, newParams);
+    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() {