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
@@ -1,6 +1,7 @@
package org.zstack.storage.ceph.primary.capacity;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
Expand Down Expand Up @@ -238,23 +239,23 @@ public Long calculateAvailableCapacityByRatio(CephOsdGroupVO osdGroup, String pr
for (String poolName : poolNames) {
String installPathPrefix = String.format("ceph://%s", poolName);
long volSize = volumes.parallelStream()
.filter(v -> v.getInstallPath() != null && v.getInstallPath()
.filter(v -> !StringUtils.isEmpty(v.getInstallPath()) && v.getInstallPath()
.substring(0, v.getInstallPath().lastIndexOf("/"))
.equals((installPathPrefix)))
.map(VolumeVO::getSize)
.map(v -> Long.parseLong(String.valueOf(v)))
.reduce(0L, Long::sum);

long imageCacheSize = imageCaches.parallelStream()
.filter(v -> v.getInstallUrl() != null && v.getInstallUrl()
.filter(v -> !StringUtils.isEmpty(v.getInstallUrl()) && v.getInstallUrl()
.substring(0, v.getInstallUrl().lastIndexOf("/"))
.equals((installPathPrefix)))
.map(ImageCacheVO::getSize)
.map(v -> Long.parseLong(String.valueOf(v)))
.reduce(0L, Long::sum);

long snapShotSize = snapshots.parallelStream()
.filter(v -> v.getPrimaryStorageInstallPath() != null && v.getPrimaryStorageInstallPath()
.filter(v -> !StringUtils.isEmpty(v.getPrimaryStorageInstallPath()) && v.getPrimaryStorageInstallPath()
.substring(0, v.getPrimaryStorageInstallPath().lastIndexOf("/"))
.equals((installPathPrefix)))
.map(VolumeSnapshotVO::getSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CephXskyPoolCapacityCase extends SubCase {
env.create {
testReconnectPrimaryStorage()
testSkipCalculateCapacityWhichInstallPathIsNull()
testSkipCalculateCapacityWhichInstallPathIsEmpty()
}
}

Expand Down Expand Up @@ -205,4 +206,33 @@ class CephXskyPoolCapacityCase extends SubCase {
SQL.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.uuid, rootSnapshot.uuid)
.set(VolumeSnapshotVO_.primaryStorageInstallPath, volumeSnapshotInstallPath).update()
}

void testSkipCalculateCapacityWhichInstallPathIsEmpty() {
PrimaryStorageInventory ps = env.inventoryByName("ceph-pri") as PrimaryStorageInventory
VmInstanceInventory vm = env.inventoryByName("test-vm") as VmInstanceInventory

VolumeSnapshotInventory rootSnapshot = createVolumeSnapshot {
name = "root-volume-snapshot-empty-path"
volumeUuid = vm.rootVolumeUuid
} as VolumeSnapshotInventory

String volumeInstallPath = Q.New(VolumeVO.class).eq(VolumeVO_.uuid, vm.rootVolumeUuid).select(VolumeVO_.installPath)
.findValue()
String volumeSnapshotInstallPath = Q.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.uuid, rootSnapshot.uuid)
.select(VolumeSnapshotVO_.primaryStorageInstallPath)
.findValue()

// mock install path is empty string
SQL.New(VolumeVO.class).eq(VolumeVO_.uuid, vm.rootVolumeUuid).set(VolumeVO_.installPath, "").update()
SQL.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.uuid, rootSnapshot.uuid)
.set(VolumeSnapshotVO_.primaryStorageInstallPath, "").update()

reconnectPrimaryStorage {
uuid = ps.uuid
}

SQL.New(VolumeVO.class).eq(VolumeVO_.uuid, vm.rootVolumeUuid).set(VolumeVO_.installPath, volumeInstallPath).update()
SQL.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.uuid, rootSnapshot.uuid)
.set(VolumeSnapshotVO_.primaryStorageInstallPath, volumeSnapshotInstallPath).update()
}
}