Skip to content
Snippets Groups Projects

New: Total used quota for a bucket method

Merged Petar Hristov requested to merge Issue/1951-quotaImplementation into dev
2 files
+ 57
15
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 55
15
@@ -16,11 +16,13 @@ namespace Coscine.ECSManager
public EcsManagerConfiguration EcsManagerConfiguration { get; set; }
/// <summary>
/// Creates a bucket with the provided bucket name and quota.
/// Creates a bucket with the provided bucket name and quota [GiB].
/// </summary>
/// <param name="bucketName">Name of the bucket</param>
/// <param name="quota">Quota for the bucket</param>
/// <param name="retention">Default retention period in seconds</param>
/// <param name="bucketName">Name of the bucket.</param>
/// <param name="quota">Quota for the bucket in GibiBYTE [GiB].</param>
/// <param name="retention">Default retention period in seconds [s].</param>
/// <returns>Nothing</returns>
/// <exception cref="Exception"></exception>
public async Task CreateBucket(string bucketName, long quota, long retention = 0L)
{
if (quota == 0 || quota < EcsManagerConfiguration.BucketQuotaMin || quota > EcsManagerConfiguration.BucketQuotaMax)
@@ -46,10 +48,10 @@ namespace Coscine.ECSManager
}
/// <summary>
/// Delete a bucket with the provided bucket name.
/// Deletes a bucket by its bucket name.
/// </summary>
/// /// <param name="bucketName">Name of the bucket</param>
/// /// <returns>Operation success
/// <param name="bucketName">Name of the bucket.</param>
/// <returns>Operation success boolean.</returns>
public async Task<bool> DeleteBucket(string bucketName)
{
// create new management client USING NAMESPACE ADMINISTRATOR to obtain token
@@ -69,11 +71,12 @@ namespace Coscine.ECSManager
}
/// <summary>
/// Sets the quota for the bucket.
/// Sets the quota for the bucket [GiB].
/// </summary>
/// /// <param name="bucketName">Name of the bucket</param>
/// /// <param name="quota">Quota for the bucket</param>
/// /// <returns>Operation success
/// <param name="bucketName">Name of the bucket.</param>
/// <param name="quota">Quota for the bucket in GibiBYTE [GiB].</param>
/// <returns>Operation success boolean.</returns>
/// <exception cref="Exception">Quota minimum compared to quota bucket maximum.</exception>
public async Task<bool> SetBucketQuota(string bucketName, long quota)
{
if (quota == 0 || quota < EcsManagerConfiguration.BucketQuotaMin || quota > EcsManagerConfiguration.BucketQuotaMax)
@@ -99,10 +102,10 @@ namespace Coscine.ECSManager
}
/// <summary>
/// Gets the quota for the bucket.
/// Gets the reserved quota for the bucket [GiB].
/// </summary>
/// /// <param name="bucketName">Name of the bucket</param>
/// /// <returns>Quota of the bucket
/// <param name="bucketName">Name of the bucket.</param>
/// <returns>Reserved bucket quota in GibiBYTE (GiB).</returns>
public async Task<long> GetBucketQuota(string bucketName)
{
// create new management client USING NAMESPACE ADMINISTRATOR to obtain token
@@ -120,7 +123,7 @@ namespace Coscine.ECSManager
var getBucketQuotaResult = await service.GetBucketQuota(bucketName, EcsManagerConfiguration.NamespaceName);
if (getBucketQuotaResult != null)
{
bucketQuota = getBucketQuotaResult.blockSize;
bucketQuota = getBucketQuotaResult.blockSize; // [GiB]
}
}
catch
@@ -301,5 +304,42 @@ namespace Coscine.ECSManager
return getAclResult;
}
/// <summary>
/// Gets the total used quota for the bucket [Byte].
/// </summary>
/// <param name="bucketName">Name of the bucket.</param>
/// <returns>Total used quota by all files in the bucket in BYTE (Byte).</returns>
public async Task<long> GetBucketTotalUsedQuota(string bucketName)
{
// create new management client USING NAMESPACE ADMINISTRATOR to obtain token
using var client = new CoscineECSManagementClient(EcsManagerConfiguration.NamespaceAdminName, EcsManagerConfiguration.NamespaceAdminPassword, EcsManagerConfiguration.ManagerApiEndpoint);
// authenticate
await client.Authenticate();
// using authenticated client, obtain new instance of service client
var service = client.CreateServiceClient();
decimal bucketQuota = 0;
try
{
var getBucketBillingInfo = await service.GetBucketBillingInfo(EcsManagerConfiguration.NamespaceName, bucketName, "KB");
if (getBucketBillingInfo != null)
{
bucketQuota = getBucketBillingInfo.total_size; // [KiB]
}
}
catch
{
}
finally
{
await client.LogOut();
}
// Value update time has a delay of 30 sec to a minute.
return Convert.ToInt64(bucketQuota * 1024); // KiB to Byte
}
}
}
\ No newline at end of file
Loading