Skip to content

Fix NSX SDK list handling to fetch all paginated results#12834

Merged
sureshanaparti merged 1 commit intoapache:4.22from
PlaytikaOSS:fix/nsx-sdk-list-pagenation
Apr 16, 2026
Merged

Fix NSX SDK list handling to fetch all paginated results#12834
sureshanaparti merged 1 commit intoapache:4.22from
PlaytikaOSS:fix/nsx-sdk-list-pagenation

Conversation

@ZhyliaievD
Copy link
Copy Markdown
Contributor

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)
  • 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
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 incomplete NSX SDK “list” handling by introducing a generic pagination helper that follows NSX cursor values across pages, merges results, and returns a single combined result to callers (so list operations return the full dataset, not just the first page).

Changes:

  • Added a PagedFetcher utility to iterate through cursor-based pages and accumulate all items.
  • Updated several NSX list(...) call sites in NsxApiClient to use PagedFetcher and return merged results.
  • Added unit tests covering single-page, empty-cursor, multi-page, and null-first-page-items scenarios.

Reviewed changes

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

File Description
plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/PagedFetcher.java New pagination helper that fetches pages via cursor and merges items into the first-page result.
plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxApiClient.java Switches multiple NSX list operations to fetch and merge all paginated results; also updates some logging and “first item” lookups to use Optional.
plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/PagedFetcherTest.java New JUnit tests validating pagination and edge cases for the helper.

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

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 25.85034% with 109 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.95%. Comparing base (23f633a) to head (8d70de6).
⚠️ Report is 9 commits behind head on 4.22.

Files with missing lines Patch % Lines
...va/org/apache/cloudstack/service/NsxApiClient.java 0.00% 106 Missing ⚠️
...va/org/apache/cloudstack/service/PagedFetcher.java 92.68% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12834      +/-   ##
============================================
+ Coverage     17.61%   17.95%   +0.34%     
- Complexity    15706    16531     +825     
============================================
  Files          5921     6023     +102     
  Lines        532392   541495    +9103     
  Branches      65109    66352    +1243     
============================================
+ Hits          93788    97238    +3450     
- Misses       428015   433287    +5272     
- Partials      10589    10970     +381     
Flag Coverage Δ
uitests 3.53% <ø> (-0.18%) ⬇️
unittests 19.11% <25.85%> (+0.42%) ⬆️

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.

@ZhyliaievD
Copy link
Copy Markdown
Contributor Author

ZhyliaievD commented Mar 18, 2026

Hi guys
@winterhazel @Pearl1594 @nvazquez @DaanHoogland @sureshanaparti
This is my first contribution to this project, want to clarify a bit:
I've added couple of PRs (#12834 #12833 #12835) with fixes we internally implemented for our on-premise cloudstack instance
I consider it tested as It is up and running since December 2025, with the only difference in base cloudstack version used - 4.19.0

Would appreciate if you share details on PR process, e.g. if I need to provide anything else to get this merged, what is the release schedule and any other potentially missing items needed to complete contribution? Maybe there is a doc regarding this?

@DaanHoogland
Copy link
Copy Markdown
Contributor

Hi guys @winterhazel @Pearl1594 @nvazquez @DaanHoogland @sureshanaparti This is my first contribution to this project, want to clarify a bit: I've added couple of PRs (#12834 #12833 #12835) with fixes we internally implemented for our on-premise cloudstack instance I consider it tested as It is up and running since December 2025, with the only difference in base cloudstack version used - 4.19.0

Would appreciate if you share details on PR process, e.g. if I need to provide anything else to get this merged, what is the release schedule and any other potentially missing items needed to complete contribution? Maybe there is a doc regarding this?

@ZhyliaievD , the process is that 2 people have reviewed (some lobby may be required) one of which at least has tested it, and smoke tests pass. When text only changes we sometimes skip that last test. Not many people have smoke test infra structure. (or at least admit to it.)

@ZhyliaievD
Copy link
Copy Markdown
Contributor Author

@weizhouapache @winterhazel a kind reminder about this PR 😅

@winterhazel winterhazel self-requested a review April 6, 2026 18:52
Copy link
Copy Markdown
Member

@winterhazel winterhazel left a comment

Choose a reason for hiding this comment

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

The code looks ok to me, but I don't have access to NSX (nor knowledge in it) to validate it. @Pearl1594 @nvazquez could you have a look at this?

@winterhazel
Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

@nvazquez nvazquez left a comment

Choose a reason for hiding this comment

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

Thanks @ZhyliaievD code LGTM

IMO there haven't been significant changes to the NSX plugin since 4.19 so I would expect the fixes to work properly. Would it be possible for you to test the improvements against main branch?

@ZhyliaievD
Copy link
Copy Markdown
Contributor Author

ZhyliaievD commented Apr 9, 2026

Thanks @ZhyliaievD code LGTM

IMO there haven't been significant changes to the NSX plugin since 4.19 so I would expect the fixes to work properly. Would it be possible for you to test the improvements against main branch?

Unfortunately our current env is 4.19
We have a new env with 4.22.0.0 being deployed there, I'll port nsx fixes onto 4.22.0.0 and will check against it.
(May take some time, as a lot of same-type resources needs to be generated to recheck pagination - default page size is 1000, so we need more than that to recheck it e2e)

@ZhyliaievD
Copy link
Copy Markdown
Contributor Author

Hi
We have manually tested changes made in #12833 #12834 #12835
All fixes work as expected, including:

Environmnet:
cloudstack 4.22.0.0 + patch with changes mentioned above

PS: There is no diff in nsx module between main branch and tag 4.22.0.0

@DaanHoogland
Copy link
Copy Markdown
Contributor

@winterhazel @weizhouapache at your discretion. That said @ZhyliaievD @nvazquez , does it make sense to then merge it against 22? cc @Pearl1594

Copy link
Copy Markdown
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

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

code lgtm

better to fix in 4.22.1.0
cc @sureshanaparti @rajujith

@sureshanaparti
Copy link
Copy Markdown
Contributor

code lgtm

better to fix in 4.22.1.0 cc @sureshanaparti @rajujith

@ZhyliaievD can re-target to 4.22?

@ZhyliaievD ZhyliaievD changed the base branch from main to 4.22 April 15, 2026 14:16
… 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.
@ZhyliaievD ZhyliaievD force-pushed the fix/nsx-sdk-list-pagenation branch from 48e63a3 to 8d70de6 Compare April 15, 2026 14:29
@ZhyliaievD ZhyliaievD changed the base branch from main to 4.22 April 15, 2026 14:29
@ZhyliaievD
Copy link
Copy Markdown
Contributor Author

@sureshanaparti Done

@weizhouapache
Copy link
Copy Markdown
Member

@blueorangutan package

@nvazquez
Copy link
Copy Markdown
Contributor

nvazquez commented Apr 15, 2026

Thanks @ZhyliaievD @DaanHoogland @sureshanaparti @weizhouapache - LGTM for 4.22 branch

@sureshanaparti
Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@sureshanaparti 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.

@blueorangutan
Copy link
Copy Markdown

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

@nvazquez
Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link
Copy Markdown

[SF] Trillian test result (tid-15891)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 50753 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12834-t15891-kvm-ol8.zip
Smoke tests completed. 148 look OK, 1 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestClusterDRS>:setup Error 0.00 test_cluster_drs.py

@sureshanaparti sureshanaparti modified the milestones: 4.23.0, 4.22.1 Apr 16, 2026
@sureshanaparti sureshanaparti moved this from Todo to In Progress in Apache CloudStack 4.22.1 Apr 16, 2026
@sureshanaparti sureshanaparti merged commit e0fe953 into apache:4.22 Apr 16, 2026
26 of 28 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Apache CloudStack 4.22.1 Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants