/// <summary> /// sets up the initial structure for commodity nodes /// </summary> internal void SetupCommodityTree() { // instantiate a fake session with proper credentials ClientSession ses = this.backend.GetLoopbackSession(RMCommands.CommanderDigest); try { List <Acl> acls = null; // now, build the tree RequestResponse resp; // try to create the path to the bulkwatcher node string path = BulkOperation.GetBulkWatcherName(null); resp = this.backend.ProcessMessage(new RequestCreate(path, null, null, acls, CreateMode.PersistentAllowPathCreation, null), ses); Trace.TraceInformation("SetupCommodityTree: create({0})-->{1}", path, resp == null ? Code.Unknown : (Code)resp.ResultCode); } catch (Exception e) { Trace.TraceWarning("SetupCommodityTree: ignorable error {0}", e.Message); } finally { if (ses != null) { ses.Close(); } } }
/// <summary> /// sets up the tree for commands, with the given Acls and structure /// </summary> internal void SetupCommandTree() { // instantiate a fake session with proper credentials ClientSession ses = this.backend.GetLoopbackSession(RMCommands.CommanderDigest); try { // extract the digest from Auth, and build Acls string[] digestieces = ses.Auth.ClientDigest.Split(':'); List <Acl> acls = null; if (digestieces.Length == 2) { acls = new List <Acl>() { new Acl((int)Perm.ALL, new Id(digestieces[0], digestieces[1])) }; } // now, build the tree RequestResponse resp; // try to create the path to the commands node, with the Acls resp = this.backend.ProcessMessage(new RequestCreate(this.backend.ReplicaCommandPathPrefix, null, null, acls, CreateMode.PersistentAllowPathCreation, null), ses); Trace.TraceInformation("SetupCommandTree: create({0})-->{1}", this.backend.ReplicaCommandPathPrefix, (Code)resp.ResultCode); bool needsAcl = true; // try to override the ACls, in case those were wrong Stat anyStat = new Stat(); anyStat.Aversion = anyStat.Cversion = anyStat.Version = -1; resp = this.backend.ProcessMessage(new RequestGetAcl(this.backend.ReplicaCommandPathPrefix, null, anyStat, null), ses); if (resp != null && resp.ResultCode == (int)Code.Ok) { IList <Acl> prevAcl = resp.Content as IList <Acl>; if (EqualityHelper.Equals(acls, prevAcl)) { needsAcl = false; } } if (needsAcl) { // try to override the ACls, in case those were wrong resp = this.backend.ProcessMessage(new RequestSetAcl(this.backend.ReplicaCommandPathPrefix, null, acls, -1, null), ses); Trace.TraceInformation("SetupCommandTree: setacl({0})-->{1}", this.backend.ReplicaCommandPathPrefix, (Code)resp.ResultCode); } else { Trace.TraceInformation("SetupCommandTree: setacl({0})-->{1}", this.backend.ReplicaCommandPathPrefix, "not needed"); } // now we add the paths we need to have List <string> paths = new List <string>() { this.thisCommandPathPrimary, this.thisCommandPathOneSecondary, this.thisCommandPathAllReplicas, this.thisCommandPathAllSecondaries, }; // append the instance command nodes foreach (ClusterMember m in this.backend.Factory.GetAgreedMembers()) { paths.Add(this.backend.ReplicaCommandPathPrefix + "/$$" + m.MemberId); } // create the command nodes foreach (string path in paths) { resp = this.backend.ProcessMessage(new RequestCreate(path, null, null, null, CreateMode.Persistent, null), ses); Trace.TraceInformation("SetupCommandTree: create({0})-->{1}", path, (Code)resp.ResultCode); } } finally { if (ses != null) { ses.Close(); } } }