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);
}
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();
}
}
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);
}
}
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();
}
}
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();
}
}
Aggregations