Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/21/11 17:35:42 (14 years ago)
Author:
cneumuel
Message:

#1233

  • fixed handling of StateLog in DataLayer
  • extended unit tests
  • changed style of service calls to OKB-like style (using delegates)
  • added possibility that parent jobs can be finished immediately when child jobs are finished
Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4
Files:
6 edited

Legend:

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

    r5511 r5526  
    4040        LastHeartbeat = source.LastHeartbeat,
    4141        State = source.State,
    42         StateLog = source.StateLogs.Select(x => Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList()
     42        StateLog = source.StateLogs.Select(x => Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList(),
     43        IsParentJob = source.IsParentJob,
     44        FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished
    4345      };
    4446    }
     
    5961        target.State = source.State;
    6062        if (target.StateLogs == null) target.StateLogs = new EntitySet<StateLog>();
    61         target.StateLogs.AddRange(source.StateLog.Select(x => Convert.ToEntity(x)).OrderBy(x => x.DateTime));
     63        foreach (DT.StateLog sl in source.StateLog.Where(x => x.Id == Guid.Empty)) {
     64          target.StateLogs.Add(Convert.ToEntity(sl));
     65        }
     66       
     67        //target.StateLogs.AddRange(source.StateLog.Select(x => Convert.ToEntity(x)).OrderBy(x => x.DateTime));
     68        target.IsParentJob = source.IsParentJob;
     69        target.FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished;
    6270        // RequiredPlugins are added by Dao
    6371      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs

    r5511 r5526  
    8282    }
    8383
    84     public IEnumerable<DT.Job> GetWaitingParentJobs(IEnumerable<Guid> resourceIds, int count) {
     84    /// <summary>
     85    /// returns all parent jobs which are waiting for their child jobs to finish
     86    /// </summary>
     87    /// <param name="resourceIds">list of resourceids which for which the jobs should be valid</param>
     88    /// <param name="count">maximum number of jobs to return</param>
     89    /// <param name="finished">if true, all parent jobs which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param>
     90    /// <returns></returns>
     91    public IEnumerable<DT.Job> GetParentJobs(IEnumerable<Guid> resourceIds, int count, bool finished) {
    8592      using (var db = CreateContext()) {
    8693        var query = from ar in db.AssignedResources
    87                     join sl in db.StateLogs on ar.JobId equals sl.JobId
    8894                    where resourceIds.Contains(ar.ResourceId)
    89                        && ar.Job.State == JobState.FinishOnChildJobsFinished
     95                       && ar.Job.State == JobState.Waiting
     96                       && ar.Job.IsParentJob
     97                       && (finished ? ar.Job.FinishWhenChildJobsFinished : !ar.Job.FinishWhenChildJobsFinished)
    9098                       && (from child in db.Jobs
    9199                           where child.ParentJobId == ar.Job.JobId
     
    103111      using (var db = CreateContext()) {
    104112        var resourceIds = GetParentResources(slave.Id).Select(r => r.Id);
    105         var waitingParentJobs = GetWaitingParentJobs(resourceIds, count);
     113        var waitingParentJobs = GetParentJobs(resourceIds, count, false);
    106114        if (count > 0 && waitingParentJobs.Count() >= count) return waitingParentJobs.Take(count).ToArray();
    107115
    108116        var query = from ar in db.AssignedResources
    109117                    where resourceIds.Contains(ar.ResourceId)
     118                       && !(ar.Job.IsParentJob && ar.Job.FinishWhenChildJobsFinished)
    110119                       && ar.Job.State == JobState.Waiting
    111120                       && ar.Job.CoresNeeded <= slave.FreeCores
     
    160169    #endregion
    161170
     171    #region StateLog Methods
     172
     173    public DT.StateLog GetStateLog(Guid id) {
     174      using (var db = CreateContext()) {
     175        return Convert.ToDto(db.StateLogs.SingleOrDefault(x => x.StateLogId == id));
     176      }
     177    }
     178
     179    public IEnumerable<DT.StateLog> GetStateLogs(Expression<Func<StateLog, bool>> predicate) {
     180      using (var db = CreateContext()) {
     181        return db.StateLogs.Where(predicate).Select(x => Convert.ToDto(x)).ToArray();
     182      }
     183    }
     184
     185    public Guid AddStateLog(DT.StateLog dto) {
     186      using (var db = CreateContext()) {
     187        var entity = Convert.ToEntity(dto);
     188        db.StateLogs.InsertOnSubmit(entity);
     189        db.SubmitChanges();
     190        return entity.StateLogId;
     191      }
     192    }
     193
     194    public void UpdateStateLog(DT.StateLog dto) {
     195      using (var db = CreateContext()) {
     196        var entity = db.StateLogs.FirstOrDefault(x => x.StateLogId == dto.Id);
     197        if (entity == null) db.StateLogs.InsertOnSubmit(Convert.ToEntity(dto));
     198        else Convert.ToEntity(dto, entity);
     199        db.SubmitChanges();
     200      }
     201    }
     202
     203    public void DeleteStateLog(Guid id) {
     204      using (var db = CreateContext()) {
     205        var entity = db.StateLogs.FirstOrDefault(x => x.StateLogId == id);
     206        if (entity != null) db.StateLogs.DeleteOnSubmit(entity);
     207        db.SubmitChanges();
     208      }
     209    }
     210    #endregion
     211
    162212    #region HiveExperiment Methods
    163213    public DT.HiveExperiment GetHiveExperiment(Guid id) {
     
    507557
    508558    #endregion
     559
    509560  }
    510561}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml

    r5511 r5526  
    6060    <Type Name="Job">
    6161      <Column Name="JobId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
     62      <Column Name="JobState" Member="State" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState" DbType="VarChar(30)" CanBeNull="false" />
     63      <Column Name="ExecutionTime" Type="System.String" DbType="VarChar(30)" CanBeNull="true" />
     64      <Column Name="LastHeartbeat" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
    6265      <Column Name="ParentJobId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    63       <Column Name="ExecutionTime" Type="System.String" DbType="VarChar(30)" CanBeNull="true" />
    6466      <Column Name="Priority" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    6567      <Column Name="CoresNeeded" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    6668      <Column Name="MemoryNeeded" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    67       <Column Name="LastHeartbeat" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
    68       <Column Name="JobState" Member="State" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState" DbType="VarChar(30)" CanBeNull="false" />
     69      <Column Name="IsParentJob" Type="System.Boolean" DbType="Bit" CanBeNull="false" />
     70      <Column Name="FinishWhenChildJobsFinished" Type="System.Boolean" DbType="Bit" CanBeNull="false" />
    6971      <Association Name="Job_AssignedResource" Member="AssignedResources" ThisKey="JobId" OtherKey="JobId" Type="AssignedResource" />
    7072      <Association Name="Job_RequiredPlugin" Member="RequiredPlugins" ThisKey="JobId" OtherKey="JobId" Type="RequiredPlugin" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml.layout

    r5511 r5526  
    2727      </nestedChildShapes>
    2828    </classShape>
    29     <classShape Id="695bfc39-59f3-4e60-8644-f847964bf62c" absoluteBounds="6.5, 1, 2, 2.3478011067708335">
     29    <classShape Id="695bfc39-59f3-4e60-8644-f847964bf62c" absoluteBounds="6.5, 1, 2, 2.7324039713541666">
    3030      <DataClassMoniker Name="/HiveDataContext/Job" />
    3131      <nestedChildShapes>
    32         <elementListCompartment Id="a6a30e11-03d1-4869-82e6-b733f4ef9974" absoluteBounds="6.5150000000000006, 1.46, 1.9700000000000002, 1.7878011067708333" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
     32        <elementListCompartment Id="a6a30e11-03d1-4869-82e6-b733f4ef9974" absoluteBounds="6.5150000000000006, 1.46, 1.9700000000000002, 2.1724039713541665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
    3333      </nestedChildShapes>
    3434    </classShape>
     
    7676      </nodes>
    7777    </associationConnector>
    78     <associationConnector edgePoints="[(8.5 : 3.34780110677083); (8.875 : 3.875)]" fixedFrom="NotFixed" fixedTo="NotFixed">
     78    <associationConnector edgePoints="[(8.5 : 3.73240397135417); (8.875 : 3.875)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    7979      <AssociationMoniker Name="/HiveDataContext/Job/Job_AssignedResource" />
    8080      <nodes>
     
    8383      </nodes>
    8484    </associationConnector>
    85     <associationConnector edgePoints="[(7.4687475 : 3.34780110677083); (7.4687475 : 5.5)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     85    <associationConnector edgePoints="[(7.4687475 : 3.73240397135417); (7.4687475 : 5.5)]" fixedFrom="Algorithm" fixedTo="Algorithm">
    8686      <AssociationMoniker Name="/HiveDataContext/Job/Job_RequiredPlugin" />
    8787      <nodes>
     
    104104      </nodes>
    105105    </associationConnector>
    106     <associationConnector edgePoints="[(6.5 : 2.98640055338542); (6.125 : 2.98640055338542)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     106    <associationConnector edgePoints="[(6.5 : 3.17870198567708); (6.125 : 3.17870198567708)]" fixedFrom="Algorithm" fixedTo="Algorithm">
    107107      <AssociationMoniker Name="/HiveDataContext/Job/Job_HiveExperiment" />
    108108      <nodes>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs

    r5511 r5526  
    13931393    private System.Guid _JobId;
    13941394   
     1395    private global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState _State;
     1396   
     1397    private string _ExecutionTime;
     1398   
     1399    private System.Nullable<System.DateTime> _LastHeartbeat;
     1400   
    13951401    private System.Nullable<System.Guid> _ParentJobId;
    13961402   
    1397     private string _ExecutionTime;
    1398    
    13991403    private int _Priority;
    14001404   
     
    14031407    private int _MemoryNeeded;
    14041408   
    1405     private System.Nullable<System.DateTime> _LastHeartbeat;
    1406    
    1407     private global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState _State;
     1409    private bool _IsParentJob;
     1410   
     1411    private bool _FinishWhenChildJobsFinished;
    14081412   
    14091413    private EntitySet<AssignedResource> _AssignedResources;
     
    14251429    partial void OnJobIdChanging(System.Guid value);
    14261430    partial void OnJobIdChanged();
     1431    partial void OnStateChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState value);
     1432    partial void OnStateChanged();
     1433    partial void OnExecutionTimeChanging(string value);
     1434    partial void OnExecutionTimeChanged();
     1435    partial void OnLastHeartbeatChanging(System.Nullable<System.DateTime> value);
     1436    partial void OnLastHeartbeatChanged();
    14271437    partial void OnParentJobIdChanging(System.Nullable<System.Guid> value);
    14281438    partial void OnParentJobIdChanged();
    1429     partial void OnExecutionTimeChanging(string value);
    1430     partial void OnExecutionTimeChanged();
    14311439    partial void OnPriorityChanging(int value);
    14321440    partial void OnPriorityChanged();
     
    14351443    partial void OnMemoryNeededChanging(int value);
    14361444    partial void OnMemoryNeededChanged();
    1437     partial void OnLastHeartbeatChanging(System.Nullable<System.DateTime> value);
    1438     partial void OnLastHeartbeatChanged();
    1439     partial void OnStateChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState value);
    1440     partial void OnStateChanged();
     1445    partial void OnIsParentJobChanging(bool value);
     1446    partial void OnIsParentJobChanged();
     1447    partial void OnFinishWhenChildJobsFinishedChanging(bool value);
     1448    partial void OnFinishWhenChildJobsFinishedChanged();
    14411449    #endregion
    14421450   
     
    14721480    }
    14731481   
     1482    [global::System.Data.Linq.Mapping.ColumnAttribute(Name="JobState", Storage="_State", DbType="VarChar(30)", CanBeNull=false)]
     1483    public global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState State
     1484    {
     1485      get
     1486      {
     1487        return this._State;
     1488      }
     1489      set
     1490      {
     1491        if ((this._State != value))
     1492        {
     1493          this.OnStateChanging(value);
     1494          this.SendPropertyChanging();
     1495          this._State = value;
     1496          this.SendPropertyChanged("State");
     1497          this.OnStateChanged();
     1498        }
     1499      }
     1500    }
     1501   
     1502    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ExecutionTime", DbType="VarChar(30)")]
     1503    public string ExecutionTime
     1504    {
     1505      get
     1506      {
     1507        return this._ExecutionTime;
     1508      }
     1509      set
     1510      {
     1511        if ((this._ExecutionTime != value))
     1512        {
     1513          this.OnExecutionTimeChanging(value);
     1514          this.SendPropertyChanging();
     1515          this._ExecutionTime = value;
     1516          this.SendPropertyChanged("ExecutionTime");
     1517          this.OnExecutionTimeChanged();
     1518        }
     1519      }
     1520    }
     1521   
     1522    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastHeartbeat", DbType="DateTime")]
     1523    public System.Nullable<System.DateTime> LastHeartbeat
     1524    {
     1525      get
     1526      {
     1527        return this._LastHeartbeat;
     1528      }
     1529      set
     1530      {
     1531        if ((this._LastHeartbeat != value))
     1532        {
     1533          this.OnLastHeartbeatChanging(value);
     1534          this.SendPropertyChanging();
     1535          this._LastHeartbeat = value;
     1536          this.SendPropertyChanged("LastHeartbeat");
     1537          this.OnLastHeartbeatChanged();
     1538        }
     1539      }
     1540    }
     1541   
    14741542    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ParentJobId", DbType="UniqueIdentifier")]
    14751543    public System.Nullable<System.Guid> ParentJobId
     
    14961564    }
    14971565   
    1498     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ExecutionTime", DbType="VarChar(30)")]
    1499     public string ExecutionTime
    1500     {
    1501       get
    1502       {
    1503         return this._ExecutionTime;
    1504       }
    1505       set
    1506       {
    1507         if ((this._ExecutionTime != value))
    1508         {
    1509           this.OnExecutionTimeChanging(value);
    1510           this.SendPropertyChanging();
    1511           this._ExecutionTime = value;
    1512           this.SendPropertyChanged("ExecutionTime");
    1513           this.OnExecutionTimeChanged();
    1514         }
    1515       }
    1516     }
    1517    
    15181566    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Priority", DbType="Int NOT NULL")]
    15191567    public int Priority
     
    15761624    }
    15771625   
    1578     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastHeartbeat", DbType="DateTime")]
    1579     public System.Nullable<System.DateTime> LastHeartbeat
    1580     {
    1581       get
    1582       {
    1583         return this._LastHeartbeat;
    1584       }
    1585       set
    1586       {
    1587         if ((this._LastHeartbeat != value))
    1588         {
    1589           this.OnLastHeartbeatChanging(value);
    1590           this.SendPropertyChanging();
    1591           this._LastHeartbeat = value;
    1592           this.SendPropertyChanged("LastHeartbeat");
    1593           this.OnLastHeartbeatChanged();
    1594         }
    1595       }
    1596     }
    1597    
    1598     [global::System.Data.Linq.Mapping.ColumnAttribute(Name="JobState", Storage="_State", DbType="VarChar(30)", CanBeNull=false)]
    1599     public global::HeuristicLab.Services.Hive.Common.DataTransfer.JobState State
    1600     {
    1601       get
    1602       {
    1603         return this._State;
    1604       }
    1605       set
    1606       {
    1607         if ((this._State != value))
    1608         {
    1609           this.OnStateChanging(value);
    1610           this.SendPropertyChanging();
    1611           this._State = value;
    1612           this.SendPropertyChanged("State");
    1613           this.OnStateChanged();
     1626    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsParentJob", DbType="Bit")]
     1627    public bool IsParentJob
     1628    {
     1629      get
     1630      {
     1631        return this._IsParentJob;
     1632      }
     1633      set
     1634      {
     1635        if ((this._IsParentJob != value))
     1636        {
     1637          this.OnIsParentJobChanging(value);
     1638          this.SendPropertyChanging();
     1639          this._IsParentJob = value;
     1640          this.SendPropertyChanged("IsParentJob");
     1641          this.OnIsParentJobChanged();
     1642        }
     1643      }
     1644    }
     1645   
     1646    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FinishWhenChildJobsFinished", DbType="Bit")]
     1647    public bool FinishWhenChildJobsFinished
     1648    {
     1649      get
     1650      {
     1651        return this._FinishWhenChildJobsFinished;
     1652      }
     1653      set
     1654      {
     1655        if ((this._FinishWhenChildJobsFinished != value))
     1656        {
     1657          this.OnFinishWhenChildJobsFinishedChanging(value);
     1658          this.SendPropertyChanging();
     1659          this._FinishWhenChildJobsFinished = value;
     1660          this.SendPropertyChanged("FinishWhenChildJobsFinished");
     1661          this.OnFinishWhenChildJobsFinishedChanged();
    16141662        }
    16151663      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs

    r5511 r5526  
    1515    void DeleteJob(Guid id);
    1616    IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count);
     17    IEnumerable<DT.Job> GetParentJobs(IEnumerable<Guid> resourceIds, int count, bool finished);
    1718    #endregion
    1819
     
    2324    void UpdateJobData(DT.JobData dto);
    2425    void DeleteJobData(Guid id);
     26    #endregion
     27
     28    #region StateLog Methods
     29    DT.StateLog GetStateLog(Guid id);
     30    IEnumerable<DT.StateLog> GetStateLogs(Expression<Func<StateLog, bool>> predicate);
     31    Guid AddStateLog(DT.StateLog dto);
     32    void UpdateStateLog(DT.StateLog dto);
     33    void DeleteStateLog(Guid id);
    2534    #endregion
    2635
Note: See TracChangeset for help on using the changeset viewer.