Skip to content

Conversation

@shwstppr
Copy link
Contributor

@shwstppr shwstppr commented Aug 4, 2025

Description

This PR adds the httprequesttype parameter to the listApis response, allowing clients to invoke APIs using the appropriate HTTP methods — GET or POST. API classes can specify the supported HTTP methods via annotations. If no annotation is present, the request type will be inferred based on the API name.

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):

How Has This Been Tested?

lisApis output,

(local) 🐱 > list apis filter=name,httprequesttype
{
  "api": [
    {
      "httprequesttype": "POST",
      "name": "createVPCOffering"
    },
    {
      "httprequesttype": "POST",
      "name": "ldapCreateAccount"
    },
    {
      "httprequesttype": "POST",
      "name": "copyIso"
    },
    {
      "httprequesttype": "POST",
      "name": "deleteAutoScaleVmProfile"
    },
    {
      "httprequesttype": "POST",
      "name": "rebootSystemVm"
    },
    {
      "httprequesttype": "GET",
      "name": "listDedicatedZones"
    },
    {
      "httprequesttype": "GET",
      "name": "listElastistorPool"
    },
    {
      "httprequesttype": "POST",
      "name": "changeBgpPeersForNetwork"
    },
    {
      "httprequesttype": "POST",
      "name": "removeNodesFromKubernetesCluster"
    },

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

@sureshanaparti
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@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

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

@DaanHoogland
Copy link
Contributor

good initiative, would it make sense to have GET or POST as default so we don’t have to change all external plugins?

@shwstppr
Copy link
Contributor Author

shwstppr commented Aug 4, 2025

@DaanHoogland with change, it already returns GET/POST based on the apiName when the annotation is not added,

(local) 🐱 > list apis filter=name,httprequesttype
{
  "api": [
    {
      "httprequesttype": "POST",
      "name": "createVPCOffering"
    },
    {
      "httprequesttype": "POST",
      "name": "ldapCreateAccount"
    },
    {
      "httprequesttype": "POST",
      "name": "copyIso"
    },
    {
      "httprequesttype": "POST",
      "name": "deleteAutoScaleVmProfile"
    },
    {
      "httprequesttype": "POST",
      "name": "rebootSystemVm"
    },
    {
      "httprequesttype": "GET",
      "name": "listDedicatedZones"
    },
    {
      "httprequesttype": "GET",
      "name": "listElastistorPool"
    },
    {
      "httprequesttype": "POST",
      "name": "changeBgpPeersForNetwork"
    },
    {
      "httprequesttype": "POST",
      "name": "removeNodesFromKubernetesCluster"
    },
...

I added the annotation to some classes because they were listed in ApiServlet class as GET commands explicitly

@DaanHoogland
Copy link
Contributor

ok, @shwstppr , not claiming this as a universal truth but for this change

    String httpMethod() default “GET";

would have made the change simpler.

@shwstppr
Copy link
Contributor Author

shwstppr commented Aug 4, 2025

ok, @shwstppr , not claiming this as a universal truth but for this change

    String httpMethod() default “GET";

would have made the change simpler.

@DaanHoogland not necessarily IMO. If we return GET as default, then adding GET annotation will become useless, as we will always be double-checking. Leaving it empty helps in assigning a value using regex only when the annotation is not added

@sureshanaparti sureshanaparti added this to the 4.21.1 milestone Aug 4, 2025
@shwstppr shwstppr modified the milestones: 4.21.1, 4.22.0 Aug 4, 2025
Signed-off-by: Abhishek Kumar <[email protected]>
@codecov
Copy link

codecov bot commented Aug 5, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.58%. Comparing base (5798fb4) to head (859cfdb).

Files with missing lines Patch % Lines
server/src/main/java/com/cloud/api/ApiServlet.java 77.27% 2 Missing and 3 partials ⚠️
.../cloudstack/api/response/ApiDiscoveryResponse.java 85.71% 1 Missing ⚠️
.../cloudstack/discovery/ApiDiscoveryServiceImpl.java 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #11382      +/-   ##
============================================
+ Coverage     17.56%   17.58%   +0.01%     
- Complexity    15548    15582      +34     
============================================
  Files          5913     5913              
  Lines        529440   529466      +26     
  Branches      64670    64677       +7     
============================================
+ Hits          93018    93124     +106     
+ Misses       425964   425874      -90     
- Partials      10458    10468      +10     
Flag Coverage Δ
uitests 3.58% <ø> (ø)
unittests 18.65% <80.00%> (+0.02%) ⬆️

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.

@shwstppr
Copy link
Contributor Author

shwstppr commented Aug 5, 2025

@blueorangutan package

@blueorangutan
Copy link

@shwstppr 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

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

@shwstppr shwstppr closed this Aug 6, 2025
@shwstppr shwstppr reopened this Aug 6, 2025
Signed-off-by: Abhishek Kumar <[email protected]>
@shwstppr
Copy link
Contributor Author

shwstppr commented Aug 8, 2025

@blueorangutan package

@blueorangutan
Copy link

@shwstppr 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

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

@shwstppr
Copy link
Contributor Author

shwstppr commented Aug 8, 2025

@blueorangutan test

@blueorangutan
Copy link

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

@blueorangutan
Copy link

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

Test Result Time (s) Test File

@shwstppr shwstppr marked this pull request as ready for review August 29, 2025 19:35
@vishesh92 vishesh92 requested a review from Copilot October 13, 2025 07:56
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 adds HTTP request type information to the listApis API response, allowing clients to know whether to use GET or POST when invoking APIs. The implementation includes adding an httpMethod annotation parameter to the @APICommand annotation and logic to determine the appropriate HTTP method based on annotations or API naming patterns.

Key changes:

  • Added httpMethod parameter to @APICommand annotation for explicit HTTP method specification
  • Modified API discovery service to include HTTP request type in response
  • Updated validation logic to use annotations and naming patterns to determine allowed HTTP methods

Reviewed Changes

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

Show a summary per file
File Description
api/src/main/java/org/apache/cloudstack/api/APICommand.java Added httpMethod parameter to APICommand annotation
api/src/main/java/org/apache/cloudstack/api/ApiConstants.java Added HTTP_REQUEST_TYPE constant
api/src/main/java/org/apache/cloudstack/api/command/admin/offering/IsAccountAllowedToCreateOfferingsWithTagsCmd.java Added GET httpMethod annotation
plugins/api/discovery/src/main/java/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java Added httpRequestType field to API response
plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java Implemented logic to determine HTTP request type
plugins/api/discovery/src/test/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImplTest.java Added comprehensive test coverage for HTTP request type logic
server/src/main/java/com/cloud/api/ApiServlet.java Refactored validation logic to use annotations and patterns
server/src/test/java/com/cloud/api/ApiServletTest.java Added extensive test coverage for validation logic
Multiple plugin command files Added GET httpMethod annotations to read-only APIs

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm, not all co-pilot’s comments are senseless, though I can live without addressing them in this context.

@shwstppr shwstppr modified the milestones: 4.22.1, 4.23 Nov 28, 2025
@shwstppr
Copy link
Contributor Author

@DaanHoogland I've addressed 2 of 3 comments from Copilot. For changing match pattern I think it can be a separate PR

@blueorangutan package

@blueorangutan
Copy link

@shwstppr 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

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

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