org.apache.solr.api.ZkClusterPluginsSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-core Show documentation
Show all versions of solr-core Show documentation
Apache Solr (module: core)
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.api;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import org.apache.solr.client.solrj.request.beans.PluginMeta;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.handler.admin.ContainerPluginsApi;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.data.Stat;
/**
* The plugin configurations are stored and retrieved from the ZooKeeper cluster properties, stored
* at the {@link ZkStateReader#CONTAINER_PLUGINS} location This supports mutable configurations, and
* management via the /cluster/plugin APIs
*/
public class ZkClusterPluginsSource implements ClusterPluginsSource {
private final Supplier zkClientSupplier;
private final ContainerPluginsApi api;
public ZkClusterPluginsSource(CoreContainer coreContainer) {
this.zkClientSupplier = coreContainer.zkClientSupplier;
this.api = new ContainerPluginsApi(coreContainer, this);
}
@Override
public ContainerPluginsApi.Read getReadApi() {
return api.readAPI;
}
@Override
public ContainerPluginsApi.Edit getEditApi() {
return api.editAPI;
}
/**
* Retrieve the current plugin configurations.
*
* @return current plugin configurations, where keys are plugin names and values are {@link
* PluginMeta} plugin metadata.
* @throws IOException on IO errors
*/
@Override
@SuppressWarnings("unchecked")
public Map plugins() throws IOException {
SolrZkClient zkClient = zkClientSupplier.get();
try {
Map clusterPropsJson =
(Map)
Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true));
return Map.copyOf(
(Map)
clusterPropsJson.computeIfAbsent(
ZkStateReader.CONTAINER_PLUGINS, o -> new LinkedHashMap<>()));
} catch (KeeperException.NoNodeException e) {
return new LinkedHashMap<>();
} catch (KeeperException | InterruptedException e) {
throw new IOException("Error reading cluster property", SolrZkClient.checkInterrupted(e));
}
}
@Override
public void persistPlugins(Function