Changeset 15969
- Timestamp:
- 06/21/18 15:27:56 (6 years ago)
- Location:
- branches/2839_HiveProjectManagement
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.cs
r15966 r15969 30 30 using HeuristicLab.Data.Views; 31 31 using HeuristicLab.Data; 32 using HeuristicLab.Clients.Hive.Views; 32 33 33 34 namespace HeuristicLab.Clients.Hive.Administrator.Views { … … 38 39 private const string JOB_NAME = "Name"; 39 40 private const string JOB_OWNER = "Owner"; 41 private const string JOB_OWNERID = "Owner Id"; 40 42 private const string JOB_DATECREATED = "Date Created"; 41 43 private const string JOB_STATE = "State"; 42 44 private const string JOB_DESCRIPTION = "Description"; 45 private const string JOB_TASKCOUNT = "Tasks"; 46 private const string JOB_CALCULATINGTASKCOUNT = "Calculating"; 47 private const string JOB_FINISHEDTASKCOUNT = "Finished"; 48 49 50 private readonly Color onlineStatusColor = Color.FromArgb(255, 189, 249, 143); // #bdf98f 51 private readonly Color onlineStatusColor2 = Color.FromArgb(255, 157, 249, 143); // #9df98f 52 private readonly Color statisticsPendingStatusColor = Color.FromArgb(255, 249, 210, 145); // #f9d291 53 private readonly Color deletionPendingStatusColor = Color.FromArgb(255, 249, 172, 144); // #f9ac90 54 private readonly Color deletionPendingStatusColor2 = Color.FromArgb(255, 249, 149, 143); // #f9958f 43 55 44 56 public new Project Content { … … 47 59 } 48 60 49 public ProjectJobsView() /*: base()*/{61 public ProjectJobsView() { 50 62 InitializeComponent(); 63 64 removeButton.Enabled = false; 65 matrixView.DataGridView.SelectionChanged += DataGridView_SelectionChanged; 66 } 67 68 private void DataGridView_SelectionChanged(object sender, EventArgs e) { 69 if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return; 70 71 bool anyDeletable = false; 72 foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) { 73 if (((string)r.Cells[0].Value) == JobState.Online.ToString()) anyDeletable = true; 74 } 75 76 removeButton.Enabled = anyDeletable; 51 77 } 52 78 … … 54 80 protected override void OnContentChanged() { 55 81 base.OnContentChanged(); 82 removeButton.Enabled = false; 56 83 UpdateJobs(); 57 84 } … … 61 88 62 89 refreshButton.Enabled = enabled; 63 removeButton.Enabled = enabled;90 removeButton.Enabled = false; 64 91 matrixView.Enabled = enabled; 65 92 } … … 72 99 73 100 private void refreshButton_Click(object sender, EventArgs e) { 74 HiveAdminClient.Instance.Refresh(); 75 // Update list/matrix 101 RefreshJobs(); 76 102 } 77 103 78 104 private async void removeButton_Click(object sender, EventArgs e) { 79 // remove selected job(s) 105 if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return; 106 107 var jobNamesToDelete = new List<string>(); 108 var jobIdsToDelete = new List<Guid>(); 109 foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) { 110 if(((string)r.Cells[0].Value) == JobState.Online.ToString()) { 111 jobNamesToDelete.Add(" - " + ((string)r.Cells[3].Value)); 112 jobIdsToDelete.Add(Guid.Parse((string)r.Cells[8].Value)); 113 } 114 } 115 116 if(jobIdsToDelete.Any()) { 117 var result = MessageBox.Show("Do you really want to remove following job(s):\n\n" 118 + String.Join("\n", jobNamesToDelete), 119 "HeuristicLab Hive Administrator", 120 MessageBoxButtons.YesNo, 121 MessageBoxIcon.Question); 122 123 if (result == DialogResult.Yes) { 124 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 125 action: () => { 126 DeleteJobs(jobIdsToDelete); 127 }, 128 finallyCallback: () => { 129 matrixView.DataGridView.ClearSelection(); 130 removeButton.Enabled = false; 131 RefreshJobs(); 132 }); 133 } 134 } 80 135 } 81 136 … … 83 138 84 139 #region Helpers 140 private void RefreshJobs() { 141 HiveAdminClient.Instance.RefreshJobs(); 142 UpdateJobs(); 143 } 144 85 145 private StringMatrix CreateValueMatrix() { 86 146 var jobs = HiveAdminClient.Instance.Jobs[Content.Id]; 87 string[,] values = new string[jobs.Count, 7]; 147 var resources = HiveAdminClient.Instance.Resources; 148 string[,] values = new string[jobs.Count, 10]; 88 149 89 150 for(int i = 0; i < jobs.Count; i++) { 90 151 var job = jobs.ElementAt(i); 91 values[i, 0] = job.Id.ToString(); 92 values[i, 1] = job.Name; 93 values[i, 2] = job.OwnerUserId.ToString(); 94 values[i, 3] = job.OwnerUsername; 95 values[i, 4] = job.DateCreated.ToString(); 96 values[i, 5] = job.State.ToString(); 97 values[i, 6] = job.Description; 98 } 99 152 153 values[i, 0] = job.State.ToString(); 154 values[i, 1] = job.DateCreated.ToString(); 155 values[i, 2] = job.OwnerUsername; 156 values[i, 3] = job.Name; 157 values[i, 4] = job.JobCount.ToString(); 158 values[i, 5] = job.CalculatingCount.ToString(); 159 values[i, 6] = job.FinishedCount.ToString(); 160 values[i, 7] = job.Description; 161 values[i, 8] = job.Id.ToString(); 162 values[i, 9] = job.OwnerUserId.ToString(); 163 } 164 100 165 var matrix = new StringMatrix(values); 101 matrix.ColumnNames = new string[] { JOB_ ID, JOB_NAME, JOB_OWNER, JOB_OWNER, JOB_DATECREATED, JOB_STATE, JOB_DESCRIPTION};166 matrix.ColumnNames = new string[] { JOB_STATE, JOB_DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID }; 102 167 matrix.SortableView = true; 103 168 return matrix; 104 169 } 105 170 106 171 private void UpdateJobs() { 107 172 if (InvokeRequired) Invoke((Action)UpdateJobs); … … 115 180 } 116 181 matrixView.Content = matrix; 182 183 foreach(DataGridViewRow row in matrixView.DataGridView.Rows) { 184 string val = ((string)row.Cells[0].Value); 185 if (val == JobState.Online.ToString()) { 186 row.DefaultCellStyle.BackColor = onlineStatusColor; 187 } else if(val == JobState.StatisticsPending.ToString()) { 188 row.DefaultCellStyle.BackColor = statisticsPendingStatusColor; 189 } else if(val == JobState.DeletionPending.ToString()) { 190 row.DefaultCellStyle.BackColor = deletionPendingStatusColor; 191 } 192 } 193 117 194 matrixView.DataGridView.AutoResizeColumns(); 118 //foreach(DataGridViewColumn col in matrixView.DataGridView.Columns) { 119 // col.Width = -2; 120 //} 195 matrixView.DataGridView.Columns[0].MinimumWidth = 90; 196 matrixView.DataGridView.Columns[1].MinimumWidth = 108; 197 } 198 } 199 200 private void DeleteJobs(List<Guid> jobIds) { 201 try { 202 HiveAdminClient.DeleteJobs(jobIds); 203 } catch (AnonymousUserException) { 204 ShowHiveInformationDialog(); 205 } 206 } 207 208 private void ShowHiveInformationDialog() { 209 if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog); 210 else { 211 using (HiveInformationDialog dialog = new HiveInformationDialog()) { 212 dialog.ShowDialog(this); 213 } 121 214 } 122 215 } -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r15966 r15969 79 79 } 80 80 81 82 //private Dictionary<Guid, HashSet<Project>> projectAncestors;83 //public Dictionary<Guid, HashSet<Project>> ProjectAncestors {84 // get { return projectAncestors; }85 //}86 87 //private Dictionary<Guid, HashSet<Project>> projectDescendants;88 //public Dictionary<Guid, HashSet<Project>> ProjectDescendants {89 // get { return projectDescendants; }90 //}91 92 //private Dictionary<Guid, HashSet<Resource>> resourceAncestors;93 //public Dictionary<Guid, HashSet<Resource>> ResourceAncestors {94 // get { return resourceAncestors; }95 //}96 97 //private Dictionary<Guid, HashSet<Resource>> resourceDescendants;98 //public Dictionary<Guid, HashSet<Resource>> ResourceDescendants {99 // get { return resourceDescendants; }100 //}101 102 81 private Dictionary<Guid, HashSet<Guid>> projectAncestors; 103 82 public Dictionary<Guid, HashSet<Guid>> ProjectAncestors { … … 160 139 .ForEach(a => projectResourceAssignments.Add(a)); 161 140 projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection<Job>())); 162 service.GetJobsByProjectIds(projectIds) 163 .ForEach(j => jobs[j.ProjectId].Add(j)); 141 var unsortedJobs = service.GetJobsByProjectIds(projectIds) 142 .OrderBy(x => x.DateCreated).ToList(); 143 144 unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 145 unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 146 unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 164 147 } 165 148 }); … … 264 247 } 265 248 249 public void RefreshJobs() { 250 var projectIds = new List<Guid>(); 251 jobs = new Dictionary<Guid, HiveItemCollection<Job>>(); 252 253 HiveServiceLocator.Instance.CallHiveService(service => { 254 service.GetProjectsForAdministration().ForEach(p => projectIds.Add(p.Id)); 255 if(projectIds.Any()) { 256 projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection<Job>())); 257 var unsortedJobs = service.GetJobsByProjectIds(projectIds) 258 .OrderBy(x => x.DateCreated).ToList(); 259 unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 260 unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 261 unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 262 } 263 }); 264 } 265 266 public void SortJobs() { 267 for(int i = 0; i < jobs.Count; i++) { 268 var projectId = jobs.Keys.ElementAt(i); 269 var unsortedJobs = jobs.Values.ElementAt(i); 270 271 var sortedJobs = new HiveItemCollection<Job>(); 272 sortedJobs.AddRange(unsortedJobs.Where(j => j.State == JobState.DeletionPending)); 273 sortedJobs.AddRange(unsortedJobs.Where(j => j.State == JobState.StatisticsPending)); 274 sortedJobs.AddRange(unsortedJobs.Where(j => j.State == JobState.Online)); 275 276 jobs[projectId] = sortedJobs; 277 } 278 } 279 266 280 #endregion 267 281 … … 331 345 HiveServiceLocator.Instance.CallHiveService((s) => s.DeleteProject(item.Id)); 332 346 } 347 } 348 349 public static void DeleteJobs(List<Guid> jobIds) { 350 351 HiveServiceLocator.Instance.CallHiveService((s) => s.UpdateJobStates(jobIds, JobState.StatisticsPending)); 333 352 } 334 353 #endregion -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveServiceClient.cs
r15966 r15969 75 75 76 76 public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; 77 77 78 78 } 79 79 … … 2400 2400 void UpdateJobState(System.Guid JobId, HeuristicLab.Clients.Hive.JobState jobState); 2401 2401 2402 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/UpdateJobStates", ReplyAction="http://tempuri.org/IHiveService/UpdateJobStatesResponse")] 2403 void UpdateJobStates(System.Collections.Generic.List<System.Guid> jobIds, HeuristicLab.Clients.Hive.JobState jobState); 2404 2402 2405 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetAssignedResourcesForJob", ReplyAction="http://tempuri.org/IHiveService/GetAssignedResourcesForJobResponse")] 2403 2406 System.Collections.Generic.List<HeuristicLab.Clients.Hive.AssignedJobResource> GetAssignedResourcesForJob(System.Guid jobId); … … 2686 2689 } 2687 2690 2691 public void UpdateJobStates(System.Collections.Generic.List<System.Guid> jobIds, HeuristicLab.Clients.Hive.JobState jobState) 2692 { 2693 base.Channel.UpdateJobStates(jobIds, jobState); 2694 } 2695 2688 2696 public System.Collections.Generic.List<HeuristicLab.Clients.Hive.AssignedJobResource> GetAssignedResourcesForJob(System.Guid jobId) 2689 2697 { -
branches/2839_HiveProjectManagement/HeuristicLab.Services.Access/3.3/UserManager.cs
r15577 r15969 46 46 public string GetUserNameById(Guid userId) { 47 47 var user = GetUserById(userId); 48 if (user != null ) {48 if (user != null && !string.IsNullOrWhiteSpace(user.UserName)) { 49 49 return user.UserName; 50 50 } else { -
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.