public SolrZkClient getZkClient(String zkHost, int zkClientSessionTimeout, int zkClientConnectTimeout) { if (zkHost == null) { throw new IllegalArgumentException("zkHost must not be null"); } SolrZkClient zkClient; try { zkClient = new SolrZkClient(zkHost, zkClientSessionTimeout, zkClientConnectTimeout); } catch (Exception e) { throw new IllegalArgumentException("Cannot connect to ZooKeeper: " + zkHost, e); } return zkClient; }
public SolrZkClient getZkClient(String zkHost) { if (zkHost == null) { throw new IllegalArgumentException("zkHost must not be null"); } SolrZkClient zkClient; try { zkClient = new SolrZkClient(zkHost, 30000); } catch (Exception e) { throw new IllegalArgumentException("Cannot connect to ZooKeeper: " + zkHost, e); } return zkClient; }
public SolrZkClient getZkClient(String zkHost) { if (zkHost == null) { throw new IllegalArgumentException("zkHost must not be null"); } SolrZkClient zkClient; try { zkClient = new SolrZkClient(zkHost, 30000); } catch (Exception e) { throw new IllegalArgumentException("Cannot connect to ZooKeeper: " + zkHost, e); } return zkClient; }
public SolrZkClient getZkClient(String zkHost) { if (zkHost == null) { throw new IllegalArgumentException("zkHost must not be null"); } SolrZkClient zkClient; try { zkClient = new SolrZkClient(zkHost, 30000); } catch (Exception e) { throw new IllegalArgumentException("Cannot connect to ZooKeeper: " + zkHost, e); } return zkClient; }
public SolrZkClient getZkClient(String zkHost) { if (zkHost == null) { throw new IllegalArgumentException("zkHost must not be null"); } SolrZkClient zkClient; try { zkClient = new SolrZkClient(zkHost, 30000); } catch (Exception e) { throw new IllegalArgumentException("Cannot connect to ZooKeeper: " + zkHost, e); } return zkClient; }
public SolrZkClient getZkClient(String zkHost) { if (zkHost == null) { throw new IllegalArgumentException("zkHost must not be null"); } SolrZkClient zkClient; try { zkClient = new SolrZkClient(zkHost, 30000); } catch (Exception e) { throw new IllegalArgumentException("Cannot connect to ZooKeeper: " + zkHost, e); } return zkClient; }
public ZkStateReader(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout) { this.zkClient = new SolrZkClient(zkServerAddress, zkClientTimeout, zkClientConnectTimeout, // on reconnect, reload cloud info new OnReconnect() { @Override public void command() { try { ZkStateReader.this.createClusterStateWatchersAndUpdate(); } catch (KeeperException e) { log.error("A ZK error has occurred", e); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "A ZK error has occurred", e); } catch (InterruptedException e) { // Restore the interrupted status Thread.currentThread().interrupt(); log.error("Interrupted", e); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "Interrupted", e); } } }); this.configManager = new ZkConfigManager(zkClient); this.closeClient = true; this.securityNodeListener = null; }
protected void printLayout(String zkHost) throws Exception { SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT); zkClient.printLayoutToStdOut(); zkClient.close(); }
public static void makeSolrZkNode(String zkHost) throws Exception { SolrZkClient zkClient = new SolrZkClient(zkHost, TIMEOUT); zkClient.makePath("/solr", false, true); zkClient.close(); }
/** * Check that a path exists in this server * @param path the path to check * @throws IOException if an IO exception occurs */ public void ensurePathExists(String path) throws IOException { try (SolrZkClient client = new SolrZkClient(getZkHost(), 10000)) { client.makePath(path, false); } catch (InterruptedException | KeeperException e) { throw new IOException("Error checking path " + path, SolrZkClient.checkInterrupted(e)); } }
private void populateZkWithCollectionInfo() { System.setProperty("zkHost", zkHostString); try { URL url = ConfigurationUtils.locate(FileSystem.getDefaultFileSystem(), "", solrDirectory + "/collection1/conf"); if (url == null) { try { url = new URL(solrDirectory + "/collection1/conf"); } catch (MalformedURLException e) { LOGGER.error("unable to load solr config", e); } } URI solrDirectoryFile = url.toURI(); try (SolrZkClient zkClient = new SolrZkClient(zkHostString, TIMEOUT, 45000, null)) { ZkConfigManager manager = new ZkConfigManager(zkClient); manager.uploadConfigDir(Paths.get(solrDirectoryFile), solrCollectionName); } } catch (URISyntaxException | IOException e) { LOGGER.error("unable to populate zookeeper", e); } }
/** * 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(); }
protected void printLayout() throws Exception { SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); zkClient.printLayoutToStdOut(); zkClient.close(); }
private void waitForAllNodes(int numServers, int timeout) throws IOException, InterruptedException { try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { int numliveNodes = 0; int retries = timeout; String liveNodesPath = "/solr/live_nodes"; // Wait up to {timeout} seconds for number of live_nodes to match up number of servers do { if (zkClient.exists(liveNodesPath, true)) { numliveNodes = zkClient.getChildren(liveNodesPath, null, true).size(); if (numliveNodes == numServers) { break; } } retries--; if (retries == 0) { throw new IllegalStateException("Solr servers failed to register with ZK." + " Current count: " + numliveNodes + "; Expected count: " + numServers); } Thread.sleep(1000); } while (numliveNodes != numServers); } catch (KeeperException e) { throw new IOException("Error communicating with zookeeper", e); } }
/** * 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(); }
public ZkStateReader(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout) { this.zkClient = new SolrZkClient(zkServerAddress, zkClientTimeout, zkClientConnectTimeout, // on reconnect, reload cloud info new OnReconnect() { @Override public void command() { try { ZkStateReader.this.createClusterStateWatchersAndUpdate(); } catch (KeeperException e) { log.error("", e); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } catch (InterruptedException e) { // Restore the interrupted status Thread.currentThread().interrupt(); log.error("", e); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } } }); this.cmdExecutor = new ZkCmdExecutor(zkClientTimeout); this.configManager = new ZkConfigManager(zkClient); this.closeClient = true; this.securityNodeListener = null; }
/** * Upload a config set * @param configDir a path to the config set to upload * @param configName the name to give the configset */ public void uploadConfigSet(Path configDir, String configName) throws IOException, KeeperException, InterruptedException { try(SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null)) { ZkConfigManager manager = new ZkConfigManager(zkClient); manager.uploadConfigDir(configDir, configName); } }
static void tryCleanPath(String zkHost, String path) throws Exception { SolrZkClient zkClient = new SolrZkClient(zkHost, TIMEOUT); if (zkClient.exists(path, true)) { zkClient.clean(path); } zkClient.close(); } }
try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset()), true); if (jettyConfig.sslConfig != null && jettyConfig.sslConfig.isSSLMode()) {
public static void buildZooKeeper(String zkHost, String zkAddress, File solrhome, String config, String schema) throws Exception { SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null); zkClient.makePath("/solr", false, true); zkClient.close(); zkClient = new SolrZkClient(zkAddress, AbstractZkTestCase.TIMEOUT);