Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/01/11 15:51:11 (14 years ago)
Author:
cneumuel
Message:

#1233

  • changed the workflow of aquireing a new job from server.
    • if a job is available for calculation, the slave receives the jobId already with the heartbeats. The job is then exclusively assigned to this slave.
  • extended the metainfo for a slave by OperatingSystem and CpuArchitecture
  • enhanced the way plugin-dependencies are discovered by using the types used by XmlGenerator. Now only mimimum amount of plugins are transferred.
  • selection of waiting jobs now consideres assigned slave-group
  • more unit tests for service
  • added unit tests for experiment manager
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs

    r5402 r5404  
    8282    }
    8383
    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()) {
    8786        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
    9595                    orderby ar.Job.Priority descending
    9696                    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();
    109115        return waitingJobs.Union(waitingParentJobs).OrderByDescending(x => x.Priority);
    110116      }
     
    350356      using (var db = CreateContext()) {
    351357        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        }
    353364        db.SubmitChanges();
    354365      }
     
    408419        return job.AssignedResources.Select(x => Convert.ToDto(x.Resource)).ToArray();
    409420      }
     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);
    410438    }
    411439    #endregion
Note: See TracChangeset for help on using the changeset viewer.