Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Update and enable storage command]: reset command for storage account #200

Merged
merged 8 commits into from
Sep 30, 2023

Conversation

melindawangmsft
Copy link
Collaborator

work item:#192

doc/storageCommand.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
int resetAssetCount = 0;
foreach (var asset in assetList)
}
protected async Task MigrateTaskAsync(BlobContainerClient container, int resetAssetCount, CancellationToken cancellationToken)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues on this function:

(1) param int resetAssetCount should be changed to "ref int resetAssetCount", because this value is updated inside the function, and it should be reported back to the caller.

(2) protected can be changed to private, there is no derived class from ResetCommand.

}
_logger.LogDebug("{resetAssetCount} out of {totalAssetCount} assets has been reset.", resetAssetCount, assetList.Count);
}
else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here should be moved to the place where it is not an AMS account, nor Storage Account. A good place is to move to after line 39, when it is not a storage account, throw the exception.

}
catch (Exception)
else if (account != null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If IsAMSAccountAsync return true, would the account is always not null, this check seems not right.

The similar code pattern applies to all other classes.

ams/BaseMigrator.cs Outdated Show resolved Hide resolved
ams/BaseMigrator.cs Outdated Show resolved Hide resolved
{
return (false, account);
}
return account ==null?(false, account):(true, account);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case, when this exception is throw, but account is still not null?

Comment on lines 66 to 77
try
{
account = await GetMediaAccountAsync(accountName, cancellationToken);
return (true, account);
}
catch (RequestFailedException ex)
{
if (ex.ErrorCode != null && ex.ErrorCode.Equals("ResourceNotFound"))
{
return (false, account);
}
return account ==null?(false, account):(true, account);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can be changed as below:

    protected async Task<(bool, MediaServicesAccountResource?)> IsAMSAccountAsync(string accountName, CancellationToken cancellationToken)
    {  
        MediaServicesAccountResource? amsAccount = null;

        try
        {
            amsAccount = await _resourceProvider.GetMediaAccountAsync(accountName, cancellationToken);
        }
        catch (Exception ex)
        {
            if (ex is OutOfMemoryException) throw;  // It is a fatal error.

            // For any other exception, swallow the exception, treat it as not-AMS account, 
            // The caller then has a chance to treat it as storage account and try it again,
            // if it is still failed, the caller will throw exception appropriately.
        }

        return (amsAccount != null, amsAccount);
    }

Once this function returns true, the AmsAccount must be available, if it is false, the caller should do further check if it is a storage account, otherwise, report error or throw exception in the caller side.

@melindawangmsft melindawangmsft merged commit 95420a0 into main Sep 30, 2023
2 of 3 checks passed
@melindawangmsft melindawangmsft deleted the melinda/storage branch September 30, 2023 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants