示例#1
0
 public Task deleteNode(string path)
 {
     return(ZooKeeper.Using(hostPort, CONNECTION_TIMEOUT, NullWatcher.Instance, zk =>
     {
         return ZKUtil.deleteRecursiveAsync(zk, path);
     }));
 }
示例#2
0
        public async Task <IEnumerable <NodeViewModel> > GetAllAsync()
        {
            var rootNodes = await Api.getChildrenAsync("/");

            var allTasks = rootNodes.Children.Select(x => ZKUtil.listSubTreeBFS(Api, "/" + x));
            var allNodes = (await Task.WhenAll(allTasks)).SelectMany(x => x).ToArray();

            return(allNodes.Select(x => new NodeViewModel(this, x, GetNodeName(x))).ToArray());
        }
示例#3
0
        public Task DeleteMembershipTableEntries(string deploymentId)
        {
            string pathToDelete = "/" + deploymentId;

            return(UsingZookeeper(rootConnectionString, async zk =>
            {
                await ZKUtil.deleteRecursiveAsync(zk, pathToDelete);
                await zk.sync(pathToDelete);
            }));
        }
示例#4
0
 /// <summary>Parse an ACL list.</summary>
 /// <remarks>
 /// Parse an ACL list. This includes configuration indirection
 /// <see cref="Org.Apache.Hadoop.Util.ZKUtil.ResolveConfIndirection(string)"/>
 /// </remarks>
 /// <param name="zkAclConf">configuration string</param>
 /// <returns>an ACL list</returns>
 /// <exception cref="System.IO.IOException">on a bad ACL parse</exception>
 public virtual IList <ACL> ParseACLs(string zkAclConf)
 {
     try
     {
         return(ZKUtil.ParseACLs(ZKUtil.ResolveConfIndirection(zkAclConf)));
     }
     catch (ZKUtil.BadAclFormatException e)
     {
         throw new IOException("Parsing " + zkAclConf + " :" + e, e);
     }
 }
示例#5
0
 /// <exception cref="System.IO.IOException"/>
 public override void Format(NamespaceInfo ns)
 {
     try
     {
         // delete old info
         Stat baseStat   = null;
         Stat ledgerStat = null;
         if ((baseStat = zkc.Exists(basePath, false)) != null)
         {
             if ((ledgerStat = zkc.Exists(ledgerPath, false)) != null)
             {
                 foreach (EditLogLedgerMetadata l in GetLedgerList(true))
                 {
                     try
                     {
                         bkc.DeleteLedger(l.GetLedgerId());
                     }
                     catch (BKException.BKNoSuchLedgerExistsException)
                     {
                         Log.Warn("Ledger " + l.GetLedgerId() + " does not exist;" + " Cannot delete.");
                     }
                 }
             }
             ZKUtil.DeleteRecursive(zkc, basePath);
         }
         // should be clean now.
         zkc.Create(basePath, new byte[] { (byte)('0') }, ZooDefs.Ids.OpenAclUnsafe, CreateMode
                    .Persistent);
         BKJournalProtos.VersionProto.Builder builder = BKJournalProtos.VersionProto.NewBuilder
                                                            ();
         builder.SetNamespaceInfo(PBHelper.Convert(ns)).SetLayoutVersion(BkjmLayoutVersion
                                                                         );
         byte[] data = Sharpen.Runtime.GetBytesForString(TextFormat.PrintToString(((BKJournalProtos.VersionProto
                                                                                    )builder.Build())), Charsets.Utf8);
         zkc.Create(versionPath, data, ZooDefs.Ids.OpenAclUnsafe, CreateMode.Persistent);
         zkc.Create(ledgerPath, new byte[] { (byte)('0') }, ZooDefs.Ids.OpenAclUnsafe, CreateMode
                    .Persistent);
     }
     catch (KeeperException ke)
     {
         Log.Error("Error accessing zookeeper to format", ke);
         throw new IOException("Error accessing zookeeper to format", ke);
     }
     catch (Exception ie)
     {
         Sharpen.Thread.CurrentThread().Interrupt();
         throw new IOException("Interrupted during format", ie);
     }
     catch (BKException bke)
     {
         throw new IOException("Error cleaning up ledgers during format", bke);
     }
 }
示例#6
0
 public virtual void Setup()
 {
     zkc = ConnectZooKeeper(Hostport);
     try
     {
         ZKUtil.DeleteRecursive(zkc, BkRootPath);
     }
     catch (KeeperException.NoNodeException e)
     {
         Log.Debug("Ignoring no node exception on cleanup", e);
     }
     catch (Exception e)
     {
         Log.Error("Exception when deleting bookie root path in zk", e);
     }
 }
示例#7
0
        /// <summary>Utility method to fetch the ZK ACLs from the configuration</summary>
        /// <exception cref="System.Exception"/>
        public static IList <ACL> GetZKAcls(Configuration conf)
        {
            // Parse authentication from configuration.
            string zkAclConf = conf.Get(YarnConfiguration.RmZkAcl, YarnConfiguration.DefaultRmZkAcl
                                        );

            try
            {
                zkAclConf = ZKUtil.ResolveConfIndirection(zkAclConf);
                return(ZKUtil.ParseACLs(zkAclConf));
            }
            catch (Exception e)
            {
                Log.Error("Couldn't read ACLs based on " + YarnConfiguration.RmZkAcl);
                throw;
            }
        }
示例#8
0
        /// <summary>Utility method to fetch ZK auth info from the configuration</summary>
        /// <exception cref="System.Exception"/>
        public static IList <ZKUtil.ZKAuthInfo> GetZKAuths(Configuration conf)
        {
            string zkAuthConf = conf.Get(YarnConfiguration.RmZkAuth);

            try
            {
                zkAuthConf = ZKUtil.ResolveConfIndirection(zkAuthConf);
                if (zkAuthConf != null)
                {
                    return(ZKUtil.ParseAuth(zkAuthConf));
                }
                else
                {
                    return(Sharpen.Collections.EmptyList());
                }
            }
            catch (Exception e)
            {
                Log.Error("Couldn't read Auth based on " + YarnConfiguration.RmZkAuth);
                throw;
            }
        }
示例#9
0
        /// <exception cref="Org.Apache.Hadoop.HadoopIllegalArgumentException"/>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Zookeeper.KeeperException"/>
        private void InitZK()
        {
            zkQuorum = conf.Get(ZkQuorumKey);
            int zkTimeout = conf.GetInt(ZkSessionTimeoutKey, ZkSessionTimeoutDefault);
            // Parse ACLs from configuration.
            string zkAclConf = conf.Get(ZkAclKey, ZkAclDefault);

            zkAclConf = ZKUtil.ResolveConfIndirection(zkAclConf);
            IList <ACL> zkAcls = ZKUtil.ParseACLs(zkAclConf);

            if (zkAcls.IsEmpty())
            {
                zkAcls = ZooDefs.Ids.CreatorAllAcl;
            }
            // Parse authentication from configuration.
            string zkAuthConf = conf.Get(ZkAuthKey);

            zkAuthConf = ZKUtil.ResolveConfIndirection(zkAuthConf);
            IList <ZKUtil.ZKAuthInfo> zkAuths;

            if (zkAuthConf != null)
            {
                zkAuths = ZKUtil.ParseAuth(zkAuthConf);
            }
            else
            {
                zkAuths = Collections.EmptyList();
            }
            // Sanity check configuration.
            Preconditions.CheckArgument(zkQuorum != null, "Missing required configuration '%s' for ZooKeeper quorum"
                                        , ZkQuorumKey);
            Preconditions.CheckArgument(zkTimeout > 0, "Invalid ZK session timeout %s", zkTimeout
                                        );
            int maxRetryNum = conf.GetInt(CommonConfigurationKeys.HaFcElectorZkOpRetriesKey,
                                          CommonConfigurationKeys.HaFcElectorZkOpRetriesDefault);

            elector = new ActiveStandbyElector(zkQuorum, zkTimeout, GetParentZnode(), zkAcls,
                                               zkAuths, new ZKFailoverController.ElectorCallbacks(this), maxRetryNum);
        }