Add Garnet cache cluster PowerShell cmdlets - #29933
Conversation
|
Thank you for your contribution @kcheekuri! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
Pull request overview
This PR adds new Az.CosmosDB cmdlets and supporting model/constants intended to manage “Garnet” cache clusters (create/get/update/delete), and wires them into the module export surface and changelog.
Changes:
- Added new Garnet cluster cmdlets:
New-,Get-,Update-,Remove-AzCosmosDBGarnetCluster. - Added a PowerShell-facing result wrapper model (
PSGarnetClusterGetResults) and help-message constants. - Updated module exports (psd1), CosmosDB management SDK AutoRest config (README), and CosmosDB module ChangeLog entry.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CosmosDB/CosmosDB/Models/PSGarnetClusterGetResults.cs | Adds PowerShell wrapper types for Garnet cluster get results/properties. |
| src/CosmosDB/CosmosDB/Helpers/Constants.cs | Introduces help-message constants for the new cmdlets’ parameters. |
| src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs | Implements New-AzCosmosDBGarnetCluster cmdlet. |
| src/CosmosDB/CosmosDB/Garnet/GetAzCosmosDBGarnetCluster.cs | Implements Get-AzCosmosDBGarnetCluster cmdlet. |
| src/CosmosDB/CosmosDB/Garnet/UpdateAzCosmosDBGarnetCluster.cs | Implements Update-AzCosmosDBGarnetCluster cmdlet. |
| src/CosmosDB/CosmosDB/Garnet/RemoveAzCosmosDBGarnetCluster.cs | Implements Remove-AzCosmosDBGarnetCluster cmdlet. |
| src/CosmosDB/CosmosDB/ChangeLog.md | Adds an “Upcoming Release” entry describing the new cmdlets. |
| src/CosmosDB/CosmosDB/Az.CosmosDB.psd1 | Exports the new cmdlets from the Az.CosmosDB module. |
| src/CosmosDB/CosmosDB.Management.Sdk/README.md | Updates AutoRest input configuration to include the 2026-04-01-preview Garnet OpenAPI. |
Comments suppressed due to low confidence (8)
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:95
- CosmosDBManagementClient from the in-repo CosmosDB.Management.Sdk project does not currently expose a GarnetClusters operation group (there are no "Garnet"/"GarnetClusters" types in CosmosDB.Management.Sdk/Generated). These calls to CosmosDBManagementClient.GarnetClusters will fail to compile until the management SDK is regenerated and committed (or the correct SDK reference is added).
GarnetClusterResource result = CosmosDBManagementClient.GarnetClusters.CreateUpdateWithHttpMessagesAsync(
ResourceGroupName,
Name,
garnetCluster).GetAwaiter().GetResult().Body;
WriteObject(new PSGarnetClusterGetResults(result));
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:55
- Using
SwitchParameterhere only allows setting AvailabilityZone to true (presence) or leaving it unspecified; it doesn't allow explicitly setting it to false. Other CosmosDB cmdlets typically use nullable booleans (bool?) for these optional flags so callers can pass$trueor$false.
public SwitchParameter AvailabilityZone { get; set; }
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:79
- After changing the AvailabilityZone parameter to
bool?, the model assignment should pass the value through directly rather than converting from a SwitchParameter.
AvailabilityZone = AvailabilityZone.IsPresent ? true : (bool?)null,
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:61
- Using
SwitchParameterfor Persistence prevents callers from explicitly setting persistence to false (it can only be enabled via switch presence). Consider usingbool?to allow$true/$falseand preserve 'not specified' via null.
public SwitchParameter Persistence { get; set; }
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:81
- After changing the Persistence parameter to
bool?, pass the value through directly into the SDK model instead of translating from a SwitchParameter.
Persistence = Persistence.IsPresent ? true : (bool?)null,
src/CosmosDB/CosmosDB/Garnet/GetAzCosmosDBGarnetCluster.cs:57
- When
-Nameis provided without-ResourceGroupName, this cmdlet currently ignoresNameand returns all clusters in the subscription. EitherNameshould be rejected without a resource group, or the subscription list should be filtered by name.
else
{
IEnumerable<GarnetClusterResource> garnetClusters = CosmosDBManagementClient.GarnetClusters.ListBySubscriptionWithHttpMessagesAsync().GetAwaiter().GetResult().Body;
foreach (GarnetClusterResource garnetCluster in garnetClusters)
{
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:27
- This PR adds four new cmdlets with non-trivial create/get/update/delete behavior, but no corresponding scenario tests (and recordings) were added under src/CosmosDB/CosmosDB.Test. CosmosDB already has extensive ScenarioTests coverage for other cmdlets, so these should be covered as well to prevent regressions.
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBGarnetCluster", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSGarnetClusterGetResults))]
public class NewAzCosmosDBGarnetCluster : AzureCosmosDBCmdletBase
src/CosmosDB/CosmosDB/Garnet/GetAzCosmosDBGarnetCluster.cs:43
- This references
CosmosDBManagementClient.GarnetClusters, but the in-repo CosmosDB.Management.Sdk project currently has no generated GarnetClusters operation group (no "Garnet" types under CosmosDB.Management.Sdk/Generated). This will not compile until the management SDK is regenerated/updated to include GarnetClusters.
GarnetClusterResource garnetCluster = CosmosDBManagementClient.GarnetClusters.GetWithHttpMessagesAsync(ResourceGroupName, Name).GetAwaiter().GetResult().Body;
WriteObject(new PSGarnetClusterGetResults(garnetCluster));
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; |
| using Microsoft.Azure.Commands.CosmosDB.Helpers; | ||
| using Microsoft.Azure.Commands.CosmosDB.Models; | ||
| using Microsoft.Azure.Management.CosmosDB.Models; | ||
| using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; |
| [Parameter(Mandatory = false, HelpMessage = Constants.GarnetClusterPersistenceHelpMessage)] | ||
| public SwitchParameter Persistence { get; set; } |
| ClusterType = ClusterType, | ||
| Extensions = Extensions != null ? new List<string>(Extensions) : null, | ||
| AuthenticationMethod = AuthenticationMethod, | ||
| Persistence = Persistence.IsPresent ? true : (bool?)null |
| // Garnet Cluster constants | ||
| public const string GarnetClusterNameHelpMessage = "Name of the Garnet Cluster."; | ||
| public const string GarnetClusterObjectHelpMessage = "Garnet Cluster Object."; | ||
| public const string GarnetClusterSubnetIdHelpMessage = "Resource id of a subnet that this cluster's management service should have its network interface attached to."; |
| GarnetClusterResource result = CosmosDBManagementClient.GarnetClusters.UpdateWithHttpMessagesAsync( | ||
| ResourceGroupName, | ||
| Name, | ||
| patch).GetAwaiter().GetResult().Body; | ||
| WriteObject(new PSGarnetClusterGetResults(result)); |
|
|
||
| if (ShouldProcess(Name, "Deleting CosmosDB Garnet Cluster")) | ||
| { | ||
| CosmosDBManagementClient.GarnetClusters.DeleteWithHttpMessagesAsync(ResourceGroupName, Name).GetAwaiter().GetResult(); |
Add PowerShell cmdlet support for Garnet cache cluster management under the Az.CosmosDB module, following the Managed Cassandra pattern. This includes: - New-AzCosmosDBGarnetCluster: Create a new Garnet cache cluster with conflict detection - Get-AzCosmosDBGarnetCluster: Get/List Garnet cluster(s) by name, resource group, subscription, ResourceId, or pipeline InputObject - Update-AzCosmosDBGarnetCluster: Update an existing cluster with GET-then-merge pattern and ResourceId/InputObject support - Remove-AzCosmosDBGarnetCluster: Delete a cluster with ResourceId, InputObject, AsJob, and PassThru support Supporting changes: - NewOrUpdateAzGarnetCluster shared base class for common parameters - PSGarnetClusterResource and PSGarnetClusterResourceProperties models in Models/Garnet/ subfolder - Garnet constants for help messages (including Location) - SDK autorest config updated to include 2026-04-01-preview openapi.json - Module manifest updated to export new cmdlets - ChangeLog updated Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4bc80a3 to
266b877
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (3)
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:28
OutputTypeshould describe objects written to the pipeline, not exceptions that may be thrown. Listing an exception type here can mislead tooling/help generation.
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBGarnetCluster", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSGarnetClusterResource), typeof(ConflictingResourceException))]
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:33
- No markdown help files were added/updated for the new Garnet cluster cmdlets (there are no
src/CosmosDB/CosmosDB/help/*Garnet*files). This module keeps cmdlet help insrc/CosmosDB/CosmosDB/help/, so these should be generated/checked in as part of adding new cmdlets.
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBGarnetCluster", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSGarnetClusterResource), typeof(ConflictingResourceException))]
public class NewAzCosmosDBGarnetCluster : NewOrUpdateAzGarnetCluster
{
[Parameter(Mandatory = true, HelpMessage = Constants.GarnetClusterLocationHelpMessage)]
[ValidateNotNullOrEmpty]
public string Location { get; set; }
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:66
- The CosmosDB module has extensive scenario coverage under
src/CosmosDB/CosmosDB.Test/ScenarioTests/, but there are no new scenario tests or session records for the newly added Garnet cluster cmdlets. Adding at least basic create/get/update/remove (including piping-InputObject/-ResourceIdparameter sets) tests would help prevent regressions.
public override void ExecuteCmdlet()
{
GarnetClusterResource existingCluster = null;
try
{
existingCluster = CosmosDBManagementClient.GarnetClusters.GetWithHttpMessagesAsync(ResourceGroupName, ClusterName).GetAwaiter().GetResult().Body;
}
catch (CloudException e)
{
if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
{
throw;
}
}
| using Microsoft.Azure.Management.CosmosDB.Models; | ||
| using Microsoft.Azure.Management.CosmosDB; | ||
| using Microsoft.Azure.PowerShell.Cmdlets.CosmosDB.Exceptions; |
| IDictionary<string, string> tagsDict; | ||
| if (Tag != null) | ||
| { | ||
| tagsDict = base.PopulateTags(Tag); | ||
| } | ||
| else | ||
| { | ||
| tagsDict = existingCluster.Tags; | ||
| } |
| @@ -41,6 +42,7 @@ input-file: | |||
| - https://github.com/Azure/azure-rest-api-specs/tree/$(commit)/specification/cosmos-db/resource-manager/Microsoft.DocumentDB/DocumentDB/stable/$(apiversion)/services.json | |||
| - https://github.com/Azure/azure-rest-api-specs/tree/$(commit)/specification/cosmos-db/resource-manager/Microsoft.DocumentDB/DocumentDB/stable/$(apiversion)/fleet.json | |||
| - https://github.com/Azure/azure-rest-api-specs/tree/$(commit)/specification/cosmos-db/resource-manager/Microsoft.DocumentDB/DocumentDB/preview/$(previewapiversion)/tablerbac.json | |||
| - https://github.com/Azure/azure-rest-api-specs/tree/$(commit)/specification/cosmos-db/resource-manager/Microsoft.DocumentDB/DocumentDB/preview/$(garnetpreviewapiversion)/openapi.json | |||
- Fix Tags not being passed in Update PATCH request (high severity bug) - Add UTF-8 BOM to all Garnet .cs files to match codebase convention - Use correct commit hash (2a96231) for 2026-04-01-preview Garnet spec Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (5)
src/CosmosDB/CosmosDB/Helpers/Constants.cs:332
- Help messages in this file consistently use “Resource ID” capitalization. This new Garnet help message uses “Resource id”, which is inconsistent in user-facing help output.
public const string GarnetClusterSubnetIdHelpMessage = "Resource id of a subnet that this cluster's management service should have its network interface attached to.";
src/CosmosDB/CosmosDB/Garnet/NewOrUpdateAzGarnetCluster.cs:45
- The help message constrains -ClusterType to specific values, but the parameter currently accepts any string. Adding a PSArgumentCompleter (or ValidateSet) would make the cmdlet easier to use and fail earlier on invalid input.
[Parameter(Mandatory = false, HelpMessage = Constants.GarnetClusterClusterTypeHelpMessage)]
[ValidateNotNullOrEmpty]
public string ClusterType { get; set; }
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:29
- This PR adds new cmdlets but does not add the corresponding markdown help files under src/CosmosDB/CosmosDB/help (e.g., New-AzCosmosDBGarnetCluster.md, Get-AzCosmosDBGarnetCluster.md, etc.). This will leave the module without up-to-date Get-Help content for the new surface area.
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBGarnetCluster", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSGarnetClusterResource), typeof(ConflictingResourceException))]
public class NewAzCosmosDBGarnetCluster : NewOrUpdateAzGarnetCluster
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:55
- The new Garnet cluster cmdlets introduce create/get/update/delete behavior, but this PR doesn’t add CosmosDB scenario tests covering these cmdlets (compare with existing CosmosDB.Test ScenarioTests for other resource types). Adding at least a basic playback test for the CRUD flow would help prevent regressions.
public override void ExecuteCmdlet()
{
GarnetClusterResource existingCluster = null;
try
src/CosmosDB/CosmosDB/Garnet/NewOrUpdateAzGarnetCluster.cs:41
- The help message constrains -AuthenticationMethod to specific values, but the parameter currently accepts any string. Adding a PSArgumentCompleter (or ValidateSet) here would guide users and prevent accidental invalid values being sent to the service.
[Parameter(Mandatory = false, HelpMessage = Constants.GarnetClusterAuthenticationMethodHelpMessage)]
[ValidateNotNullOrEmpty]
public string AuthenticationMethod { get; set; }
Generated from garnet.json (extracted Garnet-only spec from 2026-04-01-preview openapi.json to avoid conflicts with existing swagger files). Generated files: - GarnetClustersOperations.cs (CRUD + List operations) - IGarnetClustersOperations.cs (interface) - 10 model classes (GarnetClusterResource, Properties, Patch, etc.) - CosmosDBManagementClient.cs updated with GarnetClusters property Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The GarnetClusterResourcePatch model only has Properties, no Tags. Tags can only be updated via PUT (CreateUpdate), not PATCH. Removed dead tagsDict code from Update cmdlet. Build verified: 0 errors, 0 warnings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 27 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:28
- The module uses per-cmdlet markdown help files under src/CosmosDB/CosmosDB/help (e.g., help/Remove-AzManagedCassandraCluster.md), but this PR adds new Garnet cmdlets without adding corresponding help docs. This will leave the cmdlets undocumented in the module's help folder and can break doc/help validation steps that expect these files.
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBGarnetCluster", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSGarnetClusterResource), typeof(ConflictingResourceException))]
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:56
- New cmdlets introduce create/update/get/delete behavior for Garnet clusters, but there are no matching scenario tests under src/CosmosDB/CosmosDB.Test/ScenarioTests (the test project has coverage for other CosmosDB cmdlets, e.g. ManagedCassandraOperationsTests.ps1). Adding scenario tests (and recordings if applicable) would help prevent regressions in parameter sets and basic CRUD flows.
public override void ExecuteCmdlet()
{
GarnetClusterResource existingCluster = null;
try
{
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 27 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (4)
src/CosmosDB/CosmosDB/Models/Garnet/PSGarnetClusterResourceProperties.cs:53
- The PowerShell model is missing an
EndPointsproperty, so endpoint data from the service response can’t be returned to users.
/// <summary>
/// Gets or sets resource id of the subnet for the cluster's management service.
/// </summary>
public string SubnetId { get; set; }
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:52
- New Garnet cluster cmdlets are introduced here, but there are no corresponding scenario tests in
src/CosmosDB/CosmosDB.Test/ScenarioTests(there are tests for Accounts/SQL/ManagedCassandra/etc.). Adding scenario tests for create/get/update/remove would help prevent regressions and align with the repo’s expected validation workflow.
public override void ExecuteCmdlet()
src/CosmosDB/CosmosDB/Models/Garnet/PSGarnetClusterResourceProperties.cs:41
PSGarnetClusterResourcePropertiesdoesn’t surface the clusterEndPointsreturned by the SDK (GarnetClusterResourceProperties.EndPoints). Since these endpoints are how clients connect to the cluster, omitting them makesGet-AzCosmosDBGarnetClusteroutput incomplete.
This issue also appears on line 49 of the same file.
ProvisioningState = properties.ProvisioningState;
SubnetId = properties.SubnetId;
ReplicationFactor = properties.ReplicationFactor;
ShardCount = properties.ShardCount;
NodeSku = properties.NodeSku;
AvailabilityZone = properties.AvailabilityZone;
AuthenticationMethod = properties.AuthenticationMethod;
Persistence = properties.Persistence;
AllocationState = properties.AllocationState;
ClusterType = properties.ClusterType;
Extensions = properties.Extensions;
src/CosmosDB/CosmosDB/Garnet/NewAzCosmosDBGarnetCluster.cs:29
- This PR adds new cmdlets but doesn’t include the corresponding markdown help files under
src/CosmosDB/CosmosDB/help/(for example,New-AzCosmosDBGarnetCluster.md,Get-AzCosmosDBGarnetCluster.md, etc.). Without these, users won’t getGet-Helpcontent consistent with the rest of the module.
This issue also appears on line 52 of the same file.
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CosmosDBGarnetCluster", DefaultParameterSetName = NameParameterSet, SupportsShouldProcess = true), OutputType(typeof(PSGarnetClusterResource), typeof(ConflictingResourceException))]
public class NewAzCosmosDBGarnetCluster : NewOrUpdateAzGarnetCluster
|
|
||
| /// <param name="extensions">Extensions to be added or updated on cluster. | ||
| /// </param> | ||
| public GarnetClusterResourceProperties(string provisioningState = default(string), string subnetId = default(string), System.Collections.Generic.IList<GarnetClusterResourcePropertiesEndPointsItem> endPoints = default(System.Collections.Generic.IList<GarnetClusterResourcePropertiesEndPointsItem>), int? replicationFactor = default(int?), int? shardCount = default(int?), string nodeSku = default(string), bool? availabilityZone = default(bool?), string authenticationMethod = default(string), bool? persistence = default(bool?), string allocationState = default(string), string clusterType = default(string), ErrorDetailAutoGenerated2 provisionError = default(ErrorDetailAutoGenerated2), System.Collections.Generic.IList<string> extensions = default(System.Collections.Generic.IList<string>)) |
There was a problem hiding this comment.
please merge swagger to azure-rest-api-specs, do not check in it here
Add PowerShell cmdlet support for Garnet cache cluster management under the Az.CosmosDB module. This includes:
Supporting changes:
Description
Mandatory Checklist
Please choose the target release of Azure PowerShell. (⚠️ Target release is a different concept from API readiness. Please click below links for details.)
Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information:ChangeLog.mdfile(s) appropriatelysrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.## Upcoming Releaseheader in the past tense.ChangeLog.mdif no new release is required, such as fixing test case only.