Example usage for org.apache.solr.common.cloud ClusterState getCollection

List of usage examples for org.apache.solr.common.cloud ClusterState getCollection

Introduction

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

Prototype

public DocCollection getCollection(String collection) 

Source Link

Document

Get the named DocCollection object, or throw an exception if it doesn't exist.

Usage

From source file:org.janusgraph.diskstorage.solr.SolrIndex.java

License:Apache License

/**
 * Wait for all the collection shards to be ready.
 *//*w  w w  .j  a v  a2  s .co  m*/
private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection)
        throws KeeperException, InterruptedException {
    final ZkStateReader zkStateReader = server.getZkStateReader();
    try {
        boolean cont = true;

        while (cont) {
            boolean sawLiveRecovering = false;
            zkStateReader.forceUpdateCollection(collection);
            final ClusterState clusterState = zkStateReader.getClusterState();
            final Map<String, Slice> slices = clusterState.getCollection(collection).getSlicesMap();
            Preconditions.checkNotNull(slices, "Could not find collection:" + collection);

            // change paths for Replica.State per Solr refactoring
            // remove SYNC state per: https://tinyurl.com/pag6rwt
            for (final Map.Entry<String, Slice> entry : slices.entrySet()) {
                final Map<String, Replica> shards = entry.getValue().getReplicasMap();
                for (final Map.Entry<String, Replica> shard : shards.entrySet()) {
                    final String state = shard.getValue().getStr(ZkStateReader.STATE_PROP).toUpperCase();
                    if ((Replica.State.RECOVERING.name().equals(state)
                            || Replica.State.DOWN.name().equals(state))
                            && 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");
    }
}