Ejemplo n.º 1
0
        private static List <DTOs.Result <DTOs.BatchSet> > GetSourceBatches(IRSAPIClient proxy)
        {
            DTOs.Query <DTOs.BatchSet> query = new DTOs.Query <DTOs.BatchSet>();
            query.Fields = DTOs.FieldValue.AllFields;

            DTOs.QueryResultSet <DTOs.BatchSet> resultSet = new DTOs.QueryResultSet <DTOs.BatchSet>();
            try
            {
                resultSet = proxy.Repositories.BatchSet.Query(query, 0);
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception when querying for batches: {message}", ex);
                return(null);
            }

            if (resultSet.Success)
            {
                if (resultSet.Results.Count > 0)
                {
                    _logger.LogInformation("{0} batch sets found in {1}", resultSet.Results.Count, proxy.APIOptions.WorkspaceID);
                    return(resultSet.Results);
                }
                else
                {
                    _logger.LogWarning("Query was successful but no batches exist.");
                    return(null);
                }
            }
            else
            {
                _logger.LogError("Unsuccessful query for batches: {message}", resultSet.Results[0].Message);
                return(null);
            }
        }
        public void Run()
        {
            int  counter;
            bool outOfServers = false;

            //while there are rows in the agent desired list and we have not run out of servers
            while (_agentsDesired.Count > 0 && outOfServers == false)
            {
                _logger.LogDebug(string.Format("{0} AgentsDesiredObjects desired", _agentsDesired.Count));
                //Create index counter for _agentsDesired
                counter = _agentsDesired.Count() - 1;

                //before counter gets to negative index range
                while (counter >= 0)
                {
                    //Are there any agents to be created for this object?
                    if (_agentsDesired[counter].Count > 0)
                    {
                        //Are there any servers available?
                        if (_spotsPerServer.Count > 0)
                        {
                            //Order the agent servers by spots descending, and then select first object
                            _spotsPerServer = _spotsPerServer.OrderByDescending(x => x.Spots).ToList();
                            if (_spotsPerServer[0].Spots > 0)
                            {
                                _createAgent.Create(_agentsDesired[counter].Guid, _spotsPerServer[0].AgentServerArtifactId);

                                _spotsPerServer[0].Spots      -= 1;
                                _agentsDesired[counter].Count -= 1;

                                if (_agentsDesired[counter].Count < 1)
                                {
                                    _agentsDesired.Remove(_agentsDesired[counter]);
                                }

                                if (_spotsPerServer[0].Spots < 1)
                                {
                                    _spotsPerServer.Remove(_spotsPerServer[0]);
                                }
                            }
                            else
                            {
                                _spotsPerServer.Remove(_spotsPerServer[0]);
                            }
                        }
                        else
                        {
                            //Out of servers!
                            _logger.LogWarning("We've run out of spots! {count} remaining AgentsDesiredObjects", _agentsDesired.Count);
                            outOfServers = true;
                            break;
                        }
                    }
                    else
                    {
                        _agentsDesired.Remove(_agentsDesired[0]);
                    }
                    counter -= 1;
                }
            }
        }