Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,6 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
List<VolumeVO> searchRemovedByVms(List<Long> vmIds, Long batchSize);

VolumeVO findOneByIScsiName(String iScsiName);

int getVolumeCountByOfferingId(long diskOfferingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
protected GenericSearchBuilder<VolumeVO, SumCount> primaryStorageSearch2;
protected GenericSearchBuilder<VolumeVO, SumCount> secondaryStorageSearch;
private final SearchBuilder<VolumeVO> poolAndPathSearch;
final GenericSearchBuilder<VolumeVO, Integer> CountByOfferingId;

@Inject
ReservationDao reservationDao;
Expand Down Expand Up @@ -504,6 +505,11 @@ public VolumeDaoImpl() {
poolAndPathSearch.and("poolId", poolAndPathSearch.entity().getPoolId(), Op.EQ);
poolAndPathSearch.and("path", poolAndPathSearch.entity().getPath(), Op.EQ);
poolAndPathSearch.done();

CountByOfferingId = createSearchBuilder(Integer.class);
CountByOfferingId.select(null, Func.COUNT, CountByOfferingId.entity().getId());
CountByOfferingId.and("diskOfferingId", CountByOfferingId.entity().getDiskOfferingId(), Op.EQ);
CountByOfferingId.done();
}

@Override
Expand Down Expand Up @@ -909,4 +915,12 @@ public VolumeVO findOneByIScsiName(String iScsiName) {
sc.setParameters("iScsiName", iScsiName);
return findOneIncludingRemovedBy(sc);
}

@Override
public int getVolumeCountByOfferingId(long diskOfferingId) {
SearchCriteria<Integer> sc = CountByOfferingId.create();
sc.setParameters("diskOfferingId", diskOfferingId);
List<Integer> results = customSearch(sc, null);
return results.get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,5 @@ List<VMInstanceVO> searchRemovedByRemoveDate(final Date startDate, final Date en

Map<String, Long> getNameIdMapForVmIds(Collection<Long> ids);

int getVmCountByOfferingId(Long serviceOfferingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
protected SearchBuilder<VMInstanceVO> LastHostAndStatesSearch;
protected SearchBuilder<VMInstanceVO> VmsNotInClusterUsingPool;
protected SearchBuilder<VMInstanceVO> IdsPowerStateSelectSearch;
GenericSearchBuilder<VMInstanceVO, Integer> CountByOfferingId;

@Inject
ResourceTagDao tagsDao;
Expand Down Expand Up @@ -344,6 +345,11 @@ protected void init() {
IdsPowerStateSelectSearch.entity().getPowerStateUpdateCount(),
IdsPowerStateSelectSearch.entity().getPowerStateUpdateTime());
IdsPowerStateSelectSearch.done();

CountByOfferingId = createSearchBuilder(Integer.class);
CountByOfferingId.select(null, Func.COUNT, CountByOfferingId.entity().getId());
CountByOfferingId.and("serviceOfferingId", CountByOfferingId.entity().getServiceOfferingId(), Op.EQ);
CountByOfferingId.done();
}

@Override
Expand Down Expand Up @@ -1224,4 +1230,15 @@ public Map<String, Long> getNameIdMapForVmIds(Collection<Long> ids) {
return vms.stream()
.collect(Collectors.toMap(VMInstanceVO::getInstanceName, VMInstanceVO::getId));
}

@Override
public int getVmCountByOfferingId(Long serviceOfferingId) {
if (serviceOfferingId == null) {
return 0;
}
SearchCriteria<Integer> sc = CountByOfferingId.create();
sc.setParameters("serviceOfferingId", serviceOfferingId);
List<Integer> count = customSearch(sc, null);
return count.get(0);
}
}
25 changes: 21 additions & 4 deletions server/src/main/java/com/cloud/user/DomainManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.cloud.api.query.vo.VpcOfferingJoinVO;
import com.cloud.configuration.Resource;
import com.cloud.domain.dao.DomainDetailsDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.network.vpc.dao.VpcOfferingDao;
import com.cloud.network.vpc.dao.VpcOfferingDetailsDao;
import com.cloud.offerings.dao.NetworkOfferingDao;
Expand Down Expand Up @@ -85,6 +87,7 @@
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.service.dao.ServiceOfferingDetailsDao;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ManagerBase;
Expand All @@ -101,6 +104,8 @@
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.ReservationContextImpl;
import com.cloud.vm.dao.VMInstanceDao;

import org.apache.commons.lang3.StringUtils;

@Component
Expand Down Expand Up @@ -141,6 +146,14 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
@Inject
private ProjectDao _projectDao;
@Inject
private VMInstanceDao vmInstanceDao;
@Inject
private NetworkDao networkDao;
@Inject
private VolumeDao volumeDao;
@Inject
private VpcDao vpcDao;
@Inject
private ProjectManager _projectMgr;
@Inject
private RegionManager _regionMgr;
Expand Down Expand Up @@ -543,7 +556,8 @@ private void removeVpcOfferings(Long domainId, String domainIdString) {
List<Long> vpcOfferingsDetailsToRemove = new ArrayList<>();
List<VpcOfferingJoinVO> vpcOfferingsForThisDomain = vpcOfferingJoinDao.findByDomainId(domainId);
for (VpcOfferingJoinVO vpcOffering : vpcOfferingsForThisDomain) {
if (domainIdString.equals(vpcOffering.getDomainId())) {
int vpcCount = vpcDao.getVpcCountByOfferingId(vpcOffering.getId());
if (domainIdString.equals(vpcOffering.getDomainId()) && vpcCount == 0) {
vpcOfferingDao.remove(vpcOffering.getId());
} else {
vpcOfferingsDetailsToRemove.add(vpcOffering.getId());
Expand All @@ -558,7 +572,8 @@ private void removeNetworkOfferings(Long domainId, String domainIdString) {
List<Long> networkOfferingsDetailsToRemove = new ArrayList<>();
List<NetworkOfferingJoinVO> networkOfferingsForThisDomain = networkOfferingJoinDao.findByDomainId(domainId, false);
for (NetworkOfferingJoinVO networkOffering : networkOfferingsForThisDomain) {
if (domainIdString.equals(networkOffering.getDomainId())) {
int networkCount = networkDao.getNetworkCountByNetworkOffId(networkOffering.getId());
if (domainIdString.equals(networkOffering.getDomainId()) && networkCount == 0) {
networkOfferingDao.remove(networkOffering.getId());
} else {
networkOfferingsDetailsToRemove.add(networkOffering.getId());
Expand All @@ -573,7 +588,8 @@ private void removeServiceOfferings(Long domainId, String domainIdString) {
List<Long> serviceOfferingsDetailsToRemove = new ArrayList<>();
List<ServiceOfferingJoinVO> serviceOfferingsForThisDomain = serviceOfferingJoinDao.findByDomainId(domainId);
for (ServiceOfferingJoinVO serviceOffering : serviceOfferingsForThisDomain) {
if (domainIdString.equals(serviceOffering.getDomainId())) {
int vmCount = vmInstanceDao.getVmCountByOfferingId(serviceOffering.getId());
if (domainIdString.equals(serviceOffering.getDomainId()) && vmCount == 0) {
serviceOfferingDao.remove(serviceOffering.getId());
} else {
serviceOfferingsDetailsToRemove.add(serviceOffering.getId());
Expand All @@ -588,7 +604,8 @@ private void removeDiskOfferings(Long domainId, String domainIdString) {
List<Long> diskOfferingsDetailsToRemove = new ArrayList<>();
List<DiskOfferingJoinVO> diskOfferingsForThisDomain = diskOfferingJoinDao.findByDomainId(domainId);
for (DiskOfferingJoinVO diskOffering : diskOfferingsForThisDomain) {
if (domainIdString.equals(diskOffering.getDomainId())) {
int volumeCount = volumeDao.getVolumeCountByOfferingId(diskOffering.getId());
if (domainIdString.equals(diskOffering.getDomainId()) && volumeCount == 0) {
diskOfferingDao.remove(diskOffering.getId());
} else {
diskOfferingsDetailsToRemove.add(diskOffering.getId());
Expand Down
Loading