private DimTime UpdateDimTimeTable(PersistenceManager pm) { var dimTimeDao = pm.DimTimeDao; var now = DateTime.Now; var timeEntry = new DimTime { Time = now, Minute = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0), Hour = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0), Day = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0), Month = new DateTime(now.Year, now.Month, 1, 0, 0, 0), Year = new DateTime(now.Year, 1, 1, 0, 0, 0) }; return dimTimeDao.Save(timeEntry); }
private void UpdateFactClientInfoTable(DimTime newTime, PersistenceManager pm) { var factClientInfoDao = pm.FactClientInfoDao; var slaveDao = pm.SlaveDao; var dimClientDao = pm.DimClientDao; var newRawFactInfos = from s in slaveDao.GetAll() join c in dimClientDao.GetActiveClients() on s.ResourceId equals c.ResourceId join lcf in factClientInfoDao.GetLastUpdateTimestamps() on c.ResourceId equals lcf.ResourceId into joinCf from cf in joinCf.DefaultIfEmpty() select new { ClientId = c.Id, UserId = s.OwnerUserId ?? Guid.Empty, TotalCores = s.Cores ?? 0, FreeCores = s.FreeCores ?? 0, TotalMemory = s.Memory ?? 0, FreeMemory = s.FreeMemory ?? 0, CpuUtilization = s.CpuUtilization, SlaveState = s.SlaveState, IsAllowedToCalculate = s.IsAllowedToCalculate, LastFactTimestamp = cf.Timestamp }; factClientInfoDao.Save( from x in newRawFactInfos.ToList() let duration = x.LastFactTimestamp != null ? (int)(newTime.Time - (DateTime)x.LastFactTimestamp).TotalSeconds : (int)SmallestTimeSpan.TotalSeconds select new FactClientInfo { ClientId = x.ClientId, DimTime = newTime, UserId = x.UserId, NumUsedCores = x.TotalCores - x.FreeCores, NumTotalCores = x.TotalCores, UsedMemory = x.TotalMemory - x.FreeMemory, TotalMemory = x.TotalMemory, CpuUtilization = Math.Round(x.CpuUtilization, 2), SlaveState = x.SlaveState, IdleTime = x.SlaveState == SlaveState.Idle && x.IsAllowedToCalculate ? duration : 0, UnavailableTime = x.SlaveState == SlaveState.Idle && !x.IsAllowedToCalculate ? duration : 0, OfflineTime = x.SlaveState == SlaveState.Offline ? duration : 0, IsAllowedToCalculate = x.IsAllowedToCalculate } ); }
partial void UpdateDimTime(DimTime instance);
partial void DeleteDimTime(DimTime instance);
partial void InsertDimTime(DimTime instance);