Changeset 4267 for branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs
- Timestamp:
- 08/19/10 15:47:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs
r4264 r4267 10 10 11 11 namespace HeuristicLab.Hive.Server.LINQDataAccess { 12 public class JobDao : BaseDao<JobDto, Job>, IJobDao {13 12 public class JobDao : BaseDao<JobDto, Job>, IJobDao { 13 14 14 #region IGenericDao<JobDto,Job> Members 15 15 … … 28 28 IQueryable<JobDto> query = null; 29 29 if (jobState == JobState.Finished) { 30 31 where job.JobState == Enum.GetName(typeof(JobState), jobState)32 33 30 query = from job in Context.Jobs 31 where job.JobState == Enum.GetName(typeof(JobState), jobState) 32 orderby job.DateFinished 33 select EntityToDto(job, null); 34 34 } else if (jobState == JobState.Calculating || jobState == JobState.SnapshotRequested || jobState == JobState.SnapshotSent) { 35 35 query = from job in Context.Jobs 36 37 38 36 where job.JobState == Enum.GetName(typeof(JobState), jobState) 37 orderby job.DateCalculated 38 select EntityToDto(job, null); 39 39 } else { 40 40 query = from job in Context.Jobs 41 42 43 41 where job.JobState == Enum.GetName(typeof(JobState), jobState) 42 orderby job.DateCreated 43 select EntityToDto(job, null); 44 44 } 45 45 … … 74 74 j.SerializedJob = job.SerializedJobData; 75 75 foreach (Guid assignRessourceId in job.JobInfo.AssignedResourceIds) 76 j.AssignedResources.Add(new AssignedResource { ResourceId = assignRessourceId });76 j.AssignedResources.Add(new AssignedResource { ResourceId = assignRessourceId }); 77 77 Context.Jobs.InsertOnSubmit(j); 78 78 CommitChanges(); … … 89 89 public void Update(JobDto bObj) { 90 90 Job job = Context.Jobs.SingleOrDefault(j => j.JobId.Equals(bObj.Id)); 91 DtoToEntity(bObj, job); 92 CommitChanges(); 93 } 94 95 public IEnumerable<JobDto> FindActiveJobsOfSlave( ClientDto client) {91 DtoToEntity(bObj, job); 92 CommitChanges(); 93 } 94 95 public IEnumerable<JobDto> FindActiveJobsOfSlave(SlaveDto slave) { 96 96 return (from j in Context.Jobs 97 where (j.JobState == Enum.GetName(typeof 98 j.JobState == Enum.GetName(typeof 99 j.JobState == Enum.GetName(typeof 100 j.JobState == Enum.GetName(typeof 101 (j.ResourceId.Equals( client.Id))97 where (j.JobState == Enum.GetName(typeof(JobState), JobState.Calculating) || 98 j.JobState == Enum.GetName(typeof(JobState), JobState.Aborted) || 99 j.JobState == Enum.GetName(typeof(JobState), JobState.SnapshotRequested) || 100 j.JobState == Enum.GetName(typeof(JobState), JobState.SnapshotSent)) && 101 (j.ResourceId.Equals(slave.Id)) 102 102 select EntityToDto(j, null)).ToList(); 103 103 } 104 104 105 public IEnumerable<JobDto> FindFittingJobsForSlave(JobState state, int freeCores, int freeMemory, Guid clientId) {106 ClientGroupDao cgd = new ClientGroupDao();107 108 List<Guid> idList = new List<Guid>(cgd.FindAllGroupAndParentGroupIdsFor Client(clientId));105 public IEnumerable<JobDto> FindFittingJobsForSlave(JobState state, int freeCores, int freeMemory, Guid slaveId) { 106 SlaveGroupDao cgd = new SlaveGroupDao(); 107 108 List<Guid> idList = new List<Guid>(cgd.FindAllGroupAndParentGroupIdsForSlave(slaveId)); 109 109 //Add myself too - enables jobs for one specific host! 110 idList.Add( clientId);111 112 var q = (from ar in Context.AssignedResources 113 where ar.Job.JobState == Enum.GetName(typeof 110 idList.Add(slaveId); 111 112 var q = (from ar in Context.AssignedResources 113 where ar.Job.JobState == Enum.GetName(typeof(JobState), JobState.Offline) && 114 114 ar.Job.CoresNeeded <= freeCores && 115 115 ar.Job.MemoryNeeded <= freeMemory && 116 116 idList.Contains(ar.ResourceId) 117 orderby ar.Job.Priority descending 117 orderby ar.Job.Priority descending 118 118 select EntityToDto(ar.Job, null)); 119 119 return q.ToList(); … … 122 122 public IEnumerable<JobDto> GetJobsByState(JobState state) { 123 123 return (from j in Context.Jobs 124 where (j.JobState == Enum.GetName(typeof 124 where (j.JobState == Enum.GetName(typeof(JobState), state)) 125 125 select EntityToDto(j, null)).ToList(); 126 126 } 127 127 128 public void AssignSlaveToJob(Guid clientId, Guid jobId) {129 Client c = Context.Resources.OfType<Client>().SingleOrDefault(client => client.ResourceId.Equals(clientId));128 public void AssignSlaveToJob(Guid slaveId, Guid jobId) { 129 Slave c = Context.Resources.OfType<Slave>().SingleOrDefault(slave => slave.ResourceId.Equals(slaveId)); 130 130 Job j = Context.Jobs.SingleOrDefault(job => job.JobId.Equals(jobId)); 131 131 c.Jobs.Add(j); 132 j. Client= c;133 CommitChanges(); 132 j.Slave = c; 133 CommitChanges(); 134 134 } 135 135 136 136 public void SetJobOffline(JobDto job) { 137 137 Job j = Context.Jobs.SingleOrDefault(jq => jq.JobId.Equals(job.Id)); 138 j. Client= null;139 j.JobState = Enum.GetName(typeof(JobState), JobState.Offline); 138 j.Slave = null; 139 j.JobState = Enum.GetName(typeof(JobState), JobState.Offline); 140 140 CommitChanges(); 141 141 } 142 142 143 143 public Stream GetSerializedJobStream(Guid jobId) { 144 VarBinarySource source = 145 new VarBinarySource( 146 (SqlConnection)Context.Connection, null, 147 "Job", "SerializedJob", "JobId", jobId); 148 144 VarBinarySource source = new VarBinarySource((SqlConnection)Context.Connection, null, "Job", "SerializedJob", "JobId", jobId); 149 145 return new VarBinaryStream(source); 150 146 } … … 152 148 public IEnumerable<JobDto> FindJobsById(IEnumerable<Guid> jobIds) { 153 149 IQueryable<JobDto> jobs = from job in Context.Jobs 154 where jobIds.Contains(job.JobId)155 select EntityToDto(job, null);150 where jobIds.Contains(job.JobId) 151 select EntityToDto(job, null); 156 152 157 153 return jobs.ToList(); … … 182 178 183 179 //Assigned ressources are not used atm! 184 // Clientis not used ATM - not sure when we stopped using those...180 //Slave is not used ATM - not sure when we stopped using those... 185 181 public override JobDto EntityToDto(Job source, JobDto target) { 186 182 if (source == null) 187 183 return null; 188 if (target == null)184 if (target == null) 189 185 target = new JobDto(); 190 186 191 187 //target.ParentJob = null; 192 188 //target.PluginsNeeded = null; 193 //target. Client= null;189 //target.Slave = null; 194 190 //target.Project = null; 195 191 196 192 target.CoresNeeded = source.CoresNeeded; 197 193 target.MemoryNeeded = source.MemoryNeeded; … … 204 200 target.Exception = source.Exception; 205 201 target.Percentage = source.Percentage; 206 202 207 203 target.Priority = source.Priority; 208 target.State = (JobState) Enum.Parse(typeof(JobState), source.JobState, true);204 target.State = (JobState)Enum.Parse(typeof(JobState), source.JobState, true); 209 205 return target; 210 206 }
Note: See TracChangeset
for help on using the changeset viewer.