本文整理汇总了Java中org.apache.solr.client.solrj.impl.CloudSolrClient.getZkStateReader方法的典型用法代码示例。如果您正苦于以下问题:Java CloudSolrClient.getZkStateReader方法的具体用法?Java CloudSolrClient.getZkStateReader怎么用?Java CloudSolrClient.getZkStateReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.impl.CloudSolrClient
的用法示例。
在下文中一共展示了CloudSolrClient.getZkStateReader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildShardList
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
protected List<String> buildShardList(CloudSolrClient cloudSolrServer, final String collection) {
ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
ClusterState clusterState = zkStateReader.getClusterState();
DocCollection docCollection = clusterState.getCollection(collection);
Collection<Slice> slices = docCollection.getSlices();
if (slices == null) {
throw new IllegalArgumentException("Collection " + collection + " not found!");
}
Set<String> liveNodes = clusterState.getLiveNodes();
Random random = new Random();
List<String> shards = new ArrayList<String>();
for (Slice slice : slices) {
List<String> replicas = new ArrayList<String>();
for (Replica r : slice.getReplicas()) {
ZkCoreNodeProps replicaCoreProps = new ZkCoreNodeProps(r);
if (liveNodes.contains(replicaCoreProps.getNodeName())) {
replicas.add(replicaCoreProps.getCoreUrl());
}
}
int numReplicas = replicas.size();
if (numReplicas == 0) {
throw new IllegalStateException(
"Shard " + slice.getName() + " does not have any active replicas!");
}
String replicaUrl = (numReplicas == 1) ?
replicas.get(0) :
replicas.get(random.nextInt(replicas.size()));
shards.add(replicaUrl);
}
return shards;
}
示例2: getAliasList
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
protected List<String> getAliasList(CloudSolrClient cloudSolrClient, String collectionAlias) {
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
Aliases aliases = zkStateReader.getAliases();
String collectionsInAlias = aliases.getCollectionAlias(collectionAlias);
log.info("Looked up collection list "+collectionsInAlias+" for collection collectionsInAlias: "+collectionAlias);
return (collectionsInAlias != null) ? StrUtils.splitSmart(collectionsInAlias, ",", true) : new ArrayList<String>(0);
}
示例3: checkIfCollectionExists
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
/**
* Checks if the collection has already been created in Solr.
*/
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
ZkStateReader zkStateReader = server.getZkStateReader();
zkStateReader.updateClusterState();
ClusterState clusterState = zkStateReader.getClusterState();
return clusterState.getCollectionOrNull(collection) != null;
}
示例4: waitForRecoveriesToFinish
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
/**
* Wait for all the collection shards to be ready.
*/
private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
ZkStateReader zkStateReader = server.getZkStateReader();
try {
boolean cont = true;
while (cont) {
boolean sawLiveRecovering = false;
zkStateReader.updateClusterState();
ClusterState clusterState = zkStateReader.getClusterState();
Map<String, Slice> slices = clusterState.getSlicesMap(collection);
Preconditions.checkNotNull("Could not find collection:" + collection, slices);
for (Map.Entry<String, Slice> entry : slices.entrySet()) {
Map<String, Replica> shards = entry.getValue().getReplicasMap();
for (Map.Entry<String, Replica> shard : shards.entrySet()) {
String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
if ((state.equals(Replica.State.RECOVERING.toString())
|| state.equals(Replica.State.DOWN.toString()))
&& clusterState.liveNodesContain(shard.getValue().getStr(
ZkStateReader.NODE_NAME_PROP))) {
sawLiveRecovering = true;
}
}
}
if (!sawLiveRecovering) {
cont = false;
} else {
Thread.sleep(1000);
}
}
} finally {
logger.info("Exiting solr wait");
}
}
示例5: getCollectionsCreatedWithConfig
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
/** Returns the collection names that were created with the given configuration name. */
@SuppressWarnings("resource")
public static List<String> getCollectionsCreatedWithConfig(CloudSolrClient solrClient, String configName) {
final List<String> result = Lists.newArrayList();
final ZkStateReader zkStateReader = solrClient.getZkStateReader();
for (final String collection : zkStateReader.getClusterState().getCollectionsMap().keySet()) {
final String collectionConfigName = getCollectionConfigName(zkStateReader, collection);
if (configName.equals(collectionConfigName)) {
result.add(collection);
}
}
return result;
}
示例6: getShardList
import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
/**
* Returns the list of shards of the default collection.
*
* @param zkHost ZooKeeper URL
* @param chronixCollection Solr collection name for chronix time series data
* @return the list of shards of the default collection
*/
public List<String> getShardList(String zkHost, String chronixCollection) throws IOException {
CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost);
List<String> shards = new ArrayList<>();
try {
cloudSolrClient.connect();
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
ClusterState clusterState = zkStateReader.getClusterState();
String[] collections;
if (clusterState.hasCollection(chronixCollection)) {
collections = new String[]{chronixCollection};
} else {
// might be a collection alias?
Aliases aliases = zkStateReader.getAliases();
String aliasedCollections = aliases.getCollectionAlias(chronixCollection);
if (aliasedCollections == null)
throw new IllegalArgumentException("Collection " + chronixCollection + " not found!");
collections = aliasedCollections.split(",");
}
Set<String> liveNodes = clusterState.getLiveNodes();
Random random = new Random(5150);
for (String coll : collections) {
for (Slice slice : clusterState.getSlices(coll)) {
List<String> replicas = new ArrayList<>();
for (Replica r : slice.getReplicas()) {
if (r.getState().equals(Replica.State.ACTIVE)) {
ZkCoreNodeProps replicaCoreProps = new ZkCoreNodeProps(r);
if (liveNodes.contains(replicaCoreProps.getNodeName()))
replicas.add(replicaCoreProps.getCoreUrl());
}
}
int numReplicas = replicas.size();
if (numReplicas == 0)
throw new IllegalStateException("Shard " + slice.getName() + " in collection " +
coll + " does not have any active replicas!");
String replicaUrl = (numReplicas == 1) ? replicas.get(0) : replicas.get(random.nextInt(replicas.size()));
shards.add(replicaUrl);
}
}
} finally {
cloudSolrClient.close();
}
return shards;
}