コード例 #1
0
ファイル: RemoveCommand.cs プロジェクト: erpframework/cloudb
        private CommandResultCode RemovePath(NetworkContext context, string pathName, string rootAddress)
        {
            IServiceAddress address;

            // If machine is null, we need to find the machine the path is on,
            if (rootAddress == null) {
                PathInfo pathInfo = context.Network.GetPathInfo(pathName);
                if (pathInfo == null) {
                    Out.WriteLine("The path '" + pathName + "' was not found.");
                    return CommandResultCode.ExecutionFailed;
                }
                address = pathInfo.RootLeader;
            } else {
                address = ServiceAddresses.ParseString(rootAddress);
            }

            Out.WriteLine("Removing path " + pathName + " from root " + address);
            Out.Flush();

            MachineProfile p = context.Network.GetMachineProfile(address);
            if (p == null) {
                Out.WriteLine("Error: Machine was not found in the network schema.");
                return CommandResultCode.ExecutionFailed;
            }
            if (!p.IsRoot) {
                Out.WriteLine("Error: Given machine is not a root.");
                return CommandResultCode.ExecutionFailed;
            }

            // Remove the path,
            context.Network.RemovePathFromNetwork(pathName, address);
            Out.WriteLine("done.");
            return CommandResultCode.Success;
        }
コード例 #2
0
ファイル: StopCommand.cs プロジェクト: ikvm/cloudb
        private CommandResultCode StopRole(NetworkContext context, string role, IServiceAddress address)
        {
            Out.WriteLine("Stopping role " + role + " on " + address);

            MachineProfile p = context.Network.GetMachineProfile(address);
            if (p == null) {
                Out.WriteLine("Error: Machine was not found in the network schema.");
                return CommandResultCode.ExecutionFailed;
            }

            // Here we have some rules,
            // 1. The manager can not be relieved until all block and root servers have
            //    been.

            MachineProfile currentManager = context.Network.ManagerServer;
            MachineProfile[] currentRoots = context.Network.RootServers;
            MachineProfile[] currentBlocks = context.Network.BlockServers;
            if (role.Equals("manager")) {
                if (currentRoots.Length > 0 ||
                    currentBlocks.Length > 0) {
                    Error.WriteLine("Error: Can not relieve manager role when there are existing block and root assignments.");
                    return CommandResultCode.ExecutionFailed;
                }
            }

            // Check that the machine is performing the role,
            bool isPerforming = false;
            if (role.Equals("block")) {
                isPerforming = p.IsBlock;
            } else if (role.Equals("manager")) {
                isPerforming = p.IsManager;
            } else if (role.Equals("root")) {
                isPerforming = p.IsRoot;
            } else {
                Error.WriteLine("Unknown role " + role);
                return CommandResultCode.SyntaxError;
            }

            if (!isPerforming) {
                Error.WriteLine("Error: The machine is not assigned to the " + role + " role.");
                return CommandResultCode.ExecutionFailed;
            }

            // Perform the assignment,
            if (role.Equals("block")) {
                context.Network.DeregisterBlock(address);
                context.Network.StopService(address, ServiceType.Block);
            } else if (role.Equals("manager")) {
                context.Network.StopService(address, ServiceType.Manager);
            } else if (role.Equals("root")) {
                context.Network.DeregisterRoot(address);
                context.Network.StopService(address, ServiceType.Root);
            } else {
                Error.WriteLine("Unknown role " + role);
                return CommandResultCode.SyntaxError;
            }

            Out.WriteLine("done.");
            return CommandResultCode.Success;
        }
コード例 #3
0
ファイル: RollbackCommand.cs プロジェクト: ikvm/cloudb
        private void Rollback(NetworkContext networkContext, string pathName, string time, bool hours)
        {
            if (hours) {
                int numHours;
                if (!Int32.TryParse(time, out numHours)) {
                    Error.WriteLine("must be a valid number of hours.");
                    throw new FormatException();
                }

                Out.WriteLine("reverting " + time + " hours.");

                DateTime timems = DateTime.Now.AddHours(-numHours);
                RollbackPathToTime(networkContext, pathName, timems);
            } else {
                // Try and parse it
                try {
                    DateTime date = DateTime.Parse(time);

                    RollbackPathToTime(networkContext, pathName, date);
                } catch (FormatException) {
                    Error.Write("unable to parse timestamp '");
                    Error.Write(time);
                    Error.Write("': ");
                    Error.Write("must be formatted in one of the standards formats ");
                    Error.WriteLine("(eg. 'feb 25, 2010 2:25am')");
                }
            }
        }
コード例 #4
0
ファイル: AddCommand.cs プロジェクト: ikvm/cloudb
        private CommandResultCode AddPath(NetworkContext context, string pathType, string pathName, string rootAddress)
        {
            IServiceAddress address = ServiceAddresses.ParseString(rootAddress);
            Out.WriteLine("Adding path " + pathType + " " + pathName + " to root " + address.ToString());

            MachineProfile p = context.Network.GetMachineProfile(address);
            if (p == null) {
                Error.WriteLine("error: Machine was not found in the network schema.");
                return CommandResultCode.ExecutionFailed;
            }
            if (!p.IsRoot) {
                Error.WriteLine("error: Given machine is not a root.");
                return CommandResultCode.ExecutionFailed;
            }

            // Add the path,
            try {
                context.Network.AddPath(address, pathName, pathType);
            } catch (Exception e) {
                Error.WriteLine("cannot add the path: " + e.Message);
                return CommandResultCode.ExecutionFailed;
            }

            Out.WriteLine("done.");
            return CommandResultCode.Success;
        }
コード例 #5
0
ファイル: RemoveCommand.cs プロジェクト: ikvm/cloudb
        private CommandResultCode RemovePath(NetworkContext context, string pathName, String rootAddress)
        {
            IServiceAddress address;
            // If machine is null, we need to find the machine the path is on,
            if (String.IsNullOrEmpty(rootAddress)) {
                address = context.Network.GetRoot(pathName);
                if (address == null) {
                    Error.WriteLine("error: unable to find path " + pathName);
                    return CommandResultCode.ExecutionFailed;
                }
            } else {
                address = ServiceAddresses.ParseString(rootAddress);
            }

            Out.WriteLine("removing path " + pathName + " from root " + address.ToString());

            MachineProfile p = context.Network.GetMachineProfile(address);
            if (p == null) {
                Error.WriteLine("error: machine was not found in the network schema.");
                return CommandResultCode.ExecutionFailed;
            }
            if (!p.IsRoot) {
                Error.WriteLine("error: given machine is not a root.");
                return CommandResultCode.ExecutionFailed;
            }

            // Remove the path,
            context.Network.RemovePath(address, pathName);
            Out.WriteLine("done.");
            return CommandResultCode.Success;
        }
コード例 #6
0
ファイル: StartCommand.cs プロジェクト: ikvm/cloudb
        private CommandResultCode StartRole(NetworkContext context, string role, IServiceAddress address)
        {
            Out.WriteLine("Starting role " + role + " on " + address);

            MachineProfile p = context.Network.GetMachineProfile(address);
            if (p == null) {
                Error.WriteLine("Error: Machine was not found in the network schema.");
                return CommandResultCode.ExecutionFailed;
            }

            // Here we have some rules,
            // 1. There must be a manager service assigned before block and roots can be
            //    assigned.
            // 2. Only one manager server can exist.

            MachineProfile current_manager = context.Network.ManagerServer;
            if (!role.Equals("manager") && current_manager == null) {
                Error.WriteLine("Error: Can not assign block or root role when no manager is available on the network.");
                return CommandResultCode.ExecutionFailed;
            } else if (role.Equals("manager") && current_manager != null) {
                Out.WriteLine("Error: Can not assign manager because manager role already assigned.");
                return CommandResultCode.ExecutionFailed;
            }

            // Check if the machine already performing the role,
            bool already_doing_it = false;
            if (role.Equals("block")) {
                already_doing_it = p.IsBlock;
            } else if (role.Equals("manager")) {
                already_doing_it = p.IsManager;
            } else if (role.Equals("root")) {
                already_doing_it = p.IsRoot;
            } else {
                Error.WriteLine("Unknown role " + role);
                return CommandResultCode.SyntaxError;
            }

            if (already_doing_it) {
                Error.WriteLine("Error: The machine is already assigned to the " + role + " role.");
                return CommandResultCode.ExecutionFailed;
            }

            // Perform the assignment,
            if (role.Equals("block")) {
                context.Network.StartService(address, ServiceType.Block);
                context.Network.RegisterBlock(address);
            } else if (role.Equals("manager")) {
                context.Network.StartService(address, ServiceType.Manager);
            } else if (role.Equals("root")) {
                context.Network.StartService(address, ServiceType.Root);
                context.Network.RegisterRoot(address);
            } else {
                Error.WriteLine("Unknown role " + role);
                return CommandResultCode.SyntaxError;
            }

            Out.WriteLine("done.");
            return CommandResultCode.Success;
        }
コード例 #7
0
ファイル: AddCommand.cs プロジェクト: ikvm/cloudb
        private CommandResultCode AddValue(NetworkContext context, CommandArguments args)
        {
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string value = args.Current;

            if (String.IsNullOrEmpty(value))
                return CommandResultCode.ExecutionFailed;

            if (value[0] == '\'') {
                bool endFound = false;
                StringBuilder sb = new StringBuilder();
                while (!endFound) {
                    for (int i = 0; !String.IsNullOrEmpty(value) && i < value.Length; i++) {
                        char c = value[i];
                        if (c == '\'' && i > 0) {
                            endFound = true;
                            break;
                        }

                        sb.Append(c);
                    }

                    if (!endFound && args.MoveNext()) {
                        sb.Append(' ');
                        value = args.Current;
                    }
                }

                value = sb.ToString();
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "into")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string tableName = args.Current;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "with")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;
            if (args.Current != "key")
                return CommandResultCode.SyntaxError;
            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string key = args.Current;

            string pathName = null;

            if (args.MoveNext()) {
                if (args.Current != "to")
                    return CommandResultCode.SyntaxError;
                if (!args.MoveNext())
                    return CommandResultCode.SyntaxError;

                pathName = args.Current;
            }

            try {
                context.AddValueToPath(pathName, tableName, key, value);
            } catch(Exception e) {
                Error.WriteLine("error while adding the value: " + e.Message);
                Error.WriteLine();
                return CommandResultCode.ExecutionFailed;
            }

            return CommandResultCode.Success;
        }
コード例 #8
0
ファイル: RollbackCommand.cs プロジェクト: ikvm/cloudb
        private void RollbackPathToTime(NetworkContext context, string pathName, DateTime time)
        {
            IServiceAddress address = context.Network.GetRoot(pathName);
            if (address == null)
                throw new ApplicationException("path '" + pathName + "' was not found.");

            Out.WriteLine("Reverting path " + pathName + " to " + time);

            DataAddress[] dataAddresses = context.Network.GetHistoricalPathRoots(address, pathName, time, 20);

            if (dataAddresses.Length == 0) {
                Out.WriteLine("no historical roots found.");
                return;
            }

            Out.WriteLine();
            Out.WriteLine("found the following roots:");
            foreach(DataAddress da in dataAddresses) {
                Out.WriteLine("  " + da);
            }

            Out.WriteLine();
            Out.WriteLine("WARNING: Great care must be taken when rolling back a path. This");
            Out.WriteLine(" operation is only intended as a way to recover from some types");
            Out.WriteLine(" of corruption or other data inconsistency issues.");
            Out.WriteLine(" Before agreeing to rollback the path, ensure there are no open");
            Out.WriteLine(" writable transactions currently active on the path. A commit");
            Out.WriteLine(" write on this path before this operation completes may undo the");
            Out.WriteLine(" rollback or worse, put the path back into an inconsistent ");
            Out.WriteLine(" state.");
            Out.WriteLine();

            Question question = new Question("If you are sure you want to continue type YES (case-sensitive) ", new object[] { "YES", "no" }, 1);
            Answer answer = question.Ask(Application, false);
            if (answer.SelectedOption != 0)
                return;

            Out.WriteLine();

            context.Network.PublishPath(address, pathName, dataAddresses[0]);
            Out.WriteLine("done.");
        }
コード例 #9
0
ファイル: FixCommand.cs プロジェクト: ikvm/cloudb
        private void BlockMapProcess(NetworkContext context, IBlockMapProcess process)
        {
            Out.WriteLine("Processing...");

            // Refresh
            context.Network.Refresh();

            MachineProfile manager = context.Network.ManagerServer;
            if (manager == null)
                throw new ApplicationException("Error: Manager currently not available.");

            // Generate a map of server guid value to MachineProfile for that machine
            // node currently available.
            MachineProfile[] blockServers = context.Network.BlockServers;
            long[] availableBlockGuids = new long[blockServers.Length];
            Dictionary<long, MachineProfile> sguidToAddress = new Dictionary<long, MachineProfile>();
            for (int i = 0; i < blockServers.Length; ++i) {
                long serverGuid = context.Network.GetBlockGuid(blockServers[i].Address);
                availableBlockGuids[i] = serverGuid;
                sguidToAddress[availableBlockGuids[i]] = blockServers[i];
            }

            Array.Sort(availableBlockGuids);

            int blockServerCount = blockServers.Length;
            Out.WriteLine("Block servers currently available: " + blockServerCount);
            if (blockServerCount < 3) {
                Out.WriteLine("WARNING: There are currently less than 3 block servers available.");
            }

            // The map of block_id to list of server guids that contain the block,
            Dictionary<long, List<long>> blockIdMap = new Dictionary<long, List<long>>();

            // For each block server,
            Dictionary<long, MachineProfile>.KeyCollection serverGuids = sguidToAddress.Keys;
            foreach (long serverGuid in serverGuids) {
                MachineProfile block = sguidToAddress[serverGuid];
                // Fetch the list of blocks for the server,
                long[] blockIds = context.Network.GetBlockList(block.Address);
                foreach (long blockId in blockIds) {
                    // Build the association,
                    List<long> list = blockIdMap[blockId];
                    if (list == null) {
                        list = new List<long>(5);
                        blockIdMap[blockId] = list;
                    }
                    list.Add(serverGuid);
                }
            }

            // Now, 'block_id_map' contains the actual map of block id to servers as
            // reported by the block servers. We now need to compare this to the map
            // the manager server has.

            // The total number of mappings recorded by the manager,
            long count = context.Network.GetBlockMappingCount();
            long[] m = context.Network.GetBlockMappingRange(0, Int64.MaxValue);

            long blCur = -1;
            List<long> list1 = new List<long>();

            for (int i = 0; i < m.Length; i += 2) {
                long bl = m[i];      // the block id
                long sg = m[i + 1];  // the server guid

                if (bl != blCur) {
                    if (list1.Count > 0) {
                        // Check this block,
                        List<long> in_list = blockIdMap[blCur];
                        process.ManagerProcess(blCur, list1, in_list, sguidToAddress);
                    }
                    list1.Clear();
                    blCur = bl;
                }
                list1.Add(sg);
            }

            // For each block,
            Dictionary<long, List<long>>.KeyCollection blockIds1 = blockIdMap.Keys;
            int minBlockThreshold = Math.Min(3, Math.Max(blockServerCount, 1));
            foreach (long block_id in blockIds1) {
                List<long> blockIdOnSguids = blockIdMap[block_id];
                List<long> availableSguids = new List<long>();
                foreach (long block_sguid in blockIdOnSguids) {
                    if (Array.BinarySearch(availableBlockGuids, block_sguid) >= 0) {
                        availableSguids.Add(block_sguid);
                    }
                }

                process.Process(block_id, availableSguids,
                                availableBlockGuids, minBlockThreshold,
                                sguidToAddress);

            }
        }
コード例 #10
0
ファイル: FixCommand.cs プロジェクト: ikvm/cloudb
 public BlockMapProcessImpl(FixCommand command, NetworkContext context, Random r)
 {
     this.command = command;
     this.context = context;
     this.r = r;
 }
コード例 #11
0
ファイル: ShowCommand.cs プロジェクト: ikvm/cloudb
        public void ShowStatus(NetworkContext context)
        {
            ColumnDesign[] columns = new ColumnDesign[3];
            columns[0] = new ColumnDesign("Status");
            columns[1] = new ColumnDesign("Service");
            columns[2] = new ColumnDesign("Address");

            TableRenderer table = new TableRenderer(columns, Out);

            context.Network.Refresh();

            IDictionary<IServiceAddress, string> status_info = null;
            // Manager servers status,
            MachineProfile manager = context.Network.ManagerServer;
            if (manager != null) {
                ColumnValue[] row = new ColumnValue[3];
                row[0] = new ColumnValue("UP");
                row[1] = new ColumnValue("Manager");
                row[2] = new ColumnValue(manager.Address.ToString());

                try {
                    status_info = context.Network.GetBlocksStatus();
                } catch (NetworkAdminException e) {
                    Error.WriteLine("Error retrieving manager status info: " + e.Message);
                }

                table.AddRow(row);
            } else {
                Error.WriteLine("! Manager server not available");
            }

            // Status of root servers
            MachineProfile[] roots = context.Network.RootServers;
            if (roots.Length == 0) {
                Out.WriteLine("! Root servers not available");
            }
            foreach (MachineProfile r in roots) {
                ColumnValue[] row = new ColumnValue[3];
                if (r.HasError) {
                    row[0] = new ColumnValue("DOWN");
                } else {
                    row[0] = new ColumnValue("UP");
                }

                row[1] = new ColumnValue("Root");
                row[2] = new ColumnValue(r.Address.ToString());

                if (r.HasError) {
                    Out.Write("  ");
                    Out.WriteLine(r.ErrorState);
                }

                table.AddRow(row);
            }

            // The block servers we fetch from the map,
            List<IServiceAddress> blocks = new List<IServiceAddress>();
            if (status_info != null) {
                foreach (IServiceAddress s in status_info.Keys) {
                    blocks.Add(s);
                }
            } else {
                MachineProfile[] sblocks = context.Network.BlockServers;
                foreach (MachineProfile b in sblocks) {
                    blocks.Add(b.Address);
                }
            }
            blocks.Sort();

            if (blocks.Count == 0) {
                Out.WriteLine("! Block servers not available");
            }
            foreach (IServiceAddress b in blocks) {
                ColumnValue[] row = new ColumnValue[3];

                if (status_info != null) {
                    String status_str = status_info[b];
                    if (status_str.Equals("UP")) {
                        // Manager reported up
                        row[0] = new ColumnValue("UP");
                    } else if (status_str.Equals("DOWN CLIENT REPORT")) {
                        // Manager reported down from client report of error
                        row[0] = new ColumnValue("D-CR");
                    } else if (status_str.Equals("DOWN HEARTBEAT")) {
                        // Manager reported down from heart beat check on the server
                        row[0] = new ColumnValue("D-HB");
                    } else if (status_str.Equals("DOWN SHUTDOWN")) {
                        // Manager reported down from shut down request
                        row[0] = new ColumnValue("D-SD");
                    } else {
                        row[0] = new ColumnValue("?ERR");
                    }

                } else {
                    // Try and get status from machine profile
                    MachineProfile r = context.Network.GetMachineProfile(b);
                    if (r.HasError) {
                        row[0] = new ColumnValue("DOWN");
                    } else {
                        row[0] = new ColumnValue("UP");
                    }
                }

                row[1] = new ColumnValue("Block");
                row[2] = new ColumnValue(b.ToString());

                table.AddRow(row);
            }

            table.CloseTable();
        }
コード例 #12
0
ファイル: ShowCommand.cs プロジェクト: ikvm/cloudb
        private CommandResultCode ShowPaths(NetworkContext context)
        {
            MachineProfile[] roots = context.Network.RootServers;
            if (roots.Length == 0) {
                Error.WriteLine("No root servers available on the network.");
                return CommandResultCode.ExecutionFailed;
            }

            context.Network.Refresh();

            // For each root server in the network,
            foreach (MachineProfile root in roots) {
                IServiceAddress rootService = root.Address;
                Out.Write("Root server: ");
                Out.WriteLine(rootService.ToString());
                Out.WriteLine();

                PathProfile[] paths = context.Network.GetPathsFromRoot(rootService);

                if (paths.Length == 0) {
                    Out.WriteLine("  [No paths on this root server]");
                    Out.WriteLine();
                } else {
                    ColumnDesign[] columns = new ColumnDesign[3];
                    columns[0] = new ColumnDesign("Name", ColumnAlignment.Right);
                    columns[1] = new ColumnDesign("Type", ColumnAlignment.Center);
                    columns[2] = new ColumnDesign("Status", ColumnAlignment.Center);

                    TableRenderer table = new TableRenderer(columns, Out);
                    foreach (PathProfile p in paths) {
                        ColumnValue[] row = new ColumnValue[3];
                        row[0] = new ColumnValue(p.Path);
                        row[1] = new ColumnValue(p.PathType);

                        try {
                            string stats = context.Network.GetPathStats(p.RootAddress, p.Path);
                            if (stats != null)
                                row[2] = new ColumnValue(stats);
                        } catch (NetworkAdminException e) {
                            row[2] = new ColumnValue("ERROR RETRIEVING");
                        }
                    }

                    table.CloseTable();
                }
            }

            return CommandResultCode.Success;
        }
コード例 #13
0
ファイル: ShowCommand.cs プロジェクト: ikvm/cloudb
        private void ShowNetwork(NetworkContext context)
        {
            MachineProfile[] profiles = context.Network.MachineProfiles;

            int managerCount = 0;
            int rootCount = 0;
            int blockCount = 0;

            ColumnDesign[] columns = new ColumnDesign[2];
            columns[0] = new ColumnDesign("MRB");
            columns[0].Width = 20;
            columns[1] = new ColumnDesign("Address");

            TableRenderer table = new TableRenderer(columns, Out);
            context.Network.Refresh();

            foreach (MachineProfile p in profiles) {
                if (p.HasError) {
                    ColumnValue[] row = new ColumnValue[2];
                    row[0] = new ColumnValue(p.ErrorState);
                    row[1] = new ColumnValue(p.Address.ToString());
                    table.AddRow(row);
                } else {
                    string mrb = String.Empty;
                    mrb += p.IsManager ? "M" : ".";
                    mrb += p.IsRoot ? "R" : ".";
                    mrb += p.IsBlock ? "B" : ".";

                    ColumnValue[] row = new ColumnValue[2];
                    row[0] = new ColumnValue(mrb);
                    row[1] = new ColumnValue(p.Address.ToString());
                    table.AddRow(row);

                    managerCount += p.IsManager ? 1 : 0;
                    rootCount += p.IsRoot ? 1 : 0;
                    blockCount += p.IsBlock ? 1 : 0;
                }
            }

            table.CloseTable();

            Out.WriteLine();
            if (profiles.Length == 1) {
                Out.WriteLine("one machine in the network.");
            } else {
                Out.WriteLine(profiles.Length + " machines in the network.");
            }

            if (managerCount == 0) {
                Out.Write("none manager");
            } else if (managerCount == 1) {
                Out.Write("one manager");
            } else {
                Out.Write(managerCount + " managers");
            }

            Out.Write(", ");

            if (rootCount == 0) {
                Out.Write("none root");
            } else if (rootCount == 1) {
                Out.Write("one root");
            } else {
                Out.Write(rootCount + " roots");
            }

            Out.Write(", ");

            if (blockCount == 0) {
                Out.Write("none block");
            } else if (blockCount == 1) {
                Out.Write("one block");
            } else {
                Out.Write(blockCount + " blocks");
            }

            Out.WriteLine();
        }
コード例 #14
0
ファイル: ShowCommand.cs プロジェクト: yuexiaoyun/cloudb
        private CommandResultCode ShowPaths(NetworkContext context)
        {
            MachineProfile[] roots = context.Network.GetRootServers();
            if (roots.Length == 0) {
                Out.WriteLine("No root servers available on the network.");
                return CommandResultCode.ExecutionFailed;
            }

            Out.Flush();
            context.Network.Refresh();

            // Get all paths from the manager cluster,
            String[] pathNames = context.Network.GetAllPathNames();

            int count = 0;
            foreach (string pathName in pathNames) {
                PathInfo pathInfo = context.Network.GetPathInfo(pathName);
                OutputPathInfo(context, pathInfo);
                Out.Flush();
                ++count;
            }

            Out.WriteLine();
            Out.WriteLine("Path Count: " + count);
            Out.Flush();

            return CommandResultCode.Success;
        }
コード例 #15
0
ファイル: ShowCommand.cs プロジェクト: yuexiaoyun/cloudb
        private void ShowFree(NetworkContext context)
        {
            // Refresh
            context.Network.Refresh();

            MachineProfile[] machines = context.Network.GetAllMachineProfiles();
            if (machines.Length == 0) {
                Out.WriteLine("No machines in the network.");
            } else {
                ColumnDesign[] columns = new ColumnDesign[4];
                columns[0] = new ColumnDesign("Machine");
                columns[1] = new ColumnDesign("Used Memory");
                columns[2] = new ColumnDesign("Used Disk");
                columns[3] = new ColumnDesign("Notes");

                TableRenderer table = new TableRenderer(columns, Out);

                foreach (var machine in machines) {
                    ColumnValue[] row = new ColumnValue[4];
                    if (machine.IsError) {
                        row[3] = new ColumnValue(" ERROR: " + machine.ErrorMessage);
                    } else {
                        row[0] = new ColumnValue(machine.ServiceAddress.ToString());
                        row[1] = new ColumnValue(MemoryReport(machine.MemoryUsed, machine.MemoryTotal));
                        row[2] = new ColumnValue(MemoryReport(machine.DiskUsed, machine.DiskTotal));
                        if (machine.DiskUsed > ((double) machine.DiskTotal*0.85d)) {
                            row[3] = new ColumnValue(" WARNING: Node is close to full - used storage within 85% of total");
                        }
                    }

                    table.AddRow(row);
                }

                table.CloseTable();
            }
        }
コード例 #16
0
ファイル: ShowCommand.cs プロジェクト: yuexiaoyun/cloudb
        private CommandResultCode ShowAnalytics(NetworkContext context)
        {
            context.Network.Refresh();

            MachineProfile[] profiles = context.Network.GetAllMachineProfiles();

            foreach (MachineProfile p in profiles) {
                Out.WriteLine(p.ServiceAddress.ToString());
                Out.Write("  ");
                if (p.IsError) {
                    Out.Write("Error: ");
                    Out.WriteLine(p.ErrorMessage);
                    return CommandResultCode.ExecutionFailed;
                }

                long[] stats = context.Network.GetAnalyticsStats(p.ServiceAddress);
                if (stats.Length < 4) {
                    Out.WriteLine("Sorry, no analytics available yet.");
                    return CommandResultCode.ExecutionFailed;
                }

                PrintStatItem(stats, 1);
                Out.Write(" ");
                PrintStatItem(stats, 5);
                Out.Write(" ");
                PrintStatItem(stats, 15);
                Out.WriteLine();

                Out.Flush();
            }

            Out.WriteLine();
            return CommandResultCode.Success;
        }
コード例 #17
0
ファイル: ShowCommand.cs プロジェクト: yuexiaoyun/cloudb
        private void OutputPathInfo(NetworkContext context, PathInfo p)
        {
            string pathName = p.PathName;

            Out.Write("+Name: ");
            Out.Write(pathName);
            Out.Write(" (");
            Out.Write(p.PathType);
            Out.WriteLine(")");

            Out.Write(" Srvs: ");
            IServiceAddress leader = p.RootLeader;
            IServiceAddress[] srvs = p.RootServers;
            foreach (IServiceAddress srv in srvs) {
                bool il = srv.Equals(leader);
                if (il)
                    Out.Write("[");
                Out.Write(srv.ToString());
                if (il)
                    Out.Write("*]");
                Out.Write(" ");
            }
            Out.WriteLine();

            Out.Write(" Status: ");
            try {
                String stats = context.Network.GetPathStats(p);
                if (stats != null) {
                    Out.Write(stats);
                }
            } catch (NetworkAdminException e) {
                Out.Write("Error retrieving stats: " + e.Message);
            }

            Out.WriteLine();
            Out.WriteLine();
        }