Apache Lucene open-source search software
SOLR-12387: fixing a test failure
Noble Paulf9d807af755f
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.javaindex 01d2fe89884..269bb50641d 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java@@ -206,9 +206,10 @@ public class CollectionsHandler extends RequestHandlerBase implements Permissionreturn this.coreContainer;}- protected void copyFromClusterProp(Map<String, Object> props, String prop) {+ protected void copyFromClusterProp(Map<String, Object> props, String prop) throws IOException {if (props.get(prop) != null) return;//if it's already specified , return- Object defVal = coreContainer.getZkController().getZkStateReader().getClusterProperty(ImmutableList.of(COLLECTION_DEF, prop), null);+ Object defVal = new ClusterProperties(coreContainer.getZkController().getZkStateReader().getZkClient())+ .getClusterProperty(ImmutableList.of(COLLECTION_DEF, prop), null);if (defVal != null) props.put(prop, String.valueOf(defVal));}diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterProperties.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterProperties.javaindex 87896daad5b..446923b81de 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterProperties.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterProperties.java@@ -21,6 +21,7 @@ import java.io.IOException;import java.lang.invoke.MethodHandles;import java.util.Collections;import java.util.LinkedHashMap;+import java.util.List;import java.util.Map;import org.apache.solr.common.SolrException;@@ -67,6 +68,23 @@ public class ClusterProperties {return value;}+ /**+ * Read the value of a cluster property, returning a default if it is not set+ *+ * @param key the property name or the full path to the property as a list of parts.+ * @param defaultValue the default value+ * @param <T> the type of the property+ * @return the property value+ * @throws IOException if there is an error reading the value from the cluster+ */+ @SuppressWarnings("unchecked")+ public <T> T getClusterProperty(List<String> key, T defaultValue) throws IOException {+ T value = (T) Utils.getObjectByPath(getClusterProperties(), false, key);+ if (value == null)+ return defaultValue;+ return value;+ }+/*** Return the cluster properties* @throws IOException if there is an error reading properties from the clusterdiff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.javaindex 6b65c344d4c..a86c5e28448 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java@@ -961,6 +961,12 @@ public class ZkStateReader implements Closeable {return value;}+ /**Same as the above but allows a full json path as a list of parts+ *+ * @param keyPath path to the property example ["collectionDefauls", "numShards"]+ * @param defaultValue a default value to use if no such property exists+ * @return the cluster property, or a default if the property is not set+ */public <T> T getClusterProperty(List<String> keyPath, T defaultValue) {T value = (T) Utils.getObjectByPath( clusterProperties, false, keyPath);if (value == null)