Ejemplo n.º 1
0
        // Prints the tree without changing the tree view state
        public static String PrintTree(ZooKeeperWrapper zk, String machinesPath, String sellersPath, String stamp)
        {
            StringBuilder sb       = new StringBuilder();
            List <String> machines = zk.GetChildren(machinesPath, true);

            sb.AppendLine("[" + stamp + "] Machines Tree: ");
            foreach (var machine in machines)
            {
                var machineRecord = zk.GetData <ZNodesDataStructures.MachineNode>(machinesPath + "/" + machine, true);
                sb.AppendLine("[" + stamp + "] \\-" + machine);
                sb.AppendLine("[" + stamp + "]       \\-P: " + String.Join(" ", machineRecord.primaryOf));
                sb.AppendLine("[" + stamp + "]       \\-B: " + String.Join(" ", machineRecord.backsUp));
            }
            sb.AppendLine("[" + stamp + "] Sellers Tree: ");
            List <String> sellers = zk.GetChildren(sellersPath, true);

            foreach (var seller in sellers)
            {
                sb.AppendLine("[" + stamp + "] \\-" + seller);
                var sellerMachines = zk.GetChildren(sellersPath + "/" + seller, true);
                foreach (var sellerMachine in sellerMachines)
                {
                    var machineSellerRecord = zk.GetData <ZNodesDataStructures.SellerNode>(sellersPath + "/" + seller + "/" + sellerMachine, true);
                    sb.AppendLine("[" + stamp + "]       \\-" + machineSellerRecord.role + ": " + sellerMachine + " " + machineSellerRecord.uri);
                }
            }
            return(sb.ToString());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Set machines subtree events. this will register the following events:
 ///
 /// <para>1. a new machine node joins the subtree - fires MachinesNodeWatch</para>
 /// <para>2. an existing machine got message or died - fires MachineNodeWatch</para>
 ///
 /// </summary>
 ///
 private void setMachinesChildrenWatcher()
 {
     try
     {
         List <String> machines = zk.GetChildren(MachinesPath, new MachinesNodeWatch(this)); // Watch for new nodes
         foreach (var machine in machines)
         {
             String path = MachinesPath + "/" + machine;
             zk.GetData <ZNodesDataStructures.MachineNode>(path, new MachineNodeWatch(this));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Failed setting Machines Node children watch due to " + ex.Message);
         throw ex;
     }
 }
Ejemplo n.º 3
0
        public TreeView(ZooKeeperWrapper zk, String machinesPath, String sellersPath)
        {
            this.machinesPath = machinesPath;
            this.sellersPath  = sellersPath;
            this.zk           = zk;

            var newMachinesView = zk.GetChildren(machinesPath, false);
            var newSellersView  = zk.GetChildren(sellersPath, false);

            // Build machines tree from ZK
            machinesData.Clear();
            foreach (var machine in newMachinesView)
            {
                var machineData = zk.GetData <ZNodesDataStructures.MachineNode>(machinesPath + "/" + machine, false);
                machinesData.Add(machine, machineData);
            }

            // Build sellers tree from ZK
            sellersData.Clear();
            foreach (var seller in newSellersView)
            {
                var sellerMachines = zk.GetChildren(sellersPath + "/" + seller, false);
                if (sellerMachines.Count > 2)
                {
                    throw new Exception("Seller " + seller + " has too many machines: " + String.Join(" ", sellerMachines));
                }

                Dictionary <ZNodesDataStructures.SellerNode.NodeRole, ZNodesDataStructures.SellerNode> nodeRoles = new Dictionary <ZNodesDataStructures.SellerNode.NodeRole, ZNodesDataStructures.SellerNode>();
                foreach (var machine in sellerMachines)
                {
                    var machineSellerNode = zk.GetData <ZNodesDataStructures.SellerNode>(sellersPath + "/" + seller + "/" + machine, false);
                    nodeRoles[machineSellerNode.role] = machineSellerNode;
                }

                //if (nodeRoles.Count != 2)
                //{
                //    throw new Exception("Seller " + seller + "doesn't have needed roles " + String.Join(" ", nodeRoles.Keys.ToArray()));
                //}

                sellersData[seller] = new Dictionary <ZNodesDataStructures.SellerNode.NodeRole, ZNodesDataStructures.SellerNode>(nodeRoles);
            }
        }