Skip to content

Fix NSX SDK list handling to fetch all paginated results - #12241

Closed
wolfchkov wants to merge 1 commit into
apache:mainfrom
PlaytikaOSS:fix-nsx-sdk-list-pagenation
Closed

Fix NSX SDK list handling to fetch all paginated results#12241
wolfchkov wants to merge 1 commit into
apache:mainfrom
PlaytikaOSS:fix-nsx-sdk-list-pagenation

Conversation

@wolfchkov

@wolfchkovwolfchkov commented Dec 11, 2025

Copy link
Copy Markdown

Fix for NSX plugin.

Description

NSX SDK list operations are pageable: the API returns a non-null and non-empty cursor field when more pages are available. The previous implementation only fetched the first page and ignored pagination.

This change updates the list retrieval flow to:

  • follow the cursor chain until no further pages exist
  • accumulate items from all pages
  • return a single merged result to the caller

This ensures that list operations return the complete dataset rather than just the first page.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • [ x] Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • [x ] Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • [ x] Minor

Bug Severity

  • BLOCKER
  • [ x] Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@boring-cyborg

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

@codecov

codecovBot commented Dec 11, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.85034% with 109 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.46%. Comparing base (3c64847) to head (070b956).
⚠️ Report is 471 commits behind head on main.

Files with missing linesPatch %Lines
...va/org/apache/cloudstack/service/NsxApiClient.java0.00%106 Missing ⚠️
...va/org/apache/cloudstack/service/PagedFetcher.java92.68%0 Missing and 3 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #12241 +/- ##
============================================
+ Coverage 3.58% 17.46% +13.88% - Complexity 0 15525 +15525 
============================================
Files 445 5914 +5469 Lines 37552 529493 +491941 Branches 6914 64685 +57771 ============================================
+ Hits 1347 92488 +91141 - Misses 36039 426584 +390545 - Partials 166 10421 +10255 
FlagCoverage Δ
uitests3.58% <ø> (ø)
unittests18.52% <25.85%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes NSX SDK list operations to properly handle pagination by following cursor chains until all pages are fetched. Previously, only the first page of results was retrieved, which could lead to incomplete data when the result set exceeded a single page.

Key Changes:

  • Introduced a new PagedFetcher utility class that implements cursor-based pagination logic
  • Updated multiple list operations in NsxApiClient to use PagedFetcher for complete result retrieval
  • Added comprehensive unit tests for the pagination functionality

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

FileDescription
PagedFetcher.javaNew utility class implementing cursor-based pagination with a fluent builder pattern for fetching all pages of results
PagedFetcherTest.javaComprehensive unit tests covering single-page, multi-page, and edge cases for the pagination logic
NsxApiClient.javaUpdated list operations (NAT rules, transport zones, segment ports, LB monitors, groups, services, etc.) to use PagedFetcher; refactored methods to return Optional for cleaner null handling; improved logging consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

… and non-empty
`cursor` field when more pages are available. The previous implementation only
fetched the first page and ignored pagination.
This change updates the list retrieval flow to:
- follow the `cursor` chain until no further pages exist
- accumulate items from all pages
- return a single merged result to the caller
This ensures that list operations return the complete dataset rather than just
the first page.
@wolfchkov
wolfchkovforce-pushed the fix-nsx-sdk-list-pagenation branch from de4cf14 to 070b956CompareDecember 11, 2025 13:48

@Pearl1594Pearl1594 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code lgtm.

@Pearl1594

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@wolfchkov

Copy link
Copy Markdown
Author

This fix is currently undergoing testing. When the test results are ready, I will update the description accordingly.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16006

@ZhyliaievD
ZhyliaievD deleted the fix-nsx-sdk-list-pagenation branch March 17, 2026 10:01
@nvazquez

Copy link
Copy Markdown
Contributor

Hi @wolfchkov@ZhyliaievD this PR seems to be fixing the same issue as #12834. Please advise which one should be kept and we can close the other one.

@weizhouapacheweizhouapache modified the milestone: 4.22.1May 7, 2026
@weizhouapache

Copy link
Copy Markdown
Member

#12834 has been merged

closing this

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wolfchkov@Pearl1594@blueorangutan@nvazquez@weizhouapache