Skip to content

Commit 089e964

Browse files
Fix global setting reference for max secondary storage (#6496)
* Fix global setting reference for max secondary storage usage based on account or project * Changed a variable naming * Replaced config enum usage with configkey class for global settings * Fixed grammar mistake * Fixed code smells
1 parent aee7bb9 commit 089e964

7 files changed

Lines changed: 30 additions & 31 deletions

File tree

api/src/main/java/com/cloud/user/ResourceLimitService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727

2828
public interface ResourceLimitService {
2929

30-
static final ConfigKey<Long> ResourceCountCheckInterval = new ConfigKey<Long>("Advanced", Long.class, "resourcecount.check.interval", "300",
30+
static final ConfigKey<Long> MaxAccountSecondaryStorage = new ConfigKey<>("Account Defaults", Long.class, "max.account.secondary.storage", "400",
31+
"The default maximum secondary storage space (in GiB) that can be used for an account", false);
32+
static final ConfigKey<Long> MaxProjectSecondaryStorage = new ConfigKey<>("Project Defaults", Long.class, "max.project.secondary.storage", "400",
33+
"The default maximum secondary storage space (in GiB) that can be used for a project", false);
34+
static final ConfigKey<Long> ResourceCountCheckInterval = new ConfigKey<>("Advanced", Long.class, "resourcecount.check.interval", "300",
3135
"Time (in seconds) to wait before running resource recalculation and fixing task. Default is 300 seconds, Setting this to 0 disables execution of the task", false);
3236

3337
/**

core/src/main/java/org/apache/cloudstack/storage/command/TemplateOrVolumePostUploadCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class TemplateOrVolumePostUploadCommand {
4949

5050
String description;
5151

52-
private String defaultMaxAccountSecondaryStorage;
52+
private long defaultMaxSecondaryStorageInGB;
5353

5454
private long processTimeout;
5555

@@ -185,12 +185,12 @@ public void setDescription(String description) {
185185
this.description = description;
186186
}
187187

188-
public void setDefaultMaxAccountSecondaryStorage(String defaultMaxAccountSecondaryStorage) {
189-
this.defaultMaxAccountSecondaryStorage = defaultMaxAccountSecondaryStorage;
188+
public void setDefaultMaxSecondaryStorageInGB(long defaultMaxSecondaryStorageInGB) {
189+
this.defaultMaxSecondaryStorageInGB = defaultMaxSecondaryStorageInGB;
190190
}
191191

192-
public String getDefaultMaxAccountSecondaryStorage() {
193-
return defaultMaxAccountSecondaryStorage;
192+
public long getDefaultMaxSecondaryStorageInGB() {
193+
return defaultMaxSecondaryStorageInGB;
194194
}
195195

196196
public void setAccountId(long accountId) {

server/src/main/java/com/cloud/configuration/Config.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,14 +1361,6 @@ public enum Config {
13611361
"200",
13621362
"The default maximum primary storage space (in GiB) that can be used for an account",
13631363
null),
1364-
DefaultMaxAccountSecondaryStorage(
1365-
"Account Defaults",
1366-
ManagementServer.class,
1367-
Long.class,
1368-
"max.account.secondary.storage",
1369-
"400",
1370-
"The default maximum secondary storage space (in GiB) that can be used for an account",
1371-
null),
13721364

13731365
//disabling lb as cluster sync does not work with distributed cluster
13741366
SubDomainNetworkAccess(
@@ -1497,14 +1489,6 @@ public enum Config {
14971489
"200",
14981490
"The default maximum primary storage space (in GiB) that can be used for an project",
14991491
null),
1500-
DefaultMaxProjectSecondaryStorage(
1501-
"Project Defaults",
1502-
ManagementServer.class,
1503-
Long.class,
1504-
"max.project.secondary.storage",
1505-
"400",
1506-
"The default maximum secondary storage space (in GiB) that can be used for an project",
1507-
null),
15081492

15091493
ProjectInviteRequired(
15101494
"Project Defaults",

server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
226226
projectResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectCpus.key())));
227227
projectResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectMemory.key())));
228228
projectResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPrimaryStorage.key())));
229-
projectResourceLimitMap.put(Resource.ResourceType.secondary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectSecondaryStorage.key())));
229+
projectResourceLimitMap.put(Resource.ResourceType.secondary_storage, MaxProjectSecondaryStorage.value());
230230

231231
accountResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key())));
232232
accountResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key())));
@@ -238,7 +238,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
238238
accountResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountCpus.key())));
239239
accountResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountMemory.key())));
240240
accountResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPrimaryStorage.key())));
241-
accountResourceLimitMap.put(Resource.ResourceType.secondary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key())));
241+
accountResourceLimitMap.put(Resource.ResourceType.secondary_storage, MaxAccountSecondaryStorage.value());
242242

243243
domainResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPublicIPs.key())));
244244
domainResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSnapshots.key())));
@@ -1100,7 +1100,7 @@ public String getConfigComponentName() {
11001100

11011101
@Override
11021102
public ConfigKey<?>[] getConfigKeys() {
1103-
return new ConfigKey<?>[] {ResourceCountCheckInterval};
1103+
return new ConfigKey<?>[] {ResourceCountCheckInterval, MaxAccountSecondaryStorage, MaxProjectSecondaryStorage};
11041104
}
11051105

11061106
protected class ResourceCountCheckTask extends ManagedContextRunnable {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,13 @@ public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws
456456
//using the existing max upload size configuration
457457
command.setProcessTimeout(NumbersUtil.parseLong(_configDao.getValue("vmware.package.ova.timeout"), 3600));
458458
command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
459-
command.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
460459
command.setAccountId(vol.getAccountId());
460+
Account account = _accountDao.findById(vol.getAccountId());
461+
if (account.getType().equals(Account.Type.PROJECT)) {
462+
command.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxProjectSecondaryStorage.value());
463+
} else {
464+
command.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxAccountSecondaryStorage.value());
465+
}
461466
Gson gson = new GsonBuilder().create();
462467
String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
463468
response.setMetadata(metadata);

server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
import com.cloud.storage.download.DownloadMonitor;
9494
import com.cloud.template.VirtualMachineTemplate.State;
9595
import com.cloud.user.Account;
96+
import com.cloud.user.ResourceLimitService;
9697
import com.cloud.utils.Pair;
9798
import com.cloud.utils.UriUtils;
9899
import com.cloud.utils.db.DB;
@@ -398,8 +399,13 @@ public List<TemplateOrVolumePostUploadCommand> doInTransaction(TransactionStatus
398399
templateOnStore.getDataStore().getRole().toString());
399400
//using the existing max template size configuration
400401
payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key()));
401-
payload.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
402402
payload.setAccountId(template.getAccountId());
403+
Account account = _accountDao.findById(template.getAccountId());
404+
if (account.getType().equals(Account.Type.PROJECT)) {
405+
payload.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxProjectSecondaryStorage.value());
406+
} else {
407+
payload.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxAccountSecondaryStorage.value());
408+
}
403409
payload.setRemoteEndPoint(ep.getPublicAddr());
404410
payload.setRequiresHvm(template.requiresHvm());
405411
payload.setDescription(template.getDisplayText());

services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,12 +3275,12 @@ private synchronized void checkSecondaryStorageResourceLimit(TemplateOrVolumePos
32753275
"accountTemplateDirSize: " + accountTemplateDirSize + " accountSnapshotDirSize: " + accountSnapshotDirSize + " accountVolumeDirSize: " + accountVolumeDirSize);
32763276

32773277
int accountDirSizeInGB = getSizeInGB(accountTemplateDirSize + accountSnapshotDirSize + accountVolumeDirSize);
3278-
int defaultMaxAccountSecondaryStorageInGB = Integer.parseInt(cmd.getDefaultMaxAccountSecondaryStorage());
3278+
long defaultMaxSecondaryStorageInGB = cmd.getDefaultMaxSecondaryStorageInGB();
32793279

3280-
if (defaultMaxAccountSecondaryStorageInGB != Resource.RESOURCE_UNLIMITED && (accountDirSizeInGB + contentLengthInGB) > defaultMaxAccountSecondaryStorageInGB) {
3281-
s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxAccountSecondaryStorageInGB: " + defaultMaxAccountSecondaryStorageInGB + " contentLengthInGB:"
3280+
if (defaultMaxSecondaryStorageInGB != Resource.RESOURCE_UNLIMITED && (accountDirSizeInGB + contentLengthInGB) > defaultMaxSecondaryStorageInGB) {
3281+
s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxSecondaryStorageInGB: " + defaultMaxSecondaryStorageInGB + " contentLengthInGB:"
32823282
+ contentLengthInGB); // extra attention
3283-
String errorMessage = "Maximum number of resources of type secondary_storage for account has exceeded";
3283+
String errorMessage = "Maximum number of resources of type secondary_storage for account/project has exceeded";
32843284
updateStateMapWithError(cmd.getEntityUUID(), errorMessage);
32853285
throw new InvalidParameterValueException(errorMessage);
32863286
}

0 commit comments

Comments
 (0)