public ZkStateReader(SolrZkClient zkClient, Runnable securityNodeListener) { this.zkClient = zkClient; this.configManager = new ZkConfigManager(zkClient); this.closeClient = false; this.securityNodeListener = securityNodeListener; }
public static void downConfig(SolrZkClient zkClient, String confName, Path confPath) throws IOException { ZkConfigManager manager = new ZkConfigManager(zkClient); // Try to download the configset manager.downloadConfigDir(confName, confPath); }
public static void upConfig(SolrZkClient zkClient, Path confPath, String confName) throws IOException { ZkConfigManager manager = new ZkConfigManager(zkClient); // Try to download the configset manager.uploadConfigDir(confPath, confName); }
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; }
/** * Download and return the config directory from ZK */ public File downloadConfigDir(SolrZkClient zkClient, String configName, File dir) throws IOException, InterruptedException, KeeperException { Preconditions.checkArgument(dir.exists()); Preconditions.checkArgument(dir.isDirectory()); ZkConfigManager manager = new ZkConfigManager(zkClient); manager.downloadConfigDir(configName, dir.toPath()); File confDir = new File(dir, "conf"); if (!confDir.isDirectory()) { // create a temporary directory with "conf" subdir and mv the config in there. This is // necessary because of CDH-11188; solrctl does not generate nor accept directories with e.g. // conf/solrconfig.xml which is necessary for proper solr operation. This should work // even if solrctl changes. confDir = new File(Files.createTempDir().getAbsolutePath(), "conf"); confDir.getParentFile().deleteOnExit(); Files.move(dir, confDir); dir = confDir.getParentFile(); } verifyConfigDir(confDir); return dir; }
/** * Download and return the config directory from ZK */ public File downloadConfigDir(SolrZkClient zkClient, String configName, File dir) throws IOException, InterruptedException, KeeperException { Preconditions.checkArgument(dir.exists()); Preconditions.checkArgument(dir.isDirectory()); ZkConfigManager manager = new ZkConfigManager(zkClient); manager.downloadConfigDir(configName, dir.toPath()); File confDir = new File(dir, "conf"); if (!confDir.isDirectory()) { // create a temporary directory with "conf" subdir and mv the config in there. This is // necessary because of CDH-11188; solrctl does not generate nor accept directories with e.g. // conf/solrconfig.xml which is necessary for proper solr operation. This should work // even if solrctl changes. confDir = new File(Files.createTempDir().getAbsolutePath(), "conf"); confDir.getParentFile().deleteOnExit(); Files.move(dir, confDir); dir = confDir.getParentFile(); } verifyConfigDir(confDir); return dir; }
public ZkStateReader(SolrZkClient zkClient, Runnable securityNodeListener) { this.zkClient = zkClient; this.cmdExecutor = new ZkCmdExecutor(zkClient.getZkClientTimeout()); this.configManager = new ZkConfigManager(zkClient); this.closeClient = false; this.securityNodeListener = securityNodeListener; }
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(); }
/** * 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(); }
File dir = Files.createTempDir(); dir.deleteOnExit(); ZkConfigManager configManager = new ZkConfigManager(zkClient); configManager.downloadConfigDir(configName, dir.toPath()); File confDir = new File(dir, "conf");
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); } }