Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/13/15 15:22:51 (9 years ago)
Author:
ascheibe
Message:

#2388

  • prevent disposing of hive data context
  • more cleanups
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApi/GroupController.cs

    r12562 r12858  
    3535
    3636    public DT.GroupDetails GetGroupDetails(Guid id) {
    37       using (var pm = PersistenceManager) {
    38         var dimClientDao = pm.DimClientDao;
    39         var factClientInfoDao = pm.FactClientInfoDao;
    40         var factTaskDao = pm.FactTaskDao;
    41         return pm.UseTransaction(() => {
    42           var clientTimeData = factClientInfoDao.GetAll()
    43             .Join(dimClientDao.GetAll(), x => x.ClientId, y => y.Id, (x, y) => new {
    44               y.ResourceGroupId,
    45               x.IdleTime,
    46               x.OfflineTime,
    47               x.UnavailableTime
    48             })
    49             .Where(x => x.ResourceGroupId == id)
    50             .GroupBy(x => x.ResourceGroupId)
    51             .Select(x => new {
    52               TotalIdleTime = x.Sum(y => y.IdleTime),
    53               TotalOfflineTime = x.Sum(y => y.OfflineTime),
    54               TotalUnavailableTime = x.Sum(y => y.UnavailableTime)
    55             })
    56             .FirstOrDefault();
     37      var pm = PersistenceManager;
     38      var dimClientDao = pm.DimClientDao;
     39      var factClientInfoDao = pm.FactClientInfoDao;
     40      var factTaskDao = pm.FactTaskDao;
     41      return pm.UseTransaction(() => {
     42        var clientTimeData = factClientInfoDao.GetAll()
     43          .Join(dimClientDao.GetAll(), x => x.ClientId, y => y.Id, (x, y) => new {
     44            y.ResourceGroupId,
     45            x.IdleTime,
     46            x.OfflineTime,
     47            x.UnavailableTime
     48          })
     49          .Where(x => x.ResourceGroupId == id)
     50          .GroupBy(x => x.ResourceGroupId)
     51          .Select(x => new {
     52            TotalIdleTime = x.Sum(y => y.IdleTime),
     53            TotalOfflineTime = x.Sum(y => y.OfflineTime),
     54            TotalUnavailableTime = x.Sum(y => y.UnavailableTime)
     55          })
     56          .FirstOrDefault();
    5757
    58           var taskTimeData = factTaskDao.GetByGroupId(id)
    59             .Select(x => new {
    60               id,
    61               x.CalculatingTime,
    62               x.TransferTime
    63             })
    64             .GroupBy(x => x.id)
    65             .Select(x => new {
    66               CalculatingTime = x.Sum(y => y.CalculatingTime),
    67               TransferTime = x.Sum(y => y.TransferTime)
    68             })
    69             .FirstOrDefault();
    70           return (from client in dimClientDao.GetActiveClients().Where(x => x.ResourceGroupId == id)
     58        var taskTimeData = factTaskDao.GetByGroupId(id)
     59          .Select(x => new {
     60            id,
     61            x.CalculatingTime,
     62            x.TransferTime
     63          })
     64          .GroupBy(x => x.id)
     65          .Select(x => new {
     66            CalculatingTime = x.Sum(y => y.CalculatingTime),
     67            TransferTime = x.Sum(y => y.TransferTime)
     68          })
     69          .FirstOrDefault();
     70        return (from client in dimClientDao.GetActiveClients().Where(x => x.ResourceGroupId == id)
     71                join info in factClientInfoDao.GetAll()
     72                  on client.Id equals info.ClientId into clientInfoJoin
     73                from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1)
     74                let offline = (clientInfo.SlaveState == DA.SlaveState.Offline)
     75                select new {
     76                  ResourceGroupId = client.ResourceGroupId,
     77                  GroupName = client.GroupName,
     78                  TotalCores = clientInfo.NumTotalCores,
     79                  UsedCores = offline ? 0 : clientInfo.NumUsedCores,
     80                  TotalMemory = clientInfo.TotalMemory,
     81                  UsedMemory = offline ? 0 : clientInfo.UsedMemory,
     82                  CpuUtilization = offline ? 0 : clientInfo.CpuUtilization,
     83                  SlaveState = clientInfo.SlaveState
     84                })
     85          .GroupBy(x => new { x.ResourceGroupId, x.GroupName })
     86          .Select(x => new DT.GroupDetails {
     87            Id = id,
     88            Name = x.Key.GroupName,
     89            TotalClients = x.Count(),
     90            OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline),
     91            TotalCores = x.Sum(y => y.TotalCores),
     92            UsedCores = x.Sum(y => y.UsedCores),
     93            TotalMemory = x.Sum(y => y.TotalMemory),
     94            UsedMemory = x.Sum(y => y.UsedMemory),
     95            TotalCpuUtilization = x.Average(y => (double?)y.CpuUtilization) ?? 0.0,
     96            ActiveCpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0,
     97            TotalUnavailableTime = clientTimeData != null ? clientTimeData.TotalUnavailableTime : 0,
     98            TotalCalculatingTime = taskTimeData != null ? taskTimeData.CalculatingTime : 0,
     99            TotalIdleTime = clientTimeData != null ? clientTimeData.TotalIdleTime : 0,
     100            TotalOfflineTime = clientTimeData != null ? clientTimeData.TotalOfflineTime : 0,
     101            TotalTransferringTime = taskTimeData != null ? taskTimeData.TransferTime : 0,
     102            TasksStates = factTaskDao.GetByGroupId(id)
     103                                  .GroupBy(y => y.TaskState)
     104                                  .Select(y => new DT.TaskStateCount {
     105                                    State = y.Key.ToString(),
     106                                    Count = y.Count()
     107                                  }).ToList()
     108          }).FirstOrDefault();
     109      });
     110    }
     111
     112    public DT.GroupPage GetGroups(int page, int size) {
     113      var pm = PersistenceManager;
     114      var dimClientDao = pm.DimClientDao;
     115      var factClientInfoDao = pm.FactClientInfoDao;
     116      var data = (from client in dimClientDao.GetActiveClients()
    71117                  join info in factClientInfoDao.GetAll()
    72118                    on client.Id equals info.ClientId into clientInfoJoin
     
    75121                  select new {
    76122                    ResourceGroupId = client.ResourceGroupId,
    77                     GroupName = client.GroupName,
    78123                    TotalCores = clientInfo.NumTotalCores,
    79124                    UsedCores = offline ? 0 : clientInfo.NumUsedCores,
     
    82127                    CpuUtilization = offline ? 0 : clientInfo.CpuUtilization,
    83128                    SlaveState = clientInfo.SlaveState
    84                   })
    85             .GroupBy(x => new { x.ResourceGroupId, x.GroupName })
    86             .Select(x => new DT.GroupDetails {
    87               Id = id,
    88               Name = x.Key.GroupName,
    89               TotalClients = x.Count(),
    90               OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline),
    91               TotalCores = x.Sum(y => y.TotalCores),
    92               UsedCores = x.Sum(y => y.UsedCores),
    93               TotalMemory = x.Sum(y => y.TotalMemory),
    94               UsedMemory = x.Sum(y => y.UsedMemory),
    95               TotalCpuUtilization = x.Average(y => (double?)y.CpuUtilization) ?? 0.0,
    96               ActiveCpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0,
    97               TotalUnavailableTime = clientTimeData != null ? clientTimeData.TotalUnavailableTime : 0,
    98               TotalCalculatingTime = taskTimeData != null ? taskTimeData.CalculatingTime : 0,
    99               TotalIdleTime = clientTimeData != null ? clientTimeData.TotalIdleTime : 0,
    100               TotalOfflineTime = clientTimeData != null ? clientTimeData.TotalOfflineTime : 0,
    101               TotalTransferringTime = taskTimeData != null ? taskTimeData.TransferTime : 0,
    102               TasksStates = factTaskDao.GetByGroupId(id)
    103                                     .GroupBy(y => y.TaskState)
    104                                     .Select(y => new DT.TaskStateCount {
    105                                       State = y.Key.ToString(),
    106                                       Count = y.Count()
    107                                     }).ToList()
    108             }).FirstOrDefault();
     129                  }).GroupBy(x => x.ResourceGroupId).Select(x => new {
     130                    GroupId = x.Key,
     131                    TotalClients = x.Count(),
     132                    OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline),
     133                    TotalCores = x.Sum(y => y.TotalCores),
     134                    UsedCores = x.Sum(y => y.UsedCores),
     135                    TotalMemory = x.Sum(y => y.TotalMemory),
     136                    UsedMemory = x.Sum(y => y.UsedMemory),
     137                    CpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0
     138                  });
     139      var query = dimClientDao.GetAll()
     140        .GroupBy(x => new { x.ResourceGroupId, x.GroupName })
     141        .Select(x => new {
     142          Id = x.Key.ResourceGroupId ?? default(Guid),
     143          Name = x.Key.GroupName
    109144        });
    110       }
    111     }
    112 
    113     public DT.GroupPage GetGroups(int page, int size) {
    114       using (var pm = PersistenceManager) {
    115         var dimClientDao = pm.DimClientDao;
    116         var factClientInfoDao = pm.FactClientInfoDao;
    117         var data = (from client in dimClientDao.GetActiveClients()
    118                     join info in factClientInfoDao.GetAll()
    119                       on client.Id equals info.ClientId into clientInfoJoin
    120                     from clientInfo in clientInfoJoin.OrderByDescending(x => x.Time).Take(1)
    121                     let offline = (clientInfo.SlaveState == DA.SlaveState.Offline)
    122                     select new {
    123                       ResourceGroupId = client.ResourceGroupId,
    124                       TotalCores = clientInfo.NumTotalCores,
    125                       UsedCores = offline ? 0 : clientInfo.NumUsedCores,
    126                       TotalMemory = clientInfo.TotalMemory,
    127                       UsedMemory = offline ? 0 : clientInfo.UsedMemory,
    128                       CpuUtilization = offline ? 0 : clientInfo.CpuUtilization,
    129                       SlaveState = clientInfo.SlaveState
    130                     }).GroupBy(x => x.ResourceGroupId).Select(x => new {
    131                       GroupId = x.Key,
    132                       TotalClients = x.Count(),
    133                       OnlineClients = x.Count(y => y.SlaveState != DA.SlaveState.Offline),
    134                       TotalCores = x.Sum(y => y.TotalCores),
    135                       UsedCores = x.Sum(y => y.UsedCores),
    136                       TotalMemory = x.Sum(y => y.TotalMemory),
    137                       UsedMemory = x.Sum(y => y.UsedMemory),
    138                       CpuUtilization = x.Where(y => y.SlaveState != DA.SlaveState.Offline).Average(y => (double?)y.CpuUtilization) ?? 0.0
    139                     });
    140         var query = dimClientDao.GetAll()
    141           .GroupBy(x => new { x.ResourceGroupId, x.GroupName })
    142           .Select(x => new {
    143             Id = x.Key.ResourceGroupId ?? default(Guid),
    144             Name = x.Key.GroupName
    145           });
    146         return pm.UseTransaction(() => new DT.GroupPage {
    147           TotalGroups = query.Count(),
    148           Groups = query
    149           .Skip((page - 1) * size)
    150           .Take(size)
    151           .Join(data, x => x.Id, y => y.GroupId,
    152             (group, info) => new DT.Group {
    153               Id = group.Id,
    154               Name = group.Name,
    155               TotalClients = info.TotalClients,
    156               OnlineClients = info.OnlineClients,
    157               TotalCores = info.TotalCores,
    158               UsedCores = info.UsedCores,
    159               TotalMemory = info.TotalMemory,
    160               UsedMemory = info.UsedMemory,
    161               CpuUtilization = info.CpuUtilization
    162             }).ToList()
    163         });
    164       }
     145      return pm.UseTransaction(() => new DT.GroupPage {
     146        TotalGroups = query.Count(),
     147        Groups = query
     148        .Skip((page - 1) * size)
     149        .Take(size)
     150        .Join(data, x => x.Id, y => y.GroupId,
     151          (group, info) => new DT.Group {
     152            Id = group.Id,
     153            Name = group.Name,
     154            TotalClients = info.TotalClients,
     155            OnlineClients = info.OnlineClients,
     156            TotalCores = info.TotalCores,
     157            UsedCores = info.UsedCores,
     158            TotalMemory = info.TotalMemory,
     159            UsedMemory = info.UsedMemory,
     160            CpuUtilization = info.CpuUtilization
     161          }).ToList()
     162      });
    165163    }
    166164  }
Note: See TracChangeset for help on using the changeset viewer.