Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/29/18 17:38:50 (7 years ago)
Author:
jzenisek
Message:

#2839 implemented project facts-logging in HiveStatisticsGenerator

Location:
branches/HiveProjectManagement
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectDao.cs

    r15577 r15666  
    2828  public class ProjectDao : GenericDao<Guid, Project> {
    2929    public ProjectDao(DataContext dataContext) : base(dataContext) { }
     30
     31    public class ProjectStats {
     32      public Guid ProjectId { get; set; }
     33      public int Cores { get; set; }
     34      public int Memory { get; set; }
     35    }
    3036
    3137    public override Project GetById(Guid id) {
     
    7076    }
    7177
     78    public IEnumerable<ProjectStats> GetUsageStatsPerProject() {
     79      return DataContext.ExecuteQuery<ProjectStats>(GetUsageStatsPerProjectQueryString).ToList();
     80    }
     81
     82    public IEnumerable<ProjectStats> GetAvailabilityStatsPerProject() {
     83      return DataContext.ExecuteQuery<ProjectStats>(GetAvailabilityStatsPerProjectQueryString).ToList();
     84    }
     85
    7286    #region Compiled queries
    7387    private static readonly Func<DataContext, Guid, Project> GetByIdQuery =
     
    7993
    8094    #region String queries
     95    private const string GetUsageStatsPerProjectQueryString = @"
     96      SELECT j.ProjectId, SUM(t.CoresNeeded) AS Cores, SUM(t.MemoryNeeded) AS Memory
     97      FROM [Task] t, [Job] j
     98      WHERE t.TaskState = 'Calculating'
     99      AND t.JobId = j.JobId
     100      GROUP BY j.ProjectId
     101    ";
     102
     103    private const string GetAvailabilityStatsPerProjectQueryString = @"
     104      WITH rtree AS
     105      (
     106        SELECT ResourceId, ParentResourceId
     107        FROM [Resource]
     108        UNION ALL
     109        SELECT rt.ResourceId, r.ParentResourceId
     110        FROM [Resource] r
     111        JOIN rtree rt ON rt.ParentResourceId = r.ResourceId
     112      )
     113      SELECT apr.ProjectId, SUM(res.Cores) AS Cores, SUM(res.Memory) AS Memory
     114      FROM rtree, [AssignedProjectResource] apr, [Resource] res
     115      WHERE rtree.ResourceId = res.ResourceId
     116      AND res.ResourceType = 'Slave'
     117      AND (res.SlaveState = 'Idle' OR SlaveState = 'Calculating')
     118      AND rtree.ParentResourceId = apr.ResourceId
     119      GROUP BY apr.ProjectId
     120      UNION
     121      SELECT apr.ProjectId, SUM(res.Cores) AS Cores, SUM(res.Memory) AS Memory
     122      FROM [AssignedProjectResource] apr, [Resource] res
     123      WHERE apr.ResourceId = res.ResourceId
     124      AND res.ResourceType = 'Slave'
     125      AND (res.SlaveState = 'Idle' OR SlaveState = 'Calculating')
     126      GROUP BY apr.ProjectId
     127    ";
     128
    81129    private const string GetUsageGrantedProjectsForUserQueryString = @"
    82130      SELECT DISTINCT p.*
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs

    r15644 r15666  
    9393
    9494    #region String queries
    95     private const string GetParentTasksQueryString = @"
    96       SELECT t.* FROM [Task] t, [Job] j, [AssignedJobResource] ajr
    97         WHERE t.IsParentTask = 1
    98         AND t.TaskState = 'Waiting'
     95    private const string GetCalculatingChildTasksByProjectId = @"
     96      SELECT t.* FROM [Task] t, [Job] j
     97        WHERE t.IsParentTask = 0
     98        AND t.TaskState = 'Calculating'
    9999        AND t.JobId = j.JobId
    100         AND j.JobId = ajr.JobId
    101         AND t.FinishWhenChildJobsFinished = 1
    102         ... TODO (not necessary)
     100        AND j.ProjectId = {0}
     101        ORDER BY j.ProjectId
    103102    ";
    104103    private const string GetWaitingTasksQueryString = @"
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs

    r15659 r15666  
    5959          pm.UseTransaction(() => {
    6060            UpdateFactClientInfoTable(time, pm);
    61             UpdateFactProjectInfoTable(time, pm); // in progress
     61            UpdateFactProjectInfoTable(time, pm);
    6262            pm.SubmitChanges();
    6363          });
     
    118118    }
    119119
     120    // add new projects
     121    // delete expired projects
     122    // update information of existing projects
    120123    private void UpdateDimProjectTable(PersistenceManager pm) {
    121124      var projectDao = pm.ProjectDao;
     
    353356
    354357    private void UpdateFactProjectInfoTable(DimTime newTime, PersistenceManager pm) {
    355       // TODO
     358      var factProjectInfoDao = pm.FactProjectInfoDao;
     359      var dimProjectDao = pm.DimProjectDao;
     360      var projectDao = pm.ProjectDao;
     361
     362      var projectAvailabilityStats = projectDao.GetAvailabilityStatsPerProject();
     363      var projectUsageStats = projectDao.GetUsageStatsPerProject();
     364      var dimProjects = dimProjectDao.GetAllOnlineProjects().ToList();
     365
     366      factProjectInfoDao.Save(
     367        from dimp in dimProjects
     368        let aStats = projectAvailabilityStats.Where(x => x.ProjectId == dimp.ProjectId).SingleOrDefault()
     369        let uStats = projectUsageStats.Where(x => x.ProjectId == dimp.ProjectId).SingleOrDefault()
     370        select new FactProjectInfo {
     371            ProjectId = dimp.ProjectId,
     372            DimTime = newTime,
     373            NumTotalCores = aStats != null ? aStats.Cores : 0,
     374            TotalMemory = aStats != null ? aStats.Memory : 0,
     375            NumUsedCores = uStats != null ? uStats.Cores : 0,
     376            UsedMemory = uStats != null ? uStats.Memory : 0
     377          }
     378        );
    356379    }
    357380
Note: See TracChangeset for help on using the changeset viewer.