-
Notifications
You must be signed in to change notification settings - Fork 0
<feature>[storage]: support cleanAllVmMetadata param #3760
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
base: feature-zsv-5.0.0-vm-support-vtpm-and-secuceboot
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ | |
| import java.io.File; | ||
| import java.util.*; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
@@ -3558,6 +3559,11 @@ public void done(ErrorCodeList errorCodeList) { | |
|
|
||
| @Override | ||
| protected void handle(final CleanupVmInstanceMetadataOnPrimaryStorageMsg msg) { | ||
| if (msg.isCleanAllVmMetadata()) { | ||
| handleCleanAllVmMetadataOnLocalStorage(msg); | ||
| return; | ||
| } | ||
|
|
||
| thdf.chainSubmit(new ChainTask(msg) { | ||
| @Override | ||
| public String getSyncSignature() { | ||
|
|
@@ -3623,4 +3629,64 @@ public String getName() { | |
| } | ||
| }); | ||
| } | ||
|
|
||
| private void handleCleanAllVmMetadataOnLocalStorage(final CleanupVmInstanceMetadataOnPrimaryStorageMsg msg) { | ||
| CleanupVmInstanceMetadataOnPrimaryStorageReply reply = new CleanupVmInstanceMetadataOnPrimaryStorageReply(); | ||
|
|
||
| List<String> connectedHostUuids = SQL.New( | ||
| "select h.hostUuid from LocalStorageHostRefVO h, HostVO host" + | ||
| " where h.primaryStorageUuid = :psUuid" + | ||
| " and h.hostUuid = host.uuid" + | ||
| " and host.status = :hstatus", String.class) | ||
| .param("psUuid", self.getUuid()) | ||
| .param("hstatus", HostStatus.Connected) | ||
| .list(); | ||
| if (connectedHostUuids.isEmpty()) { | ||
| logger.warn(String.format("[MetadataCleanup] cleanAll: no connected host found for local ps[uuid:%s]", self.getUuid())); | ||
| reply.setCleanedCount(0); | ||
| bus.reply(msg, reply); | ||
| return; | ||
| } | ||
|
|
||
| AtomicInteger totalCleaned = new AtomicInteger(0); | ||
| new While<>(connectedHostUuids).all((hostUuid, com) -> { | ||
| final LocalStorageHypervisorBackend bkd; | ||
| try { | ||
| LocalStorageHypervisorFactory f = getHypervisorBackendFactoryByHostUuid(hostUuid); | ||
| bkd = f.getHypervisorBackend(self); | ||
| } catch (Exception e) { | ||
| logger.warn(String.format("[MetadataCleanup] cleanAll: failed to prepare backend for host[uuid:%s] on ps[uuid:%s]: %s", | ||
| hostUuid, self.getUuid(), e.getMessage())); | ||
| com.addError(operr("failed to prepare backend for host[uuid:%s]: %s", hostUuid, e.getMessage())); | ||
| com.done(); | ||
| return; | ||
| } | ||
| bkd.handle(msg, hostUuid, new ReturnValueCompletion<CleanupVmInstanceMetadataOnPrimaryStorageReply>(com) { | ||
| @Override | ||
| public void success(CleanupVmInstanceMetadataOnPrimaryStorageReply returnValue) { | ||
| totalCleaned.addAndGet(returnValue.getCleanedCount()); | ||
| com.done(); | ||
| } | ||
|
|
||
| @Override | ||
| public void fail(ErrorCode errorCode) { | ||
| logger.warn(String.format("[MetadataCleanup] cleanAll: failed on host[uuid:%s] on ps[uuid:%s]: %s", | ||
| hostUuid, self.getUuid(), errorCode)); | ||
| com.addError(errorCode); | ||
| com.done(); | ||
| } | ||
| }); | ||
| }).run(new WhileDoneCompletion(msg) { | ||
| @Override | ||
| public void done(ErrorCodeList errorCodeList) { | ||
| if (!errorCodeList.getCauses().isEmpty() && errorCodeList.getCauses().size() == connectedHostUuids.size()) { | ||
| reply.setError(operr("failed to cleanup all vm metadata from all hosts on local primary storage[uuid:%s], causes: %s", | ||
| self.getUuid(), errorCodeList)); | ||
| } else { | ||
| reply.setCleanedCount(totalCleaned.get()); | ||
| } | ||
| bus.reply(msg, reply); | ||
|
Comment on lines
+3636
to
+3688
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不要把断连主机默认为“已全部清理”。 这里仅遍历 建议和本类的 🤖 Prompt for AI Agents |
||
| } | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 50376
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 321
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 381
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 229
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 4193
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1841
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 11401
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 119
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 115
需要添加参数组合验证。
现在
vmUuids和cleanAllVmMetadata都是可选的,但代码中没有验证至少一个参数被设置。建议在VmInstanceApiInterceptor中为APICleanupVmInstanceMetadataMsg添加验证方法,确保:vmUuids非空或cleanAllVmMetadata=true(至少满足其一),避免发送空清理请求。同时,
__example__()方法应覆盖新增的cleanAllVmMetadata参数,以提升 API 文档的可发现性。🤖 Prompt for AI Agents