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 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); }
/** * Copy a config in ZooKeeper * * @param fromConfig the config to copy from * @param toConfig the config to copy to * @throws IOException if an I/O error occurs */ public void copyConfigDir(String fromConfig, String toConfig) throws IOException { copyConfigDir(fromConfig, toConfig, null); }
public ZkStateReader(SolrZkClient zkClient, Runnable securityNodeListener) { this.zkClient = zkClient; this.configManager = new ZkConfigManager(zkClient); this.closeClient = false; this.securityNodeListener = securityNodeListener; }
/** * Download a named config from Zookeeper to a location on the filesystem * @param configName the name of the config * @param downloadPath the path to write config files to * @throws IOException if an I/O exception occurs */ public void downloadConfig(String configName, Path downloadPath) throws IOException { connect(); zkStateReader.getConfigManager().downloadConfigDir(configName, downloadPath); }
/** * Upload a set of config files to Zookeeper and give it a name * * NOTE: You should only allow trusted users to upload configs. If you * are allowing client access to zookeeper, you should protect the * /configs node against unauthorised write access. * * @param configPath {@link java.nio.file.Path} to the config files * @param configName the name of the config * @throws IOException if an IO error occurs */ public void uploadConfig(Path configPath, String configName) throws IOException { connect(); zkStateReader.getConfigManager().uploadConfigDir(configPath, configName); }
/** * Copy a config in ZooKeeper * * @param fromConfig the config to copy from * @param toConfig the config to copy to * @param copiedToZkPaths should be an empty Set, will be filled in by function with the paths that were actually copied to. * @throws IOException if an I/O error occurs */ public void copyConfigDir(String fromConfig, String toConfig, Set<String> copiedToZkPaths) throws IOException { copyConfigDirFromZk(CONFIGS_ZKNODE + "/" + fromConfig, CONFIGS_ZKNODE + "/" + toConfig, copiedToZkPaths); }
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 a named config from Zookeeper to a location on the filesystem * @param configName the name of the config * @param downloadPath the path to write config files to * @throws IOException if an I/O exception occurs */ public void downloadConfig(String configName, Path downloadPath) throws IOException { connect(); zkStateReader.getConfigManager().downloadConfigDir(configName, downloadPath); }
/** * Upload a set of config files to Zookeeper and give it a name * * NOTE: You should only allow trusted users to upload configs. If you * are allowing client access to zookeeper, you should protect the * /configs node against unauthorised write access. * * @param configPath {@link java.nio.file.Path} to the config files * @param configName the name of the config * @throws IOException if an IO error occurs */ public void uploadConfig(Path configPath, String configName) throws IOException { connect(); zkStateReader.getConfigManager().uploadConfigDir(configPath, configName); }
private void copyConfigDirFromZk(String fromZkPath, String toZkPath, Set<String> copiedToZkPaths) throws IOException { try { List<String> files = zkClient.getChildren(fromZkPath, null, true); for (String file : files) { List<String> children = zkClient.getChildren(fromZkPath + "/" + file, null, true); if (children.size() == 0) { final String toZkFilePath = toZkPath + "/" + file; log.info("Copying zk node {} to {}", fromZkPath + "/" + file, toZkFilePath); byte[] data = zkClient.getData(fromZkPath + "/" + file, null, null, true); zkClient.makePath(toZkFilePath, data, true); if (copiedToZkPaths != null) copiedToZkPaths.add(toZkFilePath); } else { copyConfigDirFromZk(fromZkPath + "/" + file, toZkPath + "/" + file, copiedToZkPaths); } } } catch (KeeperException | InterruptedException e) { throw new IOException("Error copying nodes from zookeeper path " + fromZkPath + " to " + toZkPath, SolrZkClient.checkInterrupted(e)); } }
/** * 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); } }
/** * 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; }
/** * 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(); }
/** * 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(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; }
/** * 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"); if (!confDir.isDirectory()) {
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); } }