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

This commit is contained in:
Ilan Ginzburg 2020-09-17 15:01:19 +02:00 committed by GitHub
parent 2364a7aded
commit dbba48b3e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 20 deletions

View File

@ -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>
*/

View File

@ -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>
*/

View File

@ -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);
}