mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
server: check service offering (storage) tags when reallocate a ROOT disk (#5501)
* server: check service offering (storage) tags when reallocate a ROOT disk * server: resize volumes in Allocated state
This commit is contained in:
parent
e92ce916f3
commit
669ab73efe
@ -94,6 +94,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
|
||||
|
||||
List<VolumeVO> findReadyRootVolumesByInstance(long instanceId);
|
||||
|
||||
List<VolumeVO> findReadyAndAllocatedRootVolumesByInstance(long instanceId);
|
||||
|
||||
List<Long> listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId);
|
||||
|
||||
List<Long> listZoneWidePoolIdsByVolumeCount(long dcId, long accountId);
|
||||
|
||||
@ -61,6 +61,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
protected final GenericSearchBuilder<VolumeVO, Long> ActiveTemplateSearch;
|
||||
protected final SearchBuilder<VolumeVO> InstanceStatesSearch;
|
||||
protected final SearchBuilder<VolumeVO> AllFieldsSearch;
|
||||
protected final SearchBuilder<VolumeVO> RootDiskStateSearch;
|
||||
protected GenericSearchBuilder<VolumeVO, Long> CountByAccount;
|
||||
protected GenericSearchBuilder<VolumeVO, SumCount> primaryStorageSearch;
|
||||
protected GenericSearchBuilder<VolumeVO, SumCount> primaryStorageSearch2;
|
||||
@ -217,6 +218,15 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeVO> findReadyAndAllocatedRootVolumesByInstance(long instanceId) {
|
||||
SearchCriteria<VolumeVO> sc = RootDiskStateSearch.create();
|
||||
sc.setParameters("instanceId", instanceId);
|
||||
sc.setParameters("state", Volume.State.Ready, State.Allocated);
|
||||
sc.setParameters("vType", Volume.Type.ROOT);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeVO> findByPod(long podId) {
|
||||
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
|
||||
@ -365,6 +375,12 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
||||
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
|
||||
RootDiskStateSearch = createSearchBuilder();
|
||||
RootDiskStateSearch.and("state", RootDiskStateSearch.entity().getState(), Op.IN);
|
||||
RootDiskStateSearch.and("vType", RootDiskStateSearch.entity().getVolumeType(), Op.EQ);
|
||||
RootDiskStateSearch.and("instanceId", RootDiskStateSearch.entity().getInstanceId(), Op.EQ);
|
||||
RootDiskStateSearch.done();
|
||||
|
||||
DetachedAccountIdSearch = createSearchBuilder();
|
||||
DetachedAccountIdSearch.and("accountId", DetachedAccountIdSearch.entity().getAccountId(), Op.EQ);
|
||||
DetachedAccountIdSearch.and("destroyed", DetachedAccountIdSearch.entity().getState(), Op.NEQ);
|
||||
|
||||
@ -1639,7 +1639,8 @@ StateListener<State, VirtualMachine.Event, VirtualMachine>, Configurable {
|
||||
|
||||
DiskOfferingVO diskOffering = _diskOfferingDao.findById(toBeCreated.getDiskOfferingId());
|
||||
|
||||
if (vmProfile.getTemplate().getFormat() == Storage.ImageFormat.ISO && vmProfile.getServiceOffering().getTagsArray().length != 0) {
|
||||
if ((vmProfile.getTemplate().getFormat() == Storage.ImageFormat.ISO || toBeCreated.getVolumeType() == Volume.Type.ROOT)
|
||||
&& vmProfile.getServiceOffering().getTagsArray().length != 0) {
|
||||
diskOffering.setTagsArray(Arrays.asList(vmProfile.getServiceOffering().getTagsArray()));
|
||||
}
|
||||
|
||||
|
||||
@ -1271,7 +1271,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
|
||||
DiskOfferingVO newRootDiskOffering = _diskOfferingDao.findById(newServiceOffering.getId());
|
||||
|
||||
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vmInstance.getId());
|
||||
List<VolumeVO> vols = _volsDao.findReadyAndAllocatedRootVolumesByInstance(vmInstance.getId());
|
||||
|
||||
for (final VolumeVO rootVolumeOfVm : vols) {
|
||||
DiskOfferingVO currentRootDiskOffering = _diskOfferingDao.findById(rootVolumeOfVm.getDiskOfferingId());
|
||||
@ -1347,7 +1347,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
private void resizeRootVolumeOfVmWithNewOffering(VMInstanceVO vmInstance, ServiceOfferingVO newServiceOffering)
|
||||
throws ResourceAllocationException {
|
||||
DiskOfferingVO newROOTDiskOffering = _diskOfferingDao.findById(newServiceOffering.getId());
|
||||
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vmInstance.getId());
|
||||
List<VolumeVO> vols = _volsDao.findReadyAndAllocatedRootVolumesByInstance(vmInstance.getId());
|
||||
|
||||
for (final VolumeVO rootVolumeOfVm : vols) {
|
||||
rootVolumeOfVm.setDiskOfferingId(newROOTDiskOffering.getId());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user