- Timestamp:
- 08/13/15 15:22:51 (9 years ago)
- Location:
- branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/ClientController.cs
r12776 r12858 38 38 39 39 public DT.ClientDetails GetClientDetails(Guid id) { 40 using (var pm = PersistenceManager) { 41 var dimClientDao = pm.DimClientDao; 42 var factClientInfoDao = pm.FactClientInfoDao; 43 var factTaskDao = pm.FactTaskDao; 44 return pm.UseTransaction(() => { 45 var timeData = factClientInfoDao.GetByClientId(id) 46 .GroupBy(x => x.ClientId) 47 .Select(x => new { 48 TotalIdleTime = x.Sum(y => y.IdleTime), 49 TotalOfflineTime = x.Sum(y => y.OfflineTime), 50 TotalUnavailableTime = x.Sum(y => y.UnavailableTime) 51 }).FirstOrDefault(); 52 var taskTimeData = factTaskDao.GetByClientId(id) 53 .GroupBy(x => x.LastClientId) 54 .Select(x => new { 55 TotalCalculatingTime = x.Sum(y => y.CalculatingTime), 56 TotalTransferringTime = x.Sum(y => y.TransferTime) 57 }).FirstOrDefault(); 58 var startDate = factClientInfoDao.GetByClientId(id) 59 .Where(x => x.SlaveState == SlaveState.Offline) 40 var pm = PersistenceManager; 41 var dimClientDao = pm.DimClientDao; 42 var factClientInfoDao = pm.FactClientInfoDao; 43 var factTaskDao = pm.FactTaskDao; 44 return pm.UseTransaction(() => { 45 var timeData = factClientInfoDao.GetByClientId(id) 46 .GroupBy(x => x.ClientId) 47 .Select(x => new { 48 TotalIdleTime = x.Sum(y => y.IdleTime), 49 TotalOfflineTime = x.Sum(y => y.OfflineTime), 50 TotalUnavailableTime = x.Sum(y => y.UnavailableTime) 51 }).FirstOrDefault(); 52 var taskTimeData = factTaskDao.GetByClientId(id) 53 .GroupBy(x => x.LastClientId) 54 .Select(x => new { 55 TotalCalculatingTime = x.Sum(y => y.CalculatingTime), 56 TotalTransferringTime = x.Sum(y => y.TransferTime) 57 }).FirstOrDefault(); 58 var startDate = factClientInfoDao.GetByClientId(id) 59 .Where(x => x.SlaveState == SlaveState.Offline) 60 .OrderByDescending(x => x.Time) 61 .Select(x => x.Time).FirstOrDefault(); 62 long upTime = 0; 63 if (startDate == default(DateTime)) { 64 startDate = factClientInfoDao.GetByClientId(id) 60 65 .OrderByDescending(x => x.Time) 61 .Select(x => x.Time).FirstOrDefault(); 62 long upTime = 0; 63 if (startDate == default(DateTime)) { 64 startDate = factClientInfoDao.GetByClientId(id) 65 .OrderByDescending(x => x.Time) 66 .Select(x => x.Time) 67 .FirstOrDefault(); 68 } 69 if (startDate != default(DateTime)) { 70 upTime = (long)(DateTime.Now - startDate).TotalSeconds; 71 } 72 return (from client in dimClientDao.GetAll().Where(x => x.Id == id) 73 join info in factClientInfoDao.GetAll() 74 on client.Id equals info.ClientId into clientInfoJoin 75 from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1) 76 let offline = (client.ExpirationTime != null || clientInfo.SlaveState == SlaveState.Offline) 77 select new DT.ClientDetails { 78 Id = client.Id, 79 Name = client.Name, 80 TotalCores = clientInfo.NumTotalCores, 81 UsedCores = offline ? 0 : clientInfo.NumUsedCores, 82 TotalMemory = clientInfo.TotalMemory, 83 UsedMemory = offline ? 0 : clientInfo.UsedMemory, 84 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 85 State = offline ? SlaveState.Offline.ToString() : clientInfo.SlaveState.ToString(), 86 LastUpdate = clientInfo.Time, 87 GroupId = client.ResourceGroupId, 88 GroupName = client.GroupName, 89 UpTime = offline ? 0 : upTime, 90 TotalUnavailableTime = timeData != null ? timeData.TotalUnavailableTime : 0, 91 TotalCalculatingTime = taskTimeData != null ? taskTimeData.TotalCalculatingTime : 0, 92 TotalIdleTime = timeData != null ? timeData.TotalIdleTime : 0, 93 TotalOfflineTime = timeData != null ? timeData.TotalOfflineTime : 0, 94 TotalTransferringTime = taskTimeData != null ? taskTimeData.TotalTransferringTime : 0, 95 TasksStates = factTaskDao.GetByClientId(id) 96 .GroupBy(x => x.TaskState) 97 .Select(x => new DT.TaskStateCount { 98 State = x.Key.ToString(), 99 Count = x.Count() 100 }).ToList(), 101 Users = factTaskDao.GetAll() 102 .Where(x => x.LastClientId == id) 103 .Select(x => new DT.User { 104 Id = x.DimJob.UserId, 105 Name = x.DimJob.UserName 106 }) 107 .Distinct() 108 .ToList() 109 }) 110 .FirstOrDefault(); 111 }); 112 } 66 .Select(x => x.Time) 67 .FirstOrDefault(); 68 } 69 if (startDate != default(DateTime)) { 70 upTime = (long)(DateTime.Now - startDate).TotalSeconds; 71 } 72 return (from client in dimClientDao.GetAll().Where(x => x.Id == id) 73 join info in factClientInfoDao.GetAll() 74 on client.Id equals info.ClientId into clientInfoJoin 75 from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1) 76 let offline = (client.ExpirationTime != null || clientInfo.SlaveState == SlaveState.Offline) 77 select new DT.ClientDetails { 78 Id = client.Id, 79 Name = client.Name, 80 TotalCores = clientInfo.NumTotalCores, 81 UsedCores = offline ? 0 : clientInfo.NumUsedCores, 82 TotalMemory = clientInfo.TotalMemory, 83 UsedMemory = offline ? 0 : clientInfo.UsedMemory, 84 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 85 State = offline ? SlaveState.Offline.ToString() : clientInfo.SlaveState.ToString(), 86 LastUpdate = clientInfo.Time, 87 GroupId = client.ResourceGroupId, 88 GroupName = client.GroupName, 89 UpTime = offline ? 0 : upTime, 90 TotalUnavailableTime = timeData != null ? timeData.TotalUnavailableTime : 0, 91 TotalCalculatingTime = taskTimeData != null ? taskTimeData.TotalCalculatingTime : 0, 92 TotalIdleTime = timeData != null ? timeData.TotalIdleTime : 0, 93 TotalOfflineTime = timeData != null ? timeData.TotalOfflineTime : 0, 94 TotalTransferringTime = taskTimeData != null ? taskTimeData.TotalTransferringTime : 0, 95 TasksStates = factTaskDao.GetByClientId(id) 96 .GroupBy(x => x.TaskState) 97 .Select(x => new DT.TaskStateCount { 98 State = x.Key.ToString(), 99 Count = x.Count() 100 }).ToList(), 101 Users = factTaskDao.GetAll() 102 .Where(x => x.LastClientId == id) 103 .Select(x => new DT.User { 104 Id = x.DimJob.UserId, 105 Name = x.DimJob.UserName 106 }) 107 .Distinct() 108 .ToList() 109 }) 110 .FirstOrDefault(); 111 }); 113 112 } 114 113 115 114 public DT.ClientPage GetClients(int page, int size, bool expired = false) { 116 using (var pm = PersistenceManager) { 117 var dimClientDao = pm.DimClientDao; 118 var factClientInfoDao = pm.FactClientInfoDao; 119 return pm.UseTransaction(() => { 120 var clients = expired ? dimClientDao.GetExpiredClients() : dimClientDao.GetActiveClients(); 121 var query = (from client in clients 122 join info in factClientInfoDao.GetAll() 123 on client.Id equals info.ClientId into clientInfoJoin 124 from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1) 125 let offline = (expired || clientInfo.SlaveState == SlaveState.Offline) 126 select new DT.Client { 127 Id = client.Id, 128 Name = client.Name, 129 TotalCores = clientInfo.NumTotalCores, 130 UsedCores = offline ? 0 : clientInfo.NumUsedCores, 131 TotalMemory = clientInfo.TotalMemory, 132 UsedMemory = offline ? 0 : clientInfo.UsedMemory, 133 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 134 State = offline ? SlaveState.Offline.ToString() : clientInfo.SlaveState.ToString(), 135 GroupId = client.ResourceGroupId, 136 GroupName = client.GroupName, 137 IsAllowedToCalculate = clientInfo.IsAllowedToCalculate 138 }); 139 return new DT.ClientPage { 140 TotalClients = query.Count(), 141 Clients = query.Skip((page - 1) * size) 142 .Take(size) 143 .ToList() 144 }; 145 }); 146 } 115 var pm = PersistenceManager; 116 var dimClientDao = pm.DimClientDao; 117 var factClientInfoDao = pm.FactClientInfoDao; 118 return pm.UseTransaction(() => { 119 var clients = expired ? dimClientDao.GetExpiredClients() : dimClientDao.GetActiveClients(); 120 var query = (from client in clients 121 join info in factClientInfoDao.GetAll() 122 on client.Id equals info.ClientId into clientInfoJoin 123 from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1) 124 let offline = (expired || clientInfo.SlaveState == SlaveState.Offline) 125 select new DT.Client { 126 Id = client.Id, 127 Name = client.Name, 128 TotalCores = clientInfo.NumTotalCores, 129 UsedCores = offline ? 0 : clientInfo.NumUsedCores, 130 TotalMemory = clientInfo.TotalMemory, 131 UsedMemory = offline ? 0 : clientInfo.UsedMemory, 132 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 133 State = offline ? SlaveState.Offline.ToString() : clientInfo.SlaveState.ToString(), 134 GroupId = client.ResourceGroupId, 135 GroupName = client.GroupName, 136 IsAllowedToCalculate = clientInfo.IsAllowedToCalculate 137 }); 138 return new DT.ClientPage { 139 TotalClients = query.Count(), 140 Clients = query.Skip((page - 1) * size) 141 .Take(size) 142 .ToList() 143 }; 144 }); 147 145 } 148 146 … … 155 153 increment += 5; 156 154 } 157 using (var pm = PersistenceManager) { 158 var factClientInfo = pm.FactClientInfoDao; 159 var clientInfos = factClientInfo.GetByClientId(id) 160 .Where(x => x.Time >= start && x.Time <= end) 161 .OrderBy(x => x.Time) 162 .ToList(); 163 var clientStatus = new DT.ClientStatus { 164 CpuUtilization = 0, 165 TotalCores = 0, 166 UsedCores = 0, 167 TotalMemory = 0, 168 UsedMemory = 0 155 var pm = PersistenceManager; 156 var factClientInfo = pm.FactClientInfoDao; 157 var clientInfos = factClientInfo.GetByClientId(id) 158 .Where(x => x.Time >= start && x.Time <= end) 159 .OrderBy(x => x.Time) 160 .ToList(); 161 var clientStatus = new DT.ClientStatus { 162 CpuUtilization = 0, 163 TotalCores = 0, 164 UsedCores = 0, 165 TotalMemory = 0, 166 UsedMemory = 0 167 }; 168 int i = 1; 169 foreach (var clientInfo in clientInfos) { 170 clientStatus.CpuUtilization += clientInfo.CpuUtilization; 171 clientStatus.TotalCores += clientInfo.NumTotalCores; 172 clientStatus.UsedCores += clientInfo.NumUsedCores; 173 clientStatus.TotalMemory += clientInfo.TotalMemory; 174 clientStatus.UsedMemory += clientInfo.UsedMemory; 175 if (i >= increment) { 176 clientStatus.Timestamp = JavascriptUtils.ToTimestamp(clientInfo.Time); 177 clientStatus.CpuUtilization /= i; 178 clientStatus.TotalCores /= i; 179 clientStatus.UsedCores /= i; 180 clientStatus.TotalMemory /= i; 181 clientStatus.UsedMemory /= i; 182 yield return clientStatus; 183 clientStatus = new DT.ClientStatus { 184 CpuUtilization = 0, 185 TotalCores = 0, 186 UsedCores = 0, 187 TotalMemory = 0, 188 UsedMemory = 0 189 }; 190 i = 1; 191 } else { 192 ++i; 193 } 194 } 195 } 196 197 public DT.ClientPage GetClientsByGroupId(Guid id, int page, int size, bool expired = false) { 198 var pm = PersistenceManager; 199 var dimClientDao = pm.DimClientDao; 200 var factClientInfoDao = pm.FactClientInfoDao; 201 return pm.UseTransaction(() => { 202 var clients = expired ? dimClientDao.GetExpiredClients() : dimClientDao.GetActiveClients(); 203 clients = clients.Where(x => x.ResourceGroupId == id); 204 var query = (from client in clients 205 join info in factClientInfoDao.GetAll() 206 on client.Id equals info.ClientId into clientInfoJoin 207 from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1) 208 let offline = (expired || clientInfo.SlaveState == SlaveState.Offline) 209 select new DT.Client { 210 Id = client.Id, 211 Name = client.Name, 212 TotalCores = clientInfo.NumTotalCores, 213 UsedCores = offline ? 0 : clientInfo.NumUsedCores, 214 TotalMemory = clientInfo.TotalMemory, 215 UsedMemory = offline ? 0 : clientInfo.UsedMemory, 216 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 217 State = offline ? SlaveState.Offline.ToString() : clientInfo.SlaveState.ToString(), 218 GroupId = client.ResourceGroupId, 219 GroupName = client.GroupName, 220 IsAllowedToCalculate = clientInfo.IsAllowedToCalculate 221 }); 222 return new DT.ClientPage { 223 TotalClients = query.Count(), 224 Clients = query.Skip((page - 1) * size) 225 .Take(size) 226 .ToList() 169 227 }; 170 int i = 1; 171 foreach (var clientInfo in clientInfos) { 172 clientStatus.CpuUtilization += clientInfo.CpuUtilization; 173 clientStatus.TotalCores += clientInfo.NumTotalCores; 174 clientStatus.UsedCores += clientInfo.NumUsedCores; 175 clientStatus.TotalMemory += clientInfo.TotalMemory; 176 clientStatus.UsedMemory += clientInfo.UsedMemory; 177 if (i >= increment) { 178 clientStatus.Timestamp = JavascriptUtils.ToTimestamp(clientInfo.Time); 179 clientStatus.CpuUtilization /= i; 180 clientStatus.TotalCores /= i; 181 clientStatus.UsedCores /= i; 182 clientStatus.TotalMemory /= i; 183 clientStatus.UsedMemory /= i; 184 yield return clientStatus; 185 clientStatus = new DT.ClientStatus { 186 CpuUtilization = 0, 187 TotalCores = 0, 188 UsedCores = 0, 189 TotalMemory = 0, 190 UsedMemory = 0 191 }; 192 i = 1; 193 } else { 194 ++i; 195 } 196 } 197 } 198 } 199 200 public DT.ClientPage GetClientsByGroupId(Guid id, int page, int size, bool expired = false) { 201 using (var pm = PersistenceManager) { 202 var dimClientDao = pm.DimClientDao; 203 var factClientInfoDao = pm.FactClientInfoDao; 204 return pm.UseTransaction(() => { 205 var clients = expired ? dimClientDao.GetExpiredClients() : dimClientDao.GetActiveClients(); 206 clients = clients.Where(x => x.ResourceGroupId == id); 207 var query = (from client in clients 208 join info in factClientInfoDao.GetAll() 209 on client.Id equals info.ClientId into clientInfoJoin 210 from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1) 211 let offline = (expired || clientInfo.SlaveState == SlaveState.Offline) 212 select new DT.Client { 213 Id = client.Id, 214 Name = client.Name, 215 TotalCores = clientInfo.NumTotalCores, 216 UsedCores = offline ? 0 : clientInfo.NumUsedCores, 217 TotalMemory = clientInfo.TotalMemory, 218 UsedMemory = offline ? 0 : clientInfo.UsedMemory, 219 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 220 State = offline ? SlaveState.Offline.ToString() : clientInfo.SlaveState.ToString(), 221 GroupId = client.ResourceGroupId, 222 GroupName = client.GroupName, 223 IsAllowedToCalculate = clientInfo.IsAllowedToCalculate 224 }); 225 return new DT.ClientPage { 226 TotalClients = query.Count(), 227 Clients = query.Skip((page - 1) * size) 228 .Take(size) 229 .ToList() 230 }; 231 }); 232 } 228 }); 233 229 } 234 230 … … 241 237 increment += 5; 242 238 } 243 using (var pm = PersistenceManager) { 244 var factClientInfo = pm.FactClientInfoDao; 245 var dimClientDao = pm.DimClientDao; 246 var clientInfos = factClientInfo.GetAll() 247 .Where(x => x.Time >= start && x.Time <= end) 248 .OrderBy(x => x.Time) 249 .Join(dimClientDao.GetAll(), 250 fact => fact.ClientId, 251 client => client.Id, 252 (fact, client) => new { 253 client.ResourceGroupId, 254 fact.Time, 255 fact.CpuUtilization, 256 fact.NumTotalCores, 257 fact.NumUsedCores, 258 fact.TotalMemory, 259 fact.UsedMemory 260 }) 261 .Where(x => x.ResourceGroupId == id) 262 .ToList(); 263 var clientStatus = new DT.ClientStatus { 264 CpuUtilization = 0, 265 TotalCores = 0, 266 UsedCores = 0, 267 TotalMemory = 0, 268 UsedMemory = 0 269 }; 270 int i = 1; 271 foreach (var clientInfo in clientInfos) { 272 clientStatus.CpuUtilization += clientInfo.CpuUtilization; 273 clientStatus.TotalCores += clientInfo.NumTotalCores; 274 clientStatus.UsedCores += clientInfo.NumUsedCores; 275 clientStatus.TotalMemory += clientInfo.TotalMemory; 276 clientStatus.UsedMemory += clientInfo.UsedMemory; 277 if (i >= increment) { 278 clientStatus.Timestamp = JavascriptUtils.ToTimestamp(clientInfo.Time); 279 clientStatus.CpuUtilization /= i; 280 clientStatus.TotalCores /= i; 281 clientStatus.UsedCores /= i; 282 clientStatus.TotalMemory /= i; 283 clientStatus.UsedMemory /= i; 284 yield return clientStatus; 285 clientStatus = new DT.ClientStatus { 286 CpuUtilization = 0, 287 TotalCores = 0, 288 UsedCores = 0, 289 TotalMemory = 0, 290 UsedMemory = 0 291 }; 292 i = 1; 293 } else { 294 ++i; 295 } 239 var pm = PersistenceManager; 240 var factClientInfo = pm.FactClientInfoDao; 241 var dimClientDao = pm.DimClientDao; 242 var clientInfos = factClientInfo.GetAll() 243 .Where(x => x.Time >= start && x.Time <= end) 244 .OrderBy(x => x.Time) 245 .Join(dimClientDao.GetAll(), 246 fact => fact.ClientId, 247 client => client.Id, 248 (fact, client) => new { 249 client.ResourceGroupId, 250 fact.Time, 251 fact.CpuUtilization, 252 fact.NumTotalCores, 253 fact.NumUsedCores, 254 fact.TotalMemory, 255 fact.UsedMemory 256 }) 257 .Where(x => x.ResourceGroupId == id) 258 .ToList(); 259 var clientStatus = new DT.ClientStatus { 260 CpuUtilization = 0, 261 TotalCores = 0, 262 UsedCores = 0, 263 TotalMemory = 0, 264 UsedMemory = 0 265 }; 266 int i = 1; 267 foreach (var clientInfo in clientInfos) { 268 clientStatus.CpuUtilization += clientInfo.CpuUtilization; 269 clientStatus.TotalCores += clientInfo.NumTotalCores; 270 clientStatus.UsedCores += clientInfo.NumUsedCores; 271 clientStatus.TotalMemory += clientInfo.TotalMemory; 272 clientStatus.UsedMemory += clientInfo.UsedMemory; 273 if (i >= increment) { 274 clientStatus.Timestamp = JavascriptUtils.ToTimestamp(clientInfo.Time); 275 clientStatus.CpuUtilization /= i; 276 clientStatus.TotalCores /= i; 277 clientStatus.UsedCores /= i; 278 clientStatus.TotalMemory /= i; 279 clientStatus.UsedMemory /= i; 280 yield return clientStatus; 281 clientStatus = new DT.ClientStatus { 282 CpuUtilization = 0, 283 TotalCores = 0, 284 UsedCores = 0, 285 TotalMemory = 0, 286 UsedMemory = 0 287 }; 288 i = 1; 289 } else { 290 ++i; 296 291 } 297 292 } -
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/ExceptionController.cs
r12562 r12858 35 35 36 36 public DT.ExceptionPage GetExceptions(int page, int size) { 37 using (var pm = PersistenceManager) { 38 var dimClientDao = pm.DimClientDao; 39 var dimJobDao = pm.DimJobDao; 40 var factTaskDao = pm.FactTaskDao; 41 var tasks = factTaskDao.GetTasksWithException(); 42 return pm.UseTransaction(() => new DT.ExceptionPage { 43 TotalExceptions = tasks.Count(), 44 Exceptions = (from factTask in tasks 45 join dimJob in dimJobDao.GetAll() on factTask.JobId equals dimJob.JobId 46 join dimClient in dimClientDao.GetAll() on factTask.LastClientId equals 47 dimClient.Id into taskClientJoin 48 from a in taskClientJoin.DefaultIfEmpty() 49 let endTime = factTask.EndTime ?? DateTime.Now 50 select new DT.Exception { 51 TaskId = factTask.TaskId, 52 JobId = factTask.JobId, 53 JobName = dimJob.JobName, 54 UserId = dimJob.UserId, 55 UserName = dimJob.UserName, 56 ClientId = factTask.LastClientId ?? default(Guid), 57 ClientName = a != null ? a.Name : string.Empty, 58 Date = endTime, 59 Details = factTask.Exception 60 }) 61 .OrderByDescending(x => x.Date) 62 .Skip((page - 1) * size) 63 .Take(size) 64 .ToList() 65 }); 66 } 37 var pm = PersistenceManager; 38 var dimClientDao = pm.DimClientDao; 39 var dimJobDao = pm.DimJobDao; 40 var factTaskDao = pm.FactTaskDao; 41 var tasks = factTaskDao.GetTasksWithException(); 42 return pm.UseTransaction(() => new DT.ExceptionPage { 43 TotalExceptions = tasks.Count(), 44 Exceptions = (from factTask in tasks 45 join dimJob in dimJobDao.GetAll() on factTask.JobId equals dimJob.JobId 46 join dimClient in dimClientDao.GetAll() on factTask.LastClientId equals 47 dimClient.Id into taskClientJoin 48 from a in taskClientJoin.DefaultIfEmpty() 49 let endTime = factTask.EndTime ?? DateTime.Now 50 select new DT.Exception { 51 TaskId = factTask.TaskId, 52 JobId = factTask.JobId, 53 JobName = dimJob.JobName, 54 UserId = dimJob.UserId, 55 UserName = dimJob.UserName, 56 ClientId = factTask.LastClientId ?? default(Guid), 57 ClientName = a != null ? a.Name : string.Empty, 58 Date = endTime, 59 Details = factTask.Exception 60 }) 61 .OrderByDescending(x => x.Date) 62 .Skip((page - 1) * size) 63 .Take(size) 64 .ToList() 65 }); 67 66 } 68 67 } -
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/GroupController.cs
r12562 r12858 35 35 36 36 public DT.GroupDetails GetGroupDetails(Guid id) { 37 using (var pm = PersistenceManager) {38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 37 var pm = PersistenceManager; 38 var dimClientDao = pm.DimClientDao; 39 var factClientInfoDao = pm.FactClientInfoDao; 40 var factTaskDao = pm.FactTaskDao; 41 return pm.UseTransaction(() => { 42 var clientTimeData = factClientInfoDao.GetAll() 43 .Join(dimClientDao.GetAll(), x => x.ClientId, y => y.Id, (x, y) => new { 44 y.ResourceGroupId, 45 x.IdleTime, 46 x.OfflineTime, 47 x.UnavailableTime 48 }) 49 .Where(x => x.ResourceGroupId == id) 50 .GroupBy(x => x.ResourceGroupId) 51 .Select(x => new { 52 TotalIdleTime = x.Sum(y => y.IdleTime), 53 TotalOfflineTime = x.Sum(y => y.OfflineTime), 54 TotalUnavailableTime = x.Sum(y => y.UnavailableTime) 55 }) 56 .FirstOrDefault(); 57 57 58 var taskTimeData = factTaskDao.GetByGroupId(id) 59 .Select(x => new { 60 id, 61 x.CalculatingTime, 62 x.TransferTime 63 }) 64 .GroupBy(x => x.id) 65 .Select(x => new { 66 CalculatingTime = x.Sum(y => y.CalculatingTime), 67 TransferTime = x.Sum(y => y.TransferTime) 68 }) 69 .FirstOrDefault(); 70 return (from client in dimClientDao.GetActiveClients().Where(x => x.ResourceGroupId == id) 58 var taskTimeData = factTaskDao.GetByGroupId(id) 59 .Select(x => new { 60 id, 61 x.CalculatingTime, 62 x.TransferTime 63 }) 64 .GroupBy(x => x.id) 65 .Select(x => new { 66 CalculatingTime = x.Sum(y => y.CalculatingTime), 67 TransferTime = x.Sum(y => y.TransferTime) 68 }) 69 .FirstOrDefault(); 70 return (from client in dimClientDao.GetActiveClients().Where(x => x.ResourceGroupId == id) 71 join info in factClientInfoDao.GetAll() 72 on client.Id equals info.ClientId into clientInfoJoin 73 from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1) 74 let offline = (clientInfo.SlaveState == DA.SlaveState.Offline) 75 select new { 76 ResourceGroupId = client.ResourceGroupId, 77 GroupName = client.GroupName, 78 TotalCores = clientInfo.NumTotalCores, 79 UsedCores = offline ? 0 : clientInfo.NumUsedCores, 80 TotalMemory = clientInfo.TotalMemory, 81 UsedMemory = offline ? 0 : clientInfo.UsedMemory, 82 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 83 SlaveState = clientInfo.SlaveState 84 }) 85 .GroupBy(x => new { x.ResourceGroupId, x.GroupName }) 86 .Select(x => new DT.GroupDetails { 87 Id = id, 88 Name = x.Key.GroupName, 89 TotalClients = x.Count(), 90 OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline), 91 TotalCores = x.Sum(y => y.TotalCores), 92 UsedCores = x.Sum(y => y.UsedCores), 93 TotalMemory = x.Sum(y => y.TotalMemory), 94 UsedMemory = x.Sum(y => y.UsedMemory), 95 TotalCpuUtilization = x.Average(y => (double?)y.CpuUtilization) ?? 0.0, 96 ActiveCpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0, 97 TotalUnavailableTime = clientTimeData != null ? clientTimeData.TotalUnavailableTime : 0, 98 TotalCalculatingTime = taskTimeData != null ? taskTimeData.CalculatingTime : 0, 99 TotalIdleTime = clientTimeData != null ? clientTimeData.TotalIdleTime : 0, 100 TotalOfflineTime = clientTimeData != null ? clientTimeData.TotalOfflineTime : 0, 101 TotalTransferringTime = taskTimeData != null ? taskTimeData.TransferTime : 0, 102 TasksStates = factTaskDao.GetByGroupId(id) 103 .GroupBy(y => y.TaskState) 104 .Select(y => new DT.TaskStateCount { 105 State = y.Key.ToString(), 106 Count = y.Count() 107 }).ToList() 108 }).FirstOrDefault(); 109 }); 110 } 111 112 public DT.GroupPage GetGroups(int page, int size) { 113 var pm = PersistenceManager; 114 var dimClientDao = pm.DimClientDao; 115 var factClientInfoDao = pm.FactClientInfoDao; 116 var data = (from client in dimClientDao.GetActiveClients() 71 117 join info in factClientInfoDao.GetAll() 72 118 on client.Id equals info.ClientId into clientInfoJoin … … 75 121 select new { 76 122 ResourceGroupId = client.ResourceGroupId, 77 GroupName = client.GroupName,78 123 TotalCores = clientInfo.NumTotalCores, 79 124 UsedCores = offline ? 0 : clientInfo.NumUsedCores, … … 82 127 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 83 128 SlaveState = clientInfo.SlaveState 84 }) 85 .GroupBy(x => new { x.ResourceGroupId, x.GroupName }) 86 .Select(x => new DT.GroupDetails { 87 Id = id, 88 Name = x.Key.GroupName, 89 TotalClients = x.Count(), 90 OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline), 91 TotalCores = x.Sum(y => y.TotalCores), 92 UsedCores = x.Sum(y => y.UsedCores), 93 TotalMemory = x.Sum(y => y.TotalMemory), 94 UsedMemory = x.Sum(y => y.UsedMemory), 95 TotalCpuUtilization = x.Average(y => (double?)y.CpuUtilization) ?? 0.0, 96 ActiveCpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0, 97 TotalUnavailableTime = clientTimeData != null ? clientTimeData.TotalUnavailableTime : 0, 98 TotalCalculatingTime = taskTimeData != null ? taskTimeData.CalculatingTime : 0, 99 TotalIdleTime = clientTimeData != null ? clientTimeData.TotalIdleTime : 0, 100 TotalOfflineTime = clientTimeData != null ? clientTimeData.TotalOfflineTime : 0, 101 TotalTransferringTime = taskTimeData != null ? taskTimeData.TransferTime : 0, 102 TasksStates = factTaskDao.GetByGroupId(id) 103 .GroupBy(y => y.TaskState) 104 .Select(y => new DT.TaskStateCount { 105 State = y.Key.ToString(), 106 Count = y.Count() 107 }).ToList() 108 }).FirstOrDefault(); 129 }).GroupBy(x => x.ResourceGroupId).Select(x => new { 130 GroupId = x.Key, 131 TotalClients = x.Count(), 132 OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline), 133 TotalCores = x.Sum(y => y.TotalCores), 134 UsedCores = x.Sum(y => y.UsedCores), 135 TotalMemory = x.Sum(y => y.TotalMemory), 136 UsedMemory = x.Sum(y => y.UsedMemory), 137 CpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0 138 }); 139 var query = dimClientDao.GetAll() 140 .GroupBy(x => new { x.ResourceGroupId, x.GroupName }) 141 .Select(x => new { 142 Id = x.Key.ResourceGroupId ?? default(Guid), 143 Name = x.Key.GroupName 109 144 }); 110 } 111 } 112 113 public DT.GroupPage GetGroups(int page, int size) { 114 using (var pm = PersistenceManager) { 115 var dimClientDao = pm.DimClientDao; 116 var factClientInfoDao = pm.FactClientInfoDao; 117 var data = (from client in dimClientDao.GetActiveClients() 118 join info in factClientInfoDao.GetAll() 119 on client.Id equals info.ClientId into clientInfoJoin 120 from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1) 121 let offline = (clientInfo.SlaveState == DA.SlaveState.Offline) 122 select new { 123 ResourceGroupId = client.ResourceGroupId, 124 TotalCores = clientInfo.NumTotalCores, 125 UsedCores = offline ? 0 : clientInfo.NumUsedCores, 126 TotalMemory = clientInfo.TotalMemory, 127 UsedMemory = offline ? 0 : clientInfo.UsedMemory, 128 CpuUtilization = offline ? 0 : clientInfo.CpuUtilization, 129 SlaveState = clientInfo.SlaveState 130 }).GroupBy(x => x.ResourceGroupId).Select(x => new { 131 GroupId = x.Key, 132 TotalClients = x.Count(), 133 OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline), 134 TotalCores = x.Sum(y => y.TotalCores), 135 UsedCores = x.Sum(y => y.UsedCores), 136 TotalMemory = x.Sum(y => y.TotalMemory), 137 UsedMemory = x.Sum(y => y.UsedMemory), 138 CpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0 139 }); 140 var query = dimClientDao.GetAll() 141 .GroupBy(x => new { x.ResourceGroupId, x.GroupName }) 142 .Select(x => new { 143 Id = x.Key.ResourceGroupId ?? default(Guid), 144 Name = x.Key.GroupName 145 }); 146 return pm.UseTransaction(() => new DT.GroupPage { 147 TotalGroups = query.Count(), 148 Groups = query 149 .Skip((page - 1) * size) 150 .Take(size) 151 .Join(data, x => x.Id, y => y.GroupId, 152 (group, info) => new DT.Group { 153 Id = group.Id, 154 Name = group.Name, 155 TotalClients = info.TotalClients, 156 OnlineClients = info.OnlineClients, 157 TotalCores = info.TotalCores, 158 UsedCores = info.UsedCores, 159 TotalMemory = info.TotalMemory, 160 UsedMemory = info.UsedMemory, 161 CpuUtilization = info.CpuUtilization 162 }).ToList() 163 }); 164 } 145 return pm.UseTransaction(() => new DT.GroupPage { 146 TotalGroups = query.Count(), 147 Groups = query 148 .Skip((page - 1) * size) 149 .Take(size) 150 .Join(data, x => x.Id, y => y.GroupId, 151 (group, info) => new DT.Group { 152 Id = group.Id, 153 Name = group.Name, 154 TotalClients = info.TotalClients, 155 OnlineClients = info.OnlineClients, 156 TotalCores = info.TotalCores, 157 UsedCores = info.UsedCores, 158 TotalMemory = info.TotalMemory, 159 UsedMemory = info.UsedMemory, 160 CpuUtilization = info.CpuUtilization 161 }).ToList() 162 }); 165 163 } 166 164 } -
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/JobController.cs
r12562 r12858 47 47 48 48 public DT.JobDetails GetJobDetails(Guid id) { 49 using (var pm = PersistenceManager) { 50 var dimJobDao = pm.DimJobDao; 51 var factTaskDao = pm.FactTaskDao; 52 return pm.UseTransaction(() => { 53 var job = dimJobDao.GetById(id); 54 if (job != null) { 55 var timeData = factTaskDao.GetByJobId(id).GroupBy(x => x.JobId).Select(x => new { 56 AvgTransferringTime = (long)x.Average(y => y.TransferTime), 57 MinCalculatingTime = (long)x.Min(y => y.CalculatingTime), 58 MaxCalculatingTime = (long)x.Max(y => y.CalculatingTime), 59 AvgCalculatingTime = (long)x.Average(y => y.CalculatingTime), 60 TotalCalculatingTime = (long)x.Sum(y => y.CalculatingTime), 61 TotalWaitingTime = (long)x.Sum(y => y.WaitingTime) 62 }).FirstOrDefault(); 63 DateTime endTime = job.DateCompleted ?? DateTime.Now; 64 long totalTime = (long)(endTime - job.DateCreated).TotalSeconds; 65 return new DT.JobDetails { 66 Id = job.JobId, 67 Name = job.JobName, 68 UserId = job.UserId, 69 UserName = job.UserName, 70 DateCreated = job.DateCreated, 71 DateCompleted = job.DateCompleted, 72 TotalTasks = job.TotalTasks, 73 CompletedTasks = job.CompletedTasks, 74 AvgTransferringTime = timeData != null ? timeData.AvgTransferringTime : 0, 75 AvgCalculatingTime = timeData != null ? timeData.AvgCalculatingTime : 0, 76 MinCalculatingTime = timeData != null ? timeData.MinCalculatingTime : 0, 77 MaxCalculatingTime = timeData != null ? timeData.MaxCalculatingTime : 0, 78 TotalCalculatingTime = timeData != null ? timeData.TotalCalculatingTime : 0, 79 TotalWaitingTime = timeData != null ? timeData.TotalWaitingTime : 0, 80 TotalTime = totalTime, 81 TasksStates = factTaskDao.GetByJobId(id) 82 .GroupBy(x => x.TaskState) 83 .Select(x => new DT.TaskStateCount { 84 State = x.Key.ToString(), 85 Count = x.Count() 86 }).ToList() 87 }; 88 } 89 return null; 90 }); 91 } 49 var pm = PersistenceManager; 50 var dimJobDao = pm.DimJobDao; 51 var factTaskDao = pm.FactTaskDao; 52 return pm.UseTransaction(() => { 53 var job = dimJobDao.GetById(id); 54 if (job != null) { 55 var timeData = factTaskDao.GetByJobId(id).GroupBy(x => x.JobId).Select(x => new { 56 AvgTransferringTime = (long)x.Average(y => y.TransferTime), 57 MinCalculatingTime = (long)x.Min(y => y.CalculatingTime), 58 MaxCalculatingTime = (long)x.Max(y => y.CalculatingTime), 59 AvgCalculatingTime = (long)x.Average(y => y.CalculatingTime), 60 TotalCalculatingTime = (long)x.Sum(y => y.CalculatingTime), 61 TotalWaitingTime = (long)x.Sum(y => y.WaitingTime) 62 }).FirstOrDefault(); 63 DateTime endTime = job.DateCompleted ?? DateTime.Now; 64 long totalTime = (long)(endTime - job.DateCreated).TotalSeconds; 65 return new DT.JobDetails { 66 Id = job.JobId, 67 Name = job.JobName, 68 UserId = job.UserId, 69 UserName = job.UserName, 70 DateCreated = job.DateCreated, 71 DateCompleted = job.DateCompleted, 72 TotalTasks = job.TotalTasks, 73 CompletedTasks = job.CompletedTasks, 74 AvgTransferringTime = timeData != null ? timeData.AvgTransferringTime : 0, 75 AvgCalculatingTime = timeData != null ? timeData.AvgCalculatingTime : 0, 76 MinCalculatingTime = timeData != null ? timeData.MinCalculatingTime : 0, 77 MaxCalculatingTime = timeData != null ? timeData.MaxCalculatingTime : 0, 78 TotalCalculatingTime = timeData != null ? timeData.TotalCalculatingTime : 0, 79 TotalWaitingTime = timeData != null ? timeData.TotalWaitingTime : 0, 80 TotalTime = totalTime, 81 TasksStates = factTaskDao.GetByJobId(id) 82 .GroupBy(x => x.TaskState) 83 .Select(x => new DT.TaskStateCount { 84 State = x.Key.ToString(), 85 Count = x.Count() 86 }).ToList() 87 }; 88 } 89 return null; 90 }); 92 91 } 93 92 … … 100 99 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); 101 100 } 102 using (var pm = PersistenceManager) { 103 var dimJobDao = pm.DimJobDao; 104 return pm.UseTransaction(() => { 105 var jobs = dimJobDao.GetByUserId(id).Where(x => completed ? (x.DateCompleted != null) : (x.DateCompleted == null)); 106 return new DT.JobPage { 107 TotalJobs = jobs.Count(), 108 Jobs = jobs.OrderByDescending(x => x.DateCompleted ?? DateTime.MaxValue) 109 .Skip((page - 1) * size) 110 .Take(size) 111 .Select(x => ConvertToDT(x)) 112 .ToList() 113 }; 114 }); 115 } 101 var pm = PersistenceManager; 102 var dimJobDao = pm.DimJobDao; 103 return pm.UseTransaction(() => { 104 var jobs = dimJobDao.GetByUserId(id).Where(x => completed ? (x.DateCompleted != null) : (x.DateCompleted == null)); 105 return new DT.JobPage { 106 TotalJobs = jobs.Count(), 107 Jobs = jobs.OrderByDescending(x => x.DateCompleted ?? DateTime.MaxValue) 108 .Skip((page - 1) * size) 109 .Take(size) 110 .Select(x => ConvertToDT(x)) 111 .ToList() 112 }; 113 }); 116 114 } 117 115 … … 124 122 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); 125 123 } 126 using (var pm = PersistenceManager) { 127 var dimJobDao = pm.DimJobDao; 128 return pm.UseTransaction(() => { 129 return dimJobDao.GetByUserId(id) 130 .Where(x => completed ? (x.DateCompleted != null) : (x.DateCompleted == null)) 131 .Select(x => ConvertToDT(x)) 132 .ToList(); 133 }); 134 } 124 var pm = PersistenceManager; 125 var dimJobDao = pm.DimJobDao; 126 return pm.UseTransaction(() => { 127 return dimJobDao.GetByUserId(id) 128 .Where(x => completed ? (x.DateCompleted != null) : (x.DateCompleted == null)) 129 .Select(x => ConvertToDT(x)) 130 .ToList(); 131 }); 135 132 } 136 133 137 134 [Authorize(Roles = HiveRoles.Administrator)] 138 135 public IEnumerable<DT.Job> GetAllActiveJobsFromAllUsers() { 139 using (var pm = PersistenceManager) { 140 var dimJobDao = pm.DimJobDao; 141 return pm.UseTransaction(() => { 142 return dimJobDao.GetAll() 143 .Where(x => x.DateCompleted == null) 144 .OrderByDescending(x => x.DateCreated) 145 .Select(x => ConvertToDT(x)) 146 .ToList(); 147 }); 148 } 136 var pm = PersistenceManager; 137 var dimJobDao = pm.DimJobDao; 138 return pm.UseTransaction(() => { 139 return dimJobDao.GetAll() 140 .Where(x => x.DateCompleted == null) 141 .OrderByDescending(x => x.DateCreated) 142 .Select(x => ConvertToDT(x)) 143 .ToList(); 144 }); 149 145 } 150 146 -
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/TaskController.cs
r12768 r12858 51 51 [HttpPost] 52 52 public DT.TaskPage GetTasksByJobId(Guid id, int page, int size, IEnumerable<string> states) { 53 using (var pm = PersistenceManager) {54 55 56 53 var pm = PersistenceManager; 54 var dimJobDao = pm.DimJobDao; 55 var dimClientDao = pm.DimClientDao; 56 var factTaskDao = pm.FactTaskDao; 57 57 58 59 60 61 62 63 64 58 DA.DimJob job = pm.UseTransaction(() => dimJobDao.GetById(id)); 59 if (job == null) { 60 throw new ArgumentException("invalid job id"); 61 } 62 if (job.UserId != UserManager.CurrentUserId) { 63 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); 64 } 65 65 66 return pm.UseTransaction(() => { 67 var tasks = factTaskDao.GetByJobId(id).Where(x => states.Contains(x.TaskState.ToString())); 68 return new DT.TaskPage { 69 TotalTasks = tasks.Count(), 70 Tasks = (from factTask in tasks 71 join dimJob in dimJobDao.GetAll() on factTask.JobId equals dimJob.JobId 72 join dimClient in dimClientDao.GetAll() on factTask.LastClientId equals 73 dimClient.Id into taskClientJoin 74 from a in taskClientJoin.DefaultIfEmpty() 75 let startTime = factTask.StartTime ?? DateTime.Now 76 let endTime = factTask.EndTime ?? DateTime.Now 77 select new DT.Task { 78 Id = factTask.TaskId, 79 JobId = factTask.JobId, 80 JobName = dimJob.JobName, 81 TotalTime = (long)(endTime - startTime).TotalSeconds, 82 CalculatingTime = factTask.CalculatingTime, 83 WaitingTime = factTask.WaitingTime, 84 TransferTime = factTask.TransferTime, 85 InitialWaitingTime = factTask.InitialWaitingTime, 86 NumCalculationRuns = factTask.NumCalculationRuns, 87 NumRetries = factTask.NumRetries, 88 CoresRequired = factTask.CoresRequired, 89 MemoryRequired = factTask.MemoryRequired, 90 Priority = factTask.Priority, 91 State = factTask.TaskState.ToString(), 92 LastClientId = factTask.LastClientId, 93 LastClientName = a != null ? a.Name : string.Empty, 94 UserId = dimJob.UserId, 95 UserName = dimJob.UserName, 96 StartTime = factTask.StartTime, 97 EndTime = factTask.EndTime, 98 Exception = factTask.Exception 99 }) 100 .Skip((page - 1) * size) 101 .Take(size) 102 .ToList() 103 }; 104 }); 105 } 66 return pm.UseTransaction(() => { 67 var tasks = factTaskDao.GetByJobId(id).Where(x => states.Contains(x.TaskState.ToString())); 68 return new DT.TaskPage { 69 TotalTasks = tasks.Count(), 70 Tasks = (from factTask in tasks 71 join dimJob in dimJobDao.GetAll() on factTask.JobId equals dimJob.JobId 72 join dimClient in dimClientDao.GetAll() on factTask.LastClientId equals 73 dimClient.Id into taskClientJoin 74 from a in taskClientJoin.DefaultIfEmpty() 75 let startTime = factTask.StartTime ?? DateTime.Now 76 let endTime = factTask.EndTime ?? DateTime.Now 77 select new DT.Task { 78 Id = factTask.TaskId, 79 JobId = factTask.JobId, 80 JobName = dimJob.JobName, 81 TotalTime = (long)(endTime - startTime).TotalSeconds, 82 CalculatingTime = factTask.CalculatingTime, 83 WaitingTime = factTask.WaitingTime, 84 TransferTime = factTask.TransferTime, 85 InitialWaitingTime = factTask.InitialWaitingTime, 86 NumCalculationRuns = factTask.NumCalculationRuns, 87 NumRetries = factTask.NumRetries, 88 CoresRequired = factTask.CoresRequired, 89 MemoryRequired = factTask.MemoryRequired, 90 Priority = factTask.Priority, 91 State = factTask.TaskState.ToString(), 92 LastClientId = factTask.LastClientId, 93 LastClientName = a != null ? a.Name : string.Empty, 94 UserId = dimJob.UserId, 95 UserName = dimJob.UserName, 96 StartTime = factTask.StartTime, 97 EndTime = factTask.EndTime, 98 Exception = factTask.Exception 99 }) 100 .Skip((page - 1) * size) 101 .Take(size) 102 .ToList() 103 }; 104 }); 106 105 } 107 106 … … 109 108 public DT.TaskPage GetTasksByClientId(Guid id, int page, int size, IEnumerable<string> states, Guid userId = default(Guid)) { 110 109 bool isAdministrator = User.IsInRole(HiveRoles.Administrator); 111 using (var pm = PersistenceManager) { 112 var dimJobDao = pm.DimJobDao; 113 var dimClientDao = pm.DimClientDao; 114 var factTaskDao = pm.FactTaskDao; 115 return pm.UseTransaction(() => { 116 var tasks = factTaskDao.GetByClientId(id).Where(x => states.Contains(x.TaskState.ToString())); 117 if (userId != Guid.Empty) { 118 tasks = tasks.Where(x => x.DimJob.UserId == userId); 119 } 120 return new DT.TaskPage { 121 TotalTasks = tasks.Count(), 122 Tasks = (from factTask in tasks 123 join dimJob in dimJobDao.GetAll() on factTask.JobId equals dimJob.JobId 124 join dimClient in dimClientDao.GetAll() on factTask.LastClientId equals 125 dimClient.Id into taskClientJoin 126 from a in taskClientJoin.DefaultIfEmpty() 127 let startTime = factTask.StartTime ?? DateTime.Now 128 let endTime = factTask.EndTime ?? DateTime.Now 129 select new DT.Task { 130 Id = isAdministrator ? factTask.TaskId : default(Guid), 131 JobId = isAdministrator ? factTask.JobId : default(Guid), 132 JobName = isAdministrator ? dimJob.JobName : string.Empty, 133 TotalTime = (long)(endTime - startTime).TotalSeconds, 134 CalculatingTime = factTask.CalculatingTime, 135 WaitingTime = factTask.WaitingTime, 136 TransferTime = factTask.TransferTime, 137 InitialWaitingTime = factTask.InitialWaitingTime, 138 NumCalculationRuns = factTask.NumCalculationRuns, 139 NumRetries = factTask.NumRetries, 140 CoresRequired = factTask.CoresRequired, 141 MemoryRequired = factTask.MemoryRequired, 142 Priority = factTask.Priority, 143 State = factTask.TaskState.ToString(), 144 LastClientId = factTask.LastClientId, 145 LastClientName = a != null ? a.Name : string.Empty, 146 UserId = isAdministrator ? dimJob.UserId : default(Guid), 147 UserName = isAdministrator ? dimJob.UserName : string.Empty, 148 StartTime = factTask.StartTime, 149 EndTime = factTask.EndTime, 150 Exception = isAdministrator ? factTask.Exception : string.Empty 151 }) 152 .OrderByDescending(x => x.EndTime ?? DateTime.MaxValue) 153 .Skip((page - 1) * size) 154 .Take(size) 155 .ToList() 156 }; 157 }); 158 } 110 var pm = PersistenceManager; 111 var dimJobDao = pm.DimJobDao; 112 var dimClientDao = pm.DimClientDao; 113 var factTaskDao = pm.FactTaskDao; 114 return pm.UseTransaction(() => { 115 var tasks = factTaskDao.GetByClientId(id).Where(x => states.Contains(x.TaskState.ToString())); 116 if (userId != Guid.Empty) { 117 tasks = tasks.Where(x => x.DimJob.UserId == userId); 118 } 119 return new DT.TaskPage { 120 TotalTasks = tasks.Count(), 121 Tasks = (from factTask in tasks 122 join dimJob in dimJobDao.GetAll() on factTask.JobId equals dimJob.JobId 123 join dimClient in dimClientDao.GetAll() on factTask.LastClientId equals 124 dimClient.Id into taskClientJoin 125 from a in taskClientJoin.DefaultIfEmpty() 126 let startTime = factTask.StartTime ?? DateTime.Now 127 let endTime = factTask.EndTime ?? DateTime.Now 128 select new DT.Task { 129 Id = isAdministrator ? factTask.TaskId : default(Guid), 130 JobId = isAdministrator ? factTask.JobId : default(Guid), 131 JobName = isAdministrator ? dimJob.JobName : string.Empty, 132 TotalTime = (long)(endTime - startTime).TotalSeconds, 133 CalculatingTime = factTask.CalculatingTime, 134 WaitingTime = factTask.WaitingTime, 135 TransferTime = factTask.TransferTime, 136 InitialWaitingTime = factTask.InitialWaitingTime, 137 NumCalculationRuns = factTask.NumCalculationRuns, 138 NumRetries = factTask.NumRetries, 139 CoresRequired = factTask.CoresRequired, 140 MemoryRequired = factTask.MemoryRequired, 141 Priority = factTask.Priority, 142 State = factTask.TaskState.ToString(), 143 LastClientId = factTask.LastClientId, 144 LastClientName = a != null ? a.Name : string.Empty, 145 UserId = isAdministrator ? dimJob.UserId : default(Guid), 146 UserName = isAdministrator ? dimJob.UserName : string.Empty, 147 StartTime = factTask.StartTime, 148 EndTime = factTask.EndTime, 149 Exception = isAdministrator ? factTask.Exception : string.Empty 150 }) 151 .OrderByDescending(x => x.EndTime ?? DateTime.MaxValue) 152 .Skip((page - 1) * size) 153 .Take(size) 154 .ToList() 155 }; 156 }); 159 157 } 160 158 161 159 public HttpResponseMessage GetTaskDataById(Guid id) { 162 using (var pm = PersistenceManager) { 163 var taskDataDao = pm.TaskDataDao; 164 return pm.UseTransaction(() => { 165 var taskData = taskDataDao.GetById(id); 166 if (taskData == null) 167 return new HttpResponseMessage(HttpStatusCode.NotFound); 168 HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); 169 var stream = new MemoryStream(taskData.Data); 170 result.Content = new StreamContent(stream); 171 result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); 172 result.Content.Headers.ContentDisposition = 173 new ContentDispositionHeaderValue("attachment") { 174 FileName = string.Format("{0}.hl", id) 175 }; 176 return result; 177 }); 178 } 160 var pm = PersistenceManager; 161 var taskDataDao = pm.TaskDataDao; 162 return pm.UseTransaction(() => { 163 var taskData = taskDataDao.GetById(id); 164 if (taskData == null) 165 return new HttpResponseMessage(HttpStatusCode.NotFound); 166 HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); 167 var stream = new MemoryStream(taskData.Data); 168 result.Content = new StreamContent(stream); 169 result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); 170 result.Content.Headers.ContentDisposition = 171 new ContentDispositionHeaderValue("attachment") { 172 FileName = string.Format("{0}.hl", id) 173 }; 174 return result; 175 }); 179 176 } 180 177 } -
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/UserController.cs
r12562 r12858 37 37 38 38 public IEnumerable<DT.User> GetUsers() { 39 using (var pm = PersistenceManager) { 40 var dimUserDao = pm.DimUserDao; 41 return pm.UseTransaction(() => { 42 return dimUserDao.GetAll().Select(x => new DT.User { 43 Id = x.UserId, 44 Name = x.Name 45 }).ToList(); 46 }); 47 } 39 var pm = PersistenceManager; 40 var dimUserDao = pm.DimUserDao; 41 return pm.UseTransaction(() => { 42 return dimUserDao.GetAll().Select(x => new DT.User { 43 Id = x.UserId, 44 Name = x.Name 45 }).ToList(); 46 }); 48 47 } 49 48 50 49 public DT.UserDetails GetUser(Guid id) { 51 using (var pm = PersistenceManager) { 52 var dimUserDao = pm.DimUserDao; 53 var factTaskDao = pm.FactTaskDao; 54 return pm.UseTransaction(() => { 55 var user = dimUserDao.GetById(id); 56 if (user != null) { 57 return new DT.UserDetails { 58 Id = user.UserId, 59 Name = user.Name, 60 TasksStates = factTaskDao.GetByUserId(id) 61 .GroupBy(x => x.TaskState) 62 .Select(x => new DT.TaskStateCount { 63 State = x.Key.ToString(), 64 Count = x.Count() 65 }).ToList() 66 }; 67 } 68 return null; 69 }); 70 } 50 var pm = PersistenceManager; 51 var dimUserDao = pm.DimUserDao; 52 var factTaskDao = pm.FactTaskDao; 53 return pm.UseTransaction(() => { 54 var user = dimUserDao.GetById(id); 55 if (user != null) { 56 return new DT.UserDetails { 57 Id = user.UserId, 58 Name = user.Name, 59 TasksStates = factTaskDao.GetByUserId(id) 60 .GroupBy(x => x.TaskState) 61 .Select(x => new DT.TaskStateCount { 62 State = x.Key.ToString(), 63 Count = x.Count() 64 }).ToList() 65 }; 66 } 67 return null; 68 }); 71 69 } 72 70 }
Note: See TracChangeset
for help on using the changeset viewer.