Esempio n. 1
0
        public static async Task downloadFromZK(SolrZkClient zkClient, string zkPath, string filePath, CancellationToken token)
        {
            try
            {
                token.ThrowIfCancellationRequested();
                var children = await zkClient.getChildren(zkPath, null, true);

                // If it has no children, it's a leaf node, write the associated data from the ZNode.
                // Otherwise, continue recursing, but write the associated data to a special file if any
                if (!children.Any())
                {
                    // If we didn't copy data down, then we also didn't create the file. But we still need a marker on the local
                    // disk so create an empty file.
                    if (await copyDataDown(zkClient, zkPath, filePath) == 0)
                    {
                        Debug.WriteLine("Download: " + filePath);
                        File.Create(filePath);
                    }
                }
                else
                {
                    Directory.CreateDirectory(filePath); // Make parent dir.
                                                         // ZK nodes, whether leaf or not can have data. If it's a non-leaf node and
                                                         // has associated data write it into the special file.
                    token.ThrowIfCancellationRequested();
                    Debug.WriteLine("Download: " + filePath);
                    await copyDataDown(zkClient, zkPath, Path.Combine(filePath, ZKNODE_DATA_FILE));

                    foreach (var child in children)
                    {
                        var zkChild = zkPath;
                        if (zkChild.EndsWith("/") == false)
                        {
                            zkChild += "/";
                        }
                        zkChild += child;
                        if (await isEphemeral(zkClient, zkChild))
                        {
                            // Don't copy ephemeral nodes
                            continue;
                        }
                        // Go deeper into the tree now
                        await downloadFromZK(zkClient, zkChild, Path.Combine(filePath, child), token);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is KeeperException || ex is ThreadInterruptedException)
                {
                    throw new IOException("Error downloading files from zookeeper path " + zkPath + " to " + filePath,
                                          SolrZkClient.checkInterrupted(ex));
                }
                throw;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Check whether a config exists in Zookeeper
 /// </summary>
 /// <param name="configName">The config to check existance on</param>
 /// <returns>Whether the config exists or not</returns>
 /// <exception cref="IOException">If an I/O error occurs</exception>
 public async Task <bool> configExists(string configName)
 {
     try
     {
         return(await zkClient.exists(ConfigsZKnode + "/" + configName, true));
     }
     catch (Exception ex)
     {
         if (ex is KeeperException || ex is ThreadInterruptedException)
         {
             throw new IOException("Error checking whether config exists", SolrZkClient.checkInterrupted(ex));
         }
         throw;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Delete a config in ZooKeeper
 /// </summary>
 /// <param name="configName">The config to delete</param>
 /// <param name="token"></param>
 /// <exception cref="IOException">If an I/O error occurs</exception>
 public async Task deleteConfigDir(string configName, CancellationToken token)
 {
     try
     {
         await zkClient.clean(ConfigsZKnode + "/" + configName, token);
     }
     catch (Exception ex)
     {
         if (ex is KeeperException || ex is ThreadInterruptedException)
         {
             throw new IOException("Error checking whether config exists", SolrZkClient.checkInterrupted(ex));
         }
         throw;
     }
 }
Esempio n. 4
0
 public async Task <List <string> > listConfigs()
 {
     try
     {
         return(await zkClient.getChildren(ConfigsZKnode, null, true));
     }
     catch (KeeperException.NoNodeException)
     {
         return(new List <string>());
     }
     catch (Exception ex)
     {
         if (ex is KeeperException || ex is ThreadInterruptedException)
         {
             throw new IOException("Error listing configs", SolrZkClient.checkInterrupted(ex));
         }
         throw;
     }
 }
Esempio n. 5
0
        private static async Task uploadFileToZk(SolrZkClient zkClient, string zkNode, string file, Regex filenameExclusions)
        {
            var fielName = Path.GetFileName(file);

            if (filenameExclusions != null && filenameExclusions.Match(fielName ?? throw new InvalidOperationException("File name is empty")).Success)
            {
                //TODO: Log here
                //log.info("uploadToZK skipping '{}' due to filenameExclusions '{}'", filename, filenameExclusions);
                return;
            }
            try
            {
                // if the path exists (and presumably we're uploading data to it) just set its data
                if (Path.GetFileName(file).Equals(ZKNODE_DATA_FILE) && (await zkClient.exists(zkNode, true)))
                {
                    await zkClient.setData(zkNode, file, true);
                }
                else
                {
                    //Can't work async because it will try to create same path
                    zkClient.makePath(zkNode, file, false, true).Wait();
                }
            }
            catch (KeeperException ex)
            {
                throw new Exception("Error uploading file " + file + " to zookeeper path " + zkNode, SolrZkClient.checkInterrupted(ex));
            }
        }
Esempio n. 6
0
        private async Task copyConfigDirFromZk(string fromZkPath, string toZkPath, ISet <string> copiedToZkPaths = null)
        {
            try
            {
                var files = await zkClient.getChildren(fromZkPath, null, true);

                foreach (var file in files)
                {
                    var children = await zkClient.getChildren(fromZkPath + "/" + file, null, true);

                    if (!children.Any())
                    {
                        var toZkFilePath = toZkPath + "/" + file;
                        //TODO: Log here
                        //logger.info("Copying zk node {} to {}",fromZkPath + "/" + file, toZkFilePath);
                        var data = await zkClient.getData(fromZkPath + "/" + file, null, null, true);

                        //Take care it fails on Exists
                        await zkClient.makePath(toZkFilePath, data, true);

                        copiedToZkPaths?.Add(toZkFilePath);
                    }
                    else
                    {
                        await copyConfigDirFromZk(fromZkPath + "/" + file, toZkPath + "/" + file, copiedToZkPaths);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is KeeperException || ex is ThreadInterruptedException)
                {
                    throw new IOException("Error copying nodes from zookeeper path " + fromZkPath + " to " + toZkPath, SolrZkClient.checkInterrupted(ex));
                }
                throw;
            }
        }