File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/manager Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change 4343import org .apache .cloudstack .storage .image .store .ImageStoreImpl ;
4444import org .apache .logging .log4j .Logger ;
4545import org .apache .logging .log4j .LogManager ;
46- import org .apache .commons .collections .CollectionUtils ;
4746import org .springframework .stereotype .Component ;
4847
4948import com .cloud .server .StatsCollector ;
@@ -180,14 +179,16 @@ public DataStore getRandomImageStore(List<DataStore> imageStores) {
180179
181180 @ Override
182181 public DataStore getImageStoreWithFreeCapacity (List <DataStore > imageStores ) {
183- List <DataStore > orderedImageStores = orderImageStoresOnFreeCapacity (imageStores );
184- if (CollectionUtils .isEmpty (orderedImageStores )) {
185- logger .error (String .format ("Could not find an image storage in zone with less than %d usage" ,
186- Math .round (_statsCollector .getImageStoreCapacityThreshold () * 100 )));
187- return null ;
182+ imageStores .sort ((store1 , store2 ) -> Long .compare (_statsCollector .imageStoreCurrentFreeCapacity (store2 ),
183+ _statsCollector .imageStoreCurrentFreeCapacity (store1 )));
184+ for (DataStore imageStore : imageStores ) {
185+ if (_statsCollector .imageStoreHasEnoughCapacity (imageStore )) {
186+ return imageStore ;
187+ }
188188 }
189-
190- return orderedImageStores .get (0 );
189+ logger .error (String .format ("Could not find an image storage in zone with less than %d usage" ,
190+ Math .round (_statsCollector .getImageStoreCapacityThreshold () * 100 )));
191+ return null ;
191192 }
192193
193194 @ Override
You can’t perform that action at this time.
0 commit comments