Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private static String desensitizeUrl(String url) {
return url;
}

@Override
public String getIdentity() {
return identity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.zstack.header.core.ReturnValueCompletion;
import org.zstack.header.host.HostInventory;
import org.zstack.header.storage.addon.*;
import org.zstack.header.storage.primary.StorageResourceStats;
import org.zstack.header.storage.snapshot.VolumeSnapshotStats;
import org.zstack.header.volume.VolumeProtocol;
import org.zstack.header.volume.VolumeStats;
Expand Down Expand Up @@ -64,7 +65,7 @@ public interface PrimaryStorageControllerSvc {
// support uri or path
void stats(String installPath, ReturnValueCompletion<VolumeStats> comp);

void batchStats(Collection<String> installPath, ReturnValueCompletion<List<VolumeStats>> comp);
void batchStats(Collection<String> installPaths, ReturnValueCompletion<List<StorageResourceStats>> comp);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

为新增接口契约补充有效 Javadoc。

batchStats 现在同时承担卷/快照资源统计,建议明确参数含义及返回值可能是 VolumeStatsVolumeSnapshotStats,避免实现方误用。

+    /**
+     * 批量查询卷或快照安装路径对应的资源统计。
+     *
+     * `@param` installPaths 卷或快照安装路径
+     * `@param` comp         统计结果回调
+     */
    void batchStats(Collection<String> installPaths, ReturnValueCompletion<List<StorageResourceStats>> comp);

根据路径指令,接口方法必须配有有效 Javadoc。

📝 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
void batchStats(Collection<String> installPaths, ReturnValueCompletion<List<StorageResourceStats>> comp);
/**
* 批量查询卷或快照安装路径对应的资源统计
*
* `@param` installPaths 卷或快照安装路径
* `@param` comp 统计结果回调
*/
void batchStats(Collection<String> installPaths, ReturnValueCompletion<List<StorageResourceStats>> comp);
🤖 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
`@header/src/main/java/org/zstack/header/storage/addon/primary/PrimaryStorageControllerSvc.java`
at line 68, 为 PrimaryStorageControllerSvc.batchStats 补充有效 Javadoc,明确
installPaths 表示待统计的卷或快照资源路径,说明 comp 的返回结果为资源统计列表,元素可能是 VolumeStats 或
VolumeSnapshotStats,并注明完成回调的用途。

Source: Path instructions


void expandVolume(String installPath, long size, ReturnValueCompletion<VolumeStats> comp);
void setVolumeQos(BaseVolumeInfo v, Completion comp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class AskVolumeSnapshotCapabilityMsg extends NeedReplyMessage implements PrimaryStorageMessage {
private String primaryStorageUuid;
private VolumeInventory volume;
private String volumeType;

@Override
public String getPrimaryStorageUuid() {
Expand All @@ -26,4 +27,12 @@ public VolumeInventory getVolume() {
public void setVolume(VolumeInventory volume) {
this.volume = volume;
}

public String getVolumeType() {
return volumeType;
}

public void setVolumeType(String volumeType) {
this.volumeType = volumeType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ public String getType() {
return type;
}

public String getIdentity() {
return type;
}

public void setType(String type) {
this.type = type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.zstack.header.storage.primary;

public class StorageResourceStats {
protected String installPath;
protected Long actualSize;
protected Long size;

public String getInstallPath() {
return installPath;
}

public void setInstallPath(String installPath) {
this.installPath = installPath;
}

public Long getActualSize() {
return actualSize;
}

public void setActualSize(Long actualSize) {
this.actualSize = actualSize;
}

public Long getSize() {
return size;
}

public void setSize(long size) {
this.size = size;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public static enum VolumeSnapshotPlacementType {
EXTERNAL,
}

public static enum VolumeSnapshotMode {
REDIRECT_ON_WRITE,
COPY_ON_WRITE,
}

private boolean support;

/***
Expand All @@ -34,6 +39,8 @@ public static enum VolumeSnapshotPlacementType {
private VolumeSnapshotArrangementType arrangementType;

private VolumeSnapshotPlacementType placementType;

private VolumeSnapshotMode mode;

/***
* If volume snapshot is inner snapshot on volume, it must be set.
Expand Down Expand Up @@ -66,6 +73,14 @@ public void setPlacementType(VolumeSnapshotPlacementType placementType) {
this.placementType = placementType;
}

public VolumeSnapshotMode getMode() {
return mode;
}

public void setMode(VolumeSnapshotMode mode) {
this.mode = mode;
}

public boolean isSupportCreateOnHypervisor() {
return supportCreateOnHypervisor;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
package org.zstack.header.storage.snapshot;

public class VolumeSnapshotStats {
private String installPath;
private long actualSize;
import org.zstack.header.storage.primary.StorageResourceStats;

public String getInstallPath() {
return installPath;
}

public void setInstallPath(String installPath) {
this.installPath = installPath;
}

public long getActualSize() {
return actualSize;
}

public void setActualSize(long actualSize) {
this.actualSize = actualSize;
}
public class VolumeSnapshotStats extends StorageResourceStats {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

import java.util.Map;

public class BatchSyncVolumeSizeOnPrimaryStorageMsg extends NeedReplyMessage implements PrimaryStorageMessage {
public class BatchSyncVolumeResourceSizeOnPrimaryStorageMsg extends NeedReplyMessage implements PrimaryStorageMessage {
private String hostUuid;

private String primaryStorageUuid;

private Map<String, String> volumeUuidInstallPaths;

private Map<String, String> snapshotUuidInstallPaths;

private boolean withSnapshot;

public void setHostUuid(String hostUuid) {
this.hostUuid = hostUuid;
}
Expand All @@ -35,4 +39,20 @@ public void setVolumeUuidInstallPaths(Map<String, String> volumeUuidInstallPaths
public Map<String, String> getVolumeUuidInstallPaths() {
return volumeUuidInstallPaths;
}

public Map<String, String> getSnapshotUuidInstallPaths() {
return snapshotUuidInstallPaths;
}

public void setSnapshotUuidInstallPaths(Map<String, String> snapshotUuidInstallPaths) {
this.snapshotUuidInstallPaths = snapshotUuidInstallPaths;
}

public boolean isWithSnapshot() {
return withSnapshot;
}

public void setWithSnapshot(boolean withSnapshot) {
this.withSnapshot = withSnapshot;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.zstack.header.volume;

import org.zstack.header.message.MessageReply;

import java.util.HashMap;
import java.util.Map;

public class BatchSyncVolumeResourceSizeOnPrimaryStorageReply extends MessageReply {
private Map<String, Long> volumeActualSizes = new HashMap<>();

private Map<String, Long> snapshotActualSizes = new HashMap<>();

public void setVolumeActualSizes(Map<String, Long> actualSizes) {
this.volumeActualSizes = actualSizes;
}

public Map<String, Long> getVolumeActualSizes() {
return volumeActualSizes;
}

public Map<String, Long> getSnapshotActualSizes() {
return snapshotActualSizes;
}

public void setSnapshotActualSizes(Map<String, Long> snapshotActualSizes) {
this.snapshotActualSizes = snapshotActualSizes;
}
}

This file was deleted.

31 changes: 3 additions & 28 deletions header/src/main/java/org/zstack/header/volume/VolumeStats.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.zstack.header.volume;

public class VolumeStats {
protected String installPath;
import org.zstack.header.storage.primary.StorageResourceStats;

public class VolumeStats extends StorageResourceStats {
protected String format;
protected Long actualSize;
protected Long size;
/**
* The parent uri of the volume, vendor://pool/path@snapshot or snapshot://uuid
*/
Expand All @@ -29,30 +28,6 @@ public VolumeStats(String installPath, Long actualSize, Long size) {
public VolumeStats() {
}

public String getInstallPath() {
return installPath;
}

public void setInstallPath(String installPath) {
this.installPath = installPath;
}

public Long getActualSize() {
return actualSize;
}

public void setActualSize(Long actualSize) {
this.actualSize = actualSize;
}

public Long getSize() {
return size;
}

public void setSize(long size) {
this.size = size;
}

public void setFormat(String format) {
this.format = format;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3325,11 +3325,16 @@ protected void handle(AskVolumeSnapshotCapabilityMsg msg) {
AskVolumeSnapshotCapabilityReply reply = new AskVolumeSnapshotCapabilityReply();
VolumeSnapshotCapability cap = new VolumeSnapshotCapability();

String volumeType = msg.getVolume().getType();
String volumeType = msg.getVolumeType();
if (volumeType == null) {
volumeType = msg.getVolume().getType();
}

if (VolumeType.Data.toString().equals(volumeType) || VolumeType.Root.toString().equals(volumeType)) {
cap.setSupport(true);
cap.setArrangementType(VolumeSnapshotArrangementType.INDIVIDUAL);
cap.setPlacementType(VolumeSnapshotCapability.VolumeSnapshotPlacementType.INTERNAL);
cap.setMode(VolumeSnapshotCapability.VolumeSnapshotMode.REDIRECT_ON_WRITE);
cap.setVolumePathFromInternalSnapshotRegex("^[^@]+");
} else if (VolumeType.Memory.toString().equals(volumeType)) {
cap.setSupport(false);
Expand Down Expand Up @@ -3397,10 +3402,10 @@ public void fail(ErrorCode errorCode) {
}

@Override
protected void handle(BatchSyncVolumeSizeOnPrimaryStorageMsg msg) {
protected void handle(BatchSyncVolumeResourceSizeOnPrimaryStorageMsg msg) {
inQueue().name(String.format("batch-sync-volume-size-on-primarystorage-%s", self.getUuid()))
.asyncBackup(msg)
.run(chain -> BatchSyncVolumeSizeOnPrimaryStorage(msg, new NoErrorCompletion(chain) {
.run(chain -> BatchSyncVolumeResourceSizeOnPrimaryStorage(msg, new NoErrorCompletion(chain) {
Comment on lines +3405 to +3408

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

私有方法名违反 lowerCamelCase 命名规范

私有方法 BatchSyncVolumeResourceSizeOnPrimaryStorage 首字母大写,不符合方法命名应使用 lowerCamelCase 的规范。正好此次重命名,建议一并修正大小写。

♻️ 建议修正
-                .run(chain -> BatchSyncVolumeResourceSizeOnPrimaryStorage(msg, new NoErrorCompletion(chain) {
+                .run(chain -> batchSyncVolumeResourceSizeOnPrimaryStorage(msg, new NoErrorCompletion(chain) {
-    private void BatchSyncVolumeResourceSizeOnPrimaryStorage(BatchSyncVolumeResourceSizeOnPrimaryStorageMsg msg, NoErrorCompletion completion) {
+    private void batchSyncVolumeResourceSizeOnPrimaryStorage(BatchSyncVolumeResourceSizeOnPrimaryStorageMsg msg, NoErrorCompletion completion) {

As per path instructions, "方法名、参数名、成员变量和局部变量:使用 lowerCamelCase 风格。"

Also applies to: 3427-3457

🤖 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
`@plugin/ceph/src/main/java/org/zstack/storage/ceph/primary/CephPrimaryStorageBase.java`
around lines 3405 - 3408, 将私有方法 BatchSyncVolumeResourceSizeOnPrimaryStorage
重命名为符合 lowerCamelCase 的 batchSyncVolumeResourceSizeOnPrimaryStorage,并同步更新
handle(BatchSyncVolumeResourceSizeOnPrimaryStorageMsg) 及所有相关调用、方法引用和声明。

Source: Path instructions

@Override
public void done() {
chain.next();
Expand All @@ -3419,8 +3424,8 @@ protected void syncVolumeSize(String volumeUuid, String installPath, final Retur
httpCall(GET_VOLUME_SIZE_PATH, cmd, GetVolumeSizeRsp.class, completion);
}

private void BatchSyncVolumeSizeOnPrimaryStorage(BatchSyncVolumeSizeOnPrimaryStorageMsg msg, NoErrorCompletion completion) {
BatchSyncVolumeSizeOnPrimaryStorageReply reply = new BatchSyncVolumeSizeOnPrimaryStorageReply();
private void BatchSyncVolumeResourceSizeOnPrimaryStorage(BatchSyncVolumeResourceSizeOnPrimaryStorageMsg msg, NoErrorCompletion completion) {
BatchSyncVolumeResourceSizeOnPrimaryStorageReply reply = new BatchSyncVolumeResourceSizeOnPrimaryStorageReply();

GetBatchVolumeSizeCmd cmd = new GetBatchVolumeSizeCmd();
cmd.volumeUuidInstallPaths = msg.getVolumeUuidInstallPaths();
Expand All @@ -3436,7 +3441,7 @@ public void success(GetBatchVolumeSizeRsp rsp) {
markVolumeActualSize(volumeUuid, actualSize);
}

reply.setActualSizes(rsp.actualSizes);
reply.setVolumeActualSizes(rsp.actualSizes);
bus.reply(msg, reply);
completion.done();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.zstack.header.storage.addon.*;
import org.zstack.header.storage.addon.primary.*;
import org.zstack.header.storage.primary.ImageCacheInventory;
import org.zstack.header.storage.primary.StorageResourceStats;
import org.zstack.header.storage.primary.VolumeSnapshotCapability;
import org.zstack.header.storage.snapshot.VolumeSnapshotStats;
import org.zstack.header.volume.*;
Expand Down Expand Up @@ -93,6 +94,7 @@ public class ExponStorageController implements PrimaryStorageControllerSvc, Prim
scap.setSupport(true);
scap.setArrangementType(VolumeSnapshotCapability.VolumeSnapshotArrangementType.INDIVIDUAL);
scap.setPlacementType(VolumeSnapshotCapability.VolumeSnapshotPlacementType.INTERNAL);
scap.setMode(VolumeSnapshotCapability.VolumeSnapshotMode.REDIRECT_ON_WRITE);
scap.setSupportCreateOnHypervisor(false);
scap.setSupportLazyDelete(true);
scap.setVolumePathFromInternalSnapshotRegex("^[^@]+");
Expand Down Expand Up @@ -1158,15 +1160,15 @@ public void stats(String installPath, ReturnValueCompletion<VolumeStats> comp) {
}

@Override
public void batchStats(Collection<String> installPath, ReturnValueCompletion<List<VolumeStats>> comp) {
List<VolumeStats> stats = installPath.stream().map(it -> {
public void batchStats(Collection<String> installPaths, ReturnValueCompletion<List<StorageResourceStats>> comp) {
List<StorageResourceStats> stats = installPaths.stream().map(it -> {
VolumeModule vol = apiHelper.getVolume(getVolIdFromPath(it));
VolumeStats s = new VolumeStats();
s.setInstallPath(it);
s.setSize(vol.getVolumeSize());
s.setActualSize(vol.getDataSize());
s.setFormat(VolumeConstant.VOLUME_FORMAT_RAW);
return s;
return (StorageResourceStats) s;
}).collect(Collectors.toList());
comp.success(stats);
}
Expand Down
Loading