- Timestamp:
- 06/25/15 18:21:19 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Status/3.3/WebApi/DataController.cs
r12467 r12515 27 27 using HeuristicLab.Services.Hive; 28 28 using HeuristicLab.Services.Hive.DataAccess; 29 using DAL = HeuristicLab.Services.Hive.DataAccess; 30 using DTO = HeuristicLab.Services.WebApp.Status.WebApi.DataTransfer; 29 using HeuristicLab.Services.Hive.DataAccess.Interfaces; 30 using DA = HeuristicLab.Services.Hive.DataAccess; 31 using DT = HeuristicLab.Services.WebApp.Status.WebApi.DataTransfer; 31 32 32 33 namespace HeuristicLab.Services.WebApp.Status.WebApi { 33 34 public class DataController : ApiController { 35 private IPersistenceManager PersistenceManager { 36 get { return ServiceLocator.Instance.PersistenceManager; } 37 } 34 38 35 39 // start temporary quickfix … … 53 57 } 54 58 55 public IEnumerable<DT O.TaskStatus> GetTaskStatus(HiveDataContext db) {59 public IEnumerable<DT.TaskStatus> GetTaskStatus(HiveDataContext db) { 56 60 var query = db.ExecuteQuery<UserTaskStatus>(SQL_USER_TASK_STATUS).ToList(); 57 return query.Select(uts => new DT O.TaskStatus {58 User = new DT O.User {61 return query.Select(uts => new DT.TaskStatus { 62 User = new DT.User { 59 63 Id = uts.UserId.ToString(), 60 64 Name = ServiceLocator.Instance.UserManager.GetUserById(uts.UserId).UserName … … 66 70 // end temporary quickfix 67 71 68 public DTO.Status GetStatus() { 72 public DT.Status GetStatus() { 73 DT.TimeStatus timeStatus = null; 74 using (var pm = PersistenceManager) { 75 76 // TODO: 77 // new DT.TimeStatus { 78 // AvgCalculatingTime = 0, 79 // AvgWaitingTime = 0, 80 // MaxCalculatingTime = 0, 81 // MinCalculatingTime = 0, 82 // TotalCpuTime = 0, 83 // BeginDate = DateTime.Now 84 //} 85 } 86 69 87 using (var db = new HiveDataContext()) { 70 var onlineSlaves = (from slave in db.Resources.OfType<DA L.Slave>()88 var onlineSlaves = (from slave in db.Resources.OfType<DA.Slave>() 71 89 where slave.SlaveState == SlaveState.Calculating || slave.SlaveState == SlaveState.Idle 72 90 select slave).ToList(); … … 76 94 int freeCalculatingMemory = calculatingSlaves.Any() ? (int)calculatingSlaves.Sum(s => s.FreeMemory) / 1024 : 0; 77 95 78 return new DT O.Status {79 CoreStatus = new DT O.CoreStatus {96 return new DT.Status { 97 CoreStatus = new DT.CoreStatus { 80 98 TotalCores = onlineSlaves.Sum(s => s.Cores ?? 0), 81 99 FreeCores = onlineSlaves.Sum(s => s.FreeCores ?? 0), // temporary for old chart data 82 100 ActiveCores = activeSlaves.Sum(s => s.Cores ?? 0), 83 CalculatingCores = calculatingSlaves.Sum(s => s.Cores ?? 0) 101 CalculatingCores = calculatingSlaves.Sum(s => s.Cores ?? 0) - calculatingSlaves.Sum(s => s.FreeCores ?? 0) 84 102 }, 85 CpuUtilizationStatus = new DT O.CpuUtilizationStatus {103 CpuUtilizationStatus = new DT.CpuUtilizationStatus { 86 104 TotalCpuUtilization = onlineSlaves.Any() 87 105 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2) … … 94 112 : 0.0 95 113 }, 96 MemoryStatus = new DT O.MemoryStatus {114 MemoryStatus = new DT.MemoryStatus { 97 115 TotalMemory = onlineSlaves.Any() ? (int)onlineSlaves.Sum(s => s.Memory) / 1024 : 0, 98 116 FreeMemory = onlineSlaves.Any() ? (int)onlineSlaves.Sum(s => s.FreeMemory) / 1024 : 0, … … 100 118 UsedMemory = calculatingMemory - freeCalculatingMemory 101 119 }, 120 TimeStatus = timeStatus, 102 121 TasksStatus = GetTaskStatus(db), 103 SlavesStatus = onlineSlaves.Select(x => new DT O.SlaveStatus {104 Slave = new DT O.Slave {122 SlavesStatus = onlineSlaves.Select(x => new DT.SlaveStatus { 123 Slave = new DT.Slave { 105 124 Id = x.ResourceId.ToString(), 106 125 Name = x.Name … … 119 138 } 120 139 121 public IEnumerable<DT O.Status> GetStatusHistory(DateTime start, DateTime end) {140 public IEnumerable<DT.Status> GetStatusHistory(DateTime start, DateTime end) { 122 141 TimeSpan ts = end - start; 123 142 int increment = 1; … … 135 154 .OrderBy(s => s.Timestamp) 136 155 .ToList(); 137 var status = new DT O.Status {138 CoreStatus = new DT O.CoreStatus(),139 CpuUtilizationStatus = new DT O.CpuUtilizationStatus(),140 MemoryStatus = new DT O.MemoryStatus()156 var status = new DT.Status { 157 CoreStatus = new DT.CoreStatus(), 158 CpuUtilizationStatus = new DT.CpuUtilizationStatus(), 159 MemoryStatus = new DT.MemoryStatus() 141 160 }; 142 161 int freeCores = 0; … … 165 184 status.MemoryStatus.UsedMemory = status.MemoryStatus.TotalMemory - freeMemory; 166 185 yield return status; 167 status = new DT O.Status {168 CoreStatus = new DT O.CoreStatus(),169 CpuUtilizationStatus = new DT O.CpuUtilizationStatus(),170 MemoryStatus = new DT O.MemoryStatus()186 status = new DT.Status { 187 CoreStatus = new DT.CoreStatus(), 188 CpuUtilizationStatus = new DT.CpuUtilizationStatus(), 189 MemoryStatus = new DT.MemoryStatus() 171 190 }; 172 191 freeCores = 0;
Note: See TracChangeset
for help on using the changeset viewer.