@@ -167,7 +167,13 @@ protected DataStore verifyHeuristicRulesForZone(VMTemplateVO template, Long zone
167167 return heuristicRuleHelper .getImageStoreIfThereIsHeuristicRule (zoneId , heuristicType , template );
168168 }
169169
170- protected boolean isZoneAndImageStoreAvailable (DataStore imageStore , Long zoneId , Map <Long , Integer > zoneCopyCount , int replicaLimit ) {
170+ protected int getSecStorageCopyLimit (VMTemplateVO template , long zoneId ) {
171+ return isPrivateTemplate (template )
172+ ? TemplateManager .PrivateTemplateSecStorageCopy .valueIn (zoneId )
173+ : TemplateManager .PublicTemplateSecStorageCopy .valueIn (zoneId );
174+ }
175+
176+ protected boolean isZoneAndImageStoreAvailable (DataStore imageStore , Long zoneId , Map <Long , Integer > zoneCopyCount , int copyLimit ) {
171177 if (zoneId == null ) {
172178 logger .warn (String .format ("Zone ID is null, cannot allocate ISO/template in image store [%s]." , imageStore ));
173179 return false ;
@@ -190,8 +196,8 @@ protected boolean isZoneAndImageStoreAvailable(DataStore imageStore, Long zoneId
190196 }
191197
192198 int currentCount = zoneCopyCount .getOrDefault (zoneId , 0 );
193- if (replicaLimit > 0 && currentCount >= replicaLimit ) {
194- logger .info ("Replica limit of {} reached for zone [{}]; skipping image store [{}]." , replicaLimit , zone , imageStore );
199+ if (copyLimit > 0 && currentCount >= copyLimit ) {
200+ logger .info ("Copy limit of {} reached for zone [{}]; skipping image store [{}]." , copyLimit , zone , imageStore );
195201 return false ;
196202 }
197203
@@ -204,16 +210,13 @@ protected boolean isZoneAndImageStoreAvailable(DataStore imageStore, Long zoneId
204210 * {@link TemplateProfile#getZoneIdList()}.
205211 */
206212 protected void postUploadAllocation (List <DataStore > imageStores , VMTemplateVO template , List <TemplateOrVolumePostUploadCommand > payloads ) {
207- boolean isPrivate = isPrivateTemplate (template );
208213 Map <Long , Integer > zoneCopyCount = new HashMap <>();
209214 Collections .shuffle (imageStores );
210215 for (DataStore imageStore : imageStores ) {
211216 Long zoneId_is = imageStore .getScope ().getScopeId ();
212- int replicaLimit = zoneId_is == null ? 0 : (isPrivate
213- ? TemplateManager .PrivateTemplateSecStorageCopy .valueIn (zoneId_is )
214- : TemplateManager .PublicTemplateSecStorageCopy .valueIn (zoneId_is ));
217+ int copyLimit = zoneId_is == null ? 0 : getSecStorageCopyLimit (template , zoneId_is );
215218
216- if (!isZoneAndImageStoreAvailable (imageStore , zoneId_is , zoneCopyCount , replicaLimit )) {
219+ if (!isZoneAndImageStoreAvailable (imageStore , zoneId_is , zoneCopyCount , copyLimit )) {
217220 continue ;
218221 }
219222
0 commit comments