- Timestamp:
- 10/18/18 14:07:32 (6 years ago)
- Location:
- branches/2931_OR-Tools_LP_MIP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2931_OR-Tools_LP_MIP
- Property svn:mergeinfo changed
/branches/2916_IndexedDataTableSerialization (added) merged: 15918 /trunk merged: 16168-16169,16177,16179,16184-16187,16202-16209,16211,16213,16216,16218-16219,16221,16223-16224,16232
- Property svn:mergeinfo changed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Clients.Hive merged: 16202,16204-16205,16208-16209
- Property svn:mergeinfo changed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r16139 r16235 26 26 using System.Collections.Generic; 27 27 using System.Linq; 28 using HeuristicLab.Clients.Access; 28 29 29 30 namespace HeuristicLab.Clients.Hive { … … 70 71 } 71 72 72 private Dictionary<Guid, HiveItemCollection< Job>> jobs;73 public Dictionary<Guid, HiveItemCollection< Job>> Jobs {73 private Dictionary<Guid, HiveItemCollection<RefreshableJob>> jobs; 74 public Dictionary<Guid, HiveItemCollection<RefreshableJob>> Jobs { 74 75 get { return jobs; } 75 76 set { … … 77 78 jobs = value; 78 79 } 80 } 81 82 private Dictionary<Guid, List<LightweightTask>> tasks; 83 public Dictionary<Guid, List<LightweightTask>> Tasks { 84 get { return tasks; } 79 85 } 80 86 … … 143 149 projects = new ItemList<Project>(); 144 150 projectResourceAssignments = new ItemList<AssignedProjectResource>(); 145 jobs = new Dictionary<Guid, HiveItemCollection<Job>>(); 151 jobs = new Dictionary<Guid, HiveItemCollection<RefreshableJob>>(); 152 tasks = new Dictionary<Guid, List<LightweightTask>>(); 146 153 projectNames = new Dictionary<Guid, string>(); 147 154 resourceNames = new Dictionary<Guid, string>(); … … 160 167 service.GetAssignedResourcesForProjectsAdministration(projectIds) 161 168 .ForEach(a => projectResourceAssignments.Add(a)); 162 projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection< Job>()));169 projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection<RefreshableJob>())); 163 170 var unsortedJobs = service.GetJobsByProjectIds(projectIds) 164 171 .OrderBy(x => x.DateCreated).ToList(); 165 172 166 unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 167 unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 168 unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 173 unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j))); 174 unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j))); 175 unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j))); 176 177 foreach (var job in jobs.SelectMany(x => x.Value)) 178 LoadLightweightJob(job); 169 179 170 180 projectNames = service.GetProjectNames(); … … 306 316 public void RefreshJobs() { 307 317 var projectIds = new List<Guid>(); 308 jobs = new Dictionary<Guid, HiveItemCollection<Job>>(); 318 jobs = new Dictionary<Guid, HiveItemCollection<RefreshableJob>>(); 319 tasks = new Dictionary<Guid, List<LightweightTask>>(); 309 320 310 321 HiveServiceLocator.Instance.CallHiveService(service => { 311 322 service.GetProjectsForAdministration().ForEach(p => projectIds.Add(p.Id)); 312 323 if(projectIds.Any()) { 313 projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection< Job>()));324 projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection<RefreshableJob>())); 314 325 var unsortedJobs = service.GetJobsByProjectIds(projectIds) 315 326 .OrderBy(x => x.DateCreated).ToList(); 316 unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 317 unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 318 unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(j)); 327 328 unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j))); 329 unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j))); 330 unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j))); 331 332 foreach(var job in jobs.SelectMany(x => x.Value)) 333 LoadLightweightJob(job); 319 334 } 320 335 }); 336 } 337 338 public void LoadLightweightJob(RefreshableJob refreshableJob) { 339 var job = refreshableJob.Job; 340 var lightweightTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(job.Id)); 341 342 if (tasks.ContainsKey(job.Id)) { 343 tasks[job.Id].Clear(); 344 tasks[job.Id].AddRange(lightweightTasks); 345 } else { 346 tasks.Add(job.Id, new List<LightweightTask>(lightweightTasks)); 347 } 348 349 if (lightweightTasks != null && lightweightTasks.Count > 0 && lightweightTasks.All(x => x.Id != Guid.Empty)) { 350 if (lightweightTasks.All(x => 351 x.State == TaskState.Finished 352 || x.State == TaskState.Aborted 353 || x.State == TaskState.Failed)) { 354 refreshableJob.ExecutionState = ExecutionState.Stopped; 355 refreshableJob.RefreshAutomatically = false; 356 } else if ( 357 lightweightTasks 358 .Where(x => x.ParentTaskId != null) 359 .All(x => 360 x.State != TaskState.Waiting 361 || x.State != TaskState.Transferring 362 || x.State != TaskState.Calculating) 363 && lightweightTasks 364 .Where(x => x.ParentTaskId != null) 365 .Any(x => x.State == TaskState.Paused)) { 366 refreshableJob.ExecutionState = ExecutionState.Paused; 367 refreshableJob.RefreshAutomatically = false; 368 } else if (lightweightTasks.Any(x => x.State == TaskState.Calculating 369 || x.State == TaskState.Transferring 370 || x.State == TaskState.Waiting)) { 371 refreshableJob.ExecutionState = ExecutionState.Started; 372 } 373 374 refreshableJob.ExecutionTime = TimeSpan.FromMilliseconds(lightweightTasks.Sum(x => x.ExecutionTime.TotalMilliseconds)); 375 } 321 376 } 322 377 … … 326 381 var unsortedJobs = jobs.Values.ElementAt(i); 327 382 328 var sortedJobs = new HiveItemCollection< Job>();329 sortedJobs.AddRange(unsortedJobs.Where(j => j. State == JobState.DeletionPending));330 sortedJobs.AddRange(unsortedJobs.Where(j => j. State == JobState.StatisticsPending));331 sortedJobs.AddRange(unsortedJobs.Where(j => j. State == JobState.Online));383 var sortedJobs = new HiveItemCollection<RefreshableJob>(); 384 sortedJobs.AddRange(unsortedJobs.Where(j => j.Job.State == JobState.DeletionPending)); 385 sortedJobs.AddRange(unsortedJobs.Where(j => j.Job.State == JobState.StatisticsPending)); 386 sortedJobs.AddRange(unsortedJobs.Where(j => j.Job.State == JobState.Online)); 332 387 333 388 jobs[projectId] = sortedJobs; … … 404 459 } 405 460 406 public static void DeleteJobs(List<Guid> jobIds) { 407 461 public static void RemoveJobs(List<Guid> jobIds) { 408 462 HiveServiceLocator.Instance.CallHiveService((s) => s.UpdateJobStates(jobIds, JobState.StatisticsPending)); 463 } 464 #endregion 465 466 #region Job Handling 467 468 public static void ResumeJob(RefreshableJob refreshableJob) { 469 HiveServiceLocator.Instance.CallHiveService(service => { 470 var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id); 471 foreach (var task in tasks) { 472 if (task.State == TaskState.Paused) { 473 service.RestartTask(task.Id); 474 } 475 } 476 }); 477 refreshableJob.ExecutionState = ExecutionState.Started; 478 } 479 480 public static void PauseJob(RefreshableJob refreshableJob) { 481 HiveServiceLocator.Instance.CallHiveService(service => { 482 var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id); 483 foreach (var task in tasks) { 484 if (task.State != TaskState.Finished && task.State != TaskState.Aborted && task.State != TaskState.Failed) 485 service.PauseTask(task.Id); 486 } 487 }); 488 refreshableJob.ExecutionState = ExecutionState.Paused; 489 } 490 491 public static void StopJob(RefreshableJob refreshableJob) { 492 HiveServiceLocator.Instance.CallHiveService(service => { 493 var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id); 494 foreach (var task in tasks) { 495 if (task.State != TaskState.Finished && task.State != TaskState.Aborted && task.State != TaskState.Failed) 496 service.StopTask(task.Id); 497 } 498 }); 499 refreshableJob.ExecutionState = ExecutionState.Stopped; 500 } 501 502 public static void RemoveJob(RefreshableJob refreshableJob) { 503 HiveServiceLocator.Instance.CallHiveService((service) => { 504 service.UpdateJobState(refreshableJob.Id, JobState.StatisticsPending); 505 }); 409 506 } 410 507 #endregion … … 436 533 if (resourceDescendants.ContainsKey(id)) return resources.Where(x => resourceDescendants[id].Contains(x.Id)); 437 534 else return Enumerable.Empty<Resource>(); 535 } 536 537 public IEnumerable<Resource> GetDisabledResourceAncestors(IEnumerable<Resource> availableResources) { 538 var missingParentIds = availableResources 539 .Where(x => x.ParentResourceId.HasValue) 540 .SelectMany(x => resourceAncestors[x.Id]).Distinct() 541 .Where(x => !availableResources.Select(y => y.Id).Contains(x)); 542 543 return resources.OfType<SlaveGroup>().Union(disabledParentResources).Where(x => missingParentIds.Contains(x.Id)); 438 544 } 439 545 … … 478 584 479 585 if(projectAncestors.ContainsKey(pro.Id)) { 480 return GetAvailableProjectAncestors(pro.Id).Where(x => x.OwnerUserId == userId).Any(); 586 return GetAvailableProjectAncestors(pro.Id).Any(x => x.OwnerUserId == userId); 587 } 588 589 if (pro.ParentProjectId != null && pro.ParentProjectId != Guid.Empty) { 590 var parent = projects.FirstOrDefault(x => x.Id == pro.ParentProjectId.Value); 591 if (parent != null) 592 return parent.OwnerUserId == userId || GetAvailableProjectAncestors(parent.Id).Any(x => x.OwnerUserId == userId); 481 593 } 482 594 … … 491 603 // ... or the new parent is not stored yet 492 604 // ... or there is not parental change 493 if (child == null 494 || (parent != null && parent.Id == Guid.Empty) 495 || (parent != null && parent.Id == child.ParentProjectId)) { 605 if (child == null 606 || (parent != null && parent.Id == Guid.Empty) 607 || (parent != null && parent.Id == child.ParentProjectId)) { 608 changePossible = false; 609 } else if (parent == null && !IsAdmin()) { 610 // ... if parent is null, but user is no admin (only admins are allowed to create root projects) 611 changePossible = false; 612 } else if (parent != null && (!IsAdmin() && parent.OwnerUserId != UserInformation.Instance.User.Id && !CheckOwnershipOfParentProject(parent, UserInformation.Instance.User.Id))) { 613 // ... if the user is no admin nor owner of the new parent or grand..grandparents 496 614 changePossible = false; 497 615 } else if(parent != null && projectDescendants.ContainsKey(child.Id)) { … … 525 643 return changePossible; 526 644 } 645 646 public IEnumerable<Resource> GetAssignedResourcesForJob(Guid jobId) { 647 var assignedJobResource = HiveServiceLocator.Instance.CallHiveService(service => service.GetAssignedResourcesForJob(jobId)); 648 return Resources.Where(x => assignedJobResource.Select(y => y.ResourceId).Contains(x.Id)); 649 } 650 651 private bool IsAdmin() { 652 return HiveRoles.CheckAdminUserPermissions(); 653 } 527 654 #endregion 528 655 }
Note: See TracChangeset
for help on using the changeset viewer.