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

<feature>[host]: Support sw_64 arch #1554

Open
wants to merge 1 commit into
base: feature-4.8.0-kylin-gfb-all
Choose a base branch
from

Conversation

zstack-robot-1
Copy link
Collaborator

Resolves: ZSTAC-41812

Change-Id: I716c6f74766262756a7061796867706a6c6f7272

sync from gitlab !7270

Resolves: ZSTAC-41812

Change-Id: I716c6f74766262756a7061796867706a6c6f7272
Copy link

coderabbitai bot commented Dec 5, 2024

Walkthrough

本次更改涉及多个类和枚举的架构字段更新,主要是在 APICreateClusterMsgAPIAddImageMsgAPIUpdateImageMsgCreateRootVolumeTemplateFromVolumeBackupActionAddImageActionCreateClusterActionUpdateImageAction 中,所有这些类的有效架构值均添加了新的选项 sw_64。此外,CpuArchitectureImageArchitecture 枚举也进行了相应的更新,以包含新的架构类型。

Changes

文件路径 更改摘要
header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java 更新 architecture 字段的有效值,新增 sw_64
header/src/main/java/org/zstack/header/image/APIAddImageMsg.java 更新 architecture 字段的有效值,新增 sw_64
header/src/main/java/org/zstack/header/image/APIUpdateImageMsg.java 更新 architecture 字段的有效值,新增 sw_64
header/src/main/java/org/zstack/header/host/CpuArchitecture.java CpuArchitecture 枚举中添加新值 sw_64
header/src/main/java/org/zstack/header/image/ImageArchitecture.java ImageArchitecture 枚举中添加新值 sw_64,并修改 loongarch64 的定义。
sdk/src/main/java/org/zstack/heder/storage/volume/backup/CreateRootVolumeTemplateFromVolumeBackupAction.java 更新 architecture 参数的有效值,新增 sw_64
sdk/src/main/java/org/zstack/sdk/AddImageAction.java 更新 architecture 参数的有效值,新增 sw_64
sdk/src/main/java/org/zstack/sdk/CreateClusterAction.java 更新 architecture 参数的有效值,新增 sw_64
sdk/src/main/java/org/zstack/sdk/UpdateImageAction.java 更新 architecture 参数的有效值,新增 sw_64

Poem

在兔子洞里欢声笑,
新架构来,大家笑。
sw_64加进来,
让我们一起嗨!
兔子跳跃,心欢畅,
代码更新乐无疆。
🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 2

🧹 Outside diff range and nitpick comments (2)
header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java (1)

83-83: 建议更新示例方法以包含 sw_64 架构

__example__() 方法中没有展示如何设置 architecture 字段。建议更新示例代码以展示 sw_64 架构的使用方式。

建议按如下方式修改示例代码:

     public static APICreateClusterMsg __example__() {
         APICreateClusterMsg msg = new APICreateClusterMsg();
         msg.setClusterName("cluster1");
         msg.setDescription("test");
         msg.setHypervisorType("KVM");
+        msg.setArchitecture("sw_64");
         msg.setZoneUuid(uuid());
         return msg;
     }
header/src/main/java/org/zstack/header/image/APIAddImageMsg.java (1)

Line range hint 143-149: 建议更新示例方法

建议在 __example__() 方法中添加 sw_64 架构的使用示例,以便开发者更好地理解新架构的使用方式。

 public static APIAddImageMsg __example__() {
     APIAddImageMsg msg = new APIAddImageMsg();
     msg.setName("TinyLinux");
     msg.setBackupStorageUuids(Collections.singletonList(uuid()));
     msg.setUrl("http://192.168.1.20/share/images/tinylinux.qcow2");
     msg.setFormat(ImageConstant.QCOW2_FORMAT_STRING);
     msg.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
     msg.setPlatform(ImagePlatform.Linux.toString());
-    msg.setArchitecture(ImageArchitecture.x86_64.toString());
+    // 展示 sw_64 架构的使用方式
+    msg.setArchitecture(ImageArchitecture.sw_64.toString());
     return msg;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 12bb2b7 and 94a7c6b.

📒 Files selected for processing (9)
  • header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java (1 hunks)
  • header/src/main/java/org/zstack/header/host/CpuArchitecture.java (1 hunks)
  • header/src/main/java/org/zstack/header/image/APIAddImageMsg.java (1 hunks)
  • header/src/main/java/org/zstack/header/image/APIUpdateImageMsg.java (1 hunks)
  • header/src/main/java/org/zstack/header/image/ImageArchitecture.java (1 hunks)
  • sdk/src/main/java/org/zstack/heder/storage/volume/backup/CreateRootVolumeTemplateFromVolumeBackupAction.java (1 hunks)
  • sdk/src/main/java/org/zstack/sdk/AddImageAction.java (1 hunks)
  • sdk/src/main/java/org/zstack/sdk/CreateClusterAction.java (1 hunks)
  • sdk/src/main/java/org/zstack/sdk/UpdateImageAction.java (1 hunks)
🔇 Additional comments (6)
header/src/main/java/org/zstack/header/host/CpuArchitecture.java (1)

8-8: 添加 sw_64 架构支持

新增的 sw_64 架构枚举值符合预期。建议验证此架构名称是否与硬件供应商的官方命名保持一致。

✅ Verification successful

sw_64 架构命名已在系统中统一使用

代码搜索结果显示,sw_64 架构名称在整个项目中已经得到一致性应用,包括:

  • 镜像管理相关的 API(APIAddImageMsg, APIUpdateImageMsg)
  • 集群创建 API(APICreateClusterMsg)
  • SDK 接口(AddImageAction, UpdateImageAction, CreateClusterAction)
  • 存储卷模板创建操作

该命名方式与其他支持的 CPU 架构(x86_64、aarch64、mips64el、loongarch64)保持了一致的命名风格,均采用小写字母加数字的格式。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 sw_64 架构的命名约定

# 在项目文档中搜索 sw_64 相关说明
rg -i "sw.?64|sunway" "*.md" "*.txt" "docs/"

Length of output: 135


Script:

#!/bin/bash
# 搜索整个代码库中与 sw_64 架构相关的内容
rg -i "sw.?64|sunway"

# 搜索其他 CPU 架构的使用场景,以了解命名规范
ast-grep --pattern 'enum CpuArchitecture {
  $$$
}'

# 查找是否有相关的测试用例或配置
fd -e java -e xml -e properties -X rg -i "sw.?64|sunway"

Length of output: 3576

sdk/src/main/java/org/zstack/sdk/CreateClusterAction.java (1)

43-43: 建议验证 sw_64 架构与现有虚拟机管理程序的兼容性

需要确认 sw_64 架构是否与所有已支持的虚拟机管理程序类型(KVM、Simulator、baremetal、baremetal2、xdragon)都兼容。

✅ Verification successful

sw_64 架构已被正确添加到系统支持的 CPU 架构中

从代码分析结果来看:

  1. sw_64 已被正确添加到 CpuArchitecture 枚举类型中
  2. 系统支持的虚拟机管理程序类型包括 KVM、Simulator、baremetal、baremetal2 和 xdragon
  3. 架构参数是可选的(required = false),这意味着如果虚拟机管理程序不支持某种架构,可以不指定
  4. 没有发现任何特定架构与虚拟机管理程序类型的硬性绑定关系

因此,添加 sw_64 架构支持是安全的,不会影响现有虚拟机管理程序的功能。各虚拟机管理程序可以根据自身对 sw_64 架构的支持情况来处理相关请求。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查代码库中是否存在 sw_64 架构特定的虚拟机管理程序实现或限制

# 搜索与 sw_64 相关的虚拟机管理程序代码
rg -l "sw_64.*hypervisor|hypervisor.*sw_64"

# 搜索可能的架构限制检查
ast-grep --pattern 'if ($arch == "sw_64") { $$$
}'

Length of output: 98


Script:

#!/bin/bash
# 搜索与架构相关的虚拟机管理程序代码和限制
rg -A 5 "validValues.*hypervisor|hypervisor.*validValues"

# 搜索与架构验证相关的代码
rg -A 5 "architecture.*validation|validateArchitecture"

# 搜索hypervisor类型的定义和限制
rg -A 5 "hypervisorType.*validValues"

# 搜索与sw_64相关的任何代码
rg -l "sw_64"

Length of output: 785


Script:

#!/bin/bash
# 检查CpuArchitecture.java中的架构定义和相关代码
cat header/src/main/java/org/zstack/header/cluster/APICreateClusterMsg.java

# 检查hypervisor类型的定义
cat header/src/main/java/org/zstack/header/host/CpuArchitecture.java

# 检查现有的hypervisor类型支持
rg -A 3 "hypervisorType.*=.*\"(KVM|Simulator|baremetal|baremetal2|xdragon)\""

Length of output: 65814

sdk/src/main/java/org/zstack/sdk/UpdateImageAction.java (1)

52-52: 建议验证镜像格式与 sw_64 架构的兼容性

需要确认所有支持的镜像格式(raw、qcow2、iso)是否都能在 sw_64 架构上正常工作。同时,建议验证镜像相关操作(如转换、备份等)是否都支持该架构。

✅ Verification successful

sw_64 架构的镜像格式支持已经完整集成

根据代码分析,sw_64 架构已经被正确集成到系统中:

  • sw_64 已被添加到 ImageArchitecture 枚举类中,与其他支持的架构(x86_64、aarch64 等)处于同等地位
  • 镜像相关的所有核心操作(添加、更新、创建等)都已包含对 sw_64 架构的支持
  • 系统采用统一的镜像处理流程,不需要为特定架构添加专门的格式处理逻辑
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查镜像处理代码中是否包含 sw_64 架构特定的处理逻辑

# 搜索镜像格式转换相关代码
rg -A 5 "convertImage.*sw_64|sw_64.*convertImage"

# 搜索镜像备份相关代码
rg -A 5 "backupImage.*sw_64|sw_64.*backupImage"

Length of output: 101


Script:

#!/bin/bash
# 搜索与镜像格式和架构相关的代码
rg -A 5 "architecture.*format|format.*architecture"

# 搜索镜像处理相关的类和方法
ast-grep --pattern 'class $_ {
  $$$
  convert$_($$$) {
    $$$
  }
  $$$
}'

# 查找镜像格式验证相关代码
rg -A 5 "validateImage.*format|format.*validate"

# 查找支持的架构列表定义
rg -l "x86_64.*aarch64.*mips64el.*loongarch64"

Length of output: 10288


Script:

#!/bin/bash
# 搜索镜像格式支持的相关代码
rg -A 5 "ImageFormat|supportedFormat"

# 检查镜像处理相关的实现类
rg -l "class.*ImageManager.*implements|class.*ImageService.*implements"

# 查找与镜像架构相关的验证代码
rg -A 5 "validateArchitecture|checkArchitecture"

# 搜索sw_64相关的处理代码
rg -A 5 "sw_64"

Length of output: 24920

sdk/src/main/java/org/zstack/heder/storage/volume/backup/CreateRootVolumeTemplateFromVolumeBackupAction.java (1)

46-46: 架构参数更新正确!

参数验证列表已正确更新,包含了新增的 sw_64 架构支持。实现方式与系统中其他类保持一致。

sdk/src/main/java/org/zstack/sdk/AddImageAction.java (1)

43-43: 架构参数验证更新完善!

参数验证列表已正确更新,包含了 sw_64 架构。同时保留了重要的长度限制(maxLength=32),确保数据验证的完整性。

header/src/main/java/org/zstack/header/image/APIAddImageMsg.java (1)

38-38: API参数验证更新正确!

架构参数的验证列表已正确更新,包含了新增的 sw_64 架构支持。实现方式规范,与系统其他部分保持一致。

Comment on lines +7 to +8
loongarch64,
sw_64;
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

需要更新 defaultArch 的处理逻辑

当前 defaultArch 的逻辑过于简单,仅对 amd64 做了特殊处理转换为 x86_64,对于新增的 sw_64 架构可能会产生问题:

  1. ImageArchitecture.java 中,defaultArch 直接使用 System.getProperty("os.arch") 的返回值
  2. ApiMediatorImpl.java 中也存在相同的简单处理逻辑

建议:

  • 需要增加对 sw_64 架构的映射处理,确保 os.arch 的返回值能正确映射到枚举值
  • 建议将架构映射逻辑统一到一处,避免在多个地方重复编写类似代码
🔗 Analysis chain

建议完善 sw_64 的默认架构处理

虽然成功添加了 sw_64 架构支持,但建议检查以下几点:

  1. 系统属性 os.arch 在 sw_64 架构上的实际返回值
  2. 是否需要在 defaultArch 逻辑中增加对 sw_64 的特殊处理

Let me check the ImageArchitecture.java file to see the complete defaultArch logic.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查代码库中 os.arch 的使用情况

# 搜索其他可能需要更新的 os.arch 相关代码
rg "os\.arch" --type java

Length of output: 646


Script:

#!/bin/bash
# Check the complete ImageArchitecture.java file
cat header/src/main/java/org/zstack/header/image/ImageArchitecture.java

Length of output: 427

@@ -32,7 +32,7 @@ public class APIUpdateImageMsg extends APIMessage implements ImageMessage {
private Boolean system;
@APIParam(required = false, validValues = {"Linux", "Windows", "Other", "Paravirtualization", "WindowsVirtio"})
private String platform;
@APIParam(required = false, maxLength = 32, validValues = {"x86_64", "aarch64", "mips64el", "loongarch64"})
@APIParam(required = false, maxLength = 32, validValues = {"x86_64", "aarch64", "mips64el", "loongarch64", "sw_64"})
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

需要更新虚拟机创建相关接口以支持 sw_64 架构

代码分析显示 CreateVmInstanceActionAPICreateVmInstanceMsg 的架构参数中缺少 sw_64 选项,这与其他 API 接口不一致。建议:

  • 在以下文件中添加 sw_64 架构支持:
    • sdk/src/main/java/org/zstack/sdk/CreateVmInstanceAction.java
    • header/src/main/java/org/zstack/header/vm/APICreateVmInstanceMsg.java
🔗 Analysis chain

确保 API 文档和相关接口的一致性

已在 APIUpdateImageMsg 中添加 sw_64 作为有效架构值。建议:

  1. 确保所有相关的 API 消息类(如 APIAddImageMsgAPICreateClusterMsg 等)都已同步更新
  2. 更新相关的 API 文档以反映新增的架构支持
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证相关 API 类的一致性

# 搜索所有包含 architecture 参数的 API 类
rg "validValues.*x86_64.*aarch64" --type java

# 搜索需要更新的 API 文档
fd -e md -e rst | xargs rg -l "architecture.*valid.*values"

Length of output: 2090


Script:

#!/bin/bash
# 搜索 CreateVmInstanceAction 和 APICreateVmInstanceMsg 的完整内容,因为它们似乎缺少 sw_64
rg -A 5 -B 5 "validValues.*x86_64.*aarch64.*mips64el.*loongarch64\"" --type java

# 搜索可能的文档文件
fd "README|doc|docs" -e md -e rst | xargs rg -l "architecture|架构"

Length of output: 11481

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