You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2018/09/06 21:10:48 UTC

lucene-solr:branch_7x: SOLR-12612: Accept custom keys in cluster properties

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 42f1fe1d4 -> 50c92f1a0


SOLR-12612: Accept custom keys in cluster properties

Cluster properties restriction of known keys only is relaxed, and now unknown properties starting with "ext."
will be allowed. This allows custom to plugins set their own cluster properties.


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

Branch: refs/heads/branch_7x
Commit: 50c92f1a0a1006af5b03ce276796b4378e0ecdc9
Parents: 42f1fe1
Author: Tomas Fernandez Lobbe <tf...@apache.org>
Authored: Thu Sep 6 14:07:30 2018 -0700
Committer: Tomas Fernandez Lobbe <tf...@apache.org>
Committed: Thu Sep 6 14:10:37 2018 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 +++
 .../solr/cloud/TestClusterProperties.java       | 25 +++++++++++++++++++-
 .../solr/common/cloud/ClusterProperties.java    | 23 ++++++++++++++----
 3 files changed, 46 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50c92f1a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a1165f0..5700693 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -158,6 +158,9 @@ New Features
 
 * SOLR-11943: Add machine learning functions for location data (Joel Bernstein)
 
+* SOLR-12612: Cluster properties restriction of known keys only is relaxed, and now unknown properties starting with "ext."
+  will be allowed. This allows custom to plugins set their own cluster properties. (Jeffery Yuan via Tomás Fernández Löbbe)
+
 Bug Fixes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50c92f1a/solr/core/src/test/org/apache/solr/cloud/TestClusterProperties.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestClusterProperties.java b/solr/core/src/test/org/apache/solr/cloud/TestClusterProperties.java
index c5575af..c082e37 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestClusterProperties.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestClusterProperties.java
@@ -18,6 +18,7 @@
 package org.apache.solr.cloud;
 
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.common.SolrException;
 import org.apache.solr.common.cloud.ClusterProperties;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.junit.BeforeClass;
@@ -25,14 +26,21 @@ import org.junit.Test;
 
 public class TestClusterProperties extends SolrCloudTestCase {
 
+  private ClusterProperties props;
+  
   @BeforeClass
   public static void setupCluster() throws Exception {
     configureCluster(1).configure();
   }
 
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    props = new ClusterProperties(zkClient());
+  }
+
   @Test
   public void testClusterProperties() throws Exception {
-    ClusterProperties props = new ClusterProperties(zkClient());
     assertEquals("false", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, "false"));
 
     CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, "true").process(cluster.getSolrClient());
@@ -41,5 +49,20 @@ public class TestClusterProperties extends SolrCloudTestCase {
     CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, "false").process(cluster.getSolrClient());
     assertEquals("false", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, "true"));
   }
+  
+  @Test
+  public void testSetPluginClusterProperty() throws Exception {
+    String propertyName = ClusterProperties.EXT_PROPRTTY_PREFIX + "pluginA.propertyA";
+    CollectionAdminRequest.setClusterProperty(propertyName, "valueA")
+        .process(cluster.getSolrClient());
+    assertEquals("valueA", props.getClusterProperty(propertyName, null));
+  }
+  
+  @Test(expected = SolrException.class)
+  public void testSetInvalidPluginClusterProperty() throws Exception {
+    String propertyName = "pluginA.propertyA";
+    CollectionAdminRequest.setClusterProperty(propertyName, "valueA")
+        .process(cluster.getSolrClient());
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50c92f1a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterProperties.java
----------------------------------------------------------------------
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.java
index 446923b..2452540 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
@@ -42,7 +42,8 @@ import org.slf4j.LoggerFactory;
 public class ClusterProperties {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-
+  public static final String EXT_PROPRTTY_PREFIX = "ext.";
+  
   private final SolrZkClient client;
 
   /**
@@ -119,9 +120,7 @@ public class ClusterProperties {
   @SuppressWarnings("unchecked")
   public void setClusterProperty(String propertyName, String propertyValue) throws IOException {
 
-    if (!ZkStateReader.KNOWN_CLUSTER_PROPS.contains(propertyName)) {
-      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Not a known cluster property " + propertyName);
-    }
+    validatePropertyName(propertyName);
 
     for (; ; ) {
       Stat s = new Stat();
@@ -155,4 +154,20 @@ public class ClusterProperties {
       break;
     }
   }
+
+  /**
+   * The propertyName should be either: <br/>
+   * 1. <code>ZkStateReader.KNOWN_CLUSTER_PROPS</code> that is used by solr itself.<br/>
+   * 2. Custom property: it can be created by third-party extensions and should start with prefix <b>"ext."</b> and it's
+   * recommended to also add prefix of plugin name or company name or package name to avoid conflict.
+   * 
+   * @param propertyName The property name to validate
+   */
+  private void validatePropertyName(String propertyName) {
+    if (!ZkStateReader.KNOWN_CLUSTER_PROPS.contains(propertyName)
+        && !propertyName.startsWith(EXT_PROPRTTY_PREFIX)) {
+      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Not a known cluster property or starts with prefix "
+          + EXT_PROPRTTY_PREFIX + ", propertyName: " + propertyName);
+    }
+  }
 }