using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Services.Hive; using DA = HeuristicLab.Services.Hive.DataAccess; using DT = HeuristicLab.Services.Hive.DataTransfer; namespace HeuristicLab.Services.Optimization.Scaler.Hive { public static class HiveHelper { public static double GetGlobalUsage() { // from Status.aspx.cs of HeuristicLab.Services.Hive.WebRole var dao = ServiceLocator.Instance.HiveDao; var transactionManager = ServiceLocator.Instance.TransactionManager; IEnumerable onlineSlaves = new List(); IEnumerable resourceIds = new List(); transactionManager.UseTransaction(() => { resourceIds = dao.GetResources(x => true).Select(y => y.Id); }, false, false); transactionManager.UseTransaction(() => { onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId)); }, false, false); return onlineSlaves.Count() > 0 ? onlineSlaves.Average(s => s.CpuUtilization) : 0.0d; } } }