Skip to content

Commit 3bae392

Browse files
author
Pearl Dsilva
committed
Add support to update secondary and primary storage URLs
1 parent 522283b commit 3bae392

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public class UpdateImageStoreCmd extends BaseCmd {
5050
description = "The number of bytes CloudStack can use on this image storage.\n\tNOTE: this will be overwritten by the StatsCollector as soon as there is a SSVM to query the storage.")
5151
private Long capacityBytes;
5252

53+
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = false,
54+
description = "The new URL for the image store (e.g. nfs://new-host/export). " +
55+
"The image store must be in read-only state before its URL can be changed. " +
56+
"After updating, destroy and recreate any Secondary Storage VMs so they remount the new path.",
57+
since = "4.23.0")
58+
private String url;
59+
5360
/////////////////////////////////////////////////////
5461
/////////////////// Accessors ///////////////////////
5562
/////////////////////////////////////////////////////
@@ -70,6 +77,10 @@ public Long getCapacityBytes() {
7077
return capacityBytes;
7178
}
7279

80+
public String getUrl() {
81+
return url;
82+
}
83+
7384
/////////////////////////////////////////////////////
7485
/////////////// API Implementation///////////////////
7586
/////////////////////////////////////////////////////

engine/components-api/src/main/java/com/cloud/storage/StorageManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void connectHostsToPool(DataStore primaryStore, List<Long> hostIds, Scope scope,
411411

412412
Long getDiskIopsWriteRate(ServiceOffering offering, DiskOffering diskOffering);
413413

414-
ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly, Long capacityBytes);
414+
ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly, Long capacityBytes, String url);
415415

416416
void cleanupDownloadUrls();
417417

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ private void updateStorageStats(ConcurrentHashMap<Long, StorageStats> storageSta
17871787
&& (_storageStats.get(storeId).getCapacityBytes() == 0l
17881788
|| _storageStats.get(storeId).getCapacityBytes() != storageStats.get(storeId).getCapacityBytes())) {
17891789
// get add to DB rigorously
1790-
_storageManager.updateImageStoreStatus(storeId, null, null, storageStats.get(storeId).getCapacityBytes());
1790+
_storageManager.updateImageStoreStatus(storeId, null, null, storageStats.get(storeId).getCapacityBytes(), null);
17911791
}
17921792
}
17931793
// if in _storageStats and not in storageStats it gets discarded

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,10 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I
12851285
changes = true;
12861286
}
12871287

1288+
if (cmd.getUrl() != null) {
1289+
changes = true;
1290+
}
1291+
12881292
if (changes) {
12891293
StoragePoolVO storagePool = _storagePoolDao.findById(id);
12901294
DataStoreProvider dataStoreProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
@@ -1300,6 +1304,21 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I
13001304
_storagePoolDao.updateCapacityIops(id, updatedCapacityIops);
13011305
}
13021306
if (cmd.getUrl() != null) {
1307+
if (!storagePool.isInMaintenance()) {
1308+
throw new InvalidParameterValueException("Storage pool must be in Maintenance state before its URL can be changed. " +
1309+
"Please put the pool into maintenance first.");
1310+
}
1311+
URI newUri;
1312+
try {
1313+
newUri = new URI(cmd.getUrl());
1314+
} catch (URISyntaxException e) {
1315+
throw new InvalidParameterValueException("Invalid URL format: " + cmd.getUrl());
1316+
}
1317+
storagePool.setHostAddress(newUri.getHost());
1318+
storagePool.setPath(newUri.getPath());
1319+
if (newUri.getPort() != -1) {
1320+
storagePool.setPort(newUri.getPort());
1321+
}
13031322
details.put("url", cmd.getUrl());
13041323
}
13051324
_storagePoolDao.update(id, storagePool);
@@ -4129,18 +4148,25 @@ public ImageStore migrateToObjectStore(String name, String url, String providerN
41294148

41304149
@Override
41314150
public ImageStore updateImageStore(UpdateImageStoreCmd cmd) {
4132-
return updateImageStoreStatus(cmd.getId(), cmd.getName(), cmd.getReadonly(), cmd.getCapacityBytes());
4151+
return updateImageStoreStatus(cmd.getId(), cmd.getName(), cmd.getReadonly(), cmd.getCapacityBytes(), cmd.getUrl());
41334152
}
41344153

41354154
@Override
41364155
@ActionEvent(eventType = EventTypes.EVENT_UPDATE_IMAGE_STORE_ACCESS_STATE,
41374156
eventDescription = "image store access updated")
4138-
public ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly, Long capacityBytes) {
4157+
public ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly, Long capacityBytes, String url) {
41394158
// Input validation
41404159
ImageStoreVO imageStoreVO = _imageStoreDao.findById(id);
41414160
if (imageStoreVO == null) {
41424161
throw new IllegalArgumentException("Unable to find image store with ID: " + id);
41434162
}
4163+
if (url != null) {
4164+
if (!imageStoreVO.isReadonly()) {
4165+
throw new InvalidParameterValueException("Image store must be set to read-only (maintenance) state before its URL can be changed. " +
4166+
"Please set readOnly=true on the image store first.");
4167+
}
4168+
imageStoreVO.setUrl(url);
4169+
}
41444170
if (com.cloud.utils.StringUtils.isNotBlank(name)) {
41454171
imageStoreVO.setName(name);
41464172
}
@@ -4156,7 +4182,7 @@ public ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly,
41564182

41574183
@Override
41584184
public ImageStore updateImageStoreStatus(Long id, Boolean readonly) {
4159-
return updateImageStoreStatus(id, null, readonly, null);
4185+
return updateImageStoreStatus(id, null, readonly, null, null);
41604186
}
41614187

41624188
/**

0 commit comments

Comments
 (0)