Changeset 5404 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs
- Timestamp:
- 02/01/11 15:51:11 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs
r5402 r5404 82 82 } 83 83 84 public IEnumerable<DT.Job> GetWaitingParentJobs(Guid slaveId) { 85 using (var db = CreateContext()) { 86 // todo: slaveId is unused! 84 public IEnumerable<DT.Job> GetWaitingParentJobs(IEnumerable<Guid> resourceIds, int count) { 85 using (var db = CreateContext()) { 87 86 var query = from ar in db.AssignedResources 88 where ar.Job.JobState == JobState.WaitingForChildJobs && 89 (from child in db.Jobs 90 where child.ParentJobId == ar.Job.JobId 91 select child.JobState == JobState.Finished).All(x => x) && 92 (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet) 93 where child.ParentJobId == ar.Job.JobId 94 select child).Count() > 0 87 where resourceIds.Contains(ar.ResourceId) 88 && ar.Job.JobState == JobState.WaitingForChildJobs 89 && (from child in db.Jobs 90 where child.ParentJobId == ar.Job.JobId 91 select child.JobState == JobState.Finished).All(x => x) 92 && (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet) 93 where child.ParentJobId == ar.Job.JobId 94 select child).Count() > 0 95 95 orderby ar.Job.Priority descending 96 96 select Convert.ToDto(ar.Job); 97 return query.ToArray(); 98 } 99 } 100 101 public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave) { 102 using (var db = CreateContext()) { 103 var query = from j in db.Jobs 104 where j.JobState == JobState.Waiting && j.CoresNeeded <= slave.FreeCores && j.MemoryNeeded <= slave.FreeMemory 105 orderby j.Priority descending 106 select Convert.ToDto(j); 107 var waitingJobs = query.ToArray(); 108 var waitingParentJobs = GetWaitingParentJobs(slave.Id); 97 return count == 0 ? query.ToArray() : query.Take(count).ToArray(); 98 } 99 } 100 101 public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count) { 102 using (var db = CreateContext()) { 103 var resourceIds = GetParentResources(slave.Id).Select(r => r.Id); 104 var waitingParentJobs = GetWaitingParentJobs(resourceIds, count); 105 if (count > 0 && waitingParentJobs.Count() >= count) return waitingParentJobs.Take(count).ToArray(); 106 107 var query = from ar in db.AssignedResources 108 where resourceIds.Contains(ar.ResourceId) 109 && ar.Job.JobState == JobState.Waiting 110 && ar.Job.CoresNeeded <= slave.FreeCores 111 && ar.Job.MemoryNeeded <= slave.FreeMemory 112 orderby ar.Job.Priority descending 113 select Convert.ToDto(ar.Job); 114 var waitingJobs = (count == 0 ? query : query.Take(count)).ToArray(); 109 115 return waitingJobs.Union(waitingParentJobs).OrderByDescending(x => x.Priority); 110 116 } … … 350 356 using (var db = CreateContext()) { 351 357 var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == id); 352 if (entity != null) db.Resources.DeleteOnSubmit(entity); 358 if (entity != null) { 359 if (db.Resources.Where(r => r.ParentResourceId == id).Count() > 0) { 360 throw new DaoException("Cannot delete SlaveGroup as long as there are Slaves in the group"); 361 } 362 db.Resources.DeleteOnSubmit(entity); 363 } 353 364 db.SubmitChanges(); 354 365 } … … 408 419 return job.AssignedResources.Select(x => Convert.ToDto(x.Resource)).ToArray(); 409 420 } 421 } 422 423 /// <summary> 424 /// Returns all parent resources of a resource (the given resource is also added) 425 /// </summary> 426 private IEnumerable<DT.Resource> GetParentResources(Guid resourceId) { 427 using (var db = CreateContext()) { 428 var resources = new List<Resource>(); 429 CollectParentResources(resources, db.Resources.Where(r => r.ResourceId == resourceId).Single()); 430 return resources.Select(r => Convert.ToDto(r)).ToArray(); 431 } 432 } 433 434 private void CollectParentResources(List<Resource> resources, Resource resource) { 435 if (resource == null) return; 436 resources.Add(resource); 437 CollectParentResources(resources, resource.ParentResource); 410 438 } 411 439 #endregion
Note: See TracChangeset
for help on using the changeset viewer.