Java Code Examples for org.apache.solr.common.cloud.SolrZkClient#create()
The following examples show how to use
org.apache.solr.common.cloud.SolrZkClient#create() .
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: CdcrProcessStateManager.java From lucene-solr with Apache License 2.0 | 6 votes |
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); if (log.isInfoEnabled()) { 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); } }
Example 2
Source File: CdcrBufferStateManager.java From lucene-solr with Apache License 2.0 | 6 votes |
private void createStateNode() { SolrZkClient zkClient = core.getCoreContainer().getZkController().getZkClient(); try { if (!zkClient.exists(this.getZnodePath(), true)) { if (!zkClient.exists(this.getZnodeBase(), true)) { zkClient.makePath(this.getZnodeBase(), null, CreateMode.PERSISTENT, null, false, true); // Should be a no-op if node exists } zkClient.create(this.getZnodePath(), DEFAULT_STATE.getBytes(), CreateMode.PERSISTENT, true); if (log.isInfoEnabled()) { 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 buffer state node", e); } }
Example 3
Source File: SaslZkACLProviderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
protected void setupZNodes() throws Exception { SolrZkClient zkClient = new SolrZkClientWithACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { zkClient.create("/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath("/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.create(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); } finally { zkClient.close(); } zkClient = new SolrZkClientNoACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { zkClient.create("/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath("/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); } finally { zkClient.close(); } }
Example 4
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 5
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 6
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 7
Source File: OverriddenZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); if (log.isInfoEnabled()) { log.info("####SETUP_START {}", getTestName()); } createTempDir(); zkDir =createTempDir().resolve("zookeeper/server1/data"); log.info("ZooKeeper dataDir:{}", zkDir); zkServer = new ZkTestServer(zkDir); zkServer.run(false); System.setProperty("zkHost", zkServer.getZkAddress()); SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders("connectAndAllACLUsername", "connectAndAllACLPassword", "readonlyACLUsername", "readonlyACLPassword").getSolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); zkClient.makePath("/solr", false, true); zkClient.close(); zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders("connectAndAllACLUsername", "connectAndAllACLPassword", "readonlyACLUsername", "readonlyACLPassword").getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); zkClient.create("/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath("/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.create(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.close(); zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null).getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); zkClient.getSolrZooKeeper().addAuthInfo("digest", ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(DATA_ENCODING)); zkClient.create("/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath("/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.close(); if (log.isInfoEnabled()) { log.info("####SETUP_END {}", getTestName()); } }
Example 8
Source File: TestConfigSetsAPI.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testUploadErrors() throws Exception { final SolrClient solrClient = getHttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); ByteBuffer emptyData = ByteBuffer.allocate(0); // Checking error when no configuration name is specified in request @SuppressWarnings({"rawtypes"}) Map map = postDataAndGetResponse(solrCluster.getSolrClient(), solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/admin/configs?action=UPLOAD", emptyData, null, null); assertNotNull(map); long statusCode = (long) getObjectByPath(map, false, Arrays.asList("responseHeader", "status")); assertEquals(400l, statusCode); SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null); // Create dummy config files in zookeeper zkClient.makePath("/configs/myconf", true); zkClient.create("/configs/myconf/firstDummyFile", "first dummy content".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); zkClient.create("/configs/myconf/anotherDummyFile", "second dummy content".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); // Checking error when configuration name specified already exists map = postDataAndGetResponse(solrCluster.getSolrClient(), solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/admin/configs?action=UPLOAD&name=myconf", emptyData, null, null); assertNotNull(map); statusCode = (long) getObjectByPath(map, false, Arrays.asList("responseHeader", "status")); assertEquals(400l, statusCode); assertTrue("Expected file doesnt exist in zk. It's possibly overwritten", zkClient.exists("/configs/myconf/firstDummyFile", true)); assertTrue("Expected file doesnt exist in zk. It's possibly overwritten", zkClient.exists("/configs/myconf/anotherDummyFile", true)); zkClient.close(); solrClient.close(); }