Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -28,6 +28,9 @@
>

<bean id="accountGuestVlanMapDaoImpl" class="com.cloud.network.dao.AccountGuestVlanMapDaoImpl" />
<bean id="accountDetailsDaoImpl" class="com.cloud.user.AccountDetailsDaoImpl" />
<bean id="domainDaoImpl" class="com.cloud.domain.dao.DomainDaoImpl" />
<bean id="domainDetailsDaoImpl" class="com.cloud.domain.dao.DomainDetailsDaoImpl" />
<bean id="clusterDaoImpl" class="com.cloud.dc.dao.ClusterDaoImpl" />
<bean id="clusterDetailsDaoImpl" class="com.cloud.dc.ClusterDetailsDaoImpl" />
<bean id="dataCenterDaoImpl" class="com.cloud.dc.dao.DataCenterDaoImpl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public boolean stop() {
*/
@Override
public boolean isQuotaEmailTypeEnabledForAccount(AccountVO account, QuotaEmailTemplateTypes quotaEmailTemplateType) {
boolean quotaEmailsEnabled = QuotaConfig.QuotaEnableEmails.valueIn(account.getAccountId());
boolean quotaEmailsEnabled = _quotaManager.findConfigurationValue(account, QuotaConfig.QuotaEnableEmails);
if (!quotaEmailsEnabled) {
logger.debug("Configuration [{}] is disabled for account [{}]. Therefore, the account will not receive Quota email of type [{}].", QuotaConfig.QuotaEnableEmails.key(), account, quotaEmailTemplateType);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import com.cloud.user.AccountVO;
import com.cloud.utils.component.Manager;
import org.apache.cloudstack.framework.config.ConfigKey;

public interface QuotaManager extends Manager {

boolean calculateQuotaUsage();

boolean isLockable(AccountVO account);

boolean findConfigurationValue(AccountVO accountVO, ConfigKey<Boolean> key);

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import com.cloud.domain.DomainDetailVO;
import com.cloud.domain.dao.DomainDetailsDao;
import com.cloud.user.Account;
import com.cloud.user.AccountDetailVO;
import com.cloud.user.AccountDetailsDao;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.quota.activationrule.presetvariables.Configuration;
import org.apache.cloudstack.quota.activationrule.presetvariables.GenericPresetVariable;
Expand Down Expand Up @@ -89,6 +94,10 @@

@Inject
protected PresetVariableHelper presetVariableHelper;
@Inject
protected AccountDetailsDao accountDetailsDao;
@Inject
protected DomainDetailsDao domainDetailsDao;

private static TimeZone usageAggregationTimeZone = TimeZone.getTimeZone("GMT");
static final BigDecimal GiB_DECIMAL = BigDecimal.valueOf(ByteScaleUtils.GiB);
Expand Down Expand Up @@ -340,12 +349,41 @@
}

protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO usageRecord) {
if (Boolean.FALSE.equals(QuotaConfig.QuotaAccountEnabled.valueIn(accountVO.getAccountId()))) {
boolean calculateUsageRecord = findConfigurationValue(accountVO, QuotaConfig.QuotaAccountEnabled);

Check warning on line 352 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java#L352

Added line #L352 was not covered by tests
if (!calculateUsageRecord && usageRecord != null) {
logger.debug("Considering usage record [{}] as calculated and skipping it because account [{}] has the quota plugin disabled.",
usageRecord.toString(usageAggregationTimeZone), accountVO.reflectionToString());
return false;
}
return true;
return calculateUsageRecord;
}

Check warning on line 359 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java#L358-L359

Added lines #L358 - L359 were not covered by tests

@Override
public boolean findConfigurationValue(AccountVO accountVO, ConfigKey<Boolean> key) {
boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());

Check warning on line 365 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java#L362-L365

Added lines #L362 - L365 were not covered by tests
if (accountDetail != null) {
result = Boolean.TRUE.equals(Boolean.valueOf(accountDetail.getValue()));
logger.trace("Using value [{}] found in account [{}] settings to configuration [{}].", result, accountVO, key.key());
return result;

Check warning on line 369 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java#L367-L369

Added lines #L367 - L369 were not covered by tests
}

if (Boolean.parseBoolean(_configDao.getValue("enable.account.settings.for.domain"))) {
logger.trace("Searching for configuration [{}] of account [{}] in its domain [{}] settings.", key.key(), accountVO, accountVO.getDomainId());
DomainDetailVO domainDetail = domainDetailsDao.findDetail(accountVO.getDomainId(), key.key());

Check warning on line 374 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java#L373-L374

Added lines #L373 - L374 were not covered by tests
if (domainDetail != null) {
result = Boolean.TRUE.equals(Boolean.valueOf(domainDetail.getValue()));
logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
return result;

Check warning on line 378 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java#L376-L378

Added lines #L376 - L378 were not covered by tests
}
}
logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
return result;
}

Check warning on line 383 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java#L381-L383

Added lines #L381 - L383 were not covered by tests

protected String getConfigValueOrDefaultValue(ConfigKey<?> key) {
return ObjectUtils.defaultIfNull(_configDao.getValue(key.key()), key.defaultValue());

Check warning on line 386 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java#L385-L386

Added lines #L385 - L386 were not covered by tests
}

protected List<QuotaUsageVO> persistUsagesAndQuotaUsagesAndRetrievePersistedQuotaUsages(List<Pair<UsageVO, QuotaUsageVO>> pairsUsageAndQuotaUsage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDaoImpl;
import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
import org.apache.cloudstack.quota.vo.QuotaAccountVO;
import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO;
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -116,9 +115,6 @@ public void setup() throws IllegalAccessException, NoSuchFieldException, Configu
@Test
public void isQuotaEmailTypeEnabledForAccountTestConfigurationIsEnabledAndEmailIsConfiguredReturnConfiguredValue() {
boolean expectedValue = !QuotaConfig.QuotaEnableEmails.value();
QuotaEmailConfigurationVO quotaEmailConfigurationVoMock = Mockito.mock(QuotaEmailConfigurationVO.class);
Mockito.when(quotaEmailConfigurationVoMock.isEnabled()).thenReturn(expectedValue);
Mockito.doReturn(quotaEmailConfigurationVoMock).when(quotaEmailConfigurationDaoMock).findByAccountIdAndEmailTemplateType(Mockito.anyLong(), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class));

boolean result = quotaAlertManager.isQuotaEmailTypeEnabledForAccount(accountMock, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY);

Expand All @@ -129,6 +125,8 @@ public void isQuotaEmailTypeEnabledForAccountTestConfigurationIsEnabledAndEmailI
public void isQuotaEmailTypeEnabledForAccountTestConfigurationIsEnabledAndEmailIsNotConfiguredReturnDefaultValue() {
boolean defaultValue = QuotaConfig.QuotaEnableEmails.value();

Mockito.when(quotaManagerMock.findConfigurationValue(accountMock, QuotaConfig.QuotaEnableEmails)).thenReturn(true);

boolean result = quotaAlertManager.isQuotaEmailTypeEnabledForAccount(accountMock, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY);

Assert.assertEquals(defaultValue, result);
Expand Down
Loading