Search in sources :

Example 36 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class ZkNodePropsTest method testBasic.

@Test
public void testBasic() throws IOException {
    Map<String, Object> props = new HashMap<>();
    props.put("prop1", "value1");
    props.put("prop2", "value2");
    props.put("prop3", "value3");
    props.put("prop4", "value4");
    props.put("prop5", "value5");
    props.put("prop6", "value6");
    ZkNodeProps zkProps = new ZkNodeProps(props);
    byte[] bytes = Utils.toJSON(zkProps);
    ZkNodeProps props2 = ZkNodeProps.load(bytes);
    assertEquals("value1", props2.getStr("prop1"));
    assertEquals("value2", props2.getStr("prop2"));
    assertEquals("value3", props2.getStr("prop3"));
    assertEquals("value4", props2.getStr("prop4"));
    assertEquals("value5", props2.getStr("prop5"));
    assertEquals("value6", props2.getStr("prop6"));
}
Also used : HashMap(java.util.HashMap) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) Test(org.junit.Test)

Example 37 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method showCounts.

public void showCounts() {
    Set<String> theShards = shardToJetty.keySet();
    for (String shard : theShards) {
        List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
        for (CloudJettyRunner cjetty : solrJetties) {
            ZkNodeProps props = cjetty.info;
            System.err.println("PROPS:" + props);
            try {
                SolrParams query = params("q", "*:*", "rows", "0", "distrib", "false", "tests", // "tests" is just a
                "checkShardConsistency");
                // tag that won't do
                // anything except be
                // echoed in logs
                long num = cjetty.client.solrClient.query(query).getResults().getNumFound();
                System.err.println("DOCS:" + num);
            } catch (SolrServerException | SolrException | IOException e) {
                System.err.println("error contacting client: " + e.getMessage() + "\n");
                continue;
            }
            boolean live = false;
            String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
            ZkStateReader zkStateReader = cloudClient.getZkStateReader();
            if (zkStateReader.getClusterState().liveNodesContain(nodeName)) {
                live = true;
            }
            System.err.println(" live:" + live);
        }
    }
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 38 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class AbstractZkTestCase method buildZooKeeper.

// static to share with distrib test
public static void buildZooKeeper(String zkHost, String zkAddress, File solrhome, String config, String schema) throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null);
    zkClient.makePath("/solr", false, true);
    zkClient.close();
    zkClient = new SolrZkClient(zkAddress, AbstractZkTestCase.TIMEOUT);
    Map<String, Object> props = new HashMap<>();
    props.put("configName", "conf1");
    final ZkNodeProps zkProps = new ZkNodeProps(props);
    zkClient.makePath("/collections/collection1", Utils.toJSON(zkProps), CreateMode.PERSISTENT, true);
    zkClient.makePath("/collections/collection1/shards", CreateMode.PERSISTENT, true);
    zkClient.makePath("/collections/control_collection", Utils.toJSON(zkProps), CreateMode.PERSISTENT, true);
    zkClient.makePath("/collections/control_collection/shards", CreateMode.PERSISTENT, true);
    // for now, always upload the config and schema to the canonical names
    putConfig("conf1", zkClient, solrhome, config, "solrconfig.xml");
    putConfig("conf1", zkClient, solrhome, schema, "schema.xml");
    putConfig("conf1", zkClient, solrhome, "solrconfig.snippet.randomindexconfig.xml");
    putConfig("conf1", zkClient, solrhome, "stopwords.txt");
    putConfig("conf1", zkClient, solrhome, "protwords.txt");
    putConfig("conf1", zkClient, solrhome, "currency.xml");
    putConfig("conf1", zkClient, solrhome, "enumsConfig.xml");
    putConfig("conf1", zkClient, solrhome, "open-exchange-rates.json");
    putConfig("conf1", zkClient, solrhome, "mapping-ISOLatin1Accent.txt");
    putConfig("conf1", zkClient, solrhome, "old_synonyms.txt");
    putConfig("conf1", zkClient, solrhome, "synonyms.txt");
    zkClient.close();
}
Also used : HashMap(java.util.HashMap) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 39 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class ForceLeaderTest method unsetLeader.

protected void unsetLeader(String collection, String slice) throws Exception {
    DistributedQueue inQueue = Overseer.getStateUpdateQueue(cloudClient.getZkStateReader().getZkClient());
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.LEADER.toLower(), ZkStateReader.SHARD_ID_PROP, slice, ZkStateReader.COLLECTION_PROP, collection);
    inQueue.offer(Utils.toJSON(m));
    ClusterState clusterState = null;
    boolean transition = false;
    for (int counter = 10; counter > 0; counter--) {
        clusterState = zkStateReader.getClusterState();
        Replica newLeader = clusterState.getSlice(collection, slice).getLeader();
        if (newLeader == null) {
            transition = true;
            break;
        }
        Thread.sleep(1000);
    }
    if (!transition) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not unset replica leader" + ". Cluster state: " + printClusterStateInfo(collection));
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException)

Example 40 with ZkNodeProps

use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.

the class LeaderElectionTest method testCancelElection.

@Test
public void testCancelElection() throws Exception {
    LeaderElector first = new LeaderElector(zkClient);
    ZkNodeProps props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, "http://127.0.0.1/solr/", ZkStateReader.CORE_NAME_PROP, "1");
    ElectionContext firstContext = new ShardLeaderElectionContextBase(first, "slice1", "collection2", "dummynode1", props, zkStateReader);
    first.setup(firstContext);
    first.joinElection(firstContext, false);
    Thread.sleep(1000);
    assertEquals("original leader was not registered", "http://127.0.0.1/solr/1/", getLeaderUrl("collection2", "slice1"));
    LeaderElector second = new LeaderElector(zkClient);
    props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, "http://127.0.0.1/solr/", ZkStateReader.CORE_NAME_PROP, "2");
    ElectionContext context = new ShardLeaderElectionContextBase(second, "slice1", "collection2", "dummynode2", props, zkStateReader);
    second.setup(context);
    second.joinElection(context, false);
    Thread.sleep(1000);
    assertEquals("original leader should have stayed leader", "http://127.0.0.1/solr/1/", getLeaderUrl("collection2", "slice1"));
    firstContext.cancelElection();
    Thread.sleep(1000);
    assertEquals("new leader was not registered", "http://127.0.0.1/solr/2/", getLeaderUrl("collection2", "slice1"));
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) Test(org.junit.Test)

Aggregations

ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)91 SolrException (org.apache.solr.common.SolrException)35 HashMap (java.util.HashMap)28 Replica (org.apache.solr.common.cloud.Replica)22 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)20 ArrayList (java.util.ArrayList)19 Slice (org.apache.solr.common.cloud.Slice)19 KeeperException (org.apache.zookeeper.KeeperException)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)16 Test (org.junit.Test)16 DocCollection (org.apache.solr.common.cloud.DocCollection)15 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)14 Map (java.util.Map)13 ClusterState (org.apache.solr.common.cloud.ClusterState)13 IOException (java.io.IOException)10 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)10 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)10 NamedList (org.apache.solr.common.util.NamedList)10 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)9 SolrCore (org.apache.solr.core.SolrCore)8