示例#1
0
        /// <summary>
        /// construct a new Computer object
        /// </summary>
        /// <param name="n">the unique name of the daemon</param>
        /// <param name="host">the computer the daemon is running on</param>
        /// <param name="rn">the rack the daemon is running on</param>
        /// <param name="rack">the scheduling queue associated with the computer's rack</param>
        /// <param name="cluster">the global scheduling queue associated with the cluster</param>
        /// <param name="pServer">the address of the daemon's http server for process scheduling</param>
        /// <param name="fServer">the address of the daemon's http server for file proxying</param>
        /// <param name="directory">the daemon's local directory</param>
        /// <param name="log">connection to the logging subsystem</param>
        public Computer(string n, string host, string rn, ProcessQueue rack, ProcessQueue cluster,
                        string pServer, string fServer, string directory, ClusterInterface.ILogger log)
        {
            logger         = log;
            name           = n;
            localDirectory = directory;
            processServer  = pServer;
            fileServer     = fServer;
            computerName   = host;
            rackName       = rn;
            localQueue     = new ProcessQueue();
            rackQueue      = rack;
            clusterQueue   = cluster;

            logger.Log("Created computer " + name + " on host " + computerName + ":" + rackName + ":" + localDirectory + ":" + fileServer);

            // make the Task that CommandLoop blocks on; when finishWaiter is started it returns null
            // causing CommandLoop to exit.
            finishWaiter       = new TaskCompletionSource <Process>();
            childFinishWaiters = new HashSet <TaskCompletionSource <Process> >();
            finishWaiter.Task.ContinueWith((t) => Task.Run(() => SetChildFinishWaiters()));

            // this is started when the Command Loop exits
            exited = new TaskCompletionSource <bool>();

            nextTask = 1;
        }
示例#2
0
        public LocalScheduler(ClusterInterface.ILogger l)
        {
            logger = l;

            computers = new Dictionary<string, Computer>();
            localities = new Dictionary<string, List<Computer>>();
            racks = new Dictionary<string, Rack>();
            clusterQueue = new ProcessQueue();

            flusher = new Task(() => { });

            clusterInterface = new PeloponneseInterface();

            dummyCancelComputer = new Computer("dummy for canceling", "nowhere", "no rack", null, null,
                                               "no server", "no server", "no directory", logger);

            l.Log("LocalScheduler created");
        }
示例#3
0
        public LocalScheduler(ClusterInterface.ILogger l)
        {
            logger = l;

            computers    = new Dictionary <string, Computer>();
            localities   = new Dictionary <string, List <Computer> >();
            racks        = new Dictionary <string, Rack>();
            clusterQueue = new ProcessQueue();

            flusher = new Task(() => { });

            clusterInterface = new PeloponneseInterface();

            dummyCancelComputer = new Computer("dummy for canceling", "nowhere", "no rack", null, null,
                                               "no server", "no server", "no directory", logger);

            l.Log("LocalScheduler created");
        }
        public bool Initialize(LocalScheduler p, ClusterInterface.ILogger l)
        {
            parent = p;
            logger = l;
            epoch = 0;
            version = 0;
            targetNumberOfWorkers = -1;
            knownWorkers = new Dictionary<string, string>();
            reasonableReached = new TaskCompletionSource<bool>();
            shutdownTask = new TaskCompletionSource<XContainer>();
            waitingForComputer = new List<Task>();
            exited = new TaskCompletionSource<bool>();

            jobGuid = Environment.GetEnvironmentVariable(Constants.EnvJobGuid);
            if (jobGuid == null)
            {
                logger.Log("Can't find environment variable " + Constants.EnvJobGuid + ": exiting");
                return false;
            }

            serverAddress = Environment.GetEnvironmentVariable(Constants.EnvManagerServerUri);
            if (serverAddress == null)
            {
                logger.Log("Can't find environment variable " + Constants.EnvManagerServerUri + ": exiting");
                return false;
            }

            var groupName = Environment.GetEnvironmentVariable(Constants.EnvProcessGroup);
            if (groupName == null)
            {
                logger.Log("Can't find environment variable " + Constants.EnvProcessGroup + ": exiting");
                return false;
            }

            var procIdentifier = Environment.GetEnvironmentVariable(Constants.EnvProcessIdentifier);
            if (procIdentifier == null)
            {
                logger.Log("Can't find environment variable " + Constants.EnvProcessIdentifier + ": exiting");
                return false;
            }

            var element = new XElement("ProcessDetails");
            var status = element.ToString();

            string registration = String.Format("{0}register?guid={1}&group={2}&identifier={3}", serverAddress, jobGuid, groupName, procIdentifier);
            IHttpRequest request = ClusterInterface.HttpClient.Create(registration);
            request.Timeout = 30 * 1000; // if this doesn't come back quickly, we'll get an exception and quit
            request.Method = "POST";

            try
            {
                using (Stream upload = request.GetRequestStream())
                {
                    using (StreamWriter sw = new StreamWriter(upload))
                    {
                        sw.Write(status);
                    }
                }

                using (IHttpResponse response = request.GetResponse())
                {
                    logger.Log("Server registration succeeded");
                    return true;
                }
            }
            catch (NotHttpException e)
            {
                // if this failed, there's nothing much more we can do
                logger.Log("Server registration failed message " + e.Message + " status " + e.Response.StatusCode + ": " + e.Response.StatusDescription);
                return false;
            }
            catch (Exception e)
            {
                // if this failed, there's nothing much more we can do
                logger.Log("Server registration failed message " + e.Message);
                return false;
            }
        }
示例#5
0
 private static LocalScheduler Create(ClusterInterface.ILogger logger)
 {
     return(new LocalScheduler(logger));
 }
示例#6
0
        public bool Initialize(LocalScheduler p, ClusterInterface.ILogger l)
        {
            parent  = p;
            logger  = l;
            epoch   = 0;
            version = 0;
            targetNumberOfWorkers = -1;
            knownWorkers          = new Dictionary <string, string>();
            reasonableReached     = new TaskCompletionSource <bool>();
            shutdownTask          = new TaskCompletionSource <XContainer>();
            waitingForComputer    = new List <Task>();
            exited = new TaskCompletionSource <bool>();

            jobGuid = Environment.GetEnvironmentVariable(Constants.EnvJobGuid);
            if (jobGuid == null)
            {
                logger.Log("Can't find environment variable " + Constants.EnvJobGuid + ": exiting");
                return(false);
            }

            serverAddress = Environment.GetEnvironmentVariable(Constants.EnvManagerServerUri);
            if (serverAddress == null)
            {
                logger.Log("Can't find environment variable " + Constants.EnvManagerServerUri + ": exiting");
                return(false);
            }

            var groupName = Environment.GetEnvironmentVariable(Constants.EnvProcessGroup);

            if (groupName == null)
            {
                logger.Log("Can't find environment variable " + Constants.EnvProcessGroup + ": exiting");
                return(false);
            }

            var procIdentifier = Environment.GetEnvironmentVariable(Constants.EnvProcessIdentifier);

            if (procIdentifier == null)
            {
                logger.Log("Can't find environment variable " + Constants.EnvProcessIdentifier + ": exiting");
                return(false);
            }

            var element = new XElement("ProcessDetails");
            var status  = element.ToString();

            string       registration = String.Format("{0}register?guid={1}&group={2}&identifier={3}", serverAddress, jobGuid, groupName, procIdentifier);
            IHttpRequest request      = ClusterInterface.HttpClient.Create(registration);

            request.Timeout = 30 * 1000; // if this doesn't come back quickly, we'll get an exception and quit
            request.Method  = "POST";

            try
            {
                using (Stream upload = request.GetRequestStream())
                {
                    using (StreamWriter sw = new StreamWriter(upload))
                    {
                        sw.Write(status);
                    }
                }

                using (IHttpResponse response = request.GetResponse())
                {
                    logger.Log("Server registration succeeded");
                    return(true);
                }
            }
            catch (NotHttpException e)
            {
                // if this failed, there's nothing much more we can do
                logger.Log("Server registration failed message " + e.Message + " status " + e.Response.StatusCode + ": " + e.Response.StatusDescription);
                return(false);
            }
            catch (Exception e)
            {
                // if this failed, there's nothing much more we can do
                logger.Log("Server registration failed message " + e.Message);
                return(false);
            }
        }