- Timestamp:
- 04/23/13 10:37:45 (11 years ago)
- Location:
- branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3
- Property svn:ignore
-
old new 2 2 bin 3 3 obj 4 *.user
-
- Property svn:ignore
-
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/HiveDtoDao.cs
r9385 r9391 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Data.Linq;25 24 using System.Linq; 26 25 using System.Linq.Expressions; … … 28 27 29 28 namespace HeuristicLab.Services.Hive.DataAccess { 30 public class HiveD ao : IHiveDao {29 public class HiveDtoDao : IHiveDtoDao { 31 30 public static HiveDataContext CreateContext(bool longRunning = false) { 32 31 var context = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); … … 35 34 } 36 35 37 public HiveD ao() { }36 public HiveDtoDao() { } 38 37 39 38 #region Task Methods … … 43 42 } 44 43 } 45 46 public Task GetTaskDA(Guid id) {47 var db = HiveOperationContext.Current.DataContext;48 return GetTaskByIdQuery(db, id).SingleOrDefault();49 }50 51 private static Func<HiveDataContext, Guid, IQueryable<Task>> GetTaskByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid id) =>52 from t in db.Tasks53 where t.TaskId == id54 select t55 );56 44 57 45 public IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate) { … … 150 138 db.SubmitChanges(); 151 139 } 152 }153 154 public void UpdateTaskDA(Task task) {155 var db = HiveOperationContext.Current.DataContext;156 db.SubmitChanges();157 140 } 158 141 … … 212 195 } 213 196 214 public IQueryable<TaskInfoForScheduler> GetWaitingTasksDA(Slave slave) {215 var db = HiveOperationContext.Current.DataContext;216 217 var parentResources = GetParentResourcesDA(slave.ResourceId);218 var resourceIds = parentResources.Select(x => x.ResourceId);219 //Originally we checked here if there are parent tasks which should be calculated (with GetParentTasks(resourceIds, count, false);).220 //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated),221 //we skip this step because it's wasted runtime222 223 return from ar in db.AssignedResources224 where resourceIds.Contains(ar.ResourceId)225 && !(ar.Task.IsParentTask && ar.Task.FinishWhenChildJobsFinished)226 && ar.Task.State == TaskState.Waiting227 && ar.Task.CoresNeeded <= slave.FreeCores228 && ar.Task.MemoryNeeded <= slave.FreeMemory229 select new TaskInfoForScheduler() { TaskId = ar.Task.TaskId, JobId = ar.Task.JobId, Priority = ar.Task.Priority };230 }231 232 /*private static Func<HiveDataContext, Guid, Slave, IQueryable<TaskInfoForScheduler>> GetWaitingTasksQuery = CompiledQuery.Compile((HiveDataContext db, Guid id, Slave slave) =>233 from ar in db.AssignedResources234 where ar.ResourceId == id235 && !(ar.Task.IsParentTask && ar.Task.FinishWhenChildJobsFinished)236 && ar.Task.State == TaskState.Waiting237 && ar.Task.CoresNeeded <= slave.FreeCores238 && ar.Task.MemoryNeeded <= slave.FreeMemory239 select new TaskInfoForScheduler() { TaskId = ar.Task.TaskId, JobId = ar.Task.JobId, Priority = ar.Task.Priority }240 );*/241 242 197 public DT.Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) { 243 198 using (var db = CreateContext()) { … … 267 222 return DT.Convert.ToDto(task); 268 223 } 269 }270 271 public Task UpdateTaskStateDA(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) {272 var db = HiveOperationContext.Current.DataContext;273 274 db.StateLogs.InsertOnSubmit(new StateLog {275 TaskId = taskId,276 State = taskState,277 SlaveId = slaveId,278 UserId = userId,279 Exception = exception,280 DateTime = DateTime.Now281 });282 283 var task = GetTaskDA(taskId);284 task.State = taskState;285 286 db.SubmitChanges();287 288 return task;289 224 } 290 225 #endregion … … 581 516 } 582 517 583 public Slave GetSlaveDA(Guid id) {584 var db = HiveOperationContext.Current.DataContext;585 return GetSlaveByIdQuery(db, id).SingleOrDefault();586 }587 588 private static Func<HiveDataContext, Guid, IQueryable<Slave>> GetSlaveByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid slaveId) =>589 from s in db.Resources.OfType<Slave>()590 where s.ResourceId == slaveId591 select s592 );593 594 518 public IEnumerable<DT.Slave> GetSlaves(Expression<Func<Slave, bool>> predicate) { 595 519 using (var db = CreateContext()) { … … 614 538 db.SubmitChanges(); 615 539 } 616 }617 618 public void UpdateSlaveDA(Slave slave) {619 var db = HiveOperationContext.Current.DataContext;620 db.SubmitChanges();621 540 } 622 541 … … 736 655 } 737 656 738 public IQueryable<Guid> GetAssignedResourcesIdsDA(Guid taskId) {739 var db = HiveOperationContext.Current.DataContext;740 return GetAssignedResourcesIdQuery(db, taskId);741 }742 743 private static Func<HiveDataContext, Guid, IQueryable<Guid>> GetAssignedResourcesIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) =>744 from ar in db.AssignedResources745 where ar.TaskId == taskId746 select ar.ResourceId747 );748 749 657 /// <summary> 750 658 /// Returns all parent resources of a resource (the given resource is also added) … … 757 665 } 758 666 } 759 760 public IEnumerable<Resource> GetParentResourcesDA(Guid resourceId) {761 var db = HiveOperationContext.Current.DataContext;762 var child = db.Resources.Single(r => r.ResourceId == resourceId);763 764 yield return child;765 while (child.ParentResource != null) {766 child = child.ParentResource;767 yield return child;768 }769 }770 771 public IEnumerable<Guid> GetParentResourcesIDsDA(Guid resourceId) {772 var db = HiveOperationContext.Current.DataContext;773 var child = db.Resources.Single(r => r.ResourceId == resourceId);774 775 yield return resourceId;776 while (child.ParentResource != null) {777 child = child.ParentResource;778 yield return child.ResourceId;779 }780 }781 782 public IQueryable<int> GetNumberOfDowntimesFromParentResourcesAtCurrentTimeDA(Guid resourceId, DowntimeType type) {783 var db = HiveOperationContext.Current.DataContext;784 785 var ids = GetParentResourcesIDsDA(resourceId).ToArray();786 787 return from r in db.Resources788 where ids.Contains(r.ResourceId)789 select (from d in db.Downtimes790 where d.ResourceId == r.ResourceId && d.DowntimeType == type && (DateTime.Now >= d.StartDate) && (DateTime.Now <= d.EndDate)791 select d).Count();792 }793 794 /*private static Func<HiveDataContext, Guid, DowntimeType, int> GetNumberOfDowntimesAtCurrentTimeQuery =795 CompiledQuery.Compile((HiveDataContext db, Guid ids, DowntimeType type) =>796 (from d in db.Downtimes797 where d.ResourceId == ids && d.DowntimeType == type && (DateTime.Now >= d.StartDate) && (DateTime.Now <= d.EndDate)798 select d).Count()799 );*/800 667 801 668 private static void CollectParentResources(ICollection<Resource> resources, Resource resource) {
Note: See TracChangeset
for help on using the changeset viewer.