Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-14613: use set-placement-plugin for both setting and unsetting plugin config

Ilan Ginzburgdbba48b3e56b
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 0beb82767dc..a39390f01c7 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 2d18b3eb874..d738fb8e399 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 9b4fa748669..5ce564ed5cf 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);
}