Changeset 4368 for branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs
- Timestamp:
- 09/07/10 10:22:27 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs
r4333 r4368 73 73 Job j = DtoToEntity(job.JobInfo, null); 74 74 j.SerializedJob = job.SerializedJobData; 75 foreach (Guid assignRessourceId in job.JobInfo.AssignedResourceIds)76 j.AssignedResources.Add(new AssignedResource { ResourceId = assignRessourceId });75 //foreach (Guid assignRessourceId in job.JobInfo.AssignedResourceIds) 76 // j.AssignedResources.Add(new AssignedResource { ResourceId = assignRessourceId }); 77 77 Context.Jobs.InsertOnSubmit(j); 78 78 CommitChanges(); … … 98 98 j.JobState == Enum.GetName(typeof(JobState), JobState.Aborted) || 99 99 j.JobState == Enum.GetName(typeof(JobState), JobState.SnapshotRequested) || 100 j.JobState == Enum.GetName(typeof(JobState), JobState.SnapshotSent)) && 100 j.JobState == Enum.GetName(typeof(JobState), JobState.SnapshotSent) || 101 j.JobState == Enum.GetName(typeof(JobState), JobState.WaitForChildJobs)) && 101 102 (j.ResourceId.Equals(slave.Id)) 102 103 select EntityToDto(j, null)).ToList(); 103 104 } 104 105 105 public IEnumerable<JobDto> FindFittingJobs ForSlave(JobState state, int freeCores, int freeMemory, Guid slaveId) {106 public IEnumerable<JobDto> FindFittingJobs(JobState state, int freeCores, int freeMemory, Guid slaveId) { 106 107 SlaveGroupDao cgd = new SlaveGroupDao(); 107 108 … … 111 112 112 113 var q = (from ar in Context.AssignedResources 113 where ar.Job.JobState == Enum.GetName(typeof(JobState), JobState.Offline) &&114 where ar.Job.JobState == Enum.GetName(typeof(JobState), state) && 114 115 ar.Job.CoresNeeded <= freeCores && 115 116 ar.Job.MemoryNeeded <= freeMemory && … … 120 121 } 121 122 123 public IEnumerable<JobDto> FindJobsWithFinishedChilds(Guid slaveId) { 124 SlaveGroupDao cgd = new SlaveGroupDao(); 125 126 List<Guid> idList = new List<Guid>(cgd.FindAllGroupAndParentGroupIdsForSlave(slaveId)); 127 //Add myself too - enables jobs for one specific host! 128 idList.Add(slaveId); 129 130 var query = from ar in Context.AssignedResources 131 where ar.Job.JobState == Enum.GetName(typeof(JobState), JobState.WaitForChildJobs) && 132 (from child in Context.Jobs 133 where child.ParentJobId == ar.Job.JobId 134 select child.JobState == Enum.GetName(typeof(JobState), JobState.Finished)).All(x => x) 135 orderby ar.Job.Priority descending 136 select EntityToDto(ar.Job, null); 137 var list = query.ToList(); 138 return list; 139 } 140 122 141 public IEnumerable<JobDto> GetJobsByState(JobState state) { 123 142 return (from j in Context.Jobs … … 127 146 128 147 public void AssignSlaveToJob(Guid slaveId, Guid jobId) { 129 Slave c= Context.Resources.OfType<Slave>().SingleOrDefault(slave => slave.ResourceId.Equals(slaveId));148 Slave s = Context.Resources.OfType<Slave>().SingleOrDefault(slave => slave.ResourceId.Equals(slaveId)); 130 149 Job j = Context.Jobs.SingleOrDefault(job => job.JobId.Equals(jobId)); 131 c.Jobs.Add(j); 132 j.Slave = c; 150 s.Jobs.Add(j); 151 j.Slave = s; 152 CommitChanges(); 153 } 154 155 public void UnAssignSlaveToJob(Guid jobId) { 156 Job j = Context.Jobs.SingleOrDefault(job => job.JobId.Equals(jobId)); 157 j.Slave = null; 133 158 CommitChanges(); 134 159 } … … 153 178 } 154 179 155 public bool IsUserAuthorizedForJobs( stringuserId, params Guid[] jobIds) {180 public bool IsUserAuthorizedForJobs(Guid userId, params Guid[] jobIds) { 156 181 var jobs = from job in Context.Jobs 157 182 where jobIds.Contains(job.JobId) … … 159 184 return jobs.All(job => job.UserId == userId); 160 185 } 186 187 public IEnumerable<JobDto> FindJobsByParentId(Guid? parentJobId, bool recursive) { 188 IQueryable<JobDto> query = from job in Context.Jobs 189 where parentJobId == null ? !job.ParentJobId.HasValue : job.ParentJobId.Value == parentJobId 190 select EntityToDto(job, null); 191 List<JobDto> jobs = query.ToList(); 192 if (recursive) { 193 List<JobDto> childs = new List<JobDto>(); 194 foreach (JobDto job in jobs) { 195 childs.AddRange(FindJobsByParentId(job.Id, recursive)); 196 } 197 jobs.AddRange(childs); 198 } 199 return jobs; 200 } 201 161 202 #endregion 162 203 … … 181 222 target.JobState = Enum.GetName(typeof(JobState), source.State); 182 223 target.UserId = source.UserId; 224 if (source.ParentJob != null) { 225 target.ParentJobId = source.ParentJob.Id; 226 } 227 228 foreach (Guid assignRessourceId in source.AssignedResourceIds) { 229 if (!target.AssignedResources.Select(x => x.ResourceId).Contains(assignRessourceId)) { 230 target.AssignedResources.Add(new AssignedResource { ResourceId = assignRessourceId }); 231 } 232 } 233 183 234 return target; 184 235 } 185 236 186 //Assigned ressources are not used atm!187 237 //Slave is not used ATM - not sure when we stopped using those... 188 238 public override JobDto EntityToDto(Job source, JobDto target) { … … 199 249 target.DateFinished = source.DateFinished; 200 250 target.Id = source.JobId; 201 251 202 252 target.Exception = source.Exception; 203 253 target.Percentage = source.Percentage; … … 206 256 target.State = (JobState)Enum.Parse(typeof(JobState), source.JobState, true); 207 257 target.UserId = source.UserId; 258 259 if (source.ParentJobId.HasValue) { 260 target.ParentJob = new JobDto() { Id = source.ParentJobId.Value }; 261 } 262 target.AssignedResourceIds = source.AssignedResources.Select(x => x.ResourceId).ToList(); 263 208 264 return target; 209 265 }
Note: See TracChangeset
for help on using the changeset viewer.