Exemplo n.º 1
0
        /// <summary>
        /// Checks agent queue and decides, if we need to provision or not
        /// </summary>
        /// <param name="areWeCheckingToStartVm">describes function which called us</param>
        public static void AgentsQueue(bool areWeCheckingToStartVm)
        {
            var maxAgentsCount = DataRetriever.GetAllAccessibleAgents(Properties.AgentsPoolId);

            if (maxAgentsCount == 0)
            {
                Console.WriteLine($"There is 0 agents assigned to pool with id {Properties.AgentsPoolId}. Could not proceed, exiting...");
                LeaveTheBuilding.Exit(DataRetriever);
            }

            var onlineAgentsCount = 0;
            var countNullable     = DataRetriever.GetOnlineAgentsCount(Properties.AgentsPoolId);

            if (countNullable == null)
            {
                //something went wrong
                Console.WriteLine("Could not retrieve amount of agents online, exiting...");
                LeaveTheBuilding.Exit(DataRetriever);
            }
            else
            {
                onlineAgentsCount = countNullable.Value;
            }

            var waitingJobsCount = DataRetriever.GetCurrentJobsRunningCount(Properties.AgentsPoolId);

            if (waitingJobsCount == onlineAgentsCount && !new DynamicProps().WeAreInsideBusinessTime)
            {
                //nothing to do here
                return;
            }

            Operations.WorkWithVmss(onlineAgentsCount, maxAgentsCount, areWeCheckingToStartVm);
        }
Exemplo n.º 2
0
        private static IVirtualMachineScaleSet GetVirtualMachinesScaleSet(string rgName,
                                                                          string virtualMachinesScaleSetName)
        {
            var credentials = AzureCreds();

            var azure = Azure
                        .Configure()
                        .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                        .Authenticate(credentials)
                        .WithSubscription(ConfigurationManager.AppSettings[Constants.AzureSubscriptionIdSettingName]);
            var virtualMachineScaleSet = azure.VirtualMachineScaleSets.GetByResourceGroup(rgName, virtualMachinesScaleSetName);

            if (virtualMachineScaleSet != null)
            {
                return(virtualMachineScaleSet);
            }
            Console.WriteLine($"Could not retrieve Virtual Machines Scale Set with name {virtualMachinesScaleSetName} in resource group {rgName}. Exiting...");
            LeaveTheBuilding.Exit(Checker.DataRetriever);

            return(null);
        }