Skip to content

[ZCF-3922] add license auth info api#4163

Open
zstack-robot-1 wants to merge 1 commit into
5.5.24from
sync/hanyu.liang/zcf-3922@@2
Open

[ZCF-3922] add license auth info api#4163
zstack-robot-1 wants to merge 1 commit into
5.5.24from
sync/hanyu.liang/zcf-3922@@2

Conversation

@zstack-robot-1
Copy link
Copy Markdown
Collaborator

Summary

  • add SDK/testlib support for GetLicenseAuthorizationInfo API
  • expose license authorization info inventories including serverVersion and quotas

Validation

  • mvn -Dmaven.test.skip=true -T 8 -P premium clean install
  • mvn -pl mevoco,test-premium -DfailIfNoTests=false -Dtest=org.zstack.test.integration.premium.license.client.LicenseClientServerApiCase test

sync from gitlab !10068

Resolves: ZCF-3922

Change-Id: If9579e1648bc614985e13855fc84ade1a49fc38a
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Could not fetch remote config from http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml: TimeoutError: The operation was aborted due to timeout
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

总体说明

该变更向 ZStack SDK 添加了许可证授权信息查询功能。实现包括新增五个 Java 类定义数据模型和 API 动作,在映射表中注册类名关联,以及在测试框架中集成新的辅助方法。所有变更保持了现有代码的一致性和模式。

变更

许可证授权信息 API 集成

层级 / 文件 说明
许可证授权数据模型
sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationInfo.java, sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationQuotaInventory.java
新增 LicenseAuthorizationInfo 类,包含鉴权类型、连接状态、服务器/站点信息、产品线、快照状态、同步时间、许可证配额等字段。新增 LicenseAuthorizationQuotaInventory 类作为配额清单,包含认证实体、产品、模块、许可证类型、配额使用情况、发放/过期日期及状态等字段。
授权信息查询 API 动作
sdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoAction.java, sdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoResult.java
新增 GetLicenseAuthorizationInfoAction 继承 AbstractAction,实现同步 call() 和异步 call(Completion) 方法。定义参数字段(systemTagsuserTagsisSuppressCredentialCheckrequestIp)。配置 REST 端点为 GET /licenses/authorization-info,不需要会话验证和轮询。makeResult() 方法将 API 响应映射为 Result 容器。新增 GetLicenseAuthorizationInfoResult 作为结果封装,提供 LicenseAuthorizationInfo info 字段访问器。
框架注册与测试支持
sdk/src/main/java/SourceClassMap.java, testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
SourceClassMap 中同时注册源到目标和目标到源的类名映射关系。在 ApiHelper.groovy 中新增 getLicenseAuthorizationInfo() 测试辅助方法,并统一了多个 API 辅助方法中 apipath 系统属性的处理逻辑,包括 API 路径跟踪和记录。

🎯 2 (Simple) | ⏱️ ~12 分钟

🐰 许可证授权信息已就位,
查询端点配置妥当,
数据模型齐全备,
测试框架已融合,
映射关系已注册!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰准确地总结了主要变更:添加许可证授权信息 API 的 SDK 和测试库支持,与所有代码变更直接相关。
Description check ✅ Passed 描述详细说明了变更内容(添加 SDK/testlib 支持和许可证授权信息库),包括验证步骤,与代码变更完全相关。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/hanyu.liang/zcf-3922@@2

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationInfo.java (2)

103-109: ⚡ Quick win

List 字段缺少泛型类型参数。

字段 quotas 使用了原始类型 java.util.List,应指定具体的泛型类型参数。根据命名推测应为 List<LicenseAuthorizationQuotaInventory>

♻️ 建议的修复
-    public java.util.List quotas;
-    public void setQuotas(java.util.List quotas) {
+    public java.util.List<LicenseAuthorizationQuotaInventory> quotas;
+    public void setQuotas(java.util.List<LicenseAuthorizationQuotaInventory> quotas) {
         this.quotas = quotas;
     }
-    public java.util.List getQuotas() {
+    public java.util.List<LicenseAuthorizationQuotaInventory> getQuotas() {
         return this.quotas;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationInfo.java` around lines
103 - 109, The quotas field and its accessor methods in class
LicenseAuthorizationInfo use a raw java.util.List; change the field declaration
from "public java.util.List quotas" to "public
java.util.List<LicenseAuthorizationQuotaInventory> quotas" and update the
signatures of setQuotas and getQuotas to accept/return
List<LicenseAuthorizationQuotaInventory>; also add or ensure the appropriate
import for LicenseAuthorizationQuotaInventory (or fully qualify it) so the
compiler recognizes the generic type.

95-101: ⚡ Quick win

List 字段缺少泛型类型参数。

字段 addOns 使用了原始类型 java.util.List,应指定具体的泛型类型参数以确保类型安全。例如 List<LicenseAddOnInventory> 或适当的元素类型。

♻️ 建议的修复
-    public java.util.List addOns;
-    public void setAddOns(java.util.List addOns) {
+    public java.util.List<LicenseAddOnInventory> addOns;
+    public void setAddOns(java.util.List<LicenseAddOnInventory> addOns) {
         this.addOns = addOns;
     }
-    public java.util.List getAddOns() {
+    public java.util.List<LicenseAddOnInventory> getAddOns() {
         return this.addOns;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationInfo.java` around lines
95 - 101, The field addOns in LicenseAuthorizationInfo uses a raw
java.util.List; change it to a parameterized type (e.g.,
List<LicenseAddOnInventory>) and update the getter and setter signatures
accordingly (getAddOns, setAddOns) to use the same generic type; also add or
ensure the appropriate import for LicenseAddOnInventory (or the correct element
type) is present so the class is type-safe.
sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationQuotaInventory.java (1)

95-101: ⚡ Quick win

Boolean 字段的 getter 方法未遵循 JavaBean 规范。

字段 expiredplatform 的 getter 方法使用了 getExpired() / getPlatform(),JavaBean 规范建议 boolean 类型字段使用 is 前缀(isExpired() / isPlatform())。虽然 get 前缀在技术上可行,但 is 前缀是更标准的做法,有助于与各种框架(如序列化库)更好地兼容。

♻️ 建议的修复
     public boolean expired;
     public void setExpired(boolean expired) {
         this.expired = expired;
     }
-    public boolean getExpired() {
+    public boolean isExpired() {
         return this.expired;
     }

     public boolean platform;
     public void setPlatform(boolean platform) {
         this.platform = platform;
     }
-    public boolean getPlatform() {
+    public boolean isPlatform() {
         return this.platform;
     }

Also applies to: 103-109

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationQuotaInventory.java`
around lines 95 - 101, The boolean fields expired and platform use
getExpired()/getPlatform() which don't follow JavaBean boolean naming; update
the getters to isExpired() and isPlatform() respectively (keep existing setters
setExpired/setPlatform) and ensure any usages/serialization that call
getExpired/getPlatform are updated to call the new is* methods or both getters
are provided for backward compatibility; locate methods getExpired/getPlatform
in LicenseAuthorizationQuotaInventory and replace/alias them with
isExpired/isPlatform to conform to the JavaBean convention.
sdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoAction.java (1)

28-32: ⚡ Quick win

参数字段缺少泛型类型参数。

字段 systemTagsuserTags 使用了原始类型 java.util.List。应指定泛型类型参数(通常为 List<String>)以确保类型安全并符合项目中其他 API Action 类的惯例。

♻️ 建议的修复
     `@Param`(required = false)
-    public java.util.List systemTags;
+    public java.util.List<String> systemTags;

     `@Param`(required = false)
-    public java.util.List userTags;
+    public java.util.List<String> userTags;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoAction.java`
around lines 28 - 32, Fields systemTags and userTags in
GetLicenseAuthorizationInfoAction are declared with raw type java.util.List;
change their declarations to use a generic type (e.g., java.util.List<String>)
to ensure type safety and follow the project's API Action conventions — update
the field types for systemTags and userTags in the
GetLicenseAuthorizationInfoAction class and adjust any callers or serializers if
they rely on raw types.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy`:
- Around line 23700-23704: The new getLicenseAuthorizationInfo helper creates a
org.zstack.sdk.GetLicenseAuthorizationInfoAction instance (variable a) but never
assigns a.sessionId, so API calls lack authentication; set a.sessionId to the
same session variable used elsewhere in this file (the common
sessionId/adminSession value used by getLicenseCapabilities, attachDGpuToVm,
updateVmDGpu) before invoking the closure (i.e., before c()), ensuring the
action carries the session credential.

---

Nitpick comments:
In `@sdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoAction.java`:
- Around line 28-32: Fields systemTags and userTags in
GetLicenseAuthorizationInfoAction are declared with raw type java.util.List;
change their declarations to use a generic type (e.g., java.util.List<String>)
to ensure type safety and follow the project's API Action conventions — update
the field types for systemTags and userTags in the
GetLicenseAuthorizationInfoAction class and adjust any callers or serializers if
they rely on raw types.

In `@sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationInfo.java`:
- Around line 103-109: The quotas field and its accessor methods in class
LicenseAuthorizationInfo use a raw java.util.List; change the field declaration
from "public java.util.List quotas" to "public
java.util.List<LicenseAuthorizationQuotaInventory> quotas" and update the
signatures of setQuotas and getQuotas to accept/return
List<LicenseAuthorizationQuotaInventory>; also add or ensure the appropriate
import for LicenseAuthorizationQuotaInventory (or fully qualify it) so the
compiler recognizes the generic type.
- Around line 95-101: The field addOns in LicenseAuthorizationInfo uses a raw
java.util.List; change it to a parameterized type (e.g.,
List<LicenseAddOnInventory>) and update the getter and setter signatures
accordingly (getAddOns, setAddOns) to use the same generic type; also add or
ensure the appropriate import for LicenseAddOnInventory (or the correct element
type) is present so the class is type-safe.

In `@sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationQuotaInventory.java`:
- Around line 95-101: The boolean fields expired and platform use
getExpired()/getPlatform() which don't follow JavaBean boolean naming; update
the getters to isExpired() and isPlatform() respectively (keep existing setters
setExpired/setPlatform) and ensure any usages/serialization that call
getExpired/getPlatform are updated to call the new is* methods or both getters
are provided for backward compatibility; locate methods getExpired/getPlatform
in LicenseAuthorizationQuotaInventory and replace/alias them with
isExpired/isPlatform to conform to the JavaBean convention.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cb5ebf9e-deef-4e4d-bbee-3833a246fb27

📥 Commits

Reviewing files that changed from the base of the PR and between 1e95d5d and e11603a.

📒 Files selected for processing (6)
  • sdk/src/main/java/SourceClassMap.java
  • sdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoAction.java
  • sdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoResult.java
  • sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationInfo.java
  • sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationQuotaInventory.java
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy

Comment on lines +23700 to +23704
def a = new org.zstack.sdk.GetLicenseAuthorizationInfoAction()

c.resolveStrategy = Closure.OWNER_FIRST
c.delegate = a
c()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

缺少 sessionId 赋值,API 调用可能因未认证而失败。

新增的 getLicenseAuthorizationInfo 方法在创建 action 后没有设置 a.sessionId,而同文件中其它所有辅助方法(如 Line 23728 的 getLicenseCapabilities、Line 3694 的 attachDGpuToVm、Line 48113 的 updateVmDGpu)都包含该赋值。缺失会导致调用时没有会话凭证,测试中很可能触发认证错误。

🐛 建议补充 sessionId 赋值
     def getLicenseAuthorizationInfo(`@DelegatesTo`(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.GetLicenseAuthorizationInfoAction.class) Closure c) {
         def a = new org.zstack.sdk.GetLicenseAuthorizationInfoAction()
-
+        a.sessionId = Test.currentEnvSpec?.session?.uuid
         c.resolveStrategy = Closure.OWNER_FIRST
         c.delegate = a
         c()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def a = new org.zstack.sdk.GetLicenseAuthorizationInfoAction()
c.resolveStrategy = Closure.OWNER_FIRST
c.delegate = a
c()
def a = new org.zstack.sdk.GetLicenseAuthorizationInfoAction()
a.sessionId = Test.currentEnvSpec?.session?.uuid
c.resolveStrategy = Closure.OWNER_FIRST
c.delegate = a
c()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy` around lines 23700
- 23704, The new getLicenseAuthorizationInfo helper creates a
org.zstack.sdk.GetLicenseAuthorizationInfoAction instance (variable a) but never
assigns a.sessionId, so API calls lack authentication; set a.sessionId to the
same session variable used elsewhere in this file (the common
sessionId/adminSession value used by getLicenseCapabilities, attachDGpuToVm,
updateVmDGpu) before invoking the closure (i.e., before c()), ensuring the
action carries the session credential.

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.

2 participants