using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using XSockets.Client; using XSockets.Core.Common.Socket.Event.Interface; using MySql.Data.MySqlClient; using System.Diagnostics; using Toolbox; namespace H_Man { class Program { static void Main(string[] args) { try { string command = string.Empty; if (args.Length > 0) { command = args[0]; } DatabaseManager dbManager = new DatabaseManager(true); DecisionMaker decisionMaker = new DecisionMaker (); //HostManager hostManager = new HostManager(); //HostManager hostManager = new HostManager(decisionMaker); HostManager hostManager = new HostManager(dbManager, decisionMaker); // This is required to save XenMon log files into DB //ResourceHandler.DBManager = dbManager; Credit2Scheduler scheduler = new Credit2Scheduler(); // Step Xen: Set scheduler parameters // - to the values for test if (command == "reset") { ResourceHandler.ReadAllVMs(); scheduler.ResetParameters(); Logger.Log("Reseted scheduler parameters to their defaults"); } // Step Xen: Set scheduler parameters // - to the values for test if (command == "report") { string subCommand = args[1]; if (subCommand == "waitingtime") { if (hostManager.IsHostReadyToMonitor) { Logger.Log("Reported waiting time. Please back up hosthistory.log!"); //ResourceHandler.TotalHostWaitingTime(); ResourceHandler.ReportWaitingTime(); } } } // Step Xen: Load certain scheduler parameters // - to the values for test if (command == "load") { if (hostManager.IsHostReadyToMonitor) { ResourceHandler.ReadAllVMs(); hostManager.LoadConfig(int.Parse(args[1])); Logger.Log("Loaded scheduler parameters for cluster number specified"); } } // Step Xen: Set scheduler parameters // - to the values for test if (command == "set") { ResourceHandler.ReadAllVMs(); scheduler.SetParameters(int.Parse(args[1]), int.Parse(args[2]), int.Parse(args[3]), int.Parse(args[4])); Logger.Log("Set scheduler parameters"); } // Step Log: Start Xenmon for logging // - Run XenMon for a while // - Stop XenMon if (command == "runxenmon") { hostManager.DeleteXenMonLogFiles(); hostManager.StartXenMon(); Console.WriteLine("Logging internal scheduler metrics for a minute..."); Thread.Sleep(int.Parse(args[1]) * 1000); hostManager.StopXenMon(); } // Step 1 : Cluster Host Machines (Offline) // - Monitor Resource Usage // - Save it into Database if (command == "discoverer") { hostManager.StartHandling (); Console.WriteLine("Press enter to exit stop H-Man"); Console.ReadLine(); hostManager.StopHandling (); } // Step 2 : Find Optimum Configuration of Xen Credit Scheduler2 (Offline) // - Set up host machine compliant with the center of cluster // - Employ simulated annealing if (command == "optimizer") { hostManager.FindClusterOptimumConfigurations (); } // Step 3 : Load Scheduler Configuration at run-time (Online) // - Monitor host machine resource usage // - Classify host machine // - Load the configuration if (command == "observer") { hostManager.IsClassificationEnabled = true; hostManager.StartHandling (); Console.WriteLine("Press enter to exit stop H-Man"); Console.ReadLine(); hostManager.StopHandling (); } } catch (Exception exc) { Logger.Log(exc); } } } }