Exemplo n.º 1
0
        private static void handleInput(DataTypes.ConfigurationFileObject config, string[] command)
        {
            List <string> psCandidate   = null;
            List <string> nodeCandidate = null;

            switch (command[0].ToLower())
            {
            case "start":
                if (config.ConfigurationNodes.Where(i => i.NodeName.Equals(command[1])).Select(i => i.TargetData).First().Contains("."))
                {       //HACK: So that start other nodes does not do anything
                    psCandidate = config.getAddressesFromOPName(command[1]);
                    var res = psCandidate.First();
                    pcsServers[res].start(command[1]);
                }
                //foreach (var p in ps)
                //{
                //    pcsServers[p].start(command[1]);
                //}

                break;

            case "status":
                foreach (var pcss in pcsServers.Select(i => i.Value))
                {
                    pcss.status();
                }
                break;

            case "interval":
                Interval = Convert.ToInt32(command[2]);
                break;

            case "crash":
                psCandidate   = config.getAddressesFromOPName(command[1]);
                nodeCandidate = config.ConfigurationNodes.Where(i => i.NodeName == command[1]).SelectMany(n => n.Addresses).ToList();
                var toCrash = psCandidate[Convert.ToInt32(command[2])];
                pcsServers[toCrash].crash(nodeAddressMapping[nodeCandidate[Convert.ToInt32(command[2])]]);
                break;

            case "freeze":
                psCandidate   = config.getAddressesFromOPName(command[1]);
                nodeCandidate = config.ConfigurationNodes.Where(i => i.NodeName == command[1]).SelectMany(n => n.Addresses).ToList();
                var toFreeze = psCandidate[Convert.ToInt32(command[2])];
                pcsServers[toFreeze].freeze(nodeAddressMapping[nodeCandidate[Convert.ToInt32(command[2])]]);
                break;

            case "unfreeze":
                psCandidate   = config.getAddressesFromOPName(command[1]);
                nodeCandidate = config.ConfigurationNodes.Where(i => i.NodeName == command[1]).SelectMany(n => n.Addresses).ToList();
                var toThaw = psCandidate[Convert.ToInt32(command[2])];
                pcsServers[toThaw].unfreeze(nodeAddressMapping[nodeCandidate[Convert.ToInt32(command[2])]]);
                break;

            case "wait":
                Thread.Sleep(Convert.ToInt32(command[1]));
                break;

            default:
                Console.WriteLine("Invalid command");
                break;
            }
            Thread.Sleep(Interval);
        }