- Timestamp:
- 01/04/13 16:29:03 (12 years ago)
- Location:
- branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r8687 r9109 141 141 <Compile Include="Interfaces\IHiveDao.cs" /> 142 142 <Compile Include="Interfaces\ITaskScheduler.cs" /> 143 <Compile Include="Scheduler\JobInfoForScheduler.cs" /> 143 144 <Compile Include="Scheduler\RoundRobinTaskScheduler.cs" /> 144 145 <Compile Include="Settings.cs" /> -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/HiveDao.cs
r8707 r9109 49 49 } 50 50 51 public IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate) { 52 List<DT.LightweightTask> tasks = new List<DT.LightweightTask>(); 53 54 using (var db = CreateContext()) { 55 var tasksQuery = db.Tasks.Where(predicate).Select(task => new { task.TaskId, task.ExecutionTimeMs, task.ParentTaskId, task.StateLogs, task.State, task.Command }); 56 var taskDatasQuery = db.Tasks.Where(predicate).Where(task => task.JobData != null).Select(task => new { task.TaskId, task.JobData.LastUpdate }); 57 58 foreach (var task in tasksQuery) { 59 DT.LightweightTask t = new DT.LightweightTask(); 60 t.Id = task.TaskId; 61 t.ExecutionTime = TimeSpan.FromMilliseconds(task.ExecutionTimeMs); 62 t.ParentTaskId = task.ParentTaskId; 63 t.StateLog = task.StateLogs == null ? new List<DT.StateLog>() : task.StateLogs.Select(x => DataTransfer.Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList(); 64 t.State = DataTransfer.Convert.ToDto(task.State); 65 t.Command = DataTransfer.Convert.ToDto(task.Command); 66 t.LastTaskDataUpdate = taskDatasQuery.Where(x => x.TaskId == task.TaskId).Count() > 0 ? taskDatasQuery.Select(x => x.LastUpdate).First() : DateTime.MinValue; 67 tasks.Add(t); 68 } 69 } 70 return tasks; 71 } 72 51 73 public Guid AddTask(DT.Task dto) { 52 74 using (var db = CreateContext()) { … … 255 277 } 256 278 279 public IEnumerable<JobInfoForScheduler> GetJobInfoForScheduler(Expression<Func<Job, bool>> predicate) { 280 using (var db = CreateContext()) { 281 return db.Jobs.Where(predicate).Select(x => new JobInfoForScheduler() { Id = x.JobId, DateCreated = x.DateCreated, OwnerUserId = x.OwnerUserId }).ToArray(); 282 } 283 } 284 257 285 public Guid AddJob(DT.Job dto) { 258 286 using (var db = CreateContext()) { 259 287 var entity = DT.Convert.ToEntity(dto); 260 288 db.Jobs.InsertOnSubmit(entity); 261 if (!db. Jobs.Any(x => x.OwnerUserId == dto.OwnerUserId))289 if (!db.UserPriorities.Any(x => x.UserId == dto.OwnerUserId)) 262 290 EnqueueUserPriority(new DT.UserPriority { Id = dto.OwnerUserId, DateEnqueued = dto.DateCreated }); 263 291 db.SubmitChanges(); … … 592 620 public IEnumerable<DT.Resource> GetChildResources(Guid resourceId) { 593 621 using (var db = CreateContext()) { 594 var childs = new List<DT.Resource>(); 595 foreach (var child in db.Resources.Where(x => x.ParentResourceId == resourceId)) { 596 childs.Add(DT.Convert.ToDto(child)); 597 childs.AddRange(GetChildResources(child.ResourceId)); 598 } 599 return childs; 600 } 622 return CollectChildResources(resourceId, db); 623 } 624 } 625 626 public IEnumerable<DT.Resource> CollectChildResources(Guid resourceId, HiveDataContext db) { 627 var childs = new List<DT.Resource>(); 628 foreach (var child in db.Resources.Where(x => x.ParentResourceId == resourceId)) { 629 childs.Add(DT.Convert.ToDto(child)); 630 childs.AddRange(CollectChildResources(child.ResourceId, db)); 631 } 632 return childs; 601 633 } 602 634 … … 779 811 if (entity != null) db.Statistics.DeleteOnSubmit(entity); 780 812 db.SubmitChanges(); 813 } 814 } 815 816 public Dictionary<Guid, int> GetWaitingTasksByUser() { 817 using (var db = CreateContext()) { 818 var waitingTasksByUser = from task in db.Tasks 819 where task.State == TaskState.Waiting 820 group task by task.Job.OwnerUserId into g 821 select new { UserId = g.Key, UsedCores = g.Count() }; 822 return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores); 823 } 824 } 825 826 public Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds) { 827 using (var db = CreateContext()) { 828 var waitingTasksByUser = from task in db.Tasks 829 where task.State == TaskState.Waiting && task.AssignedResources.Any(x => resourceIds.Contains(x.ResourceId)) 830 group task by task.Job.OwnerUserId into g 831 select new { UserId = g.Key, UsedCores = g.Count() }; 832 return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores); 833 } 834 } 835 836 public Dictionary<Guid, int> GetCalculatingTasksByUser() { 837 using (var db = CreateContext()) { 838 var calculatingTasksByUser = from task in db.Tasks 839 where task.State == TaskState.Calculating 840 group task by task.Job.OwnerUserId into g 841 select new { UserId = g.Key, UsedCores = g.Count() }; 842 return calculatingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores); 843 } 844 } 845 846 public Dictionary<Guid, int> GetCalculatingTasksByUserForResources(List<Guid> resourceIds) { 847 using (var db = CreateContext()) { 848 var calculatingTasksByUser = from task in db.Tasks 849 where task.State == TaskState.Calculating && task.AssignedResources.Any(x => resourceIds.Contains(x.ResourceId)) 850 group task by task.Job.OwnerUserId into g 851 select new { UserId = g.Key, UsedCores = g.Count() }; 852 return calculatingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores); 781 853 } 782 854 } -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/HiveService.cs
r8687 r9109 128 128 129 129 return trans.UseTransaction(() => { 130 return dao.Get Tasks(x => x.JobId == jobId).Select(x => new LightweightTask(x)).ToArray();130 return dao.GetLightweightTasks(task => task.JobId == jobId).ToArray(); 131 131 }, false, false); 132 132 } -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDao.cs
r8707 r9109 31 31 DT.Task GetTask(Guid id); 32 32 IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate); 33 IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate); 33 34 Guid AddTask(DT.Task dto); 34 35 void UpdateTask(DT.Task dto); … … 58 59 DT.Job GetJob(Guid id); 59 60 IEnumerable<DT.Job> GetJobs(Expression<Func<Job, bool>> predicate); 61 IEnumerable<JobInfoForScheduler> GetJobInfoForScheduler(Expression<Func<Job, bool>> predicate); 60 62 Guid AddJob(DT.Job dto); 61 63 void UpdateJob(DT.Job dto); … … 145 147 146 148 #region Statistics Methods 149 Dictionary<Guid, int> GetWaitingTasksByUser(); 150 Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds); 151 Dictionary<Guid, int> GetCalculatingTasksByUser(); 152 Dictionary<Guid, int> GetCalculatingTasksByUserForResources(List<Guid> resourceIds); 147 153 DT.Statistics GetStatistic(Guid id); 148 154 IEnumerable<DT.Statistics> GetStatistics(Expression<Func<Statistics, bool>> predicate); -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r8997 r9109 87 87 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned."); 88 88 } 89 catch (Exception ex) { 90 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager threw an exception in ProcessHeartbeat: " + ex.ToString()); 91 } 89 92 finally { 90 93 if (mutexAquired) mutex.ReleaseMutex(); -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs
r8998 r9109 36 36 var userPriorities = dao.GetUserPriorities(x => true).OrderBy(x => x.DateEnqueued).ToArray(); 37 37 38 var jobs = new List<Job >();38 var jobs = new List<JobInfoForScheduler>(); 39 39 foreach (var userPriority in userPriorities) { 40 jobs.AddRange(dao.GetJob s(x => x.OwnerUserId == userPriority.Id));40 jobs.AddRange(dao.GetJobInfoForScheduler(x => x.OwnerUserId == userPriority.Id)); 41 41 } 42 42 … … 44 44 task => task.JobId, 45 45 job => job.Id, 46 (task, job) => new { Task = task, Job = job })46 (task, job) => new { Task = task, JobInfo = job }) 47 47 .OrderByDescending(x => x.Task.Priority) 48 48 .ToList(); … … 55 55 for (int i = 0; i < count; i++) { 56 56 var defaultEntry = taskJobRelations.First(); // search first task which is not included yet 57 var priorityEntries = taskJobRelations.Where(x => x.Job .OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); // search for tasks with desired user priority57 var priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); // search for tasks with desired user priority 58 58 while (!priorityEntries.Any() && ++priorityIndex < userPriorities.Length) 59 priorityEntries = taskJobRelations.Where(x => x.Job .OwnerUserId == userPriorities[priorityIndex].Id).ToArray();59 priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); 60 60 if (priorityEntries.Any()) { // tasks with desired user priority found 61 var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.Job .DateCreated).First();61 var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.JobInfo.DateCreated).First(); 62 62 if (defaultEntry.Task.Priority <= priorityEntry.Task.Priority) { 63 63 taskJobRelations.Remove(priorityEntry);
Note: See TracChangeset
for help on using the changeset viewer.