3535
3636import javax .inject .Inject ;
3737
38+ import com .cloud .resourcelimit .CheckedReservation ;
3839import org .apache .cloudstack .api .ApiConstants ;
3940import org .apache .cloudstack .api .ApiErrorCode ;
4041import org .apache .cloudstack .api .InternalIdentity ;
8788import org .apache .cloudstack .framework .jobs .impl .OutcomeImpl ;
8889import org .apache .cloudstack .framework .jobs .impl .VmWorkJobVO ;
8990import org .apache .cloudstack .jobs .JobInfo ;
91+ import org .apache .cloudstack .reservation .dao .ReservationDao ;
9092import org .apache .cloudstack .resourcedetail .DiskOfferingDetailVO ;
9193import org .apache .cloudstack .resourcedetail .SnapshotPolicyDetailVO ;
9294import org .apache .cloudstack .resourcedetail .dao .DiskOfferingDetailsDao ;
@@ -354,6 +356,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
354356 private BackupDao backupDao ;
355357 @ Inject
356358 HostPodDao podDao ;
359+ @ Inject
360+ private ReservationDao reservationDao ;
357361
358362
359363 protected Gson _gson ;
@@ -918,8 +922,12 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
918922
919923 Storage .ProvisioningType provisioningType = diskOffering .getProvisioningType ();
920924
921- // Check that the resource limit for volume & primary storage won't be exceeded
922- _resourceLimitMgr .checkVolumeResourceLimit (owner ,displayVolume , size , diskOffering );
925+ List <String > tags = _resourceLimitMgr .getResourceLimitStorageTagsForResourceCountOperation (displayVolume , diskOffering );
926+ if (tags .size () == 1 && tags .get (0 ) == null ) {
927+ tags = new ArrayList <>();
928+ }
929+ try (CheckedReservation volumeReservation = new CheckedReservation (owner , ResourceType .volume , null , tags , 1L , reservationDao , _resourceLimitMgr );
930+ CheckedReservation primaryStorageReservation = new CheckedReservation (owner , ResourceType .primary_storage , null , tags , size , reservationDao , _resourceLimitMgr )) {
923931
924932 // Verify that zone exists
925933 DataCenterVO zone = _dcDao .findById (zoneId );
@@ -942,6 +950,10 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
942950
943951 return commitVolume (cmd , caller , owner , displayVolume , zoneId , diskOfferingId , provisioningType , size , minIops , maxIops , parentVolume , userSpecifiedName ,
944952 _uuidMgr .generateUuid (Volume .class , cmd .getCustomId ()), details );
953+ } catch (Exception e ) {
954+ logger .error (e );
955+ throw new RuntimeException (e );
956+ }
945957 }
946958
947959 @ Override
0 commit comments