/// <summary>Get the list of virtual machines, based on the precondition check on the schedule table and activity table. /// here precondion ==> get the virtual machines from the crawler which are not in the recent scheduled list and not in the recent activities.</summary> /// <param name="scaleSetId">scale set id to filter the virtual machines.</param> /// <returns></returns> private IList <VirtualMachineCrawlerResponse> GetVirtualMachineSet(string loadBalancerId) { var rowKey = loadBalancerId.Replace(Delimeters.ForwardSlash, Delimeters.Exclamatory); var groupNameFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, rowKey); var resultsSet = ResourceFilterHelper.QueryCrawlerResponseByMeanTime <VirtualMachineCrawlerResponse>(_azureClient.AzureSettings, StorageTableNames.VirtualMachineCrawlerTableName, groupNameFilter); resultsSet = resultsSet.Where(x => PowerState.Parse(x.State) == PowerState.Running).ToList(); if (resultsSet == null || !resultsSet.Any()) { return(null); } // TODO combine the schedule and activity table var scheduleEntities = ResourceFilterHelper.QuerySchedulesByMeanTime <ScheduledRules>( _azureClient.AzureSettings, StorageTableNames.ScheduledRulesTableName); var scheduleEntitiesResourceIds = scheduleEntities == null || !scheduleEntities.Any() ? new List <string>() : scheduleEntities.Select(x => x.RowKey.Replace(Delimeters.Exclamatory, Delimeters.ForwardSlash)); var result = resultsSet.Where(x => !scheduleEntitiesResourceIds.Contains(x.Id)); return(result.ToList()); }
/// <summary>Get the list of virtual machines, based on the preconditioncheck on the schedule table and activity table. /// here precondion ==> get the virtual machines from the crawler which are not in the recent scheduled list and not in the recent activities.</summary> /// <returns></returns> private IList <VirtualMachineCrawlerResponse> GetRandomVmSet() { //To remove the virtual machines which are recently executed. var executedResultsSet = new List <VirtualMachineCrawlerResponse>(); var groupNameFilter = TableQuery.GenerateFilterCondition("VirtualMachineGroup", QueryComparisons.Equal, VirtualMachineGroup.VirtualMachines.ToString()); var resultsSet = ResourceFilterHelper.QueryCrawlerResponseByMeanTime <VirtualMachineCrawlerResponse>( azureClient.AzureSettings, StorageTableNames.VirtualMachineCrawlerTableName, groupNameFilter); resultsSet = resultsSet.Where(x => PowerState.Parse(x.State) == PowerState.Running).ToList(); if (!resultsSet.Any()) { return(null); } var scheduleEntities = ResourceFilterHelper.QuerySchedulesByMeanTime <ScheduledRules>(azureClient.AzureSettings, StorageTableNames.ScheduledRulesTableName); var scheduleEntitiesResourceIds = scheduleEntities == null || !scheduleEntities.Any() ? new List <string>() : scheduleEntities.Select(x => x.RowKey.Replace(Delimeters.Exclamatory, Delimeters.ForwardSlash)); if (scheduleEntitiesResourceIds.Count() != 0) { foreach (var result in resultsSet) { foreach (var Id in scheduleEntitiesResourceIds) { if ((Id.Contains(result.ResourceGroupName)) && (Id.Contains(result.ResourceName))) { executedResultsSet.Add(result); break; } } } //List<VirtualMachineCrawlerResponse> resultsSets = resultsSet.Where(x => (scheduleEntitiesResourceIds.Contains(x.ResourceGroupName) && scheduleEntitiesResourceIds.Contains(x.ResourceName))).ToList(); return(resultsSet = resultsSet.Except(executedResultsSet).ToList()); } else { return(resultsSet.ToList()); } }
/// <summary>Get the list of virtual machines, based on the preconditioncheck on the schedule table and activity table. /// here precondion ==> get the virtual machines from the crawler which are not in the recent scheduled list and not in the recent activities.</summary> /// <returns></returns> private IList <VirtualMachineCrawlerResponse> GetRandomVmSet() { var groupNameFilter = TableQuery.GenerateFilterCondition("VirtualMachineGroup", QueryComparisons.Equal, VirtualMachineGroup.VirtualMachines.ToString()); var resultsSet = ResourceFilterHelper.QueryCrawlerResponseByMeanTime <VirtualMachineCrawlerResponse>( azureClient.AzureSettings, StorageTableNames.VirtualMachineCrawlerTableName, groupNameFilter); resultsSet = resultsSet.Where(x => PowerState.Parse(x.State) == PowerState.Running).ToList(); if (!resultsSet.Any()) { return(null); } var scheduleEntities = ResourceFilterHelper.QuerySchedulesByMeanTime <ScheduledRules>(azureClient.AzureSettings, StorageTableNames.ScheduledRulesTableName); var scheduleEntitiesResourceIds = scheduleEntities == null || !scheduleEntities.Any() ? new List <string>() : scheduleEntities.Select(x => x.RowKey.Replace(Delimeters.Exclamatory, Delimeters.ForwardSlash)); var result = resultsSet.Where(x => !scheduleEntitiesResourceIds.Contains(x.Id)); return(result.ToList()); }