Changeset 16386 for branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs
- Timestamp:
- 12/15/18 12:07:16 (6 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Services.Hive
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs
r15583 r16386 37 37 public void GenerateStatistics() { 38 38 using (var pm = new PersistenceManager()) { 39 40 pm.UseTransaction(() => { 41 UpdateDimProjectTable(pm); 42 pm.SubmitChanges(); 43 }); 44 39 45 pm.UseTransaction(() => { 40 46 UpdateDimUserTable(pm); 47 41 48 UpdateDimJobTable(pm); 42 49 UpdateDimClientsTable(pm); … … 54 61 UpdateFactClientInfoTable(time, pm); 55 62 pm.SubmitChanges(); 63 UpdateFactProjectInfoTable(time, pm); 64 pm.SubmitChanges(); 56 65 }); 57 66 58 67 pm.UseTransaction(() => { 59 Update TaskFactsTable(pm);68 UpdateFactTaskTable(pm); 60 69 try { 61 70 pm.SubmitChanges(); … … 72 81 }); 73 82 } 83 84 pm.UseTransaction(() => { 85 FlagJobsForDeletion(pm); 86 pm.SubmitChanges(); 87 }); 74 88 } 75 89 } … … 106 120 } 107 121 122 // add new projects 123 // delete expired projects 124 // update information of existing projects 125 private void UpdateDimProjectTable(PersistenceManager pm) { 126 var projectDao = pm.ProjectDao; 127 var dimProjectDao = pm.DimProjectDao; 128 129 var projects = projectDao.GetAll().ToList(); 130 var dimProjects = dimProjectDao.GetAllOnlineProjects().ToList(); 131 132 var onlineProjects = dimProjects.Where(x => projects.Select(y => y.ProjectId).Contains(x.ProjectId)); 133 var addedProjects = projects.Where(x => !dimProjects.Select(y => y.ProjectId).Contains(x.ProjectId)); 134 var removedProjects = dimProjects.Where(x => !projects.Select(y => y.ProjectId).Contains(x.ProjectId)); 135 136 // set expiration time of removed projects 137 foreach (var p in removedProjects) { 138 p.DateExpired = DateTime.Now; 139 } 140 141 // add new projects 142 dimProjectDao.Save(addedProjects.Select(x => new DimProject { 143 ProjectId = x.ProjectId, 144 ParentProjectId = x.ParentProjectId, 145 Name = x.Name, 146 Description = x.Description, 147 OwnerUserId = x.OwnerUserId, 148 StartDate = x.StartDate, 149 EndDate = x.EndDate, 150 DateCreated = x.DateCreated, 151 DateExpired = null 152 })); 153 154 // expire project if its parent has changed and create a new entry 155 // otherwise perform "normal" update 156 foreach (var dimP in onlineProjects) { 157 var p = projects.Where(x => x.ProjectId == dimP.ProjectId).SingleOrDefault(); 158 if (p != null) { 159 if (dimP.ParentProjectId == null ? p.ParentProjectId != null : dimP.ParentProjectId != p.ParentProjectId) { // or: (!object.Equals(dimP.ParentProjectId, p.ParentProjectId)) 160 dimP.DateExpired = DateTime.Now; 161 dimProjectDao.Save(new DimProject { 162 ProjectId = p.ProjectId, 163 ParentProjectId = p.ParentProjectId, 164 Name = p.Name, 165 Description = p.Description, 166 OwnerUserId = p.OwnerUserId, 167 StartDate = p.StartDate, 168 EndDate = p.EndDate, 169 DateCreated = p.DateCreated, 170 DateExpired = null 171 }); 172 } else { 173 dimP.Name = p.Name; 174 dimP.Description = p.Description; 175 dimP.OwnerUserId = p.OwnerUserId; 176 dimP.StartDate = p.StartDate; 177 dimP.EndDate = p.EndDate; 178 } 179 } 180 } 181 } 182 108 183 private void UpdateDimJobTable(PersistenceManager pm) { 184 var dimProjectDao = pm.DimProjectDao; 109 185 var dimJobDao = pm.DimJobDao; 110 186 var jobDao = pm.JobDao; … … 118 194 JobName = x.Name ?? string.Empty, 119 195 DateCreated = x.DateCreated, 196 ProjectId = dimProjectDao.GetLastValidIdByProjectId(x.ProjectId), 120 197 TotalTasks = taskDao.GetAll().Count(y => y.JobId == x.JobId) 121 198 }) … … 127 204 UserName = GetUserName(x.UserId), 128 205 DateCreated = x.DateCreated, 206 ProjectId = x.ProjectId, 129 207 TotalTasks = x.TotalTasks, 130 208 CompletedTasks = 0, … … 134 212 135 213 private void UpdateExistingDimJobs(PersistenceManager pm) { 214 var dimProjectDao = pm.DimProjectDao; 136 215 var jobDao = pm.JobDao; 137 216 var dimJobDao = pm.DimJobDao; … … 151 230 } 152 231 } 232 var job = jobDao.GetById(dimJob.JobId); 153 233 if (totalTasks == completedTasks) { 154 234 var completeDate = factTaskDao.GetLastCompletedTaskFromJob(dimJob.JobId); 155 235 if (completeDate == null) { 156 if (job Dao.GetById(dimJob.JobId)== null) {236 if (job == null) { 157 237 completeDate = DateTime.Now; 158 238 } … … 160 240 dimJob.DateCompleted = completeDate; 161 241 } 242 if(job != null) { 243 dimJob.JobName = job.Name; 244 dimJob.ProjectId = dimProjectDao.GetLastValidIdByProjectId(job.ProjectId); 245 } 246 162 247 dimJob.TotalTasks = totalTasks; 163 248 dimJob.CompletedTasks = completedTasks; … … 165 250 } 166 251 252 private void FlagJobsForDeletion(PersistenceManager pm) { 253 var jobDao = pm.JobDao; 254 var jobs = jobDao.GetJobsReadyForDeletion(); 255 foreach(var job in jobs) { 256 job.State = JobState.DeletionPending; 257 } 258 } 259 167 260 private void UpdateDimClientsTable(PersistenceManager pm) { 168 261 var dimClientDao = pm.DimClientDao; 169 var slaveDao = pm.SlaveDao; 170 var slaves = slaveDao.GetAll(); 171 var recentlyAddedClients = dimClientDao.GetActiveClients(); 172 var slaveIds = slaves.Select(x => x.ResourceId); 173 174 var removedClientIds = recentlyAddedClients 175 .Where(x => !slaveIds.Contains(x.ResourceId)) 176 .Select(x => x.Id); 177 var modifiedClients = 178 from slave in slaves 179 join client in recentlyAddedClients on slave.ResourceId equals client.ResourceId 180 where (slave.Name != client.Name 181 || slave.ParentResourceId == null && client.ResourceGroupId != null // because both can be null and null comparison 182 || slave.ParentResourceId != null && client.ResourceGroupId == null // does return no entry on the sql server 183 || slave.ParentResourceId != client.ResourceGroupId 184 || ((slave.ParentResource != null) && slave.ParentResource.ParentResourceId != client.ResourceGroup2Id)) 185 select new { 186 SlaveId = slave.ResourceId, 187 ClientId = client.Id 188 }; 189 var clientIds = dimClientDao.GetActiveClients().Select(x => x.ResourceId); 190 var modifiedClientIds = modifiedClients.Select(x => x.SlaveId); 191 var newClients = slaves 192 .Where(x => !clientIds.Contains(x.ResourceId) 193 || modifiedClientIds.Contains(x.ResourceId)) 194 .Select(x => new { 195 x.ResourceId, 196 x.Name, 197 ResourceGroupId = x.ParentResourceId, 198 GroupName = x.ParentResource != null ? x.ParentResource.Name : null, 199 ResourceGroup2Id = x.ParentResource != null ? x.ParentResource.ParentResourceId : null, 200 GroupName2 = x.ParentResource != null ? x.ParentResource.ParentResource != null ? x.ParentResource.ParentResource.Name : null : null 201 }) 202 .ToList(); 203 204 var clientsToUpdate = removedClientIds.Union(modifiedClients.Select(x => x.ClientId)); 205 dimClientDao.UpdateExpirationTime(clientsToUpdate, DateTime.Now); 206 dimClientDao.Save(newClients.Select(x => new DimClient { 262 var resourceDao = pm.ResourceDao; 263 264 var resources = resourceDao.GetAll().ToList(); 265 var dimClients = dimClientDao.GetAllOnlineClients().ToList(); 266 267 var onlineClients = dimClients.Where(x => resources.Select(y => y.ResourceId).Contains(x.ResourceId)); 268 var addedResources = resources.Where(x => !dimClients.Select(y => y.ResourceId).Contains(x.ResourceId)); 269 var removedResources = dimClients.Where(x => !resources.Select(y => y.ResourceId).Contains(x.ResourceId)); 270 271 // set expiration time of removed resources 272 foreach(var r in removedResources) { 273 r.DateExpired = DateTime.Now; 274 } 275 276 // add new resources 277 dimClientDao.Save(addedResources.Select(x => new DimClient { 207 278 ResourceId = x.ResourceId, 279 ParentResourceId = x.ParentResourceId, 208 280 Name = x.Name, 209 ExpirationTime = null, 210 ResourceGroupId = x.ResourceGroupId, 211 GroupName = x.GroupName, 212 ResourceGroup2Id = x.ResourceGroup2Id, 213 GroupName2 = x.GroupName2 281 ResourceType = x.ResourceType, 282 DateCreated = DateTime.Now, 283 DateExpired = null 214 284 })); 215 } 285 286 // expire client if its parent has changed and create a new entry 287 // otherwise perform "normal" update 288 foreach(var dimc in onlineClients) { 289 var r = resources.Where(x => x.ResourceId == dimc.ResourceId).SingleOrDefault(); 290 if(r != null) { 291 if(dimc.ParentResourceId == null ? r.ParentResourceId != null : dimc.ParentResourceId != r.ParentResourceId) { 292 var now = DateTime.Now; 293 dimc.DateExpired = now; 294 dimClientDao.Save(new DimClient { 295 ResourceId = r.ResourceId, 296 ParentResourceId = r.ParentResourceId, 297 Name = r.Name, 298 ResourceType = r.ResourceType, 299 DateCreated = now, 300 DateExpired = null 301 }); 302 } else { 303 dimc.Name = r.Name; 304 } 305 } 306 } 307 } 308 309 //// (1) for new slaves (not yet reported in Table DimClients) ... 310 //// and modified slaves (name or parent resource changed) a new DimClient-entry is created 311 //// (2) for already reported removed and modifid clients the expiration date is set 312 //private void UpdateDimClientsTableOld(PersistenceManager pm) { 313 // var dimClientDao = pm.DimClientDao; 314 // var slaveDao = pm.SlaveDao; 315 // var slaves = slaveDao.GetAll(); 316 // var recentlyAddedClients = dimClientDao.GetAllOnlineClients(); 317 // var slaveIds = slaves.Select(x => x.ResourceId); 318 319 // var removedClientIds = recentlyAddedClients 320 // .Where(x => !slaveIds.Contains(x.ResourceId)) 321 // .Select(x => x.Id); 322 // var modifiedClients = 323 // from slave in slaves 324 // join client in recentlyAddedClients on slave.ResourceId equals client.ResourceId 325 // where (slave.Name != client.Name 326 // || slave.ParentResourceId == null && client.ResourceGroupId != null // because both can be null and null comparison 327 // || slave.ParentResourceId != null && client.ResourceGroupId == null // does return no entry on the sql server 328 // || slave.ParentResourceId != client.ResourceGroupId 329 // || ((slave.ParentResource != null) && slave.ParentResource.ParentResourceId != client.ResourceGroup2Id)) 330 // select new { 331 // SlaveId = slave.ResourceId, 332 // ClientId = client.Id 333 // }; 334 // var clientIds = dimClientDao.GetAllOnlineClients().Select(x => x.ResourceId); 335 // var modifiedClientIds = modifiedClients.Select(x => x.SlaveId); 336 // var newClients = slaves 337 // .Where(x => !clientIds.Contains(x.ResourceId) 338 // || modifiedClientIds.Contains(x.ResourceId)) 339 // .Select(x => new { 340 // x.ResourceId, 341 // x.Name, 342 // ResourceGroupId = x.ParentResourceId, 343 // GroupName = x.ParentResource != null ? x.ParentResource.Name : null, 344 // ResourceGroup2Id = x.ParentResource != null ? x.ParentResource.ParentResourceId : null, 345 // GroupName2 = x.ParentResource != null ? x.ParentResource.ParentResource != null ? x.ParentResource.ParentResource.Name : null : null 346 // }) 347 // .ToList(); 348 349 // var clientsToUpdate = removedClientIds.Union(modifiedClients.Select(x => x.ClientId)); 350 // dimClientDao.UpdateExpirationTime(clientsToUpdate, DateTime.Now); 351 // dimClientDao.Save(newClients.Select(x => new DimClient { 352 // ResourceId = x.ResourceId, 353 // Name = x.Name, 354 // ExpirationTime = null, 355 // ResourceGroupId = x.ResourceGroupId, 356 // GroupName = x.GroupName, 357 // ResourceGroup2Id = x.ResourceGroup2Id, 358 // GroupName2 = x.GroupName2 359 // })); 360 //} 361 216 362 217 363 private void UpdateFactClientInfoTable(DimTime newTime, PersistenceManager pm) { … … 222 368 var newRawFactInfos = 223 369 from s in slaveDao.GetAll() 224 join c in dimClientDao.GetA ctiveClients() on s.ResourceId equals c.ResourceId370 join c in dimClientDao.GetAllOnlineSlaves() on s.ResourceId equals c.ResourceId 225 371 join lcf in factClientInfoDao.GetLastUpdateTimestamps() on c.ResourceId equals lcf.ResourceId into joinCf 226 372 from cf in joinCf.DefaultIfEmpty() … … 261 407 } 262 408 263 private void UpdateTaskFactsTable(PersistenceManager pm) { 409 private void UpdateFactProjectInfoTable(DimTime newTime, PersistenceManager pm) { 410 var factProjectInfoDao = pm.FactProjectInfoDao; 411 var dimProjectDao = pm.DimProjectDao; 412 var projectDao = pm.ProjectDao; 413 414 var projectAvailabilityStats = projectDao.GetAvailabilityStatsPerProject(); 415 var projectUsageStats = projectDao.GetUsageStatsPerProject(); 416 var dimProjects = dimProjectDao.GetAllOnlineProjects().ToList(); 417 418 factProjectInfoDao.Save( 419 from dimp in dimProjects 420 let aStats = projectAvailabilityStats.Where(x => x.ProjectId == dimp.ProjectId).SingleOrDefault() 421 let uStats = projectUsageStats.Where(x => x.ProjectId == dimp.ProjectId).SingleOrDefault() 422 select new FactProjectInfo { 423 ProjectId = dimp.Id, 424 DimTime = newTime, 425 NumTotalCores = aStats != null ? aStats.Cores : 0, 426 TotalMemory = aStats != null ? aStats.Memory : 0, 427 NumUsedCores = uStats != null ? uStats.Cores : 0, 428 UsedMemory = uStats != null ? uStats.Memory : 0 429 } 430 ); 431 } 432 433 private void UpdateFactTaskTable(PersistenceManager pm) { 264 434 var factTaskDao = pm.FactTaskDao; 265 435 var taskDao = pm.TaskDao; … … 267 437 268 438 var factTaskIds = factTaskDao.GetAll().Select(x => x.TaskId); 269 var notFinishedFactTasks = factTaskDao.GetNotFinishedTasks().Select(x => new { 270 x.TaskId, 271 x.LastClientId 272 }); 273 274 var newTasks = 439 var notFinishedFactTasks = factTaskDao.GetNotFinishedTasks(); 440 //var notFinishedFactTasks = factTaskDao.GetNotFinishedTasks().Select(x => new { 441 // x.TaskId, 442 // x.LastClientId 443 //}); 444 445 // query several properties for all new and not finished tasks 446 // in order to use them later either... 447 // (1) to update the fact task entry of not finished tasks 448 // (2) to insert a new fact task entry for new tasks 449 var newAndNotFinishedTasks = 275 450 (from task in taskDao.GetAllChildTasks() 276 451 let stateLogs = task.StateLogs.OrderByDescending(x => x.DateTime) … … 280 455 join lastFactTask in notFinishedFactTasks on task.TaskId equals lastFactTask.TaskId into lastFactPerTask 281 456 from lastFact in lastFactPerTask.DefaultIfEmpty() 282 join client in dimClientDao.GetA ctiveClients() on lastSlaveId equals client.ResourceId into clientsPerSlaveId457 join client in dimClientDao.GetAllOnlineClients() on lastSlaveId equals client.ResourceId into clientsPerSlaveId 283 458 from client in clientsPerSlaveId.DefaultIfEmpty() 284 459 select new { … … 296 471 }).ToList(); 297 472 298 //insert facts for new tasks 473 // (1) update data of already existing facts 474 // i.e. for all in newAndNotFinishedTasks where NotFinishedTask = true 475 foreach (var notFinishedFactTask in notFinishedFactTasks) { 476 var nfftUpdate = newAndNotFinishedTasks.Where(x => x.TaskId == notFinishedFactTask.TaskId).SingleOrDefault(); 477 if(nfftUpdate != null) { 478 var taskData = CalculateFactTaskData(nfftUpdate.StateLogs); 479 480 notFinishedFactTask.StartTime = taskData.StartTime; 481 notFinishedFactTask.EndTime = taskData.EndTime; 482 notFinishedFactTask.LastClientId = nfftUpdate.LastClientId; 483 notFinishedFactTask.Priority = nfftUpdate.Priority; 484 notFinishedFactTask.CoresRequired = nfftUpdate.CoresRequired; 485 notFinishedFactTask.MemoryRequired = nfftUpdate.MemoryRequired; 486 notFinishedFactTask.NumCalculationRuns = taskData.CalculationRuns; 487 notFinishedFactTask.NumRetries = taskData.Retries; 488 notFinishedFactTask.WaitingTime = taskData.WaitingTime; 489 notFinishedFactTask.CalculatingTime = taskData.CalculatingTime; 490 notFinishedFactTask.TransferTime = taskData.TransferTime; 491 notFinishedFactTask.TaskState = nfftUpdate.State; 492 notFinishedFactTask.Exception = taskData.Exception; 493 notFinishedFactTask.InitialWaitingTime = taskData.InitialWaitingTime; 494 } 495 } 496 497 // (2) insert facts for new tasks 498 // i.e. for all in newAndNotFinishedTasks where NotFinishedTask = false 299 499 factTaskDao.Save( 300 from x in new Tasks500 from x in newAndNotFinishedTasks 301 501 where !x.NotFinishedTask 302 502 let taskData = CalculateFactTaskData(x.StateLogs) … … 320 520 }); 321 521 322 //update data of already existing facts 323 foreach (var notFinishedTask in factTaskDao.GetNotFinishedTasks()) { 324 var ntc = newTasks.Where(x => x.TaskId == notFinishedTask.TaskId); 325 if (ntc.Any()) { 326 var x = ntc.Single(); 327 var taskData = CalculateFactTaskData(x.StateLogs); 328 329 notFinishedTask.StartTime = taskData.StartTime; 330 notFinishedTask.EndTime = taskData.EndTime; 331 notFinishedTask.LastClientId = x.LastClientId; 332 notFinishedTask.Priority = x.Priority; 333 notFinishedTask.CoresRequired = x.CoresRequired; 334 notFinishedTask.MemoryRequired = x.MemoryRequired; 335 notFinishedTask.NumCalculationRuns = taskData.CalculationRuns; 336 notFinishedTask.NumRetries = taskData.Retries; 337 notFinishedTask.WaitingTime = taskData.WaitingTime; 338 notFinishedTask.CalculatingTime = taskData.CalculatingTime; 339 notFinishedTask.TransferTime = taskData.TransferTime; 340 notFinishedTask.TaskState = x.State; 341 notFinishedTask.Exception = taskData.Exception; 342 notFinishedTask.InitialWaitingTime = taskData.InitialWaitingTime; 343 } 344 } 522 523 ////update data of already existing facts 524 //foreach (var notFinishedTask in factTaskDao.GetNotFinishedTasks()) { 525 // var ntc = newTasks.Where(x => x.TaskId == notFinishedTask.TaskId); 526 // if (ntc.Any()) { 527 // var x = ntc.Single(); 528 // var taskData = CalculateFactTaskData(x.StateLogs); 529 530 // notFinishedTask.StartTime = taskData.StartTime; 531 // notFinishedTask.EndTime = taskData.EndTime; 532 // notFinishedTask.LastClientId = x.LastClientId; 533 // notFinishedTask.Priority = x.Priority; 534 // notFinishedTask.CoresRequired = x.CoresRequired; 535 // notFinishedTask.MemoryRequired = x.MemoryRequired; 536 // notFinishedTask.NumCalculationRuns = taskData.CalculationRuns; 537 // notFinishedTask.NumRetries = taskData.Retries; 538 // notFinishedTask.WaitingTime = taskData.WaitingTime; 539 // notFinishedTask.CalculatingTime = taskData.CalculatingTime; 540 // notFinishedTask.TransferTime = taskData.TransferTime; 541 // notFinishedTask.TaskState = x.State; 542 // notFinishedTask.Exception = taskData.Exception; 543 // notFinishedTask.InitialWaitingTime = taskData.InitialWaitingTime; 544 // } 545 //} 345 546 } 346 547
Note: See TracChangeset
for help on using the changeset viewer.