From 04fe8344b0af15da0cd594f9e7e60a370fd703e8 Mon Sep 17 00:00:00 2001 From: Rene Peinthor Date: Fri, 22 Dec 2023 13:29:09 +0100 Subject: [PATCH] linstor: Outline get storagepools from resourcegroup into function --- .../kvm/storage/LinstorStorageAdaptor.java | 41 +------------------ .../storage/datastore/util/LinstorUtil.java | 27 +++++++----- 2 files changed, 18 insertions(+), 50 deletions(-) diff --git a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java index deee5fb6c413..fbe4f3a73022 100644 --- a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java +++ b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java @@ -47,7 +47,6 @@ import com.linbit.linstor.api.model.ProviderKind; import com.linbit.linstor.api.model.ResourceDefinition; import com.linbit.linstor.api.model.ResourceDefinitionModify; -import com.linbit.linstor.api.model.ResourceGroup; import com.linbit.linstor.api.model.ResourceGroupSpawn; import com.linbit.linstor.api.model.ResourceMakeAvailable; import com.linbit.linstor.api.model.ResourceWithVolumes; @@ -505,25 +504,7 @@ public long getAvailable(LinstorStoragePool pool) { DevelopersApi linstorApi = getLinstorAPI(pool); final String rscGroupName = pool.getResourceGroup(); try { - List rscGrps = linstorApi.resourceGroupList( - Collections.singletonList(rscGroupName), - null, - null, - null); - - if (rscGrps.isEmpty()) { - final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName); - s_logger.error(errMsg); - throw new CloudRuntimeException(errMsg); - } - - List storagePools = linstorApi.viewStoragePools( - Collections.emptyList(), - rscGrps.get(0).getSelectFilter().getStoragePoolList(), - null, - null, - null - ); + List storagePools = LinstorUtil.getRscGroupStoragePools(linstorApi, rscGroupName); final long free = storagePools.stream() .filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS) @@ -541,25 +522,7 @@ public long getUsed(LinstorStoragePool pool) { DevelopersApi linstorApi = getLinstorAPI(pool); final String rscGroupName = pool.getResourceGroup(); try { - List rscGrps = linstorApi.resourceGroupList( - Collections.singletonList(rscGroupName), - null, - null, - null); - - if (rscGrps.isEmpty()) { - final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName); - s_logger.error(errMsg); - throw new CloudRuntimeException(errMsg); - } - - List storagePools = linstorApi.viewStoragePools( - Collections.emptyList(), - rscGrps.get(0).getSelectFilter().getStoragePoolList(), - null, - null, - null - ); + List storagePools = LinstorUtil.getRscGroupStoragePools(linstorApi, rscGroupName); final long used = storagePools.stream() .filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS) diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java index b6904b90b29f..e953c94db220 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java @@ -136,28 +136,33 @@ public static String getSnapshotPath(com.linbit.linstor.api.model.StoragePool sp return path; } - public static long getCapacityBytes(String linstorUrl, String rscGroupName) { - DevelopersApi linstorApi = getLinstorAPI(linstorUrl); - try { - List rscGrps = linstorApi.resourceGroupList( + public static List getRscGroupStoragePools(DevelopersApi api, String rscGroupName) + throws ApiException { + List rscGrps = api.resourceGroupList( Collections.singletonList(rscGroupName), null, null, null); - if (rscGrps.isEmpty()) { - final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName); - s_logger.error(errMsg); - throw new CloudRuntimeException(errMsg); - } + if (rscGrps.isEmpty()) { + final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName); + s_logger.error(errMsg); + throw new CloudRuntimeException(errMsg); + } - List storagePools = linstorApi.viewStoragePools( + return api.viewStoragePools( Collections.emptyList(), rscGrps.get(0).getSelectFilter().getStoragePoolList(), null, null, null - ); + ); + } + + public static long getCapacityBytes(String linstorUrl, String rscGroupName) { + DevelopersApi linstorApi = getLinstorAPI(linstorUrl); + try { + List storagePools = getRscGroupStoragePools(linstorApi, rscGroupName); return storagePools.stream() .filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS)