Search in sources :

Example 81 with SolrZkClient

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

the class CdcrBufferStateManager method synchronize.

/**
   * Synchronise the state to Zookeeper. This method must be called only by the handler receiving the
   * action.
   */
void synchronize() {
    SolrZkClient zkClient = core.getCoreContainer().getZkController().getZkClient();
    try {
        zkClient.setData(this.getZnodePath(), this.getState().getBytes(), true);
        // check if nobody changed it in the meantime, and set a new watcher
        this.setState(CdcrParams.BufferState.get(zkClient.getData(this.getZnodePath(), watcher, null, true)));
    } catch (KeeperException | InterruptedException e) {
        log.warn("Failed synchronising new state", e);
    }
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) KeeperException(org.apache.zookeeper.KeeperException)

Example 82 with SolrZkClient

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

the class CdcrProcessStateManager method createStateNode.

private void createStateNode() {
    SolrZkClient zkClient = core.getCoreContainer().getZkController().getZkClient();
    try {
        if (!zkClient.exists(this.getZnodePath(), true)) {
            if (!zkClient.exists(this.getZnodeBase(), true)) {
                // Should be a no-op if the node exists
                zkClient.makePath(this.getZnodeBase(), null, CreateMode.PERSISTENT, null, false, true);
            }
            zkClient.create(this.getZnodePath(), DEFAULT_STATE.getBytes(), CreateMode.PERSISTENT, true);
            log.info("Created znode {}", this.getZnodePath());
        }
    } catch (KeeperException.NodeExistsException ne) {
    // Someone got in first and created the node.
    } catch (KeeperException | InterruptedException e) {
        log.warn("Failed to create CDCR process state node", e);
    }
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) KeeperException(org.apache.zookeeper.KeeperException)

Example 83 with SolrZkClient

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

the class TestConfigSetsAPI method verifyCreate.

private void verifyCreate(String baseConfigSetName, String configSetName, Map<String, String> oldProps, Map<String, String> newProps) throws Exception {
    final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
    final SolrClient solrClient = getHttpSolrClient(baseUrl);
    setupBaseConfigSet(baseConfigSetName, oldProps);
    SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null);
    try {
        ZkConfigManager configManager = new ZkConfigManager(zkClient);
        assertFalse(configManager.configExists(configSetName));
        Create create = new Create();
        create.setBaseConfigSetName(baseConfigSetName).setConfigSetName(configSetName);
        if (newProps != null) {
            Properties p = new Properties();
            p.putAll(newProps);
            create.setNewConfigSetProperties(p);
        }
        ConfigSetAdminResponse response = create.process(solrClient);
        assertNotNull(response.getResponse());
        assertTrue(configManager.configExists(configSetName));
        verifyProperties(configSetName, oldProps, newProps, zkClient);
    } finally {
        zkClient.close();
    }
    solrClient.close();
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) Create(org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create) ConfigSetAdminResponse(org.apache.solr.client.solrj.response.ConfigSetAdminResponse) ConfigSetProperties(org.apache.solr.core.ConfigSetProperties) Properties(java.util.Properties) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 84 with SolrZkClient

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

the class TestConfigSetsAPI method uploadConfigSet.

private void uploadConfigSet(String configSetName, String suffix, String username, String password) throws Exception {
    // Read zipped sample config
    ByteBuffer sampleZippedConfig = TestDynamicLoading.getFileContent(createTempZipFile("solr/configsets/upload/" + configSetName), false);
    SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null);
    try {
        ZkConfigManager configManager = new ZkConfigManager(zkClient);
        assertFalse(configManager.configExists(configSetName + suffix));
        Map map = postDataAndGetResponse(solrCluster.getSolrClient(), solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/admin/configs?action=UPLOAD&wt=json&name=" + configSetName + suffix, sampleZippedConfig, username, password);
        assertNotNull(map);
        long statusCode = (long) getObjectByPath(map, false, Arrays.asList("responseHeader", "status"));
        assertEquals(0l, statusCode);
        assertTrue("managed-schema file should have been uploaded", zkClient.exists("/configs/" + configSetName + suffix + "/managed-schema", true));
        assertTrue("managed-schema file contents on zookeeper are not exactly same as that of the file uploaded in config", Arrays.equals(zkClient.getData("/configs/" + configSetName + suffix + "/managed-schema", null, null, true), readFile("solr/configsets/upload/" + configSetName + "/managed-schema")));
        assertTrue("solrconfig.xml file should have been uploaded", zkClient.exists("/configs/" + configSetName + suffix + "/solrconfig.xml", true));
        byte[] data = zkClient.getData("/configs/" + configSetName + suffix, null, null, true);
        //assertEquals("{\"trusted\": false}", new String(data, StandardCharsets.UTF_8));
        assertTrue("solrconfig.xml file contents on zookeeper are not exactly same as that of the file uploaded in config", Arrays.equals(zkClient.getData("/configs/" + configSetName + suffix + "/solrconfig.xml", null, null, true), readFile("solr/configsets/upload/" + configSetName + "/solrconfig.xml")));
    } finally {
        zkClient.close();
    }
}
Also used : ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) ByteBuffer(java.nio.ByteBuffer) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 85 with SolrZkClient

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

the class TestConfigSetsAPI method testDelete.

@Test
public void testDelete() throws Exception {
    final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
    final SolrClient solrClient = getHttpSolrClient(baseUrl);
    final String configSet = "configSet";
    solrCluster.uploadConfigSet(configset("configset-2"), configSet);
    SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null);
    try {
        ZkConfigManager configManager = new ZkConfigManager(zkClient);
        assertTrue(configManager.configExists(configSet));
        Delete delete = new Delete();
        delete.setConfigSetName(configSet);
        ConfigSetAdminResponse response = delete.process(solrClient);
        assertNotNull(response.getResponse());
        assertFalse(configManager.configExists(configSet));
    } finally {
        zkClient.close();
    }
    solrClient.close();
}
Also used : Delete(org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Delete) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) ConfigSetAdminResponse(org.apache.solr.client.solrj.response.ConfigSetAdminResponse) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) BasicAuthIntegrationTest(org.apache.solr.security.BasicAuthIntegrationTest) 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