You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by il...@apache.org on 2020/09/17 13:01:30 UTC

[lucene-solr] branch master updated: SOLR-14613: use set-placement-plugin for both setting and unsetting plugin config

This is an automated email from the ASF dual-hosted git repository.

ilan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new dbba48b  SOLR-14613: use set-placement-plugin for both setting and unsetting plugin config
dbba48b is described below

commit dbba48b3e56be541572f170a9fae95d039236c1a
Author: Ilan Ginzburg <il...@gmail.com>
AuthorDate: Thu Sep 17 15:01:19 2020 +0200

    SOLR-14613: use set-placement-plugin for both setting and unsetting plugin config
---
 .../cluster/placement/PlacementPluginConfig.java   |  4 ++--
 .../SamplePluginAffinityReplicaPlacement.java      |  2 +-
 .../java/org/apache/solr/handler/ClusterAPI.java   | 27 ++++++++--------------
 3 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/PlacementPluginConfig.java b/solr/core/src/java/org/apache/solr/cluster/placement/PlacementPluginConfig.java
index 0beb827..a39390f 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/PlacementPluginConfig.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/PlacementPluginConfig.java
@@ -54,7 +54,7 @@ package org.apache.solr.cluster.placement;
  *     "myfirstString": "a text value",
  *     "aLong": 50,
  *     "aDoubleConfig": 3.1415928,
- *     "shouldIStay": true
+ *     "shouldIStay": true}
  * </pre>
  *
  * <p>In order to delete the placement-plugin section from {@code /clusterprops.json} (and to fallback to either Legacy
@@ -63,7 +63,7 @@ package org.apache.solr.cluster.placement;
  * <pre>
  *
  * curl -X POST -H 'Content-type:application/json' -d '{
- *   "unset-placement-plugin" : null
+ *   "set-placement-plugin" : null
  * }' http://localhost:8983/api/cluster
  * </pre>
  */
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/plugins/SamplePluginAffinityReplicaPlacement.java b/solr/core/src/java/org/apache/solr/cluster/placement/plugins/SamplePluginAffinityReplicaPlacement.java
index 2d18b3e..d738fb8 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/plugins/SamplePluginAffinityReplicaPlacement.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/plugins/SamplePluginAffinityReplicaPlacement.java
@@ -105,7 +105,7 @@ import java.util.stream.Collectors;
  * <pre>
  *
   curl -X POST -H 'Content-type:application/json' -d '{
-    "unset-placement-plugin" : null
+    "set-placement-plugin" : null
   }' http://localhost:8983/api/cluster
  * </pre>
  */
diff --git a/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java b/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
index 9b4fa74..5ce564e 100644
--- a/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
+++ b/solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
@@ -161,28 +161,21 @@ public class ClusterAPI {
     public void setPlacementPlugin(PayloadObj<Map<String, Object>> obj) {
       Map<String, Object> placementPluginConfig = obj.getDataMap();
       ClusterProperties clusterProperties = new ClusterProperties(coreContainer.getZkController().getZkClient());
-      // Very basic sanity check (not checking class actually exists)
-      if (!placementPluginConfig.containsKey(PlacementPluginConfigImpl.CONFIG_CLASS)) {
-        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Must contain " + PlacementPluginConfigImpl.CONFIG_CLASS + " attribute");
+      // When the json contains { "set-placement-plugin" : null }, the map is empty, not null.
+      final boolean unset = placementPluginConfig.isEmpty();
+      // Very basic sanity check. Real validation will be done when the config is used...
+      if (!unset && !placementPluginConfig.containsKey(PlacementPluginConfigImpl.CONFIG_CLASS)) {
+        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Must contain " + PlacementPluginConfigImpl.CONFIG_CLASS + " attribute (or be null)");
       }
       try {
         // Need to reset to null first otherwise the mappings in placementPluginConfig are added to existing ones
-        // in /clusterprops.json rather than replace them
-        clusterProperties.setClusterProperties(
-                Collections.singletonMap(PlacementPluginConfigImpl.PLACEMENT_PLUGIN_CONFIG_KEY, null));
-        clusterProperties.setClusterProperties(
-                Collections.singletonMap(PlacementPluginConfigImpl.PLACEMENT_PLUGIN_CONFIG_KEY, placementPluginConfig));
-      } catch (Exception e) {
-        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error in API", e);
-      }
-    }
-
-    @Command(name = "unset-placement-plugin")
-    public void unsetPlacementPlugin(PayloadObj<Object> obj) {
-      ClusterProperties clusterProperties = new ClusterProperties(coreContainer.getZkController().getZkClient());
-      try {
+        // in /clusterprops.json rather than replacing them. If removing the config, that's all we do.
         clusterProperties.setClusterProperties(
                 Collections.singletonMap(PlacementPluginConfigImpl.PLACEMENT_PLUGIN_CONFIG_KEY, null));
+        if (!unset) {
+          clusterProperties.setClusterProperties(
+                  Collections.singletonMap(PlacementPluginConfigImpl.PLACEMENT_PLUGIN_CONFIG_KEY, placementPluginConfig));
+        }
       } catch (Exception e) {
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error in API", e);
       }