You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Furkan KAMACI <fu...@gmail.com> on 2014/02/10 20:31:52 UTC
Re: List and Edit Config Files at Zookeeper from a Client Application
Hi;
I've read similar threads and implemented a solution. I think that it maybe
useful for anybody else so I write down what I did:
public class ResourceUpdater {
public static void updateJsonFileInZk(CloudSolrServer cloudSolrServer,
String zkFilePath, String filePath) throws IOException, KeeperException,
InterruptedException {
SolrZkClient zkClient = getZkClient(cloudSolrServer);
File jsonFile = new File(filePath);
if (!jsonFile.isFile()) {
System.err.println(jsonFile.getAbsolutePath() + " not found.");
return;
}
byte[] data = readFile(jsonFile);
updateJsonFileInZk(zkClient, zkFilePath, data);
}
public static void updateJsonFileInZk(SolrZkClient zkClient, String
zkFilePath, byte[] jsonData) throws UnsupportedEncodingException,
KeeperException, InterruptedException {
if (!validateJson(jsonData)){
System.err.println("Json is invalid");
return;
}
zkClient.setData(zkFilePath, jsonData, true);
}
public static void updateJsonFileInZk(CloudSolrServer cloudSolrServer,
String zkFilePath, byte[] jsonData) throws Exception {
if (!validateJson(jsonData)){
System.err.println("Json is invalid");
return;
}
SolrZkClient zkClient = getZkClient(cloudSolrServer);
zkClient.setData(zkFilePath, jsonData, true);
}
private static SolrZkClient getZkClient(CloudSolrServer cloudSolrServer){
ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
return zkStateReader.getZkClient();
}
}
Thanks;
Furkan KAMACI
2014-01-31 16:30 GMT+02:00 Furkan KAMACI <fu...@gmail.com>:
> Hi;
>
> I am developing an application that will have an ability to list and edit
> SolrCloud config files at Zookeeper. Basically operator will able to see
> stopwords, synonyms (also elevator). Operator will edit it from my
> dashboard and this files will be updated at Zookeper.
>
> Currently I use cloud-scripts that is shipped with Solr. SolrZkClient,
> ResourceLoader are options to use. What is the most convenient way for my
> list and edit purpose?
>
> Thanks;
> Furkan KAMACI
>