Skip to content
Snippets Groups Projects
Commit 51522bc7 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Merge branch 'Product/1600-rdsS3QuotaManagement' into 'Sprint/2021-13'

Product/1600 rdsS3QuotaManagement

See merge request !161
parents 22493dde cbf714f7
Branches Sprint/2021-13
Tags
2 merge requests!161Product/1600 rdsS3QuotaManagement,!160Sprint/2021 13
...@@ -44,9 +44,6 @@ namespace Coscine.Api.Project.Controllers ...@@ -44,9 +44,6 @@ namespace Coscine.Api.Project.Controllers
private readonly InvitationModel _invitationModel; private readonly InvitationModel _invitationModel;
private readonly RoleModel _roleModel; private readonly RoleModel _roleModel;
private readonly UserModel _userModel; private readonly UserModel _userModel;
private readonly int _maxAvailable = 100;
private readonly string _userUrlPrefix = "https://purl.org/coscine/users";
private readonly Uri _orgPrefixUrl = new Uri("http://www.w3.org/ns/org#");
private readonly RdfStoreConnector _rdfStoreConnector; private readonly RdfStoreConnector _rdfStoreConnector;
/// <summary> /// <summary>
...@@ -213,10 +210,16 @@ namespace Coscine.Api.Project.Controllers ...@@ -213,10 +210,16 @@ namespace Coscine.Api.Project.Controllers
Id = x.Id, Id = x.Id,
Name = x.DisplayName, Name = x.DisplayName,
Used = CalculateUsed(x, projectGuid), Used = CalculateUsed(x, projectGuid),
Allocated = projectQuota == null ? 0 : projectQuota.Quota Allocated = projectQuota == null ? 0 : projectQuota.Quota,
Maximum = projectQuota.MaxQuota
}; };
} }
private int GetMaxQuota(Guid projectId, Guid resourceTypeId)
{
return _projectQuotaModel.GetWhere(x => x.ProjectId == projectId && x.ResourceTypeId == resourceTypeId).MaxQuota;
}
private int CalculateUsed(ResourceType resourceType, Guid projectId) private int CalculateUsed(ResourceType resourceType, Guid projectId)
{ {
var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resourceType.DisplayName, _configuration); var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resourceType.DisplayName, _configuration);
...@@ -281,7 +284,8 @@ namespace Coscine.Api.Project.Controllers ...@@ -281,7 +284,8 @@ namespace Coscine.Api.Project.Controllers
Id = resourceTypeGuid, Id = resourceTypeGuid,
Name = resourceType.DisplayName, Name = resourceType.DisplayName,
Used = CalculateUsed(resourceType, projectGuid), Used = CalculateUsed(resourceType, projectGuid),
Allocated = projectQuota.Quota Allocated = projectQuota.Quota,
Maximum = projectQuota.MaxQuota
}; };
return Json(projectQuotaReturnObject); return Json(projectQuotaReturnObject);
...@@ -327,7 +331,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -327,7 +331,7 @@ namespace Coscine.Api.Project.Controllers
return NotFound($"Could not find resourceType with id: {resourceTypeId}"); return NotFound($"Could not find resourceType with id: {resourceTypeId}");
} }
return Json(new MaxProjectQuota { Id = resourceTypeGuid, Available = _maxAvailable }); return Json(new MaxProjectQuota { Id = resourceTypeGuid, Available = GetMaxQuota(projectGuid, resourceTypeGuid) });
} }
/// <summary> /// <summary>
...@@ -371,9 +375,16 @@ namespace Coscine.Api.Project.Controllers ...@@ -371,9 +375,16 @@ namespace Coscine.Api.Project.Controllers
return NotFound($"Could not find resourceType with id: {resourceTypeId}"); return NotFound($"Could not find resourceType with id: {resourceTypeId}");
} }
if (resourceType.DisplayName.Equals("rdss3")) var resourceTypeDefinition = ResourceTypeFactory.CreateResourceTypeObject(resourceType.DisplayName, _configuration);
if (resourceTypeDefinition == null)
{ {
return BadRequest($"Cannot adjust quota for rdss3."); return BadRequest($"No provider for: \"{resourceType.DisplayName}\".");
}
if (!resourceTypeDefinition.GetResourceTypeInformation().Result.IsQuotaAdjustable)
{
return BadRequest($"Cannot adjust quota for {resourceType.DisplayName}.");
} }
if (updateProjectQuotaObject.Allocated < 0) if (updateProjectQuotaObject.Allocated < 0)
...@@ -389,9 +400,11 @@ namespace Coscine.Api.Project.Controllers ...@@ -389,9 +400,11 @@ namespace Coscine.Api.Project.Controllers
return BadRequest($"Cannot set quota ({updateProjectQuotaObject.Allocated}) below the used value ({used})."); return BadRequest($"Cannot set quota ({updateProjectQuotaObject.Allocated}) below the used value ({used}).");
} }
if (updateProjectQuotaObject.Allocated > _maxAvailable) var maxAvailabe = GetMaxQuota(projectGuid, resourceTypeGuid);
if (updateProjectQuotaObject.Allocated > maxAvailabe)
{ {
return BadRequest($"Cannot set quota to {updateProjectQuotaObject.Allocated}. It would exceed the limit of {_maxAvailable}"); return BadRequest($"Cannot set quota to {updateProjectQuotaObject.Allocated}. It would exceed the limit of {maxAvailabe}");
} }
projectQuotaForCurrent.Quota = updateProjectQuotaObject.Allocated; projectQuotaForCurrent.Quota = updateProjectQuotaObject.Allocated;
......
...@@ -23,5 +23,6 @@ ...@@ -23,5 +23,6 @@
<PackageReference Include="Coscine.Logging" Version="2.*-*" /> <PackageReference Include="Coscine.Logging" Version="2.*-*" />
<PackageReference Include="Coscine.Metadata" Version="2.*-*" /> <PackageReference Include="Coscine.Metadata" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" /> <PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" />
<PackageReference Include="Coscine.ResourceTypeBase" Version="2.*-*" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -23,5 +23,10 @@ namespace Coscine.Api.Project.ReturnObjects ...@@ -23,5 +23,10 @@ namespace Coscine.Api.Project.ReturnObjects
/// How much space is availabe to be taken by resources (in gb). /// How much space is availabe to be taken by resources (in gb).
/// </summary> /// </summary>
public int Allocated { get; set; } public int Allocated { get; set; }
/// <summary>
/// Maximum amount of quota (in gb).
/// </summary>
public int Maximum { get; set; }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment