Skip to content
Draft
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 @@ -50,6 +50,13 @@ public class UpdateImageStoreCmd extends BaseCmd {
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.")
private Long capacityBytes;

@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = false,
description = "The new URL for the image store (e.g. nfs://new-host/export). " +
"The image store must be in read-only state before its URL can be changed. " +
"After updating, destroy and recreate any Secondary Storage VMs so they remount the new path.",
since = "4.23.0")
private String url;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -70,6 +77,10 @@ public Long getCapacityBytes() {
return capacityBytes;
}

public String getUrl() {
return url;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void connectHostsToPool(DataStore primaryStore, List<Long> hostIds, Scope scope,

Long getDiskIopsWriteRate(ServiceOffering offering, DiskOffering diskOffering);

ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly, Long capacityBytes);
ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly, Long capacityBytes, String url);

void cleanupDownloadUrls();

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/com/cloud/server/StatsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
}
}

protected void init(Map<String, String> configs) {

Check warning on line 433 in server/src/main/java/com/cloud/server/StatsCollector.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 127 to 64, Complexity from 19 to 14, Nesting Level from 3 to 2, Number of Variables from 12 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKQjc-PA8pjUL6Z0&open=AZ5BdKQjc-PA8pjUL6Z0&pullRequest=13193
_executor = Executors.newScheduledThreadPool(6, new NamedThreadFactory("StatsCollector"));

hostStatsInterval = NumbersUtil.parseLong(configs.get("host.stats.interval"), ONE_MINUTE_IN_MILLISCONDS);
Expand Down Expand Up @@ -1448,7 +1448,7 @@
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {

Check warning on line 1451 in server/src/main/java/com/cloud/server/StatsCollector.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 70 to 64, Complexity from 15 to 14, Nesting Level from 3 to 2, Number of Variables from 15 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKQjc-PA8pjUL6Z1&open=AZ5BdKQjc-PA8pjUL6Z1&pullRequest=13193
Pair<Map<Long, VMInstanceVO>, Map<String, Long>> vmsAndMap = getVmMapForStatsForHost(host);
Map<Long, VMInstanceVO> vmMap = vmsAndMap.first();
HashMap<Long, List<? extends VmDiskStats>> vmDiskStatsById =
Expand Down Expand Up @@ -1557,7 +1557,7 @@
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {

Check warning on line 1560 in server/src/main/java/com/cloud/server/StatsCollector.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 68 to 64, Complexity from 19 to 14, Nesting Level from 3 to 2, Number of Variables from 15 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKQjc-PA8pjUL6Z2&open=AZ5BdKQjc-PA8pjUL6Z2&pullRequest=13193
Pair<Map<Long, VMInstanceVO>, Map<String, Long>> vmsAndMap = getVmMapForStatsForHost(host);
Map<Long, VMInstanceVO> vmMap = vmsAndMap.first();
HashMap<Long, List<? extends VmNetworkStats>> vmNetworkStatsById =
Expand Down Expand Up @@ -1698,7 +1698,7 @@

class StorageCollector extends ManagedContextRunnable {
@Override
protected void runInContext() {

Check warning on line 1701 in server/src/main/java/com/cloud/server/StatsCollector.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 76 to 64, Complexity from 23 to 14, Nesting Level from 6 to 2, Number of Variables from 24 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKQjc-PA8pjUL6Zz&open=AZ5BdKQjc-PA8pjUL6Zz&pullRequest=13193
try {
if (logger.isDebugEnabled()) {
logger.debug("StorageCollector is running...");
Expand Down Expand Up @@ -1787,7 +1787,7 @@
&& (_storageStats.get(storeId).getCapacityBytes() == 0l
|| _storageStats.get(storeId).getCapacityBytes() != storageStats.get(storeId).getCapacityBytes())) {
// get add to DB rigorously
_storageManager.updateImageStoreStatus(storeId, null, null, storageStats.get(storeId).getCapacityBytes());
_storageManager.updateImageStoreStatus(storeId, null, null, storageStats.get(storeId).getCapacityBytes(), null);
}
}
// if in _storageStats and not in storageStats it gets discarded
Expand Down
32 changes: 29 additions & 3 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@
}

@Override
public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException {

Check warning on line 967 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 112 to 64, Complexity from 22 to 14, Nesting Level from 3 to 2, Number of Variables from 25 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKKhc-PA8pjUL6Zw&open=AZ5BdKKhc-PA8pjUL6Zw&pullRequest=13193
jsInterpreterHelper.ensureInterpreterEnabledIfParameterProvided(ApiConstants.IS_TAG_A_RULE, Boolean.TRUE.equals(cmd.isTagARule()));

String providerName = cmd.getStorageProviderName();
Expand Down Expand Up @@ -1094,7 +1094,7 @@
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}

protected Map<String,String> extractUriParamsAsMap(String url) {

Check warning on line 1097 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 66 to 64, Complexity from 16 to 14, Nesting Level from 3 to 2, Number of Variables from 13 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKKhc-PA8pjUL6Zy&open=AZ5BdKKhc-PA8pjUL6Zy&pullRequest=13193
Map<String,String> uriParams = new HashMap<>();
UriUtils.UriInfo uriInfo;
try {
Expand Down Expand Up @@ -1222,7 +1222,7 @@

@Override
@ActionEvent(eventType = EventTypes.EVENT_UPDATE_PRIMARY_STORAGE, eventDescription = "update storage pool")
public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {

Check warning on line 1225 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 91 to 64, Complexity from 22 to 14, Nesting Level from 4 to 2, Number of Variables from 19 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKKhc-PA8pjUL6Zv&open=AZ5BdKKhc-PA8pjUL6Zv&pullRequest=13193
// Input validation
jsInterpreterHelper.ensureInterpreterEnabledIfParameterProvided(ApiConstants.IS_TAG_A_RULE, Boolean.TRUE.equals(cmd.isTagARule()));

Expand Down Expand Up @@ -1285,6 +1285,10 @@
changes = true;
}

if (cmd.getUrl() != null) {
changes = true;
}

if (changes) {
StoragePoolVO storagePool = _storagePoolDao.findById(id);
DataStoreProvider dataStoreProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
Expand All @@ -1300,6 +1304,21 @@
_storagePoolDao.updateCapacityIops(id, updatedCapacityIops);
}
if (cmd.getUrl() != null) {
if (!storagePool.isInMaintenance()) {
throw new InvalidParameterValueException("Storage pool must be in Maintenance state before its URL can be changed. " +
"Please put the pool into maintenance first.");
}
URI newUri;
try {
newUri = new URI(cmd.getUrl());
} catch (URISyntaxException e) {
throw new InvalidParameterValueException("Invalid URL format: " + cmd.getUrl());
}
storagePool.setHostAddress(newUri.getHost());
storagePool.setPath(newUri.getPath());
if (newUri.getPort() != -1) {
storagePool.setPort(newUri.getPort());
}
details.put("url", cmd.getUrl());
}
_storagePoolDao.update(id, storagePool);
Expand Down Expand Up @@ -1421,7 +1440,7 @@

@Override
@ActionEvent(eventType = EventTypes.EVENT_CONFIGURE_STORAGE_ACCESS, eventDescription = "configuring storage groups", async = true)
public boolean configureStorageAccess(ConfigureStorageAccessCmd cmd) {

Check warning on line 1443 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 106 to 64, Complexity from 35 to 14, Nesting Level from 3 to 2, Number of Variables from 27 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKKhc-PA8pjUL6Zx&open=AZ5BdKKhc-PA8pjUL6Zx&pullRequest=13193
Long zoneId = cmd.getZoneId();
Long podId = cmd.getPodId();
Long clusterId = cmd.getClusterId();
Expand Down Expand Up @@ -2915,7 +2934,7 @@
}

@Override
public Pair<Boolean, String> checkIfReadyVolumeFitsInStoragePoolWithStorageAccessGroups(StoragePool destPool, Volume volume) {

Check warning on line 2937 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 74 to 64, Complexity from 20 to 14, Nesting Level from 6 to 2, Number of Variables from 21 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ5BdKKhc-PA8pjUL6Zu&open=AZ5BdKKhc-PA8pjUL6Zu&pullRequest=13193
if (Volume.State.Ready.equals(volume.getState())) {
Long vmId = volume.getInstanceId();
VMInstanceVO vm = null;
Expand Down Expand Up @@ -4129,18 +4148,25 @@

@Override
public ImageStore updateImageStore(UpdateImageStoreCmd cmd) {
return updateImageStoreStatus(cmd.getId(), cmd.getName(), cmd.getReadonly(), cmd.getCapacityBytes());
return updateImageStoreStatus(cmd.getId(), cmd.getName(), cmd.getReadonly(), cmd.getCapacityBytes(), cmd.getUrl());
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_UPDATE_IMAGE_STORE_ACCESS_STATE,
eventDescription = "image store access updated")
public ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly, Long capacityBytes) {
public ImageStore updateImageStoreStatus(Long id, String name, Boolean readonly, Long capacityBytes, String url) {
// Input validation
ImageStoreVO imageStoreVO = _imageStoreDao.findById(id);
if (imageStoreVO == null) {
throw new IllegalArgumentException("Unable to find image store with ID: " + id);
}
if (url != null) {
if (!imageStoreVO.isReadonly()) {
throw new InvalidParameterValueException("Image store must be set to read-only (maintenance) state before its URL can be changed. " +
"Please set readOnly=true on the image store first.");
}
imageStoreVO.setUrl(url);
}
if (com.cloud.utils.StringUtils.isNotBlank(name)) {
imageStoreVO.setName(name);
}
Expand All @@ -4156,7 +4182,7 @@

@Override
public ImageStore updateImageStoreStatus(Long id, Boolean readonly) {
return updateImageStoreStatus(id, null, readonly, null);
return updateImageStoreStatus(id, null, readonly, null, null);
}

/**
Expand Down
Loading