mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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
This commit is contained in:
parent
aee7bb9e34
commit
089e9647f1
@ -27,7 +27,11 @@ import org.apache.cloudstack.framework.config.ConfigKey;
|
|||||||
|
|
||||||
public interface ResourceLimitService {
|
public interface ResourceLimitService {
|
||||||
|
|
||||||
static final ConfigKey<Long> ResourceCountCheckInterval = new ConfigKey<Long>("Advanced", Long.class, "resourcecount.check.interval", "300",
|
static final ConfigKey<Long> MaxAccountSecondaryStorage = new ConfigKey<>("Account Defaults", Long.class, "max.account.secondary.storage", "400",
|
||||||
|
"The default maximum secondary storage space (in GiB) that can be used for an account", false);
|
||||||
|
static final ConfigKey<Long> MaxProjectSecondaryStorage = new ConfigKey<>("Project Defaults", Long.class, "max.project.secondary.storage", "400",
|
||||||
|
"The default maximum secondary storage space (in GiB) that can be used for a project", false);
|
||||||
|
static final ConfigKey<Long> ResourceCountCheckInterval = new ConfigKey<>("Advanced", Long.class, "resourcecount.check.interval", "300",
|
||||||
"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);
|
"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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public class TemplateOrVolumePostUploadCommand {
|
|||||||
|
|
||||||
String description;
|
String description;
|
||||||
|
|
||||||
private String defaultMaxAccountSecondaryStorage;
|
private long defaultMaxSecondaryStorageInGB;
|
||||||
|
|
||||||
private long processTimeout;
|
private long processTimeout;
|
||||||
|
|
||||||
@ -185,12 +185,12 @@ public class TemplateOrVolumePostUploadCommand {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultMaxAccountSecondaryStorage(String defaultMaxAccountSecondaryStorage) {
|
public void setDefaultMaxSecondaryStorageInGB(long defaultMaxSecondaryStorageInGB) {
|
||||||
this.defaultMaxAccountSecondaryStorage = defaultMaxAccountSecondaryStorage;
|
this.defaultMaxSecondaryStorageInGB = defaultMaxSecondaryStorageInGB;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultMaxAccountSecondaryStorage() {
|
public long getDefaultMaxSecondaryStorageInGB() {
|
||||||
return defaultMaxAccountSecondaryStorage;
|
return defaultMaxSecondaryStorageInGB;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccountId(long accountId) {
|
public void setAccountId(long accountId) {
|
||||||
|
|||||||
@ -1361,14 +1361,6 @@ public enum Config {
|
|||||||
"200",
|
"200",
|
||||||
"The default maximum primary storage space (in GiB) that can be used for an account",
|
"The default maximum primary storage space (in GiB) that can be used for an account",
|
||||||
null),
|
null),
|
||||||
DefaultMaxAccountSecondaryStorage(
|
|
||||||
"Account Defaults",
|
|
||||||
ManagementServer.class,
|
|
||||||
Long.class,
|
|
||||||
"max.account.secondary.storage",
|
|
||||||
"400",
|
|
||||||
"The default maximum secondary storage space (in GiB) that can be used for an account",
|
|
||||||
null),
|
|
||||||
|
|
||||||
//disabling lb as cluster sync does not work with distributed cluster
|
//disabling lb as cluster sync does not work with distributed cluster
|
||||||
SubDomainNetworkAccess(
|
SubDomainNetworkAccess(
|
||||||
@ -1497,14 +1489,6 @@ public enum Config {
|
|||||||
"200",
|
"200",
|
||||||
"The default maximum primary storage space (in GiB) that can be used for an project",
|
"The default maximum primary storage space (in GiB) that can be used for an project",
|
||||||
null),
|
null),
|
||||||
DefaultMaxProjectSecondaryStorage(
|
|
||||||
"Project Defaults",
|
|
||||||
ManagementServer.class,
|
|
||||||
Long.class,
|
|
||||||
"max.project.secondary.storage",
|
|
||||||
"400",
|
|
||||||
"The default maximum secondary storage space (in GiB) that can be used for an project",
|
|
||||||
null),
|
|
||||||
|
|
||||||
ProjectInviteRequired(
|
ProjectInviteRequired(
|
||||||
"Project Defaults",
|
"Project Defaults",
|
||||||
|
|||||||
@ -226,7 +226,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
|||||||
projectResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectCpus.key())));
|
projectResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectCpus.key())));
|
||||||
projectResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectMemory.key())));
|
projectResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectMemory.key())));
|
||||||
projectResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPrimaryStorage.key())));
|
projectResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPrimaryStorage.key())));
|
||||||
projectResourceLimitMap.put(Resource.ResourceType.secondary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectSecondaryStorage.key())));
|
projectResourceLimitMap.put(Resource.ResourceType.secondary_storage, MaxProjectSecondaryStorage.value());
|
||||||
|
|
||||||
accountResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key())));
|
accountResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key())));
|
||||||
accountResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key())));
|
accountResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key())));
|
||||||
@ -238,7 +238,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
|||||||
accountResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountCpus.key())));
|
accountResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountCpus.key())));
|
||||||
accountResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountMemory.key())));
|
accountResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountMemory.key())));
|
||||||
accountResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPrimaryStorage.key())));
|
accountResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPrimaryStorage.key())));
|
||||||
accountResourceLimitMap.put(Resource.ResourceType.secondary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key())));
|
accountResourceLimitMap.put(Resource.ResourceType.secondary_storage, MaxAccountSecondaryStorage.value());
|
||||||
|
|
||||||
domainResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPublicIPs.key())));
|
domainResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPublicIPs.key())));
|
||||||
domainResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSnapshots.key())));
|
domainResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSnapshots.key())));
|
||||||
@ -1100,7 +1100,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigKey<?>[] getConfigKeys() {
|
public ConfigKey<?>[] getConfigKeys() {
|
||||||
return new ConfigKey<?>[] {ResourceCountCheckInterval};
|
return new ConfigKey<?>[] {ResourceCountCheckInterval, MaxAccountSecondaryStorage, MaxProjectSecondaryStorage};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class ResourceCountCheckTask extends ManagedContextRunnable {
|
protected class ResourceCountCheckTask extends ManagedContextRunnable {
|
||||||
|
|||||||
@ -456,8 +456,13 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||||||
//using the existing max upload size configuration
|
//using the existing max upload size configuration
|
||||||
command.setProcessTimeout(NumbersUtil.parseLong(_configDao.getValue("vmware.package.ova.timeout"), 3600));
|
command.setProcessTimeout(NumbersUtil.parseLong(_configDao.getValue("vmware.package.ova.timeout"), 3600));
|
||||||
command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
|
command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
|
||||||
command.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
|
|
||||||
command.setAccountId(vol.getAccountId());
|
command.setAccountId(vol.getAccountId());
|
||||||
|
Account account = _accountDao.findById(vol.getAccountId());
|
||||||
|
if (account.getType().equals(Account.Type.PROJECT)) {
|
||||||
|
command.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxProjectSecondaryStorage.value());
|
||||||
|
} else {
|
||||||
|
command.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxAccountSecondaryStorage.value());
|
||||||
|
}
|
||||||
Gson gson = new GsonBuilder().create();
|
Gson gson = new GsonBuilder().create();
|
||||||
String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
|
String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
|
||||||
response.setMetadata(metadata);
|
response.setMetadata(metadata);
|
||||||
|
|||||||
@ -93,6 +93,7 @@ import com.cloud.storage.dao.VMTemplateZoneDao;
|
|||||||
import com.cloud.storage.download.DownloadMonitor;
|
import com.cloud.storage.download.DownloadMonitor;
|
||||||
import com.cloud.template.VirtualMachineTemplate.State;
|
import com.cloud.template.VirtualMachineTemplate.State;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
|
import com.cloud.user.ResourceLimitService;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.UriUtils;
|
import com.cloud.utils.UriUtils;
|
||||||
import com.cloud.utils.db.DB;
|
import com.cloud.utils.db.DB;
|
||||||
@ -398,8 +399,13 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||||||
templateOnStore.getDataStore().getRole().toString());
|
templateOnStore.getDataStore().getRole().toString());
|
||||||
//using the existing max template size configuration
|
//using the existing max template size configuration
|
||||||
payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key()));
|
payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key()));
|
||||||
payload.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
|
|
||||||
payload.setAccountId(template.getAccountId());
|
payload.setAccountId(template.getAccountId());
|
||||||
|
Account account = _accountDao.findById(template.getAccountId());
|
||||||
|
if (account.getType().equals(Account.Type.PROJECT)) {
|
||||||
|
payload.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxProjectSecondaryStorage.value());
|
||||||
|
} else {
|
||||||
|
payload.setDefaultMaxSecondaryStorageInGB(ResourceLimitService.MaxAccountSecondaryStorage.value());
|
||||||
|
}
|
||||||
payload.setRemoteEndPoint(ep.getPublicAddr());
|
payload.setRemoteEndPoint(ep.getPublicAddr());
|
||||||
payload.setRequiresHvm(template.requiresHvm());
|
payload.setRequiresHvm(template.requiresHvm());
|
||||||
payload.setDescription(template.getDisplayText());
|
payload.setDescription(template.getDisplayText());
|
||||||
|
|||||||
@ -3275,12 +3275,12 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||||||
"accountTemplateDirSize: " + accountTemplateDirSize + " accountSnapshotDirSize: " + accountSnapshotDirSize + " accountVolumeDirSize: " + accountVolumeDirSize);
|
"accountTemplateDirSize: " + accountTemplateDirSize + " accountSnapshotDirSize: " + accountSnapshotDirSize + " accountVolumeDirSize: " + accountVolumeDirSize);
|
||||||
|
|
||||||
int accountDirSizeInGB = getSizeInGB(accountTemplateDirSize + accountSnapshotDirSize + accountVolumeDirSize);
|
int accountDirSizeInGB = getSizeInGB(accountTemplateDirSize + accountSnapshotDirSize + accountVolumeDirSize);
|
||||||
int defaultMaxAccountSecondaryStorageInGB = Integer.parseInt(cmd.getDefaultMaxAccountSecondaryStorage());
|
long defaultMaxSecondaryStorageInGB = cmd.getDefaultMaxSecondaryStorageInGB();
|
||||||
|
|
||||||
if (defaultMaxAccountSecondaryStorageInGB != Resource.RESOURCE_UNLIMITED && (accountDirSizeInGB + contentLengthInGB) > defaultMaxAccountSecondaryStorageInGB) {
|
if (defaultMaxSecondaryStorageInGB != Resource.RESOURCE_UNLIMITED && (accountDirSizeInGB + contentLengthInGB) > defaultMaxSecondaryStorageInGB) {
|
||||||
s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxAccountSecondaryStorageInGB: " + defaultMaxAccountSecondaryStorageInGB + " contentLengthInGB:"
|
s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxSecondaryStorageInGB: " + defaultMaxSecondaryStorageInGB + " contentLengthInGB:"
|
||||||
+ contentLengthInGB); // extra attention
|
+ contentLengthInGB); // extra attention
|
||||||
String errorMessage = "Maximum number of resources of type secondary_storage for account has exceeded";
|
String errorMessage = "Maximum number of resources of type secondary_storage for account/project has exceeded";
|
||||||
updateStateMapWithError(cmd.getEntityUUID(), errorMessage);
|
updateStateMapWithError(cmd.getEntityUUID(), errorMessage);
|
||||||
throw new InvalidParameterValueException(errorMessage);
|
throw new InvalidParameterValueException(errorMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user