public async Task <IActionResult> SaveAndRemoveExistingNotificationTresholds(Guid serverId, [FromBody] NotificationResourceThresholdDTO notificationResourceThresholdDto) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); if (server == null) { return(BadRequest("Server id is either null or you are not the owner")); } var notificationResourceThresholdToDelete = await _unitOfWork.NotificationThresholds.GetAll(q => q.ServerId == server.Id ); _unitOfWork.NotificationThresholds.DeleteRange(notificationResourceThresholdToDelete); var notificationResourceThresholdToSave = _mapper.Map <NotificationResourceThreshold>(notificationResourceThresholdDto); notificationResourceThresholdToSave.ServerId = server.Id; await _unitOfWork.NotificationThresholds.Insert(notificationResourceThresholdToSave); return(NoContent()); }
public async Task <IActionResult> SetHardDisksForServer( Guid serverId, [FromBody] IList <CreateHardDiskServer> hardDiskServersDto ) { var server = await ServerUtilController.GetUserHisServerFromApiKey(serverId, HttpContext); if (server == null) { return(BadRequest("Sever id is either null or you are not the owner of the server.")); } var hardDiskServers = _mapper.Map <IList <HardDiskServer> >(hardDiskServersDto); // set the right server id hardDiskServers.ForAll(s => s.ServerId = serverId.ToString()); // so we overwrite the existing. await RemoveExistingHardDisksOfServer(serverId.ToString()); await _unitOfWork.HardDisksServers.InsertRange(hardDiskServers); await HardDiskEventChecker(server, hardDiskServers); return(NoContent()); }
public async Task <IList <PortServer> > GetServerPorts(Guid serverId) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); var portsOfServer = await _unitOfWork.PortsServer.GetAll( q => q.ServerId == server.Id ); return(portsOfServer); }
public async Task <IList <HardDiskServer> > GetHardDisksOfServer(Guid serverId) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); var hardDiskServers = await _unitOfWork.HardDisksServers.GetAll( q => q.ServerId == server.Id ); return(hardDiskServers); }
public async Task <IList <ServerEventDto> > GetEventsOfServer(Guid serverId) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); var serverEvents = await _unitOfWork.ServerEvents.GetAll( q => q.ServerId == server.Id, orderBy => orderBy.OrderByDescending(s => s.CreatedAt) ); return(_mapper.Map <IList <ServerEventDto> >(serverEvents)); }
public async Task <IActionResult> SaveNetworkUSage(Guid serverId, [FromBody] CreateNetworkUsageDto networkUsageDto) { // TODO check if not something was already posted in the past minute var server = await ServerUtilController.GetUserHisServerFromApiKey(serverId, HttpContext); var networkUsage = _mapper.Map <NetworkUsage>(networkUsageDto); networkUsage.ServerId = server.Id; networkUsage.CreatedAt = DateTime.Now; await _unitOfWork.NetworkUsages.Insert(networkUsage); return(Ok()); }
public async Task <IActionResult> GetNotificationTresholdSettings(Guid serverId) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); if (server == null) { return(BadRequest("Server id is either null or you are not the owner")); } var notificationResourceThreshold = await _unitOfWork.NotificationThresholds.Get( q => q.ServerId == server.Id ); return(Ok(notificationResourceThreshold)); }
public async Task <IActionResult> GetNetworkServerAdapters(Guid serverId) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); if (server == null) { return(BadRequest("Server id is either null or you are not the owner")); } var networkAdapterServers = await _unitOfWork.NetworkAdaptersServer.GetAll( q => q.ServerId == server.Id ); var networkAdaptersServersMapped = _mapper.Map <IList <NetworkAdapterServerDto> >(networkAdapterServers); return(Ok(networkAdaptersServersMapped)); }
public async Task <IActionResult> SaveRamUsageMinuteOfServer(Guid serverId, [FromBody] CreateRamUsageDto ramUsageDto) { // TODO check if not something was already posted in the past minute var server = await ServerUtilController.GetUserHisServerFromApiKey(serverId, HttpContext); var ramUsage = _mapper.Map <RamUsage>(ramUsageDto); ramUsage.ServerId = server.Id; ramUsage.CreatedAt = DateTime.Now; await _unitOfWork.RAMUsages.Insert(ramUsage); ramUsage.Server = server; await RAMEventLoggerChecker(ramUsage); return(Ok()); }
public async Task <IList <NetworkUsageDTO> > GetNetworkUsageOfServer(Guid serverId, [FromQuery] CreatedBetween createdBetween) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); var networkUsages = await _unitOfWork.NetworkUsages.GetAll( q => q.ServerId == server.Id && createdBetween.From >= q.CreatedAt && createdBetween.To <= q.CreatedAt ); // year 1 is the default which means the user dit not provide a year. if (createdBetween.From.Year != 1 && createdBetween.From.Year != 1) { networkUsages = await _unitOfWork.NetworkUsages.GetAll( q => server.Id == q.ServerId ); } return(_mapper.Map <IList <NetworkUsageDTO> >(networkUsages)); }
public async Task <IList <CpuUsageDto> > GetCpuUsageOfServer(Guid serverId, [FromQuery] CreatedBetween createdBetween) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); var cpusUsageServers = await _unitOfWork.CpuUsagesServers.GetAll( q => q.ServerId == server.Id ); // year 1 is the default which means the user dit not provide a year. if (createdBetween.From.Year != 1 && createdBetween.From.Year != 1) { cpusUsageServers = await _unitOfWork.CpuUsagesServers.GetAll( q => server.Id == q.ServerId && q.CreatedAt >= createdBetween.From && q.CreatedAt <= createdBetween.To ); } return(_mapper.Map <IList <CpuUsageDto> >(cpusUsageServers)); }
public async Task <IList <RamUsageDto> > GetRamUsageOfServer(Guid serverId, [FromQuery] CreatedBetween createdBetween) { var server = await ServerUtilController.GetServerFromJwt(serverId, HttpContext); var ramUsages = await _unitOfWork.RAMUsages.GetAll( q => q.ServerId == server.Id && createdBetween.From >= q.CreatedAt && createdBetween.To <= q.CreatedAt ); // TODO refactor (or on unit of work layer) // year 1 is the default which means the user dit not provide a year. if (createdBetween.From.Year != 1 && createdBetween.From.Year != 1) { ramUsages = await _unitOfWork.RAMUsages.GetAll( q => server.Id == q.ServerId && q.CreatedAt >= createdBetween.From && q.CreatedAt <= createdBetween.To ); } return(_mapper.Map <IList <RamUsageDto> >(ramUsages)); }
public async Task <IActionResult> SaveCpuUsageMinuteOfServer(Guid serverId, [FromBody] CpuUsageDto cpuUsageDto) { var server = await ServerUtilController.GetUserHisServerFromApiKey(serverId, HttpContext); var cpuUsage = _mapper.Map <CpuUsageServer>(cpuUsageDto); cpuUsage.ServerId = server.Id; cpuUsage.CreatedAt = DateTime.Now; await _unitOfWork.CpuUsagesServers.Insert(cpuUsage); cpuUsage.Server = server; // check if within a minute a new cpu usage was reported. It has 40 seconds to post. // This check is to see if the server is offline or not _backgroundJobClient.Schedule <ServerPowerStatusSetter>(s => s.SetServerPowerStatus(server), new TimeSpan(0, 1, 10) ); await CPUEventLoggerChecker(cpuUsage); return(NoContent()); }
public async Task <IActionResult> SetNetworkAdapterServer( Guid serverId, [FromBody] IList <CreateNetworkAdapterServerDto> networkAdapterServerDto ) { var server = await ServerUtilController.GetUserHisServerFromApiKey(serverId, HttpContext); if (server == null) { return(BadRequest("Server id is either null or you are not the owner of the server.")); } var networkAdaptersOfServer = _mapper.Map <IList <NetworkAdapterServer> >(networkAdapterServerDto); // set the right server id networkAdaptersOfServer.ForAll(s => s.ServerId = serverId.ToString()); // so we overwrite the existing. await RemoveExistingNetworkAdaptersOfServer(serverId.ToString()); await _unitOfWork.NetworkAdaptersServer.InsertRange(networkAdaptersOfServer); return(NoContent()); }