Example usage for org.apache.solr.common.cloud ZkStateReader NODE_NAME_PROP

List of usage examples for org.apache.solr.common.cloud ZkStateReader NODE_NAME_PROP

Introduction

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

Prototype

String NODE_NAME_PROP

To view the source code for org.apache.solr.common.cloud ZkStateReader NODE_NAME_PROP.

Click Source Link

Usage

From source file:com.thinkaurelius.titan.diskstorage.solr.Solr5Index.java

License:Apache License

/**
 * Wait for all the collection shards to be ready.
 */// w  ww .  j  av  a  2 s.com
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(true);
            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(ZkStateReader.RECOVERING) || state.equals(ZkStateReader.SYNC)
                            || state.equals(ZkStateReader.DOWN))
                            && 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");
    }
}

From source file:org.apache.sentry.tests.e2e.solr.AbstractSolrSentryTestBase.java

License:Apache License

protected static void waitForRecoveriesToFinish(String collection, CloudSolrServer solrServer, boolean verbose,
        boolean failOnTimeout, int timeoutSeconds) throws Exception {
    LOG.info("Entering solr wait with timeout " + timeoutSeconds);
    ZkStateReader zkStateReader = solrServer.getZkStateReader();
    try {//  w  w w  . j a  v a  2 s. c  o  m
        boolean cont = true;
        int cnt = 0;

        while (cont) {
            if (verbose)
                LOG.debug("-");
            boolean sawLiveRecovering = false;
            zkStateReader.updateClusterState(true);
            ClusterState clusterState = zkStateReader.getClusterState();
            Map<String, Slice> slices = clusterState.getSlicesMap(collection);
            assertNotNull("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()) {
                    if (verbose)
                        LOG.debug("rstate:" + shard.getValue().getStr(ZkStateReader.STATE_PROP) + " live:"
                                + clusterState.liveNodesContain(shard.getValue().getNodeName()));
                    String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
                    if ((state.equals(ZkStateReader.RECOVERING) || state.equals(ZkStateReader.SYNC)
                            || state.equals(ZkStateReader.DOWN))
                            && clusterState
                                    .liveNodesContain(shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP))) {
                        sawLiveRecovering = true;
                    }
                }
            }
            if (!sawLiveRecovering || cnt == timeoutSeconds) {
                if (!sawLiveRecovering) {
                    if (verbose)
                        LOG.debug("no one is recovering");
                } else {
                    if (verbose)
                        LOG.debug("Gave up waiting for recovery to finish..");
                    if (failOnTimeout) {
                        fail("There are still nodes recovering - waited for " + timeoutSeconds + " seconds");
                        // won't get here
                        return;
                    }
                }
                cont = false;
            } else {
                Thread.sleep(1000);
            }
            cnt++;
        }
    } finally {
        LOG.info("Exiting solr wait");
    }
}

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

License:Apache License

/**
 * Wait for all the collection shards to be ready.
 *///from w w  w.jav a 2  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");
    }
}

From source file:org.opencommercesearch.CloudSearchServerUnitTest.java

License:Apache License

private void initZkMocks() throws KeeperException, InterruptedException {
    when(zkClient.exists(anyString(), anyBoolean())).thenReturn(false);
    when(zkStatereader.getClusterState()).thenReturn(clusterState);
    Set<String> liveNodes = new HashSet<String>();
    liveNodes.add("nodeName1");
    liveNodes.add("nodeName2");
    when(clusterState.getLiveNodes()).thenReturn(liveNodes);

    Map<String, Slice> slices = new HashMap<String, Slice>();
    slices.put("slice1", slice1);
    slices.put("slice2", slice2);
    when(clusterState.getSlicesMap(cloudSearchServer.getRulesCollection(getLocale()))).thenReturn(slices);
    when(clusterState.getSlicesMap(cloudSearchServer.getCatalogCollection(getLocale()))).thenReturn(slices);

    Collection<Replica> replicas = Arrays.asList(replica1, replica2);
    when(slice1.getReplicas()).thenReturn(replicas);

    when(replica1.getStr(ZkStateReader.NODE_NAME_PROP)).thenReturn("nodeName1");
    when(replica2.getStr(ZkStateReader.NODE_NAME_PROP)).thenReturn("nodeName2");
    when(replica1.getStr(ZkStateReader.STATE_PROP)).thenReturn(ZkStateReader.ACTIVE);
    when(replica2.getStr(ZkStateReader.STATE_PROP)).thenReturn(ZkStateReader.DOWN);
    when(replica1.getStr(ZkStateReader.BASE_URL_PROP)).thenReturn("http://node1.opencommercesearch.org");
    when(replica2.getStr(ZkStateReader.BASE_URL_PROP)).thenReturn("http://node2.opencommercesearch.org");
    when(replica1.getStr(ZkStateReader.CORE_NAME_PROP)).thenReturn("mycore");
    when(replica2.getStr(ZkStateReader.CORE_NAME_PROP)).thenReturn("mycore");

    when(catalogSolrServer.getZkStateReader()).thenReturn(zkStatereader);
    when(catalogSolrServer.getLbServer()).thenReturn(lbHttpSolrServer);
    when(rulesSolrServer.getZkStateReader()).thenReturn(zkStatereader);
    when(rulesSolrServer.getLbServer()).thenReturn(lbHttpSolrServer);
    when(lbHttpSolrServer.getHttpClient()).thenReturn(httpClient);
}

From source file:org.vootoo.server.Vootoo.java

License:Apache License

public static SolrCore checkProps(CoreContainer cores, ZkNodeProps zkProps) {
    String corename;/*from w  w  w . j av a2  s.  co m*/
    SolrCore core = null;
    if (cores.getZkController().getNodeName().equals(zkProps.getStr(ZkStateReader.NODE_NAME_PROP))) {
        corename = zkProps.getStr(ZkStateReader.CORE_NAME_PROP);
        core = cores.getCore(corename);
    }
    return core;
}