Skip to content
Merged
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
6 changes: 5 additions & 1 deletion api/src/main/java/com/cloud/user/ResourceLimitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

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);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class TemplateOrVolumePostUploadCommand {

String description;

private String defaultMaxAccountSecondaryStorage;
private long defaultMaxSecondaryStorageInGB;

private long processTimeout;

Expand Down Expand Up @@ -185,12 +185,12 @@ public void setDescription(String description) {
this.description = description;
}

public void setDefaultMaxAccountSecondaryStorage(String defaultMaxAccountSecondaryStorage) {
this.defaultMaxAccountSecondaryStorage = defaultMaxAccountSecondaryStorage;
public void setDefaultMaxSecondaryStorageInGB(long defaultMaxSecondaryStorageInGB) {
this.defaultMaxSecondaryStorageInGB = defaultMaxSecondaryStorageInGB;
}

public String getDefaultMaxAccountSecondaryStorage() {
return defaultMaxAccountSecondaryStorage;
public long getDefaultMaxSecondaryStorageInGB() {
return defaultMaxSecondaryStorageInGB;
}

public void setAccountId(long accountId) {
Expand Down
16 changes: 0 additions & 16 deletions server/src/main/java/com/cloud/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -1361,14 +1361,6 @@ public enum Config {
"200",
"The default maximum primary storage space (in GiB) that can be used for an account",
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
SubDomainNetworkAccess(
Expand Down Expand Up @@ -1497,14 +1489,6 @@ public enum Config {
"200",
"The default maximum primary storage space (in GiB) that can be used for an project",
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(
"Project Defaults",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
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.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.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key())));
Expand All @@ -238,7 +238,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
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.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.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSnapshots.key())));
Expand Down Expand Up @@ -1100,7 +1100,7 @@ public String getConfigComponentName() {

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {ResourceCountCheckInterval};
return new ConfigKey<?>[] {ResourceCountCheckInterval, MaxAccountSecondaryStorage, MaxProjectSecondaryStorage};
}

protected class ResourceCountCheckTask extends ManagedContextRunnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,13 @@ public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws
//using the existing max upload size configuration
command.setProcessTimeout(NumbersUtil.parseLong(_configDao.getValue("vmware.package.ova.timeout"), 3600));
command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
command.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
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();
String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
response.setMetadata(metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import com.cloud.storage.download.DownloadMonitor;
import com.cloud.template.VirtualMachineTemplate.State;
import com.cloud.user.Account;
import com.cloud.user.ResourceLimitService;
import com.cloud.utils.Pair;
import com.cloud.utils.UriUtils;
import com.cloud.utils.db.DB;
Expand Down Expand Up @@ -398,8 +399,13 @@ public List<TemplateOrVolumePostUploadCommand> doInTransaction(TransactionStatus
templateOnStore.getDataStore().getRole().toString());
//using the existing max template size configuration
payload.setMaxUploadSize(_configDao.getValue(Config.MaxTemplateAndIsoSize.key()));
payload.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
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.setRequiresHvm(template.requiresHvm());
payload.setDescription(template.getDisplayText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3275,12 +3275,12 @@ private synchronized void checkSecondaryStorageResourceLimit(TemplateOrVolumePos
"accountTemplateDirSize: " + accountTemplateDirSize + " accountSnapshotDirSize: " + accountSnapshotDirSize + " accountVolumeDirSize: " + 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) {
s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxAccountSecondaryStorageInGB: " + defaultMaxAccountSecondaryStorageInGB + " contentLengthInGB:"
if (defaultMaxSecondaryStorageInGB != Resource.RESOURCE_UNLIMITED && (accountDirSizeInGB + contentLengthInGB) > defaultMaxSecondaryStorageInGB) {
s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxSecondaryStorageInGB: " + defaultMaxSecondaryStorageInGB + " contentLengthInGB:"
+ 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);
throw new InvalidParameterValueException(errorMessage);
}
Expand Down