Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make isAccountAllowedToCreateOfferingsWithTags API id parameter required #10338

Open
wants to merge 1 commit into
base: 4.20
Choose a base branch
from

Conversation

erik-bock-silva
Copy link

Description

This PR makes the id parameter from isAccountAllowedToCreateOfferingsWithTags api required to prevent a NullPointerException when trying to execute the command without an id.

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

I've created a test environment with a CloudStack setup. When I tried to execute the command without the id parameter, the following exception was thrown:

2025-02-03 15:00:11,909 ERROR [c.c.a.ApiServer] (qtp1507118393-20:[ctx-de956cc8, ctx-37d7a594]) (logid:5e002cf6) unhandled exception executing api command: [Ljava.lang.String;@588ef940 java.lang.NullPointerException: Cannot invoke "java.lang.Long.longValue()" because the return value of "org.apache.cloudstack.api.command.admin.offering.IsAccountAllowedToCreateOfferingsWithTagsCmd.getId()" is null
	at com.cloud.configuration.ConfigurationManagerImpl.isAccountAllowedToCreateOfferingsWithTags(ConfigurationManagerImpl.java:8076)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
	at jdk.proxy3/jdk.proxy3.$Proxy149.isAccountAllowedToCreateOfferingsWithTags(Unknown Source)
	at org.apache.cloudstack.api.command.admin.offering.IsAccountAllowedToCreateOfferingsWithTagsCmd.execute(IsAccountAllowedToCreateOfferingsWithTagsCmd.java:37)

Then I built and applied the updated packages to my environment. After that, I tried to force the same error to ensure my fix was working. The response shown was now the message: Missing required parameters: id

@DaanHoogland DaanHoogland added this to the 4.20.1 milestone Feb 6, 2025
@DaanHoogland
Copy link
Contributor

If it was impossible to execute the query before without id, I am alright with it. Otherwise this is a backwards incompatibility.

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 16.00%. Comparing base (96b757c) to head (d24a8b3).
Report is 40 commits behind head on 4.20.

Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #10338      +/-   ##
============================================
- Coverage     16.13%   16.00%   -0.14%     
- Complexity    12972    13062      +90     
============================================
  Files          5639     5644       +5     
  Lines        494297   494915     +618     
  Branches      59908    59960      +52     
============================================
- Hits          79773    79188     -585     
- Misses       405698   406890    +1192     
- Partials       8826     8837      +11     
Flag Coverage Δ
uitests 4.01% <ø> (-0.01%) ⬇️
unittests 16.83% <ø> (-0.15%) ⬇️

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.

@bernardodemarco
Copy link
Collaborator

If it was impossible to execute the query before without id, I am alright with it. Otherwise this is a backwards incompatibility.

@DaanHoogland, yes, previously, it was impossible to execute the API without an id.

When the API's service layer method is executed, the flow tries to retrieve the account with the specified id from the DB:

public Boolean isAccountAllowedToCreateOfferingsWithTags(IsAccountAllowedToCreateOfferingsWithTagsCmd cmd) {
Account caller = CallContext.current().getCallingAccount();
Account targetAccount = _accountMgr.getAccount(cmd.getId());

However, the getAccount method expects the accountId parameter as the long primitive:

@Override
public Account getAccount(long accountId) {
return _accountDao.findByIdIncludingRemoved(accountId);
}

Therefore, when the method is executed specifying null as argument, a NPE is thrown.

Copy link
Collaborator

@bernardodemarco bernardodemarco left a comment

Choose a reason for hiding this comment

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

clgtm

@bernardodemarco
Copy link
Collaborator

@blueorangutan package

@blueorangutan
Copy link

@bernardodemarco 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 12367

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.

4 participants