Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Storage/API/IStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ public interface IStorageService
/// <param name="bucketName">Name of the bucket</param>
/// <param name="objectDict">Artifact dictionary to verify</param>
/// <returns>all valid artifacts</returns>
Task<Dictionary<string, string>> VerifyObjectsExist(string bucketName, Dictionary<string, string> objectDict);
Dictionary<string, string> VerifyObjectsExist(string bucketName, Dictionary<string, string> objectDict);

/// <summary>
/// Verifies the existance of an artifact to ensure that they exist.
/// </summary>
/// <param name="bucketName">Name of the bucket</param>
/// <param name="objectPair">Artifact to verify</param>
/// <returns>valid artifact</returns>
KeyValuePair<string, string> VerifyObjectExists(string bucketName, KeyValuePair<string, string> objectPair);
}
}
39 changes: 33 additions & 6 deletions src/Storage/MinIo/MinIoStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.Extensions.Options;
using Minio;
using Minio.DataModel;
using Minio.Exceptions;
using Monai.Deploy.Storage.Common;
using Monai.Deploy.Storage.Common.Extensions;
using Monai.Deploy.Storage.Configuration;
Expand Down Expand Up @@ -121,7 +120,7 @@ public IList<VirtualFileInfo> ListObjects(string bucketName, string? prefix = ""
return files;
}

public async Task<Dictionary<string, string>> VerifyObjectsExist(string bucketName, Dictionary<string, string> objectDict)
public Dictionary<string, string> VerifyObjectsExist(string bucketName, Dictionary<string, string> objectDict)
{
Guard.Against.NullOrWhiteSpace(bucketName, nameof(bucketName));
Guard.Against.Null(objectDict, nameof(objectDict));
Expand All @@ -132,19 +131,47 @@ public async Task<Dictionary<string, string>> VerifyObjectsExist(string bucketNa
{
try
{
await _client.StatObjectAsync(bucketName, $"{obj.Value}/{obj.Key}");
var fileObjects = ListObjects(bucketName, obj.Value);
var folderObjects = ListObjects(bucketName, obj.Value.EndsWith("/") ? obj.Value : $"{obj.Value}/", true);

existingObjectsDict.Add(obj.Key, obj.Value);
if (!folderObjects.Any() && !fileObjects.Any())
{
_logger.FileNotFoundError(bucketName, $"{obj.Value}");

continue;
}
}
catch (ObjectNotFoundException)
catch (Exception e)
{
_logger.FileNotFoundError(bucketName, $"{obj.Value}/{obj.Key}");
_logger.LogError(e.Message);

continue;
}

existingObjectsDict.Add(obj.Key, obj.Value);
}

return existingObjectsDict;
}

public KeyValuePair<string, string> VerifyObjectExists(string bucketName, KeyValuePair<string, string> objectPair)
{
Guard.Against.NullOrWhiteSpace(bucketName, nameof(bucketName));
Guard.Against.Null(objectPair, nameof(objectPair));

var fileObjects = ListObjects(bucketName, objectPair.Value);
var folderObjects = ListObjects(bucketName, objectPair.Value.EndsWith("/") ? objectPair.Value : $"{objectPair.Value}/", true);

if (folderObjects.Any() || fileObjects.Any())
{
return objectPair;
}

_logger.FileNotFoundError(bucketName, $"{objectPair.Value}");

return default;
}

public async Task PutObject(string bucketName, string objectName, Stream data, long size, string contentType, Dictionary<string, string> metadata, CancellationToken cancellationToken = default)
{
Guard.Against.NullOrWhiteSpace(bucketName, nameof(bucketName));
Expand Down