Java Code Examples for org.apache.solr.common.cloud.SolrZkClient#setData()
The following examples show how to use
org.apache.solr.common.cloud.SolrZkClient#setData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDynamicURP.java From lucene-solr with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupCluster() throws Exception { System.setProperty("enable.runtime.lib", "true"); configureCluster(3) .addConfig("conf", configset("cloud-minimal")) .configure(); SolrZkClient zkClient = cluster.getSolrClient().getZkStateReader().getZkClient(); String path = ZkStateReader.CONFIGS_ZKNODE + "/conf/solrconfig.xml"; byte[] data = zkClient.getData(path, null, null, true); String solrconfigStr = new String(data, StandardCharsets.UTF_8); zkClient.setData(path, solrconfigStr.replace("</config>", "<updateRequestProcessorChain name=\"test_urp\" processor=\"testURP\" default=\"true\">\n" + " <processor class=\"solr.RunUpdateProcessorFactory\"/>\n" + " </updateRequestProcessorChain>\n" + "\n" + " <updateProcessor class=\"runtimecode.TestURP\" name=\"testURP\" runtimeLib=\"true\"></updateProcessor>\n" + "</config>").getBytes(StandardCharsets.UTF_8), true ); CollectionAdminRequest.createCollection(COLLECTION, "conf", 3, 1).process(cluster.getSolrClient()); waitForState("", COLLECTION, clusterShape(3, 3)); }
Example 2
Source File: UploadConfigurationHandler.java From ambari-logsearch with Apache License 2.0 | 5 votes |
private void uploadFileToZk(SolrZkClient zkClient, String filePath, String configsPath) throws FileNotFoundException { InputStream is = new FileInputStream(filePath); try { if (zkClient.exists(configsPath, true)) { zkClient.setData(configsPath, IOUtils.toByteArray(is), true); } else { zkClient.create(configsPath, IOUtils.toByteArray(is), CreateMode.PERSISTENT, true); } } catch (Exception e) { throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(is); } }
Example 3
Source File: ConfigSetsHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private void createZkNodeIfNotExistsAndSetData(SolrZkClient zkClient, String filePathInZk, byte[] data) throws Exception { if (!zkClient.exists(filePathInZk, true)) { zkClient.create(filePathInZk, data, CreateMode.PERSISTENT, true); } else { zkClient.setData(filePathInZk, data, true); } }
Example 4
Source File: CdcrProcessStateManager.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * 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.ProcessState.get(zkClient.getData(this.getZnodePath(), watcher, null, true))); } catch (KeeperException | InterruptedException e) { log.warn("Failed synchronising new state", e); } }
Example 5
Source File: CdcrBufferStateManager.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 6
Source File: ZkController.java From lucene-solr with Apache License 2.0 | 5 votes |
public static void touchConfDir(ZkSolrResourceLoader zkLoader) { SolrZkClient zkClient = zkLoader.getZkController().getZkClient(); try { zkClient.setData(zkLoader.getConfigSetZkPath(), new byte[]{0}, true); } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); // Restore the interrupted status } final String msg = "Error 'touching' conf location " + zkLoader.getConfigSetZkPath(); log.error(msg, e); throw new SolrException(ErrorCode.SERVER_ERROR, msg, e); } }
Example 7
Source File: TestConfigReload.java From lucene-solr with Apache License 2.0 | 5 votes |
private void checkConfReload(SolrZkClient client, String resPath, String name, String uri) throws Exception { Stat stat = new Stat(); byte[] data = null; try { data = client.getData(resPath, null, stat, true); } catch (KeeperException.NoNodeException e) { data = "{}".getBytes(StandardCharsets.UTF_8); log.info("creating_node {}",resPath); client.create(resPath,data, CreateMode.PERSISTENT,true); } long startTime = System.nanoTime(); Stat newStat = client.setData(resPath, data, true); client.setData("/configs/conf1", new byte[]{1}, true); assertTrue(newStat.getVersion() > stat.getVersion()); if (log.isInfoEnabled()) { log.info("new_version {}", newStat.getVersion()); } Integer newVersion = newStat.getVersion(); long maxTimeoutSeconds = 60; DocCollection coll = cloudClient.getZkStateReader().getClusterState().getCollection("collection1"); List<String> urls = new ArrayList<>(); for (Slice slice : coll.getSlices()) { for (Replica replica : slice.getReplicas()) urls.add(""+replica.get(ZkStateReader.BASE_URL_PROP) + "/"+replica.get(ZkStateReader.CORE_NAME_PROP)); } HashSet<String> succeeded = new HashSet<>(); while ( TimeUnit.SECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS) < maxTimeoutSeconds){ Thread.sleep(50); for (String url : urls) { MapWriter respMap = getAsMap(url + uri); if (String.valueOf(newVersion).equals(respMap._getStr(asList(name, "znodeVersion"), null))) { succeeded.add(url); } } if(succeeded.size() == urls.size()) break; succeeded.clear(); } assertEquals(StrUtils.formatString("tried these servers {0} succeeded only in {1} ", urls, succeeded) , urls.size(), succeeded.size()); }
Example 8
Source File: SolrSnapshotManager.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * This method updates an entry for the named snapshot for the specified collection in Zookeeper. * * @param zkClient Zookeeper client * @param collectionName The name of the collection * @param meta The {@linkplain CollectionSnapshotMetaData} corresponding to named snapshot * @throws KeeperException In case of Zookeeper error * @throws InterruptedException In case of thread interruption. */ public static void updateCollectionLevelSnapshot(SolrZkClient zkClient, String collectionName, CollectionSnapshotMetaData meta) throws KeeperException, InterruptedException { String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.of(meta.getName())); zkClient.setData(zkPath, Utils.toJSON(meta), -1, true); }