- Timestamp:
- 06/21/18 15:27:56 (6 years ago)
- Location:
- branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15966 r15969 336 336 .Select(x => x.ToDto()) 337 337 .ToList(); 338 var statistics = taskDao.GetAll() 339 .Where(x => jobs.Select(y => y.Id).Contains(x.JobId)) 340 .GroupBy(x => x.JobId) 341 .Select(x => new { 342 x.Key, 343 TotalCount = x.Count(), 344 CalculatingCount = x.Count(y => y.State == DA.TaskState.Calculating), 345 FinishedCount = x.Count(y => CompletedStates.Contains(y.State)) 346 }) 347 .ToList(); 348 foreach (var job in jobs) { 349 var statistic = statistics.FirstOrDefault(x => x.Key == job.Id); 350 if (statistic != null) { 351 job.JobCount = statistic.TotalCount; 352 job.CalculatingCount = statistic.CalculatingCount; 353 job.FinishedCount = statistic.FinishedCount; 354 } 355 job.OwnerUsername = UserManager.GetUserNameById(job.OwnerUserId); 356 if (currentUserId == job.OwnerUserId) { 357 job.Permission = Permission.Full; 358 } else { 359 var jobPermission = jobPermissionDao.GetByJobAndUserId(job.Id, currentUserId); 360 job.Permission = jobPermission == null ? Permission.NotAllowed : jobPermission.Permission.ToDto(); 361 } 362 } 338 339 EvaluateJobs(pm, jobs); 363 340 return jobs; 364 341 }); … … 381 358 382 359 if(administrationGrantedProjects.Select(x => x.ProjectId).Contains(projectId)) { 383 returnjobDao.GetByProjectId(projectId)360 var jobs = jobDao.GetByProjectId(projectId) 384 361 .Select(x => x.ToDto()) 385 362 .ToList(); 363 364 EvaluateJobs(pm, jobs); 365 return jobs; 386 366 } else { 387 367 return Enumerable.Empty<DT.Job>(); … … 407 387 408 388 if(requestedAndGrantedProjectIds.Any()) { 409 returnjobDao.GetByProjectIds(requestedAndGrantedProjectIds)389 var jobs = jobDao.GetByProjectIds(requestedAndGrantedProjectIds) 410 390 .Select(x => x.ToDto()) 411 391 .ToList(); 392 393 EvaluateJobs(pm, jobs); 394 return jobs; 412 395 } else { 413 396 return Enumerable.Empty<DT.Job>(); … … 548 531 } 549 532 533 public void UpdateJobStates(IEnumerable<Guid> jobIds, DT.JobState jobState) { 534 if (jobState != JobState.StatisticsPending) return; // only process requests for "StatisticsPending" 535 536 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 537 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator); 538 var currentUserId = UserManager.CurrentUserId; 539 540 var pm = PersistenceManager; 541 using (new PerformanceLogger("UpdateJobsState")) { 542 var jobDao = pm.JobDao; 543 var projectDao = pm.ProjectDao; 544 pm.UseTransaction(() => { 545 foreach(var jobId in jobIds) { 546 var job = jobDao.GetById(jobId); 547 if (job != null) { 548 549 var administrationGrantedProjects = projectDao 550 .GetAdministrationGrantedProjectsForUser(currentUserId) 551 .ToList(); 552 553 // check if user is granted to administer the job-parenting project 554 if (isAdministrator || administrationGrantedProjects.Contains(job.Project)) { 555 // note: allow solely state changes from "Online" to "StatisticsPending" = deletion request by user for HiveStatisticGenerator 556 if (job.State == DA.JobState.Online) { 557 job.State = DA.JobState.StatisticsPending; 558 foreach (var task in job.Tasks 559 .Where(x => x.State == DA.TaskState.Waiting 560 || x.State == DA.TaskState.Paused 561 || x.State == DA.TaskState.Offline)) { 562 task.State = DA.TaskState.Aborted; 563 } 564 pm.SubmitChanges(); 565 } 566 } 567 } 568 } 569 }); 570 } 571 } 572 550 573 public IEnumerable<DT.AssignedJobResource> GetAssignedResourcesForJob(Guid jobId) { 551 574 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); … … 1738 1761 } 1739 1762 1763 private void EvaluateJobs(IPersistenceManager pm, IEnumerable<DT.Job> jobs) { 1764 if (jobs == null || !jobs.Any()) return; 1765 1766 var currentUserId = UserManager.CurrentUserId; 1767 var taskDao = pm.TaskDao; 1768 var jobPermissionDao = pm.JobPermissionDao; 1769 1770 var statistics = taskDao.GetAll() 1771 .Where(x => jobs.Select(y => y.Id).Contains(x.JobId)) 1772 .GroupBy(x => x.JobId) 1773 .Select(x => new { 1774 x.Key, 1775 TotalCount = x.Count(), 1776 CalculatingCount = x.Count(y => y.State == DA.TaskState.Calculating), 1777 FinishedCount = x.Count(y => CompletedStates.Contains(y.State)) 1778 }) 1779 .ToList(); 1780 1781 foreach (var job in jobs) { 1782 var statistic = statistics.FirstOrDefault(x => x.Key == job.Id); 1783 if (statistic != null) { 1784 job.JobCount = statistic.TotalCount; 1785 job.CalculatingCount = statistic.CalculatingCount; 1786 job.FinishedCount = statistic.FinishedCount; 1787 } 1788 1789 job.OwnerUsername = UserManager.GetUserNameById(job.OwnerUserId); 1790 1791 if (currentUserId == job.OwnerUserId) { 1792 job.Permission = Permission.Full; 1793 } else { 1794 var jobPermission = jobPermissionDao.GetByJobAndUserId(job.Id, currentUserId); 1795 job.Permission = jobPermission == null ? Permission.NotAllowed : jobPermission.Permission.ToDto(); 1796 } 1797 } 1798 } 1740 1799 #endregion 1741 1800 } -
branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
r15966 r15969 94 94 95 95 [OperationContract] 96 void UpdateJobStates(IEnumerable<Guid> jobIds, JobState jobState); 97 98 [OperationContract] 96 99 IEnumerable<AssignedJobResource> GetAssignedResourcesForJob(Guid jobId); 97 100 #endregion
Note: See TracChangeset
for help on using the changeset viewer.