Skip to content

Commit 8b7b7a0

Browse files
committed
Delay in displaying VM migrate dialog due to get vm snapshot size for a
storage pool.
1 parent 4f0dbaa commit 8b7b7a0

3 files changed

Lines changed: 28 additions & 15 deletions

File tree

‎engine/schema/src/com/cloud/storage/dao/VolumeDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
3737

3838
Pair<Long, Long> getNonDestroyedCountAndTotalByPool(long poolId);
3939

40+
long getVMSnapshotSizeByPool(long poolId);
41+
4042
List<VolumeVO> findByInstance(long id);
4143

4244
List<VolumeVO> findByInstanceAndType(long id, Volume.Type vType);

‎engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
5959
protected final SearchBuilder<VolumeVO> DetachedAccountIdSearch;
6060
protected final SearchBuilder<VolumeVO> TemplateZoneSearch;
6161
protected final GenericSearchBuilder<VolumeVO, SumCount> TotalSizeByPoolSearch;
62+
protected final GenericSearchBuilder<VolumeVO, SumCount> TotalVMSnapshotSizeByPoolSearch;
6263
protected final GenericSearchBuilder<VolumeVO, Long> ActiveTemplateSearch;
6364
protected final SearchBuilder<VolumeVO> InstanceStatesSearch;
6465
protected final SearchBuilder<VolumeVO> AllFieldsSearch;
@@ -316,6 +317,15 @@ public VolumeDaoImpl() {
316317
TotalSizeByPoolSearch.and("state", TotalSizeByPoolSearch.entity().getState(), Op.NEQ);
317318
TotalSizeByPoolSearch.done();
318319

320+
TotalVMSnapshotSizeByPoolSearch = createSearchBuilder(SumCount.class);
321+
TotalVMSnapshotSizeByPoolSearch.select("sum", Func.SUM, TotalVMSnapshotSizeByPoolSearch.entity().getVmSnapshotChainSize());
322+
TotalVMSnapshotSizeByPoolSearch.and("poolId", TotalVMSnapshotSizeByPoolSearch.entity().getPoolId(), Op.EQ);
323+
TotalVMSnapshotSizeByPoolSearch.and("removed", TotalVMSnapshotSizeByPoolSearch.entity().getRemoved(), Op.NULL);
324+
TotalVMSnapshotSizeByPoolSearch.and("state", TotalVMSnapshotSizeByPoolSearch.entity().getState(), Op.NEQ);
325+
TotalVMSnapshotSizeByPoolSearch.and("vType", TotalVMSnapshotSizeByPoolSearch.entity().getVolumeType(), Op.EQ);
326+
TotalVMSnapshotSizeByPoolSearch.and("instanceId", TotalVMSnapshotSizeByPoolSearch.entity().getInstanceId(), Op.NNULL);
327+
TotalVMSnapshotSizeByPoolSearch.done();
328+
319329
ActiveTemplateSearch = createSearchBuilder(Long.class);
320330
ActiveTemplateSearch.and("pool", ActiveTemplateSearch.entity().getPoolId(), Op.EQ);
321331
ActiveTemplateSearch.and("template", ActiveTemplateSearch.entity().getTemplateId(), Op.EQ);
@@ -516,6 +526,20 @@ public Pair<Long, Long> getNonDestroyedCountAndTotalByPool(long poolId) {
516526
return new Pair<Long, Long>(sumCount.count, sumCount.sum);
517527
}
518528

529+
@Override
530+
public long getVMSnapshotSizeByPool(long poolId) {
531+
SearchCriteria<SumCount> sc = TotalVMSnapshotSizeByPoolSearch.create();
532+
sc.setParameters("poolId", poolId);
533+
sc.setParameters("state", State.Destroy);
534+
sc.setParameters("vType", Volume.Type.ROOT.toString());
535+
List<SumCount> results = customSearch(sc, null);
536+
if (results != null) {
537+
return results.get(0).sum;
538+
} else {
539+
return 0;
540+
}
541+
}
542+
519543
@Override
520544
@DB
521545
public boolean remove(Long id) {

‎server/src/com/cloud/capacity/CapacityManagerImpl.java‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.naming.ConfigurationException;
2929

3030
import org.apache.log4j.Logger;
31+
3132
import org.apache.cloudstack.framework.config.ConfigDepot;
3233
import org.apache.cloudstack.framework.config.ConfigKey;
3334
import org.apache.cloudstack.framework.config.Configurable;
@@ -69,7 +70,6 @@
6970
import com.cloud.storage.StorageManager;
7071
import com.cloud.storage.VMTemplateStoragePoolVO;
7172
import com.cloud.storage.VMTemplateVO;
72-
import com.cloud.storage.VolumeVO;
7373
import com.cloud.storage.dao.VMTemplatePoolDao;
7474
import com.cloud.storage.dao.VolumeDao;
7575
import com.cloud.utils.DateUtil;
@@ -474,19 +474,6 @@ public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolea
474474

475475
}
476476

477-
private long getVMSnapshotAllocatedCapacity(StoragePoolVO pool){
478-
List<VolumeVO> volumes = _volumeDao.findByPoolId(pool.getId());
479-
long totalSize = 0;
480-
for (VolumeVO volume : volumes) {
481-
if(volume.getInstanceId() == null)
482-
continue;
483-
Long chainSize = volume.getVmSnapshotChainSize();
484-
if(chainSize != null)
485-
totalSize += chainSize;
486-
}
487-
return totalSize;
488-
}
489-
490477
@Override
491478
public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation){
492479

@@ -495,7 +482,7 @@ public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateFo
495482
long totalAllocatedSize = sizes.second() + sizes.first() * _extraBytesPerVolume;
496483

497484
// Get size for VM Snapshots
498-
totalAllocatedSize = totalAllocatedSize + getVMSnapshotAllocatedCapacity(pool);
485+
totalAllocatedSize = totalAllocatedSize + _volumeDao.getVMSnapshotSizeByPool(pool.getId());
499486

500487
// Iterate through all templates on this storage pool
501488
boolean tmpinstalled = false;

0 commit comments

Comments
 (0)