Java Code Examples for org.apache.solr.common.cloud.SolrZkClient#close()
The following examples show how to use
org.apache.solr.common.cloud.SolrZkClient#close() .
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: ZkController.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Validates if the chroot exists in zk (or if it is successfully created). * Optionally, if create is set to true this method will create the path in * case it doesn't exist * * @return true if the path exists or is created false if the path doesn't * exist and 'create' = false */ public static boolean checkChrootPath(String zkHost, boolean create) throws KeeperException, InterruptedException { if (!SolrZkClient.containsChroot(zkHost)) { return true; } log.trace("zkHost includes chroot"); String chrootPath = zkHost.substring(zkHost.indexOf("/"), zkHost.length()); SolrZkClient tmpClient = new SolrZkClient(zkHost.substring(0, zkHost.indexOf("/")), 60000, 30000, null, null, null); boolean exists = tmpClient.exists(chrootPath, true); if (!exists && create) { tmpClient.makePath(chrootPath, false, true); exists = true; } tmpClient.close(); return exists; }
Example 2
Source File: SaslZkACLProviderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test @AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-13075") public void testSaslZkACLProvider() throws Exception { // Test with Sasl enabled SolrZkClient zkClient = new SolrZkClientWithACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, true, true, true, true, true, true, true, true, true, true); } finally { zkClient.close(); } // Test without Sasl enabled setupZNodes(); System.setProperty("zookeeper.sasl.client", "false"); zkClient = new SolrZkClientNoACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, true, true, false, false, false, false, false, false, false, false); } finally { zkClient.close(); System.clearProperty("zookeeper.sasl.client"); } }
Example 3
Source File: ConnectionManagerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Ignore public void testConnectionManager() throws Exception { // setup a SolrZkClient to do some getBaseUrlForNodeName testing Path zkDir = createTempDir("zkData"); ZkTestServer server = new ZkTestServer(zkDir); try { server.run(); SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT); ConnectionManager cm = zkClient.getConnectionManager(); try { assertFalse(cm.isLikelyExpired()); zkClient.getSolrZooKeeper().closeCnxn(); long sessionId = zkClient.getSolrZooKeeper().getSessionId(); server.expire(sessionId); Thread.sleep(TIMEOUT); assertTrue(cm.isLikelyExpired()); } finally { cm.close(); zkClient.close(); } } finally { server.shutdown(); } }
Example 4
Source File: ConnectionManagerTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testLikelyExpired() throws Exception { // setup a SolrZkClient to do some getBaseUrlForNodeName testing Path zkDir = createTempDir("zkData"); ZkTestServer server = new ZkTestServer(zkDir); try { server.run(); SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT); ConnectionManager cm = zkClient.getConnectionManager(); try { assertFalse(cm.isLikelyExpired()); assertTrue(cm.isConnectedAndNotClosed()); cm.process(new WatchedEvent(EventType.None, KeeperState.Disconnected, "")); // disconnect shouldn't immediately set likelyExpired assertFalse(cm.isConnectedAndNotClosed()); assertFalse(cm.isLikelyExpired()); // but it should after the timeout Thread.sleep((long)(zkClient.getZkClientTimeout() * 1.5)); assertFalse(cm.isConnectedAndNotClosed()); assertTrue(cm.isLikelyExpired()); // even if we disconnect immediately again cm.process(new WatchedEvent(EventType.None, KeeperState.Disconnected, "")); assertFalse(cm.isConnectedAndNotClosed()); assertTrue(cm.isLikelyExpired()); // reconnect -- should no longer be likely expired cm.process(new WatchedEvent(EventType.None, KeeperState.SyncConnected, "")); assertFalse(cm.isLikelyExpired()); assertTrue(cm.isConnectedAndNotClosed()); } finally { cm.close(); zkClient.close(); } } finally { server.shutdown(); } }
Example 5
Source File: TestStressLiveNodes.java From lucene-solr with Apache License 2.0 | 5 votes |
/** returns the true set of live nodes (currently in zk) as a sorted list */ private static List<String> getTrueLiveNodesFromZk() throws Exception { SolrZkClient client = newSolrZkClient(); try { ArrayList<String> result = new ArrayList<>(client.getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true)); Collections.sort(result); return result; } finally { client.close(); } }
Example 6
Source File: ZkSolrClientTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressWarnings({"try"}) public void testMakeRootNode() throws Exception { try (ZkConnection conn = new ZkConnection ()) { final SolrZkClient zkClient = new SolrZkClient(conn.getServer().getZkHost(), AbstractZkTestCase.TIMEOUT); try { assertTrue(zkClient.exists("/solr", true)); } finally { zkClient.close(); } } }
Example 7
Source File: TestSolrCloudWithDelegationTokens.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testZNodePaths() throws Exception { getDelegationToken(null, "bar", solrClientPrimary); SolrZkClient zkClient = new SolrZkClient(miniCluster.getZkServer().getZkAddress(), 1000); try { assertTrue(zkClient.exists("/security/zkdtsm", true)); assertTrue(zkClient.exists("/security/token", true)); } finally { zkClient.close(); } }
Example 8
Source File: OverriddenZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testReadonlyCredentialsSolrZkClientFactoryUsingVMParamsProvidersButWithDifferentVMParamsNames() throws Exception { useReadonlyCredentials(); SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, true, true, false, false, false, false, false, false, false, false); } finally { zkClient.close(); } }
Example 9
Source File: OverriddenZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testAllCredentialsSolrZkClientFactoryUsingVMParamsProvidersButWithDifferentVMParamsNames() throws Exception { useAllCredentials(); SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, true, true, true, true, true, true, true, true, true, true); } finally { zkClient.close(); } }
Example 10
Source File: VMParamsZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testWrongCredentials() throws Exception { useWrongCredentials(); SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { doTest(zkClient, false, false, false, false, false, false, false, false, false, false); } finally { zkClient.close(); } }
Example 11
Source File: VMParamsZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@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(); } }
Example 12
Source File: OverriddenZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders("readonlyACLUsername", "readonlyACLPassword", null, null).getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, true, true, false, false, false, false, false, false, false, false); } finally { zkClient.close(); } }
Example 13
Source File: OverriddenZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testWrongCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders("connectAndAllACLUsername", "connectAndAllACLPasswordWrong", null, null).getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, false, false, false, false, false, false, false, false, false, false); } finally { zkClient.close(); } }
Example 14
Source File: OverriddenZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testNoCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null).getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, false, false, false, false, false, false, false, false, false, false); } finally { zkClient.close(); } }
Example 15
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 16
Source File: VMParamsZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@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(); } }
Example 17
Source File: OutOfBoxZkACLAndCredentialsProvidersTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testOutOfBoxSolrZkClient() throws Exception { SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest(zkClient, true, true, true, true, true, true, true, true, true, true); } finally { zkClient.close(); } }
Example 18
Source File: SolrTestingUtility.java From hbase-indexer with Apache License 2.0 | 5 votes |
/** * Utility method to upload a Solr config into ZooKeeper. If you don't have the config in the form of * a filesystem directory, you might want to use {@link #uploadConfig(String, byte[], byte[])}. */ public void uploadConfig(String confName, File confDir) throws IOException { SolrZkClient zkClient = new SolrZkClient(zkConnectString, 30000, 30000, new OnReconnect() { @Override public void command() { } }); new ZkConfigManager(zkClient).uploadConfigDir(confDir.toPath(), confName); zkClient.close(); }
Example 19
Source File: SolrXmlInZkTest.java From lucene-solr with Apache License 2.0 | 4 votes |
private void setUpZkAndDiskXml(boolean toZk, boolean leaveOnLocal) throws Exception { Path tmpDir = createTempDir(); Path solrHome = tmpDir.resolve("home"); copyMinConf(new File(solrHome.toFile(), "myCollect")); if (leaveOnLocal) { FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr-stress-new.xml"), new File(solrHome.toFile(), "solr.xml")); } ignoreException("No UpdateLog found - cannot sync"); ignoreException("No UpdateLog found - cannot recover"); System.setProperty("zkClientTimeout", "8000"); zkDir = tmpDir.resolve("zookeeper" + System.nanoTime()).resolve("server1").resolve("data"); zkServer = new ZkTestServer(zkDir); zkServer.run(); System.setProperty("zkHost", zkServer.getZkAddress()); zkServer.buildZooKeeper("solrconfig.xml", "schema.xml"); zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); if (toZk) { zkClient.makePath("solr.xml", XML_FOR_ZK.getBytes(StandardCharsets.UTF_8), true); } zkClient.close(); if (log.isInfoEnabled()) { log.info("####SETUP_START {}", getTestName()); } // set some system properties for use by tests Properties props = new Properties(); props.setProperty("solr.test.sys.prop1", "propone"); props.setProperty("solr.test.sys.prop2", "proptwo"); cfg = SolrDispatchFilter.loadNodeConfig(solrHome, props); if (log.isInfoEnabled()) { log.info("####SETUP_END {}", getTestName()); } }
Example 20
Source File: AbstractDistribZkTestBase.java From lucene-solr with Apache License 2.0 | 4 votes |
protected void printLayout() throws Exception { SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); zkClient.printLayoutToStream(System.out); zkClient.close(); }