Search in sources :

Example 61 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project vind by RBMHTechnology.

the class CollectionManagementService method updateCollection.

/**
 * 1. Check if config set is already deployed on the solr server, if not: download from repo and upload to zK
 * 2. Switch configuration
 * 3. Check if dependencies (runtime-libs) are installed, if not download and install (and name it with group:artefact:version)
 * 4. Add/Update collection runtime-libs
 *
 * @param collectionName {@link String} name of the collection to update.
 * @param configName should be either the name of an already defined configuration in the solr cloud or the full
 *                   name of an artifact accessible in one of the default repositories.
 * @throws {@link IOException} is thrown when a problem with the solr request occurs.
 */
public void updateCollection(String collectionName, String configName) throws IOException {
    final String origConfigName;
    try {
        final CollectionAdminResponse status = new CollectionAdminRequest.ClusterStatus().setCollectionName(collectionName).process(client);
        if (status.getStatus() == 0) {
            origConfigName = (String) ((Map) ((SimpleOrderedMap) ((NamedList) status.getResponse().get("cluster")).get("collections")).get(collectionName)).get("configName");
        // origMaxShards = (String)((Map) ((SimpleOrderedMap) ((NamedList) status.getResponse().get("cluster")).get("collections")).get(collectionName)).get("maxShardsPerNode");
        // origReplicationFactor = (String)((Map) ((SimpleOrderedMap) ((NamedList) status.getResponse().get("cluster")).get("collections")).get(collectionName)).get("replicationFactor");
        } else {
            throw new IOException("Unable to get current status of collection [" + collectionName + "]");
        }
    } catch (SolrServerException e) {
        throw new IOException("Unable to get current status of collection [" + collectionName + "]", e);
    }
    // TODO get and remove current runtime libs: Is this really needed?
    // Update or install configuration
    this.checkAndInstallConfiguration(configName, true);
    if (!origConfigName.equals(configName)) {
        // Change config set of the collection to the new one
        try (final SolrZkClient zkClient = new SolrZkClient(zkHost, 4000)) {
            // TODO: The following call to the collections API is working from solr >= 6
            /*final SolrQuery modifyCollectionQuery = new SolrQuery();
                modifyCollectionQuery.setRequestHandler("/admin/collections");
                modifyCollectionQuery.set("action", "MODIFYCOLLECTION");
                modifyCollectionQuery.set("collection", collectionName);
                modifyCollectionQuery.set("collection.configName", configName);
                modifyCollectionQuery.set("rule", new String[0]);
                modifyCollectionQuery.set("snitch", new String[0]);
                modifyCollectionQuery.set("maxShardsPerNode", origMaxShards);
                modifyCollectionQuery.set("replicationFactor", origReplicationFactor);
                client.query(modifyCollectionQuery);

                or probably

                final CollectionAdminResponse modifyCollection = new CollectionAdminRequest.ModifyCollection()
                        .setCollectionName(collectionName)
                        create.setConfigName(configName);
                        create.setNumShards(numOfShards);
                        create.setReplicationFactor(numOfReplicas);
                        .process(client);
                */
            // Update link to config set
            ZkController.linkConfSet(zkClient, collectionName, configName);
            // Reload collection
            final CollectionAdminResponse reload = new CollectionAdminRequest.Reload().setCollectionName(collectionName).process(client);
            if (!reload.isSuccess()) {
                throw new IOException("Unable to reload collection [" + collectionName + "]");
            }
        } catch (SolrServerException e) {
            throw new IOException("Unable to update collection [" + collectionName + "]", e);
        } catch (KeeperException | InterruptedException e) {
            throw new IOException("Unable to update collection [" + collectionName + "]", e);
        }
    }
    final Map<String, Long> updatedRuntimeDependencies = checkAndInstallRuntimeDependencies(collectionName);
    this.addOrUpdateRuntimeDependencies(updatedRuntimeDependencies, collectionName);
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) KeeperException(org.apache.zookeeper.KeeperException)

Example 62 with SolrZkClient

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

the class TestZkChroot method testInitPathExists.

@Test
public void testInitPathExists() throws Exception {
    String chroot = "/foo/bar4";
    System.setProperty("bootstrap_conf", "true");
    System.setProperty("zkHost", zkServer.getZkHost() + chroot);
    SolrZkClient zkClient = null;
    try {
        zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT);
        zkClient.makePath("/foo/bar4", true);
        assertTrue(zkClient.exists(chroot, true));
        assertFalse(zkClient.exists(chroot + "/clusterstate.json", true));
        cores = CoreContainer.createAndLoad(home);
        assertTrue(zkClient.exists(chroot + "/clusterstate.json", 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)

Example 63 with SolrZkClient

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

the class RemoteSolrServerProvider method createCollectionIfNeeded.

private void createCollectionIfNeeded(CloudSolrServer cloudSolrServer) throws SolrServerException {
    String solrCollection = remoteSolrServerConfiguration.getSolrCollection();
    try {
        ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
        SolrZkClient zkClient = zkStateReader.getZkClient();
        if (zkClient.isConnected() && !zkClient.exists("/configs/" + solrCollection, false)) {
            String solrConfDir = remoteSolrServerConfiguration.getSolrConfDir();
            File dir;
            if (solrConfDir != null && solrConfDir.length() > 0) {
                dir = new File(solrConfDir);
            } else {
                dir = new File(getClass().getResource("/solr/oak/conf").getFile());
            }
            ZkController.uploadConfigDir(zkClient, dir, solrCollection);
            UpdateRequest req = new UpdateRequest("/admin/collections");
            req.setParam("action", "CREATE");
            req.setParam("numShards", String.valueOf(remoteSolrServerConfiguration.getSolrShardsNo()));
            req.setParam("replicationFactor", String.valueOf(remoteSolrServerConfiguration.getSolrReplicationFactor()));
            req.setParam("collection.configName", solrCollection);
            req.setParam("name", solrCollection);
            cloudSolrServer.request(req);
        }
    } catch (Exception e) {
        log.warn("could not create collection {}", solrCollection);
        throw new SolrServerException(e);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) File(java.io.File) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Example 64 with SolrZkClient

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

the class VMParamsZkACLAndCredentialsProvidersTest method testAllCredentials.

@Test
public void testAllCredentials() throws Exception {
    useAllCredentials();
    SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
    try {
        doTest(zkClient, true, true, true, true, true, true, true, true, true, true);
    } finally {
        zkClient.close();
    }
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) Test(org.junit.Test)

Example 65 with SolrZkClient

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

the class VMParamsZkACLAndCredentialsProvidersTest method testReadonlyCredentials.

@Test
public void testReadonlyCredentials() throws Exception {
    useReadonlyCredentials();
    SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
    try {
        doTest(zkClient, true, true, false, false, false, false, false, false, false, false);
    } finally {
        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