Skip to content

Commit 11aecf4

Browse files
committed
updated max project default settings to ConfigKey implementation. Also split unit test in ResourceManagerImplTest into multiple smaller tests
1 parent c562dba commit 11aecf4

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public interface ResourceLimitService {
4343
"A comma-separated list of tags for host resource limits", true);
4444
static final ConfigKey<String> ResourceLimitStorageTags = new ConfigKey<>("Advanced", String.class, "resource.limit.storage.tags", "",
4545
"A comma-separated list of tags for storage resource limits", true);
46+
static final ConfigKey<Long> DefaultMaxAccountProjects = new ConfigKey<>("Account Defaults",Long.class,"max.account.projects","10",
47+
"The default maximum number of projects that can be created for an account",false);
48+
static final ConfigKey<Long> DefaultMaxDomainProjects = new ConfigKey<>("Domain Defaults",Long.class,"max.domain.projects","50",
49+
"The default maximum number of projects that can be created for a domain",false);
4650

4751
static final List<ResourceType> HostTagsSupportingTypes = List.of(ResourceType.user_vm, ResourceType.cpu, ResourceType.memory);
4852
static final List<ResourceType> StorageTagsSupportingTypes = List.of(ResourceType.volume, ResourceType.primary_storage);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
288288
accountResourceLimitMap.put(Resource.ResourceType.memory.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountMemory.key())));
289289
accountResourceLimitMap.put(Resource.ResourceType.primary_storage.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPrimaryStorage.key())));
290290
accountResourceLimitMap.put(Resource.ResourceType.secondary_storage.name(), MaxAccountSecondaryStorage.value());
291-
accountResourceLimitMap.put(Resource.ResourceType.project.name(),Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountProjects.key())));
291+
accountResourceLimitMap.put(Resource.ResourceType.project.name(), DefaultMaxAccountProjects.value());
292292

293293
domainResourceLimitMap.put(Resource.ResourceType.public_ip.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPublicIPs.key())));
294294
domainResourceLimitMap.put(Resource.ResourceType.snapshot.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSnapshots.key())));
@@ -301,7 +301,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
301301
domainResourceLimitMap.put(Resource.ResourceType.memory.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainMemory.key())));
302302
domainResourceLimitMap.put(Resource.ResourceType.primary_storage.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPrimaryStorage.key())));
303303
domainResourceLimitMap.put(Resource.ResourceType.secondary_storage.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSecondaryStorage.key())));
304-
domainResourceLimitMap.put(Resource.ResourceType.project.name(),Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainProjects.key())));
304+
domainResourceLimitMap.put(Resource.ResourceType.project.name(), DefaultMaxDomainProjects.value());
305305
} catch (NumberFormatException e) {
306306
logger.error("NumberFormatException during configuration", e);
307307
throw new ConfigurationException("Configuration failed due to NumberFormatException, see log for the stacktrace");
@@ -2111,7 +2111,9 @@ public ConfigKey<?>[] getConfigKeys() {
21112111
MaxAccountSecondaryStorage,
21122112
MaxProjectSecondaryStorage,
21132113
ResourceLimitHostTags,
2114-
ResourceLimitStorageTags
2114+
ResourceLimitStorageTags,
2115+
DefaultMaxAccountProjects,
2116+
DefaultMaxDomainProjects
21152117
};
21162118
}
21172119

server/src/test/java/com/cloud/resourcelimit/ResourceLimitManagerImplTest.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -509,46 +509,64 @@ public void testFindCorrectResourceLimitForDomain() {
509509
}
510510

511511
@Test
512-
public void testFindCorrectResourceLimitForDomainProjects() {
512+
public void testResourceUnlimitedForDomainProjects() {
513513
DomainVO domain = Mockito.mock(DomainVO.class);
514514
Mockito.when(domain.getId()).thenReturn(1L);
515+
515516
long result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.project,
516517
hostTags.get(0));
517518
Assert.assertEquals(Resource.RESOURCE_UNLIMITED, result);
519+
}
520+
@Test
521+
public void testSpecificLimitForDomainProjects() {
522+
DomainVO domain = Mockito.mock(DomainVO.class);
523+
Mockito.when(domain.getId()).thenReturn(2L);
524+
Mockito.when(domain.getParent()).thenReturn(null);
518525

519-
Mockito.when(domain.getId()).thenReturn(2L);
520-
Mockito.when(domain.getParent()).thenReturn(null);
521-
ResourceLimitVO limit = new ResourceLimitVO();
522-
limit.setMax(100L);
523-
Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(2L, Resource.ResourceOwnerType.Domain,
524-
Resource.ResourceType.project, hostTags.get(0))).thenReturn(limit);
525-
result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.project,
526-
hostTags.get(0));
527-
Assert.assertEquals(100L, result);
526+
ResourceLimitVO limit = new ResourceLimitVO();
527+
limit.setMax(100L);
528+
Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(2L, Resource.ResourceOwnerType.Domain, Resource.ResourceType.project, hostTags.get(0))).thenReturn(limit);
528529

530+
long result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.project, hostTags.get(0));
531+
Assert.assertEquals(100L, result);
532+
}
533+
534+
@Test
535+
public void testParentDomainLimitForDomainProjects() {
536+
DomainVO domain = Mockito.mock(DomainVO.class);
529537
Mockito.when(domain.getId()).thenReturn(3L);
538+
530539
DomainVO parentDomain = Mockito.mock(DomainVO.class);
531540
Mockito.when(domain.getParent()).thenReturn(5L);
532541
Mockito.when(domainDao.findById(5L)).thenReturn(parentDomain);
533-
limit = new ResourceLimitVO();
542+
543+
ResourceLimitVO limit = new ResourceLimitVO();
534544
limit.setMax(200L);
535545
Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(3L, Resource.ResourceOwnerType.Domain,
536546
Resource.ResourceType.project, hostTags.get(0))).thenReturn(null);
537547
Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(5L, Resource.ResourceOwnerType.Domain,
538548
Resource.ResourceType.project, hostTags.get(0))).thenReturn(limit);
539-
result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.project,
549+
550+
long result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.project,
540551
hostTags.get(0));
541552
Assert.assertEquals(200L, result);
553+
}
542554

543-
long defaultDomainProjectsMax = 250L;
555+
@Test
556+
public void testDefaultDomainProjectLimit() {
557+
DomainVO domain = Mockito.mock(DomainVO.class);
544558
Mockito.when(domain.getId()).thenReturn(4L);
545559
Mockito.when(domain.getParent()).thenReturn(null);
560+
561+
long defaultDomainProjectsMax = 250L;
546562
Map<String, Long> domainResourceLimitMap = new HashMap<>();
547563
domainResourceLimitMap.put(Resource.ResourceType.project.name(), defaultDomainProjectsMax);
548564
resourceLimitManager.domainResourceLimitMap = domainResourceLimitMap;
565+
549566
Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(4L, Resource.ResourceOwnerType.Domain,
550567
Resource.ResourceType.project, hostTags.get(0))).thenReturn(null);
551-
result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.project,
568+
569+
long result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.project,
552570
hostTags.get(0));
553571
Assert.assertEquals(defaultDomainProjectsMax, result);
554572
}

0 commit comments

Comments
 (0)