public virtual void TestSimple() { Timing timing = new Timing(); ChildReaper reaper = null; CuratorFramework client = CuratorFrameworkFactory.NewClient(server.GetConnectString (), timing.Session(), timing.Connection(), new RetryOneTime(1)); try { client.Start(); for (int i = 0; i < 10; ++i) { client.Create().CreatingParentsIfNeeded().ForPath("/test/" + Extensions.ToString (i)); } reaper = new ChildReaper(client, "/test", Reaper.Mode.ReapUntilDelete, 1); reaper.Start(); timing.ForWaiting().SleepABit(); Stat stat = client.CheckExists().ForPath("/test"); Assert.Equal(stat.GetNumChildren(), 0); } finally { CloseableUtils.CloseQuietly(reaper); CloseableUtils.CloseQuietly(client); } }
public virtual void TestNamespace() { Timing timing = new Timing(); ChildReaper reaper = null; CuratorFramework client = CuratorFrameworkFactory.Builder().ConnectString(server. GetConnectString()).SessionTimeoutMs(timing.Session()).ConnectionTimeoutMs(timing .Connection()).RetryPolicy(new RetryOneTime(1)).Namespace("foo").Build(); try { client.Start(); for (int i = 0; i < 10; ++i) { client.Create().CreatingParentsIfNeeded().ForPath("/test/" + Extensions.ToString (i)); } reaper = new ChildReaper(client, "/test", Reaper.Mode.ReapUntilDelete, 1); reaper.Start(); timing.ForWaiting().SleepABit(); Stat stat = client.CheckExists().ForPath("/test"); Assert.Equal(stat.GetNumChildren(), 0); stat = client.UsingNamespace(null).CheckExists().ForPath("/foo/test"); NUnit.Framework.Assert.IsNotNull(stat); Assert.Equal(stat.GetNumChildren(), 0); } finally { CloseableUtils.CloseQuietly(reaper); CloseableUtils.CloseQuietly(client); } }
/// <summary> /// Recursively expand the path into the supplied string builder, increasing /// the indentation by /// <see cref="Indent"/> /// as it proceeds (depth first) down /// the tree /// </summary> /// <param name="builder">string build to append to</param> /// <param name="path">path to examine</param> /// <param name="indent">current indentation</param> private void Expand(StringBuilder builder, string path, int indent) { try { GetChildrenBuilder childrenBuilder = curator.GetChildren(); IList <string> children = childrenBuilder.ForPath(path); foreach (string child in children) { string childPath = path + "/" + child; string body; Stat stat = curator.CheckExists().ForPath(childPath); StringBuilder bodyBuilder = new StringBuilder(256); bodyBuilder.Append(" [").Append(stat.GetDataLength()).Append("]"); if (stat.GetEphemeralOwner() > 0) { bodyBuilder.Append("*"); } if (verbose) { // verbose: extract ACLs builder.Append(" -- "); IList <ACL> acls = curator.GetACL().ForPath(childPath); foreach (ACL acl in acls) { builder.Append(RegistrySecurity.AclToString(acl)); builder.Append(" "); } } body = bodyBuilder.ToString(); // print each child Append(builder, indent, ' '); builder.Append('/').Append(child); builder.Append(body); builder.Append('\n'); // recurse Expand(builder, childPath, indent + Indent); } } catch (Exception e) { builder.Append(e.ToString()).Append("\n"); } }
/// <exception cref="System.IO.IOException"/> private void AddOrUpdateDelegationKey(DelegationKey key, bool isUpdate) { string nodeCreatePath = GetNodePath(ZkDtsmMasterKeyRoot, DelegationKeyPrefix + key .GetKeyId()); ByteArrayOutputStream os = new ByteArrayOutputStream(); DataOutputStream fsOut = new DataOutputStream(os); if (Log.IsDebugEnabled()) { Log.Debug("Storing ZKDTSMDelegationKey_" + key.GetKeyId()); } key.Write(fsOut); try { if (zkClient.CheckExists().ForPath(nodeCreatePath) != null) { zkClient.SetData().ForPath(nodeCreatePath, os.ToByteArray()).SetVersion(-1); if (!isUpdate) { Log.Debug("Key with path [" + nodeCreatePath + "] already exists.. Updating !!"); } } else { zkClient.Create().WithMode(CreateMode.Persistent).ForPath(nodeCreatePath, os.ToByteArray ()); if (isUpdate) { Log.Debug("Updating non existent Key path [" + nodeCreatePath + "].. Adding new !!" ); } } } catch (KeeperException.NodeExistsException) { Log.Debug(nodeCreatePath + " znode already exists !!"); } catch (Exception ex) { throw new IOException(ex); } finally { os.Close(); } }
private void DoWork() { foreach (string path in paths) { try { IList <string> children = client.GetChildren().ForPath(path); foreach (string name in children) { string thisPath = ZKPaths.MakePath(path, name); Stat stat = client.CheckExists().ForPath(thisPath); if ((stat != null) && (stat.GetNumChildren() == 0)) { reaper.AddPath(thisPath, mode); } } } catch (Exception e) { log.Error("Could not get children for path: " + path, e); } } }
/// <summary>Stat the file</summary> /// <param name="path">path of operation</param> /// <returns>a curator stat entry</returns> /// <exception cref="System.IO.IOException">on a failure</exception> /// <exception cref="Org.Apache.Hadoop.FS.PathNotFoundException">if the path was not found /// </exception> public virtual Stat ZkStat(string path) { CheckServiceLive(); string fullpath = CreateFullPath(path); Stat stat; try { if (Log.IsDebugEnabled()) { Log.Debug("Stat {}", fullpath); } stat = curator.CheckExists().ForPath(fullpath); } catch (Exception e) { throw OperationFailure(fullpath, "read()", e); } if (stat == null) { throw new PathNotFoundException(path); } return(stat); }