[ZCF-3922] add license auth info api#4163
Conversation
Resolves: ZCF-3922 Change-Id: If9579e1648bc614985e13855fc84ade1a49fc38a
|
Warning
|
| 层级 / 文件 | 说明 |
|---|---|
许可证授权数据模型 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) 方法。定义参数字段(systemTags、userTags、isSuppressCredentialCheck、requestIp)。配置 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 | 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.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
sdk/src/main/java/org/zstack/sdk/LicenseAuthorizationInfo.java (2)
103-109: ⚡ Quick winList 字段缺少泛型类型参数。
字段
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 winList 字段缺少泛型类型参数。
字段
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 winBoolean 字段的 getter 方法未遵循 JavaBean 规范。
字段
expired和platform的 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参数字段缺少泛型类型参数。
字段
systemTags和userTags使用了原始类型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
📒 Files selected for processing (6)
sdk/src/main/java/SourceClassMap.javasdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoAction.javasdk/src/main/java/org/zstack/sdk/GetLicenseAuthorizationInfoResult.javasdk/src/main/java/org/zstack/sdk/LicenseAuthorizationInfo.javasdk/src/main/java/org/zstack/sdk/LicenseAuthorizationQuotaInventory.javatestlib/src/main/java/org/zstack/testlib/ApiHelper.groovy
| def a = new org.zstack.sdk.GetLicenseAuthorizationInfoAction() | ||
|
|
||
| c.resolveStrategy = Closure.OWNER_FIRST | ||
| c.delegate = a | ||
| c() |
There was a problem hiding this comment.
缺少 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.
| 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.
Summary
Validation
sync from gitlab !10068