-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add config keys for controlling public/private template secondary storage replica counts #12877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
40b9e4d
f997444
0708236
e5bfeab
6dbeb52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,8 @@ | |
| public interface TemplateManager { | ||
| static final String AllowPublicUserTemplatesCK = "allow.public.user.templates"; | ||
| static final String TemplatePreloaderPoolSizeCK = "template.preloader.pool.size"; | ||
| static final String PublicTemplateSecStorageCopyCK = "public.template.secstorage.copy"; | ||
| static final String PrivateTemplateSecStorageCopyCK = "private.template.secstorage.copy"; | ||
|
Damans227 marked this conversation as resolved.
Outdated
|
||
|
|
||
| static final ConfigKey<Boolean> AllowPublicUserTemplates = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowPublicUserTemplatesCK, "true", | ||
| "If false, users will not be able to create public Templates.", true, ConfigKey.Scope.Account); | ||
|
|
@@ -64,6 +66,18 @@ public interface TemplateManager { | |
| true, | ||
| ConfigKey.Scope.Global); | ||
|
|
||
| ConfigKey<Integer> PublicTemplateSecStorageCopy = new ConfigKey<Integer>("Advanced", Integer.class, | ||
| PublicTemplateSecStorageCopyCK, "0", | ||
| "Maximum number of secondary storage pools to which a public template is copied. " + | ||
| "0 means copy to all secondary storage pools (default behavior).", | ||
| true, ConfigKey.Scope.Zone); | ||
|
|
||
| ConfigKey<Integer> PrivateTemplateSecStorageCopy = new ConfigKey<Integer>("Advanced", Integer.class, | ||
| PrivateTemplateSecStorageCopyCK, "1", | ||
| "Maximum number of secondary storage pools to which a private template is copied. " + | ||
| "Default is 1 to preserve existing behavior.", | ||
| true, ConfigKey.Scope.Zone); | ||
|
Comment on lines
+69
to
+79
|
||
|
|
||
| static final String VMWARE_TOOLS_ISO = "vmware-tools.iso"; | ||
| static final String XS_TOOLS_ISO = "xs-tools.iso"; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,11 +20,9 @@ | |
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
|
|
@@ -169,7 +167,7 @@ protected DataStore verifyHeuristicRulesForZone(VMTemplateVO template, Long zone | |
| return heuristicRuleHelper.getImageStoreIfThereIsHeuristicRule(zoneId, heuristicType, template); | ||
| } | ||
|
|
||
| protected boolean isZoneAndImageStoreAvailable(DataStore imageStore, Long zoneId, Set<Long> zoneSet, boolean isTemplatePrivate) { | ||
| protected boolean isZoneAndImageStoreAvailable(DataStore imageStore, Long zoneId, Map<Long, Integer> zoneCopyCount, int replicaLimit) { | ||
| if (zoneId == null) { | ||
| logger.warn(String.format("Zone ID is null, cannot allocate ISO/template in image store [%s].", imageStore)); | ||
| return false; | ||
|
|
@@ -191,19 +189,13 @@ protected boolean isZoneAndImageStoreAvailable(DataStore imageStore, Long zoneId | |
| return false; | ||
| } | ||
|
|
||
| if (zoneSet == null) { | ||
| logger.info(String.format("Zone set is null; therefore, the ISO/template should be allocated in every secondary storage of zone [%s].", zone)); | ||
| return true; | ||
| } | ||
|
|
||
| if (isTemplatePrivate && zoneSet.contains(zoneId)) { | ||
| logger.info(String.format("The template is private and it is already allocated in a secondary storage in zone [%s]; therefore, image store [%s] will be skipped.", | ||
| zone, imageStore)); | ||
| int currentCount = zoneCopyCount.getOrDefault(zoneId, 0); | ||
| if (replicaLimit > 0 && currentCount >= replicaLimit) { | ||
| logger.info("Replica limit of {} reached for zone [{}]; skipping image store [{}].", replicaLimit, zone, imageStore); | ||
|
DaanHoogland marked this conversation as resolved.
Outdated
|
||
| return false; | ||
| } | ||
|
|
||
| logger.info(String.format("Private template will be allocated in image store [%s] in zone [%s].", imageStore, zone)); | ||
| zoneSet.add(zoneId); | ||
| zoneCopyCount.put(zoneId, currentCount + 1); | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -212,12 +204,15 @@ protected boolean isZoneAndImageStoreAvailable(DataStore imageStore, Long zoneId | |
| * {@link TemplateProfile#getZoneIdList()}. | ||
| */ | ||
| protected void postUploadAllocation(List<DataStore> imageStores, VMTemplateVO template, List<TemplateOrVolumePostUploadCommand> payloads) { | ||
|
Comment on lines
208
to
212
|
||
| Set<Long> zoneSet = new HashSet<>(); | ||
| int replicaLimit = isPrivateTemplate(template) | ||
| ? TemplateManager.PrivateTemplateSecStorageCopy.value() | ||
| : TemplateManager.PublicTemplateSecStorageCopy.value(); | ||
| Map<Long, Integer> zoneCopyCount = new HashMap<>(); | ||
|
DaanHoogland marked this conversation as resolved.
Outdated
|
||
| Collections.shuffle(imageStores); | ||
| for (DataStore imageStore : imageStores) { | ||
| Long zoneId_is = imageStore.getScope().getScopeId(); | ||
|
|
||
| if (!isZoneAndImageStoreAvailable(imageStore, zoneId_is, zoneSet, isPrivateTemplate(template))) { | ||
| if (!isZoneAndImageStoreAvailable(imageStore, zoneId_is, zoneCopyCount, replicaLimit)) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.