Skip to content

Commit

Permalink
[EventHubs]: Fixing Get-AzEventHubNamespace to return all namespaces …
Browse files Browse the repository at this point in the history
…for subscriptions and resource groups that have more than 100 of them. (#18672)

* accounting for pagination in code

* fixes

* changelog

* fixes

* changelog update
  • Loading branch information
damodaravadhani authored Jun 27, 2022
1 parent cbfd893 commit 5c90551
Show file tree
Hide file tree
Showing 11 changed files with 2,118 additions and 1,138 deletions.
13 changes: 10 additions & 3 deletions src/EventHub/EventHub.Test/ScenarioTests/NamespaceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function NamespaceAuthTests
$createdNamespace = Get-AzEventHubNamespace -ResourceGroup $resourceGroupName -Name $namespaceName
Assert-AreEqual $createdNamespace.ResourceGroup $resourceGroupName "Namespace get : ResourceGroup name matches"
Assert-AreEqual $createdNamespace.ResourceGroupName $resourceGroupName "Namespace get : ResourceGroupName name matches"
Assert-AreEqual $createdNamespace.Name $namespaceName

#Assert
Assert-AreEqual $createdNamespace.Name $namespaceName "Namespace created earlier is not found."
Expand Down Expand Up @@ -286,10 +287,13 @@ function NamespaceTests
#Assert
Assert-True {$allCreatedNamespace.Count -ge 0 } "Namespace created earlier is not found. in list"

#Write-Debug "Get all the namespaces created in the subscription"
#$allCreatedNamespace = Get-AzEventHubNamespace
Write-Debug "Get all the namespaces created in the subscription"
$allCreatedNamespace = Get-AzEventHubNamespace

#Assert-True {$allCreatedNamespace.Count -ge 0} "Namespaces created earlier is not found."
Assert-True {$allCreatedNamespace.Count -ge 0} "Namespaces created earlier is not found."

$listByResourceGroup = Get-AzEventHubNamespace -ResourceGroup $resourceGroupName
Assert-AreEqual 4 $listByResourceGroup.Count

Write-Debug " Delete namespaces"
Remove-AzEventHubNamespace -ResourceGroup $secondResourceGroup -Name $namespaceName2
Expand Down Expand Up @@ -526,6 +530,7 @@ function ApplicationGroupTest{
$clientGroupId2 = getAssetName "SASKeyName=authkey"
$clientGroupId3 = getAssetName "SASKeyName=authkey"
$clientGroupId4 = getAssetName "SASKeyName=authkey"
$randomAppGroup = getAssetName "randomAppGroup"

try{
# Create Resource Group
Expand Down Expand Up @@ -670,6 +675,8 @@ function ApplicationGroupTest{
$appGroup3 = New-AzEventHubApplicationGroup -ResourceGroupName $resourceGroupName -NamespaceName $namespaceName -Name $appGroupName3 -ClientAppGroupIdentifier $clientGroupId3 -ThrottlingPolicyConfig $t1
$appGroup4 = New-AzEventHubApplicationGroup -ResourceGroupName $resourceGroupName -NamespaceName $namespaceName -Name $appGroupName4 -ClientAppGroupIdentifier $clientGroupId4 -ThrottlingPolicyConfig $t2

Assert-ThrowsContains { Set-AzEventHubApplicationGroup -ResourceGroupName $resourceGroupName -NamespaceName $namespaceName -Name $randomAppGroup -ThrottlingPolicyConfig $t1 } "Operation returned an invalid status code 'NotFound'"

$listOfAppGroups = Get-AzEventHubApplicationGroup -ResourceGroupName $resourceGroupName -NamespaceName $namespaceName
Assert-AreEqual $listOfAppGroups.Count 4

Expand Down
7 changes: 7 additions & 0 deletions src/EventHub/EventHub.Test/ScenarioTests/PaginationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@ public void ApplicationGroupPaginationTests()
{
TestRunner.RunTestScript("ApplicationGroupPagination");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NamespacePaginationTests()
{
TestRunner.RunTestScript("NamespacePagination");
}
}
}
11 changes: 11 additions & 0 deletions src/EventHub/EventHub.Test/ScenarioTests/PaginationTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ function ApplicationGroupPagination{

Assert-ThrowsContains { New-AzEventHubApplicationGroup -ResourceGroupName $resourceGroupName -NamespaceName $namespaceName -Name test -ClientAppGroupIdentifier SASKeyName=test -ThrottlingPolicyConfig $t1 } "Operation returned an invalid status code 'BadRequest'"
}

function NamespacePagination{
$resourceGroupName = "testpaginationforps"

$listNamespacesBySubscription = Get-AzEventHubNamespace
Assert-True { $listNamespacesBySubscription.Count -gt 200 }

$listNamespacesByResourceGroup = Get-AzEventHubNamespace -ResourceGroupName $resourceGroupName
Assert-True { $listNamespacesByResourceGroup.Count -gt 200}
Assert-True { $listNamespacesByResourceGroup.Count -lt $listNamespacesBySubscription.Count }
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/EventHub/EventHub/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
- Additional information about change #1
-->
## Upcoming Release
* Added cmdlets for CRUD operations on EventHub Application Groups.
* Added cmdlets for CRUD operations on EventHub Application Groups. The added cmdlets include,
-New-AzEventHubApplicationGroup
-Set-AzEventHubApplicationGroup
-Remove-AzEventHubApplicationGroup
-Get-AzEventHubApplicationGroup
-New-AzEventHubThrottlingPolicyConfig
* Get-AzEventHubNamespace returned a maximum of 100 namespaces for list by resource groups or list by subscriptions so far. From here onwards, for resource groups and subscriptions with over a 100 namespaces, the cmdlet will return all the namespaces. You will not see a change in the cmdlet behaviour if your resource groups or subscriptions have less than a 100 namespaces.

## Version 2.0.0
* Made `IPRule` and `VirtualNetworkRule` optional in `Set-AzEventHubNetworkRuleSet`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.EventHub.Commands.ApplicationGroups
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "EventHubThrottlingPolicyConfig"), OutputType(typeof(PSEventHubThrottlingPolicyConfigAttributes))]
public class NewAzureEventHubsThrottlingPolicyConfig: AzureEventHubsCmdletBase
{
[Parameter(Mandatory = false,
[Parameter(Mandatory = true,
Position = 0,
HelpMessage = "Name of Throttling Policy")]
public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public override void ExecuteCmdlet()
}
else if(ParameterSetName == ApplicationGroupInputObjectParameterSet)
{
//Set Cmdlets must throw exception in case the resource does not already exist
Client.GetApplicationGroup(resourceGroupName: ResourceGroupName,
namespaceName: NamespaceName,
appGroupName: Name);

//When InputObject is given as a parameter, the assumption is that the consumer has given the entire desired state
//Hence we reconstruct a new app group object
//That is why a create call and not update call.
Expand Down
62 changes: 54 additions & 8 deletions src/EventHub/EventHub/Utilities/EventHubsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,62 @@ public PSNamespaceAttributes GetNamespace(string resourceGroupName, string names

public IEnumerable<PSNamespaceAttributes> ListNamespacesByResourceGroup(string resourceGroupName)
{
var response = Client.Namespaces.ListByResourceGroup(resourceGroupName);
var resourceList = response.Select(resource => new PSNamespaceAttributes(resource));
return resourceList;
var listOfNamespaces = new List<PSNamespaceAttributes>();

string nextPageLink = null;

do
{
var pageOfNamespaces = new List<PSNamespaceAttributes>();

if (!String.IsNullOrEmpty(nextPageLink))
{
var result = Client.Namespaces.ListByResourceGroupNext(nextPageLink);
nextPageLink = result.NextPageLink;
pageOfNamespaces = result.Select(resource => new PSNamespaceAttributes(resource)).ToList();
}
else
{
var result = Client.Namespaces.ListByResourceGroup(resourceGroupName);
nextPageLink = result.NextPageLink;
pageOfNamespaces = result.Select(resource => new PSNamespaceAttributes(resource)).ToList();
}

listOfNamespaces.AddRange(pageOfNamespaces);

} while (!String.IsNullOrEmpty(nextPageLink));

return listOfNamespaces;
}

public IEnumerable<PSNamespaceAttributes> ListNamespacesBySubscription()
{
var response = Client.Namespaces.List();
var resourceList = response.Select(resource => new PSNamespaceAttributes(resource));
return resourceList;
var listOfNamespaces = new List<PSNamespaceAttributes>();

string nextPageLink = null;

do
{
var pageOfNamespaces = new List<PSNamespaceAttributes>();

if (!String.IsNullOrEmpty(nextPageLink))
{
var result = Client.Namespaces.ListNext(nextPageLink);
nextPageLink = result.NextPageLink;
pageOfNamespaces = result.Select(resource => new PSNamespaceAttributes(resource)).ToList();
}
else
{
var result = Client.Namespaces.List();
nextPageLink = result.NextPageLink;
pageOfNamespaces = result.Select(resource => new PSNamespaceAttributes(resource)).ToList();
}

listOfNamespaces.AddRange(pageOfNamespaces);

} while (!String.IsNullOrEmpty(nextPageLink));

return listOfNamespaces;
}

public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, string namespaceName, string location, string skuName, int? skuCapacity, Dictionary<string, string> tags, bool isAutoInflateEnabled, int? maximumThroughputUnits, bool isKafkaEnabled, string clusterARMId, bool isZoneRedundant, bool isDisableLocalAuth
Expand Down Expand Up @@ -957,7 +1003,7 @@ public IEnumerable<PSEventHubApplicationGroupAttributes> ListApplicationGroup(st
{
var fetchAppGroups = new List<PSEventHubApplicationGroupAttributes>();

if (nextPageLink != null)
if (!String.IsNullOrEmpty(nextPageLink))
{
var result = Client.ApplicationGroup.ListByNamespaceNext(nextPageLink);
nextPageLink = result.NextPageLink;
Expand All @@ -972,7 +1018,7 @@ public IEnumerable<PSEventHubApplicationGroupAttributes> ListApplicationGroup(st

listOfAppGroups.AddRange(fetchAppGroups);

} while (nextPageLink != null);
} while (!String.IsNullOrEmpty(nextPageLink));

return listOfAppGroups;
}
Expand Down

0 comments on commit 5c90551

Please sign in to comment.