Skip to content

fix: LB Creation avoid 404 API errors due to non-needed patches#12835

Open
ZhyliaievD wants to merge 1 commit intoapache:mainfrom
PlaytikaOSS:fix/nsx-lb-404-api-errors
Open

fix: LB Creation avoid 404 API errors due to non-needed patches#12835
ZhyliaievD wants to merge 1 commit intoapache:mainfrom
PlaytikaOSS:fix/nsx-lb-404-api-errors

Conversation

@ZhyliaievD
Copy link

Description

  • Avoid unnecessary NSX load balancer patch calls when the target resource already exists and does not need updating.
  • Reuse existing LB active monitor profiles instead of patching them again, which prevents avoidable 404 API errors during LB creation.
  • Skip server pool patching when the current NSX pool already has the same members, and skip virtual server patching when the virtual server already exists.
  • Fix createAndAddNsxLbVirtualServer() to check for an existing virtual server using the virtual server name, so existing virtual servers are detected correctly and not patched again

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

Screenshots (if appropriate):

How Has This Been Tested?

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

Copy link
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 optimizes NSX load balancer creation by avoiding unnecessary API PATCH calls when resources already exist and don't need updating. It fixes a bug where createAndAddNsxLbVirtualServer() was checking for an existing virtual server using the wrong name (the LB service name instead of the virtual server name), causing it to never detect existing virtual servers.

Changes:

  • Skip monitor profile patching when the profile already exists in NSX, and skip server pool patching when the pool already has the same members
  • Fix the virtual server existence check to use the correct virtual server name instead of the LB service name, so existing virtual servers are detected and not re-patched
  • Add comprehensive unit tests covering all the new skip/patch scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxApiClient.java Add existence checks for monitor profiles, server pools, and virtual servers to avoid unnecessary NSX API patch calls; fix virtual server lookup to use correct name
plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxApiClientTest.java Add tests for monitor profile reuse, pool member comparison skip/patch logic, and virtual server existence detection

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

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 95.83333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.05%. Comparing base (b744824) to head (4ea0f3d).

Files with missing lines Patch % Lines
...va/org/apache/cloudstack/service/NsxApiClient.java 95.83% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #12835      +/-   ##
============================================
+ Coverage     18.02%   18.05%   +0.02%     
- Complexity    16450    16477      +27     
============================================
  Files          5968     5968              
  Lines        537086   537119      +33     
  Branches      65961    65963       +2     
============================================
+ Hits          96819    96978     +159     
+ Misses       429347   429214     -133     
- Partials      10920    10927       +7     
Flag Coverage Δ
uitests 3.53% <ø> (ø)
unittests 19.22% <95.83%> (+0.03%) ⬆️

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 ZhyliaievD force-pushed the fix/nsx-lb-404-api-errors branch from 9f079d8 to 4ea0f3d Compare March 17, 2026 13:04
@DaanHoogland DaanHoogland requested a review from Copilot March 17, 2026 13:57
@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

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

Copy link
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 avoids unnecessary NSX API patch calls during load balancer creation by checking if resources already exist before patching, preventing 404 errors.

Changes:

  • Skip server pool patching when existing pool has identical members; skip virtual server patching when it already exists.
  • Reuse existing LB active monitor profiles instead of re-patching them, fetching by ID directly rather than listing all profiles.
  • Fix createAndAddNsxLbVirtualServer() to look up the virtual server by its own name instead of the LB service name.

Reviewed changes

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

File Description
NsxApiClient.java Added existence checks for pools, monitor profiles, and virtual servers before issuing patch calls; fixed virtual server lookup key.
NsxApiClientTest.java Added tests covering skip/patch scenarios for server pools, monitor profiles, virtual servers, and error handling.

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

Comment on lines +702 to +707
Set<String> currentMembersSet = poolMembersCurrent.stream()
.map(this::buildPoolMemberKey)
.collect(toSet());
return poolMembersUpdate.stream()
.map(this::buildPoolMemberKey)
.allMatch(currentMembersSet::contains);
@blueorangutan
Copy link

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

Fix existing lbVirtualServer search by lbVirtualServerName
@ZhyliaievD ZhyliaievD force-pushed the fix/nsx-lb-404-api-errors branch from 4ea0f3d to 94cabcd Compare March 17, 2026 17:02
Sign up for free to 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.

5 participants