Example usage for org.apache.solr.common.cloud DocCollection getSlices

List of usage examples for org.apache.solr.common.cloud DocCollection getSlices

Introduction

In this page you can find the example usage for org.apache.solr.common.cloud DocCollection getSlices.

Prototype

public Collection<Slice> getSlices() 

Source Link

Document

Gets the list of all slices for this collection.

Usage

From source file:com.shaie.solr.CollectionsStateHelper.java

License:Apache License

/** Returns all the replicas (of all shards and collections) that exist on the given node. */
public List<Replica> getAllNodeReplicas(String nodeName) {
    final List<Replica> replicas = Lists.newArrayList();
    final ClusterState clusterState = getClusterState();
    for (final DocCollection collection : clusterState.getCollectionsMap().values()) {
        for (final Slice slice : collection.getSlices()) {
            for (final Replica replica : slice.getReplicas()) {
                if (replica.getNodeName().equals(nodeName)) {
                    replicas.add(replica);
                }/*from w  w  w  .j a  v a2 s.com*/
            }
        }
    }
    return replicas;
}

From source file:com.shaie.solr.CollectionsStateHelper.java

License:Apache License

/** Returns all replicas per node. */
private Map<String, List<ReplicaInfo>> getNodeReplicas() {
    final ClusterState clusterState = getClusterState();
    final Map<String, List<ReplicaInfo>> result = Maps.newHashMap();
    for (final DocCollection collection : clusterState.getCollectionsMap().values()) {
        for (final Slice slice : collection.getSlices()) {
            for (final Replica replica : slice.getReplicas()) {
                List<ReplicaInfo> nodeReplicas = result.get(replica.getNodeName());
                if (nodeReplicas == null) {
                    nodeReplicas = Lists.newArrayList();
                    result.put(replica.getNodeName(), nodeReplicas);
                }/*from  ww w. ja  va 2s .  c o m*/
                nodeReplicas.add(new ReplicaInfo(replica, collection.getName(), slice.getName()));
            }
        }
    }
    return result;
}

From source file:edu.harvard.gis.hhypermap.bop.solrplugins.DateShardRoutingSearchHandler.java

License:Apache License

List<Slice> getOrderedSlices(ZkController zkController, String collection) {
    DocCollection coll = zkController.getClusterState().getCollection(collection);
    //TODO cache sorted for same coll ?
    List<Slice> slices = new ArrayList<>(coll.getSlices());
    slices.removeIf((s) -> s.getName().equals(SHARD_RT_NAME));
    // assumption: shard names sort in date order
    slices.sort(Comparator.comparing(Slice::getName));
    return slices;
}

From source file:uk.bl.wa.apache.solr.hadoop.ZooKeeperInspector.java

License:Apache License

public List<List<String>> extractShardUrls(String zkHost, String collection) {

    DocCollection docCollection = extractDocCollection(zkHost, collection);
    List<Slice> slices = getSortedSlices(docCollection.getSlices());
    List<List<String>> solrUrls = new ArrayList<List<String>>(slices.size());
    for (Slice slice : slices) {
        if (slice.getLeader() == null) {
            throw new IllegalArgumentException("Cannot find SolrCloud slice leader. "
                    + "It looks like not all of your shards are registered in ZooKeeper yet");
        }/*from   w w  w.  ja va  2 s .co m*/
        Collection<Replica> replicas = slice.getReplicas();
        List<String> urls = new ArrayList<String>(replicas.size());
        for (Replica replica : replicas) {
            ZkCoreNodeProps props = new ZkCoreNodeProps(replica);
            urls.add(props.getCoreUrl());
        }
        solrUrls.add(urls);
    }
    return solrUrls;
}