Search in sources :

Example 41 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient 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 42 with SolrZkClient

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

the class DistributedQueueTest method setupZk.

protected void setupZk() throws Exception {
    System.setProperty("zkClientTimeout", "8000");
    zkServer = new ZkTestServer(createTempDir("zkData").toFile().getAbsolutePath());
    zkServer.run();
    System.setProperty("zkHost", zkServer.getZkAddress());
    zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
    assertTrue(zkClient.isConnected());
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 43 with SolrZkClient

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

the class LeaderElectionIntegrationTest method printLayout.

private void printLayout(String zkHost) throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT);
    zkClient.printLayoutToStdOut();
    zkClient.close();
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 44 with SolrZkClient

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

the class ConnectionManagerTest method testConnectionManager.

@Ignore
public void testConnectionManager() throws Exception {
    // setup a SolrZkClient to do some getBaseUrlForNodeName testing
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
        ConnectionManager cm = zkClient.getConnectionManager();
        try {
            assertFalse(cm.isLikelyExpired());
            zkClient.getSolrZooKeeper().closeCnxn();
            long sessionId = zkClient.getSolrZooKeeper().getSessionId();
            server.expire(sessionId);
            Thread.sleep(TIMEOUT);
            assertTrue(cm.isLikelyExpired());
        } finally {
            cm.close();
            zkClient.close();
        }
    } finally {
        server.shutdown();
    }
}
Also used : ConnectionManager(org.apache.solr.common.cloud.ConnectionManager) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Ignore(org.junit.Ignore)

Example 45 with SolrZkClient

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

the class HttpPartitionTest method testLeaderInitiatedRecoveryCRUD.

/**
   * Tests handling of lir state znodes.
   */
protected void testLeaderInitiatedRecoveryCRUD() throws Exception {
    String testCollectionName = "c8n_crud_1x2";
    String shardId = "shard1";
    createCollectionRetry(testCollectionName, 1, 2, 1);
    cloudClient.setDefaultCollection(testCollectionName);
    Replica leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, shardId);
    JettySolrRunner leaderJetty = getJettyOnPort(getReplicaPort(leader));
    CoreContainer cores = leaderJetty.getCoreContainer();
    ZkController zkController = cores.getZkController();
    assertNotNull("ZkController is null", zkController);
    Replica notLeader = ensureAllReplicasAreActive(testCollectionName, shardId, 1, 2, maxWaitSecsToSeeAllActive).get(0);
    ZkCoreNodeProps replicaCoreNodeProps = new ZkCoreNodeProps(notLeader);
    String replicaUrl = replicaCoreNodeProps.getCoreUrl();
    MockCoreDescriptor cd = new MockCoreDescriptor() {

        public CloudDescriptor getCloudDescriptor() {
            return new CloudDescriptor(leader.getStr(ZkStateReader.CORE_NAME_PROP), new Properties(), this) {

                @Override
                public String getCoreNodeName() {
                    return leader.getName();
                }

                @Override
                public boolean isLeader() {
                    return true;
                }
            };
        }
    };
    zkController.updateLeaderInitiatedRecoveryState(testCollectionName, shardId, notLeader.getName(), Replica.State.DOWN, cd, true);
    Map<String, Object> lirStateMap = zkController.getLeaderInitiatedRecoveryStateObject(testCollectionName, shardId, notLeader.getName());
    assertNotNull(lirStateMap);
    assertSame(Replica.State.DOWN, Replica.State.getState((String) lirStateMap.get(ZkStateReader.STATE_PROP)));
    // test old non-json format handling
    SolrZkClient zkClient = zkController.getZkClient();
    String znodePath = zkController.getLeaderInitiatedRecoveryZnodePath(testCollectionName, shardId, notLeader.getName());
    zkClient.setData(znodePath, "down".getBytes(StandardCharsets.UTF_8), true);
    lirStateMap = zkController.getLeaderInitiatedRecoveryStateObject(testCollectionName, shardId, notLeader.getName());
    assertNotNull(lirStateMap);
    assertSame(Replica.State.DOWN, Replica.State.getState((String) lirStateMap.get(ZkStateReader.STATE_PROP)));
    zkClient.delete(znodePath, -1, false);
    // try to clean up
    attemptCollectionDelete(cloudClient, testCollectionName);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) MockCoreDescriptor(org.apache.solr.util.MockCoreContainer.MockCoreDescriptor) Properties(java.util.Properties) Replica(org.apache.solr.common.cloud.Replica) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Aggregations

SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)130 Test (org.junit.Test)46 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)34 HashMap (java.util.HashMap)21 KeeperException (org.apache.zookeeper.KeeperException)18 SolrException (org.apache.solr.common.SolrException)15 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)14 IOException (java.io.IOException)13 ClusterState (org.apache.solr.common.cloud.ClusterState)13 DocCollection (org.apache.solr.common.cloud.DocCollection)12 Map (java.util.Map)11 Slice (org.apache.solr.common.cloud.Slice)11 Replica (org.apache.solr.common.cloud.Replica)10 ArrayList (java.util.ArrayList)9 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)8 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 Overseer (org.apache.solr.cloud.Overseer)8 ZkTestServer (org.apache.solr.cloud.ZkTestServer)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)7 NamedList (org.apache.solr.common.util.NamedList)7