Search in sources :

Example 26 with SolrZkClient

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

the class SaslZkACLProviderTest method setupZNodes.

protected void setupZNodes() throws Exception {
    SolrZkClient zkClient = new SolrZkClientWithACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
    try {
        zkClient.create("/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
        zkClient.makePath("/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
        zkClient.create(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
    } finally {
        zkClient.close();
    }
    zkClient = new SolrZkClientNoACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
    try {
        zkClient.create("/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
        zkClient.makePath("/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
    } finally {
        zkClient.close();
    }
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 27 with SolrZkClient

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

the class ZkStateReaderTest method testWatchedCollectionCreation.

public void testWatchedCollectionCreation() throws Exception {
    String zkDir = createTempDir("testWatchedCollectionCreation").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    SolrZkClient zkClient = null;
    ZkStateReader reader = null;
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
        ZkController.createClusterZkNodes(zkClient);
        reader = new ZkStateReader(zkClient);
        reader.createClusterStateWatchersAndUpdate();
        reader.registerCore("c1");
        // Initially there should be no c1 collection.
        assertNull(reader.getClusterState().getCollectionRef("c1"));
        zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
        reader.forceUpdateCollection("c1");
        // Still no c1 collection, despite a collection path.
        assertNull(reader.getClusterState().getCollectionRef("c1"));
        ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
        // create new collection with stateFormat = 2
        DocCollection state = new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.CLUSTER_STATE + "/c1/state.json");
        ZkWriteCommand wc = new ZkWriteCommand("c1", state);
        writer.enqueueUpdate(reader.getClusterState(), wc, null);
        writer.writePendingUpdates();
        assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true));
        //reader.forceUpdateCollection("c1");
        reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null);
        ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1");
        assertNotNull(ref);
        assertFalse(ref.isLazilyLoaded());
        assertEquals(2, ref.get().getStateFormat());
    } finally {
        IOUtils.close(reader, zkClient);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) ZkTestServer(org.apache.solr.cloud.ZkTestServer) Overseer(org.apache.solr.cloud.Overseer) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 28 with SolrZkClient

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

the class ZkStateReaderTest method testExternalCollectionWatchedNotWatched.

public void testExternalCollectionWatchedNotWatched() throws Exception {
    String zkDir = createTempDir("testExternalCollectionWatchedNotWatched").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    SolrZkClient zkClient = null;
    ZkStateReader reader = null;
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
        ZkController.createClusterZkNodes(zkClient);
        reader = new ZkStateReader(zkClient);
        reader.createClusterStateWatchersAndUpdate();
        ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
        zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
        // create new collection with stateFormat = 2
        ZkWriteCommand c1 = new ZkWriteCommand("c1", new DocCollection("c1", new HashMap<>(), new HashMap<>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));
        writer.enqueueUpdate(reader.getClusterState(), c1, null);
        writer.writePendingUpdates();
        reader.forceUpdateCollection("c1");
        assertTrue(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
        reader.registerCore("c1");
        assertFalse(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
        reader.unregisterCore("c1");
        assertTrue(reader.getClusterState().getCollectionRef("c1").isLazilyLoaded());
    } finally {
        IOUtils.close(reader, zkClient);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ZkTestServer(org.apache.solr.cloud.ZkTestServer) Overseer(org.apache.solr.cloud.Overseer) HashMap(java.util.HashMap) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 29 with SolrZkClient

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

the class TestZkChroot method testChrootBootstrap.

@Test
public void testChrootBootstrap() throws Exception {
    String chroot = "/foo/bar";
    System.setProperty("bootstrap_conf", "true");
    System.setProperty("zkHost", zkServer.getZkHost() + chroot);
    SolrZkClient zkClient = null;
    SolrZkClient zkClient2 = null;
    try {
        cores = CoreContainer.createAndLoad(home);
        zkClient = cores.getZkController().getZkClient();
        assertTrue(zkClient.exists("/clusterstate.json", true));
        assertFalse(zkClient.exists(chroot + "/clusterstate.json", true));
        zkClient2 = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT);
        assertTrue(zkClient2.exists(chroot + "/clusterstate.json", true));
        assertFalse(zkClient2.exists("/clusterstate.json", true));
    } finally {
        if (cores != null)
            cores.shutdown();
        if (zkClient != null)
            zkClient.close();
        if (zkClient2 != null)
            zkClient2.close();
    }
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test)

Example 30 with SolrZkClient

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

the class TestZkChroot method testWithUploadDir.

@Test
public void testWithUploadDir() throws Exception {
    String chroot = "/foo/bar3";
    String configName = "testWithUploadDir";
    System.setProperty("bootstrap_conf", "false");
    System.setProperty("bootstrap_confdir", home + "/collection1/conf");
    System.setProperty("collection.configName", configName);
    System.setProperty("zkHost", zkServer.getZkHost() + chroot);
    SolrZkClient zkClient = null;
    try {
        zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT);
        assertFalse("Path '" + chroot + "' should not exist before the test", zkClient.exists(chroot, true));
        cores = CoreContainer.createAndLoad(home);
        assertTrue("solrconfig.xml should have been uploaded to zk to the correct config directory", zkClient.exists(chroot + ZkConfigManager.CONFIGS_ZKNODE + "/" + configName + "/solrconfig.xml", true));
    } finally {
        if (cores != null)
            cores.shutdown();
        if (zkClient != null)
            zkClient.close();
    }
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test)

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