Пример #1
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;
            }
        }
Пример #2
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);
            }
        }