3737import org .apache .cloudstack .annotation .dao .AnnotationDao ;
3838import org .apache .cloudstack .api .ApiCommandResourceType ;
3939import org .apache .cloudstack .api .command .user .iso .DeleteIsoCmd ;
40- import org .apache .cloudstack .api .command .user .iso .GetUploadParamsForIsoCmd ;
4140import org .apache .cloudstack .api .command .user .iso .RegisterIsoCmd ;
4241import org .apache .cloudstack .api .command .user .template .DeleteTemplateCmd ;
43- import org .apache .cloudstack .api .command .user .template .GetUploadParamsForTemplateCmd ;
4442import org .apache .cloudstack .api .command .user .template .RegisterTemplateCmd ;
4543import org .apache .cloudstack .context .CallContext ;
4644import org .apache .cloudstack .direct .download .DirectDownloadManager ;
6664import org .apache .cloudstack .storage .datastore .db .TemplateDataStoreVO ;
6765import org .apache .cloudstack .storage .heuristics .HeuristicRuleHelper ;
6866import org .apache .cloudstack .storage .image .datastore .ImageStoreEntity ;
67+ import org .apache .cloudstack .utils .bytescale .ByteScaleUtils ;
6968import org .apache .cloudstack .utils .security .DigestHelper ;
7069import org .apache .commons .collections .CollectionUtils ;
7170
@@ -217,19 +216,6 @@ public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationExce
217216 profile .setSize (templateSize );
218217 }
219218 profile .setUrl (url );
220- // Check that the resource limit for secondary storage won't be exceeded
221- _resourceLimitMgr .checkResourceLimit (_accountMgr .getAccount (cmd .getEntityOwnerId ()),
222- ResourceType .secondary_storage ,
223- UriUtils .getRemoteSize (url , followRedirects ));
224- return profile ;
225- }
226-
227- @ Override
228- public TemplateProfile prepare (GetUploadParamsForIsoCmd cmd ) throws ResourceAllocationException {
229- TemplateProfile profile = super .prepare (cmd );
230-
231- // Check that the resource limit for secondary storage won't be exceeded
232- _resourceLimitMgr .checkResourceLimit (_accountMgr .getAccount (cmd .getEntityOwnerId ()), ResourceType .secondary_storage );
233219 return profile ;
234220 }
235221
@@ -247,19 +233,7 @@ public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocatio
247233 profile .setSize (templateSize );
248234 }
249235 profile .setUrl (url );
250- // Check that the resource limit for secondary storage won't be exceeded
251- _resourceLimitMgr .checkResourceLimit (_accountMgr .getAccount (cmd .getEntityOwnerId ()),
252- ResourceType .secondary_storage ,
253- UriUtils .getRemoteSize (url , followRedirects ));
254- return profile ;
255- }
256-
257- @ Override
258- public TemplateProfile prepare (GetUploadParamsForTemplateCmd cmd ) throws ResourceAllocationException {
259- TemplateProfile profile = super .prepare (cmd );
260236
261- // Check that the resource limit for secondary storage won't be exceeded
262- _resourceLimitMgr .checkResourceLimit (_accountMgr .getAccount (cmd .getEntityOwnerId ()), ResourceType .secondary_storage );
263237 return profile ;
264238 }
265239
@@ -287,7 +261,6 @@ public VMTemplateVO create(TemplateProfile profile) {
287261 persistDirectDownloadTemplate (template .getId (), profile .getSize ());
288262 }
289263
290- _resourceLimitMgr .incrementResourceCount (profile .getAccountId (), ResourceType .template );
291264 return template ;
292265 }
293266
@@ -434,7 +407,7 @@ public List<TemplateOrVolumePostUploadCommand> doInTransaction(TransactionStatus
434407 if (payloads .isEmpty ()) {
435408 throw new CloudRuntimeException ("unable to find zone or an image store with enough capacity" );
436409 }
437- _resourceLimitMgr . incrementResourceCount ( profile . getAccountId (), ResourceType . template );
410+
438411 return payloads ;
439412 }
440413 });
@@ -477,7 +450,7 @@ private void postUploadAllocation(List<DataStore> imageStores, VMTemplateVO temp
477450 Account account = _accountDao .findById (accountId );
478451 Domain domain = _domainDao .findById (account .getDomainId ());
479452
480- payload .setDefaultMaxSecondaryStorageInGB (_resourceLimitMgr .findCorrectResourceLimitForAccountAndDomain (account , domain , ResourceType .secondary_storage , null ));
453+ payload .setDefaultMaxSecondaryStorageInGB (ByteScaleUtils . bytesToGibibytes ( _resourceLimitMgr .findCorrectResourceLimitForAccountAndDomain (account , domain , ResourceType .secondary_storage , null ) ));
481454 payload .setAccountId (accountId );
482455 payload .setRemoteEndPoint (ep .getPublicAddr ());
483456 payload .setRequiresHvm (template .requiresHvm ());
@@ -543,8 +516,8 @@ protected Void createTemplateAsyncCallBack(AsyncCallbackDispatcher<HypervisorTem
543516 UsageEventUtils .publishUsageEvent (etype , template .getAccountId (), -1 , template .getId (), template .getName (), null , null , physicalSize ,
544517 template .getSize (), VirtualMachineTemplate .class .getName (), template .getUuid ());
545518 }
546- _resourceLimitMgr .incrementResourceCount (accountId , ResourceType .secondary_storage , template .getSize ());
547519 }
520+ _resourceLimitMgr .recalculateResourceCount (accountId , tmplt .getDomainId (), ResourceType .secondary_storage .getOrdinal ());
548521 }
549522
550523 return null ;
0 commit comments