Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Fix/xxxx-resourceVisibility
  • Hotfix/1357-ymlFile
  • Hotfix/1370-swaggerDescription
  • Hotfix/2077-fixSupportAdminLog
  • Hotfix/2087-efNet6
  • Hotfix/2224-quotaSizeAnalytics
  • Hotfix/2427-adminTrouble
  • Hotfix/82-updateDepsOfAPIs
  • Issue/1866-ExtendResourceTypeConfigurationTUDo
  • Issue/1877-ExtendResourceTypeConfigurationNRWFHs
  • Issue/1910-MigrationtoNET6.0
  • Issue/1940ResouceKeysForNRWAndTUDO
  • Issue/1951-quotaImplementation
  • Issue/2001-extendAnalyticsLogger
  • Issue/2061-activateResourceTypeRdss3nrw
  • Issue/2072-wormResourceType
  • Issue/2309-docs
  • Issue/2330-fixNaNQuotainAdmin
  • Product/1119-quotaAdminPage
  • Product/1287-dotnet5Sharepoint
  • Product/1559-rdsS3QuotaManagement
  • Product/1600-rdsS3QuotaManagement
  • Product/1623-allocatedQuotaForAdmin
  • Sprint/2020-22
  • Sprint/2021-03
  • Sprint/2021-05
  • Sprint/2021-08
  • Sprint/2021-13
  • Sprint/2021-17
  • Sprint/2021-23
  • Sprint/2022-01
  • Sprint/2022-05
  • Topic/1163-adminApi
  • Topic/1335-dotnet5Apis
  • Topic/1568-quotaApiAdjustments
  • Topic/1688-allocatedQuotaForAdminApi
  • dev
  • gitkeep
  • master
  • v1.1.0
  • v2.0.0
  • v2.0.1
  • v2.0.2
  • v2.0.3
  • v2.1.0
  • v2.2.0
  • v2.2.1
  • v2.2.2
  • v2.3.0
  • v2.3.1
  • v2.3.2
  • v2.4.0
  • v2.5.0
  • v2.5.1
  • v2.5.2
  • v2.5.3
  • v2.5.4
  • v2.6.0
  • v2.6.1
  • v3.0.0
  • v3.0.1
  • v3.0.2
  • v3.0.3
  • v3.0.4
  • v3.0.5
  • v3.0.6
  • v3.0.7
  • v3.0.8
68 results

Target

Select target project
  • coscine/backend/apis/admin
1 result
Select Git revision
  • Fix/xxxx-resourceVisibility
  • Hotfix/1357-ymlFile
  • Hotfix/1370-swaggerDescription
  • Hotfix/2077-fixSupportAdminLog
  • Hotfix/2087-efNet6
  • Hotfix/2224-quotaSizeAnalytics
  • Hotfix/2427-adminTrouble
  • Hotfix/82-updateDepsOfAPIs
  • Issue/1866-ExtendResourceTypeConfigurationTUDo
  • Issue/1877-ExtendResourceTypeConfigurationNRWFHs
  • Issue/1910-MigrationtoNET6.0
  • Issue/1940ResouceKeysForNRWAndTUDO
  • Issue/1951-quotaImplementation
  • Issue/2001-extendAnalyticsLogger
  • Issue/2061-activateResourceTypeRdss3nrw
  • Issue/2072-wormResourceType
  • Issue/2309-docs
  • Issue/2330-fixNaNQuotainAdmin
  • Product/1119-quotaAdminPage
  • Product/1287-dotnet5Sharepoint
  • Product/1559-rdsS3QuotaManagement
  • Product/1600-rdsS3QuotaManagement
  • Product/1623-allocatedQuotaForAdmin
  • Sprint/2020-22
  • Sprint/2021-03
  • Sprint/2021-05
  • Sprint/2021-08
  • Sprint/2021-13
  • Sprint/2021-17
  • Sprint/2021-23
  • Sprint/2022-01
  • Sprint/2022-05
  • Topic/1163-adminApi
  • Topic/1335-dotnet5Apis
  • Topic/1568-quotaApiAdjustments
  • Topic/1688-allocatedQuotaForAdminApi
  • dev
  • gitkeep
  • master
  • v1.1.0
  • v2.0.0
  • v2.0.1
  • v2.0.2
  • v2.0.3
  • v2.1.0
  • v2.2.0
  • v2.2.1
  • v2.2.2
  • v2.3.0
  • v2.3.1
  • v2.3.2
  • v2.4.0
  • v2.5.0
  • v2.5.1
  • v2.5.2
  • v2.5.3
  • v2.5.4
  • v2.6.0
  • v2.6.1
  • v3.0.0
  • v3.0.1
  • v3.0.2
  • v3.0.3
  • v3.0.4
  • v3.0.5
  • v3.0.6
  • v3.0.7
  • v3.0.8
68 results
Show changes
Commits on Source (4)
......@@ -5,7 +5,7 @@
<AssemblyName>Coscine.Api.Admin</AssemblyName>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFramework>net6.0</TargetFramework>
<Version>2.6.1</Version>
<Version>3.0.0</Version>
</PropertyGroup>
<PropertyGroup>
<Authors>RWTH Aachen University</Authors>
......@@ -21,6 +21,6 @@
<PackageReference Include="Coscine.ApiCommons" Version="2.*-*" />
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Metadata" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypes" Version="*-*" />
<PackageReference Include="Coscine.ResourceTypes" Version="1.*-*" />
</ItemGroup>
</Project>
......@@ -5,6 +5,7 @@ using Coscine.Api.Admin.ReturnObjects;
using Coscine.ApiCommons;
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.Database.ReturnObjects;
using Coscine.Logging;
using Coscine.Metadata;
using Coscine.ResourceTypes;
......@@ -35,7 +36,6 @@ namespace Coscine.Api.Admin.Controllers
private readonly ProjectQuotaModel _projectQuotaModel;
private readonly ResourceTypeModel _resourceTypeModel;
private readonly Emitter _emitter;
private readonly float _oneGb = 1024 * 1024 * 1024;
private readonly CoscineLogger _coscineLogger;
/// <summary>
......@@ -58,6 +58,115 @@ namespace Coscine.Api.Admin.Controllers
_coscineLogger = new CoscineLogger(logger);
}
/// <summary>
/// Find the project related to the projectString(GUID or slug)
/// </summary>
/// <param name="projectString">The project id (GUID) or slug (from URL).</param>
/// <returns>JSON list of all quotas.</returns>
[HttpGet("[controller]/{projectString}")]
public ActionResult<AdminProjectObject> GetProject(string projectString)
{
var user = _authenticator.GetUserId();
if (!HasRole(user, _adminRole))
{
return Unauthorized($"User does not have the role \"{_adminRole}\".");
}
Project project;
if (Guid.TryParse(projectString, out Guid guid))
{
project = _projectModel.GetById(guid);
}
else
{
project = _projectModel.GetBySlug(projectString);
}
if (project == null)
{
return NotFound("Project was not found.");
}
var quotas = _projectQuotaModel.GetAllWhere(x => x.ProjectId == project.Id);
return new AdminProjectObject
{
Id = project.Id,
ProjectName = project.ProjectName,
DisplayName = project.DisplayName,
Quotas = quotas.Select(x => CreateAdminQuotaReturnObject(x, project.Id)).ToList(),
};
}
/// <summary>
/// Update a project maximum and allocated quota
/// </summary>
/// <param name="projectId">Id of the project</param>
/// <param name="resourceTypeId">Id of the resource type</param>
/// <param name="updateQuotaParameter">JSON object for updating the project maximum and allocated quota.</param>
/// <returns>NoContent (204) on success.</returns>
[HttpPut("[controller]/{projectId}/{resourceTypeId}")]
public IActionResult UpdateQuota(Guid projectId, Guid resourceTypeId, [FromBody] UpdateQuotaParameterObject updateQuotaParameter)
{
var user = _authenticator.GetUser();
if (!HasRole(user.Id.ToString(), _adminRole))
{
return Unauthorized($"User does not have the role \"{_adminRole}\".");
}
var reservedQuotaGiB = CalculateAllocatedForAll(_resourceTypeModel.GetById(resourceTypeId), projectId);
if (reservedQuotaGiB > updateQuotaParameter.MaximumGiB)
{
return BadRequest($"Currently {reservedQuotaGiB} GB are reserved by resources in total. Can not set the new maximum quota lower than {reservedQuotaGiB}!");
}
var projectQuotaModel = new ProjectQuotaModel();
var projectQuota = _projectQuotaModel.GetWhere(x => x.ProjectId == projectId && x.ResourceTypeId == resourceTypeId);
if (projectQuota == null)
{
return NotFound("Quota was not found.");
}
projectQuota.MaxQuota = (int)updateQuotaParameter.MaximumGiB;
projectQuota.Quota = projectQuota.MaxQuota;
projectQuotaModel.Update(projectQuota);
_emitter.EmitQuotaChanged(new AdminEventArgs(Program.Configuration) { ProjectId = projectQuota.ProjectId });
if (Request.Query != null && Request.Query["noanalyticslog"] != "true")
{
LogAnalyticsAdminProjectQuotaChange(projectQuota.ProjectId, user);
}
return NoContent();
}
private void LogAnalyticsAdminProjectQuotaChange(Guid projectId, User user)
{
try
{
var quotas = _projectQuotaModel.GetAllWhere(x => x.ProjectId == projectId);
var quotaObjects = quotas.Select(x => CreateAdminQuotaReturnObject(x, projectId)).ToList();
_coscineLogger.AnalyticsLog(
new AnalyticsLogObject
{
Type = "Action",
Operation = "Admin Project Quota Change",
UserId = user.Id.ToString(),
ProjectId = projectId.ToString(),
QuotaSize = quotaObjects.ConvertAll(x => $"{x.ResourceType}: {x.TotalReserved}/{x.TotalUsed}")
});
}
#pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception.
catch (Exception)
#pragma warning restore RCS1075 // Avoid empty catch clause that catches System.Exception.
{
}
}
/// <summary>
/// Check if the user has a specific role.
/// </summary>
......@@ -128,142 +237,51 @@ namespace Coscine.Api.Admin.Controllers
select projectResource).Any() &&
resource.TypeId == resourceType.Id);
var used = Math.Ceiling(
resources.Sum(
resource =>
var used = resources.Sum(resource =>
{
// Linked has no quota.
var rt = ResourceTypeFactory.Instance.GetResourceType(resource);
if (rt.GetResourceTypeInformation().Result.IsQuotaAvailable)
{
return rt.GetResourceQuotaUsed(resource.Id.ToString(), _resourceModel.GetResourceTypeOptions(resource.Id)).Result / _oneGb;
return rt.GetResourceQuotaUsed(resource.Id.ToString(), _resourceModel.GetResourceTypeOptions(resource.Id)).Result;
}
else
{
return 0;
}
}
)
);
return (int)used;
}
/// <summary>
/// Find the project related to the projectString(GUID or slug)
/// </summary>
/// <param name="projectString">Either the id (GUID) of the project or the slug.</param>
/// <returns>JSON list of all quotas.</returns>
[HttpGet("[controller]/{projectString}")]
public ActionResult<ProjectObject> GetProject(string projectString)
private AdminQuotaReturnObject CreateAdminQuotaReturnObject(ProjectQuota projectQuota, Guid projectId)
{
var user = _authenticator.GetUserId();
if (!HasRole(user, _adminRole))
return new AdminQuotaReturnObject
{
return Unauthorized($@"User has not the role: ""{_adminRole}"".");
}
Project project;
if (Guid.TryParse(projectString, out Guid guid))
RelationId = projectQuota.RelationId,
ResourceType = _resourceTypeModel.GetById(projectQuota.ResourceTypeId).SpecificType,
Allocated = new QuotaDimObject()
{
project = _projectModel.GetById(guid);
}
else
Value = projectQuota.Quota,
Unit = QuotaUnit.GibiBYTE,
},
Maximum = new QuotaDimObject()
{
project = _projectModel.GetBySlug(projectString);
}
if (project == null)
{
return NotFound("Project was not found.");
}
var quotas = _projectQuotaModel.GetAllWhere(x => x.ProjectId == project.Id);
return new ProjectObject
{
GUID = project.Id,
Name = project.ProjectName,
ShortName = project.DisplayName,
Quotas = quotas.Select(x => new ProjectQuotaObject
{
QuotaId = x.RelationId,
ResourceType = _resourceTypeModel.GetById(x.ResourceTypeId).SpecificType,
Quota = x.Quota,
MaxQuota = x.MaxQuota,
Used = CalculateUsedForAll(_resourceTypeModel.GetById(x.ResourceTypeId), project.Id),
Allocated = CalculateAllocatedForAll(_resourceTypeModel.GetById(x.ResourceTypeId), project.Id)
}).ToList(),
};
}
/// <summary>
/// Update the project quota
/// </summary>
/// <param name="updateQuotaParameter">JSON object for updating quota.</param>
/// <returns>NoContent (204) on success.</returns>
[HttpPost("[controller]/")]
public IActionResult UpdateQuota([FromBody] UpdateQuotaParameterObject updateQuotaParameter)
Value = projectQuota.MaxQuota,
Unit = QuotaUnit.GibiBYTE,
},
TotalReserved = new QuotaDimObject()
{
var user = _authenticator.GetUser();
if (!HasRole(user.Id.ToString(), _adminRole))
Value = CalculateAllocatedForAll(_resourceTypeModel.GetById(projectQuota.ResourceTypeId), projectId),
Unit = QuotaUnit.GibiBYTE,
},
TotalUsed = new QuotaDimObject()
{
return Unauthorized($@"User has not the role: ""{_adminRole}"".");
}
var projectQuotaModel = new ProjectQuotaModel();
var projectQuota = projectQuotaModel.GetById(updateQuotaParameter.QuotaId);
if (projectQuota == null)
{
return NotFound("Quota was not found.");
}
projectQuota.MaxQuota = (int)updateQuotaParameter.Quota;
projectQuota.Quota = projectQuota.MaxQuota;
projectQuotaModel.Update(projectQuota);
_emitter.EmitQuotaChanged(new AdminEventArgs(Program.Configuration) { ProjectId = projectQuota.ProjectId });
if (Request.Query != null && Request.Query["noanalyticslog"] != "true")
{
LogAnalyticsAdminProjectQuotaChange(projectQuota.ProjectId, user);
}
return NoContent();
}
private void LogAnalyticsAdminProjectQuotaChange(Guid projectId, User user)
{
try
{
var quotas = _projectQuotaModel.GetAllWhere(x => x.ProjectId == projectId);
var quotaObjects = quotas.Select(x => new ProjectQuotaObject
{
QuotaId = x.RelationId,
ResourceType = _resourceTypeModel.GetById(x.ResourceTypeId).DisplayName,
Quota = x.Quota,
MaxQuota = x.MaxQuota,
Used = x.Quota,
Allocated = CalculateAllocatedForAll(_resourceTypeModel.GetById(x.ResourceTypeId), projectId)
}).ToList();
_coscineLogger.AnalyticsLog(
new AnalyticsLogObject
{
Type = "Action",
Operation = "Admin Project Quota Change",
UserId = user.Id.ToString(),
ProjectId = projectId.ToString(),
QuotaSize = quotaObjects.ConvertAll(x => $"{x.ResourceType}: {x.Allocated}/{x.Used}")
});
}
#pragma warning disable RCS1075 // Avoid empty catch clause that catches System.Exception.
catch (Exception)
#pragma warning restore RCS1075 // Avoid empty catch clause that catches System.Exception.
{
}
Value = CalculateUsedForAll(_resourceTypeModel.GetById(projectQuota.ResourceTypeId), projectId),
Unit = QuotaUnit.BYTE,
},
};
}
}
}
\ No newline at end of file
......@@ -8,13 +8,8 @@ namespace Coscine.Api.Admin.ParameterObjects
public class UpdateQuotaParameterObject
{
/// <summary>
/// The id (Guid) of the quota.
/// The new maximum project quota value.
/// </summary>
public Guid QuotaId { get; set; }
/// <summary>
/// The new quota value.
/// </summary>
public uint Quota { get; set; }
public uint MaximumGiB { get; set; }
}
}
......@@ -7,26 +7,26 @@ namespace Coscine.Api.Admin.ReturnObjects
/// Retuned when searching for a project.
/// Contains basic informations and quotas.
/// </summary>
public class ProjectObject
public class AdminProjectObject
{
/// <summary>
/// Projectname (full project name)
/// Project Id
/// </summary>
public string Name { get; set; }
public Guid Id { get; set; }
/// <summary>
/// Shortname (display name)
/// Project Name (full project name)
/// </summary>
public string ShortName { get; set; }
public string ProjectName { get; set; }
/// <summary>
/// GUID (project id)
/// Project Display Name
/// </summary>
public Guid GUID { get; set; }
public string DisplayName { get; set; }
/// <summary>
/// List of the project quotas (ProjectQuotaObject)
/// List of the admin quotas (AdminQuotaReturnObject)
/// </summary>
public List<ProjectQuotaObject> Quotas { get; set; }
public IEnumerable<AdminQuotaReturnObject> Quotas { get; set; }
}
}
using Coscine.Database.ReturnObjects;
using System;
namespace Coscine.Api.Admin.ReturnObjects
{
/// <summary>
/// Returned when searching for a project, as part of the AdminProjectObject.
/// Contains quota informations.
/// </summary>
public class AdminQuotaReturnObject
{
/// <summary>
/// Quota relation id (See Database, Table 'ProjectQuotas', Column 'RelationId').
/// </summary>
public Guid RelationId { get; set; }
/// <summary>
/// Which resource type the quota is referring to.
/// </summary>
public string ResourceType { get; set; }
/// <summary>
/// How much space is used by all files in all resources in total [Bytes].
/// </summary>
public QuotaDimObject TotalUsed { get; set; }
/// <summary>
/// How much space is reserved by resources in total [GiB]. Is equal to the sum of all resource quota reserved values.
/// </summary>
public QuotaDimObject TotalReserved { get; set; }
/// <summary>
/// How much space is currently allocated and is available to be taken by resources [GiB] (See Database, Table 'ProjectQuotas', Column 'Quota').
/// </summary>
public QuotaDimObject Allocated { get; set; }
/// <summary>
/// How much maximum space is possible to be taken by resources [GiB] (See Database, Table 'ProjectQuotas', Column 'MaxQuota').
/// </summary>
public QuotaDimObject Maximum { get; set; }
}
}
using System;
namespace Coscine.Api.Admin.ReturnObjects
{
/// <summary>
/// Returned when searching for a project, as part of the ProjectQbect.
/// Contains quota informations.
/// </summary>
public class ProjectQuotaObject
{
/// <summary>
/// Id of the quota.
/// </summary>
public Guid QuotaId { get; set; }
/// <summary>
/// Which resourceType the quota is referencing.
/// </summary>
public string ResourceType { get; set; }
/// <summary>
/// The quota value.
/// </summary>
public int Quota { get; set; }
/// <summary>
/// The MaxQuota value.
/// </summary>
public int MaxQuota { get; set; }
/// <summary>
/// How much space is used by the resource (rounded up and in gb).
/// </summary>
public int? Used { get; set; }
/// <summary>
/// How much space is availabe to be taken by resource (in gb).
/// </summary>
public int? Allocated { get; set; }
}
}