Skip to content

Refactor: Modularize ApiResponseHelper#createUsageResponse#13490

Open
PrashantBhanage wants to merge 1 commit into
apache:mainfrom
PrashantBhanage:fix-11635-refactor-usage
Open

Refactor: Modularize ApiResponseHelper#createUsageResponse#13490
PrashantBhanage wants to merge 1 commit into
apache:mainfrom
PrashantBhanage:fix-11635-refactor-usage

Conversation

@PrashantBhanage

Copy link
Copy Markdown

Fixes #11635

Description

This PR addresses the technical debt in ApiResponseHelper#createUsageResponse(Usage) by modularizing the 530-line method.

  • Extracted the 500+ line switch/if-else block into a main dispatcher method populateUsageTypeSpecificDetails.
  • Created 18 individual private helper methods for each specific UsageType to improve maintainability and readability.
  • Introduced a UsageResourceDetails container class to safely manage and return resourceId and resourceType state for tag lookups.
  • Verified zero business logic changes; strictly structural refactoring.

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

Screenshots (if appropriate):

N/A (Pure backend refactoring)

How Has This Been Tested?

Ran a successful clean compile locally to verify no structural or syntax breaks:
mvn -pl server -DskipTests clean compile
Passed all local Checkstyle validations.

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

This is a pure structural refactor. Carefully verified that no business logic, string formatting, or calculations were altered. I am relying on the existing automated CI test suites to ensure data integrity and backward compatibility remain strictly intact.

Fixes apache#11635

- Extracted the 500+ line switch/if-else block into a main dispatcher method `populateUsageTypeSpecificDetails`.
- Created 18 individual private helper methods for each specific `UsageType` to improve maintainability and readability.
- Introduced a `UsageResourceDetails` container class to safely manage and return `resourceId` and `resourceType` state for tag lookups.
- Verified zero business logic changes; strictly structural refactoring.
@boring-cyborg

boring-cyborg Bot commented Jun 25, 2026

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:

@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 no SystemVM templates. I'll keep you posted as I make progress.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 1.44928% with 408 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.94%. Comparing base (82986f6) to head (61cb4ea).

Files with missing lines Patch % Lines
...src/main/java/com/cloud/api/ApiResponseHelper.java 1.44% 387 Missing and 21 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #13490   +/-   ##
=========================================
  Coverage     18.94%   18.94%           
- Complexity    18363    18369    +6     
=========================================
  Files          6192     6192           
  Lines        556361   556444   +83     
  Branches      67908    67907    -1     
=========================================
+ Hits         105397   105421   +24     
- Misses       439393   439450   +57     
- Partials      11571    11573    +2     
Flag Coverage Δ
uitests 3.51% <ø> (ø)
unittests 20.15% <1.44%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@blueorangutan

Copy link
Copy Markdown

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ApiResponseHelper#createUsageResponse(Usage) needs to be modularised (530 lines).

3 participants