Skip to content

Commit 09b63bc

Browse files
Storage pool response improvements (#10740)
* Return details of the storage pool in the response including url, and update capacityBytes and capacityIops if applicable while creating storage pool * Added capacitybytes parameter to the storage pool response in sync with the capacityiops response parameter and createStoragePool cmd request parameter (existing disksizetotal parameter in the storage pool response can be deprecated) * Don't keep url in details * Persist the capacityBytes and capacityIops in the storage_pool_details table while creating storage pool as well, for consistency - as these are updated with during update storage pool * rebase with main fixes
1 parent d2615bb commit 09b63bc

File tree

7 files changed

+61
-13
lines changed

7 files changed

+61
-13
lines changed

api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,24 @@ public class StoragePoolResponse extends BaseResponseWithAnnotations {
7777
@Param(description = "the name of the cluster for the storage pool")
7878
private String clusterName;
7979

80+
@SerializedName(ApiConstants.CAPACITY_BYTES)
81+
@Param(description = "bytes CloudStack can provision from this storage pool", since = "4.22.0")
82+
private Long capacityBytes;
83+
84+
@Deprecated(since = "4.22.0")
8085
@SerializedName("disksizetotal")
8186
@Param(description = "the total disk size of the storage pool")
8287
private Long diskSizeTotal;
8388

8489
@SerializedName("disksizeallocated")
85-
@Param(description = "the host's currently allocated disk size")
90+
@Param(description = "the pool's currently allocated disk size")
8691
private Long diskSizeAllocated;
8792

8893
@SerializedName("disksizeused")
89-
@Param(description = "the host's currently used disk size")
94+
@Param(description = "the pool's currently used disk size")
9095
private Long diskSizeUsed;
9196

92-
@SerializedName("capacityiops")
97+
@SerializedName(ApiConstants.CAPACITY_IOPS)
9398
@Param(description = "IOPS CloudStack can provision from this storage pool")
9499
private Long capacityIops;
95100

@@ -288,6 +293,14 @@ public void setClusterName(String clusterName) {
288293
this.clusterName = clusterName;
289294
}
290295

296+
public Long getCapacityBytes() {
297+
return capacityBytes;
298+
}
299+
300+
public void setCapacityBytes(Long capacityBytes) {
301+
this.capacityBytes = capacityBytes;
302+
}
303+
291304
public Long getDiskSizeTotal() {
292305
return diskSizeTotal;
293306
}

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreLifeCycle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import com.cloud.storage.StoragePool;
2525

2626
public interface PrimaryDataStoreLifeCycle extends DataStoreLifeCycle {
27-
public static final String CAPACITY_BYTES = "capacityBytes";
28-
public static final String CAPACITY_IOPS = "capacityIops";
27+
String CAPACITY_BYTES = "capacityBytes";
28+
String CAPACITY_IOPS = "capacityIops";
2929

3030
void updateStoragePool(StoragePool storagePool, Map<String, String> details);
3131
void enableStoragePool(DataStore store);

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ public StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details, Li
320320
pool = super.persist(pool);
321321
if (details != null) {
322322
for (Map.Entry<String, String> detail : details.entrySet()) {
323+
if (detail.getKey().toLowerCase().contains("password") || detail.getKey().toLowerCase().contains("token")) {
324+
displayDetails = false;
325+
}
323326
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue(), displayDetails);
324327
_detailsDao.persist(vo);
325328
}

engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ UPDATE `cloud`.`ldap_configuration` SET uuid = UUID() WHERE uuid IS NULL OR uuid
3434

3535
-- Add the column cross_zone_instance_creation to cloud.backup_repository. if enabled it means that new Instance can be created on all Zones from Backups on this Repository.
3636
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backup_repository', 'cross_zone_instance_creation', 'TINYINT(1) DEFAULT NULL COMMENT ''Backup Repository can be used for disaster recovery on another zone''');
37+
38+
-- Updated display to false for password/token detail of the storage pool details
39+
UPDATE `cloud`.`storage_pool_details` SET display = 0 WHERE name LIKE '%password%';
40+
UPDATE `cloud`.`storage_pool_details` SET display = 0 WHERE name LIKE '%token%';

engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public class PrimaryDataStoreHelper {
8585
DataStoreProviderManager dataStoreProviderMgr;
8686

8787
public DataStore createPrimaryDataStore(PrimaryDataStoreParameters params) {
88-
if(params == null)
89-
{
88+
if (params == null) {
9089
throw new InvalidParameterValueException("createPrimaryDataStore: Input params is null, please check");
9190
}
9291
StoragePoolVO dataStoreVO = dataStoreDao.findPoolByUUID(params.getUuid());

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.cloudstack.storage.datastore.lifecycle;
2020

21+
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
2324
import java.util.UUID;
@@ -139,7 +140,6 @@ public DataStore initialize(Map<String, Object> dsInfos) {
139140
Long clusterId = (Long)dsInfos.get("clusterId");
140141
Long podId = (Long)dsInfos.get("podId");
141142
Long zoneId = (Long)dsInfos.get("zoneId");
142-
String url = (String)dsInfos.get("url");
143143
String providerName = (String)dsInfos.get("providerName");
144144
HypervisorType hypervisorType = (HypervisorType)dsInfos.get("hypervisorType");
145145
if (clusterId != null && podId == null) {
@@ -148,19 +148,43 @@ public DataStore initialize(Map<String, Object> dsInfos) {
148148

149149
PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters();
150150

151-
String tags = (String)dsInfos.get("tags");
152-
String storageAccessGroups = (String)dsInfos.get(ApiConstants.STORAGE_ACCESS_GROUPS);
153151
Map<String, String> details = (Map<String, String>)dsInfos.get("details");
152+
if (dsInfos.get("capacityBytes") != null) {
153+
Long capacityBytes = (Long)dsInfos.get("capacityBytes");
154+
if (capacityBytes <= 0) {
155+
throw new IllegalArgumentException("'capacityBytes' must be greater than 0.");
156+
}
157+
if (details == null) {
158+
details = new HashMap<>();
159+
}
160+
details.put(PrimaryDataStoreLifeCycle.CAPACITY_BYTES, String.valueOf(capacityBytes));
161+
parameters.setCapacityBytes(capacityBytes);
162+
}
163+
164+
if (dsInfos.get("capacityIops") != null) {
165+
Long capacityIops = (Long)dsInfos.get("capacityIops");
166+
if (capacityIops <= 0) {
167+
throw new IllegalArgumentException("'capacityIops' must be greater than 0.");
168+
}
169+
if (details == null) {
170+
details = new HashMap<>();
171+
}
172+
details.put(PrimaryDataStoreLifeCycle.CAPACITY_IOPS, String.valueOf(capacityIops));
173+
parameters.setCapacityIops(capacityIops);
174+
}
154175

176+
parameters.setDetails(details);
177+
178+
String tags = (String)dsInfos.get("tags");
155179
parameters.setTags(tags);
156-
parameters.setStorageAccessGroups(storageAccessGroups);
157180
parameters.setIsTagARule((Boolean)dsInfos.get("isTagARule"));
158-
parameters.setDetails(details);
181+
182+
String storageAccessGroups = (String)dsInfos.get(ApiConstants.STORAGE_ACCESS_GROUPS);
183+
parameters.setStorageAccessGroups(storageAccessGroups);
159184

160185
String scheme = dsInfos.get("scheme").toString();
161186
String storageHost = dsInfos.get("host").toString();
162187
String hostPath = dsInfos.get("hostPath").toString();
163-
String uri = String.format("%s://%s%s", scheme, storageHost, hostPath);
164188

165189
Object localStorage = dsInfos.get("localStorage");
166190
if (localStorage != null) {

server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.cloud.api.ApiDBUtils;
4141
import com.cloud.api.query.vo.StoragePoolJoinVO;
4242
import com.cloud.capacity.CapacityManager;
43+
import com.cloud.server.ResourceTag;
4344
import com.cloud.storage.DataStoreRole;
4445
import com.cloud.storage.ScopeType;
4546
import com.cloud.storage.Storage;
@@ -152,6 +153,7 @@ public StoragePoolResponse newStoragePoolResponse(StoragePoolJoinVO pool, boolea
152153
}
153154
}
154155
}
156+
poolResponse.setCapacityBytes(pool.getCapacityBytes());
155157
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
156158
poolResponse.setDiskSizeAllocated(allocatedSize);
157159
poolResponse.setDiskSizeUsed(pool.getUsedBytes());
@@ -180,6 +182,8 @@ public StoragePoolResponse newStoragePoolResponse(StoragePoolJoinVO pool, boolea
180182
poolResponse.setIsTagARule(pool.getIsTagARule());
181183
poolResponse.setOverProvisionFactor(Double.toString(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId())));
182184
poolResponse.setManaged(storagePool.isManaged());
185+
Map<String, String> details = ApiDBUtils.getResourceDetails(pool.getId(), ResourceTag.ResourceObjectType.Storage);
186+
poolResponse.setDetails(details);
183187

184188
// set async job
185189
if (pool.getJobId() != null) {
@@ -252,6 +256,7 @@ public StoragePoolResponse newStoragePoolForMigrationResponse(StoragePoolJoinVO
252256
}
253257

254258
long allocatedSize = pool.getUsedCapacity();
259+
poolResponse.setCapacityBytes(pool.getCapacityBytes());
255260
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
256261
poolResponse.setDiskSizeAllocated(allocatedSize);
257262
poolResponse.setCapacityIops(pool.getCapacityIops());

0 commit comments

Comments
 (0)