@@ -49,6 +49,7 @@ public class CheckedReservation implements AutoCloseable {
4949
5050 ResourceLimitService resourceLimitService ;
5151 private final Account account ;
52+ private Long domainId ;
5253 private final ResourceType resourceType ;
5354 private Long amount ;
5455 private List <ResourceReservation > reservations ;
@@ -73,12 +74,12 @@ private void removeAllReservations() {
7374 this .reservations = null ;
7475 }
7576
76- protected void checkLimitAndPersistReservations (Account account , ResourceType resourceType , Long resourceId , List <String > resourceLimitTags , Long amount ) throws ResourceAllocationException {
77+ protected void checkLimitAndPersistReservations (Account account , Long domainId , ResourceType resourceType , Long resourceId , List <String > resourceLimitTags , Long amount ) throws ResourceAllocationException {
7778 try {
78- checkLimitAndPersistReservation (account , resourceType , resourceId , null , amount );
79+ checkLimitAndPersistReservation (account , domainId , resourceType , resourceId , null , amount );
7980 if (CollectionUtils .isNotEmpty (resourceLimitTags )) {
8081 for (String tag : resourceLimitTags ) {
81- checkLimitAndPersistReservation (account , resourceType , resourceId , tag , amount );
82+ checkLimitAndPersistReservation (account , domainId , resourceType , resourceId , tag , amount );
8283 }
8384 }
8485 } catch (ResourceAllocationException rae ) {
@@ -87,11 +88,11 @@ protected void checkLimitAndPersistReservations(Account account, ResourceType re
8788 }
8889 }
8990
90- protected void checkLimitAndPersistReservation (Account account , ResourceType resourceType , Long resourceId , String tag , Long amount ) throws ResourceAllocationException {
91+ protected void checkLimitAndPersistReservation (Account account , Long domainId , ResourceType resourceType , Long resourceId , String tag , Long amount ) throws ResourceAllocationException {
9192 if (amount > 0 ) {
92- resourceLimitService .checkResourceLimitWithTag (account , resourceType , tag , amount );
93+ resourceLimitService .checkResourceLimitWithTag (account , domainId , true , resourceType , tag , amount );
9394 }
94- ReservationVO reservationVO = new ReservationVO (account .getAccountId (), account . getDomainId () , resourceType , tag , amount );
95+ ReservationVO reservationVO = new ReservationVO (account .getAccountId (), domainId , resourceType , tag , amount );
9596 if (resourceId != null ) {
9697 reservationVO .setResourceId (resourceId );
9798 }
@@ -114,9 +115,20 @@ public CheckedReservation(Account account, ResourceType resourceType, List<Strin
114115 */
115116 public CheckedReservation (Account account , ResourceType resourceType , Long resourceId , List <String > resourceLimitTags , Long amount ,
116117 ReservationDao reservationDao , ResourceLimitService resourceLimitService ) throws ResourceAllocationException {
118+ this (account , account .getDomainId (), resourceType , resourceId , resourceLimitTags , amount , reservationDao , resourceLimitService );
119+ }
120+
121+ public CheckedReservation (Account account , Long domainId , ResourceType resourceType , Long resourceId , List <String > resourceLimitTags , Long amount ,
122+ ReservationDao reservationDao , ResourceLimitService resourceLimitService ) throws ResourceAllocationException {
117123 this .reservationDao = reservationDao ;
118124 this .resourceLimitService = resourceLimitService ;
119125 this .account = account ;
126+
127+ this .domainId = domainId ;
128+ if (domainId == null ) {
129+ this .domainId = account .getDomainId ();
130+ }
131+
120132 this .resourceType = resourceType ;
121133 this .amount = amount ;
122134 this .reservations = new ArrayList <>();
@@ -127,7 +139,7 @@ public CheckedReservation(Account account, ResourceType resourceType, Long resou
127139 setGlobalLock ();
128140 if (quotaLimitLock .lock (TRY_TO_GET_LOCK_TIME )) {
129141 try {
130- checkLimitAndPersistReservations (account , resourceType , resourceId , resourceLimitTags , amount );
142+ checkLimitAndPersistReservations (account , this . domainId , resourceType , resourceId , resourceLimitTags , amount );
131143 CallContext .current ().putContextParameter (getContextParameterKey (), getIds ());
132144 } catch (NullPointerException npe ) {
133145 throw new CloudRuntimeException ("not enough means to check limits" , npe );
@@ -138,11 +150,11 @@ public CheckedReservation(Account account, ResourceType resourceType, Long resou
138150 throw new ResourceAllocationException (String .format ("unable to acquire resource reservation \" %s\" " , quotaLimitLock .getName ()), resourceType );
139151 }
140152 } else {
141- checkLimitAndPersistReservations (account , resourceType , resourceId , resourceLimitTags , amount );
153+ checkLimitAndPersistReservations (account , this . domainId , resourceType , resourceId , resourceLimitTags , amount );
142154 }
143155 } else {
144156 logger .debug ("not reserving any amount of resources for {} in domain {}, type: {}, tag: {}" ,
145- account .getAccountName (), account . getDomainId () , resourceType , getResourceLimitTagsAsString ());
157+ account .getAccountName (), this . domainId , resourceType , getResourceLimitTagsAsString ());
146158 }
147159 }
148160
@@ -153,7 +165,7 @@ public CheckedReservation(Account account, ResourceType resourceType, Long amoun
153165
154166 @ NotNull
155167 private void setGlobalLock () {
156- String lockName = String .format ("CheckedReservation-%s/%d" , account . getDomainId () , resourceType .getOrdinal ());
168+ String lockName = String .format ("CheckedReservation-%s/%d" , this . domainId , resourceType .getOrdinal ());
157169 setQuotaLimitLock (GlobalLock .getInternLock (lockName ));
158170 }
159171
0 commit comments