-
Notifications
You must be signed in to change notification settings - Fork 176
Add Azure Managed Lustre Filesystem Import Job Create #319
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
Open
KinoriSR
wants to merge
9
commits into
main
Choose a base branch
from
kinorirosnow/amlfs-hsm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1cdb3a8
import job create command
KinoriSR c2d4507
spellcheck fixes
KinoriSR 484fc4d
rename jobName to name
KinoriSR 461bf12
ImportJob namespace
KinoriSR a04e969
fix namespace, parameters, unit tests, deployment scripts
KinoriSR 9febbd4
unit/live test fixes
KinoriSR 77c099e
format, test fixes
KinoriSR f99ecd7
no need for null coalescing
KinoriSR 6fad6fb
remove option to do use Overwrite conflict resolution modes
KinoriSR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
....AzureManagedLustre/src/Commands/FileSystem/ImportJob/FileSystemImportJobCreateCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Mcp.Core.Commands; | ||
using Azure.Mcp.Core.Extensions; | ||
using Azure.Mcp.Tools.AzureManagedLustre.Options; | ||
using Azure.Mcp.Tools.AzureManagedLustre.Options.FileSystem; | ||
using Azure.Mcp.Tools.AzureManagedLustre.Services; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Azure.Mcp.Tools.AzureManagedLustre.Commands.FileSystem; | ||
|
||
public sealed class FileSystemImportJobCreateCommand(ILogger<FileSystemImportJobCreateCommand> logger) | ||
: BaseAzureManagedLustreCommand<FileSystemImportJobCreateOptions>(logger) | ||
{ | ||
private const string CommandTitle = "Create AMLFS Import Job"; | ||
|
||
private readonly Option<string> _fileSystemOption = AzureManagedLustreOptionDefinitions.FileSystemOption; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rebase and use new Option handling pattern. new-command.md can help |
||
private readonly Option<string[]> _importPrefixesOption = AzureManagedLustreOptionDefinitions.ImportPrefixesOption; | ||
private readonly Option<string> _conflictResolutionModeOption = AzureManagedLustreOptionDefinitions.ConflictResolutionModeOption; | ||
private readonly Option<int?> _maximumErrorsOption = AzureManagedLustreOptionDefinitions.MaximumErrorsOption; | ||
private readonly Option<string> _nameOption = AzureManagedLustreOptionDefinitions.NameOption; | ||
|
||
public override string Name => "create"; | ||
|
||
public override string Description => | ||
""" | ||
Creates a manual import job for an Azure Managed Lustre (AMLFS) file system. The import job scans the linked HSM/Blob container and imports specified path prefixes (or all when omitted) honoring the chosen conflict resolution mode. Use to hydrate the AMLFS namespace or refresh content. | ||
"""; | ||
|
||
public override string Title => CommandTitle; | ||
|
||
public override ToolMetadata Metadata => new() | ||
{ | ||
Destructive = false, | ||
Idempotent = true, | ||
OpenWorld = true, | ||
ReadOnly = false, | ||
LocalRequired = false, | ||
Secret = false | ||
}; | ||
|
||
protected override void RegisterOptions(Command command) | ||
{ | ||
base.RegisterOptions(command); | ||
RequireResourceGroup(); | ||
command.Options.Add(_fileSystemOption); | ||
command.Options.Add(_importPrefixesOption); | ||
command.Options.Add(_conflictResolutionModeOption); | ||
command.Options.Add(_maximumErrorsOption); | ||
command.Options.Add(_nameOption); | ||
} | ||
|
||
protected override FileSystemImportJobCreateOptions BindOptions(ParseResult parseResult) | ||
{ | ||
var options = base.BindOptions(parseResult); | ||
options.FileSystem = parseResult.GetValueOrDefault(_fileSystemOption); | ||
var prefixes = parseResult.GetValueOrDefault(_importPrefixesOption); | ||
if (prefixes == null || prefixes.Length == 0) | ||
{ | ||
options.ImportPrefixes = new List<string> { "/" }; | ||
} | ||
else | ||
{ | ||
options.ImportPrefixes = prefixes.ToList(); | ||
} | ||
var conflictMode = parseResult.GetValueOrDefault(_conflictResolutionModeOption); | ||
if (string.IsNullOrWhiteSpace(conflictMode)) | ||
{ | ||
conflictMode = "Skip"; // default | ||
} | ||
else | ||
{ | ||
if (!string.Equals(conflictMode, "Skip", StringComparison.OrdinalIgnoreCase) && | ||
!string.Equals(conflictMode, "Fail", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
throw new ArgumentException("Azure MCP Server's Managed Lustre tooling does not support the specified conflict resolution mode. This is because the mode doesn't exist or the tool does not support potentially destructive import conflict resolution modes (overwrite variants).", nameof(_conflictResolutionModeOption)); | ||
} | ||
// Normalize casing | ||
conflictMode = char.ToUpperInvariant(conflictMode[0]) + conflictMode.Substring(1).ToLowerInvariant(); | ||
} | ||
options.ConflictResolutionMode = conflictMode; | ||
options.MaximumErrors = parseResult.GetValueOrDefault(_maximumErrorsOption) ?? -1; | ||
options.AdminStatus = "Active"; // Hard-coded since service no longer accepts parameter | ||
options.Name = parseResult.GetValueOrDefault(_nameOption); | ||
return options; | ||
} | ||
|
||
public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult) | ||
{ | ||
var options = BindOptions(parseResult); | ||
try | ||
{ | ||
if (!Validate(parseResult.CommandResult, context.Response).IsValid) | ||
{ | ||
return context.Response; | ||
} | ||
|
||
var svc = context.GetService<IAzureManagedLustreService>(); | ||
var result = await svc.CreateImportJobAsync( | ||
options.Subscription!, | ||
options.ResourceGroup!, | ||
options.FileSystem!, | ||
options.Name, | ||
options.ImportPrefixes, | ||
options.ConflictResolutionMode!, | ||
options.MaximumErrors, | ||
options.Tenant, | ||
options.RetryPolicy); | ||
|
||
context.Response.Results = ResponseResult.Create( | ||
new FileSystemImportJobCreateResult(result), | ||
AzureManagedLustreJsonContext.Default.FileSystemImportJobCreateResult); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, | ||
"Error creating AMLFS import job. FileSystem: {FileSystem} ResourceGroup: {ResourceGroup} Options: {@Options}", | ||
options.FileSystem, options.ResourceGroup, options); | ||
HandleException(context, ex); | ||
} | ||
|
||
return context.Response; | ||
} | ||
|
||
protected override int GetStatusCode(Exception ex) => ex switch | ||
{ | ||
Azure.RequestFailedException reqEx => reqEx.Status, | ||
_ => base.GetStatusCode(ex) | ||
}; | ||
|
||
internal record FileSystemImportJobCreateResult(Models.ImportJobInfo ImportJob); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...s.AzureManagedLustre/src/Options/FileSystem/ImportJob/FileSystemImportJobCreateOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
namespace Azure.Mcp.Tools.AzureManagedLustre.Options.FileSystem; | ||
|
||
public sealed class FileSystemImportJobCreateOptions : BaseAzureManagedLustreOptions | ||
{ | ||
[JsonPropertyName(AzureManagedLustreOptionDefinitions.fileSystem)] | ||
public string? FileSystem { get; set; } | ||
|
||
[JsonPropertyName(AzureManagedLustreOptionDefinitions.importPrefixes)] | ||
public IList<string>? ImportPrefixes { get; set; } | ||
|
||
[JsonPropertyName(AzureManagedLustreOptionDefinitions.conflictResolutionMode)] | ||
public string? ConflictResolutionMode { get; set; } | ||
|
||
[JsonPropertyName(AzureManagedLustreOptionDefinitions.maximumErrors)] | ||
public int? MaximumErrors { get; set; } | ||
|
||
[JsonPropertyName(AzureManagedLustreOptionDefinitions.adminStatus)] | ||
public string? AdminStatus { get; set; } | ||
|
||
[JsonPropertyName(AzureManagedLustreOptionDefinitions.name)] | ||
public string? Name { get; set; } | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't include azure in the name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a planned refactor which will be addressed after the current PRed actions are in. Here is the open conversion issue: #345 .
Is this a sufficient solution for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take that as a PR this week, thanks.