-
Notifications
You must be signed in to change notification settings - Fork 564
[ResilienceManagement] Add create commands (namespace: resilience) #2990
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
LavishSingal
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
LavishSingal:user/lsingal/resilience-create-v2
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
4 commits
Select commit
Hold shift + click to select a range
5c9c22b
Add resilience create tools (goal template/assignment, usage plan, en…
LavishSingal 34adfc9
Add resilience create commands to consolidated-tools.json
LavishSingal 71c3eec
Merge remote-tracking branch 'upstream/main' into user/lsingal/resili…
LavishSingal c948a65
fixed metadata
LavishSingal 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
Some comments aren't visible on the classic Files Changed page.
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
9 changes: 9 additions & 0 deletions
9
servers/Azure.Mcp.Server/changelog-entries/1782549900000.yaml
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,9 @@ | ||
| changes: | ||
| - section: "Features Added" | ||
| description: "Added the 'azmcp resilience goal template create' command to create or update a resilience goal template in a service group, including its goal type, high availability and disaster recovery requirements, and regional recovery point and time objectives." | ||
| - section: "Features Added" | ||
| description: "Added the 'azmcp resilience usageplan create' command to create a resilience usage plan in a resource group, including its plan type." | ||
| - section: "Features Added" | ||
| description: "Added the 'azmcp resilience usageplan enrollment create' command to create or update an enrollment under a resilience usage plan, associating it with a service group." | ||
| - section: "Features Added" | ||
| description: "Added the 'azmcp resilience goal assignment create' command to create or update a resilience goal assignment in a service group that assigns a goal template." |
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
79 changes: 79 additions & 0 deletions
79
....Tools.ResilienceManagement/src/Commands/Goals/Assignments/GoalAssignmentCreateCommand.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,79 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Net; | ||
| using Azure.Mcp.Core.Commands.Subscription; | ||
| using Azure.Mcp.Core.Services.Azure.Subscription; | ||
| using Azure.Mcp.Tools.ResilienceManagement.Commands; | ||
| using Azure.Mcp.Tools.ResilienceManagement.Models; | ||
| using Azure.Mcp.Tools.ResilienceManagement.Options.Goals.Assignments; | ||
| using Azure.Mcp.Tools.ResilienceManagement.Services; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Mcp.Core.Commands; | ||
| using Microsoft.Mcp.Core.Models.Command; | ||
|
|
||
| namespace Azure.Mcp.Tools.ResilienceManagement.Commands.Goals.Assignments; | ||
|
|
||
| [CommandMetadata( | ||
| Id = "b8e4d1c6-3a07-4f29-9d85-2c6f0a7b1e94", | ||
| Name = "create", | ||
| Title = "Create or Update Resilience Goal Assignment", | ||
| Description = """ | ||
| Creates or updates a resilience goal assignment in the specified service group that assigns the given | ||
| goal template, and returns the goal assignment information including id, name, goal assignment type, | ||
| goal template id, and provisioning state. | ||
| """, | ||
| Destructive = false, | ||
| Idempotent = true, | ||
| OpenWorld = false, | ||
| ReadOnly = false, | ||
| Secret = false, | ||
| LocalRequired = false)] | ||
| public sealed class GoalAssignmentCreateCommand(ILogger<GoalAssignmentCreateCommand> logger, IResilienceManagementService resilienceManagementService, ISubscriptionResolver subscriptionResolver) | ||
| : SubscriptionCommand<GoalAssignmentCreateOptions, GoalAssignmentCreateCommand.GoalAssignmentCreateCommandResult>(subscriptionResolver) | ||
| { | ||
| private readonly ILogger<GoalAssignmentCreateCommand> _logger = logger; | ||
| private readonly IResilienceManagementService _resilienceManagementService = resilienceManagementService; | ||
|
|
||
| public override async Task<CommandResponse> ExecuteAsync(CommandContext context, GoalAssignmentCreateOptions options, CancellationToken cancellationToken) | ||
| { | ||
| try | ||
| { | ||
| var goalAssignment = await _resilienceManagementService.CreateGoalAssignmentAsync( | ||
| options.ServiceGroup, | ||
| options.GoalAssignment, | ||
| options.GoalTemplate, | ||
| options.GoalTemplateServiceGroup, | ||
| options.GoalAssignmentType, | ||
| options.Subscription!, | ||
| options.Tenant, | ||
| options.RetryPolicy, | ||
| cancellationToken); | ||
|
|
||
| context.Response.Results = ResponseResult.Create( | ||
| new GoalAssignmentCreateCommandResult(goalAssignment), | ||
| ResilienceManagementJsonContext.Default.GoalAssignmentCreateCommandResult); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, | ||
| "Error creating goal assignment. ServiceGroup: {ServiceGroup}, GoalAssignment: {GoalAssignment}, GoalTemplate: {GoalTemplate}, Subscription: {Subscription}.", | ||
| options.ServiceGroup, options.GoalAssignment, options.GoalTemplate, options.Subscription); | ||
| HandleException(context, ex); | ||
| } | ||
|
|
||
| return context.Response; | ||
| } | ||
|
|
||
| protected override string GetErrorMessage(Exception ex) => ex switch | ||
| { | ||
| RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.Forbidden => | ||
| $"Authorization failed creating the goal assignment. Details: {reqEx.Message}", | ||
| RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.NotFound => | ||
| "Service group or goal template not found. Verify they exist and you have access.", | ||
| RequestFailedException reqEx => reqEx.Message, | ||
| _ => base.GetErrorMessage(ex) | ||
| }; | ||
|
|
||
| public record GoalAssignmentCreateCommandResult(GoalAssignmentInfo GoalAssignment); | ||
| } | ||
82 changes: 82 additions & 0 deletions
82
....Mcp.Tools.ResilienceManagement/src/Commands/Goals/Templates/GoalTemplateCreateCommand.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,82 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Net; | ||
| using Azure.Mcp.Core.Commands.Subscription; | ||
| using Azure.Mcp.Core.Services.Azure.Subscription; | ||
| using Azure.Mcp.Tools.ResilienceManagement.Commands; | ||
| using Azure.Mcp.Tools.ResilienceManagement.Models; | ||
| using Azure.Mcp.Tools.ResilienceManagement.Options.Goals.Templates; | ||
| using Azure.Mcp.Tools.ResilienceManagement.Services; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Mcp.Core.Commands; | ||
| using Microsoft.Mcp.Core.Models.Command; | ||
|
|
||
| namespace Azure.Mcp.Tools.ResilienceManagement.Commands.Goals.Templates; | ||
|
|
||
| [CommandMetadata( | ||
| Id = "f1d6b3a8-7c25-4e90-9b14-6a2d8f0c5e37", | ||
| Name = "create", | ||
| Title = "Create or Update Resilience Goal Template", | ||
| Description = """ | ||
| Creates or updates a resilience goal template in the specified service group with the given high | ||
| availability and disaster recovery requirements and regional recovery point and time objectives, and | ||
| returns the goal template information including id, name, goal type, provisioning state, recovery point | ||
| and time objectives, and high availability and disaster recovery requirements. | ||
| """, | ||
| Destructive = false, | ||
| Idempotent = true, | ||
| OpenWorld = false, | ||
| ReadOnly = false, | ||
| Secret = false, | ||
| LocalRequired = false)] | ||
| public sealed class GoalTemplateCreateCommand(ILogger<GoalTemplateCreateCommand> logger, IResilienceManagementService resilienceManagementService, ISubscriptionResolver subscriptionResolver) | ||
| : SubscriptionCommand<GoalTemplateCreateOptions, GoalTemplateCreateCommand.GoalTemplateCreateCommandResult>(subscriptionResolver) | ||
| { | ||
| private readonly ILogger<GoalTemplateCreateCommand> _logger = logger; | ||
| private readonly IResilienceManagementService _resilienceManagementService = resilienceManagementService; | ||
|
|
||
| public override async Task<CommandResponse> ExecuteAsync(CommandContext context, GoalTemplateCreateOptions options, CancellationToken cancellationToken) | ||
| { | ||
| try | ||
| { | ||
| var goalTemplate = await _resilienceManagementService.CreateGoalTemplateAsync( | ||
| options.ServiceGroup, | ||
| options.GoalTemplate, | ||
| options.GoalType, | ||
| options.RequireHighAvailability, | ||
| options.RequireDisasterRecovery, | ||
| options.RegionalRecoveryPointObjective, | ||
| options.RegionalRecoveryTimeObjective, | ||
| options.Subscription!, | ||
| options.Tenant, | ||
| options.RetryPolicy, | ||
| cancellationToken); | ||
|
|
||
| context.Response.Results = ResponseResult.Create( | ||
| new GoalTemplateCreateCommandResult(goalTemplate), | ||
| ResilienceManagementJsonContext.Default.GoalTemplateCreateCommandResult); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, | ||
| "Error creating goal template. ServiceGroup: {ServiceGroup}, GoalTemplate: {GoalTemplate}, Subscription: {Subscription}.", | ||
| options.ServiceGroup, options.GoalTemplate, options.Subscription); | ||
| HandleException(context, ex); | ||
| } | ||
|
|
||
| return context.Response; | ||
| } | ||
|
|
||
| protected override string GetErrorMessage(Exception ex) => ex switch | ||
| { | ||
| RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.Forbidden => | ||
| $"Authorization failed creating the goal template. Details: {reqEx.Message}", | ||
| RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.NotFound => | ||
| "Service group not found. Verify the service group exists and you have access.", | ||
| RequestFailedException reqEx => reqEx.Message, | ||
| _ => base.GetErrorMessage(ex) | ||
| }; | ||
|
|
||
| public record GoalTemplateCreateCommandResult(GoalTemplateInfo GoalTemplate); | ||
| } |
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
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.
This command extends from Subscription command, but it doesn't use subscription parameter, does it ?
If not, we should not extend from Subscription command.