2626
2727import javax .inject .Inject ;
2828
29+ import com .cloud .configuration .Resource ;
30+ import org .apache .cloudstack .context .CallContext ;
31+ import org .apache .cloudstack .user .ResourceReservation ;
2932import org .apache .commons .collections .CollectionUtils ;
3033import org .apache .log4j .Logger ;
3134import org .springframework .stereotype .Component ;
@@ -443,6 +446,7 @@ public VolumeDaoImpl() {
443446 CountByAccount .and ("account" , CountByAccount .entity ().getAccountId (), SearchCriteria .Op .EQ );
444447 CountByAccount .and ("state" , CountByAccount .entity ().getState (), SearchCriteria .Op .NIN );
445448 CountByAccount .and ("displayVolume" , CountByAccount .entity ().isDisplayVolume (), Op .EQ );
449+ CountByAccount .and ("resource_reservation_id" , CountByAccount .entity ().getResourceReservationId (), SearchCriteria .Op .NULL );
446450 CountByAccount .done ();
447451
448452 primaryStorageSearch = createSearchBuilder (SumCount .class );
@@ -454,6 +458,7 @@ public VolumeDaoImpl() {
454458 primaryStorageSearch .and ("displayVolume" , primaryStorageSearch .entity ().isDisplayVolume (), Op .EQ );
455459 primaryStorageSearch .and ("isRemoved" , primaryStorageSearch .entity ().getRemoved (), Op .NULL );
456460 primaryStorageSearch .and ("NotCountStates" , primaryStorageSearch .entity ().getState (), Op .NIN );
461+ primaryStorageSearch .and ("resource_reservation_id" , primaryStorageSearch .entity ().getResourceReservationId (), Op .NULL );
457462 primaryStorageSearch .done ();
458463
459464 primaryStorageSearch2 = createSearchBuilder (SumCount .class );
@@ -468,6 +473,7 @@ public VolumeDaoImpl() {
468473 primaryStorageSearch2 .and ("displayVolume" , primaryStorageSearch2 .entity ().isDisplayVolume (), Op .EQ );
469474 primaryStorageSearch2 .and ("isRemoved" , primaryStorageSearch2 .entity ().getRemoved (), Op .NULL );
470475 primaryStorageSearch2 .and ("NotCountStates" , primaryStorageSearch2 .entity ().getState (), Op .NIN );
476+ primaryStorageSearch2 .and ("resource_reservation_id" , primaryStorageSearch2 .entity ().getResourceReservationId (), Op .NULL );
471477 primaryStorageSearch2 .done ();
472478
473479 secondaryStorageSearch = createSearchBuilder (SumCount .class );
@@ -811,4 +817,13 @@ public List<VolumeVO> listByIds(List<Long> ids) {
811817 sc .setParameters ("idIN" , ids .toArray ());
812818 return listBy (sc , null );
813819 }
820+
821+ @ Override
822+ public VolumeVO persist (VolumeVO entity ) {
823+ Object obj = CallContext .current ().getContextParameter (String .format ("%s-%s" , ResourceReservation .class .getSimpleName (), Resource .ResourceType .volume .name ()));
824+ if (obj instanceof Long ) {
825+ entity .setResourceReservationId ((long )obj );
826+ }
827+ return super .persist (entity );
828+ }
814829}
0 commit comments