Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/19/10 15:47:46 (14 years ago)
Author:
cneumuel
Message:

renamed all database entities from "Client" to "Slave" (#1157)
made slave-heartbeats synchronous, also they send HBs when timetable disallows them to calculate. they will appear on the server as Idle bis IsAllowedToCalculate will be false (#1159)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/JobDao.cs

    r4264 r4267  
    1010
    1111namespace HeuristicLab.Hive.Server.LINQDataAccess {
    12   public class JobDao: BaseDao<JobDto, Job>, IJobDao {
    13    
     12  public class JobDao : BaseDao<JobDto, Job>, IJobDao {
     13
    1414    #region IGenericDao<JobDto,Job> Members
    1515
     
    2828      IQueryable<JobDto> query = null;
    2929      if (jobState == JobState.Finished) {
    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);
     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);
    3434      } else if (jobState == JobState.Calculating || jobState == JobState.SnapshotRequested || jobState == JobState.SnapshotSent) {
    3535        query = from job in Context.Jobs
    36                     where job.JobState == Enum.GetName(typeof(JobState), jobState)
    37                     orderby job.DateCalculated
    38                     select EntityToDto(job, null);
     36                where job.JobState == Enum.GetName(typeof(JobState), jobState)
     37                orderby job.DateCalculated
     38                select EntityToDto(job, null);
    3939      } else {
    4040        query = from job in Context.Jobs
    41                     where job.JobState == Enum.GetName(typeof(JobState), jobState)
    42                     orderby job.DateCreated
    43                     select EntityToDto(job, null);
     41                where job.JobState == Enum.GetName(typeof(JobState), jobState)
     42                orderby job.DateCreated
     43                select EntityToDto(job, null);
    4444      }
    4545
     
    7474      j.SerializedJob = job.SerializedJobData;
    7575      foreach (Guid assignRessourceId in job.JobInfo.AssignedResourceIds)
    76         j.AssignedResources.Add(new AssignedResource { ResourceId = assignRessourceId});
     76        j.AssignedResources.Add(new AssignedResource { ResourceId = assignRessourceId });
    7777      Context.Jobs.InsertOnSubmit(j);
    7878      CommitChanges();
     
    8989    public void Update(JobDto bObj) {
    9090      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) {
    9696      return (from j in Context.Jobs
    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(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))
    102102              select EntityToDto(j, null)).ToList();
    103103    }
    104104
    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.FindAllGroupAndParentGroupIdsForClient(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));
    109109      //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 (JobState), JobState.Offline) &&
     110      idList.Add(slaveId);
     111
     112      var q = (from ar in Context.AssignedResources
     113               where ar.Job.JobState == Enum.GetName(typeof(JobState), JobState.Offline) &&
    114114                     ar.Job.CoresNeeded <= freeCores &&
    115115                     ar.Job.MemoryNeeded <= freeMemory &&
    116116                     idList.Contains(ar.ResourceId)
    117                orderby ar.Job.Priority descending                 
     117               orderby ar.Job.Priority descending
    118118               select EntityToDto(ar.Job, null));
    119119      return q.ToList();
     
    122122    public IEnumerable<JobDto> GetJobsByState(JobState state) {
    123123      return (from j in Context.Jobs
    124               where (j.JobState == Enum.GetName(typeof (JobState), state))
     124              where (j.JobState == Enum.GetName(typeof(JobState), state))
    125125              select EntityToDto(j, null)).ToList();
    126126    }
    127127
    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));
    130130      Job j = Context.Jobs.SingleOrDefault(job => job.JobId.Equals(jobId));
    131131      c.Jobs.Add(j);
    132       j.Client = c;
    133       CommitChanges();     
     132      j.Slave = c;
     133      CommitChanges();
    134134    }
    135135
    136136    public void SetJobOffline(JobDto job) {
    137137      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);
    140140      CommitChanges();
    141141    }
    142142
    143143    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);
    149145      return new VarBinaryStream(source);
    150146    }
     
    152148    public IEnumerable<JobDto> FindJobsById(IEnumerable<Guid> jobIds) {
    153149      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);
    156152
    157153      return jobs.ToList();
     
    182178
    183179    //Assigned ressources are not used atm!
    184     //Client is not used ATM - not sure when we stopped using those...
     180    //Slave is not used ATM - not sure when we stopped using those...
    185181    public override JobDto EntityToDto(Job source, JobDto target) {
    186182      if (source == null)
    187183        return null;
    188       if(target == null)
     184      if (target == null)
    189185        target = new JobDto();
    190    
     186
    191187      //target.ParentJob = null;
    192188      //target.PluginsNeeded = null;
    193       //target.Client = null;
     189      //target.Slave = null;
    194190      //target.Project = null;
    195      
     191
    196192      target.CoresNeeded = source.CoresNeeded;
    197193      target.MemoryNeeded = source.MemoryNeeded;
     
    204200      target.Exception = source.Exception;
    205201      target.Percentage = source.Percentage;
    206      
     202
    207203      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);
    209205      return target;
    210206    }
Note: See TracChangeset for help on using the changeset viewer.